Extension:BrettCrumbs

From MediaWiki.org

Jump to: navigation, search

             

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
Brett Dutton

Release status: stable

Implementation  User interface
Description Creates simple breadcrumbs navigation based on "/"
Author(s)  Brett Dutton
Last Version  1.3.1 (11 May 2009)
MediaWiki  1.13+
License GPL
Download see below

check usage (experimental)

Contents

[edit] What can this extension do?

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.

[edit] Usage

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

  • create article http://www.mediawiki.org/foo
  • then create article http://www.mediawiki.org/foo/bar
  • then create article http://www.mediawiki.org/foo/bar/ray

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

home < foo < bar < ray

[edit] Useful Macro - SubPage

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.

[[{{PAGENAME}}/{{{1}}}|{{{2|/{{{1}}}}}}]]<noinclude>
===Instructions===
This creates a link to a sub page off the current page.

<nowiki>{{SubPage|SubLocation|SubpageName}}</nowiki>
gives: {{SubPage|SubLocation|SubpageName}}

or: <nowiki>{{SubPage|SubLocation}}</nowiki>
gives: {{SubPage|SubLocation}}
[[Category:WikiTemplates]]
</noinclude>

[edit] Download instructions

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.

[edit] Installation

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

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

[edit] Source Code

  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.3'
    
  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(), "/" ) === false ) return true; // Nice addition by ThorstenStaerk
    
  18.     if ( strpos ( $wgTitle->getPrefixedText(), "User:" ) === 0 ) return true;
    
  19.     if ( strpos ( $wgTitle->getPrefixedText(), "Special:" ) === 0 ) return true;
    
  20.     if ( strpos ( $wgTitle->getPrefixedText(), "File:" ) === 0 ) return true;
    
  21.  
    
  22.     $arr = split ( "/", $wgTitle->getPrefixedText() );
    
  23.  
    
  24.     $arrLen = count ( $arr ) - 1;
    
  25.  
    
  26.     $url = "<small><a href=\"{$wgScript}\">Home</a>";
    
  27.     $links = "";
    
  28.     for ( $i=0; $i<$arrLen; $i++ ) {
    
  29.         $links .= "/" . $arr[$i];
    
  30.         $url .= " &lt; <a href=\"{$wgScript}{$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. }
    

[edit] See also