From mediawiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
Brett Dutton
Release status: unmaintained
Implementation User interface
Description Creates simple breadcrumbs navigation from wiki pages that have been created in directory like hierarchy using forward slash (/)
Author(s) Brett Dutton
Latest version 1.4.1 (2011-07-12)
MediaWiki 1.14+
License GNU General Public License 2.0
Download see below
Example Output will look something like this at the top of the page: home < foo < bar < ray

Check usage and version matrix.

What can this extension do?[edit]

BrettCrumbs is a play on words for BreadCrumbs Navigation. This form of navigation assumes that you have created your wiki pages in a hierarchy based on the forward slash ("/") character. Used BrettCrumbs name because of vanity and because the BreadCrumbs extensions existed and were plentiful. Unfortunately none did what I needed.


So to use BrettCrumbs Extension install as described below and then create pages using the "/" character to show sub pages

  • create article http://www.yourmediawiki.org?title=foo
  • then create article http://www.yourmediawiki.org?title=foo/bar
  • then create article http://www.yourmediawiki.org?title=foo/bar/ray

On the last page (foo/bar/ray) it will have header:

home < foo < bar < ray

Useful Macro - SubPage[edit]

I created this macro that is useful for creating sub pages. Rather than typing [[foo/bar|/bar]] you can just use the macro {{SubPage|bar}} This becomes useful when you start very deep nesting with long names. To create this macro go to the url http://www.yourmediawiki.org/index.php?title=Template:SubPage&action=edit

This template is used when creating sub-page links off the current page. 
This will give the page hierarchy so that the breadcrumbs will be automatically generated. 
The template can be called in the following ways

* '''<nowiki>{{SubPage|Sub Page Location|Sub Page Name}}</nowiki>''' 
* '''<nowiki>{{SubPage|Sub Page Location}}</nowiki>''' 
*'''Sub Page Location''' The location of the sub-page
*'''Sub Page Name''' (optional) The displayed name of the sub-page

* <nowiki>{{SubPage|SubPage|My Sub Page}}</nowiki> --> {{SubPage|SubPage|My Sub Page}}
* <nowiki>{{SubPage|SubPage}}</nowiki> --> {{SubPage|SubPage}}


Example - Typical Page[edit]

This would be the mark up of a typical page using the SubPage macro defined above

*{{SubPage|New Developers}}
*{{SubPage|Java Virtual Machine Tuning}}
*{{SubPage|Eclipse Set Up}}
*{{SubPage|C Sharp|/C#}}
*{{SubPage|Windows Tricks}}

Download instructions[edit]

Please cut and paste the code found below and place it in $IP/extensions/BrettCrumbs.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php .


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

# Added this to get Breadcrumbs navigation
require_once( "$IP/extensions/BrettCrumbs.php" );

Source Code[edit]

$wgExtensionCredits['parserhook'][] = array(
    'name'=>'BrettCrumbs - Simple Breadcrumbs',
    'author'=>'Brett Dutton, brettcraigdutton at hotmail dot com',
    'description'=>'Simple bread crumbs navigation.',
$wgHooks['OutputPageBeforeHTML'][] = 'BrettCrumbs';

function BrettCrumbs (&$article, &$text) {
    global $wgTitle, $wgScript, $action ;
    if ( $action == 'edit' ) return true;
    if ( $action == 'history' ) return true;
    if ( $wgTitle->getPrefixedText() == 'Main Page' ) return true;
    if ( strpos ( $wgTitle->getPrefixedText(), 'User:' ) === 0 ) return true;
    if ( strpos ( $wgTitle->getPrefixedText(), 'Special:' ) === 0 ) return true;
    if ( strpos ( $wgTitle->getPrefixedText(), 'File:' ) === 0 ) return true;
    $arr = explode ( '/', $wgTitle->getPrefixedText() );
    $arrLen = count ( $arr ) - 1;
    $url = "<small><a href=\"{$wgScript}\">Home</a>";
    $links = '';
    for ( $i=0; $i<$arrLen; $i++ ) {
        if ( ! empty ( $links ) ) $links .= '/';
        $links .= urlencode ( $arr[$i] );
        $url .= " &lt; <a href=\"{$wgScript}?title={$links}\">" . htmlspecialchars($arr[$i]) . '</a>';
    $url .= ' &lt; ' . htmlspecialchars ( $arr[$arrLen] );
    $url .= '</small>';
    $text = $url . $text;
    return true;

See also[edit]