Extension:GlobalCssJs
Global CSS/JS Release status: stable |
|
---|---|
Implementation | Skin , MyWiki |
Description | Allows global CSS and JS on a "central" wiki to be loaded for all wikis in the farm |
Author(s) |
|
Latest version | 3.4.0 |
MediaWiki | 1.31+ |
PHP | 7.0+ |
License | GNU General Public License 2.0 or later |
Download | Usage |
Help | Help:Extension:GlobalCssJs |
|
|
Quarterly downloads | 14 (Ranked 115th) |
Translate the GlobalCssJs extension | |
Issues | Open tasks · Report a bug |
The GlobalCssJs extension allows loading CSS and JavaScript (JS) from a central wiki.
It supports wiki farm-wide and individual site-wide "MediaWiki:Global.js"/"MediaWiki:Global.css" pages and per-user "User:$username/global.js"/"User:$username/global.css" pages on a specified central wiki. The term "global" is used to mean across a wiki farm (compare with Extension:GlobalUsage) and the capitalization ("Css" and "Js") is due to MediaWiki extension naming conventions.
Installation
edit- Download and move the extracted
GlobalCssJs
folder to yourextensions/
directory.
Developers and code contributors should install the extension from Git instead, using:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/GlobalCssJs - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'GlobalCssJs' );
- Configure as required.
- Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Configuration
editwgUseGlobalSiteCssJs
editWhether to enable MediaWiki:Global.js/MediaWiki:Global.css pages. By default enabled.
$wgUseGlobalSiteCssJs = true;
wgGlobalCssJsConfig
editResourceLoader configuration of the global wiki. By default, no global wiki is specified.
$wgGlobalCssJsConfig = [
'wiki' => false,
'source' => false,
];
'wiki'
should be set to the database name of the central wiki.'source'
should be the name of the ResourceLoader source.
An example configuration might look like:
$wgGlobalCssJsConfig = [
'wiki' => 'metawiki',
'source' => 'metawiki',
];
// 'source' must point to a key in $wgResourceLoaderSources, like so:
// $wgResourceLoaderSources['metawiki'] = array(
// 'apiScript' => 'https://meta.wikimedia.org/w/api.php',
// 'loadScript' => 'https://meta.wikimedia.org/w/load.php',
//);
To test it out locally without a central repository, point it at the local wiki, like so:
$wgGlobalCssJsConfig = [
'wiki' => $wgDBname,
'source' => 'local',
];
Hook
editIf you are not using shared user tables for managing users, you can use a hook to state whether a user on one wiki is equal to another.
public static function onLoadGlobalCssJs( User $user, $centralWiki, $localWiki );
$centralWiki
is the wiki the JS/CSS is being taken from, and $localWiki
is the current wiki the request is being executed on. The hook will not be called if $centralWiki === $localWiki
.
The function should return true if the users are the same, and false if they are not. An example subscriber can be found in the CentralAuth extension.
Usage
editSee Help:Extension:GlobalCssJs for details.
This extension is being used on one or more Wikimedia projects. This probably means that the extension is stable and works well enough to be used by such high-traffic websites. Look for this extension's name in Wikimedia's CommonSettings.php and InitialiseSettings.php configuration files to see where it's installed. A full list of the extensions installed on a particular wiki can be seen on the wiki's Special:Version page. |
This extension is included in the following wiki farms/hosts and/or packages: This is not an authoritative list. Some wiki farms/hosts and/or packages may contain this extension even if they are not listed here. Always check with your wiki farms/hosts or bundle to confirm. |