r111930 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111929‎ | r111930 | r111931 >
Date:14:04, 20 February 2012
Author:nikerabbit
Status:ok
Tags:i18nreview 
Comment:
A little bit more clear way to write inline javascript
Modified paths:
  • /branches/jsgrammar/includes/resourceloader/ResourceLoaderLanguageModule.php (modified) (history)

Diff [purge]

Index: branches/jsgrammar/includes/resourceloader/ResourceLoaderLanguageModule.php
@@ -36,19 +36,23 @@
3737 }
3838 /**
3939 * @param $context ResourceLoaderContext
40 - * @return string
 40+ * @return string Javascript code
4141 */
4242 public function getScript( ResourceLoaderContext $context ) {
4343 global $wgContLang;
 44+ $code = Xml::encodeJsVar( $wgContLang->getCode() );
 45+ $forms = Xml::encodeJsVar( $this->getSiteLangGrammarForms() );
 46+
4447 $js =
45 - 'var langCode = ' . FormatJson::encode( $wgContLang->getCode() ) . ', ' .
46 - "langData = mw.language.data;\n" .
47 - "if ( langData[langCode] === undefined ) {\n" .
48 - " langData[langCode] = new mw.Map();\n" .
49 - "}\n" .
50 - Xml::encodeJsCall( 'langData[langCode].set',
51 - array( 'grammarForms', $this->getSiteLangGrammarForms( ) )
52 - );
 48+<<<JAVASCRIPT
 49+var langCode = $code,
 50+langData = mw.language.data;
 51+if ( langData[langCode] === undefined ) {
 52+ langData[langCode] = new mw.Map();
 53+}
 54+langData[langCode].set( "grammarForms", $forms );
 55+JAVASCRIPT;
 56+
5357 return $js;
5458 }
5559 /**

Status & tagging log