I took a little time last week and wrapped Neik K's parserPlus library into an extension. It implements a nice framework for grabbing localized message strings, with limited but very useful PEG-based wikitext parsing, all on the client-side. This is code that's been in use in UploadWizard for some time now, but the extension makes it available to other projects as well.
tl;dr: 1. Enable the extension, it makes two functions available in your JS. 2. string example: $( '.status' ).append( gM( 'mwe-upwiz-file-all-ok' ) ); 3. chainable jQuery example: $( '.status' ).msg( 'mwe-upwiz-file-all-ok' ); 4. It does lots more stuff, check the docs.
Why does this exist? In Neil's own words:
"In the course of writing UploadWizard, I started to rely on MwEmbed's message library, which had limited wikitext parsing. This was a great help to internationalization, and the PLURAL support was nice.
"MwEmbed was ultimately not accepted for integration into MediaWiki, so the ResourceLoader framework was invented to replace that. But we had little or no support for wikitext-parsed messages. Simple replacements were handled, but not complicated or nested parsing.
"Michael Dale and NeilK (that's me) wrote another class (MwMessage.js) to supply the needed features and some advanced ideas like dropping jQuery nodes right into message strings. But I felt that it was still a bit too hacky and had some annoying flaws. For every message, you needed to instantiate another parser. Also, parameters like $1 were replaced before the message was actually parsed, leading to some unnecessary convolutions and code repetition for the advanced jQuery-oriented features that Michael was exploiting heavily."
It's pretty cool. I can imagine this functionality being pulled into Core at some point, but for the moment the extension provides a low-impact way for the rest of us to take advantage of it. When it does get incorporated into core, code changes required in extensions should be very minimal.
Read more: http://www.mediawiki.org/wiki/Extension:JQueryMsg
-Ian
Awesome! Thanks for this :)
Svn links in article are broken.
Sent from my Android phone.
On Wed, Aug 17, 2011 at 2:35 PM, Ian Baker ian@wikimedia.org wrote:
- string example: $( '.status' ).append( gM( 'mwe-upwiz-file-all-ok' ) );
This is mostly awesome. To nitpick: I'm not a huge fan of the name gM().
It's pretty cool. I can imagine this functionality being pulled into Core at some point, but for the moment the extension provides a low-impact way for the rest of us to take advantage of it. When it does get incorporated into core, code changes required in extensions should be very minimal.
It should go into core sooner rather than later :)
-Chad
On 08/17/2011 07:56 PM, Chad wrote:
It should go into core sooner rather than later :)
Yes I also vote it goes into core as well. I have it a copy in my MwEmbed extension as well supporting TimedMediaHandler along with a few other upload wizard / mwEmbed utilities that have been making their way into core .. like mediawiki.Uri
The sooner they make it into core the less complex it is to deploy these various shared extensions dependences and the extension does not need to keep copies around to be compatible with trunk and old versions of mediaWiki.
For all intensive purposes "core" is our package manager for these cross extension dependencies.
--michael
On 8/17/11 5:56 PM, Chad wrote:
It should go into core sooner rather than later :)
Yeah, I was blocking on it for all the reasons you guys mention.
There are some bugs in it where it will do surprising things if you have HTML tags surrounding wikitext. This is fairly frequent so I always wanted to go back and fix that, haven't got enough round tuits as it will involve redoing the parser a bit. Also, we're missing GRAMMAR and GENDER support and this is important for a lot of languages.
But Ian is the kind of guy who figures out ways to have good progress today rather than waiting for perfection tomorrow. Which I very much appreciate.
This is awesome. Thanks for "extensionizing" Neil's parser lib :-)
Alolita
On Aug 17, 2011, at 11:35 AM, Ian Baker ian@wikimedia.org wrote:
I took a little time last week and wrapped Neik K's parserPlus library into an extension. It implements a nice framework for grabbing localized message strings, with limited but very useful PEG-based wikitext parsing, all on the client-side. This is code that's been in use in UploadWizard for some time now, but the extension makes it available to other projects as well.
tl;dr:
- Enable the extension, it makes two functions available in your JS.
- string example: $( '.status' ).append( gM( 'mwe-upwiz-file-all-ok' ) );
- chainable jQuery example: $( '.status' ).msg( 'mwe-upwiz-file-all-ok' );
- It does lots more stuff, check the docs.
Why does this exist? In Neil's own words:
"In the course of writing UploadWizard, I started to rely on MwEmbed's message library, which had limited wikitext parsing. This was a great help to internationalization, and the PLURAL support was nice.
"MwEmbed was ultimately not accepted for integration into MediaWiki, so the ResourceLoader framework was invented to replace that. But we had little or no support for wikitext-parsed messages. Simple replacements were handled, but not complicated or nested parsing.
"Michael Dale and NeilK (that's me) wrote another class (MwMessage.js) to supply the needed features and some advanced ideas like dropping jQuery nodes right into message strings. But I felt that it was still a bit too hacky and had some annoying flaws. For every message, you needed to instantiate another parser. Also, parameters like $1 were replaced before the message was actually parsed, leading to some unnecessary convolutions and code repetition for the advanced jQuery-oriented features that Michael was exploiting heavily."
It's pretty cool. I can imagine this functionality being pulled into Core at some point, but for the moment the extension provides a low-impact way for the rest of us to take advantage of it. When it does get incorporated into core, code changes required in extensions should be very minimal.
Read more: http://www.mediawiki.org/wiki/Extension:JQueryMsg
-Ian _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
wikitech-l@lists.wikimedia.org