2006-07-26 17:12:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup and Hooks for the CategoryTree extension, an AJAX based gadget
|
|
|
|
* to display the category structure of a wiki
|
|
|
|
*
|
2007-01-20 15:10:35 +00:00
|
|
|
* @addtogroup Extensions
|
2006-07-26 17:12:30 +00:00
|
|
|
* @author Daniel Kinzler <duesentrieb@brightbyte.de>
|
|
|
|
* @copyright © 2006 Daniel Kinzler
|
|
|
|
* @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( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constants for use with efCategoryTreeRenderChildren,
|
|
|
|
* defining what should be shown in the tree
|
|
|
|
*/
|
|
|
|
define('CT_MODE_CATEGORIES', 0);
|
|
|
|
define('CT_MODE_PAGES', 10);
|
|
|
|
define('CT_MODE_ALL', 20);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Options:
|
|
|
|
*
|
|
|
|
* $wgCategoryTreeMaxChildren - maximum number of children shown in a tree node. Default is 200
|
|
|
|
* $wgCategoryTreeAllowTag - enable <categorytree> tag. Default is true.
|
2006-07-28 16:07:55 +00:00
|
|
|
* $wgCategoryTreeDynamicTag - loads the first level of the tree in a <categorytag> dynamically.
|
|
|
|
* This way, the cache does not need to be disabled. Default is false.
|
2006-07-26 17:12:30 +00:00
|
|
|
* $wgCategoryTreeDisableCache - disabled the parser cache for pages with a <categorytree> tag. Default is true.
|
2006-08-23 19:23:17 +00:00
|
|
|
* $wgCategoryTreeUseCache - enable HTTP cache for anon users. Default is false.
|
2006-09-03 11:26:57 +00:00
|
|
|
* $wgCategoryTreeUnifiedView - use unified view on category pages, instead of "tree" or "traditional list". Default is true.
|
2006-11-22 21:48:54 +00:00
|
|
|
* $wgCategoryTreeOmitNamespace - never show namespace prefix. Default is false
|
2006-07-26 17:12:30 +00:00
|
|
|
*/
|
2006-09-02 21:54:21 +00:00
|
|
|
$wgCategoryTreeMaxChildren = 200;
|
|
|
|
$wgCategoryTreeAllowTag = true;
|
|
|
|
$wgCategoryTreeDisableCache = true;
|
|
|
|
$wgCategoryTreeDynamicTag = false;
|
|
|
|
$wgCategoryTreeHTTPCache = false;
|
2006-09-03 11:26:57 +00:00
|
|
|
$wgCategoryTreeUnifiedView = true;
|
2006-11-22 21:48:54 +00:00
|
|
|
$wgCategoryTreeOmitNamespace = false;
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register extension setup hook and credits
|
|
|
|
*/
|
|
|
|
$wgExtensionFunctions[] = 'efCategoryTree';
|
2006-08-24 17:12:13 +00:00
|
|
|
$wgExtensionCredits['specialpage'][] = array(
|
|
|
|
'name' => 'CategoryTree',
|
|
|
|
'author' => 'Daniel Kinzler',
|
2007-01-07 13:57:35 +00:00
|
|
|
'url' => 'http://meta.wikimedia.org/wiki/CategoryTree_extension',
|
|
|
|
'description' => 'AJAX based gadget to display the category structure of a wiki',
|
2006-08-24 17:12:13 +00:00
|
|
|
);
|
|
|
|
$wgExtensionCredits['parserhook'][] = array(
|
|
|
|
'name' => 'CategoryTree',
|
|
|
|
'author' => 'Daniel Kinzler',
|
2007-01-07 13:57:35 +00:00
|
|
|
'url' => 'http://meta.wikimedia.org/wiki/CategoryTree_extension',
|
|
|
|
'description' => 'AJAX based gadget to display the category structure of a wiki',
|
2006-08-24 17:12:13 +00:00
|
|
|
);
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the special page
|
|
|
|
*/
|
2006-08-24 17:12:13 +00:00
|
|
|
$wgAutoloadClasses['CategoryTreePage'] = dirname( __FILE__ ) . '/CategoryTreePage.php';
|
|
|
|
$wgAutoloadClasses['CategoryTree'] = dirname( __FILE__ ) . '/CategoryTreeFunctions.php';
|
|
|
|
$wgAutoloadClasses['CategoryTreeCategoryPage'] = dirname( __FILE__ ) . '/CategoryPageSubclass.php';
|
|
|
|
$wgSpecialPages['CategoryTree'] = 'CategoryTreePage';
|
|
|
|
#$wgHooks['SkinTemplateTabs'][] = 'efCategoryTreeInstallTabs';
|
|
|
|
$wgHooks['OutputPageParserOutput'][] = 'efCategoryTreeParserOutput';
|
|
|
|
$wgHooks['LoadAllMessages'][] = 'efInjectCategoryTreeMessages';
|
|
|
|
$wgHooks['ArticleFromTitle'][] = 'efCategoryTreeArticleFromTitle';
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* register Ajax function
|
|
|
|
*/
|
|
|
|
$wgAjaxExportList[] = 'efCategoryTreeAjaxWrapper';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook it up
|
|
|
|
*/
|
|
|
|
function efCategoryTree() {
|
2006-09-01 12:53:07 +00:00
|
|
|
global $wgUseAjax, $wgParser, $wgCategoryTreeAllowTag;
|
|
|
|
|
|
|
|
# Abort if AJAX is not enabled
|
|
|
|
if ( !$wgUseAjax ) {
|
|
|
|
wfDebug( 'efCategoryTree: $wgUseAjax is not enabled, aborting extension setup.' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
if ( $wgCategoryTreeAllowTag ) $wgParser->setHook( 'categorytree' , 'efCategoryTreeParserHook' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point for Ajax, registered in $wgAjaxExportList.
|
2006-08-24 17:12:13 +00:00
|
|
|
* This loads CategoryTreeFunctions.php and calls CategoryTree::ajax()
|
2006-07-26 17:12:30 +00:00
|
|
|
*/
|
|
|
|
function efCategoryTreeAjaxWrapper( $category, $mode = CT_MODE_CATEGORIES ) {
|
2006-08-29 15:49:23 +00:00
|
|
|
global $wgCategoryTreeHTTPCache, $wgSquidMaxAge, $wgUseSquid;
|
|
|
|
|
|
|
|
$ct = new CategoryTree;
|
|
|
|
$response = $ct->ajax( $category, $mode );
|
2006-08-23 19:23:17 +00:00
|
|
|
|
|
|
|
if ( $wgCategoryTreeHTTPCache && $wgSquidMaxAge && $wgUseSquid ) {
|
2006-08-29 15:49:23 +00:00
|
|
|
$response->setCacheDuration( $wgSquidMaxAge );
|
|
|
|
$response->setVary( 'Accept-Encoding, Cookie' ); #cache for anons only
|
2006-08-23 19:23:17 +00:00
|
|
|
#TODO: purge the squid cache when a category page is invalidated
|
|
|
|
}
|
2006-08-24 17:12:13 +00:00
|
|
|
|
2006-08-29 15:49:23 +00:00
|
|
|
return $response;
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point for the <categorytree> tag parser hook.
|
2006-08-24 17:12:13 +00:00
|
|
|
* This loads CategoryTreeFunctions.php and calls CategoryTree::getTag()
|
2006-07-26 17:12:30 +00:00
|
|
|
*/
|
2006-08-23 19:23:17 +00:00
|
|
|
function efCategoryTreeParserHook( $cat, $argv, &$parser ) {
|
2006-08-24 17:12:13 +00:00
|
|
|
$parser->mOutput->mCategoryTreeTag = true; # flag for use by efCategoryTreeParserOutput
|
2006-07-29 09:18:34 +00:00
|
|
|
|
2006-08-23 19:23:17 +00:00
|
|
|
static $initialized = false;
|
2006-07-26 23:11:23 +00:00
|
|
|
|
2006-09-02 21:54:21 +00:00
|
|
|
$divAttribs = Sanitizer::validateTagAttributes( $argv, 'div' );
|
2006-11-29 13:06:21 +00:00
|
|
|
$style = isset( $divAttribs['style'] ) ? $divAttribs['style'] : null;
|
2006-07-26 17:12:30 +00:00
|
|
|
|
2006-11-29 13:06:21 +00:00
|
|
|
$mode = isset( $argv[ 'mode' ] ) ? $argv[ 'mode' ] : null;
|
2006-07-26 17:12:30 +00:00
|
|
|
if ( $mode !== NULL ) {
|
|
|
|
$mode= trim( strtolower( $mode ) );
|
|
|
|
|
|
|
|
if ( $mode == 'all' ) $mode = CT_MODE_ALL;
|
|
|
|
else if ( $mode == 'pages' ) $mode = CT_MODE_PAGES;
|
|
|
|
else if ( $mode == 'categories' ) $mode = CT_MODE_CATEGORIES;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$mode = CT_MODE_CATEGORIES;
|
|
|
|
}
|
|
|
|
|
2006-11-29 13:06:21 +00:00
|
|
|
$hideroot = isset( $argv[ 'hideroot' ] ) ? $argv[ 'hideroot' ] : null;
|
2006-07-26 17:12:30 +00:00
|
|
|
if ( $hideroot !== NULL ) {
|
|
|
|
$hideroot = trim( strtolower( $hideroot ) );
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
if ( $hideroot === '1' || $hideroot === 'yes' || $hideroot === 'on' || $hideroot === 'true' ) {
|
|
|
|
$hideroot = true;
|
|
|
|
}
|
|
|
|
else if ( $hideroot === '0' || $hideroot === 'no' || $hideroot === 'off' || $hideroot === 'false' ) {
|
|
|
|
$hideroot = false;
|
|
|
|
}
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
2006-08-23 19:23:17 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$ct = new CategoryTree;
|
|
|
|
return $ct->getTag( $parser, $cat, $mode, $hideroot, $style );
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook callback that installs a tab for CategoryTree on Category pages
|
2006-08-24 17:12:13 +00:00
|
|
|
*/
|
|
|
|
/*
|
2006-07-26 17:12:30 +00:00
|
|
|
function efCategoryTreeInstallTabs( &$skin, &$content_actions ) {
|
|
|
|
global $wgTitle;
|
|
|
|
|
|
|
|
if ( $wgTitle->getNamespace() != NS_CATEGORY ) return true;
|
|
|
|
|
|
|
|
$special = Title::makeTitle( NS_SPECIAL, 'CategoryTree' );
|
|
|
|
|
|
|
|
$content_actions['categorytree'] = array(
|
|
|
|
'class' => false,
|
2006-08-24 17:12:13 +00:00
|
|
|
'text' => htmlspecialchars( CategoryTree::msg( 'tab' ) ),
|
2006-07-26 17:12:30 +00:00
|
|
|
'href' => $special->getLocalUrl() . '/' . $wgTitle->getPartialURL() );
|
|
|
|
return true;
|
2006-08-24 17:12:13 +00:00
|
|
|
}*/
|
2006-07-26 17:12:30 +00:00
|
|
|
|
2006-07-29 09:18:34 +00:00
|
|
|
/**
|
|
|
|
* Hook callback that injects messages and things into the <head> tag
|
|
|
|
* Does nothing if $parserOutput->mCategoryTreeTag is not set
|
|
|
|
*/
|
2006-08-24 17:12:13 +00:00
|
|
|
function efCategoryTreeParserOutput( &$outputPage, &$parserOutput ) {
|
|
|
|
if ( !empty( $parserOutput->mCategoryTreeTag ) ) {
|
|
|
|
CategoryTree::setHeaders( $outputPage );
|
|
|
|
}
|
2006-08-28 17:13:16 +00:00
|
|
|
return true;
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
2006-07-29 09:18:34 +00:00
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
/**
|
|
|
|
* inject messages used by CategoryTree into the message cache
|
|
|
|
*/
|
|
|
|
function efInjectCategoryTreeMessages() {
|
2006-08-24 17:12:13 +00:00
|
|
|
CategoryTree::msg(false);
|
|
|
|
return true;
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-08-24 17:12:13 +00:00
|
|
|
* ArticleFromTitle hook, override category page handling
|
|
|
|
*/
|
|
|
|
function efCategoryTreeArticleFromTitle( &$title, &$article ) {
|
|
|
|
if ( $title->getNamespace() == NS_CATEGORY ) {
|
|
|
|
$article = new CategoryTreeCategoryPage( $title );
|
2006-08-11 23:36:53 +00:00
|
|
|
}
|
2006-08-24 17:12:13 +00:00
|
|
|
return true;
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
2006-08-24 17:12:13 +00:00
|
|
|
|
|
|
|
?>
|