r82775 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82774‎ | r82775 | r82776 >
Date:01:11, 25 February 2011
Author:neilk
Status:deferred
Tags:
Comment:
make tests compatible with IE7
Modified paths:
  • /trunk/extensions/UploadWizard/resources/language/mw.Parser.js (modified) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html (modified) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/makeLanguageSpec.php (added) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.data.js (added) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js (modified) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.parser2.spec.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/test/jasmine/makeLanguageSpec.php
@@ -0,0 +1,113 @@
 2+<?php
 3+
 4+/**
 5+ * This PHP script defines the spec that the Javascript message parser should conform to.
 6+ *
 7+ * It does this by looking up the results of various string kinds of string parsing, with various languages,
 8+ * in the current installation of MediaWiki. It then outputs a static specification, mapping expected inputs to outputs,
 9+ * which can be used with the JasmineBDD framework. This specification can then be used by simply including it into
 10+ * the SpecRunner.html file.
 11+ *
 12+ * This is similar to Michael Dale (mdale@mediawiki.org)'s parser tests, except that it doesn't look up the
 13+ * API results while doing the test, so the Jasmine run is much faster (at the cost of being out of date in rare
 14+ * circumstances. But mostly the parsing that we are doing in Javascript doesn't change much.)
 15+ *
 16+ */
 17+
 18+$maintenanceDir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) . '/maintenance';
 19+
 20+require( "$maintenanceDir/Maintenance.php" );
 21+
 22+class MakeLanguageSpec extends Maintenance {
 23+
 24+ static $keyToTestArgs = array(
 25+ 'undelete_short' => array(
 26+ array( 0 ),
 27+ array( 1 ),
 28+ array( 2 ),
 29+ array( 5 ),
 30+ array( 21 ),
 31+ array( 101 )
 32+ ),
 33+ 'category-subcat-count' => array(
 34+ array( 0, 10 ),
 35+ array( 1, 1 ),
 36+ array( 1, 2 ),
 37+ array( 3, 30 )
 38+ )
 39+ );
 40+
 41+ public function __construct() {
 42+ parent::__construct();
 43+ $this->mDescription = "Create a JasmineBDD-compatible specification for message parsing";
 44+ // add any other options here
 45+ }
 46+
 47+ public function execute() {
 48+ list( $messages, $tests ) = $this->getMessagesAndTests();
 49+ $this->writeJavascriptFile( $messages, $tests, "spec/mediawiki.language.parser.spec.data.js" );
 50+ }
 51+
 52+ private function getMessagesAndTests() {
 53+ $messages = array();
 54+ $tests = array();
 55+ $wfMsgExtOptions = array( 'parsemag' );
 56+ foreach ( array( 'en', 'fr', 'ar', 'jp', 'zh' ) as $languageCode ) {
 57+ $wfMsgExtOptions['language'] = $languageCode;
 58+ foreach ( self::$keyToTestArgs as $key => $testArgs ) {
 59+ foreach ($testArgs as $args) {
 60+ // get the raw template, without any transformations
 61+ $template = wfMsgGetKey( $key, /* useDb */ true, $languageCode, /* transform */ false );
 62+
 63+ // get the magic-parsed version with args
 64+ $wfMsgExtArgs = array_merge( array( $key, $wfMsgExtOptions ), $args );
 65+ $result = call_user_func_array( 'wfMsgExt', $wfMsgExtArgs );
 66+
 67+ // record the template, args, language, and expected result
 68+ // fake multiple languages by flattening them together
 69+ $langKey = $languageCode . '_' . $key;
 70+ $messages[ $langKey ] = $template;
 71+ $tests[] = array(
 72+ 'name' => $languageCode . " " . $key . " " . join( ",", $args ),
 73+ 'key' => $langKey,
 74+ 'args' => $args,
 75+ 'result' => $result,
 76+ 'lang' => $languageCode
 77+ );
 78+ }
 79+ }
 80+ }
 81+ return array( $messages, $tests );
 82+ }
 83+
 84+ private function writeJavascriptFile( $messages, $tests, $dataSpecFile ) {
 85+ global $argv;
 86+ $arguments = count($argv) ? $argv : $_SERVER[ 'argv' ];
 87+
 88+ $json = new Services_JSON;
 89+ $json->pretty = true;
 90+ $javascriptPrologue = "// This file stores the results from the PHP parser for certain messages and arguments,\n"
 91+ . "// so we can test the equivalent Javascript libraries.\n"
 92+ . '// Last generated with ' . join(' ', $arguments) . ' at ' . gmdate('c') . "\n\n";
 93+ $javascriptMessages = "mediaWiki.messages.set( " . $json->encode( $messages, true ) . " );\n";
 94+ $javascriptTests = 'var jasmineMsgSpec = ' . $json->encode( $tests, true ) . ";\n";
 95+
 96+ $fp = fopen( $dataSpecFile, 'w' );
 97+ if ( !$fp ) {
 98+ die( "couldn't open $dataSpecFile for writing" );
 99+ }
 100+ $success = fwrite( $fp, $javascriptPrologue . $javascriptMessages . $javascriptTests );
 101+ if ( !$success ) {
 102+ die( "couldn't write to $dataSpecFile" );
 103+ }
 104+ $success = fclose( $fp );
 105+ if ( !$success ) {
 106+ die( "couldn't close $dataSpecFile" );
 107+ }
 108+ }
 109+}
 110+
 111+$maintClass = "MakeLanguageSpec";
 112+require_once( "$maintenanceDir/doMaintenance.php" );
 113+
 114+
Property changes on: trunk/extensions/UploadWizard/test/jasmine/makeLanguageSpec.php
___________________________________________________________________
Added: svn:eol-style
1115 + native
Added: svn:executable
2116 + *
Index: trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html
@@ -10,20 +10,25 @@
1111 <script type="text/javascript" src="/w/load.php?debug=true&lang=en&modules=jquery%7Cmediawiki&only=scripts&skin=vector"></script>
1212 <script type="text/javascript" src="lib/appendto-jquery-mockjax/jquery.mockjax.js"></script>
1313
14 - <script type="text/javascript" src="../../resources/mw.js"></script>
 14+ <script type="text/javascript" src="../../../../resources/mediawiki/mediawiki.js"></script>
 15+ <script type="text/javascript" src="../../../../resources/mediawiki.language/mediawiki.language.js"></script>
 16+ <script type="text/javascript" src="../../../../resources/mediawiki.language/mediawiki.language.parser.js"></script>
 17+ <script type="text/javascript" src="../../../../resources/jquery/jquery.mwMessage.js"></script>
