ResourceLoader/Foreign resources

MediaWiki provides a standard way of handling foreign frontend resources (local copies of upstream libraries registered as ResourceLoader modules), by defining them in a file called. This allows keeping track of and displaying which version of upstream projects is used.

MediaWiki foreign resources can be found in the  directory; extensions and skins can use the   top-level  /  field to provide the directory (relative to the extension/skin root). That directory needs to contain the  specifying what resources are used. The manageForeignResources.php maintenance script can be used to install, upload or verify the resources.

How to install a foreign resource

 * 1) Add or update the url(s) for the upstream module in  .  Look at other modules for examples. To install a module from npm,  we use the tarball distribution from npmjs.org. This is the same as what the npm CLI uses. For example, to install , use.
 * 2) If the upstream maintainers publish an integrity hash, set that as well.  Otherwise, use   to compute the integrity hash. Run   - this will download the specified file(s) and print their integrity hashes, already formatted in YAML, ready for copying to this file.
 * 3) Last but not least, decide where files go.  If you specified a direct url to JavaScript or CSS file, this step is optional. See the corresponding documentation section below for more information and examples for   keys. Once you've set any   keys, run.

foreign-resources.yaml format

 * See resources/lib/foreign-resources.yaml for up-to-date documentation

Each top-level key must use one of these types:
 * : For a plain file.
 * : For multiple plain files.
 * : For a tarball archive (file may be compressed).

The "file" type

 * : SPDX license identifier
 * : [optional] Homepage URL of library shown on Special:Version
 * : [optional] Version string of library shown on Special:Version
 * : Full URL to the remote resource.
 * : SRI cryptographic hash.
 * : [optional] The file name to use in the module directory. Default: Basename of URL.

For example, the following would produce :

The "multi-file" type

 * : SPDX license identifier
 * : [optional] Homepage URL of library shown on Special:Version
 * : [optional] Version string of library shown on Special:Version
 * : An object mapping destination paths to  and   keys.

For example:

The "tar" type

 * : SPDX license identifier
 * : [optional] Homepage URL of library shown on Special:Version
 * : [optional] Version string of library shown on Special:Version
 * : Full URL to the remote resource.
 * : SRI cryptographic hash (integrity metadata format.
 * : [optional] The default is to extract all files from the package.

To only extract some of the files or directories, use  to specify files, directories, and/or glob patterns. You can use a site like https://unpkg.com/ to easily inspect an npm package, like.

For example:

The above would extract the  file, the   directory (recursive), and any   files from the   directory.