Extension:BrettCrumbs
From MediaWiki.org
|
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:
[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
-
<?php -
$wgExtensionCredits['parserhook'][] = array(
-
'name'=>'BrettCrumbs - Simple Breadcrumbs', -
'url'=>'http://www.mediawiki.org/wiki/Extension:BrettCrumbs', -
'author'=>'Brett Dutton, brettcraigdutton at hotmail dot com', -
'description'=>'Simple bread crumbs navigation.', -
'version'=>'1.3' -
);
-
$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(), "/" ) === false ) return true; // Nice addition by ThorstenStaerk -
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 = split ( "/", $wgTitle->getPrefixedText() ); -
-
$arrLen = count ( $arr ) - 1; -
-
$url = "<small><a href=\"{$wgScript}\">Home</a>"; -
$links = ""; -
for ( $i=0; $i<$arrLen; $i++ ) { -
$links .= "/" . $arr[$i]; -
$url .= " < <a href=\"{$wgScript}{$links}\">" . htmlspecialchars($arr[$i]) . "</a>"; -
} -
$url .= " < " . htmlspecialchars ( $arr[$arrLen] ); -
$url .= "</small>"; -
-
$text = $url . $text; -
-
return true; -
}