1518 <script type="text/javascript" src="../../resources/mw.Utilities.js"></script>
1619 <script type="text/javascript" src="../../resources/mw.Uri.js"></script>
1720 <script type="text/javascript" src="../../resources/mw.Api.js"></script>
1821 <script type="text/javascript" src="../../resources/mw.Api.edit.js"></script>
19 - <script type="text/javascript" src="../../resources/language/mw.Language.js"></script>
20 - <script type="text/javascript" src="../../resources/language/mw.Parser.js"></script>
2122 <script type="text/javascript" src="../../resources/mw.Title.js"></script>
2223
2324 <!-- include spec files here... -->
2425 <script type="text/javascript" src="spec/mw.Uri.spec.js"></script>
2526 <script type="text/javascript" src="spec/mw.Api.spec.js"></script>
2627 <script type="text/javascript" src="spec/mw.Api.edit.spec.js"></script>
27 - <!-- script type="text/javascript" src="spec/mw.Language.spec.js"></script> -->
 28+
 29+ <script type="text/javascript" src="spec/mediawiki.language.parser.spec.data.js"></script>
 30+ <script type="text/javascript" src="spec/mediawiki.language.parser.spec.js"></script>
 31+
 32+ <script type="text/javascript" src="spec/jquery.mwMessage.spec.js"></script>
2833 <script type="text/javascript" src="spec/mw.Title.spec.js"></script>
2934
3035 </head>
Index: trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js
@@ -2,29 +2,30 @@
33
44 // boilerplate crap, can we eliminate this?
55
 6+/*
67 jQuery( document ).ready( function() {
78 // add "magic" to Language template parser for keywords
8 - mw.addTemplateTransform( { 'SITENAME' : function() { return wgSitename; } } );
 9+ // mediaWiki.language.parser.templateProcessors.SITENAME = function() { return wgSitename; };
910
1011 // sets up plural "magic" and so on. Seems like a bad design to have to do this, though.
11 - mw.Language.magicSetup();
 12+ // mediaWiki.language.magicSetup();
1213
1314 } );
 15+*/
