Page MenuHomePhabricator

Give site JS a chance (maybe in another NS_MEDIAWIKI page) to load at position=top
Closed, DeclinedPublic

Description

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.


Version: 1.22.0
Severity: enhancement
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=27488

Details

Reference
bz52797

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 2:11 AM
bzimport set Reference to bz52797.
bzimport added a subscriber: Unknown Object (MLST).

(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.