Extension:UseResource/en
UseResource Release status: stable |
|
---|---|
Implementation | Tag |
Description | Load JS and CSS in the MediaWiki namespace on a per-page basis. |
Author(s) | Brandon Fowler (BrandonXLFtalk) |
Compatibility policy | Snapshots releases along with MediaWiki. Master is not backward compatible. |
MediaWiki | 1.35+ |
PHP | 7+ |
License | No license specified |
Download | |
<usestyle src=...>...</usestyle> |
|
Quarterly downloads | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
Public wikis using | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
Translate the UseResource extension if it is available at translatewiki.net | |
Issues | Open tasks · Report a bug |
The UseResource extension adds the <usescript>
and <usestyle>
tags that allow JavaScript and CSS to be loaded from the MediaWiki namespace on a per-page basis.
When used in a template, pages that use the template will load the JS/CSS, this allows for the loading of scripts and stylesheets only used on some pages to be only loaded on the pages they are used on rather than being loaded on all pages using MediaWiki:Common.js and MediaWiki:Common.css or Extension:Gadgets.
Scripts can only be loaded from the MediaWiki namespace to prevent malicious code from being run, if you desire a way for user to edit stylesheets that only affect the content area, see Extension:TemplateStyles.
Installation
- <translate> [[<tvar name=2>Special:ExtensionDistributor/UseResource/en</tvar>|Download]] and move the extracted <tvar name=name>
UseResource/en
</tvar> folder to your <tvar name=ext>extensions/
</tvar> directory.</translate>
<translate> Developers and code contributors should install the extension [[<tvar name=git>Special:MyLanguage/Download from Git</tvar>|from Git]] instead, using:</translate>cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/UseResource%2Fen - <translate> Add the following code at the bottom of your <tvar name=1>LocalSettings.php </tvar> file:</translate>
wfLoadExtension( 'UseResource/en' );
- File:OOjs UI icon check-constructive.svg <translate> Done</translate> – <translate> Navigate to <tvar name=special>Special:Version</tvar> on your wiki to verify that the extension is successfully installed.</translate>
Usage
The extension is used by including <usescript src="..." />
or <usestyle src="..." />
tags on wiki pages to load the resource (script or stylesheet), replacing ...
with the name of the resource.
Resources must be located in the MediaWiki namespace and can only be edited by uses with the editinterface
user right as they are the only users allowed to edit pages in the MediaWiki namespace.
The value of the src
attribute is the name of the resource to load.
If no namespace is included, the MediaWiki namespace is assumed.
For example, if you had a script located at MediaWiki:Test.js, you could load it using <usescript src="test.js" />
.
This will fail if the requested script does not exist, is not located in the MediaWiki namespace, or if it does not have the correct content model, JavaScript for scripts and CSS for stylesheets.
If the same resource is included on a single page multiple times, it is only run once.