1416
15 -
1617 /**
1718 * Tests
1819 */
19 -describe( "mw.Language", function() {
 20+describe( "mediaWiki.language.parser", function() {
2021
2122
2223 describe( "basic message functionality", function() {
23 - mw.addMessages( {
 24+ mediaWiki.messages.set( {
2425 'simple-message': 'simple message'
2526 } );
2627
2728 it( "should return identity for simple string", function() {
28 - expect( gM( 'simple-message' ) ).toEqual( 'simple message' );
 29+ expect( mediaWiki.msg( 'simple-message' ) ).toEqual( 'simple message' );
2930 } );
3031
3132 } );
@@ -34,16 +35,17 @@
3536 /**
3637 * Get a language transform key
3738 * returns default "en" fallback if none found
 39+ * @FIXME the resource loader should do this anyway, should not be necessary to know this client side
3840 * @param String langKey The language key to be checked
3941 */
40 - mw.Language.getLangTransformKey = function( langKey ) {
41 - if( mw.Language.fallbackTransformMap[ langKey ] ) {
42 - langKey = mw.Language.fallbackTransformMap[ langKey ];
 42+ mediaWiki.language.getLangTransformKey = function( langKey ) {
 43+ if( mediaWiki.language.fallbackTransformMap[ langKey ] ) {
 44+ langKey = mediaWiki.language.fallbackTransformMap[ langKey ];
4345 }
4446 // Make sure the langKey has a transformClass:
45 - for( var i = 0; i < mw.Language.transformClass.length ; i++ ) {
46 - if( langKey == mw.Language.transformClass[i] ){
47 - return langKey
 47+ for( var i = 0; i < mediaWiki.language.transformClass.length ; i++ ) {
 48+ if( langKey == mediaWiki.language.transformClass[i] ){
 49+ return langKey;
4850 }
4951 }
5052 // By default return the base 'en' class
@@ -55,7 +57,7 @@
5658 * so it keeps up-to-date with php maping.
5759 * ( not explicitly listed here )
5860 */
59 - mw.Language.fallbackTransformMap = {
 61+ mediaWiki.language.fallbackTransformMap = {
6062 'mwl' : 'pt',
6163 'ace' : 'id',
6264 'hsb' : 'de',
@@ -215,7 +217,7 @@
216218 * @@FIXME again not needed if the resource loader manages this mapping and gives
217219 * us the "right" transform class regardless of what language key we request.
218220 */
219 - mw.Language.transformClass = ['am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh',
 221+ mediaWiki.language.transformClass = ['am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh',
220222 'bs', 'cs', 'cu', 'cy', 'dsb', 'fr', 'ga', 'gd', 'gv', 'he', 'hi',
221223 'hr', 'hsb', 'hy', 'ksh', 'ln', 'lt', 'lv', 'mg', 'mk', 'mo', 'mt',
222224 'nso', 'pl', 'pt_br', 'ro', 'ru', 'se', 'sh', 'sk', 'sl', 'sma',
@@ -224,7 +226,7 @@
225227 // wgLang??
226228 var wgLanguageCode = 'en';
227229 // Set-up base convert plural and gender (to restore for non-transform languages )
228 - var cachedConvertPlural = { 'en' : mw.Language.convertPlural };
 230+ var cachedConvertPlural = { 'en' : mediaWiki.language.convertPlural };
229231
230232 // XXX THIS ONLY WORKS FOR NEIL
231233 var wgScriptPath = 'http://wiki.ivy.local/w';
@@ -234,17 +236,17 @@
235237 * @param {String} languageCode
236238 * @param {Function} to be executed when related scripts have loaded
237239 */
238 - mw.Language.resetForLang = function( lang, fn ) {
239 - mw.Language.digitTransformTable = null;
 240+ mediaWiki.language.resetForLang = function( lang, fn ) {
 241+ mediaWiki.language.digitTransformTable = null;
240242 // Load the current language js file if it has a langKey
241 - var lang = mw.Language.getLangTransformKey( lang );
 243+ var lang = mediaWiki.language.getLangTransformKey( lang );
242244 if( cachedConvertPlural[lang] ) {
243 - mw.Language.convertPlural = cachedConvertPlural[lang];
 245+ mediaWiki.language.convertPlural = cachedConvertPlural[lang];
244246 fn();
245247 } else {
246248 mw.log( lang + " load msg transform" );
247 - $j.getScript( wgScriptPath + '/resources/mediawiki.language/languages/' + lang.toLowerCase() + '.js' , function(){
248 - cachedConvertPlural[lang] = mw.Language.convertPlural;
 249+ $j.getScript( wgScriptPath + '/resources/mediaWiki.language/languages/' + lang.toLowerCase() + '.js' , function(){
 250+ cachedConvertPlural[lang] = mediaWiki.language.convertPlural;
249251 fn();
250252 });
251253 }
@@ -253,12 +255,10 @@
254256
255257 $j.each( jasmineMsgSpec, function( i, test ) {
256258 it( "should parse " + test.name, function() {
257 - mw.Language.resetForLang( test.lang, function() {
 259+ mediaWiki.language.resetForLang( test.lang, function() {
258260 var argArray = [ test.key ].concat( test.args );
259 - result = gM.apply( this, argArray );
260 - //if ( test.name == 'jp undelete_short 0' ) {
261 - // debugger;
262 - //}
 261+ var parsedText = mediaWiki.language.parser.apply( this, argArray );
 262+ result = parsedText.getHTML();
263263 expect( result ).toEqual( test.result );
264264 } );
265265 } );
Index: trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.parser2.spec.js
@@ -373,13 +373,29 @@
374374 it ( "should handle a simple link", function() {
375375 var parser = new mediaWiki.language.parser();
376376 var parsed = parser.parse( 'en_link' );
377 - expect( parsed.html() ).toEqual( 'Simple <a href="http://example.com">link to example</a>.' );
 377+ var contents = parsed.contents();
 378+ expect( contents.length ).toEqual( 3 );
 379+ expect( contents[0].nodeName ).toEqual( '#text' );
 380+ expect( contents[0].nodeValue ).toEqual( 'Simple ' );
 381+ expect( contents[1].nodeName ).toEqual( 'A' );
 382+ expect( contents[1].getAttribute( 'href' ) ).toEqual( 'http://example.com' );
 383+ expect( contents[1].childNodes[0].nodeValue ).toEqual( 'link to example' );
 384+ expect( contents[2].nodeName ).toEqual( '#text' );
 385+ expect( contents[2].nodeValue ).toEqual( '.' );
378386 } );
379387
380388 it ( "should replace a URL into a link", function() {
381389 var parser = new mediaWiki.language.parser();
382390 var parsed = parser.parse( 'en_link_replace', [ 'http://example.com/foo', 'linking' ] );
383 - expect( parsed.html() ).toEqual( 'Complex <a href="http://example.com/foo">linking</a> behaviour.' );
 391+ var contents = parsed.contents();
 392+ expect( contents.length ).toEqual( 3 );
 393+ expect( contents[0].nodeName ).toEqual( '#text' );
 394+ expect( contents[0].nodeValue ).toEqual( 'Complex ' );
 395+ expect( contents[1].nodeName ).toEqual( 'A' );
 396+ expect( contents[1].getAttribute( 'href' ) ).toEqual( 'http://example.com/foo' );
 397+ expect( contents[1].childNodes[0].nodeValue ).toEqual( 'linking' );
 398+ expect( contents[2].nodeName ).toEqual( '#text' );
 399+ expect( contents[2].nodeValue ).toEqual( ' behaviour.' );
384400 } );
385401
386402 it ( "should bind a click handler into a link", function() {
@@ -390,12 +406,12 @@
391407 var contents = parsed.contents();
392408 expect( contents.length ).toEqual( 3 );
393409 expect( contents[0].nodeName ).toEqual( '#text' );
394 - expect( contents[0].textContent ).toEqual( 'Complex ' );
 410+ expect( contents[0].nodeValue ).toEqual( 'Complex ' );
395411 expect( contents[1].nodeName ).toEqual( 'A' );
396412 expect( contents[1].getAttribute( 'href' ) ).toEqual( '#' );
397 - expect( contents[1].textContent ).toEqual( 'linking' );
 413+ expect( contents[1].childNodes[0].nodeValue ).toEqual( 'linking' );
398414 expect( contents[2].nodeName ).toEqual( '#text' );
399 - expect( contents[2].textContent ).toEqual( ' behaviour.' );
 415+ expect( contents[2].nodeValue ).toEqual( ' behaviour.' );
400416 // determining bindings is hard in IE
401417 var anchor = parsed.find( 'a' );
402418 if ( ( $j.browser.mozilla || $j.browser.webkit ) && anchor.click ) {
@@ -414,11 +430,11 @@
415431 var contents = parsed.contents();
416432 expect( contents.length ).toEqual( 3 );
417433 expect( contents[0].nodeName ).toEqual( '#text' );
418 - expect( contents[0].textContent ).toEqual( 'Complex ' );
 434+ expect( contents[0].nodeValue ).toEqual( 'Complex ' );
419435 expect( contents[1].nodeName ).toEqual( 'BUTTON' );
420 - expect( contents[1].textContent ).toEqual( 'buttoning' );
 436+ expect( contents[1].childNodes[0].nodeValue ).toEqual( 'buttoning' );
421437 expect( contents[2].nodeName ).toEqual( '#text' );
422 - expect( contents[2].textContent ).toEqual( ' behaviour.' );
 438+ expect( contents[2].nodeValue ).toEqual( ' behaviour.' );
423439 // determining bindings is hard in IE
424440 if ( ( $j.browser.mozilla || $j.browser.webkit ) && button.click ) {
425441 expect( clicked ).toEqual( false );
@@ -474,9 +490,12 @@
475491 describe( "easy message interface functions", function() {
476492 it( "should allow a global that returns strings", function() {
477493 var gM = mediaWiki.language.parser.getMessageFunction();
 494+ // passing this through jQuery and back to string, because browsers may have subtle differences, like the case of tag names.
 495+ // a surrounding <SPAN> is needed for html() to work right
 496+ var expectedHtml = $j( '<span>Complex <a href="http://example.com/foo">linking</a> behaviour.</span>' ).html();
478497 var result = gM( 'en_link_replace', 'http://example.com/foo', 'linking' );
479498 expect( typeof result ).toEqual( 'string' );
480 - expect( result ).toEqual( 'Complex <a href="http://example.com/foo">linking</a> behaviour.' );
 499+ expect( result ).toEqual( expectedHtml );
481500 } );
482501
483502 it( "should allow a jQuery plugin that appends to nodes", function() {
@@ -485,11 +504,18 @@
486505 var clicked = false;
487506 var $button = $j( '<button>' ).click( function() { clicked = true; } );
488507 $div.find( '.foo' ).msg( 'en_link_replace', $button, 'buttoning' );
489 - expect( $div.find( '.foo' ).html() ).toEqual( 'Complex <button>buttoning</button> behaviour.' );
 508+ // passing this through jQuery and back to string, because browsers may have subtle differences, like the case of tag names.
 509+ // a surrounding <SPAN> is needed for html() to work right
 510+ var expectedHtml = $j( '<span>Complex <button>buttoning</button> behaviour.</span>' ).html();
 511+ var createdHtml = $div.find( '.foo' ).html();
 512+ // it is hard to test for clicks with IE; also it inserts or removes spaces around nodes when creating HTML tags, depending on their type.
 513+ // so need to check the strings stripped of spaces.
490514 if ( ( $j.browser.mozilla || $j.browser.webkit ) && $button.click ) {
491 - expect( clicked ).toEqual( false );
 515+ expect( createdHtml ).toEqual( expectedHtml );
492516 $div.find( 'button ').click();
493517 expect( clicked ).toEqual( true );
 518+ } else if ( $j.browser.ie ) {
 519+ expect( createdHtml.replace( /\s/, '' ) ).toEqual( expectedHtml.replace( /\s/, '' ) );
494520 }
495521 delete $j.fn.msg;
496522 } );
Index: trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.data.js
@@ -0,0 +1,488 @@
 2+// This file stores the results from the PHP parser for certain messages and arguments,
 3+// so we can test the equivalent Javascript libraries.
 4+// Last generated with makeLanguageSpec.php at 2011-01-28T02:04:09+00:00
 5+
 6+mediaWiki.messages.set( {
 7+ "en_undelete_short": "Undelete {{PLURAL:$1|one edit|$1 edits}}",
 8+ "en_category-subcat-count": "{{PLURAL:$2|This category has only the following subcategory.|This category has the following {{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}",
 9+ "fr_undelete_short": "Restaurer $1 modification{{PLURAL:$1||s}}",
 10+ "fr_category-subcat-count": "Cette cat\u00e9gorie comprend {{PLURAL:$2|la sous-cat\u00e9gorie|$2 sous-cat\u00e9gories, dont {{PLURAL:$1|celle|les $1}}}} ci-dessous.",
 11+ "ar_undelete_short": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 {{PLURAL:$1|\u062a\u0639\u062f\u064a\u0644 \u0648\u0627\u062d\u062f|\u062a\u0639\u062f\u064a\u0644\u064a\u0646|$1 \u062a\u0639\u062f\u064a\u0644\u0627\u062a|$1 \u062a\u0639\u062f\u064a\u0644|$1 \u062a\u0639\u062f\u064a\u0644\u0627}}",
 12+ "ar_category-subcat-count": "{{PLURAL:$2|\u0644\u0627 \u062a\u0635\u0627\u0646\u064a\u0641 \u0641\u0631\u0639\u064a\u0629 \u0641\u064a \u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641|\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a \u0627\u0644\u062a\u0627\u0644\u064a \u0641\u0642\u0637.|\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 {{PLURAL:$1||\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a|\u0647\u0630\u064a\u0646 \u0627\u0644\u062a\u0635\u0646\u064a\u0641\u064a\u0646 \u0627\u0644\u0641\u0631\u0639\u064a\u064a\u0646|\u0647\u0630\u0647 \u0627\u0644$1 \u062a\u0635\u0627\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a\u0629|\u0647\u0630\u0647 \u0627\u0644$1 \u062a\u0635\u0646\u064a\u0641\u0627 \u0641\u0631\u0639\u064a\u0627|\u0647\u0630\u0647 \u0627\u0644$1 \u062a\u0635\u0646\u064a\u0641 \u0641\u0631\u0639\u064a}}\u060c \u0645\u0646 \u0625\u062c\u0645\u0627\u0644\u064a $2.}}",
 13+ "jp_undelete_short": "Undelete {{PLURAL:$1|one edit|$1 edits}}",
 14+ "jp_category-subcat-count": "{{PLURAL:$2|This category has only the following subcategory.|This category has the following {{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}",
 15+ "zh_undelete_short": "\u6062\u590d\u88ab\u5220\u9664\u7684$1\u9879\u4fee\u8ba2",
 16+ "zh_category-subcat-count": "{{PLURAL:$2|\u672c\u5206\u7c7b\u53ea\u6709\u4e0b\u5217\u4e00\u4e2a\u5b50\u5206\u7c7b\u3002|\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u5217$1\u4e2a\u5b50\u5206\u7c7b\uff0c\u5171\u6709$2\u4e2a\u5b50\u5206\u7c7b\u3002}}"
 17+} );
 18+var jasmineMsgSpec = [
 19+ {
 20+ "name": "en undelete_short 0",
 21+ "key": "en_undelete_short",
 22+ "args": [
 23+ 0
 24+ ],
 25+ "result": "Undelete 0 edits",
 26+ "lang": "en"
 27+ },
 28+ {
 29+ "name": "en undelete_short 1",
 30+ "key": "en_undelete_short",
 31+ "args": [
 32+ 1
 33+ ],
 34+ "result": "Undelete one edit",
 35+ "lang": "en"
 36+ },
 37+ {
 38+ "name": "en undelete_short 2",
 39+ "key": "en_undelete_short",
 40+ "args": [
 41+ 2
 42+ ],
 43+ "result": "Undelete 2 edits",
 44+ "lang": "en"
 45+ },
 46+ {
 47+ "name": "en undelete_short 5",
 48+ "key": "en_undelete_short",
 49+ "args": [
 50+ 5
 51+ ],
 52+ "result": "Undelete 5 edits",
 53+ "lang": "en"
 54+ },
 55+ {
 56+ "name": "en undelete_short 21",
 57+ "key": "en_undelete_short",
 58+ "args": [
 59+ 21
 60+ ],
 61+ "result": "Undelete 21 edits",
 62+ "lang": "en"
 63+ },
 64+ {
 65+ "name": "en undelete_short 101",
 66+ "key": "en_undelete_short",
 67+ "args": [
 68+ 101
 69+ ],
 70+ "result": "Undelete 101 edits",
 71+ "lang": "en"
 72+ },
 73+ {
 74+ "name": "en category-subcat-count 0,10",
 75+ "key": "en_category-subcat-count",
 76+ "args": [
 77+ 0,
 78+ 10
 79+ ],
 80+ "result": "This category has the following 0 subcategories, out of 10 total.",
 81+ "lang": "en"
 82+ },
 83+ {
 84+ "name": "en category-subcat-count 1,1",
 85+ "key": "en_category-subcat-count",
 86+ "args": [
 87+ 1,
 88+ 1
 89+ ],
 90+ "result": "This category has only the following subcategory.",
 91+ "lang": "en"
 92+ },
 93+ {
 94+ "name": "en category-subcat-count 1,2",
 95+ "key": "en_category-subcat-count",
 96+ "args": [
 97+ 1,
 98+ 2
 99+ ],
 100+ "result": "This category has the following subcategory, out of 2 total.",
 101+ "lang": "en"
 102+ },
 103+ {
 104+ "name": "en category-subcat-count 3,30",
 105+ "key": "en_category-subcat-count",
 106+ "args": [
 107+ 3,
 108+ 30
 109+ ],
 110+ "result": "This category has the following 3 subcategories, out of 30 total.",
 111+ "lang": "en"
 112+ },
 113+ {
 114+ "name": "fr undelete_short 0",
 115+ "key": "fr_undelete_short",
 116+ "args": [
 117+ 0
 118+ ],
 119+ "result": "Restaurer 0 modification",
 120+ "lang": "fr"
 121+ },
 122+ {
 123+ "name": "fr undelete_short 1",
 124+ "key": "fr_undelete_short",
 125+ "args": [
 126+ 1
 127+ ],
 128+ "result": "Restaurer 1 modification",
 129+ "lang": "fr"
 130+ },
 131+ {
 132+ "name": "fr undelete_short 2",
 133+ "key": "fr_undelete_short",
 134+ "args": [
 135+ 2
 136+ ],
 137+ "result": "Restaurer 2 modifications",
 138+ "lang": "fr"
 139+ },
 140+ {
 141+ "name": "fr undelete_short 5",
 142+ "key": "fr_undelete_short",
 143+ "args": [
 144+ 5
 145+ ],
 146+ "result": "Restaurer 5 modifications",
 147+ "lang": "fr"
 148+ },
 149+ {
 150+ "name": "fr undelete_short 21",
 151+ "key": "fr_undelete_short",
 152+ "args": [
 153+ 21
 154+ ],
 155+ "result": "Restaurer 21 modifications",
 156+ "lang": "fr"
 157+ },
 158+ {
 159+ "name": "fr undelete_short 101",
 160+ "key": "fr_undelete_short",
 161+ "args": [
 162+ 101
 163+ ],
 164+ "result": "Restaurer 101 modifications",
 165+ "lang": "fr"
 166+ },
 167+ {
 168+ "name": "fr category-subcat-count 0,10",
 169+ "key": "fr_category-subcat-count",
 170+ "args": [
 171+ 0,
 172+ 10
 173+ ],
 174+ "result": "Cette cat\u00e9gorie comprend 10 sous-cat\u00e9gories, dont celle ci-dessous.",
 175+ "lang": "fr"
 176+ },
 177+ {
 178+ "name": "fr category-subcat-count 1,1",
 179+ "key": "fr_category-subcat-count",
 180+ "args": [
 181+ 1,
 182+ 1
 183+ ],
 184+ "result": "Cette cat\u00e9gorie comprend la sous-cat\u00e9gorie ci-dessous.",
 185+ "lang": "fr"
 186+ },
 187+ {
 188+ "name": "fr category-subcat-count 1,2",
 189+ "key": "fr_category-subcat-count",
 190+ "args": [
 191+ 1,
 192+ 2
 193+ ],
 194+ "result": "Cette cat\u00e9gorie comprend 2 sous-cat\u00e9gories, dont celle ci-dessous.",
 195+ "lang": "fr"
 196+ },
 197+ {
 198+ "name": "fr category-subcat-count 3,30",
 199+ "key": "fr_category-subcat-count",
 200+ "args": [
 201+ 3,
 202+ 30
 203+ ],
 204+ "result": "Cette cat\u00e9gorie comprend 30 sous-cat\u00e9gories, dont les 3 ci-dessous.",
 205+ "lang": "fr"
 206+ },
 207+ {
 208+ "name": "ar undelete_short 0",
 209+ "key": "ar_undelete_short",
 210+ "args": [
 211+ 0
 212+ ],
 213+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 \u062a\u0639\u062f\u064a\u0644 \u0648\u0627\u062d\u062f",
 214+ "lang": "ar"
 215+ },
 216+ {
 217+ "name": "ar undelete_short 1",
 218+ "key": "ar_undelete_short",
 219+ "args": [
 220+ 1
 221+ ],
 222+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 \u062a\u0639\u062f\u064a\u0644\u064a\u0646",
 223+ "lang": "ar"
 224+ },
 225+ {
 226+ "name": "ar undelete_short 2",
 227+ "key": "ar_undelete_short",
 228+ "args": [
 229+ 2
 230+ ],
 231+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 2 \u062a\u0639\u062f\u064a\u0644\u0627\u062a",
 232+ "lang": "ar"
 233+ },
 234+ {
 235+ "name": "ar undelete_short 5",
 236+ "key": "ar_undelete_short",
 237+ "args": [
 238+ 5
 239+ ],
 240+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 5 \u062a\u0639\u062f\u064a\u0644",
 241+ "lang": "ar"
 242+ },
 243+ {
 244+ "name": "ar undelete_short 21",
 245+ "key": "ar_undelete_short",
 246+ "args": [
 247+ 21
 248+ ],
 249+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 21 \u062a\u0639\u062f\u064a\u0644\u0627",
 250+ "lang": "ar"
 251+ },
 252+ {
 253+ "name": "ar undelete_short 101",
 254+ "key": "ar_undelete_short",
 255+ "args": [
 256+ 101
 257+ ],
 258+ "result": "\u0627\u0633\u062a\u0631\u062c\u0627\u0639 101 \u062a\u0639\u062f\u064a\u0644\u0627",
 259+ "lang": "ar"
 260+ },
 261+ {
 262+ "name": "ar category-subcat-count 0,10",
 263+ "key": "ar_category-subcat-count",
 264+ "args": [
 265+ 0,
 266+ 10
 267+ ],
 268+ "result": "\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u060c \u0645\u0646 \u0625\u062c\u0645\u0627\u0644\u064a 10.",
 269+ "lang": "ar"
 270+ },
 271+ {
 272+ "name": "ar category-subcat-count 1,1",
 273+ "key": "ar_category-subcat-count",
 274+ "args": [
 275+ 1,
 276+ 1
 277+ ],
 278+ "result": "\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a \u0627\u0644\u062a\u0627\u0644\u064a \u0641\u0642\u0637.",
 279+ "lang": "ar"
 280+ },
 281+ {
 282+ "name": "ar category-subcat-count 1,2",
 283+ "key": "ar_category-subcat-count",
 284+ "args": [
 285+ 1,
 286+ 2
 287+ ],
 288+ "result": "\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a\u060c \u0645\u0646 \u0625\u062c\u0645\u0627\u0644\u064a 2.",
 289+ "lang": "ar"
 290+ },
 291+ {
 292+ "name": "ar category-subcat-count 3,30",
 293+ "key": "ar_category-subcat-count",
 294+ "args": [
 295+ 3,
 296+ 30
 297+ ],
 298+ "result": "\u0647\u0630\u0627 \u0627\u0644\u062a\u0635\u0646\u064a\u0641 \u0641\u064a\u0647 \u0647\u0630\u0647 \u0627\u06443 \u062a\u0635\u0627\u0646\u064a\u0641 \u0627\u0644\u0641\u0631\u0639\u064a\u0629\u060c \u0645\u0646 \u0625\u062c\u0645\u0627\u0644\u064a 30.",
 299+ "lang": "ar"
 300+ },
 301+ {
 302+ "name": "jp undelete_short 0",
 303+ "key": "jp_undelete_short",
 304+ "args": [
 305+ 0
 306+ ],
 307+ "result": "Undelete 0 edits",
 308+ "lang": "jp"
 309+ },
 310+ {
 311+ "name": "jp undelete_short 1",
 312+ "key": "jp_undelete_short",
 313+ "args": [
 314+ 1
 315+ ],
 316+ "result": "Undelete one edit",
 317+ "lang": "jp"
 318+ },
 319+ {
 320+ "name": "jp undelete_short 2",
 321+ "key": "jp_undelete_short",
 322+ "args": [
 323+ 2
 324+ ],
 325+ "result": "Undelete 2 edits",
 326+ "lang": "jp"
 327+ },
 328+ {
 329+ "name": "jp undelete_short 5",
 330+ "key": "jp_undelete_short",
 331+ "args": [
 332+ 5
 333+ ],
 334+ "result": "Undelete 5 edits",
 335+ "lang": "jp"
 336+ },
 337+ {
 338+ "name": "jp undelete_short 21",
 339+ "key": "jp_undelete_short",
 340+ "args": [
 341+ 21
 342+ ],
 343+ "result": "Undelete 21 edits",
 344+ "lang": "jp"
 345+ },
 346+ {
 347+ "name": "jp undelete_short 101",
 348+ "key": "jp_undelete_short",
 349+ "args": [
 350+ 101
 351+ ],
 352+ "result": "Undelete 101 edits",
 353+ "lang": "jp"
 354+ },
 355+ {
 356+ "name": "jp category-subcat-count 0,10",
 357+ "key": "jp_category-subcat-count",
 358+ "args": [
 359+ 0,
 360+ 10
 361+ ],
 362+ "result": "This category has the following 0 subcategories, out of 10 total.",
 363+ "lang": "jp"
 364+ },
 365+ {
 366+ "name": "jp category-subcat-count 1,1",
 367+ "key": "jp_category-subcat-count",
 368+ "args": [
 369+ 1,
 370+ 1
 371+ ],
 372+ "result": "This category has only the following subcategory.",
 373+ "lang": "jp"
 374+ },
 375+ {
 376+ "name": "jp category-subcat-count 1,2",
 377+ "key": "jp_category-subcat-count",
 378+ "args": [
 379+ 1,
 380+ 2
 381+ ],
 382+ "result": "This category has the following subcategory, out of 2 total.",
 383+ "lang": "jp"
 384+ },
 385+ {
 386+ "name": "jp category-subcat-count 3,30",
 387+ "key": "jp_category-subcat-count",
 388+ "args": [
 389+ 3,
 390+ 30
 391+ ],
 392+ "result": "This category has the following 3 subcategories, out of 30 total.",
 393+ "lang": "jp"
 394+ },
 395+ {
 396+ "name": "zh undelete_short 0",
 397+ "key": "zh_undelete_short",
 398+ "args": [
 399+ 0
 400+ ],
 401+ "result": "\u6062\u590d\u88ab\u5220\u9664\u76840\u9879\u4fee\u8ba2",
 402+ "lang": "zh"
 403+ },
 404+ {
 405+ "name": "zh undelete_short 1",
 406+ "key": "zh_undelete_short",
 407+ "args": [
 408+ 1
 409+ ],
 410+ "result": "\u6062\u590d\u88ab\u5220\u9664\u76841\u9879\u4fee\u8ba2",
 411+ "lang": "zh"
 412+ },
 413+ {
 414+ "name": "zh undelete_short 2",
 415+ "key": "zh_undelete_short",
 416+ "args": [
 417+ 2
 418+ ],
 419+ "result": "\u6062\u590d\u88ab\u5220\u9664\u76842\u9879\u4fee\u8ba2",
 420+ "lang": "zh"
 421+ },
 422+ {
 423+ "name": "zh undelete_short 5",
 424+ "key": "zh_undelete_short",
 425+ "args": [
 426+ 5
 427+ ],
 428+ "result": "\u6062\u590d\u88ab\u5220\u9664\u76845\u9879\u4fee\u8ba2",
 429+ "lang": "zh"
 430+ },
 431+ {
 432+ "name": "zh undelete_short 21",
 433+ "key": "zh_undelete_short",
 434+ "args": [
 435+ 21
 436+ ],
 437+ "result": "\u6062\u590d\u88ab\u5220\u9664\u768421\u9879\u4fee\u8ba2",
 438+ "lang": "zh"
 439+ },
 440+ {
 441+ "name": "zh undelete_short 101",
 442+ "key": "zh_undelete_short",
 443+ "args": [
 444+ 101
 445+ ],
 446+ "result": "\u6062\u590d\u88ab\u5220\u9664\u7684101\u9879\u4fee\u8ba2",
 447+ "lang": "zh"
 448+ },
 449+ {
 450+ "name": "zh category-subcat-count 0,10",
 451+ "key": "zh_category-subcat-count",
 452+ "args": [
 453+ 0,
 454+ 10
 455+ ],
 456+ "result": "\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u52170\u4e2a\u5b50\u5206\u7c7b\uff0c\u5171\u670910\u4e2a\u5b50\u5206\u7c7b\u3002",
 457+ "lang": "zh"
 458+ },
 459+ {
 460+ "name": "zh category-subcat-count 1,1",
 461+ "key": "zh_category-subcat-count",
 462+ "args": [
 463+ 1,
 464+ 1
 465+ ],
 466+ "result": "\u672c\u5206\u7c7b\u53ea\u6709\u4e0b\u5217\u4e00\u4e2a\u5b50\u5206\u7c7b\u3002",
 467+ "lang": "zh"
 468+ },
 469+ {
 470+ "name": "zh category-subcat-count 1,2",
 471+ "key": "zh_category-subcat-count",
 472+ "args": [
 473+ 1,
 474+ 2
 475+ ],
 476+ "result": "\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u52171\u4e2a\u5b50\u5206\u7c7b\uff0c\u5171\u67092\u4e2a\u5b50\u5206\u7c7b\u3002",
 477+ "lang": "zh"
 478+ },
 479+ {
 480+ "name": "zh category-subcat-count 3,30",
 481+ "key": "zh_category-subcat-count",
 482+ "args": [
 483+ 3,
 484+ 30
 485+ ],
 486+ "result": "\u672c\u5206\u7c7b\u5305\u542b\u4e0b\u52173\u4e2a\u5b50\u5206\u7c7b\uff0c\u5171\u670930\u4e2a\u5b50\u5206\u7c7b\u3002",
 487+ "lang": "zh"
 488+ }
 489+];
Property changes on: trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.data.js
___________________________________________________________________
Added: svn:eol-style
1490 + native
Index: trunk/extensions/UploadWizard/resources/language/mw.Parser.js
@@ -3,73 +3,96 @@
44 */
55
66 // Setup swap string constants
7 -var JQUERY_SWAP_STRING = 'ZjQuerySwapZ';
 7+var JQUERY_SWAP_STRING = 'ZjQuerySwapZ';
88 var LINK_SWAP_STRING = 'ZreplaceZ';
9 -
 9+
1010 ( function( mw ) {
11 -
12 - // The parser magic global
 11+
 12+ // The parser magic global
1313 var pMagicSet = { };
14 -
 14+
1515 /**
16 - * addTemplateTransform to the parser
 16+ * addTemplateTransform to the parser
1717 *
1818 * Lets you add a set template key to be transformed by a callback function
1919 *
2020 * @param {Object} magicSet key:callback
2121 */
2222 mw.addTemplateTransform = function( magicSet ) {
23 - for ( var name in magicSet ) {
24 - pMagicSet[name] = magicSet[name];
 23+ for ( var i in magicSet ) {
 24+ pMagicSet[ i ] = magicSet[i];
2525 }
2626 };
2727
2828 /**
29 - * MediaWiki wikitext "Parser" constructor
 29+ * MediaWiki wikitext "Parser" constructor
3030 *
3131 * @param {String} wikiText the wikitext to be parsed
3232 * @return {Object} parserObj returns a parser object that has methods for getting at
3333 * things you would want
34 - */
 34+ */
3535 mw.Parser = function( wikiText, options) {
3636 // return the parserObj
37 - this.init( wikiText, options ) ;
 37+ this.init( wikiText, options ) ;
 38+ return this;
3839 };
39 -
 40+
4041 mw.Parser.prototype = {
41 -
 42+
4243 // the parser output string container
4344 pOut: false,
44 -
 45+
4546 init: function( wikiText, parserOptions ) {
46 - this.wikiText = wikiText;
47 - },
48 -
 47+ this.wikiText = wikiText;
 48+
 49+ var defaultParserOptions = {
 50+ 'templateParCount' : 2
 51+ };
 52+
 53+ this.options = $j.extend( defaultParserOptions, parserOptions);
 54+ },
 55+
4956 // Update the text value
5057 updateText : function( wikiText ) {
5158 this.wikiText = wikiText;
52 -
 59+
5360 // invalidate the output ( will force a re-parse )
5461 this.pOut = false;
5562 },
56 -
 63+ // checks if the required number of parenthesis are found
 64+ // xxx this is just a stop gap solution
 65+ checkParlookAheadOpen: function(text, a){
 66+ if( this.options.templateParCount == 2 ){
 67+ return ( text[a] == '{' && text[a + 1] == '{' );
 68+ } else if( this.options.templateParCount == 3 ) {
 69+ return ( text[a] == '{' && text[a + 1] == '{' && text[a + 2] == '{');
 70+ }
 71+ },
 72+ checkParlookAheadClose: function( text, a){
 73+ if( this.options.templateParCount == 2 ){
 74+ return ( text[a] == '}' && text[a + 1] == '}' );
 75+ } else if( this.options.templateParCount == 3 ) {
 76+ return ( text[a] == '}' && text[a + 1] == '}' && text[a + 2] == '}');
 77+ }
 78+ },
5779 /**
58 - * Quickly recursive / parse out templates:
 80+ * Quickly recursive / parse out templates:
5981 */
6082 parse: function() {
 83+ var _this = this;
6184 function recurseTokenizeNodes ( text ) {
6285 var node = { };
6386 // Inspect each char
6487 for ( var a = 0; a < text.length; a++ ) {
65 - if ( text[a] == '{' && text[a + 1] == '{' ) {
66 - a = a + 2;
 88+ if ( _this.checkParlookAheadOpen( text, a ) ) {
 89+ a = a + _this.options.templateParCount;
6790 node['parent'] = node;
6891 if ( !node['child'] ) {
6992 node['child'] = new Array();
7093 }
7194
7295 node['child'].push( recurseTokenizeNodes( text.substr( a ) ) );
73 - } else if ( text[a] == '}' && text[a + 1] == '}' ) {
 96+ } else if ( _this.checkParlookAheadClose( text, a ) ) {
7497 a++;
7598 if ( !node['parent'] ) {
7699 return node;
@@ -80,20 +103,20 @@
81104 node['text'] = '';
82105 }
83106 // Don't put }} closures into output:
84 - if ( text[a] && text[a] != '}' ) {
 107+ if ( text[a] && text[a] != '}' ) {
85108 node['text'] += text[a];
86109 }
87110 }
88111 return node;
89112 }
90 -
 113+
91114 /**
92115 * Parse template text as template name and named params
93 - * @param {String} templateString Template String to be parsed
 116+ * @param {String} templateString Template String to be parsed
94117 */
95118 function parseTmplTxt( templateString ) {
96119 var templateObject = { };
97 -
 120+
98121 // Get template name:
99122 templateName = templateString.split( '\|' ).shift() ;
100123 templateName = templateName.split( '\{' ).shift() ;
@@ -106,15 +129,15 @@
107130 templateObject["name"] = templateName.split( ':' ).shift();
108131 templateObject["arg"] = templateName.split( ':' ).pop();
109132 }
110 -
 133+
111134 var paramSet = templateString.split( '\|' );
112135 paramSet.splice( 0, 1 );
113136 if ( paramSet.length ) {
114137 templateObject.param = new Array();
115 - for ( var pInx = 0; pInx < paramSet.length; pInx++ ) {
 138+ for ( var pInx =0; pInx < paramSet.length; pInx++ ) {
116139 var paramString = paramSet[ pInx ];
117140 // check for empty param
118 - if ( paramString === '' ) {
 141+ if ( paramString == '' ) {
119142 templateObject.param[ pInx ] = '';
120143 continue;
121144 }
@@ -128,10 +151,10 @@
129152 }
130153 }
131154 }
132 - }
 155+ }
133156 return templateObject;
134157 }
135 -
 158+
136159 /**
137160 * Get the Magic text from a template node
138161 */
@@ -146,58 +169,58 @@
147170 return node.text;
148171 }
149172 }
150 -
 173+
151174 /**
152175 * swap links of form [ ] for html a links or jquery helper spans
153176 * NOTE: this could be integrated into the tokenizer but for now
154177 * is a staged process.
155178 *
156 - * @param text to swapped
 179+ * @param text to swapped
157180 */
158181 function linkSwapText( text ) {
159182 //mw.log( "linkSwapText::" + text );
160183 var re = new RegExp( /\[([^\s]+[\s]+[^\]]*)\]/g );
161184 var matchSet = text.match( re );
162 -
 185+
163186 if( !matchSet ){
164187 return text;
165 - }
 188+ }
166189
167 - text = text.replace( re , LINK_SWAP_STRING );
168 -
 190+ text = text.replace( re , LINK_SWAP_STRING );
 191+
169192 for( var i=0; i < matchSet.length; i++ ) {
170193 // Strip the leading [ and trailing ]
171194 var matchParts = matchSet[i].substr(1, matchSet[i].length-2);
172 -
173 - // Check for special jQuery type swap and replace inner JQUERY_SWAP_STRING not value
174 - if( matchParts.indexOf( JQUERY_SWAP_STRING ) !== -1 ) {
175 - // parse the link as html
176 - var $matchParts = $j('<span>' + matchParts + '</span>' );
177 -
 195+
 196+ // Check for special jQuery type swap and replace inner JQUERY_SWAP_STRING not value
 197+ if( matchParts.indexOf( JQUERY_SWAP_STRING ) !== -1 ) {
 198+ // parse the link as html
 199+ var $matchParts = $j('<span>' + matchParts + '</span>' );
 200+
178201 $jQuerySpan = $matchParts.find('#' +JQUERY_SWAP_STRING + i );
179 -
 202+
180203 var linkText = $matchParts.text();
181204 //mw.log(" going to swap in linktext: " + linkText );
182205 $jQuerySpan.text( linkText );
183 -
 206+
184207 text = text.replace( LINK_SWAP_STRING, $j('<span />' ).append( $jQuerySpan ).html() );
185 - } else {
186 - // do text string replace
187 - matchParts = matchParts.split(/ /);
188 - var link = matchParts[0];
189 - matchParts.shift();
190 - var linkText = matchParts.join(' ');
191 -
192 - text = text.replace( LINK_SWAP_STRING, '<a href="' + link + '">' + linkText + '</a>' );
 208+ } else {
 209+ // do text string replace
 210+ matchParts = matchParts.split(/ /);
 211+ var link = matchParts[0];
 212+ matchParts.shift();
 213+ var linkText = matchParts.join(' ');
 214+
 215+ text = text.replace( LINK_SWAP_STRING, '<a href="' + link + '">' + linkText + '</a>' );
193216 }
194217 }
195218 return text;
196219 }
197 -
 220+
198221 /**
199222 * recurse_magic_swap
200223 *
201 - * Go last child first swap upward:
 224+ * Go last child first swap upward:
202225 */
203226 var pNode = null;
204227 function recurse_magic_swap( node ) {
@@ -206,41 +229,41 @@
207230
208231 if ( node['child'] ) {
209232 // swap all the kids:
210 - for ( var i = 0; i < node['child'].length; i++ ) {
 233+ for ( var i in node['child'] ) {
211234 var nodeText = recurse_magic_swap( node['child'][i] );
212235 // swap it into current
213236 if ( node.text ) {
214237 node.text = node.text.replace( node['child'][i].text, nodeText );
215238 }
216239 // swap into parent
217 - pNode.text = pNode.text.replace( node['child'][i].text, nodeText );
 240+ pNode.text = pNode.text.replace( node['child'][i].text, nodeText );
218241 }
219242 // Get the updated node text
220243 var nodeText = getMagicTxtFromTempNode( node );
221244 pNode.text = pNode.text.replace( node.text , nodeText );
222245 // return the node text
223246 return node.text;
224 - } else {
 247+ } else {
225248 return getMagicTxtFromTempNode( node );
226249 }
227250 }
228 -
 251+
229252 // Parse out the template node structure:
230253 this.pNode = recurseTokenizeNodes ( this.wikiText );
231 -
232 - // Strip out the parent from the root
 254+
 255+ // Strip out the parent from the root
233256 this.pNode['parent'] = null;
234 -
 257+
235258 // Do the recursive magic swap text:
236259 this.pOut = recurse_magic_swap( this.pNode );
237 -
238 - // Do link swap
239 - this.pOut = linkSwapText( this.pOut );
 260+
 261+ // Do link swap
 262+ this.pOut = linkSwapText( this.pOut );
240263 },
241 -
 264+
242265 /**
243266 * templates
244 - *
 267+ *
245268 * Get a requested template from the wikitext (if available)
246269 * @param templateName
247270 */
@@ -249,7 +272,7 @@
250273 var tmplSet = new Array();
251274 function getMatchingTmpl( node ) {
252275 if ( node['child'] ) {
253 - for ( var i = 0; i < node['child'].length; i++ ) {
 276+ for ( var i in node['child'] ) {
254277 getMatchingTmpl( node['child'] );
255278 }
256279 }
@@ -263,53 +286,53 @@
264287 getMatchingTmpl( this.pNode );
265288 return tmplSet;
266289 },
267 -
 290+
268291 /**
269292 * getTemplateVars
270293 * returns a set of template values in a given wikitext page
271 - *
 294+ *
272295 * NOTE: should be integrated with the usability wikitext parser
273296 */
274297 getTemplateVars: function() {
275298 //mw.log('matching against: ' + wikiText);
276299 templateVars = new Array();
277300 var tempVars = wikiText.match(/\{\{\{([^\}]*)\}\}\}/gi);
278 -
 301+
279302 // Clean up results:
280303 for(var i=0; i < tempVars.length; i++) {
281 - //match
 304+ //match
282305 var tvar = tempVars[i].replace('{{{','').replace('}}}','');
283 -
 306+
284307 // Strip anything after a |
285308 if(tvar.indexOf('|') != -1) {
286309 tvar = tvar.substr(0, tvar.indexOf('|'));
287310 }
288 -
 311+
289312 // Check for duplicates:
290313 var do_add=true;
291314 for(var j=0; j < templateVars.length; j++) {
292315 if( templateVars[j] == tvar)
293316 do_add=false;
294317 }
295 -
 318+
296319 // Add the template vars to the output obj
297320 if(do_add)
298321 templateVars.push( tvar );
299322 }
300323 return templateVars;
301324 },
302 -
 325+
303326 /**
304327 * Returns the transformed wikitext
305 - *
306 - * Build output from swappable index
307 - * (all transforms must be expanded in parse stage and linearly rebuilt)
308 - * Alternatively we could build output using a place-holder & replace system
 328+ *
 329+ * Build output from swappable index
 330+ * (all transforms must be expanded in parse stage and linearly rebuilt)
 331+ * Alternatively we could build output using a place-holder & replace system
309332 * (this lets us be slightly more sloppy with ordering and indexes, but probably slower)
310 - *
311 - * Ideal: we build a 'wiki DOM'
 333+ *
 334+ * Ideal: we build a 'wiki DOM'
312335 * When editing you update the data structure directly
313 - * Then in output time you just go DOM->html-ish output without re-parsing anything
 336+ * Then in output time you just go DOM->html-ish output without re-parsing anything
314337 */
315338 getHTML: function() {
316339 // wikiText updates should invalidate pOut
@@ -319,5 +342,5 @@
320343 return this.pOut;
321344 }
322345 };
323 -
324 -}) ( window.mediaWiki );
 346+
 347+}) ( window.mw );
\ No newline at end of file

Status & tagging log