Page MenuHomePhabricator

Allow scripts to be imported with ImportJS
Closed, DuplicatePublicFeature

Description

Feature summary (what you would like to be able to do and where):

It should be possible to import scripts using ImportJS files. The sitewide ImportJS file (located at MediaWiki:ImportJS) would only permit loading scripts either on-wiki or from certain wikis within the wiki farm (on Wikimedia, this can be English Wikipedia, Wikimedia Commons, Meta-Wiki, and a few other projects with highly watched MediaWiki pages). The ImportJS page would only be editable by interface administrators. Including a local script on an ImportJS page would record the usage as a transclusion. For MediaWiki space, we can couple that with T71445 to ensure that only scripts which other interface administrators have reviewed can be run.

ImportJS-[skin] files would load scripts only for a particular skin.

Likewise, for users, ImportJS and ImportJS-[skin] would import the skin for their user profile and skin respectively. The user ImportJS would permit loading scripts only from MediaWiki: and User: namespaces, as well as on specific wikis in the wiki farm.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):

The CSS/JS incident was caused by an unvetted script being added to a user common.js file which then spread to a sitewide common.js file. This would make it harder since off site scripts cannot be loaded

Benefits (why should this be implemented?):

The two benefits are added security and improved responsiveness, since the scripts can be loaded by load.php, and it could also make it possible to use import statements at the top of scripts also recording transclusions (see T373725).

Event Timeline

Merge as duplicate since the task description (ImportJS) is just a Fandom-specific solution of global gadgets. In Wikimedia there are multiple proposed solutions of global gadgets:

  • The current available one is use mediaWiki.loader.load() to load gadgets from other wikis. To make that a real gadget a local .js page must be created. This does not get full feature of ResourceLoader (e.g. minifier).
  • T298561: Allow files from other wikis in gadget definitions would allow (1) js from other wikis to be used in gadget; (2) to load gadgets from other wikis.
  • Full global gadget support may require Gadget 2.0 to be complete. There needs to be a global repo of gadgets but Wikimedia is currently working on one (Produnto).