Extension:StyleTags

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
StyleTags

Release status: beta

Implementation Tag
Description Use style tags within mediawiki
Author(s) Neil Richards (Neilkttalk)
Latest version 0.1 (12:38, 8 January 2008 (UTC))
MediaWiki 1.10
License Attribution-Share Alike 2.0
Download No link
Example <style> .newTableClass { border-top:1px thin #CCCCCC } </style>
Hooks used
ParserAfterTidy

Translate the StyleTags extension if possible

Check usage and version matrix; code metrics

What can this extension do?[edit | edit source]

This extension allows users to embed <style>...</style> tags within any wiki page. Removes the need to continually dive into CSS files on the server (which may be impractical for what you're trying to achieve).

Very useful when trying to style tables.

There's almost certainly some security risks with this approach, but I shall allow somebody in the community to point these out as it's not relevant for how I'm using it.

Usage[edit | edit source]

<style> //CSS STYLE ELEMENTS </style>

Installation[edit | edit source]

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/EmbedStyleElement.php");

Code[edit | edit source]

<?php
 
$wgHooks['ParserAfterTidy'][] = 'StyleParserAfterTidy';
$wgExtensionFunctions[] = "styleExtSetup";
 
function styleExtSetup() {
    global $wgParser;
    $wgParser->setHook("style", "styleExtParserHook" );
}
 
$markerList = array();
 
function styleExtParserHook($input, $argv, &$parser) {
    global $markerList;
    $output = "<STYLE>".$input."</STYLE>";
    $marker = "xx-marker".count($markerList)."-xx";
    $markerList[] = $output;
    return $marker;
}
 
function StyleParserAfterTidy(&$parser, &$text) {
    // find markers in $text
    // replace markers with actual output
    global $markerList;
    for ($i=0;$i<count($markerList);$i++)
    {
      $text = preg_replace('/xx-marker'.$i.'-xx/',$markerList[$i],$text);
    }
    return true;
}
 
/**
 * EmbedStyleElement.php
 * This extension allows the use of <style></style> tags within a mediawiki page
 * written by Neil Richards
 * http://www.knowledgethoughts.com/blog
 * To activate the functionality of this extension include the following in your
 * LocalSettings.php file:
 * require_once('$IP/extensions/EmbedStyleElement.php');
 */
if(! defined( 'MEDIAWIKI' ) ) {
   echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
   die( -1 );
} else {
 
   $wgExtensionCredits['parserhook'][] = array(
       'name' => 'StyleTags',
       'author' =>'Neil Richards >> http://www.neilrichards.net ; http://www.knowledgethoughts.com/blog/ ; http://del.icio.us/knowledgethoughts', 
       'url' => 'http://www.mediawiki.org/wiki/User:Neilkt',
       'description' => 'This extension allows the use of &lt;style&gt;&lt;/style&gt; tags within a mediawiki page',
       'version'=>'0.1'
       );
 
}

See also[edit | edit source]