Page MenuHomePhabricator

Deprecation status of importScript, importStylesheet, importScriptURI, importStylesheetURI
Closed, ResolvedPublic

Description

Summary for Tech News readers

  • importScriptURI( url ) and importStylesheetURI( url ) functions are deprecated. They have been superseded by ResourceLoader. You should replace their usages with mw.loader.load( url ). The old functions will be removed in the future.
  • importScript( wikiPage ) and importStylesheet( wikiPage ) functions are not deprecated yet. They will be deprecated when a suitable ResourceLoader-based replacement is created. For new scripts, it is recommended to use the Gadgets system instead.

Original bug summary:

These two functions have been on the list of deprecated JavaScript functions for a long time:
https://www.mediawiki.org/wiki/ResourceLoader/Legacy_JavaScript#wikibits.js

If they are in fact deprecated, users should see a warning in the console so that they can start migrating their code to mw.loader.load before these functions are finally removed from MW core.

See also:

Event Timeline

He7d3r assigned this task to Krinkle.
He7d3r raised the priority of this task from to Needs Triage.
He7d3r updated the task description. (Show Details)
He7d3r added subscribers: He7d3r, matmarex, TheDJ.

Change 203293 merged by jenkins-bot:
wikibits: Mark importScript/importStylesheet utilities as deprecated

https://gerrit.wikimedia.org/r/203293

Change 203873 merged by jenkins-bot:
wikibits: Mark importScript/importStylesheet utilities as deprecated

https://gerrit.wikimedia.org/r/203873

Hmm, i'm not sure this is wise...

Something Wikia introduced after upgrading to 1.19 (i.e. have RL support) was importArticles, see http://community.wikia.com/wiki/Help:Including_additional_JavaScript_and_CSS for usage. It allows you to lookup pages by name (much like the now deprecated importScript/importStylesheet) and has all the benefits of RL. I believe it's just a wrapper for importScriptURI (perhaps swap it for mw.loader.load?), but it works really well on Wikia.

Schnark subscribed.

As long as this includes deprecating importScript and importStylesheet (rather than only importScriptURI and importStylesheetURI), I don't feel like this should be assigned to me, sorry.

Oh... I just took the owner of that Gerrit patch for filling in the assigned field on this Phabricator task.

Something Wikia introduced after upgrading to 1.19 (i.e. have RL support) was importArticles, see http://community.wikia.com/wiki/Help:Including_additional_JavaScript_and_CSS for usage. It allows you to lookup pages by name (much like the now deprecated importScript/importStylesheet) and has all the benefits of RL. I believe it's just a wrapper for importScriptURI (perhaps swap it for mw.loader.load?), but it works really well on Wikia.

That importArticles function is not a standalone shortcut for handling page names and interwiki codes. It is a handler for a larger custom framework they installed on their servers as extension to ResourceLoader.

https://github.com/Wikia/app/blob/ed0d816d/resources/wikia/wikia.wikibits.js#L20-L60
https://github.com/Wikia/app/blob/a86ae349/extensions/wikia/ArticlesAsResources/ArticlesAsResources.class.php

It doesn't handle registration or de-duplication. Nor any other features of ResourceLoader such as localisation. It serves mostly to combine and minify http requests. Performance isn't driving this issue however. Anything sufficiently widely used should become a Gadget, which supports ResourceLoader already. What's left is the shortcut syntax. Without a server component, we'd have to send all interwiki codes to the client (doesn't seem like a good idea).

We could use the hostname though. Perhaps something like this:

importFromWiki('commons.wikimedia.org', 'MediaWiki:Rtl.js');

Which would request https://commons.wikimedia.org/w/index.php?title=MediaWiki:Rtl.js&action=raw&ctype=text/javascript.

I still assert that we have no good reason to deprecate these two functions, unless we have a plan or a methodology forward that depends on it. It's pointless to bother someone with deprecation warnings that tell him to rewrite something in a way that is functionally the same as what we had, but more wordy, with more chances of making mistakes.

And I'm sure that Commons will just happily 'undeprecate' the function on its own, continuing to use it in as is, or in a new form, further complicating the landscape. On top of that the issue that we want them to ultimately use 'something else' ANYWAY, so we can ask them to do another rewrite exercise.

This will result in a lot of 'I have better things to do'-style complaints. I don't see the problem in keeping these functions around until we are at a time where they can be replaced with something that offers tru benefits to the user.

I'm with TheDJ. We still don't have a drop-in replacement... Wasn't this supposed to be superceded with GlobalGadgets/ResourceLoader 3.0 (or whatever version)? Until that is here, we should maintain these as (legacy) wrappers for mw.loader.load.

Change 206078 had a related patch set uploaded (by Bartosz Dziewoński):
wikibits: Un-deprecate importScript and importStylesheet

https://gerrit.wikimedia.org/r/206078

matmarex renamed this task from Mark importScript and importStylesheet as deprecated to Mark importScript and importStylesheet as deprecated?.Apr 23 2015, 6:55 AM
matmarex reopened this task as Open.
matmarex added a project: MW-1.25-release.

Change 206078 merged by jenkins-bot:
wikibits: Un-deprecate importScript and importStylesheet

https://gerrit.wikimedia.org/r/206078

Change 206138 had a related patch set uploaded (by Bartosz Dziewoński):
wikibits: Un-deprecate importScript and importStylesheet

https://gerrit.wikimedia.org/r/206138

Change 206138 merged by jenkins-bot:
wikibits: Un-deprecate importScript and importStylesheet

https://gerrit.wikimedia.org/r/206138

matmarex renamed this task from Mark importScript and importStylesheet as deprecated? to Deprecation status of importScript, importStylesheet, importScriptURI, importStylesheetURI.Apr 23 2015, 4:35 PM
matmarex closed this task as Resolved.
matmarex updated the task description. (Show Details)
matmarex updated the task description. (Show Details)
matmarex removed a project: Patch-For-Review.

So, um, I'm seeing these deprecation warnings (for importScript) on Wikidata ... that doesn't seem very resolved.

Use of "importScript" is deprecated. Use mw.loader instead.

I'm seeing the same console message warning for importScript on en.wikipedia too -- mostly when entering an edit session.

It is still being used in their common.js file fwiw...

It hasn't been deployed yet. We could ping a dev to ask for a lightning deploy.

That will teach me to simply gloss over everything. Upon closer inspection - I see the WP roll-out hasn't happened yet though the status here is Closed.

that doesn't seem very resolved.

@SamB: See "Resolved".