Extension:GlobalCssJs

Aus MediaWiki
Zur Navigation springen Zur Suche springen
MediaWiki extensions manual
Crystal Clear action run.svg
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) Ryan Schmidt, Szymon Świerkosz, Kunal Mehta
Latest version 3.2.0
MediaWiki 1.24+
PHP 5.4+
Database changes No
License GNU General Public License 2.0 or later
Download
Usage
Parameters
  • $wgUseGlobalSiteCssJs
  • $wgGlobalCssJsConfig
Hooks used
BeforePageDisplay
ResourceLoaderRegisterModules
EditPage::showEditForm:initial
GetPreferences
Translate the GlobalCssJs extension
Check usage and version matrix.
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.

Warning Warning: If you are not using shared user tables or CentralAuth, this extension can open up a XSS vector, which allows other users to hijack the user's account, among other things. See #Hook for information on how to integrate your authentication extension with this one.

This extension requires core fixes implemented MediaWiki 1.24. Older versions of the extension will not work, nor will this extension work with older versions of MediaWiki core.

Installation[Bearbeiten]

  • Download and place the file(s) in a directory called GlobalCssJs in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'GlobalCssJs' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

To users running MediaWiki 1.24 or earlier:

The instructions above describe the new way of installing this extension using wfLoadExtension() If you need to install this extension on these earlier versions (MediaWiki 1.24 and earlier), instead of wfLoadExtension( 'GlobalCssJs' );, you need to use:

require_once "$IP/extensions/GlobalCssJs/GlobalCssJs.php";

Configuration[Bearbeiten]

$wgUseGlobalSiteCssJs = true;
  • Whether to enable MediaWiki:Global.js/MediaWiki:Global.css pages. By default enabled.
$wgGlobalCssJsConfig = array(
	'wiki' => false,
	'source' => false,
);
  • ResourceLoader configuration of the global wiki. 'wiki' should be set to the database name of the central wiki, and 'source' should be the name of the ResourceLoader source. An example configuration might look like:
$wgGlobalCssJsConfig = array(
	'wiki' => 'metawiki',
	'source' => 'metawiki',
);
$wgResourceLoaderSources['metawiki'] = array(
	'apiScript' => '//meta.wikimedia.org/w/api.php',
	'loadScript' => '//meta.wikimedia.org/w/load.php',
);

Hook[Bearbeiten]

If 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[Bearbeiten]

See Help:Extension:GlobalCssJs for details.

See also[Bearbeiten]