Make wfScript()/mw.util.wikiScript() respect $wgScript/$wgLoadScript
authorCatrope <roan.kattouw@gmail.com>
Tue, 21 Aug 2012 19:38:00 +0000 (12:38 -0700)
committerCatrope <roan.kattouw@gmail.com>
Tue, 21 Aug 2012 21:27:04 +0000 (14:27 -0700)
mw.util.wikiScript() and mw.util.wikiScript( 'index' ) now return the
value of $wgScript rather than building the path to index.php manually;
the latter is incorrect if $wgScript is customized. Similarly,
mw.util.wikiScript( 'load' ) now uses $wgLoadScript.

Same for wfScript(), wfScript( 'index' ) and wfScript( 'load' )

The qunit tests already had a test case for wgScript, but wgScript was
set in a way that didn't trigger the bug. Changed it to use customized
wgScript and wgLoadScript values and added test cases for 'index' and
'load'

This fixes bug 39103 (wfScript/mw.util.wikiScript do not respect custom
$wgScript/$wgLoadScript) as well as bug 39102 ("Entry points" on
Special:Version do not respect custom $wgScript/$wgLoadScript)

Change-Id: I5c9e82849e314dc7a87f8ae91150cc412b4011cf

includes/GlobalFunctions.php
resources/mediawiki/mediawiki.util.js
tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js

index 708fae6..4252f55 100644 (file)
@@ -3590,13 +3590,20 @@ function wfQueriesMustScale() {
 /**
  * Get the path to a specified script file, respecting file
  * extensions; this is a wrapper around $wgScriptExtension etc.
+ * except for 'index' and 'load' which use $wgScript/$wgLoadScript
  *
  * @param $script String: script filename, sans extension
  * @return String
  */
 function wfScript( $script = 'index' ) {
-       global $wgScriptPath, $wgScriptExtension;
-       return "{$wgScriptPath}/{$script}{$wgScriptExtension}";
+       global $wgScriptPath, $wgScriptExtension, $wgScript, $wgLoadScript;
+       if ( $script === 'index' ) {
+               return $wgScript;
+       } else if ( $script === 'load' ) {
+               return $wgLoadScript;
+       } else {
+               return "{$wgScriptPath}/{$script}{$wgScriptExtension}";
+       }
 }
 
 /**
index d1bfd05..7e2bab8 100644 (file)
                 * @return string Address to script (eg. '/w/api.php' )
                 */
                wikiScript: function ( str ) {
-                       return mw.config.get( 'wgScriptPath' ) + '/' + ( str || 'index' ) +
-                               mw.config.get( 'wgScriptExtension' );
+                       str = str || 'index';
+                       if ( str === 'index' ) {
+                               return mw.config.get( 'wgScript' );
+                       } else if ( str === 'load' ) {
+                               return mw.config.get( 'wgLoadScript' );
+                       } else {
+                               return mw.config.get( 'wgScriptPath' ) + '/' + str +
+                                       mw.config.get( 'wgScriptExtension' );
+                       }
                },
 
                /**
index d9b2055..ababa8d 100644 (file)
@@ -24,14 +24,17 @@ QUnit.test( 'wikiGetlink', 3, function ( assert ) {
        assert.equal( hrefC, '/wiki/Foobar', 'Default title; Get link for current page ("Foobar")' );
 });
 
-QUnit.test( 'wikiScript', 2, function ( assert ) {
+QUnit.test( 'wikiScript', 4, function ( assert ) {
        mw.config.set({
-               'wgScript': '/w/index.php',
+               'wgScript': '/w/i.php', // customized wgScript for bug 39103
+               'wgLoadScript': '/w/l.php', // customized wgLoadScript for bug 39103
                'wgScriptPath': '/w',
                'wgScriptExtension': '.php'
        });
 
-       assert.equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript' );
+       assert.equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'wikiScript() returns wgScript' );
+       assert.equal( mw.util.wikiScript( 'index' ), mw.config.get( 'wgScript' ), "wikiScript( 'index' ) returns wgScript" );
+       assert.equal( mw.util.wikiScript( 'load' ), mw.config.get( 'wgLoadScript' ), "wikiScript( 'load' ) returns wgLoadScript" );
        assert.equal( mw.util.wikiScript( 'api' ), '/w/api.php', 'API path' );
 });