r99446 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99445‎ | r99446 | r99447 >
Date:23:29, 10 October 2011
Author:neilk
Status:ok (Comments)
Tags:
Comment:
ensure tests for mw.Uri work in non-browser environments
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.Uri.js (modified) (history)
  • /trunk/phase3/tests/jasmine/spec/mediawiki.Uri.spec.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/jasmine/spec/mediawiki.Uri.spec.js
@@ -1,5 +1,10 @@
22 ( function() {
33
 4+ // ensure we have a generic URI parser if not running in a browser
 5+ if ( !mw.Uri ) {
 6+ mw.Uri = mw.UriRelative( 'http://sample.com/' );
 7+ }
 8+
49 describe( "mw.Uri", function() {
510
611 describe( "should work well in loose and strict mode", function() {
Index: trunk/phase3/resources/mediawiki/mediawiki.Uri.js
@@ -275,9 +275,9 @@
276276 return Uri;
277277 };
278278
279 - // inject the current document location, for relative URLs
280 - mw.Uri = mw.UriRelative( document.location.href );
 279+ // if we are running in a browser, inject the current document location, for relative URLs
 280+ if ( document && document.location && document.location.href ) {
 281+ mw.Uri = mw.UriRelative( document.location.href );
 282+ }
281283
282 -
283 -
284284 } )( jQuery, mediaWiki );

Follow-up revisions

RevisionCommit summaryAuthorDate
r104643use example.com, the RFC-2606 guaranteed example url. followup to r99446neilk01:41, 30 November 2011
r106262MFT r99944, r99446, 102616 update mediawiki.Uri.js to handle protocol-relativ...neilk22:20, 14 December 2011

Comments

#Comment by Raindrift (talk | contribs)   17:38, 31 October 2011

The usual example domain is example.com, or so says RFC 2606. sample.com is real (though it's just squatted at the moment)

#Comment by Krinkle (talk | contribs)   00:28, 30 November 2011
-	mw.Uri = mw.UriRelative( document.location.href );
+	// 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 );
+	}

This means when ran in certain environments, loading the mediawiki.Uri module does not result in mw.Uri being defined.

That's a bit odd ? Perhaps it's the environments responsibility to provide a mock window.document, or we could let it fallback to an example inside the module.

Thoughts ?

#Comment by NeilK (talk | contribs)   01:33, 30 November 2011

Well, it's a bit of a mental adjustment maybe, but this module is sort of saying that all URIs on MediaWiki are relative now. Which they are, because now MediaWiki is protocol-relative everywhere.

So mw.Uri is purely a convenience -- it really is kind of like mw.UrisThatMatchTheCurrentProtocol.

In any case we are talking about things that absolutely don't matter to the site, only to testing. I don't care either way.

Status & tagging log