Extension:BreadCrumbs (Kimon)

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
BreadCrumbs (Kimon)

Release status:Extension status beta

ImplementationTemplate:Extension#type User interface
DescriptionTemplate:Extension#description Shows the user's path through the wiki. Based heavily on Manuel Schneider's extension Extension:BreadCrumbs
Author(s)Template:Extension#username Kimon Andreou (Kimontalk)
Latest versionTemplate:Extension#version 1.0.0 (2007-10-26)
MediaWikiTemplate:Extension#mediawiki Tested on 1.10; has problems with v1.16+, but workaround is available
LicenseTemplate:Extension#license GNU General Public License 2.0 or later
Download See below

$wgBreadCrumbsDelimiter $wgBreadCrumbsCount

Hooks usedTemplate:Extension#hook

Translate the BreadCrumbs (Kimon) extension if it is available at translatewiki.net

Check usage and version matrix.

This extension 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

 Bread crumbs: Main Page > Category:All extensions > Extension:BreadCrumbs (Kimon)


Parameters can be defined in the LocalSettings.php file.

Defines the delimiter to use between the individual bread crumbs. The default value is " > ".
Specifies the number of items to include in the list. Default is 5.

A sample from a working LocalSettings.php file.

# Breadcrumbs
require_once( "extensions/BreadCrumbs/BreadCrumbs.php" );
$wgBreadCrumbsCount = 6;
$wgBreadCrumbsDelimiter = ' > ';


Follow these steps to install the extension:

1. Create a directory under "extensions" called "BreadCrumbs"

2. Create a new file called "BreadCrumbs.php" in the "BreadCrumbs" directory. Paste the following code:


# 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" );

## Options:
# set the delimiter
$wgBreadCrumbsDelimiter = ' &gt; ';
# 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]",
  'license-name'  => 'GPL-2.0+',

## Main class
class BreadCrumbs {
  function BreadCrumbs() {}

  ## Set Hook:
  function setup() {
    global $wgUser, $wgHooks;

    #can we see the breadcrumbs?
    if($wgUser->getOption('breadcrumb')==0) {
    ## 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['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\">&nbsp;<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 .= '&nbsp;</div>';
    $wgOut->addHTML( $m_trail );
    # invalidate internal MediaWiki cache:
    # 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:
        'rel'   => 'stylesheet',
        'type'  => 'text/css',
        'href'  => $wgScriptPath . '/extensions/BreadCrumbs/BreadCrumbs.css'

    # Be nice:
    return true;


3. Create a new file called "BreadCrumbs.css" in the "BreadCrumbs" directory. 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 {
        background-color: #FFFFCC;
        left: 2px;

4. Append this line of code to the end of your LocalSettings.php

require_once( "$IP/extensions/BreadCrumbs/BreadCrumbs.php" );

5. Activate the breadcrumb in your user preferences ("Misc" tab, checkbox "Use breadcrumbs")

Alternative style[edit]

If you prefer a grey background rather than yellow, and to position it at the top rather than bottom of the page, then try this CSS instead in step 3:

#BreadCrumbsTrail {
        background-color: #ECECEC;
        left: 2px;

Workaround for MediaWiki v1.16 and beyond[edit]

Special:Preferences has been changed in MediaWiki v1.16. To get the extension to work, delete or comment out this snippet from BreadCrumbs.php . It will now work, but it will appear for all users rather than being an option in preferences:

#can we see the breadcrumbs?
    if($wgUser->getOption('breadcrumb')==0) {

Note: This work-around does not work on v1.16. Commenting/Deleting the above snippet, produces this error:

Detected bug in an extension! Hook BreadCrumbs::output failed to return a value; should return true to continue hook processing or false to abort.

--JSingleton 13:35, 1 September 2010 (UTC)

This extension does not work in 1.15.3 - either with or without the v1.16 work-around suggestion.

Warning: Parameter 2 to BreadCrumbs::output() expected to be a reference, value given in C:\wamp\www\KShop\includes\Hooks.php on line 117 Internal error From KShop Jump to: navigation, search Detected bug in an extension! Hook BreadCrumbs::output failed to return a value; should return true to continue hook processing or false to abort.


  1. 0 C:\wamp\www\KShop\includes\OutputPage.php(565): wfRunHooks('OutputPageParse...', Array)
  2. 1 C:\wamp\www\KShop\includes\OutputPage.php(573): OutputPage->addParserOutputNoText(Object(ParserOutput))
  3. 2 C:\wamp\www\KShop\includes\OutputPage.php(678): OutputPage->addParserOutput(Object(ParserOutput))
  4. 3 C:\wamp\www\KShop\includes\Article.php(870): OutputPage->tryParserCache(Object(Article))
  5. 4 C:\wamp\www\KShop\includes\Wiki.php(450): Article->view()
  6. 5 C:\wamp\www\KShop\includes\Wiki.php(63): MediaWiki->performAction(Object(OutputPage), Object(Article), Object(Title), Object(User), Object(WebRequest))
  7. 6 C:\wamp\www\KShop\index.php(116): MediaWiki->initialize(Object(Title), Object(Article), Object(OutputPage), Object(User), Object(WebRequest))
  8. 7 {main}

--RaGz 14:40, 1 October 2010 CST

Find this line in BreadCrumbs.php

  function output( &$m_pageObj, &$m_parserOutput ) {

and replace it by

  function output( &$m_pageObj, $m_parserOutput ) {

Works in 1.16.1 with this fix + the "user" fix mentioned at the start of this section.

If you're seeing frameborder=0 as the first breadcrumb[edit]

This happens because a loop is iterating one too many times. The simplest fix is to find this:

    for( $i = 0; $i <= $m_count; $i++ ) {
      $m_trail .= $m_skin->makeLink( $m_BreadCrumbs[$i] );
      if( $i < $m_count ) $m_trail .= $wgBreadCrumbsDelimiter;

And change the $i variable to 1 instead of 0 so it looks like this:

    for( $i = 1; $i <= $m_count; $i++ ) {
      $m_trail .= $m_skin->makeLink( $m_BreadCrumbs[$i] );
      if( $i < $m_count ) $m_trail .= $wgBreadCrumbsDelimiter;

for( $i = 1; $i <= $m count; $i++ ) {

$m trail .= $m skin->makeLink( $m BreadCrumbs[$i] );
if( $i < $m count ) $m trail .= $wgBreadCrumbsDelimiter;


Work Around Fix for MediaWiki v1.22[edit]

Following the instructions above for 'Workaround for MediaWiki v1.16 and beyond' and then you will need to change roughly line 108 from:

    $m_skin =& $wgUser->getSkin();

to this:

    $m_skin =$wgUser->getSkin();

Then you will want to replace:

    $m_trail . =$m_skin->makeLink ( $m_BreadCrumbs [$1] );

With these two lines:

    $title = Title::newFromText( $m_BreadCrumbs[$i] );
    $m_trail .= Linker::link( $title, $m_BreadCrumbs[$i] );

and everything should work wonderfully!

See also[edit]

Language: English  • Ελληνικά