Page MenuHomePhabricator

mw.msg should not return an error message if the message contains '{{SomeTemplate}}'
Closed, ResolvedPublic

Description

If mw.loader.getState( 'mediawiki.jqueryMsg' ) is not 'ready', and I execute the code

mw.messages.set( {
    'some-key': 'SomeText {{SomeTemplate}}.'
} ); 
alert( mw.msg( 'some-key' ) );

I get 'SomeText {{SomeTemplate}}.' as expected.

But if I enable any gadget which loads the module 'mediawiki.jqueryMsg', and run the same code again, the result unexpectedly changes to 'some-key: Unknown operation "sometemplate"'.

It should still be 'SomeText {{SomeTemplate}}.', because there is no magic word called 'SomeTemplate'

Details

Reference
bz52479

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:48 AM
bzimport set Reference to bz52479.
bzimport added a subscriber: Unknown Object (MLST).

Templates are not currently supported in jQueryMsg, just magic words (the code uses the word 'template' to mean magic words).

mw.msg is equivalent to mw.message(...).text()

meaning the 'text' format/operation is being used.

In the PHP parser's text mode, if a template exists, it is expanded into its wikitext. If it does not exist, it results in [[:Template:SomeTemplate]].

With the way jQueryMsg currently works, even checking if the template existed would require either:

  1. Sending extra data down from ResourceLoader
  2. Doing an API call from jQueryMsg

Thus, for now I recommend you use:

mw.message( 'some-key' ).plain()

if you want the output 'SomeText {{SomeTemplate}}.' for this kind of thing.

The 'plain' format does not try to expand {{ }} blocks, just $1, $2 replacement.

Change 113307 had a related patch set uploaded by Bartosz Dziewoński:
mediawiki.jqueryMsg: Don't throw parse errors in the user's face

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

The above patch sorta kinda addresses this by hiding the user-visible error messages.

matmarex set Security to None.
matmarex claimed this task.

This is actually entirely fixed, as far as I can tell.

The warning message is still there in the Firefox console:

mediawiki.jqueryMsg: some-key: Unknown operation "sometemplate"

That is a bug in calling code. Per comment T54479#547176 above, you should use mw.message( 'some-key' ).plain() if the message is supposed to include literal '{{', or escape the braces if you want it parsed (<nowiki/> probably won't work, but &#123; probably will).