r89895 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89894‎ | r89895 | r89896 >
Date:21:38, 11 June 2011
Author:foxtrott
Status:deferred (Comments)
Tags:
Comment:
* followup r89860: magic word renamed and internationalized
* fixes (magic word registration, loading css and js, return ParserOutput as error message)
Modified paths:
  • /trunk/extensions/Lingo/Lingo.i18n.php (modified) (history)
  • /trunk/extensions/Lingo/Lingo.php (modified) (history)
  • /trunk/extensions/Lingo/LingoHooks.php (modified) (history)
  • /trunk/extensions/Lingo/LingoMessageLog.php (modified) (history)
  • /trunk/extensions/Lingo/LingoParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Lingo/LingoHooks.php
@@ -18,21 +18,14 @@
1919 */
2020 class LingoHooks {
2121
22 - static function setup( &$parser ) {
23 - # Set a function hook associating the "noglossary" with fnLingoNoGlossary
24 - MagicWord::getDoubleUnderscoreArray()->add( 'nolingo' );
25 - return true;
26 - }
27 -
2822 static function setMagicWords( &$magicWords, $langCode ) {
29 - # Add the magic word
30 - $magicWords['nolingo'] = array( 0, '__nolingo__' );
 23+ $magicWords['noglossary'] = array( 0, '__NOGLOSSARY__', '__' . wfMsgGetKey( 'lingo-noglossary', true, $langCode ) . '__' );
3124 return true;
3225 }
3326
3427 static function parse( &$parser, &$text ) {
3528
36 - if ( !isset( $parser->mDoubleUnderscores['nolingo'] ) ) {
 29+ if ( !isset( $parser->mDoubleUnderscores['noglossary'] ) ) {
3730 LingoParser::parse( $parser, $text );
3831 }
3932
Index: trunk/extensions/Lingo/LingoMessageLog.php
@@ -75,9 +75,13 @@
7676 }
7777
7878 $ret = Html::rawElement( 'div', array('class' => 'messages'),
79 - $header .
80 - $parser->parse( $ret, $wgTitle, ParserOptions::newFromUser( $wgUser ) )->getText()
 79+ $header . "\n" .
 80+ $ret
8181 );
 82+
 83+ $ret = $parser->parse( $ret, $wgTitle, ParserOptions::newFromUser( $wgUser ) );
 84+ } else {
 85+ $ret = null;
8286 }
8387
8488 return $ret;
Index: trunk/extensions/Lingo/LingoParser.php
@@ -265,19 +265,20 @@
266266 }
267267
268268 protected function loadModules( &$parser ) {
269 - global $wgOut, $wgScriptPath;
 269+ global $wgOut, $wgScriptPath, $wgParser;
270270
271271 // load scripts
272272 if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
273 - if ( !is_null( $parser ) && ( $wgOut->isArticle() ) ) {
274 - $parser->getOutput()->addModules( 'ext.Lingo.Scripts' );
275 - } else {
 273+ $parser->getOutput()->addModules( 'ext.Lingo.Scripts' );
 274+ if ( !$wgOut->isArticle() ) {
276275 $wgOut->addModules( 'ext.Lingo.Scripts' );
277276 }
278277 } else {
279 - if ( !is_null( $parser ) && ( $wgOut->isArticle() ) ) {
280 - $parser->getOutput()->addHeadItem( "<script src='$wgScriptPath/extensions/Lingo/libs/Lingo.js'></script>\n", 'ext.Lingo.Scripts' );
281 - } else {
 278+ global $wgStylePath;
 279+ $parser->getOutput()->addHeadItem( "<script src='$wgStylePath/common/jquery.min.js'></script>\n", 'ext.Lingo.jq' );
 280+ $parser->getOutput()->addHeadItem( "<script src='$wgScriptPath/extensions/Lingo/libs/Lingo.js'></script>\n", 'ext.Lingo.Scripts' );
 281+ if ( !$wgOut->isArticle() ) {
 282+ $wgOut->addHeadItem( 'ext.Lingo.jq', "<script src='$wgStylePath/common/jquery.min.js'></script>\n" );
282283 $wgOut->addHeadItem( 'ext.Lingo.Scripts', "<script src='$wgScriptPath/extensions/Lingo/libs/Lingo.js'></script>\n" );
283284 }
284285 }
@@ -287,15 +288,13 @@
288289 // browsers. This doesn't make any sense for CSS-only modules that don't
289290 // need any JS. -> Use ResourceLoader if and when Bug 29308 gets fixed.
290291 // if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
291 -// if ( !is_null( $parser ) && ( $wgOut->isArticle() ) ) {
292 -// $parser->getOutput()->addModules( 'ext.Lingo.Styles' );
293 -// } else {
 292+// $parser->getOutput()->addModules( 'ext.Lingo.Styles' );
 293+// if ( !$wgOut->isArticle() ) {
294294 // $wgOut->addModules( 'ext.Lingo.Styles' );
295295 // }
296296 // } else {
297 - if ( !is_null( $parser ) && ( $wgOut->isArticle() ) ) {
298 - $parser->getOutput()->addHeadItem( "<link rel='stylesheet' href='$wgScriptPath/extensions/Lingo/skins/Lingo.css' />\n", 'ext.Lingo.Styles' );
299 - } else {
 297+ $parser->getOutput()->addHeadItem( "<link rel='stylesheet' href='$wgScriptPath/extensions/Lingo/skins/Lingo.css' />\n", 'ext.Lingo.Styles' );
 298+ if ( !$wgOut->isArticle() ) {
300299 $wgOut->addHeadItem( 'ext.Lingo.Styles', "<link rel='stylesheet' href='$wgScriptPath/extensions/Lingo/skins/Lingo.css' />\n" );
301300 }
302301 // }
Index: trunk/extensions/Lingo/Lingo.i18n.php
@@ -13,13 +13,14 @@
1414 'lingo-terminologypagename' => 'Terminology',
1515 'lingo-noterminologypage' => "Page '$1' does not exist.",
1616 'lingo-terminologypagenotlocal' => "Page '$1' is not a local page.",
17 -
 17+ 'lingo-noglossary' => 'NOGLOSSARY',
1818 );
1919
2020 /** Message documentation (Message documentation) */
2121 $messages['qqq'] = array(
2222 'lingo-desc' => '{{desc}}',
2323 'lingo-terminologypagename' => 'Name of the page where the terms and definitions of the glossary are stored',
 24+ 'lingo-noglossary' => 'The magic word which will suppress the application of the glossary for a page.',
2425 );
2526
2627 /** Belarusian (Taraškievica orthography) (‪Беларуская (тарашкевіца)‬)
@@ -41,6 +42,7 @@
4243 'lingo-terminologypagename' => 'Glossar',
4344 'lingo-noterminologypage' => 'Seite „$1“ ist nicht vorhanden.',
4445 'lingo-terminologypagenotlocal' => 'Seite „$1“ befindet sich nicht auf diesem Wiki.',
 46+ 'lingo-noglossary' => 'KEIN_GLOSSAR',
4547 );
4648
4749 /** French (Français)
Index: trunk/extensions/Lingo/Lingo.php
@@ -47,7 +47,7 @@
4848 // register hook handlers
4949 $wgHooks['SpecialVersionExtensionTypes'][] = 'LingoHooks::setCredits'; // set credits
5050 $wgHooks['ParserAfterTidy'][] = 'LingoHooks::parse'; // parse page
51 -$wgHooks['ParserFirstCallInit'][] = 'LingoHooks::setup'; // do late setup
 51+//$wgHooks['ParserFirstCallInit'][] = 'LingoHooks::setup'; // do late setup
5252 $wgHooks['LanguageGetMagic'][] = 'LingoHooks::setMagicWords'; // set magic words
5353
5454 // register resource modules with the Resource Loader
@@ -69,5 +69,7 @@
7070 // 'dependencies' => array( 'jquery.ui.datepicker' ),
7171 );
7272
 73+MagicWord::$mDoubleUnderscoreIDs[] = 'noglossary';
 74+
7375 unset( $dir );
7476

Follow-up revisions

RevisionCommit summaryAuthorDate
r89977* followup r89895: make magic words localisation look common...foxtrott16:26, 13 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89860new magic word nolingo, move hook handlers into separate file, fix some messagesfoxtrott23:16, 10 June 2011

Comments

#Comment by Raymond (talk | contribs)   19:07, 12 June 2011

This kind of magic words localisation looks very uncommon. The standard would be a separate Lingo.i18n.magic.php file (see ParserFunction).

#Comment by F.trott (talk | contribs)   20:57, 12 September 2011

This was fixed in r89977.

Status & tagging log