MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
Release status: unmaintained
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
Latest version 1.1 (2008-10-22)
MediaWiki 1.8+
Database changes No
License GNU General Public License 2.0

Check usage and version matrix.

The StyleByHeaderTree extension 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.


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 of rules file


  is: Introduction
    class: intro

  match: ^Question [0-9]+$
    id: question-[COUNTER]
    class: question

  is: Answer
    class: answer

  match: ^Code\s+(.*)$
    class: code-$1


  • Download, extract and place the file(s) in a directory called headerTree in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/headerTree/headerTree.php";
    $wgHooks['OutputPageBeforeHTML'][] = array(
        new HeaderTree(),
        //change this string according to your new rules file's path
  • Create a new .yml rules file fitting your needs.
  • Edit your wiki's MediaWiki:Monobook.css to use the new classes and id.
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.