How to create breadcrumb with Mediawiki

Inleiding

   
NEW VERSION 24-09-2007 This article will describe how to create a breadcrumb for MediaWiki. A breadcrumb is a category tree to show the current category for an article, with all the parent categories.

Stappen

Two simple steps

  • 1) Create CategoryBreadCrumbs.php
<?php

if (&#160;! defined( 'MEDIAWIKI' ) )
	die();

//--------------------------------------------------
// See http://www.leerwiki.nl for either updates
// or other extensions such as the Ajax Rating Script-,
// Image shadow- or EditpageMultipleInputboxes extension. 
// good luck with your Wiki! 
// B.Vahrmeijer
//----------------------------------------------------

$wgExtensionCredits['parserhook'][] = array(
'name' => 'Category Breadcrumb 24-07-2007',
'author' => 'Boudewijn Vahrmeijer',
'url' => 'http://www.leerwiki.nl/Hoofdpagina',
'version' => '1.11,1.10.1/1.9.3/1.9.2/1.8.2',
'description' => 'Category Breadcrumb for MediaWiki DMOZ style',
);

$wgUseCategoryBrowser = true;

// hook into Skintemplate.php
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = array("wfBreadCrumbsDisplay");

function wfBreadCrumbsDisplay(&$q,&$p) {
	global $wgOut,$wgArticle,$pathToRating;
	
	if ($wgArticle==null) return $out;	
	if ($wgArticle->getTitle()->mNamespace&#160;!= 0) return  $out;

 
	// get category tree
	$tree=explode('<hr />',$q->getCategories());
<p>	// kill the ugly category box below the page
    $p->set( 'catlinks', <i>);</i>
</p><p>	// set tree on top of text and register into $tpl
	$combine=$tree[1].$wgOut->mBodytext;
	$p->setRef( 'bodytext', $combine );
</p><p>	return true;
</p><p>}
</p>
?>
  • Second and final step: put insite Localsettings.php
$wgUseCategoryBrowser = true;
require_once("extensions/CategoryBreadCrumbs.php");
  • Now you have your category breadcrumb ready.

Risico's en Tips

  • When an articles has two categories, the breadcrumb will now show two lines.