2006-07-26 17:12:30 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2008-02-04 09:22:12 +00:00
|
|
|
* Core functions for the CategoryTree extension, an AJAX based gadget
|
2006-07-26 17:12:30 +00:00
|
|
|
* to display the category structure of a wiki
|
|
|
|
*
|
2007-01-20 15:10:35 +00:00
|
|
|
* @addtogroup Extensions
|
2007-03-13 11:39:12 +00:00
|
|
|
* @author Daniel Kinzler, brightbyte.de
|
|
|
|
* @copyright © 2006-2007 Daniel Kinzler
|
2008-03-18 17:38:32 +00:00
|
|
|
* @license GNU General Public Licence 2.0 or later
|
2006-07-26 17:12:30 +00:00
|
|
|
*/
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2006-07-26 17:12:30 +00:00
|
|
|
echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" );
|
|
|
|
die( 1 );
|
|
|
|
}
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
class CategoryTree {
|
|
|
|
var $mIsAjaxRequest = false;
|
2008-06-28 20:13:20 +00:00
|
|
|
var $mOptions = array();
|
|
|
|
|
|
|
|
function __construct( $options, $ajax = false ) {
|
|
|
|
global $wgCategoryTreeDefaultOptions;
|
|
|
|
|
|
|
|
$this->mIsAjaxRequest = $ajax;
|
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
# ensure default values and order of options. Order may become important, it may influence the cache key!
|
2008-06-28 20:13:20 +00:00
|
|
|
foreach ( $wgCategoryTreeDefaultOptions as $option => $default ) {
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( isset( $options[$option] ) && !is_null( $options[$option] ) ) {
|
|
|
|
$this->mOptions[$option] = $options[$option];
|
|
|
|
} else {
|
|
|
|
$this->mOptions[$option] = $default;
|
|
|
|
}
|
2008-06-28 20:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->mOptions['mode'] = self::decodeMode( $this->mOptions['mode'] );
|
2008-07-02 09:49:28 +00:00
|
|
|
|
|
|
|
if ( $this->mOptions['mode'] == CT_MODE_PARENTS ) {
|
2010-04-20 22:00:34 +00:00
|
|
|
$this->mOptions['namespaces'] = false; # namespace filter makes no sense with CT_MODE_PARENTS
|
2008-07-02 09:49:28 +00:00
|
|
|
}
|
|
|
|
|
2008-06-30 21:22:03 +00:00
|
|
|
$this->mOptions['hideprefix'] = self::decodeHidePrefix( $this->mOptions['hideprefix'] );
|
2008-06-30 14:09:47 +00:00
|
|
|
$this->mOptions['showcount'] = self::decodeBoolean( $this->mOptions['showcount'] );
|
2008-07-01 21:40:42 +00:00
|
|
|
$this->mOptions['namespaces'] = self::decodeNamespaces( $this->mOptions['namespaces'] );
|
|
|
|
|
|
|
|
if ( $this->mOptions['namespaces'] ) {
|
|
|
|
# automatically adjust mode to match namespace filter
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( sizeof( $this->mOptions['namespaces'] ) === 1
|
2008-07-01 21:40:42 +00:00
|
|
|
&& $this->mOptions['namespaces'][0] == NS_CATEGORY ) {
|
|
|
|
$this->mOptions['mode'] = CT_MODE_CATEGORIES;
|
|
|
|
} else if ( !in_array( NS_IMAGE, $this->mOptions['namespaces'] ) ) {
|
|
|
|
$this->mOptions['mode'] = CT_MODE_PAGES;
|
|
|
|
} else {
|
|
|
|
$this->mOptions['mode'] = CT_MODE_ALL;
|
|
|
|
}
|
|
|
|
}
|
2008-06-28 20:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getOption( $name ) {
|
|
|
|
return $this->mOptions[$name];
|
|
|
|
}
|
|
|
|
|
2008-07-02 09:49:28 +00:00
|
|
|
function isInverse( ) {
|
2010-04-20 22:00:34 +00:00
|
|
|
return $this->getOption( 'mode' ) == CT_MODE_PARENTS;
|
2008-07-02 09:49:28 +00:00
|
|
|
}
|
|
|
|
|
2008-07-01 21:40:42 +00:00
|
|
|
static function decodeNamespaces( $nn ) {
|
|
|
|
global $wgContLang;
|
|
|
|
|
|
|
|
if ( !$nn )
|
|
|
|
return false;
|
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( !is_array( $nn ) )
|
2008-07-01 21:40:42 +00:00
|
|
|
$nn = preg_split( '![\s#:|]+!', $nn );
|
|
|
|
|
|
|
|
$namespaces = array();
|
|
|
|
|
|
|
|
foreach ( $nn as $n ) {
|
|
|
|
if ( is_int( $n ) ) {
|
|
|
|
$ns = $n;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$n = trim( $n );
|
|
|
|
if ( $n === '' ) continue;
|
2010-04-20 22:00:34 +00:00
|
|
|
|
2008-07-01 21:40:42 +00:00
|
|
|
$lower = strtolower( $n );
|
2010-04-20 22:00:34 +00:00
|
|
|
|
|
|
|
if ( is_numeric( $n ) ) $ns = (int)$n;
|
2008-07-01 21:40:42 +00:00
|
|
|
elseif ( $n == '-' || $n == '_' || $n == '*' || $lower == 'main' ) $ns = NS_MAIN;
|
|
|
|
else $ns = $wgContLang->getNsIndex( $n );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_int( $ns ) ) {
|
|
|
|
$namespaces[] = $ns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sort( $namespaces ); # get elements into canonical order
|
|
|
|
return $namespaces;
|
|
|
|
}
|
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
static function decodeMode( $mode ) {
|
|
|
|
global $wgCategoryTreeDefaultOptions;
|
|
|
|
|
|
|
|
if ( is_null( $mode ) ) return $wgCategoryTreeDefaultOptions['mode'];
|
|
|
|
if ( is_int( $mode ) ) return $mode;
|
|
|
|
|
|
|
|
$mode = trim( strtolower( $mode ) );
|
|
|
|
|
|
|
|
if ( is_numeric( $mode ) ) return (int)$mode;
|
|
|
|
|
|
|
|
if ( $mode == 'all' ) $mode = CT_MODE_ALL;
|
|
|
|
else if ( $mode == 'pages' ) $mode = CT_MODE_PAGES;
|
2008-07-02 09:49:28 +00:00
|
|
|
else if ( $mode == 'categories' || $mode == 'sub' ) $mode = CT_MODE_CATEGORIES;
|
|
|
|
else if ( $mode == 'parents' || $mode == 'super' || $mode == 'inverse' ) $mode = CT_MODE_PARENTS;
|
2008-06-28 20:13:20 +00:00
|
|
|
else if ( $mode == 'default' ) $mode = $wgCategoryTreeDefaultOptions['mode'];
|
|
|
|
|
|
|
|
return (int)$mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to convert a string to a boolean value.
|
|
|
|
* Perhaps make this a global function in MediaWiki proper
|
|
|
|
*/
|
|
|
|
static function decodeBoolean( $value ) {
|
2010-01-06 21:24:10 +00:00
|
|
|
if ( is_null( $value ) ) return null;
|
2008-06-28 20:13:20 +00:00
|
|
|
if ( is_bool( $value ) ) return $value;
|
|
|
|
if ( is_int( $value ) ) return ( $value > 0 );
|
|
|
|
|
|
|
|
$value = trim( strtolower( $value ) );
|
2008-06-30 14:09:47 +00:00
|
|
|
if ( is_numeric( $value ) ) return ( (int)$value > 0 );
|
2008-06-28 20:13:20 +00:00
|
|
|
|
|
|
|
if ( $value == 'yes' || $value == 'y' || $value == 'true' || $value == 't' || $value == 'on' ) return true;
|
|
|
|
else if ( $value == 'no' || $value == 'n' || $value == 'false' || $value == 'f' || $value == 'off' ) return false;
|
2010-01-06 21:24:10 +00:00
|
|
|
else if ( $value == 'null' || $value == 'default' || $value == 'none' || $value == 'x' ) return null;
|
2008-06-28 20:13:20 +00:00
|
|
|
else return false;
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-30 21:22:03 +00:00
|
|
|
static function decodeHidePrefix( $value ) {
|
|
|
|
global $wgCategoryTreeDefaultOptions;
|
|
|
|
|
|
|
|
if ( is_null( $value ) ) return $wgCategoryTreeDefaultOptions['hideprefix'];
|
|
|
|
if ( is_int( $value ) ) return $value;
|
|
|
|
if ( $value === true ) return CT_HIDEPREFIX_ALWAYS;
|
|
|
|
if ( $value === false ) return CT_HIDEPREFIX_NEVER;
|
|
|
|
|
|
|
|
$value = trim( strtolower( $value ) );
|
|
|
|
|
|
|
|
if ( $value == 'yes' || $value == 'y' || $value == 'true' || $value == 't' || $value == 'on' ) return CT_HIDEPREFIX_ALWAYS;
|
|
|
|
else if ( $value == 'no' || $value == 'n' || $value == 'false' || $value == 'f' || $value == 'off' ) return CT_HIDEPREFIX_NEVER;
|
2010-04-20 22:00:34 +00:00
|
|
|
// else if ( $value == 'null' || $value == 'default' || $value == 'none' || $value == 'x' ) return $wgCategoryTreeDefaultOptions['hideprefix'];
|
2008-06-30 21:22:03 +00:00
|
|
|
else if ( $value == 'always' ) return CT_HIDEPREFIX_ALWAYS;
|
|
|
|
else if ( $value == 'never' ) return CT_HIDEPREFIX_NEVER;
|
|
|
|
else if ( $value == 'auto' ) return CT_HIDEPREFIX_AUTO;
|
|
|
|
else if ( $value == 'categories' || $value == 'category' || $value == 'smart' ) return CT_HIDEPREFIX_CATEGORIES;
|
|
|
|
else return $wgCategoryTreeDefaultOptions['hideprefix'];
|
|
|
|
}
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
/**
|
|
|
|
* Set the script tags in an OutputPage object
|
2008-02-04 09:22:12 +00:00
|
|
|
* @param OutputPage $outputPage
|
2006-08-24 17:12:13 +00:00
|
|
|
*/
|
2010-06-02 09:10:09 +00:00
|
|
|
static function setHeaders( $outputPage ) {
|
2008-07-11 23:18:41 +00:00
|
|
|
global $wgJsMimeType, $wgScriptPath, $wgContLang;
|
|
|
|
global $wgCategoryTreeHijackPageCategories, $wgCategoryTreeExtPath, $wgCategoryTreeVersion;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
# Register css file for CategoryTree
|
2008-02-04 09:22:12 +00:00
|
|
|
$outputPage->addLink(
|
|
|
|
array(
|
|
|
|
'rel' => 'stylesheet',
|
|
|
|
'type' => 'text/css',
|
2007-08-25 15:23:20 +00:00
|
|
|
'href' => "$wgScriptPath$wgCategoryTreeExtPath/CategoryTree.css?$wgCategoryTreeVersion",
|
2008-02-04 09:22:12 +00:00
|
|
|
)
|
2006-08-24 17:12:13 +00:00
|
|
|
);
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-07-11 23:18:41 +00:00
|
|
|
if ( $wgCategoryTreeHijackPageCategories ) {
|
|
|
|
# Register MSIE quirks
|
|
|
|
$outputPage->addScript(
|
|
|
|
"<!--[if IE]><link rel=\"stylesheet\" type=\"text/css\" src=\"{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTreeIE.css?{$wgCategoryTreeVersion}\"/><![endif]-->
|
|
|
|
\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-09-02 11:11:20 +00:00
|
|
|
# Register css RTL file for CategoryTree
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $wgContLang->isRTL() ) {
|
2008-02-04 09:22:12 +00:00
|
|
|
$outputPage->addLink(
|
|
|
|
array(
|
|
|
|
'rel' => 'stylesheet',
|
|
|
|
'type' => 'text/css',
|
|
|
|
'href' => "$wgScriptPath$wgCategoryTreeExtPath/CategoryTree.rtl.css?$wgCategoryTreeVersion"
|
|
|
|
)
|
2006-09-02 11:11:20 +00:00
|
|
|
);
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
# Register main js file for CategoryTree
|
2008-02-04 09:22:12 +00:00
|
|
|
$outputPage->addScript(
|
2007-08-25 15:23:20 +00:00
|
|
|
"<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.js?{$wgCategoryTreeVersion}\">" .
|
2008-02-04 09:22:12 +00:00
|
|
|
"</script>\n"
|
2006-08-24 17:12:13 +00:00
|
|
|
);
|
2008-02-04 09:22:12 +00:00
|
|
|
|
|
|
|
# Add messages
|
|
|
|
$outputPage->addScript(
|
|
|
|
" <script type=\"{$wgJsMimeType}\">
|
2010-04-20 22:00:34 +00:00
|
|
|
var categoryTreeCollapseMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-collapse' ) ) . "\";
|
|
|
|
var categoryTreeExpandMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-expand' ) ) . "\";
|
|
|
|
var categoryTreeCollapseBulletMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-collapse-bullet' ) ) . "\";
|
|
|
|
var categoryTreeExpandBulletMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-expand-bullet' ) ) . "\";
|
|
|
|
var categoryTreeLoadMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-load' ) ) . "\";
|
|
|
|
var categoryTreeLoadingMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-loading' ) ) . "\";
|
|
|
|
var categoryTreeNothingFoundMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-nothing-found' ) ) . "\";
|
|
|
|
var categoryTreeNoSubcategoriesMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-no-subcategories' ) ) . "\";
|
|
|
|
var categoryTreeNoParentCategoriesMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-no-parent-categories' ) ) . "\";
|
|
|
|
var categoryTreeNoPagesMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-no-pages' ) ) . "\";
|
|
|
|
var categoryTreeErrorMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-error' ) ) . "\";
|
|
|
|
var categoryTreeRetryMsg = \"" . Xml::escapeJsString( wfMsgNoTrans( 'categorytree-retry' ) ) . "\";
|
|
|
|
</script>\n"
|
2006-08-24 17:12:13 +00:00
|
|
|
);
|
2008-02-04 09:22:12 +00:00
|
|
|
}
|
2006-07-29 09:18:34 +00:00
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
static function getJsonCodec() {
|
2010-01-06 21:24:10 +00:00
|
|
|
static $json = null;
|
2008-06-28 20:13:20 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( !$json ) {
|
|
|
|
$json = new Services_JSON(); # recycle API's JSON codec implementation
|
2008-06-28 20:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $json;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function encodeOptions( $options, $enc ) {
|
|
|
|
if ( $enc == 'mode' || $enc == '' ) {
|
2010-04-20 22:00:34 +00:00
|
|
|
$opt = $options['mode'];
|
2008-06-28 20:13:20 +00:00
|
|
|
} elseif ( $enc == 'json' ) {
|
2010-04-20 22:00:34 +00:00
|
|
|
$json = self::getJsonCodec(); // XXX: this may be a bit heavy...
|
2008-06-28 20:13:20 +00:00
|
|
|
$opt = $json->encode( $options );
|
|
|
|
} else {
|
|
|
|
throw new MWException( 'Unknown encoding for CategoryTree options: ' . $enc );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function decodeOptions( $options, $enc ) {
|
|
|
|
if ( $enc == 'mode' || $enc == '' ) {
|
|
|
|
$opt = array( "mode" => $options );
|
|
|
|
} elseif ( $enc == 'json' ) {
|
2010-04-20 22:00:34 +00:00
|
|
|
$json = self::getJsonCodec(); // XXX: this may be a bit heavy...
|
2008-06-28 20:13:20 +00:00
|
|
|
$opt = $json->decode( $options );
|
|
|
|
$opt = get_object_vars( $opt );
|
2010-04-20 22:00:34 +00:00
|
|
|
} else {
|
2008-06-28 20:13:20 +00:00
|
|
|
throw new MWException( 'Unknown encoding for CategoryTree options: ' . $enc );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $opt;
|
|
|
|
}
|
|
|
|
|
2010-01-06 21:24:10 +00:00
|
|
|
function getOptionsAsCacheKey( $depth = null ) {
|
2008-06-28 20:13:20 +00:00
|
|
|
$key = "";
|
|
|
|
|
|
|
|
foreach ( $this->mOptions as $k => $v ) {
|
2008-07-01 21:40:42 +00:00
|
|
|
if ( is_array( $v ) ) $v = implode( '|', $v );
|
2008-06-28 20:13:20 +00:00
|
|
|
$key .= $k . ':' . $v . ';';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !is_null( $depth ) ) $key .= ";depth=" . $depth;
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
2010-01-06 21:24:10 +00:00
|
|
|
function getOptionsAsJsStructure( $depth = null ) {
|
2008-06-28 20:13:20 +00:00
|
|
|
if ( !is_null( $depth ) ) {
|
|
|
|
$opt = $this->mOptions;
|
|
|
|
$opt['depth'] = $depth;
|
|
|
|
$s = self::encodeOptions( $opt, 'json' );
|
|
|
|
} else {
|
|
|
|
$s = self::encodeOptions( $this->mOptions, 'json' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOptionsAsJsString( $depth = NULL ) {
|
|
|
|
return Xml::escapeJsString( $s );
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOptionsAsUrlParameters() {
|
|
|
|
$u = '';
|
|
|
|
|
|
|
|
foreach ( $this->mOptions as $k => $v ) {
|
|
|
|
if ( $u != '' ) $u .= '&';
|
2010-04-20 22:00:34 +00:00
|
|
|
$u .= $k . '=' . urlencode( $v ) ;
|
2008-06-28 20:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $u;
|
|
|
|
}
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
/**
|
2008-02-04 09:22:12 +00:00
|
|
|
* Ajax call. This is called by efCategoryTreeAjaxWrapper, which is used to
|
2006-08-24 17:12:13 +00:00
|
|
|
* load CategoryTreeFunctions.php on demand.
|
|
|
|
*/
|
2008-06-28 20:13:20 +00:00
|
|
|
function ajax( $category, $depth = 1 ) {
|
2010-04-06 21:46:46 +00:00
|
|
|
global $wgDBname, $wgUser;
|
2006-08-24 17:12:13 +00:00
|
|
|
$title = self::makeTitle( $category );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( ! $title ) {
|
|
|
|
return false; # TODO: error message?
|
|
|
|
}
|
2006-07-26 17:12:30 +00:00
|
|
|
|
2010-04-06 21:46:46 +00:00
|
|
|
# configkey needed to take into account variant and secure options.
|
|
|
|
$configkey = $wgUser->getPageRenderingHash();
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
# Retrieve page_touched for the category
|
|
|
|
$dbkey = $title->getDBkey();
|
2010-02-13 23:03:40 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2008-02-04 09:22:12 +00:00
|
|
|
$touched = $dbr->selectField( 'page', 'page_touched',
|
|
|
|
array(
|
2006-08-24 17:12:13 +00:00
|
|
|
'page_namespace' => NS_CATEGORY,
|
|
|
|
'page_title' => $dbkey,
|
|
|
|
), __METHOD__ );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-06 21:46:46 +00:00
|
|
|
$mckey = "$wgDBname:categorytree(" . $this->getOptionsAsCacheKey( $depth ) . "):$dbkey:$configkey";
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-29 15:49:23 +00:00
|
|
|
$response = new AjaxResponse();
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-29 15:49:23 +00:00
|
|
|
if ( $response->checkLastModified( $touched ) ) {
|
|
|
|
return $response;
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-29 15:49:23 +00:00
|
|
|
if ( $response->loadFromMemcached( $mckey, $touched ) ) {
|
|
|
|
return $response;
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
$html = $this->renderChildren( $title, $depth );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $html == '' ) {
|
|
|
|
# HACK: Safari doesn't like empty responses.
|
|
|
|
# see Bug 7219 and http://bugzilla.opendarwin.org/show_bug.cgi?id=10716
|
|
|
|
$html = ' ';
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-29 15:49:23 +00:00
|
|
|
$response->addText( $html );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-29 15:49:23 +00:00
|
|
|
$response->storeInMemcached( $mckey, 86400 );
|
|
|
|
|
|
|
|
return $response;
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-04 09:22:12 +00:00
|
|
|
* Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to
|
2006-08-24 17:12:13 +00:00
|
|
|
* load CategoryTreeFunctions.php on demand.
|
|
|
|
*/
|
2010-04-20 22:00:34 +00:00
|
|
|
function getTag( $parser, $category, $hideroot = false, $attr, $depth = 1, $allowMissing = false ) {
|
2006-08-24 17:12:13 +00:00
|
|
|
global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag;
|
|
|
|
static $uniq = 0;
|
|
|
|
|
|
|
|
$category = trim( $category );
|
|
|
|
if ( $category === '' ) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-20 22:00:34 +00:00
|
|
|
|
2008-07-02 15:13:45 +00:00
|
|
|
if ( $parser && $wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag ) {
|
2006-08-24 17:12:13 +00:00
|
|
|
$parser->disableCache();
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
$title = self::makeTitle( $category );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $title === false || $title === null ) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-30 21:35:01 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( isset( $attr['class'] ) ) {
|
|
|
|
$attr['class'] .= ' CategoryTreeTag';
|
|
|
|
} else {
|
|
|
|
$attr['class'] = ' CategoryTreeTag';
|
|
|
|
}
|
2008-07-04 20:05:29 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$html = '';
|
2008-06-30 21:35:01 +00:00
|
|
|
$html .= Xml::openElement( 'div', $attr );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-07-02 20:19:54 +00:00
|
|
|
if ( !$allowMissing && !$title->getArticleID() ) {
|
2008-03-18 17:38:32 +00:00
|
|
|
$html .= Xml::openElement( 'span', array( 'class' => 'CategoryTreeNotice' ) );
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $parser ) {
|
2009-04-14 17:44:55 +00:00
|
|
|
$html .= $parser->recursiveTagParse( wfMsgNoTrans( 'categorytree-not-found', $category ) );
|
|
|
|
} else {
|
|
|
|
$html .= wfMsgExt( 'categorytree-not-found', 'parseinline', htmlspecialchars( $category ) );
|
|
|
|
}
|
2008-03-18 17:38:32 +00:00
|
|
|
$html .= Xml::closeElement( 'span' );
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
2006-07-29 09:18:34 +00:00
|
|
|
else {
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( !$hideroot ) {
|
|
|
|
$html .= CategoryTree::renderNode( $title, $depth, $wgCategoryTreeDynamicTag );
|
|
|
|
} else if ( !$wgCategoryTreeDynamicTag ) {
|
|
|
|
$html .= $this->renderChildren( $title, $depth );
|
|
|
|
} else {
|
2006-08-24 17:12:13 +00:00
|
|
|
$uniq += 1;
|
|
|
|
$load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-03-18 17:38:32 +00:00
|
|
|
$html .= Xml::openElement( 'script', array( 'type' => 'text/javascript', 'id' => $load ) );
|
2008-06-28 20:13:20 +00:00
|
|
|
$html .= 'categoryTreeLoadChildren("' . Xml::escapeJsString( $title->getDBkey() ) . '", ' . $this->getOptionsAsJsStructure( $depth ) . ', document.getElementById("' . $load . '").parentNode);';
|
2008-03-18 17:38:32 +00:00
|
|
|
$html .= Xml::closeElement( 'script' );
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
2006-07-29 09:18:34 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-03-18 17:38:32 +00:00
|
|
|
$html .= Xml::closeElement( 'div' );
|
2006-08-24 17:12:13 +00:00
|
|
|
$html .= "\n\t\t";
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
return $html;
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
2006-08-24 17:12:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string with an HTML representation of the children of the given category.
|
|
|
|
* $title must be a Title object
|
|
|
|
*/
|
2010-06-02 09:10:09 +00:00
|
|
|
function renderChildren( $title, $depth = 1 ) {
|
2008-07-02 09:49:28 +00:00
|
|
|
global $wgCategoryTreeMaxChildren, $wgCategoryTreeUseCategoryTable;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $title->getNamespace() != NS_CATEGORY ) {
|
2007-09-18 15:52:30 +00:00
|
|
|
// Non-categories can't have children. :)
|
|
|
|
return '';
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-02-13 23:03:40 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2006-08-24 17:12:13 +00:00
|
|
|
|
2008-07-02 09:49:28 +00:00
|
|
|
$inverse = $this->isInverse();
|
2010-04-20 22:00:34 +00:00
|
|
|
$mode = $this->getOption( 'mode' );
|
|
|
|
$namespaces = $this->getOption( 'namespaces' );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-07-02 09:49:28 +00:00
|
|
|
if ( $inverse ) {
|
|
|
|
$ctJoinCond = ' cl_to = cat.page_title AND cat.page_namespace = ' . NS_CATEGORY;
|
2008-07-02 20:19:54 +00:00
|
|
|
$ctWhere = ' cl_from = ' . $title->getArticleId();
|
|
|
|
$ctJoin = ' RIGHT JOIN ';
|
2008-07-02 09:49:28 +00:00
|
|
|
$nsmatch = '';
|
2008-07-01 21:40:42 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-07-02 09:49:28 +00:00
|
|
|
$ctJoinCond = ' cl_from = cat.page_id ';
|
2008-07-02 20:19:54 +00:00
|
|
|
$ctWhere = ' cl_to = ' . $dbr->addQuotes( $title->getDBkey() );
|
|
|
|
$ctJoin = ' JOIN ';
|
2008-07-02 09:49:28 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
# namespace filter.
|
2008-07-02 09:49:28 +00:00
|
|
|
if ( $namespaces ) {
|
2010-04-20 22:00:34 +00:00
|
|
|
# NOTE: we assume that the $namespaces array contains only integers! decodeNamepsaces makes it so.
|
|
|
|
if ( sizeof( $namespaces ) === 1 ) {
|
|
|
|
$nsmatch = ' AND cat.page_namespace = ' . $namespaces[0] . ' ';
|
|
|
|
} else {
|
|
|
|
$nsmatch = ' AND cat.page_namespace IN ( ' . implode( ', ', $namespaces ) . ') ';
|
|
|
|
}
|
2008-07-02 09:49:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $mode == CT_MODE_ALL ) {
|
|
|
|
$nsmatch = '';
|
|
|
|
} else if ( $mode == CT_MODE_PAGES ) {
|
|
|
|
$nsmatch = ' AND cat.page_namespace != ' . NS_IMAGE;
|
|
|
|
} else {
|
|
|
|
$nsmatch = ' AND cat.page_namespace = ' . NS_CATEGORY;
|
|
|
|
}
|
2008-07-02 09:49:28 +00:00
|
|
|
}
|
2008-07-01 21:40:42 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
# additional stuff to be used if "transaltion" by interwiki-links is desired
|
2008-06-30 14:09:47 +00:00
|
|
|
$transFields = '';
|
|
|
|
$transJoin = '';
|
|
|
|
$transWhere = '';
|
|
|
|
|
|
|
|
# fetch member count if possible
|
2008-07-02 09:49:28 +00:00
|
|
|
$doCount = !$inverse && $wgCategoryTreeUseCategoryTable;
|
2008-06-30 14:09:47 +00:00
|
|
|
|
|
|
|
$countFields = '';
|
|
|
|
$countJoin = '';
|
|
|
|
|
|
|
|
if ( $doCount ) {
|
|
|
|
$cat = $dbr->tableName( 'category' );
|
|
|
|
$countJoin = " LEFT JOIN $cat ON cat_title = page_title AND page_namespace = " . NS_CATEGORY;
|
|
|
|
$countFields = ', cat_id, cat_title, cat_subcats, cat_pages, cat_files';
|
|
|
|
}
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$page = $dbr->tableName( 'page' );
|
|
|
|
$categorylinks = $dbr->tableName( 'categorylinks' );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-07-02 20:19:54 +00:00
|
|
|
$sql = "SELECT cat.page_namespace, cat.page_title,
|
|
|
|
cl_to, cl_from
|
2006-08-24 17:12:13 +00:00
|
|
|
$transFields
|
2008-06-30 14:09:47 +00:00
|
|
|
$countFields
|
2006-08-24 17:12:13 +00:00
|
|
|
FROM $page as cat
|
2008-07-02 20:19:54 +00:00
|
|
|
$ctJoin $categorylinks ON $ctJoinCond
|
2006-08-24 17:12:13 +00:00
|
|
|
$transJoin
|
2008-06-30 14:09:47 +00:00
|
|
|
$countJoin
|
2008-07-02 09:49:28 +00:00
|
|
|
WHERE $ctWhere
|
2006-08-24 17:12:13 +00:00
|
|
|
$nsmatch
|
2010-04-20 22:00:34 +00:00
|
|
|
" . /*AND cat.page_is_redirect = 0*/"
|
2006-08-24 17:12:13 +00:00
|
|
|
$transWhere
|
2010-02-09 16:15:47 +00:00
|
|
|
ORDER BY cl_sortkey";
|
2010-04-20 22:00:34 +00:00
|
|
|
$sql = $dbr->limitResult( $sql, (int)$wgCategoryTreeMaxChildren );
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$res = $dbr->query( $sql, __METHOD__ );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
# collect categories separately from other pages
|
|
|
|
$categories = '';
|
|
|
|
$other = '';
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-30 14:09:47 +00:00
|
|
|
while ( $row = $dbr->fetchObject( $res ) ) {
|
2010-04-20 22:00:34 +00:00
|
|
|
# NOTE: in inverse mode, the page record may be null, because we use a right join.
|
2008-07-02 20:19:54 +00:00
|
|
|
# happens for categories with no category page (red cat links)
|
2010-01-06 21:24:10 +00:00
|
|
|
if ( $inverse && $row->page_title === null ) {
|
2008-07-02 20:19:54 +00:00
|
|
|
$t = Title::makeTitle( NS_CATEGORY, $row->cl_to );
|
2010-04-20 22:00:34 +00:00
|
|
|
} else {
|
|
|
|
# TODO: translation support; ideally added to Title object
|
2008-07-02 20:19:54 +00:00
|
|
|
$t = Title::newFromRow( $row );
|
|
|
|
}
|
2007-09-01 11:26:00 +00:00
|
|
|
|
2010-01-06 21:24:10 +00:00
|
|
|
$cat = null;
|
2008-06-30 14:09:47 +00:00
|
|
|
|
|
|
|
if ( $doCount && $row->page_namespace == NS_CATEGORY ) {
|
|
|
|
$cat = Category::newFromRow( $row, $t );
|
|
|
|
}
|
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
$s = $this->renderNodeInfo( $t, $cat, $depth -1, false );
|
2007-09-01 11:26:00 +00:00
|
|
|
$s .= "\n\t\t";
|
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $row->page_namespace == NS_CATEGORY ) {
|
|
|
|
$categories .= $s;
|
|
|
|
} else {
|
|
|
|
$other .= $s;
|
|
|
|
}
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$dbr->freeResult( $res );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2007-09-01 11:26:00 +00:00
|
|
|
return $categories . $other;
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
2006-07-26 17:12:30 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
/**
|
|
|
|
* Returns a string with an HTML representation of the parents of the given category.
|
|
|
|
* $title must be a Title object
|
|
|
|
*/
|
2010-06-02 09:10:09 +00:00
|
|
|
function renderParents( $title ) {
|
2006-08-24 17:12:13 +00:00
|
|
|
global $wgCategoryTreeMaxChildren;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-02-13 23:03:40 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
# additional stuff to be used if "transaltion" by interwiki-links is desired
|
2006-08-24 17:12:13 +00:00
|
|
|
$transFields = '';
|
|
|
|
$transJoin = '';
|
|
|
|
$transWhere = '';
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$categorylinks = $dbr->tableName( 'categorylinks' );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$sql = "SELECT " . NS_CATEGORY . " as page_namespace, cl_to as page_title $transFields
|
|
|
|
FROM $categorylinks
|
|
|
|
$transJoin
|
2008-02-04 09:22:12 +00:00
|
|
|
WHERE cl_from = " . $title->getArticleID() . "
|
2006-08-24 17:12:13 +00:00
|
|
|
$transWhere
|
2010-02-09 16:15:47 +00:00
|
|
|
ORDER BY cl_to";
|
2010-04-20 22:00:34 +00:00
|
|
|
$sql = $dbr->limitResult( $sql, (int)$wgCategoryTreeMaxChildren );
|
2006-07-26 17:12:30 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$res = $dbr->query( $sql, __METHOD__ );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$special = Title::makeTitle( NS_SPECIAL, 'CategoryTree' );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
$s = '';
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-30 14:09:47 +00:00
|
|
|
while ( $row = $dbr->fetchObject( $res ) ) {
|
2010-04-20 22:00:34 +00:00
|
|
|
# TODO: translation support; ideally added to Title object
|
2008-06-30 14:09:47 +00:00
|
|
|
$t = Title::newFromRow( $row );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
# $trans = $title->getLocalizedText();
|
|
|
|
$trans = ''; # place holder for when translated titles are available
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$label = htmlspecialchars( $t->getText() );
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $trans && $trans != $label ) $label .= ' ' . Xml::element( 'i', array( 'class' => 'translation' ), $trans );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
$wikiLink = $special->getLocalURL( 'target=' . $t->getPartialURL() . '&' . $this->getOptionsAsUrlParameters() );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2009-02-09 21:59:06 +00:00
|
|
|
if ( $s !== '' ) $s .= wfMsgExt( 'pipe-separator' , 'escapenoentities' );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-03-18 17:38:32 +00:00
|
|
|
$s .= Xml::openElement( 'span', array( 'class' => 'CategoryTreeItem' ) );
|
|
|
|
$s .= Xml::openElement( 'a', array( 'class' => 'CategoryTreeLabel', 'href' => $wikiLink ) ) . $label . Xml::closeElement( 'a' );
|
|
|
|
$s .= Xml::closeElement( 'span' );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$s .= "\n\t\t";
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$dbr->freeResult( $res );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
return $s;
|
|
|
|
}
|
2006-07-26 17:12:30 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
/**
|
|
|
|
* Returns a string with a HTML represenation of the given page.
|
|
|
|
* $title must be a Title object
|
|
|
|
*/
|
2008-06-30 14:09:47 +00:00
|
|
|
function renderNode( $title, $children = 0, $loadchildren = false ) {
|
2008-07-02 09:49:28 +00:00
|
|
|
global $wgCategoryTreeUseCategoryTable;
|
|
|
|
|
|
|
|
if ( $wgCategoryTreeUseCategoryTable && $title->getNamespace() == NS_CATEGORY && !$this->isInverse() ) {
|
|
|
|
$cat = Category::newFromTitle( $title );
|
2010-04-20 22:00:34 +00:00
|
|
|
} else {
|
|
|
|
$cat = null;
|
2008-07-02 09:49:28 +00:00
|
|
|
}
|
2008-06-30 14:09:47 +00:00
|
|
|
|
|
|
|
return $this->renderNodeInfo( $title, $cat, $children, $loadchildren );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string with a HTML represenation of the given page.
|
|
|
|
* $info must be an associative array, containing at least a Title object under the 'title' key.
|
|
|
|
*/
|
|
|
|
function renderNodeInfo( $title, $cat, $children = 0, $loadchildren = false ) {
|
2010-06-01 08:58:04 +00:00
|
|
|
global $wgCategoryTreeMaxScanRows;
|
2006-08-24 17:12:13 +00:00
|
|
|
static $uniq = 0;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
$mode = $this->getOption( 'mode' );
|
2006-08-24 17:12:13 +00:00
|
|
|
$load = false;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
if ( $children > 0 && $loadchildren ) {
|
2006-08-24 17:12:13 +00:00
|
|
|
$uniq += 1;
|
2006-07-26 17:12:30 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 );
|
|
|
|
}
|
2006-07-26 17:12:30 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$ns = $title->getNamespace();
|
2008-01-14 10:09:08 +00:00
|
|
|
$key = $title->getDBkey();
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
# $trans = $title->getLocalizedText();
|
|
|
|
$trans = ''; # place holder for when translated titles are available
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
$hideprefix = $this->getOption( 'hideprefix' );
|
2008-06-30 21:22:03 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $hideprefix == CT_HIDEPREFIX_ALWAYS ) {
|
|
|
|
$hideprefix = true;
|
|
|
|
} else if ( $hideprefix == CT_HIDEPREFIX_AUTO ) {
|
|
|
|
$hideprefix = ( $mode == CT_MODE_CATEGORIES );
|
|
|
|
} else if ( $hideprefix == CT_HIDEPREFIX_CATEGORIES ) {
|
|
|
|
$hideprefix = ( $ns == NS_CATEGORY );
|
|
|
|
} else {
|
|
|
|
$hideprefix = true;
|
|
|
|
}
|
2008-06-30 21:22:03 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
# when showing only categories, omit namespace in label unless we explicitely defined the configuration setting
|
|
|
|
# patch contributed by Manuel Schneider <manuel.schneider@wikimedia.ch>, Bug 8011
|
|
|
|
if ( $hideprefix ) {
|
|
|
|
$label = htmlspecialchars( $title->getText() );
|
|
|
|
} else {
|
|
|
|
$label = htmlspecialchars( $title->getPrefixedText() );
|
|
|
|
}
|
2009-05-27 06:17:56 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $trans && $trans != $label ) {
|
|
|
|
$label .= ' ' . Xml::element( 'i', array( 'class' => 'translation' ), $trans );
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$labelClass = 'CategoryTreeLabel ' . ' CategoryTreeLabelNs' . $ns;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-07-02 20:19:54 +00:00
|
|
|
if ( !$title->getArticleId() ) {
|
|
|
|
$labelClass .= ' new';
|
|
|
|
$wikiLink = $title->getLocalURL( 'action=edit&redlink=1' );
|
|
|
|
} else {
|
|
|
|
$wikiLink = $title->getLocalURL();
|
|
|
|
}
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
if ( $ns == NS_CATEGORY ) {
|
|
|
|
$labelClass .= ' CategoryTreeLabelCategory';
|
|
|
|
} else {
|
|
|
|
$labelClass .= ' CategoryTreeLabelPage';
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( ( $ns % 2 ) > 0 ) {
|
|
|
|
$labelClass .= ' CategoryTreeLabelTalk';
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-30 14:09:47 +00:00
|
|
|
$count = false;
|
2006-08-24 17:12:13 +00:00
|
|
|
$s = '';
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
# NOTE: things in CategoryTree.js rely on the exact order of tags!
|
2006-08-24 17:12:13 +00:00
|
|
|
# Specifically, the CategoryTreeChildren div must be the first
|
|
|
|
# sibling with nodeName = DIV of the grandparent of the expland link.
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-03-18 17:38:32 +00:00
|
|
|
$s .= Xml::openElement( 'div', array( 'class' => 'CategoryTreeSection' ) );
|
|
|
|
$s .= Xml::openElement( 'div', array( 'class' => 'CategoryTreeItem' ) );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
$attr = array( 'class' => 'CategoryTreeBullet' );
|
|
|
|
|
2010-06-01 08:58:04 +00:00
|
|
|
# Get counts, with conversion to integer so === works
|
2010-06-01 14:28:08 +00:00
|
|
|
$pageCount = $cat ? intval( $cat->getPageCount() ) : 0;
|
|
|
|
$subcatCount = $cat ? intval( $cat->getSubcatCount() ) : 0;
|
|
|
|
$fileCount = $cat ? intval( $cat->getFileCount() ) : 0;
|
2010-06-01 08:58:04 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
if ( $ns == NS_CATEGORY ) {
|
2010-06-01 08:58:04 +00:00
|
|
|
|
2008-06-30 14:09:47 +00:00
|
|
|
if ( $cat ) {
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $mode == CT_MODE_CATEGORIES ) {
|
2010-06-01 08:58:04 +00:00
|
|
|
$count = $subcatCount;
|
2010-04-20 22:00:34 +00:00
|
|
|
} else if ( $mode == CT_MODE_PAGES ) {
|
2010-06-01 08:58:04 +00:00
|
|
|
$count = $pageCount - $fileCount;
|
2010-04-20 22:00:34 +00:00
|
|
|
} else {
|
2010-06-01 08:58:04 +00:00
|
|
|
$count = $pageCount;
|
2010-04-20 22:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-01 08:58:04 +00:00
|
|
|
if ( $count === 0 || $pageCount > $wgCategoryTreeMaxScanRows ) {
|
2010-05-28 02:15:44 +00:00
|
|
|
$bullet = wfMsgNoTrans( 'categorytree-empty-bullet' ) . ' ';
|
|
|
|
$attr['class'] = 'CategoryTreeEmptyBullet';
|
|
|
|
} else {
|
|
|
|
$linkattr = array( );
|
|
|
|
if ( $load ) {
|
|
|
|
$linkattr[ 'id' ] = $load;
|
|
|
|
}
|
2010-04-20 22:00:34 +00:00
|
|
|
|
2010-05-28 02:15:44 +00:00
|
|
|
$linkattr[ 'class' ] = "CategoryTreeToggle";
|
|
|
|
$linkattr['style'] = 'display: none;'; // Unhidden by JS
|
2008-06-28 20:13:20 +00:00
|
|
|
|
2010-05-28 02:15:44 +00:00
|
|
|
if ( $children == 0 || $loadchildren ) {
|
|
|
|
$tag = 'span';
|
2010-04-20 22:00:34 +00:00
|
|
|
$txt = wfMsgNoTrans( 'categorytree-expand-bullet' );
|
2010-05-28 02:15:44 +00:00
|
|
|
$linkattr[ 'onclick' ] = "if (this.href) this.href='javascript:void(0)'; categoryTreeExpandNode('" . Xml::escapeJsString( $key ) . "'," . $this->getOptionsAsJsStructure() . ",this);";
|
|
|
|
# Don't load this message for ajax requests, so that we don't have to initialise $wgLang
|
|
|
|
$linkattr[ 'title' ] = $this->mIsAjaxRequest ? '##LOAD##' : wfMsgNoTrans( 'categorytree-expand' );
|
|
|
|
} else {
|
|
|
|
$tag = 'span';
|
|
|
|
$txt = wfMsgNoTrans( 'categorytree-collapse-bullet' );
|
|
|
|
$linkattr[ 'onclick' ] = "if (this.href) this.href='javascript:void(0)'; categoryTreeCollapseNode('" . Xml::escapeJsString( $key ) . "'," . $this->getOptionsAsJsStructure() . ",this);";
|
|
|
|
$linkattr[ 'title' ] = wfMsgNoTrans( 'categorytree-collapse' );
|
|
|
|
$linkattr[ 'class' ] .= ' CategoryTreeLoaded';
|
2010-04-20 22:00:34 +00:00
|
|
|
}
|
2008-06-28 20:13:20 +00:00
|
|
|
|
2010-05-28 02:15:44 +00:00
|
|
|
if ( $tag == 'a' ) {
|
|
|
|
$linkattr[ 'href' ] = $wikiLink;
|
|
|
|
}
|
|
|
|
$bullet = Xml::openElement( $tag, $linkattr ) . $txt . Xml::closeElement( $tag ) . ' ';
|
2010-04-20 22:00:34 +00:00
|
|
|
}
|
2006-08-24 17:12:13 +00:00
|
|
|
} else {
|
2010-05-28 02:15:44 +00:00
|
|
|
$bullet = wfMsgNoTrans( 'categorytree-page-bullet' );
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
2010-06-01 08:58:04 +00:00
|
|
|
$s .= Xml::tags( 'span', $attr, $bullet ) . ' ';
|
2008-06-28 20:13:20 +00:00
|
|
|
|
2008-03-18 17:38:32 +00:00
|
|
|
$s .= Xml::openElement( 'a', array( 'class' => $labelClass, 'href' => $wikiLink ) ) . $label . Xml::closeElement( 'a' );
|
2008-06-30 14:09:47 +00:00
|
|
|
|
|
|
|
if ( $count !== false && $this->getOption( 'showcount' ) ) {
|
2010-06-01 08:58:04 +00:00
|
|
|
$pages = $pageCount - $subcatCount - $fileCount;
|
2008-06-30 14:09:47 +00:00
|
|
|
|
|
|
|
$attr = array(
|
2010-06-01 08:58:04 +00:00
|
|
|
'title' => wfMsgExt( 'categorytree-member-counts', 'parsemag', $subcatCount, $pages , $fileCount, $pageCount, $count )
|
2008-06-30 14:09:47 +00:00
|
|
|
);
|
|
|
|
|
2008-07-11 23:07:01 +00:00
|
|
|
$s .= ' ';
|
2008-07-25 21:55:13 +00:00
|
|
|
global $wgLang;
|
2008-10-20 00:57:55 +00:00
|
|
|
$s .= Xml::tags( 'span', $attr,
|
|
|
|
wfMsgExt( 'categorytree-member-num',
|
|
|
|
array( 'parsemag', 'escapenoentities' ),
|
2010-06-01 08:58:04 +00:00
|
|
|
$subcatCount,
|
2008-10-20 00:57:55 +00:00
|
|
|
$pages,
|
2010-06-01 08:58:04 +00:00
|
|
|
$fileCount,
|
|
|
|
$pageCount,
|
2008-10-20 00:57:55 +00:00
|
|
|
$wgLang->formatNum( $count ) ) );
|
2008-06-30 14:09:47 +00:00
|
|
|
}
|
|
|
|
|
2008-03-18 17:38:32 +00:00
|
|
|
$s .= Xml::closeElement( 'div' );
|
2006-08-24 17:12:13 +00:00
|
|
|
$s .= "\n\t\t";
|
2008-06-28 20:13:20 +00:00
|
|
|
$s .= Xml::openElement( 'div', array( 'class' => 'CategoryTreeChildren', 'style' => $children > 0 ? "display:block" : "display:none" ) );
|
2010-04-20 22:00:34 +00:00
|
|
|
|
|
|
|
if ( $ns == NS_CATEGORY && $children > 0 && !$loadchildren ) {
|
2008-07-01 21:40:42 +00:00
|
|
|
$children = $this->renderChildren( $title, $children );
|
|
|
|
if ( $children == '' ) {
|
|
|
|
$s .= Xml::openElement( 'i', array( 'class' => 'CategoryTreeNotice' ) );
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $mode == CT_MODE_CATEGORIES ) {
|
|
|
|
$s .= wfMsgExt( 'categorytree-no-subcategories', 'parsemag' );
|
|
|
|
} else if ( $mode == CT_MODE_PAGES ) {
|
|
|
|
$s .= wfMsgExt( 'categorytree-no-pages', 'parsemag' );
|
|
|
|
} else if ( $mode == CT_MODE_PARENTS ) {
|
|
|
|
$s .= wfMsgExt( 'categorytree-no-parent-categories', 'parsemag' );
|
|
|
|
} else {
|
|
|
|
$s .= wfMsgExt( 'categorytree-nothing-found', 'parsemag' );
|
|
|
|
}
|
2008-07-01 21:40:42 +00:00
|
|
|
$s .= Xml::closeElement( 'i' );
|
|
|
|
} else {
|
|
|
|
$s .= $children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-18 17:38:32 +00:00
|
|
|
$s .= Xml::closeElement( 'div' );
|
|
|
|
$s .= Xml::closeElement( 'div' );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
if ( $load ) {
|
|
|
|
$s .= "\n\t\t";
|
2008-03-18 17:38:32 +00:00
|
|
|
$s .= Xml::openElement( 'script', array( 'type' => 'text/javascript' ) );
|
2010-04-20 22:00:34 +00:00
|
|
|
$s .= 'categoryTreeExpandNode("' . Xml::escapeJsString( $key ) . '", ' . $this->getOptionsAsJsStructure( $children ) . ', document.getElementById("' . $load . '"));';
|
2008-03-18 17:38:32 +00:00
|
|
|
$s .= Xml::closeElement( 'script' );
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$s .= "\n\t\t";
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a Title object from a user provided (and thus unsafe) string
|
|
|
|
*/
|
|
|
|
static function makeTitle( $title ) {
|
|
|
|
global $wgContLang, $wgCanonicalNamespaceNames;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
$title = trim( $title );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-01-06 21:24:10 +00:00
|
|
|
if ( $title === null || $title === '' || $title === false ) {
|
|
|
|
return null;
|
2006-08-24 17:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# The title must be in the category namespace
|
|
|
|
# Ignore a leading Category: if there is one
|
|
|
|
$t = Title::newFromText( $title, NS_CATEGORY );
|
2007-08-25 12:40:40 +00:00
|
|
|
if ( $t && ( $t->getNamespace() != NS_CATEGORY || $t->getInterWiki() != '' ) ) {
|
2006-08-24 17:12:13 +00:00
|
|
|
$title = "Category:$title";
|
|
|
|
$t = Title::newFromText( $title );
|
|
|
|
}
|
|
|
|
return $t;
|
|
|
|
}
|
|
|
|
}
|