Last modified: 2014-08-29 02:04:55 UTC
We want to do some simple checks and redirect users in some cases (by setting window.location), but doing it in site JS creates a flash of the original page currently.
(In reply to comment #0) > We want to do some simple checks and redirect users in some cases Could you elaborate on that?
(In reply to comment #1) > (In reply to comment #0) > > We want to do some simple checks and redirect users in some cases > > Could you elaborate on that? From [[zh:MediaWiki:Common.js]]: mw.loader.using(['mediawiki.Uri'], function() { /* Search Engine variant hack */ var ref, loc; try { ref = new mw.Uri( document.referrer ); loc = new mw.Uri( location.href ); } catch ( e ) { return; } if (/\.google\./.test(ref.host) && /\/zh(-[^/]+)?\//.test(loc.path)) { loc.path = loc.path.replace(/\/zh(-[^/]+)?\//, "/wiki/"); location = loc.toString(); } } );
You can do this with a gadget now using the 'top' option, see e.g. on [[pl:MediaWiki:Gadgets-definition]]; see bug 27488. (Also, I think this is a dupe of that bug.) Not sure if we really want this in core.
(Relevant line is " main-page [ResourceLoader | top | default] | main-page.js | main-page.css".)
Shouldn't we just fix the search behavior with variants rather than using site JS here anyway?
Common.js is feature-locked as far as I'm concerned. It loads at the bottom and in the global scope. For anything else, use Gadgets. You can create a gadget with position=top.