Extension:BreadCrumbs (Kimon)
From MediaWiki.org
|
BreadCrumbs (Kimon) Release status: beta |
|||
|---|---|---|---|
| Implementation | User interface | ||
| Description | Shows the user's path through the wiki. Based heavily on Manuel Schneider's extension Extension:BreadCrumbs | ||
| Author(s) | Kimon Andreou (KimonTalk) | ||
| Last Version | 1.0.0 (2007-10-26) | ||
| MediaWiki | Tested on 1.10 | ||
| License | GPL | ||
| Download | See below | ||
|
|||
|
|||
Contents |
[edit] Description
Shows a list of visited pages during the user's session. Very useful when you want to know how you arrived wherever you are.
If the page being visited is already on the list, then the list does not grow (no dupes) and if it were a prior page, the list shrinks.
Also, a new user preference is created to allow users to optionally have this feature enabled to them. The new T/F flag is added to the "Misc." tab of the user preferences.
The line with the links is placed at the bottom of the page but, all formatting options can be easily modified by editing the accompanying CSS.
See the bottom of this page for a sample
[edit] Parameters
- $wgBreadCrumbsDelimiter
- Defines the delimiter to use between the individual bread crumbs. The default value is " > ".
- $wgBreadCrumbsCount
- Specifies the number of items to include in the list. Default is 5.
[edit] Installation
Follow these steps to install the extension:
1. Create a directory under "extensions" called "BreadCrumbs"
2. Create a new file called "BreadCrumbs.php" and paste the following code:
<?php # The BreadCrumbs extension, an extension for providing an breadcrumbs # navigation to users. # @addtogroup Extensions # @author Manuel Schneider <manuel.schneider@wikimedia.ch> # @author Kimon Andreou # @copyright © 2007 by Manuel Schneider, Kimon Andreou # @licence GNU General Public Licence 2.0 or later if( !defined( 'MEDIAWIKI' ) ) { echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); die(); } ## Options: # set the delimiter $wgBreadCrumbsDelimiter = ' > '; # number of breadcrumbs to use $wgBreadCrumbsCount = 5; $bcBreadCrumbs = new BreadCrumbs(); $wgExtensionFunctions[] = array($bcBreadCrumbs, 'setup'); $wgHooks['UserToggles'][] = array($bcBreadCrumbs, 'toggle'); $wgExtensionCredits['parserhook'][] = array( 'name' => 'BreadCrumbs', 'author' => 'Kimon Andreou', 'url' => 'http://www.mediawiki.org/wiki/Extension:BreadCrumbs_(Kimon)', 'description' => "Shows a breadcrumb navigation. Based heavily on Manuel Shneider's extension[http://www.mediawiki.org/wiki/Extension:BreadCrumbs]" ); ## ## Main class class BreadCrumbs { #constructor function BreadCrumbs() {} ## Set Hook: function setup() { global $wgUser, $wgHooks; #can we see the breadcrumbs? if($wgUser->getOption('breadcrumb')==0) { return; } ## Showing and updating the breadcrumbs trail # Hook when viewing article header: $wgHooks['ArticleViewHeader'][] = array($this, 'show'); ## Infrastructure # Hook our own CSS: $wgHooks['OutputPageParserOutput'][] = array($this, 'output'); } #Return our new user preference (t/f toggle) function toggle(&$arr) { global $wgMessageCache; #named "breadcrumb" - original, no? $arr[] = 'breadcrumb'; $wgMessageCache->addMessage('tog-breadcrumb', 'Use breadcrumbs'); return true; } #Show the breadcrumbs on the page function show( &$m_pageObj ) { global $wgUser, $wgTitle, $wgOut, $wgBreadCrumbsDelimiter, $wgBreadCrumbsCount; # deserialize data from session into array: $m_BreadCrumbs = array(); #If a session doesn't already exist, create one if( isset( $_SESSION['BreadCrumbs'] ) ) { $m_BreadCrumbs = $_SESSION['BreadCrumbs']; } else { if( !isset( $_SESSION ) ) { session_start(); } $_SESSION['BreadCrumbs'] = array(); } # cache index of last element: $m_count = count( $m_BreadCrumbs ) - 1; # if we've got too many entries, reduce the array: if( count( $m_BreadCrumbs ) > 0 && $m_BreadCrumbs[ $m_count ] != $wgTitle->getPrefixedText() ) { # reduce the array set, remove older elements: $m_BreadCrumbs = array_slice( $m_BreadCrumbs, ( 1 - $wgBreadCrumbsCount ) ); # add new page: array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText() ); } else { array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText() ); } #if returning to a page we've already visited, reduce the array $loc = array_search($wgTitle->getPrefixedText(), $m_BreadCrumbs); if(($loc >= 0)) { #shrink array $m_BreadCrumbs = array_slice($m_BreadCrumbs, 0, ($loc + 1)); } # serialize data from array to session: $_SESSION['BreadCrumbs'] = $m_BreadCrumbs; # update cache: $m_count = count( $m_BreadCrumbs ) - 1; # acquire a skin object: $m_skin =& $wgUser->getSkin(); # build the breadcrumbs trail: $m_trail = "<div id=\"BreadCrumbsTrail\"> <i>Bread crumbs:</i> "; for( $i = 0; $i <= $m_count; $i++ ) { $m_trail .= $m_skin->makeLink( $m_BreadCrumbs[$i] ); if( $i < $m_count ) $m_trail .= $wgBreadCrumbsDelimiter; } $m_trail .= ' </div>'; $wgOut->addHTML( $m_trail ); # invalidate internal MediaWiki cache: $wgTitle->invalidateCache(); $wgUser->invalidateCache(); # Return true to let the rest work: return true; } ## Entry point for the hook for printing the CSS: # todo: find a better implementation function output( &$m_pageObj, &$m_parserOutput ) { global $wgScriptPath; # Register CSS file for our select box: $m_pageObj->addLink( array( 'rel' => 'stylesheet', 'type' => 'text/css', 'href' => $wgScriptPath . '/extensions/BreadCrumbs/BreadCrumbs.css' ) ); # Be nice: return true; } } ?>
3. Create a new file called "BreadCrumbs.css" and paste the following code:
/* Stylesheet for the BreadCrumbs extension, an extension of the * edit box of MediaWiki to provide an easy way to add category links * to a specific page. * * @package MediaWiki * @subpackage Extensions * @author Manuel Schneider <manuel.schneider@wikimedia.ch> * @author Kimon Andreou * @copyright © 2007 by Manuel Schneider * @licence GNU General Public Licence 2.0 or later */ #BreadCrumbsTrail { font-size:0.8em; background-color: #FFFFCC; position:absolute; left: 2px; bottom:0; width:99%; }
4. Append this line of code to the end of your LocalSettings.php
require_once( "$IP/extensions/BreadCrumbs/BreadCrumbs.php" );

