Extension:StyleTags

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
StyleTags

Release status: beta

Implementation Tag
Description Use style tags within mediawiki
Author(s) Neil Richards (NeilktTalk)
Last 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>

Contents

[edit] What can this extension do?

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.

[edit] Usage

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

[edit] Installation

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

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

[edit] Code

<?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'
       );
 
}

[edit] See also

Personal tools