Page MenuHomePhabricator

Add support for rawParams to jqueryMsg
Closed, DeclinedPublic

Description

Just like wfMessage('foo')->rawParams($x)->escaped() works, we also need this in javascript.

For example when wanting to replace $1 with a hyperlink, we currently have to do something like this:

mw.message( msgkey )
	.escaped()
	.replace( /\$1/,
		mw.html.element( 'a', { id: 'foo' }, mw.msg( 'bar' ) )
	);

Which should become:

mw.message( msgkey )
	.rawParams(
		mw.html.element( 'a', { id: 'foo' }, mw.msg( 'bar' ) )
	);
	.escaped();

Version: 1.17.x
Severity: enhancement

Details

Reference
bz31260

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:49 PM
bzimport set Reference to bz31260.
bzimport added a subscriber: Unknown Object (MLST).
Krinkle created this task.Sep 29 2011, 11:49 PM
brion added a comment.Sep 30 2011, 6:29 PM

Yes, definitely makes sense to have closer interface parity, and it's an often handy thing. Added needs-unittest keyword as it'll want tests added to the qunit suite!

Main problem I see: if we return a *string* from .escaped() etc, then any parameters you've provided as DOM elements will need to be flattened back to HTML source on the output.

This is ok for simple cases, but if you want to do something like attach some data or behavior to an element (something that IIRC Neil's message parser for UploadWizard explicitly does) you could end up losing it.

(Event handlers etc would need to be re-added after the string gets turned back into DOM elements in the document, which is potentially awkward.)

It may be useful to have an output mode that produces a DOM element rather than HTML source.

aude added a comment.Jan 11 2013, 4:22 PM

I was looking for a way to do this today for Wikidata and hope for a solution soonish.

Note that inside JavaScript we don't really need an actual rawParams method. We just support passing jQuery or DOM objects into params.

matmarex renamed this task from Add support for rawParams to mw.message to Add support for rawParams to jqueryMsg.Dec 31 2014, 12:07 AM
matmarex set Security to None.
matmarex updated the task description. (Show Details)Oct 17 2018, 7:51 PM
matmarex closed this task as Declined.Oct 17 2018, 8:20 PM
matmarex claimed this task.
matmarex added subscribers: Catrope, matmarex.

Indeed, as @DanielFriesen says this is already possible (and @Catrope just fixed a bug that made it not work for some messages: rMW8d1844704ad6: jqueryMsg: Don't fall back to simple parser when jQuery params passed). I documented that you should pass jQuery/DOM objects to achieve this at https://www.mediawiki.org/wiki/Manual:Messages_API#Parameters_2.

matmarex added a subscriber: brion.Oct 17 2018, 8:21 PM

This is ok for simple cases, but if you want to do something like attach some data or behavior to an element (something that IIRC Neil's message parser for UploadWizard explicitly does) you could end up losing it.
(Event handlers etc would need to be re-added after the string gets turned back into DOM elements in the document, which is potentially awkward.)
It may be useful to have an output mode that produces a DOM element rather than HTML source.

I ran into the same problem and came to the same conclusion some years ago, and .parseDOM() was implemented in rMW652d4ded91ce: mediawiki.jqueryMsg: Extend mw.Message with new #parseDom method (MW 1.27).