Phabricator のプロジェクト名 #MediaWiki-extensions-CSS


Jump to navigation Jump to search
This page is a translated version of the page Extension:CSS and the translation is 25% complete.

Other languages:
Bahasa Indonesia • ‎Deutsch • ‎English • ‎català • ‎dansk • ‎español • ‎français • ‎italiano • ‎polski • ‎português • ‎português do Brasil • ‎sicilianu • ‎suomi • ‎中文 • ‎日本語
MediaWiki 拡張機能マニュアル
Crystal Clear action run.svg
リリースの状態: 安定
実装 Parser function
説明 A parser-function for adding CSS files, article or inline rules to articles
作者 Aran Dunkley, Rusty Burchfield
最新バージョン 3.5.0 (2017-06-06)
MediaWiki 1.25+
データベースの変更 いいえ
ライセンス GNU General Public License 2.0 or later
Organised Design
RawPageViewBeforeOutput で翻訳を利用できる場合は、CSS 拡張機能の翻訳にご協力ください
使用状況とバージョン マトリクスを確認してください。
問題点 未解決のタスク · バグを報告



For example, if you have a CSS article called "MyStyles.css", which are the styles intended for use with the article "MyFancyUserPage", you would add the following parser-function syntax to the latter,


If on the other hand "MyStyles.css" was a file in the /wiki/skins directory, then it would be included as shown below. Note that the file must be an absolute path with a leading slash to distinguish it from an article title.


Alternatively, CSS rules can be directly included within the parser-function (inline) as in the following example,

  body {
    background: yellow;
    font-size: 20pt;
    color: red;


  • ダウンロードして、ファイルを extensions/ フォルダー内の CSS という名前のディレクトリ内に配置します。
  • 以下のコードを LocalSettings.php の末尾に追加します:
    wfLoadExtension( 'CSS' );
  • Yes 完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。

MediaWiki 1.29 以前を稼働させている利用者へ:

上記の手順では、wfLoadExtension() を使用してこの拡張機能をインストールする新しい方法を記載しています。 この拡張機能をこれらの過去のバージョン (MediaWiki 1.29 以前) にインストールする必要がある場合は、wfLoadExtension( 'CSS' ); の代わりに以下を使用する必要があります:

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


Optionally, you can set the base URL for external files.

$wgCSSPath = false;  # Default, relative to $wgScriptPath
$wgCSSPath = '';  # Relative to the root of your server
$wgCSSPath = '';  # Relative to a different site

Use as a PageCSS replacement

There is a prior Extension:PageCSS (now archived) which used <css> and </css> tags instead of the #css: parser function. This extension can do most of what those extensions provide, but the syntax is incompatible. One way to avoid breaking existing pages which still use the old <css> tags is to use both this Extension:CSS and Extension:NewPageCSS on the same wiki.

An alternate solution (if you want to use only this extension, but have existing content which expects Extension:PageCSS) is to save this stub function as a PHP file and include it from your LocalSettings.php to remap <css> to #css:


// Stub to remap <css></css> tags to {{#css:}} parser function extension

// For use when installing to replace Extension:NewPageCSS on existing wikis

$wgHooks['ParserFirstCallInit'][] = 'wfCSSParserStubInit';
// Hook our callback function into the parser
function wfCSSParserStubInit( Parser $parser ) {

        // When the parser sees the <css> tag, it executes the stub wfCSSTagRender function (below) to invoke the {{#css:}} parser
        $parser->setHook( 'css', 'wfCSSTagRender' );
        return true;
// Execute <css> tag
function wfCSSTagRender( $input, array $args, Parser $parser, PPFrame $frame ) {

        // Stub function, just redirect the user-provided input text blindly to the {{#css:}} parser function to re-parse it as wikitext
        $output = $parser->recursiveTagParse('{{#css:' . $input . '}}', $frame);
        return $output;

At this point, the prior PageCSS (or NewPageCSS) extensions may be removed from your configuration; <css> now goes to #css: and (if you have this CSS extension already up and running) will behave the way any of the other CSS extensions always have.

Problems with changing the color or background of a specific page

Using the parser function to use the CSS from another page does not work to change the color or background of the page, however, using the parser function on a single page by itself does allow the background to be changed. To overcome this problem, it is possible to load the CSS through transclusion, which does not cause the problem of failing to load the change to the page background.