[Core JS] More fixing of global config variable usage
authorKrinkle <krinkle@users.mediawiki.org>
Sat, 31 Dec 2011 21:25:00 +0000 (21:25 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sat, 31 Dec 2011 21:25:00 +0000 (21:25 +0000)
* mw.config is the new way, and global config variable lookups are deprecated

* Based on two phase3-wide quick searches:
-- of " wg": http://toolserver.org/~krinkle/wikimedia-svn-search/view.php?id=321&hash=81700bf7486e4fee3b7bc1f83eb9eba6
-- of "!wg": http://toolserver.org/~krinkle/wikimedia-svn-search/view.php?id=327&hash=47c9d54a7a1d5d58a724dd834585f40d

Related changes:
* Changed some php comments mentioning "wg" variables to include the dollar sign, and a typo when the wf function prefix was meant.
* Removed TODO comment in wikibits.js and made it use the JS equivalent of wfUrlencode, which we have now, mw.util.wikiUrlencode
* SpecialUpload.php: use OutputPage::addJsConfigVars instead of creating a new script tag through OutputPage::addScript(Skin::makeVariablesScript(..))
* Renamed wgUploadSetup in upload.js and made it local. Not used anywhere in ./trunk/phase3 and ./trunk/extensions
* Fix OutputPage::addJsConfigVars so that it can actually be called with an array instead of two arguments for key/value
* Some minor whitespace/convention stuff around the same line

15 files changed:
docs/hooks.txt
includes/HTMLForm.php
includes/OutputPage.php
includes/logging/LogEventsList.php
includes/specials/SpecialUpload.php
maintenance/language/messages.inc
resources/Resources.php
skins/common/ajax.js
skins/common/mwsuggest.js
skins/common/protect.js
skins/common/upload.js
skins/common/wikibits.js
tests/phpunit/includes/MWNamespaceTest.php
tests/phpunit/includes/upload/UploadTest.php
tests/phpunit/skins/SideBarTest.php

index 2d63e8b..ad58d7e 100644 (file)
@@ -1221,7 +1221,7 @@ $param: Associative Array with the following additional options:
  - lim Integer Limit of items to show, default is 50
  - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
  - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty if set to true (default), "No matching items in log" is displayed if loglist is empty
- - msgKey Array If you want a nice box with a message, set this to the key of the message. First element is the message key, additional optional elements are parameters for the key that are processed with wgMsgExt and option 'parse'
+ - msgKey Array If you want a nice box with a message, set this to the key of the message. First element is the message key, additional optional elements are parameters for the key that are processed with wfMsgExt and option 'parse'
  - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset
  - wrap String Wrap the message in html (usually something like "&lt;div ...>$1&lt;/div>").
  - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
index 0559777..099b51e 100644 (file)
@@ -423,7 +423,7 @@ class HTMLForm extends ContextSource {
        }
 
        /**
-        * Display the form (sending to wgOut), with an appropriate error
+        * Display the form (sending to $wgOut), with an appropriate error
         * message or stack of messages, and any validation errors, etc.
         * @param $submitResult Mixed output from HTMLForm::trySubmit()
         */
index c83401f..84fe1e9 100644 (file)
@@ -2750,9 +2750,9 @@ $templates
         * Add one or more variables to be set in mw.config in JavaScript.
         *
         * @param $key {String|Array} Key or array of key/value pars.
-        * @param $value {Mixed} Value of the configuration variable.
+        * @param $value {Mixed} [optional] Value of the configuration variable.
         */
-       public function addJsConfigVars( $keys, $value ) {
+       public function addJsConfigVars( $keys, $value = null ) {
                if ( is_array( $keys ) ) {
                        foreach ( $keys as $key => $value ) {
                                $this->mJsConfigVars[$key] = $value;
index 5458bac..0da6b02 100644 (file)
@@ -614,7 +614,7 @@ class LogEventsList {
         *   if set to true (default), "No matching items in log" is displayed if loglist is empty
         * - msgKey Array If you want a nice box with a message, set this to the key of the message.
         *   First element is the message key, additional optional elements are parameters for the key
-        *   that are processed with wgMsgExt and option 'parse'
+        *   that are processed with wfMsgExt and option 'parse'
         * - offset Set to overwrite offset parameter in $wgRequest
         *   set to '' to unset offset
         * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
index 5782e46..720c8ba 100644 (file)
@@ -1084,7 +1084,7 @@ class UploadForm extends HTMLForm {
                );
 
                $out = $this->getOutput();
-               $out->addScript( Skin::makeVariablesScript( $scriptVars ) );
+               $out->addJsConfigVars( $scriptVars );
 
 
                $out->addModules( array(
index 22f7256..a8030e4 100644 (file)
@@ -1015,7 +1015,7 @@ $wgMessageStructure = array(
                'email',
                'prefs-help-realname',
 
-               # 3 messages depending upon wgEmailConfirmToEdit and $wgEnableUserEmail
+               # 3 messages depending upon $wgEmailConfirmToEdit and $wgEnableUserEmail
                'prefs-help-email',
                'prefs-help-email-others',
                'prefs-help-email-required',
index 8edbc24..8d73540 100644 (file)
@@ -765,7 +765,7 @@ return array(
                        'size-gigabytes',
                        'largefileserver',
                ),
-               'dependencies' => array( 'mediawiki.libs.jpegmeta' ),
+               'dependencies' => array( 'mediawiki.libs.jpegmeta', 'mediawiki.util' ),
        ),
 
        /* MediaWiki Legacy */
@@ -774,7 +774,7 @@ return array(
                'scripts' => 'common/ajax.js',
                'remoteBasePath' => $GLOBALS['wgStylePath'],
                'localBasePath' => $GLOBALS['wgStyleDirectory'],
-               'dependencies' => 'mediawiki.legacy.wikibits',
+               'dependencies' => array( 'mediawiki.util', 'mediawiki.legacy.wikibits' ),
        ),
        'mediawiki.legacy.commonPrint' => array(
                'styles' => array( 'common/commonPrint.css' => array( 'media' => 'print' ) ),
index 2a93373..121f9d1 100644 (file)
@@ -84,9 +84,7 @@ window.sajax_do_call = function(func_name, args, target) {
        var i, x, n;
        var uri;
        var post_data;
-       uri = wgServer +
-               ( ( wgScript == null ) ? ( wgScriptPath + '/index.php' ) : wgScript ) +
-               '?action=ajax';
+       uri = mw.util.wikiScript() + '?action=ajax';
        if ( sajax_request_type == 'GET' ) {
                if ( uri.indexOf( '?' ) == -1 ) {
                        uri = uri + '?rs=' + encodeURIComponent( func_name );
index 7045e1b..dac5954 100644 (file)
@@ -478,7 +478,7 @@ window.os_delayedFetch = function() {
        var query = os_timer.query;
        os_timer = null;
        var path = mw.config.get( 'wgMWSuggestTemplate' ).replace( "{namespaces}", os_getNamespaces( r ) )
-                                                                       .replace( "{dbname}", wgDBname )
+                                                                       .replace( "{dbname}", mw.config.get( 'wgDBname' ) )
                                                                        .replace( "{searchTerms}", os_encodeQuery( query ) );
 
        // try to get from cache, if not fetch using ajax
index c771d57..a23c0cb 100644 (file)
@@ -77,16 +77,20 @@ window.ProtectionForm = {
        },
 
        /**
-        * Is this protection level cascadeable?
-        * @param level String
-        *
-        * @return boolean
-        *
+        * Checks if a cerain protection level is cascadeable.
+        * @param level {String}
+        * @return {Boolean}
         */
        'isCascadeableLevel': function( level ) {
-               for (var k = 0; k < wgCascadeableLevels.length; k++) {
-                       if ( wgCascadeableLevels[k] == level ) {
-                               return true;
+               var cascadeLevels, len, i;
+
+               cascadeLevels = mw.config.get( 'wgCascadeableLevels' );
+               // cascadeLevels isn't defined on all pages
+               if ( cascadeLevels ) {
+                       for ( i = 0, len = cascadeLevels.length; i < len; i += 1 ) {
+                               if ( cascadeLevels[i] === level ) {
+                                       return true;
+                               }
                        }
                }
                return false;
index 2e8f54e..8e08af3 100644 (file)
@@ -1,3 +1,7 @@
+( function () {
+var    ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ),
+       fileExtensions = mw.config.get( 'wgFileExtensions' );
+
 window.licenseSelectorCheck = function() {
        var selector = document.getElementById( "wpLicense" );
        var selection = selector.options[selector.selectedIndex].value;
@@ -11,7 +15,7 @@ window.licenseSelectorCheck = function() {
        wgUploadLicenseObj.fetchPreview( selection );
 };
 
-window.wgUploadSetup = function() {
+function uploadSetup() {
        // Disable URL box if the URL copy upload source type is not selected
        var e = document.getElementById( 'wpSourceTypeurl' );
        if( e ) {
@@ -36,7 +40,7 @@ window.wgUploadSetup = function() {
        }
 
        // AJAX wpDestFile warnings
-       if ( wgAjaxUploadDestCheck ) {
+       if ( ajaxUploadDestCheck ) {
                // Insert an event handler that fetches upload warnings when wpDestFile
                // has been changed
                document.getElementById( 'wpDestFile' ).onchange = function ( e ) {
@@ -54,7 +58,7 @@ window.wgUploadSetup = function() {
        }
 
        var wpLicense = document.getElementById( 'wpLicense' );
-       if ( wgAjaxLicensePreview && wpLicense ) {
+       if ( mw.config.get( 'wgAjaxLicensePreview' ) && wpLicense ) {
                // License selector check
                wpLicense.onchange = licenseSelectorCheck;
 
@@ -74,8 +78,11 @@ window.wgUploadSetup = function() {
 
 
        // fillDestFile setup
-       for ( var i = 0; i < wgUploadSourceIds.length; i++ )
-               document.getElementById( wgUploadSourceIds[i] ).onchange = function (e) {
+       var     i,
+               uploadSourceIds = mw.config.get( 'wgUploadSourceIds' ),
+               len = uploadSourceIds.length;
+       for ( i = 0; i < len; i += 1 )
+               document.getElementById( uploadSourceIds[i] ).onchange = function (e) {
                        fillDestFilename( this.id );
                };
 };
@@ -89,7 +96,7 @@ window.wgUploadWarningObj = {
        'timeoutID': false,
 
        'keypress': function () {
-               if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) return;
+               if ( !ajaxUploadDestCheck || !sajax_init_object() ) return;
 
                // Find file to upload
                var destFile = document.getElementById('wpDestFile');
@@ -114,7 +121,7 @@ window.wgUploadWarningObj = {
        },
 
        'checkNow': function (fname) {
-               if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) return;
+               if ( !ajaxUploadDestCheck || !sajax_init_object() ) return;
                if ( this.timeoutID ) {
                        window.clearTimeout( this.timeoutID );
                }
@@ -123,7 +130,7 @@ window.wgUploadWarningObj = {
        },
 
        'timeout' : function() {
-               if ( !wgAjaxUploadDestCheck || !sajax_init_object() ) return;
+               if ( !ajaxUploadDestCheck || !sajax_init_object() ) return;
                injectSpinner( document.getElementById( 'wpDestFile' ), 'destcheck' );
 
                // Get variables into local scope so that they will be preserved for the
@@ -168,7 +175,7 @@ window.wgUploadWarningObj = {
 };
 
 window.fillDestFilename = function(id) {
-       if (!wgUploadAutoFill) {
+       if ( !mw.config.get( 'wgUploadAutoFill' ) ) {
                return;
        }
        if (!document.getElementById) {
@@ -197,12 +204,12 @@ window.fillDestFilename = function(id) {
        // Clear the filename if it does not have a valid extension.
        // URLs are less likely to have a useful extension, so don't include them in the
        // extension check.
-       if( wgStrictFileExtensions && wgFileExtensions && id != 'wpUploadFileURL' ) {
+       if ( mw.config.get( 'wgStrictFileExtensions' ) && fileExtensions && id !== 'wpUploadFileURL' ) {
                var found = false;
-               if( fname.lastIndexOf( '.' ) != -1 ) {
+               if ( fname.lastIndexOf( '.' ) !== -1 ) {
                        var ext = fname.substr( fname.lastIndexOf( '.' ) + 1 );
-                       for( var i = 0; i < wgFileExtensions.length; i++ ) {
-                               if( wgFileExtensions[i].toLowerCase() == ext.toLowerCase() ) {
+                       for ( var i = 0; i < fileExtensions.length; i += 1 ) {
+                               if ( fileExtensions[i].toLowerCase() === ext.toLowerCase() ) {
                                        found = true;
                                        break;
                                }
@@ -229,7 +236,7 @@ window.fillDestFilename = function(id) {
        // Replace spaces by underscores
        fname = fname.replace( / /g, '_' );
        // Capitalise first letter if needed
-       if ( wgCapitalizeUploads ) {
+       if ( mw.config.get( 'wgCapitalizeUploads' ) ) {
                fname = fname.charAt( 0 ).toUpperCase().concat( fname.substring( 1, 10000 ) );
        }
 
@@ -253,7 +260,7 @@ window.wgUploadLicenseObj = {
        'responseCache' : { '' : '' },
 
        'fetchPreview': function( license ) {
-               if( !wgAjaxLicensePreview ) return;
+               if ( !mw.config.get( 'wgAjaxLicensePreview' ) ) return;
                for (cached in this.responseCache) {
                        if (cached == license) {
                                this.showPreview( this.responseCache[license] );
@@ -265,7 +272,7 @@ window.wgUploadLicenseObj = {
                var title = document.getElementById('wpDestFile').value;
                if ( !title ) title = 'File:Sample.jpg';
 
-               var url = wgScriptPath + '/api' + wgScriptExtension
+               var url = mw.util.wikiScript( 'api' )
                        + '?action=parse&text={{' + encodeURIComponent( license ) + '}}'
                        + '&title=' + encodeURIComponent( title )
                        + '&prop=text&pst&format=json';
@@ -293,4 +300,6 @@ window.wgUploadLicenseObj = {
 
 };
 
-addOnloadHook( wgUploadSetup );
+$( document ).ready( uploadSetup );
+
+}() );
index 4fb94e6..a619f71 100644 (file)
@@ -69,9 +69,8 @@ window.addOnloadHook = function( hookFunct ) {
 };
 
 window.importScript = function( page ) {
-       // TODO: might want to introduce a utility function to match wfUrlencode() in PHP
-       var uri = wgScript + '?title=' +
-               encodeURIComponent(page.replace(/ /g,'_')).replace(/%2F/ig,'/').replace(/%3A/ig,':') +
+       var uri = mw.config.get( 'wgScript' ) + '?title=' +
+               mw.util.wikiUrlencode( page ) +
                '&action=raw&ctype=text/javascript';
        return importScriptURI( uri );
 };
@@ -90,7 +89,7 @@ window.importScriptURI = function( url ) {
 };
 
 window.importStylesheet = function( page ) {
-       return importStylesheetURI( wgScript + '?action=raw&ctype=text/css&title=' + encodeURIComponent( page.replace(/ /g,'_') ) );
+       return importStylesheetURI( mw.config.get( 'wgScript' ) + '?action=raw&ctype=text/css&title=' + mw.util.wikiUrlencode( page ) );
 };
 
 window.importStylesheetURI = function( url, media ) {
index a95f08a..6b231fc 100644 (file)
@@ -422,7 +422,7 @@ class MWNamespaceTest extends MediaWikiTestCase {
                $this->assertEquals(
                        array( NS_MAIN, NS_USER, NS_CATEGORY ),
                        MWNamespace::getcontentNamespaces(),
-                       'NS_MAIN is forced in wgContentNamespaces even if unwanted'
+                       'NS_MAIN is forced in $wgContentNamespaces even if unwanted'
                );
 
                # test other cases, return $wgcontentNamespaces as is
index 38d6aee..4293d23 100644 (file)
@@ -100,7 +100,7 @@ class UploadTest extends MediaWikiTestCase {
        }
 
        /**
-        * test uploading a 100 bytes file with wgMaxUploadSize = 100
+        * test uploading a 100 bytes file with $wgMaxUploadSize = 100
         *
         * This method should be abstracted so we can test different settings.
         */
index 441302a..ed74c6e 100644 (file)
@@ -136,7 +136,7 @@ class SideBarTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * Test wgNoFollowLinks in sidebar
+        * Test $wgNoFollowLinks in sidebar
         */
        function testRespectWgnofollowlinks() {
                global $wgNoFollowLinks;
@@ -145,7 +145,7 @@ class SideBarTest extends MediaWikiLangTestCase {
 
                $attribs = $this->getAttribs();
                $this->assertArrayNotHasKey( 'rel', $attribs,
-                       'External URL in sidebar do not have rel=nofollow when wgNoFollowLinks = false'
+                       'External URL in sidebar do not have rel=nofollow when $wgNoFollowLinks = false'
                );
 
                // Restore global
@@ -153,7 +153,7 @@ class SideBarTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * Test wgExternaLinkTarget in sidebar
+        * Test $wgExternaLinkTarget in sidebar
         */
        function testRespectExternallinktarget() {
                global $wgExternalLinkTarget;