Page MenuHomePhabricator

Allow parameter substitution on preload templates
Closed, ResolvedPublic

Description

Author: tomwkbug

Description:
EditPage.php patch to support preload parameter substitution

Preloaded text (text included into new pages using edit links of the form
http://www.mediawiki.org/wiki/example?action=edit&preload=Template:ExamplePreload ) currently cannot use parameter substitution. I think it would be useful to be able to pass parameters for {{{ }}} substitution as part of the &preload parameter.

The attached patch to EditPage.php allows parameters to be provided, ie. support for
&preload=egtemplate|param=something|one|
which would substitute {{{param}}} and {{{1}}} in egtemplate before creating the new page.

My approach is a bit kludgy and naive, probably the preload page should be properly passed through the parser, but I think could be still be useful.


Version: unspecified
Severity: enhancement

Attached:

Details

Reference
bz12853

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 10:02 PM
bzimport set Reference to bz12853.

Thanks for the patch.

However, I'm not entirely sure that allowing to specify params via url is something needed. If it is really needed though, we should be using the actual parser to do it, not str_replace'ing the parameters (which is actually much easier now that processing preload text now lives in Parser::getPreloadText )

Additionally, if we did that, we'd probably want to process {{{param|foo}}} into foo to be like normal, but then what if someone wants to use preload in order to create a template, and they want their {{{param|foo}}} in the preload source text to be untouched.

Was this ability ever implemented? I would like to create a template that has some parameters passed to it from a linked image. As a note, using pipes in the url would not be ideal if the link was called from [[File:example.jpg|link=url]] Using a pipe would force users to {{!}} the url. An alternative might be &preload=Template:Foo^param=bar^one. See [[User:Technical_13/Templates/NFCC9]] which is just a shell of what I would like to do based on implementation of some kind of ability to pass preload templates arguments. See [[User:Technical 13/SandBox/NFCC]] for full description of what I would like to be able to do with this feature.

Bump and add Jackmcbarn to the CC list as he mentioned he could try and write a patch for this on my enwp talk page.

&preload=Template:Foo^param=bar^one

I know pipes are a pain for wiki syntax, but if we're going to do this, I would still prefer we used them instead of using other characters (What if you want to use ^ in a parameter name, what if you have a template named Foo^. Using |'s doesn't cause any more confusion, and its already a reserved character). Users can always use %7C instead of {{!}} in urls.

Change 116482 had a related patch set uploaded by Jackmcbarn:
Allow passing parameters to preload

https://gerrit.wikimedia.org/r/116482

(In reply to Bawolff (Brian Wolff) from comment #5)

&preload=Template:Foo^param=bar^one

I know pipes are a pain for wiki syntax, but if we're going to do this, I
would still prefer we used them instead of using other characters (What if
you want to use ^ in a parameter name, what if you have a template named
Foo^. Using |'s doesn't cause any more confusion, and its already a reserved
character). Users can always use %7C instead of {{!}} in urls.

Per [[gerrit:116482]] the syntax will be:
action=edit&preload=Foo&preloadparams[]=first&preloadparams[]=second

Where "first" will be available as $1 and "second" will be available as $2 in the preload template of "Foo" if my understanding is correct. Does this address your issue/question Brian?

(In reply to Technical 13 from comment #7)

(In reply to Bawolff (Brian Wolff) from comment #5)

&preload=Template:Foo^param=bar^one

I know pipes are a pain for wiki syntax, but if we're going to do this, I
would still prefer we used them instead of using other characters (What if
you want to use ^ in a parameter name, what if you have a template named
Foo^. Using |'s doesn't cause any more confusion, and its already a reserved
character). Users can always use %7C instead of {{!}} in urls.

Per [[gerrit:116482]] the syntax will be:
action=edit&preload=Foo&preloadparams[]=first&preloadparams[]=second

Where "first" will be available as $1 and "second" will be available as $2
in the preload template of "Foo" if my understanding is correct. Does this
address your issue/question Brian?

I'm fine with that syntax. I object to suddenly treating ^ as magic divider.


Anyways, patch merged. As has been stated above you can do things like action=edit&preload=Foo&preloadparams[]=first&preloadparams[]=second and have $1 replaced with first, $2 replaced with second, etc. $* will output all parameters, plus a colon (Consider the $* a side effect, which would probably not change, but we make no guarantees that it won't some far off day in the future). It should probably be available on Wikipedia by April 17.