r91500 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91499‎ | r91500 | r91501 >
Date:22:10, 5 July 2011
Author:krinkle
Status:ok (Comments)
Tags:update.docs 
Comment:
mw.util.wikiGetlink default to wgPageName
* (bug 29723) mw.util.wikiGetlink() should default to wgPageName
* Solution by mybugs.mail

* Adding unit tests
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.util.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.util.js (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -66,6 +66,7 @@
6767 show the first bit of the new redirect page.
6868 * (bug 5800) Added $formCallback as a parameter to the hook
6969 EditPage::showEditForm:initial
 70+* (bug 29723) mw.util.wikiGetlink() now defaults to wgPageName.
7071
7172 === Bug fixes in 1.19 ===
7273 * (bug 28868) Show total pages in the subtitle of an image on the
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.util.js
@@ -19,10 +19,11 @@
2020 });
2121
2222 test( 'wikiGetlink', function() {
23 - expect(2);
 23+ expect(3);
2424
2525 // Not part of startUp module
2626 mw.config.set( 'wgArticlePath', '/wiki/$1' );
 27+ mw.config.set( 'wgPageName', 'Foobar' );
2728
2829 var hrefA = mw.util.wikiGetlink( 'Sandbox' );
2930 equal( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' );
@@ -30,6 +31,9 @@
3132 var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' );
3233 equal( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage',
3334 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' );
 35+
 36+ var hrefC = mw.util.wikiGetlink();
 37+ equal( hrefC, '/wiki/Foobar', 'Default title; Get link for current page ("Foobar")' );
3438 });
3539
3640 test( 'wikiScript', function() {
Index: trunk/phase3/resources/mediawiki/mediawiki.util.js
@@ -139,8 +139,8 @@
140140 * @return string Location for a page with name of 'str' or boolean false on error.
141141 */
142142 'wikiGetlink' : function( str ) {
143 -
144 - return mw.config.get( 'wgArticlePath' ).replace( '$1', this.wikiUrlencode( str ) );
 143+ return mw.config.get( 'wgArticlePath' ).replace( '$1',
 144+ this.wikiUrlencode( str || mw.config.get( 'wgPageName' ) ) );
145145 },
146146
147147 /**

Sign-offs

UserFlagDate
He7d3rinspected22:22, 5 July 2011

Comments

#Comment by He7d3r (talk | contribs)   22:21, 5 July 2011

What about updating the doc of this function to indicate that the parameter is now optional?

#Comment by He7d3r (talk | contribs)   23:59, 5 July 2011

BTW: is this approach

str || default

better than this one?

str = str ? str : default

?

If so, should it also be applied to the definition of getParamValue

#Comment by DieBuche (talk | contribs)   13:02, 6 July 2011

Logically it's the same. You save a few bytes and one assignment. The second one is useful if you use str multiple times

Status & tagging log