Extension:BrettCrumbs

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
Brett Dutton

Release status: stable

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 (12 July 2011)
MediaWiki 1.14+
License GPL
Download see below
Example Output will look something like this at the top of the page: home < foo < bar < ray
Parameters

see below

Hooks used
OutputPageBeforeHTML

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

Check usage and version matrix; code metrics

What can this extension do?[edit | edit source]

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.

Usage[edit | edit source]

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 | edit source]

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

[[{{FULLPAGENAME}}/{{{1}}}|{{{2|/{{{1}}}}}}]]<noinclude>
==Instructions==
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>''' 
 
Args:
*'''Sub Page Location''' The location of the sub-page
*'''Sub Page Name''' (optional) The displayed name of the sub-page

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

[[Category:WikiTemplates]]
</noinclude>

Example - Typical Page[edit | edit source]

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

[[Category:Developer]]
*{{SubPage|New Developers}}
*{{SubPage|Java Virtual Machine Tuning}}
*{{SubPage|Eclipse Set Up}}
*{{SubPage|C Sharp|/C#}}
*{{SubPage|Windows Tricks}}
*{{SubPage|PHP}}
*{{SubPage|JavaScript}}

Download instructions[edit | edit source]

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.

Installation[edit | edit source]

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 | edit source]

 1 <?php
 2 $wgExtensionCredits['parserhook'][] = array(
 3     'name'=>'BrettCrumbs - Simple Breadcrumbs',
 4     'url'=>'http://www.mediawiki.org/wiki/Extension:BrettCrumbs',
 5     'author'=>'Brett Dutton, brettcraigdutton at hotmail dot com',
 6     'description'=>'Simple bread crumbs navigation.',
 7     'version'=>'1.4.1'
 8 );
 9 $wgHooks['OutputPageBeforeHTML'][] = 'BrettCrumbs';
10 
11 function BrettCrumbs (&$article, &$text) {
12     global $wgTitle, $wgScript, $action ;
13  
14     if ( $action == 'edit' ) return true;
15     if ( $action == 'history' ) return true;
16     if ( $wgTitle->getPrefixedText() == 'Main Page' ) return true;
17     if ( strpos ( $wgTitle->getPrefixedText(), 'User:' ) === 0 ) return true;
18     if ( strpos ( $wgTitle->getPrefixedText(), 'Special:' ) === 0 ) return true;
19     if ( strpos ( $wgTitle->getPrefixedText(), 'File:' ) === 0 ) return true;
20  
21     $arr = explode ( '/', $wgTitle->getPrefixedText() );
22  
23     $arrLen = count ( $arr ) - 1;
24  
25     $url = "<small><a href=\"{$wgScript}\">Home</a>";
26     $links = '';
27     for ( $i=0; $i<$arrLen; $i++ ) {
28         if ( ! empty ( $links ) ) $links .= '/';
29         $links .= urlencode ( $arr[$i] );
30         $url .= " &lt; <a href=\"{$wgScript}?title={$links}\">" . htmlspecialchars($arr[$i]) . '</a>';
31     }
32     $url .= ' &lt; ' . htmlspecialchars ( $arr[$arrLen] );
33     $url .= '</small>';
34  
35     $text = $url . $text;
36  
37     return true;
38 }

See also[edit | edit source]