Omit 'window.' when accessing browsing location
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 19 Nov 2014 00:11:04 +0000 (00:11 +0000)
committerKrinkle <krinklemail@gmail.com>
Wed, 19 Nov 2014 00:13:51 +0000 (00:13 +0000)
The location object is a global, just like document.

Using it via 'window' needlessly adds complexity and, for example,
makes it harder to catch typos in static analysis.

Also standardise on location.href in place of the many different
variants, like:

 location =
 location.href =
 location.assign() =

And each with 'window', 'document' and without host object.

Change-Id: I77510294d8b5bd4b8a1b08e06817762a7839d43d

includes/installer/WebInstallerPage.php
resources/src/mediawiki.page/mediawiki.page.ready.js
resources/src/mediawiki.special/mediawiki.special.javaScriptTest.js
resources/src/mediawiki.special/mediawiki.special.preferences.js
resources/src/mediawiki/mediawiki.Uri.js
resources/src/mediawiki/mediawiki.util.js

index d507303..9ecb24b 100644 (file)
@@ -1463,7 +1463,7 @@ class WebInstallerComplete extends WebInstallerPage {
                        strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false
                ) {
                        // JS appears to be the only method that works consistently with IE7+
-                       $this->addHtml( "\n<script>jQuery( function () { document.location = " .
+                       $this->addHtml( "\n<script>jQuery( function () { location.href = " .
                                Xml::encodeJsVar( $lsUrl ) . "; } );</script>\n" );
                } else {
                        $this->parent->request->response()->header( "Refresh: 0;url=$lsUrl" );
index 246cc81..36eb9d4 100644 (file)
@@ -7,7 +7,7 @@
                // it works only comparing to window.self or window.window (http://stackoverflow.com/q/4850978/319266)
                if ( window.top !== window.self ) {
                        // Un-trap us from framesets
-                       window.top.location = window.location;
+                       window.top.location.href = location.href;
                }
        }
 
index d3e8f29..3dd65fb 100644 (file)
@@ -25,7 +25,7 @@
                        // Bind onchange event handler and append to form
                        $html.append(
                                $( select ).change( function () {
-                                       window.location = QUnit.url( { useskin: $( this ).val() } );
+                                       location.href = QUnit.url( { useskin: $( this ).val() } );
                                } )
                        );
 
index 1f6429b..043d769 100644 (file)
@@ -57,7 +57,7 @@ jQuery( function ( $ ) {
                // therefore save and restore scrollTop to prevent jumping.
                scrollTop = $( window ).scrollTop();
                if ( mode !== 'noHash' ) {
-                       window.location.hash = '#mw-prefsection-' + name;
+                       location.hash = '#mw-prefsection-' + name;
                }
                $( window ).scrollTop( scrollTop );
 
@@ -127,7 +127,7 @@ jQuery( function ( $ ) {
 
        // If we've reloaded the page or followed an open-in-new-window,
        // make the selected tab visible.
-       hash = window.location.hash;
+       hash = location.hash;
        if ( hash.match( /^#mw-prefsection-[\w\-]+/ ) ) {
                switchPrefTab( hash.replace( '#mw-prefsection-', '' ) );
        }
@@ -142,7 +142,7 @@ jQuery( function ( $ ) {
                ( document.documentMode === undefined || document.documentMode >= 8 )
        ) {
                $( window ).on( 'hashchange', function () {
-                       var hash = window.location.hash;
+                       var hash = location.hash;
                        if ( hash.match( /^#mw-prefsection-[\w\-]+/ ) ) {
                                switchPrefTab( hash.replace( '#mw-prefsection-', '' ) );
                        } else if ( hash === '' ) {
index 5566312..bb5ddfc 100644 (file)
                 * @param {Object|string} [uri] URI string, or an Object with appropriate properties (especially
                 *  another URI object to clone). Object must have non-blank `protocol`, `host`, and `path`
                 *  properties. If omitted (or set to `undefined`, `null` or empty string), then an object
-                *  will be created for the default `uri` of this constructor (`document.location` for
-                *  mw.Uri, other values for other instances -- see mw.UriRelative for details).
+                *  will be created for the default `uri` of this constructor (`location.href` for mw.Uri,
+                *  other values for other instances -- see mw.UriRelative for details).
                 * @param {Object|boolean} [options] Object with options, or (backwards compatibility) a boolean
                 *  for strictMode
                 * @param {boolean} [options.strictMode=false] Trigger strict mode parsing of the url.
                return Uri;
        };
 
-       // If we are running in a browser, inject the current document location (for relative URLs).
-       if ( document && document.location && document.location.href ) {
-               mw.Uri = mw.UriRelative( document.location.href );
-       }
+       // Default to the current browsing location (for relative URLs).
+       mw.Uri = mw.UriRelative( location.href );
 
 }( mediaWiki, jQuery ) );
index a53cbcb..cf56f29 100644 (file)
                 * Returns null if not found.
                 *
                 * @param {string} param The parameter name.
-                * @param {string} [url=document.location.href] URL to search through, defaulting to the current document's URL.
+                * @param {string} [url=location.href] URL to search through, defaulting to the current browsing location.
                 * @return {Mixed} Parameter value or null.
                 */
                getParamValue: function ( param, url ) {
                        if ( url === undefined ) {
-                               url = document.location.href;
+                               url = location.href;
                        }
                        // Get last match, stop at hash
                        var     re = new RegExp( '^[^#]*[&?]' + $.escapeRE( param ) + '=([^&#]*)' ),