Extension:StyleTags

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

Release status:Extension status beta

ImplementationTemplate:Extension#type Tag
DescriptionTemplate:Extension#description Use style tags within mediawiki
Author(s)Template:Extension#username Neil Richards (Neilkttalk)
Latest versionTemplate:Extension#version 0.1 (12:38, 8 January 2008 (UTC))
MediaWikiTemplate:Extension#mediawiki 1.10
LicenseTemplate:Extension#license Attribution-Share Alike 2.0
Download No link
ExampleTemplate:Extension#example <style> .newTableClass { border-top:1px thin #CCCCCC } </style>
Hooks usedTemplate:Extension#hook
ParserAfterTidyManual:Hooks/ParserAfterTidy

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

Check usage and version matrix.

What can this extension do?[edit]

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]

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

Installation[edit]

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

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

Code[edit]

<?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]