Page MenuHomePhabricator

importScript() not working on mobile site
Closed, InvalidPublic

Description

https://en.m.wikipedia.org/wiki/Resonator

importScript('User:Alexis Jazz/Hammertime.js');
ReferenceError: importScript is not defined

Works fine on https://en.wikipedia.org/wiki/Resonator though.

According to mediawiki.org this should be part of MediaWiki, so I'd expect this to work.

Event Timeline

Restricted Application added a project: Performance-Team. · View Herald TranscriptOct 9 2020, 10:44 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Jdlrobson closed this task as Invalid.Oct 9 2020, 2:22 PM
Jdlrobson added a subscriber: Jdlrobson.

ImportScript has been deprecated since 1.29 and thus doesnt work on mobile.
Use mw.loader instead for these scripts.

@Jdlrobson Thanks for the info. I'm afraid this means there is no way (that isn't deprecated) to load a userscript without the "ugly" index.php URL?

You can always create a wrapper function in MediaWiki:Common.js or local to your script for readability.

function loadScript( title ) {
  mw.loader.load( '/w/index.php?title=' + title + '&action=raw&ctype=text/javascript' );
}
loadScript('User:jdlrobson/script.js')

You can always create a wrapper function in MediaWiki:Common.js or local to your script for readability.

function loadScript( title ) {
  mw.loader.load( '/w/index.php?title=' + title + '&action=raw&ctype=text/javascript' );
}
loadScript('User:jdlrobson/script.js')

Thanks for the suggestion, but that would hamper cross-wiki compatibility of scripts. It would be nice if MediaWiki supported a way out of the box to load a script by referencing its wiki title.