Extension:StyleByHeaderTree

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

Release status: stable

Implementation Page action
Description Wraps sections according to header hierarchy. Gives class and id to the wrapping divs according to section title.
Author(s) François Moreau
Last version 1.0
MediaWiki 1.8+
License GPL
Download http://sourceforge.net/projects/htmlheaderstree/
Hooks used
OutputPageBeforeHTML
Check usage and version matrix

Contents

Introduction [edit]

StyleByHeaderTree does two things to rendered xhtml pages:

  • it wraps each section according to the nesting hierarchy of their respective headers;
  • it may give a class and/or an id to each wrapping div, depending on the header's content and the set of rules defined for the plugin.


Use [edit]

This is useful for styling, javascripting and adding semantics. This allows for a richer presentation without additional intervention from the authors, as long as certain conventions exist regarding section headers. In our organization, we have used this primarily as a mean to bring stronger semantics to wiki pages, which was then used to produce XML content with further extensions.

The directives associating headers with classes and id are written in a YAML file. Each rule specifies what class and id will be given to the created wrappers' header matching a regular expression or an exact string.

Your Wiki's MediaWiki:Monobook.css may then be edited to give style to the containers according to their classes and id.

Example [edit]

StyleByHeaderExtensionExample.png

Example of rules file [edit]

extensions/headerTree/example.yml:

intro:
  is: Introduction
  attr:
    class: intro
 
question:
  match: ^Question [0-9]+$
  attr:
    id: question-[COUNTER]
    class: question
 
answer:
  is: Answer
  attr:
    class: answer
 
code-color:
  match: ^Code\s+(.*)$
  attr:
    class: code-$1

Installation [edit]

Download the extension and unzip it in your mediawiki's extensions/ folder.

Append the following to LocalSettings.php:

require_once("$IP/extensions/headerTree/headerTree.php");
$wgHooks['OutputPageBeforeHTML'][] = array(
    new HeaderTree(),
    'apply',
    //change this string according to your new rules file's path
    "$IP/extensions/headerTree/example.yml");

Create a new .yml rules file fitting your needs.

Edit your Wiki's MediaWiki:Monobook.css to use the new classes and id.