Extension:CSS

From MediaWiki.org
Jump to: navigation, search

Other languages:
català • ‎Deutsch • ‎English • ‎British English • ‎español • ‎suomi • ‎français • ‎italiano • ‎日本語 • ‎polski • ‎português • ‎português do Brasil
MediaWiki extensions manual
Crystal Clear action run.png
CSS

Release status: stable

Implementation Parser function
Description A parser-function for adding CSS files, article or inline rules to articles
Author(s) Aran Dunkley, Rusty Burchfield
Latest version 3.1 (2012-01-15)
MediaWiki 1.16.x and above
Database changes No
License GPL v2+
Download
Hooks used
ParserFirstCallInit

RawPageViewBeforeOutput

Translate the CSS extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

Issues:

Open tasks · Report a bug

The CSS extension allows CSS stylesheets to be included in specific articles. The CSS can be another article, a file or can be rules defined directly within the parser-function.

Usage[edit | edit source]

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,

{{#css:MyStyles.css}}

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.

{{#css:/skins/MyStyles.css}}

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

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

Installation[edit | edit source]

Download the latest snapshot and extract it to your extensions directory. Then include it in your LocalSettings.php file as in the following example.

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 = 'http://example.org/stylesheets';  # Relative to a different site

Use as a PageCSS replacement[edit | edit source]

There is a prior Extension:PageCSS 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:

<?php
 
// Stub to remap <css></css> tags to {{#css:}} parser function extension
 
// For use when installing http://www.mediawiki.org/wiki/Extension:CSS 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[edit | edit source]

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.

Bugs[edit | edit source]

See talk page.

Possible Uses[edit | edit source]

Most of the following CSS Snippets were originally created, made, or tested using this extension:

Snippets/Circle or Oval Gallery Who wants just boring square photos when you can made them round or oval?

Snippets/CSS Typing Text Quick Message that "types" itself out on page load.

Snippets/Equal Columns In Mediawiki it's not easy to create columns. This CSS Snippet not only makes it easy, it automatically divides your content into equal length columns.

Snippets/Fading Away Image or Gallery Photo vanishes "back into" the page and then reappears.

Snippets/Image Expand on Hover Images expand when someone "hovers" over them.

Snippets/Image Slideshow created by CSS A slideshow entirely created by CSS

Snippets/Modals in Mediawiki A CSS Modal.

Snippets/Movie Credits Scrolling content that moves up like Movie Credits do.

Snippets/Pinterest Like Gallery Pinterest has proven the popularity of this gallery layout. This Snippet lets you create this galley style inside Mediawiki.

Snippets/Rotating Text Rotating Message

Snippets/Sliding Image, Text or Gallery Sliding content. Great for Landing Pages.

See also[edit | edit source]