<?php
/**
* CategoryBreadcrumb extension
*
* @author Boudewijn Vahrmeijer
* @version 2.1
* @link http://www.mediawiki.org/wiki/Extension:CategoryBreadcrumb
*
* Extended by Cynthia Mattingly @ Marketing Factory Consulting
*
* Added support for Image pages and pages using CategoryTree
* Added default breadcrumb first link to home page
*
*/
if ( ! defined( 'MEDIAWIKI' ) )
die();
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Category Breadcrumb',
'author' => 'Boudewijn Vahrmeijer',
'url' => 'http://www.mediawiki.org/wiki/Extension:CategoryBreadcrumb',
'version' => '2.1',
'description' => 'DMOZ-style category breadcrumb for MediaWiki',
);
$wgUseCategoryBrowser = true;
// hook into SkinTemplate.php
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'wfBreadCrumbsDisplay';
function wfBreadCrumbsDisplay(&$q, &$p) {
global $wgOut, $wgArticle, $wgScriptPath;
$pageClass = get_class($wgArticle);
if ($wgArticle == null) {
return true;
}
$allowedClasses = array('CategoryPage', 'CategoryTreeCategoryPage', 'ImagePage');
if (!in_array($pageClass, $allowedClasses) && $wgArticle->getTitle()->mNamespace != 0) {
return true;
}
$cats = $q->getCategories();
// kill the ugly category box below the page
$p->set( 'catlinks', '');
$homelink = '<a href="'.$wgScriptPath.'/">
<img src="'.$wgScriptPath.'/skins/common/images/mediawiki.png" width="20" height="20"> WikiName
</a>';
if (trim($cats) == '') {
$combine = $homelink.$wgOut->mBodytext;
$p->setRef( 'bodytext', $combine );
} else {
$combine = array();
// get category tree
$tree = explode('<hr />', $cats);
// set tree on top of text and register into $tpl
$cats = explode('<br />', $tree[1]);
//prepend the home link for each category
foreach ($cats as $category) {
$combine[] = $homelink.' > '.$category;
}
$bodytext = implode('<br />', $combine).$wgOut->mBodytext;
$p->setRef( 'bodytext', $bodytext);
}
return true;
}