Extension:BrettCrumbs
|
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 | ||
| Last 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 | ||
|
|||
|
|||
| Check usage and version matrix | |||
Contents |
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.
Usage [edit]
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:
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
[[{{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]
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]
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]
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]
-
<?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.4.1' -
);
-
$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 .= " < <a href=\"{$wgScript}?title={$links}\">" . htmlspecialchars($arr[$i]) . '</a>'; -
} -
$url .= ' < ' . htmlspecialchars ( $arr[$arrLen] ); -
$url .= '</small>'; -
-
$text = $url . $text; -
-
return true; -
}
