mw.util.wikiGetlink default to wgPageName
authorKrinkle <krinkle@users.mediawiki.org>
Tue, 5 Jul 2011 22:10:08 +0000 (22:10 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Tue, 5 Jul 2011 22:10:08 +0000 (22:10 +0000)
* (bug 29723) mw.util.wikiGetlink() should default to wgPageName
* Solution by mybugs.mail

* Adding unit tests

RELEASE-NOTES-1.19
resources/mediawiki/mediawiki.util.js
tests/qunit/suites/resources/mediawiki/mediawiki.util.js

index 7239544..b7397ec 100644 (file)
@@ -66,6 +66,7 @@ production.
   show the first bit of the new redirect page.
 * (bug 5800) Added $formCallback as a parameter to the hook
   EditPage::showEditForm:initial
+* (bug 29723) mw.util.wikiGetlink() now defaults to wgPageName.
 
 === Bug fixes in 1.19 ===
 * (bug 28868) Show total pages in the subtitle of an image on the
index 195f287..ec53939 100644 (file)
                 * @return string Location for a page with name of 'str' or boolean false on error.
                 */
                'wikiGetlink' : function( str ) {
-
-                       return mw.config.get( 'wgArticlePath' ).replace( '$1', this.wikiUrlencode( str ) );
+                       return mw.config.get( 'wgArticlePath' ).replace( '$1',
+                               this.wikiUrlencode( str || mw.config.get( 'wgPageName' ) ) );
                },
 
                /**
index 67fce22..7fb8fe9 100644 (file)
@@ -19,10 +19,11 @@ test( 'wikiUrlencode', function() {
 });
 
 test( 'wikiGetlink', function() {
-       expect(2);
+       expect(3);
 
        // Not part of startUp module
        mw.config.set( 'wgArticlePath', '/wiki/$1' );
+       mw.config.set( 'wgPageName', 'Foobar' );
 
        var hrefA = mw.util.wikiGetlink( 'Sandbox' );
        equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' );
@@ -30,6 +31,9 @@ test( 'wikiGetlink', function() {
        var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' );
        equal( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage',
                'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' );
+
+       var hrefC = mw.util.wikiGetlink();
+       equal( hrefC, '/wiki/Foobar', 'Default title; Get link for current page ("Foobar")' );
 });
 
 test( 'wikiScript', function() {