Merge "Fix CLI installer when --dbname is not specified on command line."
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.jqueryMsg.test.js
1 ( function ( mw, $ ) {
2 var formatText, formatParse, formatnumTests, specialCharactersPageName, expectedListUsers,
3 expectedListUsersSitename, expectedEntrypoints,
4 mwLanguageCache = {},
5 hasOwn = Object.hasOwnProperty;
6
7 // When the expected result is the same in both modes
8 function assertBothModes( assert, parserArguments, expectedResult, assertMessage ) {
9 assert.equal( formatText.apply( null, parserArguments ), expectedResult, assertMessage + ' when format is \'text\'' );
10 assert.equal( formatParse.apply( null, parserArguments ), expectedResult, assertMessage + ' when format is \'parse\'' );
11 }
12
13 QUnit.module( 'mediawiki.jqueryMsg', QUnit.newMwEnvironment( {
14 setup: function () {
15 this.originalMwLanguage = mw.language;
16 this.parserDefaults = mw.jqueryMsg.getParserDefaults();
17 mw.jqueryMsg.setParserDefaults( {
18 magic: {
19 SITENAME: 'Wiki'
20 }
21 } );
22
23 specialCharactersPageName = '"Who" wants to be a millionaire & live on \'Exotic Island\'?';
24
25 expectedListUsers = '注册<a title="Special:ListUsers" href="/wiki/Special:ListUsers">用户</a>';
26 expectedListUsersSitename = '注册<a title="Special:ListUsers" href="/wiki/Special:ListUsers">用户' +
27 'Wiki</a>';
28
29 expectedEntrypoints = '<a href="https://www.mediawiki.org/wiki/Manual:index.php">index.php</a>';
30
31 formatText = mw.jqueryMsg.getMessageFunction( {
32 format: 'text'
33 } );
34
35 formatParse = mw.jqueryMsg.getMessageFunction( {
36 format: 'parse'
37 } );
38 },
39 teardown: function () {
40 mw.language = this.originalMwLanguage;
41 mw.jqueryMsg.setParserDefaults( this.parserDefaults );
42 },
43 config: {
44 wgArticlePath: '/wiki/$1',
45 // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
46 wgNamespaceIds: {
47 template: 10,
48 template_talk: 11,
49 // Localised
50 szablon: 10,
51 dyskusja_szablonu: 11
52 },
53 // jscs:enable requireCamelCaseOrUpperCaseIdentifiers
54 wgFormattedNamespaces: {
55 // Localised
56 10: 'Szablon',
57 11: 'Dyskusja szablonu'
58 }
59 },
60 // Messages that are reused in multiple tests
61 messages: {
62 // The values for gender are not significant,
63 // what matters is which of the values is choosen by the parser
64 'gender-msg': '$1: {{GENDER:$2|blue|pink|green}}',
65 'gender-msg-currentuser': '{{GENDER:|blue|pink|green}}',
66
67 'plural-msg': 'Found $1 {{PLURAL:$1|item|items}}',
68 // See https://phabricator.wikimedia.org/T71993
69 'plural-msg-explicit-forms-nested': 'Found {{PLURAL:$1|$1 results|0=no results in {{SITENAME}}|1=$1 result}}',
70 // Assume the grammar form grammar_case_foo is not valid in any language
71 'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
72
73 'formatnum-msg': '{{formatnum:$1}}',
74
75 'portal-url': 'Project:Community portal',
76 'see-portal-url': '{{Int:portal-url}} is an important community page.',
77
78 'jquerymsg-test-statistics-users': '注册[[Special:ListUsers|用户]]',
79 'jquerymsg-test-statistics-users-sitename': '注册[[Special:ListUsers|用户{{SITENAME}}]]',
80
81 'jquerymsg-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
82
83 'external-link-replace': 'Foo [$1 bar]',
84 'external-link-plural': 'Foo {{PLURAL:$1|is [$2 one]|are [$2 some]|2=[$2 two]|3=three|4=a=b|5=}} things.',
85 'plural-only-explicit-forms': 'It is a {{PLURAL:$1|1=single|2=double}} room.'
86 }
87 } ) );
88
89 /**
90 * Be careful to no run this in parallel as it uses a global identifier (mw.language)
91 * to transport the module back to the test. It musn't be overwritten concurrentely.
92 *
93 * This function caches the mw.language data to avoid having to request the same module
94 * multiple times. There is more than one test case for any given language.
95 */
96 function getMwLanguage( langCode ) {
97 if ( !hasOwn.call( mwLanguageCache, langCode ) ) {
98 mwLanguageCache[ langCode ] = $.ajax( {
99 url: mw.util.wikiScript( 'load' ),
100 data: {
101 skin: mw.config.get( 'skin' ),
102 lang: langCode,
103 debug: mw.config.get( 'debug' ),
104 modules: [
105 'mediawiki.language.data',
106 'mediawiki.language'
107 ].join( '|' ),
108 only: 'scripts'
109 },
110 dataType: 'script',
111 cache: true
112 } ).then( function () {
113 return mw.language;
114 } );
115 }
116 return mwLanguageCache[ langCode ];
117 }
118
119 /**
120 * @param {Function[]} tasks List of functions that perform tasks
121 * that may be asynchronous. Invoke the callback parameter when done.
122 * @param {Function} complete Called when all tasks are done, or when the sequence is aborted.
123 */
124 function process( tasks, complete ) {
125 /*jshint latedef:false */
126 function abort() {
127 tasks.splice( 0, tasks.length );
128 next();
129 }
130 function next() {
131 if ( !tasks ) {
132 // This happens if after the process is completed, one of our callbacks is
133 // invoked. This can happen if a test timed out but the process was still
134 // running. In that case, ignore it. Don't invoke complete() a second time.
135 return;
136 }
137 var task = tasks.shift();
138 if ( task ) {
139 task( next, abort );
140 } else {
141 // Remove tasks list to indicate the process is final.
142 tasks = null;
143 complete();
144 }
145 }
146 next();
147 }
148
149 QUnit.test( 'Replace', 16, function ( assert ) {
150 mw.messages.set( 'simple', 'Foo $1 baz $2' );
151
152 assert.equal( formatParse( 'simple' ), 'Foo $1 baz $2', 'Replacements with no substitutes' );
153 assert.equal( formatParse( 'simple', 'bar' ), 'Foo bar baz $2', 'Replacements with less substitutes' );
154 assert.equal( formatParse( 'simple', 'bar', 'quux' ), 'Foo bar baz quux', 'Replacements with all substitutes' );
155
156 mw.messages.set( 'plain-input', '<foo foo="foo">x$1y&lt;</foo>z' );
157
158 assert.equal(
159 formatParse( 'plain-input', 'bar' ),
160 '&lt;foo foo="foo"&gt;xbary&amp;lt;&lt;/foo&gt;z',
161 'Input is not considered html'
162 );
163
164 mw.messages.set( 'plain-replace', 'Foo $1' );
165
166 assert.equal(
167 formatParse( 'plain-replace', '<bar bar="bar">&gt;</bar>' ),
168 'Foo &lt;bar bar="bar"&gt;&amp;gt;&lt;/bar&gt;',
169 'Replacement is not considered html'
170 );
171
172 mw.messages.set( 'object-replace', 'Foo $1' );
173
174 assert.equal(
175 formatParse( 'object-replace', $( '<div class="bar">&gt;</div>' ) ),
176 'Foo <div class="bar">&gt;</div>',
177 'jQuery objects are preserved as raw html'
178 );
179
180 assert.equal(
181 formatParse( 'object-replace', $( '<div class="bar">&gt;</div>' ).get( 0 ) ),
182 'Foo <div class="bar">&gt;</div>',
183 'HTMLElement objects are preserved as raw html'
184 );
185
186 assert.equal(
187 formatParse( 'object-replace', $( '<div class="bar">&gt;</div>' ).toArray() ),
188 'Foo <div class="bar">&gt;</div>',
189 'HTMLElement[] arrays are preserved as raw html'
190 );
191
192 assert.equal(
193 formatParse( 'external-link-replace', 'http://example.org/?x=y&z' ),
194 'Foo <a href="http://example.org/?x=y&amp;z">bar</a>',
195 'Href is not double-escaped in wikilink function'
196 );
197 assert.equal(
198 formatParse( 'external-link-plural', 1, 'http://example.org' ),
199 'Foo is <a href="http://example.org">one</a> things.',
200 'Link is expanded inside plural and is not escaped html'
201 );
202 assert.equal(
203 formatParse( 'external-link-plural', 2, 'http://example.org' ),
204 'Foo <a href=\"http://example.org\">two</a> things.',
205 'Link is expanded inside an explicit plural form and is not escaped html'
206 );
207 assert.equal(
208 formatParse( 'external-link-plural', 3 ),
209 'Foo three things.',
210 'A simple explicit plural form co-existing with complex explicit plural forms'
211 );
212 assert.equal(
213 formatParse( 'external-link-plural', 4, 'http://example.org' ),
214 'Foo a=b things.',
215 'Only first equal sign is used as delimiter for explicit plural form. Repeated equal signs does not create issue'
216 );
217 assert.equal(
218 formatParse( 'external-link-plural', 5, 'http://example.org' ),
219 'Foo are <a href="http://example.org">some</a> things.',
220 'Invalid explicit plural form. Plural fallback to the "other" plural form'
221 );
222 assert.equal(
223 formatParse( 'external-link-plural', 6, 'http://example.org' ),
224 'Foo are <a href="http://example.org">some</a> things.',
225 'Plural fallback to the "other" plural form'
226 );
227 assert.equal(
228 formatParse( 'plural-only-explicit-forms', 2 ),
229 'It is a double room.',
230 'Plural with explicit forms alone.'
231 );
232 } );
233
234 QUnit.test( 'Plural', 6, function ( assert ) {
235 assert.equal( formatParse( 'plural-msg', 0 ), 'Found 0 items', 'Plural test for english with zero as count' );
236 assert.equal( formatParse( 'plural-msg', 1 ), 'Found 1 item', 'Singular test for english' );
237 assert.equal( formatParse( 'plural-msg', 2 ), 'Found 2 items', 'Plural test for english' );
238 assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 6 ), 'Found 6 results', 'Plural message with explicit plural forms' );
239 assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 0 ), 'Found no results in Wiki', 'Plural message with explicit plural forms, with nested {{SITENAME}}' );
240 assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 1 ), 'Found 1 result', 'Plural message with explicit plural forms with placeholder nested' );
241 } );
242
243 QUnit.test( 'Gender', 15, function ( assert ) {
244 var originalGender = mw.user.options.get( 'gender' );
245
246 // TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg
247 // TODO: English may not be the best language for these tests. Use a language like Arabic or Russian
248 mw.user.options.set( 'gender', 'male' );
249 assert.equal(
250 formatParse( 'gender-msg', 'Bob', 'male' ),
251 'Bob: blue',
252 'Masculine from string "male"'
253 );
254 assert.equal(
255 formatParse( 'gender-msg', 'Bob', mw.user ),
256 'Bob: blue',
257 'Masculine from mw.user object'
258 );
259 assert.equal(
260 formatParse( 'gender-msg-currentuser' ),
261 'blue',
262 'Masculine for current user'
263 );
264
265 mw.user.options.set( 'gender', 'female' );
266 assert.equal(
267 formatParse( 'gender-msg', 'Alice', 'female' ),
268 'Alice: pink',
269 'Feminine from string "female"' );
270 assert.equal(
271 formatParse( 'gender-msg', 'Alice', mw.user ),
272 'Alice: pink',
273 'Feminine from mw.user object'
274 );
275 assert.equal(
276 formatParse( 'gender-msg-currentuser' ),
277 'pink',
278 'Feminine for current user'
279 );
280
281 mw.user.options.set( 'gender', 'unknown' );
282 assert.equal(
283 formatParse( 'gender-msg', 'Foo', mw.user ),
284 'Foo: green',
285 'Neutral from mw.user object' );
286 assert.equal(
287 formatParse( 'gender-msg', 'User' ),
288 'User: green',
289 'Neutral when no parameter given' );
290 assert.equal(
291 formatParse( 'gender-msg', 'User', 'unknown' ),
292 'User: green',
293 'Neutral from string "unknown"'
294 );
295 assert.equal(
296 formatParse( 'gender-msg-currentuser' ),
297 'green',
298 'Neutral for current user'
299 );
300
301 mw.messages.set( 'gender-msg-one-form', '{{GENDER:$1|User}}: $2 {{PLURAL:$2|edit|edits}}' );
302
303 assert.equal(
304 formatParse( 'gender-msg-one-form', 'male', 10 ),
305 'User: 10 edits',
306 'Gender neutral and plural form'
307 );
308 assert.equal(
309 formatParse( 'gender-msg-one-form', 'female', 1 ),
310 'User: 1 edit',
311 'Gender neutral and singular form'
312 );
313
314 mw.messages.set( 'gender-msg-lowercase', '{{gender:$1|he|she}} is awesome' );
315 assert.equal(
316 formatParse( 'gender-msg-lowercase', 'male' ),
317 'he is awesome',
318 'Gender masculine'
319 );
320 assert.equal(
321 formatParse( 'gender-msg-lowercase', 'female' ),
322 'she is awesome',
323 'Gender feminine'
324 );
325
326 mw.messages.set( 'gender-msg-wrong', '{{gender}} test' );
327 assert.equal(
328 formatParse( 'gender-msg-wrong', 'female' ),
329 ' test',
330 'Invalid syntax should result in {{gender}} simply being stripped away'
331 );
332
333 mw.user.options.set( 'gender', originalGender );
334 } );
335
336 QUnit.test( 'Case changing', 8, function ( assert ) {
337 mw.messages.set( 'to-lowercase', '{{lc:thIS hAS MEsSed uP CapItaliZatiON}}' );
338 assert.equal( formatParse( 'to-lowercase' ), 'this has messed up capitalization', 'To lowercase' );
339
340 mw.messages.set( 'to-caps', '{{uc:thIS hAS MEsSed uP CapItaliZatiON}}' );
341 assert.equal( formatParse( 'to-caps' ), 'THIS HAS MESSED UP CAPITALIZATION', 'To caps' );
342
343 mw.messages.set( 'uc-to-lcfirst', '{{lcfirst:THis hAS MEsSed uP CapItaliZatiON}}' );
344 mw.messages.set( 'lc-to-lcfirst', '{{lcfirst:thIS hAS MEsSed uP CapItaliZatiON}}' );
345 assert.equal( formatParse( 'uc-to-lcfirst' ), 'tHis hAS MEsSed uP CapItaliZatiON', 'Lcfirst caps' );
346 assert.equal( formatParse( 'lc-to-lcfirst' ), 'thIS hAS MEsSed uP CapItaliZatiON', 'Lcfirst lowercase' );
347
348 mw.messages.set( 'uc-to-ucfirst', '{{ucfirst:THis hAS MEsSed uP CapItaliZatiON}}' );
349 mw.messages.set( 'lc-to-ucfirst', '{{ucfirst:thIS hAS MEsSed uP CapItaliZatiON}}' );
350 assert.equal( formatParse( 'uc-to-ucfirst' ), 'THis hAS MEsSed uP CapItaliZatiON', 'Ucfirst caps' );
351 assert.equal( formatParse( 'lc-to-ucfirst' ), 'ThIS hAS MEsSed uP CapItaliZatiON', 'Ucfirst lowercase' );
352
353 mw.messages.set( 'mixed-to-sentence', '{{ucfirst:{{lc:thIS hAS MEsSed uP CapItaliZatiON}}}}' );
354 assert.equal( formatParse( 'mixed-to-sentence' ), 'This has messed up capitalization', 'To sentence case' );
355 mw.messages.set( 'all-caps-except-first', '{{lcfirst:{{uc:thIS hAS MEsSed uP CapItaliZatiON}}}}' );
356 assert.equal( formatParse( 'all-caps-except-first' ), 'tHIS HAS MESSED UP CAPITALIZATION', 'To opposite sentence case' );
357 } );
358
359 QUnit.test( 'Grammar', 2, function ( assert ) {
360 assert.equal( formatParse( 'grammar-msg' ), 'Przeszukaj Wiki', 'Grammar Test with sitename' );
361
362 mw.messages.set( 'grammar-msg-wrong-syntax', 'Przeszukaj {{GRAMMAR:grammar_case_xyz}}' );
363 assert.equal( formatParse( 'grammar-msg-wrong-syntax' ), 'Przeszukaj ', 'Grammar Test with wrong grammar template syntax' );
364 } );
365
366 QUnit.test( 'Match PHP parser', mw.libs.phpParserData.tests.length, function ( assert ) {
367 mw.messages.set( mw.libs.phpParserData.messages );
368 var tasks = $.map( mw.libs.phpParserData.tests, function ( test ) {
369 return function ( next, abort ) {
370 getMwLanguage( test.lang )
371 .then( function ( langClass ) {
372 mw.config.set( 'wgUserLanguage', test.lang );
373 var parser = new mw.jqueryMsg.parser( { language: langClass } );
374 assert.equal(
375 parser.parse( test.key, test.args ).html(),
376 test.result,
377 test.name
378 );
379 }, function () {
380 assert.ok( false, 'Language "' + test.lang + '" failed to load.' );
381 } )
382 .then( next, abort );
383 };
384 } );
385
386 QUnit.stop();
387 process( tasks, QUnit.start );
388 } );
389
390 QUnit.test( 'Links', 14, function ( assert ) {
391 var testCases,
392 expectedDisambiguationsText,
393 expectedMultipleBars,
394 expectedSpecialCharacters;
395
396 // The below three are all identical to or based on real messages. For disambiguations-text,
397 // the bold was removed because it is not yet implemented.
398
399 assert.htmlEqual(
400 formatParse( 'jquerymsg-test-statistics-users' ),
401 expectedListUsers,
402 'Piped wikilink'
403 );
404
405 expectedDisambiguationsText = 'The following pages contain at least one link to a disambiguation page.\nThey may have to link to a more appropriate page instead.\nA page is treated as a disambiguation page if it uses a template that is linked from ' +
406 '<a title="MediaWiki:Disambiguationspage" href="/wiki/MediaWiki:Disambiguationspage">MediaWiki:Disambiguationspage</a>.';
407
408 mw.messages.set( 'disambiguations-text', 'The following pages contain at least one link to a disambiguation page.\nThey may have to link to a more appropriate page instead.\nA page is treated as a disambiguation page if it uses a template that is linked from [[MediaWiki:Disambiguationspage]].' );
409 assert.htmlEqual(
410 formatParse( 'disambiguations-text' ),
411 expectedDisambiguationsText,
412 'Wikilink without pipe'
413 );
414
415 assert.htmlEqual(
416 formatParse( 'jquerymsg-test-version-entrypoints-index-php' ),
417 expectedEntrypoints,
418 'External link'
419 );
420
421 // Pipe trick is not supported currently, but should not parse as text either.
422 mw.messages.set( 'pipe-trick', '[[Tampa, Florida|]]' );
423 mw.messages.set( 'reverse-pipe-trick', '[[|Tampa, Florida]]' );
424 mw.messages.set( 'empty-link', '[[]]' );
425 this.suppressWarnings();
426 assert.equal(
427 formatParse( 'pipe-trick' ),
428 '[[Tampa, Florida|]]',
429 'Pipe trick should not be parsed.'
430 );
431 assert.equal(
432 formatParse( 'reverse-pipe-trick' ),
433 '[[|Tampa, Florida]]',
434 'Reverse pipe trick should not be parsed.'
435 );
436 assert.equal(
437 formatParse( 'empty-link' ),
438 '[[]]',
439 'Empty link should not be parsed.'
440 );
441 this.restoreWarnings();
442
443 expectedMultipleBars = '<a title="Main Page" href="/wiki/Main_Page">Main|Page</a>';
444 mw.messages.set( 'multiple-bars', '[[Main Page|Main|Page]]' );
445 assert.htmlEqual(
446 formatParse( 'multiple-bars' ),
447 expectedMultipleBars,
448 'Bar in anchor'
449 );
450
451 expectedSpecialCharacters = '<a title="&quot;Who&quot; wants to be a millionaire &amp; live on &#039;Exotic Island&#039;?" href="/wiki/%22Who%22_wants_to_be_a_millionaire_%26_live_on_%27Exotic_Island%27%3F">&quot;Who&quot; wants to be a millionaire &amp; live on &#039;Exotic Island&#039;?</a>';
452
453 mw.messages.set( 'special-characters', '[[' + specialCharactersPageName + ']]' );
454 assert.htmlEqual(
455 formatParse( 'special-characters' ),
456 expectedSpecialCharacters,
457 'Special characters'
458 );
459
460 mw.messages.set( 'leading-colon', '[[:File:Foo.jpg]]' );
461 assert.htmlEqual(
462 formatParse( 'leading-colon' ),
463 '<a title="File:Foo.jpg" href="/wiki/File:Foo.jpg">File:Foo.jpg</a>',
464 'Leading colon in links is stripped'
465 );
466
467 assert.htmlEqual(
468 formatParse( 'jquerymsg-test-statistics-users-sitename' ),
469 expectedListUsersSitename,
470 'Piped wikilink with parser function in the text'
471 );
472
473 testCases = [
474 [
475 'extlink-html-full',
476 'asd [http://example.org <strong>Example</strong>] asd',
477 'asd <a href="http://example.org"><strong>Example</strong></a> asd'
478 ],
479 [
480 'extlink-html-partial',
481 'asd [http://example.org foo <strong>Example</strong> bar] asd',
482 'asd <a href="http://example.org">foo <strong>Example</strong> bar</a> asd'
483 ],
484 [
485 'wikilink-html-full',
486 'asd [[Example|<strong>Example</strong>]] asd',
487 'asd <a title="Example" href="/wiki/Example"><strong>Example</strong></a> asd'
488 ],
489 [
490 'wikilink-html-partial',
491 'asd [[Example|foo <strong>Example</strong> bar]] asd',
492 'asd <a title="Example" href="/wiki/Example">foo <strong>Example</strong> bar</a> asd'
493 ]
494 ];
495
496 $.each( testCases, function () {
497 var
498 key = this[ 0 ],
499 input = this[ 1 ],
500 output = this[ 2 ];
501 mw.messages.set( key, input );
502 assert.htmlEqual(
503 formatParse( key ),
504 output,
505 'HTML in links: ' + key
506 );
507 } );
508 } );
509
510 QUnit.test( 'Replacements in links', 14, function ( assert ) {
511 var testCases = [
512 [
513 'extlink-param-href-full',
514 'asd [$1 Example] asd',
515 'asd <a href="http://example.com">Example</a> asd'
516 ],
517 [
518 'extlink-param-href-partial',
519 'asd [$1/example Example] asd',
520 'asd <a href="http://example.com/example">Example</a> asd'
521 ],
522 [
523 'extlink-param-text-full',
524 'asd [http://example.org $2] asd',
525 'asd <a href="http://example.org">Text</a> asd'
526 ],
527 [
528 'extlink-param-text-partial',
529 'asd [http://example.org Example $2] asd',
530 'asd <a href="http://example.org">Example Text</a> asd'
531 ],
532 [
533 'extlink-param-both-full',
534 'asd [$1 $2] asd',
535 'asd <a href="http://example.com">Text</a> asd'
536 ],
537 [
538 'extlink-param-both-partial',
539 'asd [$1/example Example $2] asd',
540 'asd <a href="http://example.com/example">Example Text</a> asd'
541 ],
542 [
543 'wikilink-param-href-full',
544 'asd [[$1|Example]] asd',
545 'asd <a title="Example" href="/wiki/Example">Example</a> asd'
546 ],
547 [
548 'wikilink-param-href-partial',
549 'asd [[$1/Test|Example]] asd',
550 'asd <a title="Example/Test" href="/wiki/Example/Test">Example</a> asd'
551 ],
552 [
553 'wikilink-param-text-full',
554 'asd [[Example|$2]] asd',
555 'asd <a title="Example" href="/wiki/Example">Text</a> asd'
556 ],
557 [
558 'wikilink-param-text-partial',
559 'asd [[Example|Example $2]] asd',
560 'asd <a title="Example" href="/wiki/Example">Example Text</a> asd'
561 ],
562 [
563 'wikilink-param-both-full',
564 'asd [[$1|$2]] asd',
565 'asd <a title="Example" href="/wiki/Example">Text</a> asd'
566 ],
567 [
568 'wikilink-param-both-partial',
569 'asd [[$1/Test|Example $2]] asd',
570 'asd <a title="Example/Test" href="/wiki/Example/Test">Example Text</a> asd'
571 ],
572 [
573 'wikilink-param-unpiped-full',
574 'asd [[$1]] asd',
575 'asd <a title="Example" href="/wiki/Example">Example</a> asd'
576 ],
577 [
578 'wikilink-param-unpiped-partial',
579 'asd [[$1/Test]] asd',
580 'asd <a title="Example/Test" href="/wiki/Example/Test">Example/Test</a> asd'
581 ]
582 ];
583
584 $.each( testCases, function () {
585 var
586 key = this[ 0 ],
587 input = this[ 1 ],
588 output = this[ 2 ],
589 paramHref = key.slice( 0, 8 ) === 'wikilink' ? 'Example' : 'http://example.com',
590 paramText = 'Text';
591 mw.messages.set( key, input );
592 assert.htmlEqual(
593 formatParse( key, paramHref, paramText ),
594 output,
595 'Replacements in links: ' + key
596 );
597 } );
598 } );
599
600 // Tests that {{-transformation vs. general parsing are done as requested
601 QUnit.test( 'Curly brace transformation', 16, function ( assert ) {
602 var oldUserLang = mw.config.get( 'wgUserLanguage' );
603
604 assertBothModes( assert, [ 'gender-msg', 'Bob', 'male' ], 'Bob: blue', 'gender is resolved' );
605
606 assertBothModes( assert, [ 'plural-msg', 5 ], 'Found 5 items', 'plural is resolved' );
607
608 assertBothModes( assert, [ 'grammar-msg' ], 'Przeszukaj Wiki', 'grammar is resolved' );
609
610 mw.config.set( 'wgUserLanguage', 'en' );
611 assertBothModes( assert, [ 'formatnum-msg', '987654321.654321' ], '987,654,321.654', 'formatnum is resolved' );
612
613 // Test non-{{ wikitext, where behavior differs
614
615 // Wikilink
616 assert.equal(
617 formatText( 'jquerymsg-test-statistics-users' ),
618 mw.messages.get( 'jquerymsg-test-statistics-users' ),
619 'Internal link message unchanged when format is \'text\''
620 );
621 assert.htmlEqual(
622 formatParse( 'jquerymsg-test-statistics-users' ),
623 expectedListUsers,
624 'Internal link message parsed when format is \'parse\''
625 );
626
627 // External link
628 assert.equal(
629 formatText( 'jquerymsg-test-version-entrypoints-index-php' ),
630 mw.messages.get( 'jquerymsg-test-version-entrypoints-index-php' ),
631 'External link message unchanged when format is \'text\''
632 );
633 assert.htmlEqual(
634 formatParse( 'jquerymsg-test-version-entrypoints-index-php' ),
635 expectedEntrypoints,
636 'External link message processed when format is \'parse\''
637 );
638
639 // External link with parameter
640 assert.equal(
641 formatText( 'external-link-replace', 'http://example.com' ),
642 'Foo [http://example.com bar]',
643 'External link message only substitutes parameter when format is \'text\''
644 );
645 assert.htmlEqual(
646 formatParse( 'external-link-replace', 'http://example.com' ),
647 'Foo <a href="http://example.com">bar</a>',
648 'External link message processed when format is \'parse\''
649 );
650 assert.htmlEqual(
651 formatParse( 'external-link-replace', $( '<i>' ) ),
652 'Foo <i>bar</i>',
653 'External link message processed as jQuery object when format is \'parse\''
654 );
655 assert.htmlEqual(
656 formatParse( 'external-link-replace', function () {} ),
657 'Foo <a href="#">bar</a>',
658 'External link message processed as function when format is \'parse\''
659 );
660
661 mw.config.set( 'wgUserLanguage', oldUserLang );
662 } );
663
664 QUnit.test( 'Int', 4, function ( assert ) {
665 var newarticletextSource = 'You have followed a link to a page that does not exist yet. To create the page, start typing in the box below (see the [[{{Int:Foobar}}|foobar]] for more info). If you are here by mistake, click your browser\'s back button.',
666 expectedNewarticletext,
667 helpPageTitle = 'Help:Foobar';
668
669 mw.messages.set( 'foobar', helpPageTitle );
670
671 expectedNewarticletext = 'You have followed a link to a page that does not exist yet. To create the page, start typing in the box below (see the ' +
672 '<a title="Help:Foobar" href="/wiki/Help:Foobar">foobar</a> for more info). If you are here by mistake, click your browser\'s back button.';
673
674 mw.messages.set( 'newarticletext', newarticletextSource );
675
676 assert.htmlEqual(
677 formatParse( 'newarticletext' ),
678 expectedNewarticletext,
679 'Link with nested message'
680 );
681
682 assert.equal(
683 formatParse( 'see-portal-url' ),
684 'Project:Community portal is an important community page.',
685 'Nested message'
686 );
687
688 mw.messages.set( 'newarticletext-lowercase',
689 newarticletextSource.replace( 'Int:Helppage', 'int:helppage' ) );
690
691 assert.htmlEqual(
692 formatParse( 'newarticletext-lowercase' ),
693 expectedNewarticletext,
694 'Link with nested message, lowercase include'
695 );
696
697 mw.messages.set( 'uses-missing-int', '{{int:doesnt-exist}}' );
698
699 assert.equal(
700 formatParse( 'uses-missing-int' ),
701 '[doesnt-exist]',
702 'int: where nested message does not exist'
703 );
704 } );
705
706 QUnit.test( 'Ns', 4, function ( assert ) {
707 mw.messages.set( 'ns-template-talk', '{{ns:Template talk}}' );
708 assert.equal(
709 formatParse( 'ns-template-talk' ),
710 'Dyskusja szablonu',
711 'ns: returns localised namespace when used with a canonical namespace name'
712 );
713
714 mw.messages.set( 'ns-10', '{{ns:10}}' );
715 assert.equal(
716 formatParse( 'ns-10' ),
717 'Szablon',
718 'ns: returns localised namespace when used with a namespace number'
719 );
720
721 mw.messages.set( 'ns-unknown', '{{ns:doesnt-exist}}' );
722 assert.equal(
723 formatParse( 'ns-unknown' ),
724 '',
725 'ns: returns empty string for unknown namespace name'
726 );
727
728 mw.messages.set( 'ns-in-a-link', '[[{{ns:template}}:Foo]]' );
729 assert.equal(
730 formatParse( 'ns-in-a-link' ),
731 '<a title="Szablon:Foo" href="/wiki/Szablon:Foo">Szablon:Foo</a>',
732 'ns: works when used inside a wikilink'
733 );
734 } );
735
736 // Tests that getMessageFunction is used for non-plain messages with curly braces or
737 // square brackets, but not otherwise.
738 QUnit.test( 'mw.Message.prototype.parser monkey-patch', 22, function ( assert ) {
739 var oldGMF, outerCalled, innerCalled;
740
741 mw.messages.set( {
742 'curly-brace': '{{int:message}}',
743 'single-square-bracket': '[https://www.mediawiki.org/ MediaWiki]',
744 'double-square-bracket': '[[Some page]]',
745 regular: 'Other message'
746 } );
747
748 oldGMF = mw.jqueryMsg.getMessageFunction;
749
750 mw.jqueryMsg.getMessageFunction = function () {
751 outerCalled = true;
752 return function () {
753 innerCalled = true;
754 };
755 };
756
757 function verifyGetMessageFunction( key, format, shouldCall ) {
758 var message;
759 outerCalled = false;
760 innerCalled = false;
761 message = mw.message( key );
762 message[ format ]();
763 assert.strictEqual( outerCalled, shouldCall, 'Outer function called for ' + key );
764 assert.strictEqual( innerCalled, shouldCall, 'Inner function called for ' + key );
765 delete mw.messages[ format ];
766 }
767
768 verifyGetMessageFunction( 'curly-brace', 'parse', true );
769 verifyGetMessageFunction( 'curly-brace', 'plain', false );
770
771 verifyGetMessageFunction( 'single-square-bracket', 'parse', true );
772 verifyGetMessageFunction( 'single-square-bracket', 'plain', false );
773
774 verifyGetMessageFunction( 'double-square-bracket', 'parse', true );
775 verifyGetMessageFunction( 'double-square-bracket', 'plain', false );
776
777 verifyGetMessageFunction( 'regular', 'parse', false );
778 verifyGetMessageFunction( 'regular', 'plain', false );
779
780 verifyGetMessageFunction( 'jquerymsg-test-pagetriage-del-talk-page-notify-summary', 'plain', false );
781 verifyGetMessageFunction( 'jquerymsg-test-categorytree-collapse-bullet', 'plain', false );
782 verifyGetMessageFunction( 'jquerymsg-test-wikieditor-toolbar-help-content-signature-result', 'plain', false );
783
784 mw.jqueryMsg.getMessageFunction = oldGMF;
785 } );
786
787 formatnumTests = [
788 {
789 lang: 'en',
790 number: 987654321.654321,
791 result: '987,654,321.654',
792 description: 'formatnum test for English, decimal separator'
793 },
794 {
795 lang: 'ar',
796 number: 987654321.654321,
797 result: '٩٨٧٬٦٥٤٬٣٢١٫٦٥٤',
798 description: 'formatnum test for Arabic, with decimal separator'
799 },
800 {
801 lang: 'ar',
802 number: '٩٨٧٦٥٤٣٢١٫٦٥٤٣٢١',
803 result: 987654321,
804 integer: true,
805 description: 'formatnum test for Arabic, with decimal separator, reverse'
806 },
807 {
808 lang: 'ar',
809 number: -12.89,
810 result: '-١٢٫٨٩',
811 description: 'formatnum test for Arabic, negative number'
812 },
813 {
814 lang: 'ar',
815 number: '-١٢٫٨٩',
816 result: -12,
817 integer: true,
818 description: 'formatnum test for Arabic, negative number, reverse'
819 },
820 {
821 lang: 'nl',
822 number: 987654321.654321,
823 result: '987.654.321,654',
824 description: 'formatnum test for Nederlands, decimal separator'
825 },
826 {
827 lang: 'nl',
828 number: -12.89,
829 result: '-12,89',
830 description: 'formatnum test for Nederlands, negative number'
831 },
832 {
833 lang: 'nl',
834 number: '.89',
835 result: '0,89',
836 description: 'formatnum test for Nederlands'
837 },
838 {
839 lang: 'nl',
840 number: 'invalidnumber',
841 result: 'invalidnumber',
842 description: 'formatnum test for Nederlands, invalid number'
843 },
844 {
845 lang: 'ml',
846 number: '1000000000',
847 result: '1,00,00,00,000',
848 description: 'formatnum test for Malayalam'
849 },
850 {
851 lang: 'ml',
852 number: '-1000000000',
853 result: '-1,00,00,00,000',
854 description: 'formatnum test for Malayalam, negative number'
855 },
856 /*
857 * This will fail because of wrong pattern for ml in MW(different from CLDR)
858 {
859 lang: 'ml',
860 number: '1000000000.000',
861 result: '1,00,00,00,000.000',
862 description: 'formatnum test for Malayalam with decimal place'
863 },
864 */
865 {
866 lang: 'hi',
867 number: '123456789.123456789',
868 result: '१२,३४,५६,७८९',
869 description: 'formatnum test for Hindi'
870 },
871 {
872 lang: 'hi',
873 number: '१२,३४,५६,७८९',
874 result: '१२,३४,५६,७८९',
875 description: 'formatnum test for Hindi, Devanagari digits passed'
876 },
877 {
878 lang: 'hi',
879 number: '१२३४५६,७८९',
880 result: '123456',
881 integer: true,
882 description: 'formatnum test for Hindi, Devanagari digits passed to get integer value'
883 }
884 ];
885
886 QUnit.test( 'formatnum', formatnumTests.length, function ( assert ) {
887 mw.messages.set( 'formatnum-msg', '{{formatnum:$1}}' );
888 mw.messages.set( 'formatnum-msg-int', '{{formatnum:$1|R}}' );
889 var queue = $.map( formatnumTests, function ( test ) {
890 return function ( next, abort ) {
891 getMwLanguage( test.lang )
892 .then( function ( langClass ) {
893 mw.config.set( 'wgUserLanguage', test.lang );
894 var parser = new mw.jqueryMsg.parser( { language: langClass } );
895 assert.equal(
896 parser.parse( test.integer ? 'formatnum-msg-int' : 'formatnum-msg',
897 [ test.number ] ).html(),
898 test.result,
899 test.description
900 );
901 }, function () {
902 assert.ok( false, 'Language "' + test.lang + '" failed to load' );
903 } )
904 .then( next, abort );
905 };
906 } );
907 QUnit.stop();
908 process( queue, QUnit.start );
909 } );
910
911 // HTML in wikitext
912 QUnit.test( 'HTML', 32, function ( assert ) {
913 mw.messages.set( 'jquerymsg-italics-msg', '<i>Very</i> important' );
914
915 assertBothModes( assert, [ 'jquerymsg-italics-msg' ], mw.messages.get( 'jquerymsg-italics-msg' ), 'Simple italics unchanged' );
916
917 mw.messages.set( 'jquerymsg-bold-msg', '<b>Strong</b> speaker' );
918 assertBothModes( assert, [ 'jquerymsg-bold-msg' ], mw.messages.get( 'jquerymsg-bold-msg' ), 'Simple bold unchanged' );
919
920 mw.messages.set( 'jquerymsg-bold-italics-msg', 'It is <b><i>key</i></b>' );
921 assertBothModes( assert, [ 'jquerymsg-bold-italics-msg' ], mw.messages.get( 'jquerymsg-bold-italics-msg' ), 'Bold and italics nesting order preserved' );
922
923 mw.messages.set( 'jquerymsg-italics-bold-msg', 'It is <i><b>vital</b></i>' );
924 assertBothModes( assert, [ 'jquerymsg-italics-bold-msg' ], mw.messages.get( 'jquerymsg-italics-bold-msg' ), 'Italics and bold nesting order preserved' );
925
926 mw.messages.set( 'jquerymsg-italics-with-link', 'An <i>italicized [[link|wiki-link]]</i>' );
927
928 assert.htmlEqual(
929 formatParse( 'jquerymsg-italics-with-link' ),
930 'An <i>italicized <a title="link" href="' + mw.html.escape( mw.util.getUrl( 'link' ) ) + '">wiki-link</i>',
931 'Italics with link inside in parse mode'
932 );
933
934 assert.equal(
935 formatText( 'jquerymsg-italics-with-link' ),
936 mw.messages.get( 'jquerymsg-italics-with-link' ),
937 'Italics with link unchanged in text mode'
938 );
939
940 mw.messages.set( 'jquerymsg-italics-id-class', '<i id="foo" class="bar">Foo</i>' );
941 assert.htmlEqual(
942 formatParse( 'jquerymsg-italics-id-class' ),
943 mw.messages.get( 'jquerymsg-italics-id-class' ),
944 'ID and class are allowed'
945 );
946
947 mw.messages.set( 'jquerymsg-italics-onclick', '<i onclick="alert(\'foo\')">Foo</i>' );
948 assert.htmlEqual(
949 formatParse( 'jquerymsg-italics-onclick' ),
950 '&lt;i onclick=&quot;alert(\'foo\')&quot;&gt;Foo&lt;/i&gt;',
951 'element with onclick is escaped because it is not allowed'
952 );
953
954 mw.messages.set( 'jquerymsg-script-msg', '<script >alert( "Who put this tag here?" );</script>' );
955 assert.htmlEqual(
956 formatParse( 'jquerymsg-script-msg' ),
957 '&lt;script &gt;alert( &quot;Who put this tag here?&quot; );&lt;/script&gt;',
958 'Tag outside whitelist escaped in parse mode'
959 );
960
961 assert.equal(
962 formatText( 'jquerymsg-script-msg' ),
963 mw.messages.get( 'jquerymsg-script-msg' ),
964 'Tag outside whitelist unchanged in text mode'
965 );
966
967 mw.messages.set( 'jquerymsg-script-link-msg', '<script>[[Foo|bar]]</script>' );
968 assert.htmlEqual(
969 formatParse( 'jquerymsg-script-link-msg' ),
970 '&lt;script&gt;<a title="Foo" href="' + mw.html.escape( mw.util.getUrl( 'Foo' ) ) + '">bar</a>&lt;/script&gt;',
971 'Script tag text is escaped because that element is not allowed, but link inside is still HTML'
972 );
973
974 mw.messages.set( 'jquerymsg-mismatched-html', '<i class="important">test</b>' );
975 assert.htmlEqual(
976 formatParse( 'jquerymsg-mismatched-html' ),
977 '&lt;i class=&quot;important&quot;&gt;test&lt;/b&gt;',
978 'Mismatched HTML start and end tag treated as text'
979 );
980
981 mw.messages.set( 'jquerymsg-script-and-external-link', '<script>alert( "jquerymsg-script-and-external-link test" );</script> [http://example.com <i>Foo</i> bar]' );
982 assert.htmlEqual(
983 formatParse( 'jquerymsg-script-and-external-link' ),
984 '&lt;script&gt;alert( "jquerymsg-script-and-external-link test" );&lt;/script&gt; <a href="http://example.com"><i>Foo</i> bar</a>',
985 'HTML tags in external links not interfering with escaping of other tags'
986 );
987
988 mw.messages.set( 'jquerymsg-link-script', '[http://example.com <script>alert( "jquerymsg-link-script test" );</script>]' );
989 assert.htmlEqual(
990 formatParse( 'jquerymsg-link-script' ),
991 '<a href="http://example.com">&lt;script&gt;alert( "jquerymsg-link-script test" );&lt;/script&gt;</a>',
992 'Non-whitelisted HTML tag in external link anchor treated as text'
993 );
994
995 // Intentionally not using htmlEqual for the quote tests
996 mw.messages.set( 'jquerymsg-double-quotes-preserved', '<i id="double">Double</i>' );
997 assert.equal(
998 formatParse( 'jquerymsg-double-quotes-preserved' ),
999 mw.messages.get( 'jquerymsg-double-quotes-preserved' ),
1000 'Attributes with double quotes are preserved as such'
1001 );
1002
1003 mw.messages.set( 'jquerymsg-single-quotes-normalized-to-double', '<i id=\'single\'>Single</i>' );
1004 assert.equal(
1005 formatParse( 'jquerymsg-single-quotes-normalized-to-double' ),
1006 '<i id="single">Single</i>',
1007 'Attributes with single quotes are normalized to double'
1008 );
1009
1010 mw.messages.set( 'jquerymsg-escaped-double-quotes-attribute', '<i style="font-family:&quot;Arial&quot;">Styled</i>' );
1011 assert.htmlEqual(
1012 formatParse( 'jquerymsg-escaped-double-quotes-attribute' ),
1013 mw.messages.get( 'jquerymsg-escaped-double-quotes-attribute' ),
1014 'Escaped attributes are parsed correctly'
1015 );
1016
1017 mw.messages.set( 'jquerymsg-escaped-single-quotes-attribute', '<i style=\'font-family:&#039;Arial&#039;\'>Styled</i>' );
1018 assert.htmlEqual(
1019 formatParse( 'jquerymsg-escaped-single-quotes-attribute' ),
1020 mw.messages.get( 'jquerymsg-escaped-single-quotes-attribute' ),
1021 'Escaped attributes are parsed correctly'
1022 );
1023
1024 mw.messages.set( 'jquerymsg-wikitext-contents-parsed', '<i>[http://example.com Example]</i>' );
1025 assert.htmlEqual(
1026 formatParse( 'jquerymsg-wikitext-contents-parsed' ),
1027 '<i><a href="http://example.com">Example</a></i>',
1028 'Contents of valid tag are treated as wikitext, so external link is parsed'
1029 );
1030
1031 mw.messages.set( 'jquerymsg-wikitext-contents-script', '<i><script>Script inside</script></i>' );
1032 assert.htmlEqual(
1033 formatParse( 'jquerymsg-wikitext-contents-script' ),
1034 '<i>&lt;script&gt;Script inside&lt;/script&gt;</i>',
1035 'Contents of valid tag are treated as wikitext, so invalid HTML element is treated as text'
1036 );
1037
1038 mw.messages.set( 'jquerymsg-unclosed-tag', 'Foo<tag>bar' );
1039 assert.htmlEqual(
1040 formatParse( 'jquerymsg-unclosed-tag' ),
1041 'Foo&lt;tag&gt;bar',
1042 'Nonsupported unclosed tags are escaped'
1043 );
1044
1045 mw.messages.set( 'jquerymsg-self-closing-tag', 'Foo<tag/>bar' );
1046 assert.htmlEqual(
1047 formatParse( 'jquerymsg-self-closing-tag' ),
1048 'Foo&lt;tag/&gt;bar',
1049 'Self-closing tags don\'t cause a parse error'
1050 );
1051
1052 mw.messages.set( 'jquerymsg-entities1', 'A&B' );
1053 mw.messages.set( 'jquerymsg-entities2', 'A&gt;B' );
1054 mw.messages.set( 'jquerymsg-entities3', 'A&rarr;B' );
1055 assert.htmlEqual(
1056 formatParse( 'jquerymsg-entities1' ),
1057 'A&amp;B',
1058 'Lone "&" is escaped in text'
1059 );
1060 assert.htmlEqual(
1061 formatParse( 'jquerymsg-entities2' ),
1062 'A&amp;gt;B',
1063 '"&gt;" entity is double-escaped in text' // (WHY?)
1064 );
1065 assert.htmlEqual(
1066 formatParse( 'jquerymsg-entities3' ),
1067 'A&amp;rarr;B',
1068 '"&rarr;" entity is double-escaped in text'
1069 );
1070
1071 mw.messages.set( 'jquerymsg-entities-attr1', '<i title="A&B"></i>' );
1072 mw.messages.set( 'jquerymsg-entities-attr2', '<i title="A&gt;B"></i>' );
1073 mw.messages.set( 'jquerymsg-entities-attr3', '<i title="A&rarr;B"></i>' );
1074 assert.htmlEqual(
1075 formatParse( 'jquerymsg-entities-attr1' ),
1076 '<i title="A&amp;B"></i>',
1077 'Lone "&" is escaped in attribute'
1078 );
1079 assert.htmlEqual(
1080 formatParse( 'jquerymsg-entities-attr2' ),
1081 '<i title="A&gt;B"></i>',
1082 '"&gt;" entity is not double-escaped in attribute' // (WHY?)
1083 );
1084 assert.htmlEqual(
1085 formatParse( 'jquerymsg-entities-attr3' ),
1086 '<i title="A&amp;rarr;B"></i>',
1087 '"&rarr;" entity is double-escaped in attribute'
1088 );
1089 } );
1090
1091 QUnit.test( 'Behavior in case of invalid wikitext', 3, function ( assert ) {
1092 mw.messages.set( 'invalid-wikitext', '<b>{{FAIL}}</b>' );
1093
1094 this.suppressWarnings();
1095 var logSpy = this.sandbox.spy( mw.log, 'warn' );
1096
1097 assert.equal(
1098 formatParse( 'invalid-wikitext' ),
1099 '&lt;b&gt;{{FAIL}}&lt;/b&gt;',
1100 'Invalid wikitext: \'parse\' format'
1101 );
1102
1103 assert.equal(
1104 formatText( 'invalid-wikitext' ),
1105 '<b>{{FAIL}}</b>',
1106 'Invalid wikitext: \'text\' format'
1107 );
1108
1109 assert.equal( logSpy.callCount, 2, 'mw.log.warn calls' );
1110 } );
1111
1112 QUnit.test( 'Integration', 5, function ( assert ) {
1113 var expected, logSpy, msg;
1114
1115 expected = '<b><a title="Bold" href="/wiki/Bold">Bold</a>!</b>';
1116 mw.messages.set( 'integration-test', '<b>[[Bold]]!</b>' );
1117
1118 this.suppressWarnings();
1119 logSpy = this.sandbox.spy( mw.log, 'warn' );
1120 assert.equal(
1121 window.gM( 'integration-test' ),
1122 expected,
1123 'Global function gM() works correctly'
1124 );
1125 assert.equal( logSpy.callCount, 1, 'mw.log.warn called' );
1126 this.restoreWarnings();
1127
1128 assert.equal(
1129 mw.message( 'integration-test' ).parse(),
1130 expected,
1131 'mw.message().parse() works correctly'
1132 );
1133
1134 assert.equal(
1135 $( '<span>' ).msg( 'integration-test' ).html(),
1136 expected,
1137 'jQuery plugin $.fn.msg() works correctly'
1138 );
1139
1140 mw.messages.set( 'integration-test-extlink', '[$1 Link]' );
1141 msg = mw.message(
1142 'integration-test-extlink',
1143 $( '<a>' ).attr( 'href', 'http://example.com/' )
1144 );
1145 msg.parse(); // Not a no-op
1146 assert.equal(
1147 msg.parse(),
1148 '<a href="http://example.com/">Link</a>',
1149 'Calling .parse() multiple times does not duplicate link contents'
1150 );
1151 } );
1152
1153 }( mediaWiki, jQuery ) );