mediawiki.jqueryMsg: Allow more than one thing inside a wikilink
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 28 Sep 2015 21:13:54 +0000 (23:13 +0200)
committerJforrester <jforrester@wikimedia.org>
Tue, 29 Sep 2015 14:51:30 +0000 (14:51 +0000)
So that [[foo|bar {{SITENAME}}]] becomes parseable.

Change-Id: Idf825e4df24cb9a10cac136811936e54e8fce7b6

resources/src/mediawiki/mediawiki.jqueryMsg.js
tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js

index ce92423..9463ac8 100644 (file)
                                var result = sequence( [
                                        wikilinkPage,
                                        pipe,
-                                       expression
+                                       nOrMore( 1, expression )
                                ] );
-                               return result === null ? null : [ result[ 0 ], result[ 2 ] ];
+                               return result === null ? null : [ result[ 0 ], [ 'CONCAT' ].concat( result[ 2 ] ) ];
                        }
 
                        wikilinkContents = choice( [
                        return $( '<a>' ).attr( {
                                title: page,
                                href: url
-                       } ).text( anchor );
+                       } )
+                               // FIXME This means that you can't have anything with formatting inside a wikilink.
+                               .text( anchor.jquery ? anchor.text() : anchor );
                },
 
                /**
index 161b8e1..f287caa 100644 (file)
@@ -1,5 +1,6 @@
 ( function ( mw, $ ) {
-       var formatText, formatParse, formatnumTests, specialCharactersPageName, expectedListUsers, expectedEntrypoints,
+       var formatText, formatParse, formatnumTests, specialCharactersPageName, expectedListUsers,
+               expectedListUsersSitename, expectedEntrypoints,
                mwLanguageCache = {},
                hasOwn = Object.hasOwnProperty;
 
@@ -16,6 +17,8 @@
                        specialCharactersPageName = '"Who" wants to be a millionaire & live on \'Exotic Island\'?';
 
                        expectedListUsers = '注册<a title="Special:ListUsers" href="/wiki/Special:ListUsers">用户</a>';
+                       expectedListUsersSitename = '注册<a title="Special:ListUsers" href="/wiki/Special:ListUsers">用户' +
+                               mw.config.get( 'wgSiteName' ) + '</a>';
 
                        expectedEntrypoints = '<a href="https://www.mediawiki.org/wiki/Manual:index.php">index.php</a>';
 
@@ -52,6 +55,7 @@
                        'see-portal-url': '{{Int:portal-url}} is an important community page.',
 
                        'jquerymsg-test-statistics-users': '注册[[Special:ListUsers|用户]]',
+                       'jquerymsg-test-statistics-users-sitename': '注册[[Special:ListUsers|用户{{SITENAME}}]]',
 
                        'jquerymsg-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
 
                process( tasks, QUnit.start );
        } );
 
-       QUnit.test( 'Links', 6, function ( assert ) {
+       QUnit.test( 'Links', 7, function ( assert ) {
                var expectedDisambiguationsText,
                        expectedMultipleBars,
                        expectedSpecialCharacters;
                        expectedSpecialCharacters,
                        'Special characters'
                );
+
+               assert.htmlEqual(
+                       formatParse( 'jquerymsg-test-statistics-users-sitename' ),
+                       expectedListUsersSitename,
+                       'Piped wikilink with parser function in the text'
+               );
        } );
 
        // Tests that {{-transformation vs. general parsing are done as requested