r96699 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96698‎ | r96699 | r96700 >
Date:22:03, 9 September 2011
Author:brion
Status:ok (Comments)
Tags:
Comment:
Provisional workaround for bug 30825 as it affects things run via $.ajax() using protocol-relative links built from wgServer etc -- IE 7 gets confused and denies access for protocol-relative URLs on XMLHTTPRequest, while it's ok everywhere else.
This is already internally fixed in jQuery 1.6, so won't be needed on 1.18 and later.
Modified paths:
  • /branches/wmf/1.17wmf1/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/resources/mediawiki/mediawiki.js
@@ -54,6 +54,22 @@
5555 });
5656
5757 /*
 58+ * Workaround for API hits with protocol-relative URLs on IE 7 and jQuery 1.4
 59+ */
 60+(function(jQuery) {
 61+ var origAjax = jQuery.ajax;
 62+ jQuery.ajax = function(origSettings) {
 63+ var settings = jQuery.extend({}, origSettings);
 64+ if ('url' in settings && settings.url.substring(0, 2) == '//' && typeof window.location == "object" && 'protocol' in window.location) {
 65+ // IE 7's XMLHTTPRequest gets confused by protocol-relative links.
 66+ // Resolve it for the poor dears!
 67+ settings.url = window.location.protocol + settings.url;
 68+ }
 69+ return origAjax(settings);
 70+ };
 71+})(jQuery);
 72+
 73+/*
5874 * Core MediaWiki JavaScript Library
5975 */
6076

Follow-up revisions

RevisionCommit summaryAuthorDate
r97404Move the mediawiki.test.bug30825.js helper script out of the /suites/ directo...krinkle04:50, 18 September 2011
r101356fix mediawiki.test wrong URL...hashar13:53, 31 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96679MFT r87986 -- consolidation of addScript in mediawiki.loader, also fixes bug ...brion18:39, 9 September 2011
r96680Followup r87986: qunit test case for bug 30825...brion18:43, 9 September 2011

Comments

#Comment by NeilK (talk | contribs)   23:31, 9 September 2011

Tested this on every browser in every way I could think of, with my local production setup, which more or less duplicates some of the complexity of real sites. It's a neat solution and seems like it will work.

#Comment by Raindrift (talk | contribs)   23:42, 9 September 2011

Worth noting: when jQuery 1.6 accesses window.location, it does it this way:

var ajaxLocation;
// #8138, IE may throw an exception when accessing
// a field from window.location if document.domain has been set
try {
	ajaxLocation = location.href;
} catch( e ) {
	// Use the href attribute of an A element
	// since IE will modify it given document.location
	ajaxLocation = document.createElement( "a" );
	ajaxLocation.href = "";
	ajaxLocation = ajaxLocation.href;
}

Here is the issue in the jQuery bug tracker: http://bugs.jquery.com/ticket/8138

I'm not clear on whether this will affect MediaWiki, but we may want to do the same thing (but with .protocol instead of .href, of course).

Status & tagging log