I've not done much template work since parser functions were new. Grabbing some old code examples, found it didn't work anymore. Workaround?
===
Ancient code (expected single space):
{{{{{subst|}}}#if:{{{par1|}}}|[[Category:{{{par1}}}{{{{{subst|}}}#if:{{{key1|}}}{{{{{subst|}}}!}}{{{key1}}}}}]] <!-- bpar1 --> }}{{{{{subst|}}}#if:{{{par2|}}}|[[Category:{{{par2}}}{{{{{subst|}}}#if:{{{key2|}}}{{{{{subst|}}}!}}{{{key2}}}}}]] <!-- bpar2 --> }}{{{{{subst|}}}#if:{{{par3|}}}|[[Category:{{{par3}}}{{{{{subst|}}}#if:{{{key3|}}}{{{{{subst|}}}!}}{{{key3}}}}}]] <!-- bpar3 --> }}
Also tried (expected double space, hoped for single space):
{{{{{subst|}}}#if:{{{par1|}}}| [[Category:{{{par1}}}{{{{{subst|}}}#if:{{{key1|}}}{{{{{subst|}}}!}}{{{key1}}}}}]] <!-- bpar1 --> }}{{{{{subst|}}}#if:{{{par2|}}}| [[Category:{{{par2}}}{{{{{subst|}}}#if:{{{key2|}}}{{{{{subst|}}}!}}{{{key2}}}}}]] <!-- bpar2 --> }}{{{{{subst|}}}#if:{{{par3|}}}| [[Category:{{{par3}}}{{{{{subst|}}}#if:{{{key3|}}}{{{{{subst|}}}!}}{{{key3}}}}}]] <!-- bpar3 --> }}
===
Each category should be on a new line. If the par* doesn't exist, then the }} that begins the next line would slurp up the newline, leaving no blank line.
Example {{subst:testing|par1=A|par2=B|key2=C|subst=subst:}}
As I remember, should yield something like:
[[Category:A]] <!-- bpar1 --> [[Category:B|C]] <!-- bpar2 -->
Currently output:
[[Category:A]] <!-- bpar1 -->[[Category:B]] <!-- bpar2 -->
Did the evaluation order change, so the inner {{subst:!}} happens first instead of second, and loses the C parameter (interpreting it as "else")?
And the leading and trailing linebreaks are slurped up and ignored?
Any known work around? (I tried searching meta and elsewhere, but no joy.)
William Allen Simpson wrote:
{{{{{subst|}}}#if:{{{par1|}}}|[[Category:{{{par1}}}{{{{{subst|}}}#if:{{{key1|}}}{{{{{subst|}}}!}}{{{key1}}}}}]] <!-- bpar1 --> }}{{{{{subst|}}}#if:{{{par2|}}}|[[Category:{{{par2}}}{{{{{subst|}}}#if:{{{key2|}}}{{{{{subst|}}}!}}{{{key2}}}}}]] <!-- bpar2 --> }}{{{{{subst|}}}#if:{{{par3|}}}|[[Category:{{{par3}}}{{{{{subst|}}}#if:{{{key3|}}}{{{{{subst|}}}!}}{{{key3}}}}}]] <!-- bpar3 --> }}
Nothing like a wikitext puzzle to start off your day.
Did the evaluation order change, so the inner {{subst:!}} happens first instead of second, and loses the C parameter (interpreting it as "else")?
{{subst:!}} no longer works as a separator between parser function parameters, it just works as a literal character. Welcome to MediaWiki 1.12. See:
http://meta.wikimedia.org/wiki/MNPP
For those playing at home, the simplified test case is:
{{#if: a {{!}} b }}
The condition "a | b" is true, but no return value is specified, so the default return is used, i.e. an empty string
And the leading and trailing linebreaks are slurped up and ignored?
Whitespace at the beginning and end of a parameter to #if, #ifeq, #switch, etc. is stripped. This was always the case in HTML mode, at least since MW 1.7. It's possible MW 1.12 changed it for subst mode.
Any known work around? (I tried searching meta and elsewhere, but no joy.)
Use "|" instead of "{{{{{subst|}}}!}}". Not only will it work, it'll be easier to read.
The workarounds that come to mind for the line break issue are fairly obscure and complex. If I were you I'd just put the categories on the same line and be done with it.
-- Tim Starling
Tim Starling wrote:
The workarounds that come to mind for the line break issue are fairly obscure and complex. If I were you I'd just put the categories on the same line and be done with it.
I'll need the workaround, as this was a simplified example. My actual code generates a long list of template parameters (also wanted one per line) and up to 18 categories. All on one line is not so good....
Should invoking another function (perhaps called {{newline}}) at each point preserve internal line breaks?
{{{{{subst|}}}#if:{{{par1|}}} |{{{{{subst|}}}newline |[[Category:{{{par1}}}{{{{{subst|}}}#if:{{{key1|}}}|{{{key1}}}}}]] <!-- bpar1 --> }} }}
I waited for an answer for awhile, then tried it anyway. No joy.
I created (at en:) the template {{emit category}}.
[[Category:{{{1}}}{{{{{subst|}}}#if:{{{2|}}}|{{{{{subst|}}}!}}{{{2}}}}}]]
The template ends with 1 newline, as usual.
BTW: this seems to require subst of {{!}} -- and that works, contrary to the documentation. There's probably a way to do this without the second subst, perhaps by duplicating the entire [[Category]] in both then and else clauses?
{{{{{subst|}}}#if:{{{par1|}}} |{{{{{subst|}}}emit category|1={{{par1|}}}|2={{{key1|}}}|subst={{{subst|}}}}} }}{{{{{subst|}}}#if:{{{par2|}}} |{{{{{subst|}}}emit category|1={{{par2|}}}|2={{{key2|}}}|subst={{{subst|}}}}} }}{{{{{subst|}}}#if:{{{par3|}}} |{{{{{subst|}}}emit category|1={{{par3|}}}|2={{{key3|}}}|subst={{{subst|}}}}} }}
Still yields 3 categories on the same line.
Why is the parser function sucking up the newlines in the meta template?
Tim Starling <tstarling <at> wikimedia.org> writes:
{{subst:!}} no longer works as a separator between parser function parameters, it just works as a literal character. Welcome to MediaWiki 1.12.
Seems like it was intended to be the | in [[category:foo|bar]], except that someone forgot a | from the code. Correctly it would be:
{{{{{subst|}}}#if:{{{par1|}}}|[[Category:{{{par1}}}{{{{{subst|}}}#if: {{{key1|}}}|{{{{{subst|}}}!}}{{{key1}}}}}]] <!-- bpar1 --> }}{{{{{subst|}}}#if:{{{par2|}}}|[[Category:{{{par2}}}{{{{{subst|}}}#if: {{{key2|}}}|{{{{{subst|}}}!}}{{{key2}}}}}]] <!-- bpar2 --> }}{{{{{subst|}}}#if:{{{par3|}}}|[[Category:{{{par3}}}{{{{{subst|}}}#if: {{{key3|}}}|{{{{{subst|}}}!}}{{{key3}}}}}]] <!-- bpar3 --> }}
(Note that I added extra linebreaks after #if: so that gmane doesn't complain for lines being too long.)
The workarounds that come to mind for the line break issue are fairly obscure and complex. If I were you I'd just put the categories on the same line and be done with it.
Just put the templates on separate lines and wrap the whole thing in another #if to discard additional newlines at the end:
{{#if:1| {{{{{subst|}}}#if:{{{par1|1}}}|[[Category:{{{par1}}}{{{{{subst|}}}#if: {{{key1|1}}}|{{{{{subst|}}}!}}{{{key1}}}}}]]}} {{{{{subst|}}}#if:{{{par2|}}}|[[Category:{{{par2}}}{{{{{subst|}}}#if: {{{key2|}}}|{{{{{subst|}}}!}}{{{key2}}}}}]]}} {{{{{subst|}}}#if:{{{par3|}}}|[[Category:{{{par3}}}{{{{{subst|}}}#if: {{{key3|}}}|{{{{{subst|}}}!}}{{{key3}}}}}]]}} }}
(This assumes that whenever par2 is missing, par3 is missing too.)
Hoi, At some stage Wikipedia was this thing that everybody can edit... I can not and will not edit this shit so what do you expect from the average Joe ?? Thanks, Gerard
2009/6/25 Tisza Gergő gtisza@gmail.com
Tim Starling <tstarling <at> wikimedia.org> writes:
{{subst:!}} no longer works as a separator between parser function parameters, it just works as a literal character. Welcome to MediaWiki 1.12.
Seems like it was intended to be the | in [[category:foo|bar]], except that someone forgot a | from the code. Correctly it would be:
{{{{{subst|}}}#if:{{{par1|}}}|[[Category:{{{par1}}}{{{{{subst|}}}#if: {{{key1|}}}|{{{{{subst|}}}!}}{{{key1}}}}}]]
<!-- bpar1 -->
}}{{{{{subst|}}}#if:{{{par2|}}}|[[Category:{{{par2}}}{{{{{subst|}}}#if: {{{key2|}}}|{{{{{subst|}}}!}}{{{key2}}}}}]]
<!-- bpar2 -->
}}{{{{{subst|}}}#if:{{{par3|}}}|[[Category:{{{par3}}}{{{{{subst|}}}#if: {{{key3|}}}|{{{{{subst|}}}!}}{{{key3}}}}}]]
<!-- bpar3 -->
}}
(Note that I added extra linebreaks after #if: so that gmane doesn't complain for lines being too long.)
The workarounds that come to mind for the line break issue are fairly obscure and complex. If I were you I'd just put the categories on the same line and be done with it.
Just put the templates on separate lines and wrap the whole thing in another #if to discard additional newlines at the end:
{{#if:1| {{{{{subst|}}}#if:{{{par1|1}}}|[[Category:{{{par1}}}{{{{{subst|}}}#if: {{{key1|1}}}|{{{{{subst|}}}!}}{{{key1}}}}}]]}} {{{{{subst|}}}#if:{{{par2|}}}|[[Category:{{{par2}}}{{{{{subst|}}}#if: {{{key2|}}}|{{{{{subst|}}}!}}{{{key2}}}}}]]}} {{{{{subst|}}}#if:{{{par3|}}}|[[Category:{{{par3}}}{{{{{subst|}}}#if: {{{key3|}}}|{{{{{subst|}}}!}}{{{key3}}}}}]]}} }}
(This assumes that whenever par2 is missing, par3 is missing too.)
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On Fri, Jun 26, 2009 at 12:01 PM, Gerard Meijssengerard.meijssen@gmail.com wrote:
Hoi, At some stage Wikipedia was this thing that everybody can edit... I can not and will not edit this shit so what do you expect from the average Joe ??
I can not (effectively) contribute to http://en.wikipedia.org/wiki/Ten_Commandments_in_Roman_Catholicism
Does this mean Wikipedia is a failure?
I don't think so. Not everyone needs to be able to do everything. Thats one reasons projects have communities: Other people can do the work which I'm not interested in or not qualified for. Not everyone needs to make templates— and there are some people who'd have nothing else to do but add fart jokes to science articles if the site didn't have plenty of template mongering that needed doing.
Unfortunately the existing system is needlessly exclusive. The existing parser function uses solution are so byzantine that even many people with the right interest and knowledge are significantly put off from it.
The distinction between this and a general "easy to use" is a very critical one.
It's also the case that the existing system's problems spills past its borders due to its own limitations: Regular users need to deal with things like weird whitespace handling and templates which MUST be substed (or can't be substed; at random from the user's perspective). This makes the system harder even for the vast majority of people who should never need to worry about the internals of the templates.
I think this is the most important issue, and its one with real usability impacts, but it's not due to the poor syntax. On this point, the template language could be intercal but still leave most users completely free to ignore the messy insides. The existing system doesn't because there is no clear boundary between the page and the templates (among other reasons, like the limitations of the existing 'string' manipulation functions).
Hoi, In the past the existence of templates in one wiki has been used as an argument to not accept an extension. With extensions you have functionality that is indeed intended to be external to ordinary users but you are talking about functionality that can be tested. With templates you have stuff that can adn does severely impact performance and is at the same time not usable on other systems.
While it may be so that you can not effectively contribute to an article on something esoteric as the "ten commondmanets in Roman Catholocism", it might be possible for you to translate it in another language if you have the language skills. With the way templates are I would not touch them with a barge pole if I can help it. Templates are however the only tool we consider for things like info boxes and stuff. They are as a result quite important from a functional point of view. From a usability point of view they are horrible.
In conclusion, templates are used and they prove to be problematic. The best proof of this is the recent performance issues we had. Thanks, GerardM
2009/6/26 Gregory Maxwell gmaxwell@gmail.com
On Fri, Jun 26, 2009 at 12:01 PM, Gerard Meijssengerard.meijssen@gmail.com wrote:
Hoi, At some stage Wikipedia was this thing that everybody can edit... I can
not
and will not edit this shit so what do you expect from the average Joe ??
I can not (effectively) contribute to http://en.wikipedia.org/wiki/Ten_Commandments_in_Roman_Catholicism
Does this mean Wikipedia is a failure?
I don't think so. Not everyone needs to be able to do everything. Thats one reasons projects have communities: Other people can do the work which I'm not interested in or not qualified for. Not everyone needs to make templates— and there are some people who'd have nothing else to do but add fart jokes to science articles if the site didn't have plenty of template mongering that needed doing.
Unfortunately the existing system is needlessly exclusive. The existing parser function uses solution are so byzantine that even many people with the right interest and knowledge are significantly put off from it.
The distinction between this and a general "easy to use" is a very critical one.
It's also the case that the existing system's problems spills past its borders due to its own limitations: Regular users need to deal with things like weird whitespace handling and templates which MUST be substed (or can't be substed; at random from the user's perspective). This makes the system harder even for the vast majority of people who should never need to worry about the internals of the templates.
I think this is the most important issue, and its one with real usability impacts, but it's not due to the poor syntax. On this point, the template language could be intercal but still leave most users completely free to ignore the messy insides. The existing system doesn't because there is no clear boundary between the page and the templates (among other reasons, like the limitations of the existing 'string' manipulation functions).
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
As this thread has come back, I'd like to take the time to say thank you.
Tisza Gergő wrote:
Just put the templates on separate lines and wrap the whole thing in another #if to discard additional newlines at the end:
{{#if:1| {{{{{subst|}}}#if:{{{par1|1}}}|[[Category:{{{par1}}}{{{{{subst|}}}#if: {{{key1|1}}}|{{{{{subst|}}}!}}{{{key1}}}}}]]}} {{{{{subst|}}}#if:{{{par2|}}}|[[Category:{{{par2}}}{{{{{subst|}}}#if: {{{key2|}}}|{{{{{subst|}}}!}}{{{key2}}}}}]]}} {{{{{subst|}}}#if:{{{par3|}}}|[[Category:{{{par3}}}{{{{{subst|}}}#if: {{{key3|}}}|{{{{{subst|}}}!}}{{{key3}}}}}]]}} }}
(This assumes that whenever par2 is missing, par3 is missing too.)
That worked, and I finally finished the replacements today. For just the categories, I needed 3 levels of those wrapping #if's. Elsewhere, I needed 4 levels.
Fortunately, BBedit on a Mac does a good job keeping track of the levels for balancing {}.
My final code for posterity (aligned, using my emit templates, but not putting the par test in them yet, which could probably be done to make the code cleaner) for just the categories -- see the actual 40+ parameter mess at [[Template:Catdesc wipeout parent categories]]:
{{{{{subst|}}}#if:3 | {{{{{subst|}}}#if:1 | {{{{{subst|}}}#if:{{{par1|}}} |{{{{{subst|}}}emit category |1={{{par1|}}} |2={{{key1|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{par2|}}} |{{{{{subst|}}}emit category |1={{{par2|}}} |2={{{key2|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{par3|}}} |{{{{{subst|}}}emit category |1={{{par3|}}} |2={{{key3|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{par4|}}} |{{{{{subst|}}}emit category |1={{{par4|}}} |2={{{key4|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{par5|}}} |{{{{{subst|}}}emit category |1={{{par5|}}} |2={{{key5|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{par6|}}} |{{{{{subst|}}}emit category |1={{{par6|}}} |2={{{key6|}}} |subst={{{subst|}}} }} }} }} {{{{{subst|}}}#if:2 | {{{{{subst|}}}#if:1 | {{{{{subst|}}}#if:{{{dpar1|}}} |{{{{{subst|}}}emit category |1={{{dpar1|}}} |2={{{dkey1|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{dpar2|}}} |{{{{{subst|}}}emit category |1={{{dpar2|}}} |2={{{dkey2|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{dpar3|}}} |{{{{{subst|}}}emit category |1={{{dpar3|}}} |2={{{dkey3|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{dpar4|}}} |{{{{{subst|}}}emit category |1={{{dpar4|}}} |2={{{dkey4|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{dpar5|}}} |{{{{{subst|}}}emit category |1={{{dpar5|}}} |2={{{dkey5|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{dpar6|}}} |{{{{{subst|}}}emit category |1={{{dpar6|}}} |2={{{dkey6|}}} |subst={{{subst|}}} }} }} }} {{{{{subst|}}}#if:1 | {{{{{subst|}}}#if:{{{epar1|}}} |{{{{{subst|}}}emit category |1={{{epar1|}}} |2={{{ekey1|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{epar2|}}} |{{{{{subst|}}}emit category |1={{{epar2|}}} |2={{{ekey2|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{epar3|}}} |{{{{{subst|}}}emit category |1={{{epar3|}}} |2={{{ekey3|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{epar4|}}} |{{{{{subst|}}}emit category |1={{{epar4|}}} |2={{{ekey4|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{epar5|}}} |{{{{{subst|}}}emit category |1={{{epar5|}}} |2={{{ekey5|}}} |subst={{{subst|}}} }} }} {{{{{subst|}}}#if:{{{epar6|}}} |{{{{{subst|}}}emit category |1={{{epar6|}}} |2={{{ekey6|}}} |subst={{{subst|}}} }} }} }} }} }}
wikitech-l@lists.wikimedia.org