Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/174321
Change subject: Omit 'window.' when accessing browsing location
......................................................................
Omit 'window.' when accessing browsing location
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.
Change-Id: I77510294d8b5bd4b8a1b08e06817762a7839d43d
---
M includes/installer/WebInstallerPage.php
M resources/src/mediawiki.page/mediawiki.page.ready.js
M resources/src/mediawiki.special/mediawiki.special.javaScriptTest.js
M resources/src/mediawiki.special/mediawiki.special.preferences.js
M resources/src/mediawiki/mediawiki.Uri.js
M resources/src/mediawiki/mediawiki.util.js
6 files changed, 12 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/21/174321/1
diff --git a/includes/installer/WebInstallerPage.php
b/includes/installer/WebInstallerPage.php
index d507303..9ecb24b 100644
--- a/includes/installer/WebInstallerPage.php
+++ b/includes/installer/WebInstallerPage.php
@@ -1463,7 +1463,7 @@
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" );
diff --git a/resources/src/mediawiki.page/mediawiki.page.ready.js
b/resources/src/mediawiki.page/mediawiki.page.ready.js
index 246cc81..36eb9d4 100644
--- a/resources/src/mediawiki.page/mediawiki.page.ready.js
+++ b/resources/src/mediawiki.page/mediawiki.page.ready.js
@@ -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;
}
}
diff --git
a/resources/src/mediawiki.special/mediawiki.special.javaScriptTest.js
b/resources/src/mediawiki.special/mediawiki.special.javaScriptTest.js
index d3e8f29..3dd65fb 100644
--- a/resources/src/mediawiki.special/mediawiki.special.javaScriptTest.js
+++ b/resources/src/mediawiki.special/mediawiki.special.javaScriptTest.js
@@ -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() } );
} )
);
diff --git a/resources/src/mediawiki.special/mediawiki.special.preferences.js
b/resources/src/mediawiki.special/mediawiki.special.preferences.js
index 1f6429b..043d769 100644
--- a/resources/src/mediawiki.special/mediawiki.special.preferences.js
+++ b/resources/src/mediawiki.special/mediawiki.special.preferences.js
@@ -57,7 +57,7 @@
// 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 @@
// 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 @@
( 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 === '' ) {
diff --git a/resources/src/mediawiki/mediawiki.Uri.js
b/resources/src/mediawiki/mediawiki.Uri.js
index 5566312..bb5ddfc 100644
--- a/resources/src/mediawiki/mediawiki.Uri.js
+++ b/resources/src/mediawiki/mediawiki.Uri.js
@@ -147,8 +147,8 @@
* @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.
@@ -395,9 +395,7 @@
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 ) );
diff --git a/resources/src/mediawiki/mediawiki.util.js
b/resources/src/mediawiki/mediawiki.util.js
index a53cbcb..cf56f29 100644
--- a/resources/src/mediawiki/mediawiki.util.js
+++ b/resources/src/mediawiki/mediawiki.util.js
@@ -151,12 +151,12 @@
* 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 ) + '=([^&#]*)' ),
--
To view, visit https://gerrit.wikimedia.org/r/174321
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I77510294d8b5bd4b8a1b08e06817762a7839d43d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits