2006-07-26 17:12:30 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Core functions 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
|
2007-03-13 11:39:12 +00:00
|
|
|
|
* @author Daniel Kinzler, brightbyte.de
|
|
|
|
|
* @copyright © 2006-2007 Daniel Kinzler
|
2006-07-26 17:12:30 +00:00
|
|
|
|
* @licence GNU General Public Licence 2.0 or later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if( !defined( 'MEDIAWIKI' ) ) {
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the script tags in an OutputPage object
|
|
|
|
|
* @param OutputPage $outputPage
|
|
|
|
|
*/
|
|
|
|
|
static function setHeaders( &$outputPage ) {
|
2007-08-25 15:23:20 +00:00
|
|
|
|
global $wgJsMimeType, $wgScriptPath, $wgContLang, $wgCategoryTreeExtPath, $wgCategoryTreeVersion;
|
2006-08-24 17:12:13 +00:00
|
|
|
|
efInjectCategoryTreeMessages();
|
|
|
|
|
|
|
|
|
|
# Register css file for CategoryTree
|
|
|
|
|
$outputPage->addLink(
|
|
|
|
|
array(
|
|
|
|
|
'rel' => 'stylesheet',
|
|
|
|
|
'type' => 'text/css',
|
2007-08-25 15:23:20 +00:00
|
|
|
|
'href' => "$wgScriptPath$wgCategoryTreeExtPath/CategoryTree.css?$wgCategoryTreeVersion",
|
2006-08-24 17:12:13 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2006-09-02 11:11:20 +00:00
|
|
|
|
# Register css RTL file for CategoryTree
|
|
|
|
|
if( $wgContLang->isRTL() ) {
|
|
|
|
|
$outputPage->addLink(
|
|
|
|
|
array(
|
|
|
|
|
'rel' => 'stylesheet',
|
|
|
|
|
'type' => 'text/css',
|
2007-08-25 15:23:20 +00:00
|
|
|
|
'href' => "$wgScriptPath$wgCategoryTreeExtPath/CategoryTree.rtl.css?$wgCategoryTreeVersion"
|
2006-09-02 11:11:20 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
|
# Register main js file for CategoryTree
|
|
|
|
|
$outputPage->addScript(
|
2007-08-25 15:23:20 +00:00
|
|
|
|
"<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.js?{$wgCategoryTreeVersion}\">" .
|
2006-08-24 17:12:13 +00:00
|
|
|
|
"</script>\n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# Add messages
|
|
|
|
|
$outputPage->addScript(
|
|
|
|
|
" <script type=\"{$wgJsMimeType}\">
|
2006-10-10 06:27:07 +00:00
|
|
|
|
var categoryTreeCollapseMsg = \"".Xml::escapeJsString(self::msg('collapse'))."\";
|
|
|
|
|
var categoryTreeExpandMsg = \"".Xml::escapeJsString(self::msg('expand'))."\";
|
|
|
|
|
var categoryTreeLoadMsg = \"".Xml::escapeJsString(self::msg('load'))."\";
|
|
|
|
|
var categoryTreeLoadingMsg = \"".Xml::escapeJsString(self::msg('loading'))."\";
|
|
|
|
|
var categoryTreeNothingFoundMsg = \"".Xml::escapeJsString(self::msg('nothing-found'))."\";
|
|
|
|
|
var categoryTreeNoSubcategoriesMsg = \"".Xml::escapeJsString(self::msg('no-subcategories'))."\";
|
|
|
|
|
var categoryTreeNoPagesMsg = \"".Xml::escapeJsString(self::msg('no-pages'))."\";
|
2007-08-25 15:23:20 +00:00
|
|
|
|
var categoryTreeErrorMsg = \"".Xml::escapeJsString(self::msg('error'))."\";
|
|
|
|
|
var categoryTreeRetryMsg = \"".Xml::escapeJsString(self::msg('retry'))."\";
|
2006-08-24 17:12:13 +00:00
|
|
|
|
</script>\n"
|
|
|
|
|
);
|
|
|
|
|
}
|
2006-07-29 09:18:34 +00:00
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* Ajax call. This is called by efCategoryTreeAjaxWrapper, which is used to
|
|
|
|
|
* load CategoryTreeFunctions.php on demand.
|
|
|
|
|
*/
|
|
|
|
|
function ajax( $category, $mode ) {
|
2006-08-29 15:49:23 +00:00
|
|
|
|
global $wgDBname;
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$title = self::makeTitle( $category );
|
|
|
|
|
|
|
|
|
|
if ( ! $title ) return false; #TODO: error message?
|
|
|
|
|
$this->mIsAjaxRequest = true;
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
|
# Retrieve page_touched for the category
|
|
|
|
|
$dbkey = $title->getDBkey();
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
$touched = $dbr->selectField( 'page', 'page_touched',
|
|
|
|
|
array(
|
|
|
|
|
'page_namespace' => NS_CATEGORY,
|
|
|
|
|
'page_title' => $dbkey,
|
|
|
|
|
), __METHOD__ );
|
2006-08-29 15:49:23 +00:00
|
|
|
|
|
2007-03-30 13:43:37 +00:00
|
|
|
|
$mckey = "$wgDBname:categorytree($mode):$dbkey"; //FIXME: would need to add depth parameter.
|
2006-08-29 15:49:23 +00:00
|
|
|
|
|
|
|
|
|
$response = new AjaxResponse();
|
|
|
|
|
|
|
|
|
|
if ( $response->checkLastModified( $touched ) ) {
|
|
|
|
|
return $response;
|
2006-08-24 17:12:13 +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
|
|
|
|
}
|
2006-08-29 15:49:23 +00:00
|
|
|
|
|
2007-03-30 13:43:37 +00:00
|
|
|
|
$html = $this->renderChildren( $title, $mode ); //FIXME: would need to pass depth parameter.
|
|
|
|
|
|
2006-09-03 21:44:47 +00:00
|
|
|
|
if ( $html == '' ) $html = ' '; #HACK: Safari doesn't like empty responses.
|
|
|
|
|
#see Bug 7219 and http://bugzilla.opendarwin.org/show_bug.cgi?id=10716
|
|
|
|
|
|
2006-08-29 15:49:23 +00:00
|
|
|
|
$response->addText( $html );
|
|
|
|
|
|
|
|
|
|
$response->storeInMemcached( $mckey, 86400 );
|
|
|
|
|
|
|
|
|
|
return $response;
|
2006-08-24 17:12:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to
|
|
|
|
|
* load CategoryTreeFunctions.php on demand.
|
|
|
|
|
*/
|
2007-04-30 21:18:56 +00:00
|
|
|
|
function getTag( &$parser, $category, $mode, $hideroot = false, $style = '', $depth=1 ) {
|
2006-08-24 17:12:13 +00:00
|
|
|
|
global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag;
|
|
|
|
|
static $uniq = 0;
|
|
|
|
|
|
|
|
|
|
$this->mIsAjaxRequest = false;
|
|
|
|
|
$category = trim( $category );
|
|
|
|
|
if ( $category === '' ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if ( $wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag ) {
|
|
|
|
|
$parser->disableCache();
|
|
|
|
|
}
|
|
|
|
|
$title = self::makeTitle( $category );
|
|
|
|
|
|
|
|
|
|
if ( $title === false || $title === NULL ) return false;
|
|
|
|
|
|
|
|
|
|
$html = '';
|
|
|
|
|
$html .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeTag', 'style' => $style ) );
|
|
|
|
|
|
|
|
|
|
if ( !$title->getArticleID() ) {
|
|
|
|
|
$html .= wfOpenElement( 'span', array( 'class' => 'CategoryTreeNotice' ) );
|
|
|
|
|
$html .= self::msg( 'not-found' , htmlspecialchars( $category ) );
|
|
|
|
|
$html .= wfCloseElement( 'span' );
|
|
|
|
|
}
|
2006-07-29 09:18:34 +00:00
|
|
|
|
else {
|
2007-04-30 21:18:56 +00:00
|
|
|
|
if ( !$hideroot ) $html .= CategoryTree::renderNode( $title, $mode, $depth>0, $wgCategoryTreeDynamicTag, $depth-1 );
|
2007-05-01 12:14:45 +00:00
|
|
|
|
else if ( !$wgCategoryTreeDynamicTag ) $html .= $this->renderChildren( $title, $mode, $depth-1 );
|
2007-03-30 13:43:37 +00:00
|
|
|
|
else { //FIXME: depth would need to be propagated here. this would imact the cache key, too
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$uniq += 1;
|
|
|
|
|
$load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 );
|
|
|
|
|
|
|
|
|
|
$html .= wfOpenElement( 'script', array( 'type' => 'text/javascript', 'id' => $load ) );
|
|
|
|
|
$html .= 'categoryTreeLoadChildren("' . Xml::escapeJsString( $title->getDBKey() ) . '", "' . $mode . '", document.getElementById("' . $load . '").parentNode );';
|
|
|
|
|
$html .= wfCloseElement( 'script' );
|
|
|
|
|
}
|
2006-07-29 09:18:34 +00:00
|
|
|
|
}
|
2006-08-24 17:12:13 +00:00
|
|
|
|
|
|
|
|
|
$html .= wfCloseElement( 'div' );
|
|
|
|
|
$html .= "\n\t\t";
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
2007-04-30 21:18:56 +00:00
|
|
|
|
function renderChildren( &$title, $mode = NULL, $depth=0 ) {
|
|
|
|
|
global $wgCategoryTreeMaxChildren, $wgCategoryTreeDefaultMode;
|
2006-08-24 17:12:13 +00:00
|
|
|
|
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
|
|
|
|
|
#additional stuff to be used if "transaltion" by interwiki-links is desired
|
|
|
|
|
$transFields = '';
|
|
|
|
|
$transJoin = '';
|
|
|
|
|
$transWhere = '';
|
2007-04-30 21:18:56 +00:00
|
|
|
|
|
|
|
|
|
if ( $mode === NULL ) $wgCategoryTreeDefaultMode;
|
2006-08-24 17:12:13 +00:00
|
|
|
|
|
|
|
|
|
#namespace filter. Should be configurable
|
|
|
|
|
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;
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$page = $dbr->tableName( 'page' );
|
|
|
|
|
$categorylinks = $dbr->tableName( 'categorylinks' );
|
|
|
|
|
|
2007-09-01 11:26:00 +00:00
|
|
|
|
$sql = "SELECT cat.page_namespace, cat.page_title
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$transFields
|
|
|
|
|
FROM $page as cat
|
|
|
|
|
JOIN $categorylinks ON cl_from = cat.page_id
|
|
|
|
|
$transJoin
|
|
|
|
|
WHERE cl_to = " . $dbr->addQuotes( $title->getDBKey() ) . "
|
|
|
|
|
$nsmatch
|
2006-09-01 12:53:07 +00:00
|
|
|
|
"./*AND cat.page_is_redirect = 0*/"
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$transWhere
|
2007-09-01 11:26:00 +00:00
|
|
|
|
ORDER BY cl_sortkey
|
2006-08-24 17:12:13 +00:00
|
|
|
|
LIMIT " . (int)$wgCategoryTreeMaxChildren;
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$res = $dbr->query( $sql, __METHOD__ );
|
|
|
|
|
|
2007-09-01 11:26:00 +00:00
|
|
|
|
#collect categories separately from other pages
|
|
|
|
|
$categories= '';
|
|
|
|
|
$other= '';
|
2006-08-24 17:12:13 +00:00
|
|
|
|
|
|
|
|
|
while ( $row = $dbr->fetchRow( $res ) ) {
|
2007-09-01 11:26:00 +00:00
|
|
|
|
#TODO: translation support; ideally added to Title object
|
|
|
|
|
$t = Title::makeTitle( $row['page_namespace'], $row['page_title'] );
|
|
|
|
|
|
|
|
|
|
$s = $this->renderNode( $t, $mode, $depth>0, false, $depth-1 );
|
|
|
|
|
$s .= "\n\t\t";
|
|
|
|
|
|
|
|
|
|
if ($row['page_namespace'] == NS_CATEGORY) $categories .= $s;
|
|
|
|
|
else $other .= $s;
|
2006-08-24 17:12:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$dbr->freeResult( $res );
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
static function renderParents( &$title, $mode ) {
|
|
|
|
|
global $wgCategoryTreeMaxChildren;
|
|
|
|
|
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
|
|
|
|
|
#additional stuff to be used if "transaltion" by interwiki-links is desired
|
|
|
|
|
$transFields = '';
|
|
|
|
|
$transJoin = '';
|
|
|
|
|
$transWhere = '';
|
|
|
|
|
|
|
|
|
|
$categorylinks = $dbr->tableName( 'categorylinks' );
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT " . NS_CATEGORY . " as page_namespace, cl_to as page_title $transFields
|
|
|
|
|
FROM $categorylinks
|
|
|
|
|
$transJoin
|
|
|
|
|
WHERE cl_from = " . $title->getArticleID() . "
|
|
|
|
|
$transWhere
|
|
|
|
|
ORDER BY cl_to
|
|
|
|
|
LIMIT " . (int)$wgCategoryTreeMaxChildren;
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$res = $dbr->query( $sql, __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$special = Title::makeTitle( NS_SPECIAL, 'CategoryTree' );
|
|
|
|
|
|
|
|
|
|
$s= '';
|
|
|
|
|
|
|
|
|
|
while ( $row = $dbr->fetchRow( $res ) ) {
|
|
|
|
|
#TODO: translation support; ideally added to Title object
|
|
|
|
|
$t = Title::makeTitle( $row['page_namespace'], $row['page_title'] );
|
|
|
|
|
|
|
|
|
|
#$trans = $title->getLocalizedText();
|
|
|
|
|
$trans = ''; #place holder for when translated titles are available
|
|
|
|
|
|
|
|
|
|
$label = htmlspecialchars( $t->getText() );
|
|
|
|
|
if ( $trans && $trans!=$label ) $label.= ' ' . wfElement( 'i', array( 'class' => 'translation'), $trans );
|
|
|
|
|
|
|
|
|
|
$wikiLink = $special->getLocalURL( 'target=' . $t->getPartialURL() . '&mode=' . $mode );
|
|
|
|
|
|
|
|
|
|
if ( $s !== '' ) $s .= ' | ';
|
|
|
|
|
|
|
|
|
|
$s .= wfOpenElement( 'span', array( 'class' => 'CategoryTreeItem' ) );
|
|
|
|
|
$s .= wfOpenElement( 'a', array( 'class' => 'CategoryTreeLabel', 'href' => $wikiLink ) ) . $label . wfCloseElement( 'a' );
|
|
|
|
|
$s .= wfCloseElement( 'span' );
|
|
|
|
|
|
|
|
|
|
$s .= "\n\t\t";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$dbr->freeResult( $res );
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
2007-04-30 21:18:56 +00:00
|
|
|
|
function renderNode( &$title, $mode = NULL, $children = false, $loadchildren = false, $depth = 1 ) {
|
|
|
|
|
global $wgCategoryTreeOmitNamespace, $wgCategoryTreeDefaultMode;
|
2006-08-24 17:12:13 +00:00
|
|
|
|
static $uniq = 0;
|
|
|
|
|
|
2007-04-30 21:18:56 +00:00
|
|
|
|
if ( $mode === NULL ) $wgCategoryTreeDefaultMode;
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$load = false;
|
|
|
|
|
|
2007-03-13 11:39:12 +00:00
|
|
|
|
if ( $children && $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 );
|
|
|
|
|
$children = false;
|
|
|
|
|
}
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$key = $title->getDBKey();
|
|
|
|
|
|
|
|
|
|
#$trans = $title->getLocalizedText();
|
|
|
|
|
$trans = ''; #place holder for when translated titles are available
|
|
|
|
|
|
2006-11-22 21:48:54 +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 ( $wgCategoryTreeOmitNamespace || $mode == CT_MODE_CATEGORIES ) $label = htmlspecialchars( $title->getText() );
|
2006-08-24 17:12:13 +00:00
|
|
|
|
else $label = htmlspecialchars( $title->getPrefixedText() );
|
|
|
|
|
|
|
|
|
|
if ( $trans && $trans!=$label ) $label.= ' ' . wfElement( 'i', array( 'class' => 'translation'), $trans );
|
|
|
|
|
|
|
|
|
|
$wikiLink = $title->getLocalURL();
|
|
|
|
|
|
|
|
|
|
$labelClass = 'CategoryTreeLabel ' . ' CategoryTreeLabelNs' . $ns;
|
|
|
|
|
|
|
|
|
|
if ( $ns == NS_CATEGORY ) {
|
|
|
|
|
$labelClass .= ' CategoryTreeLabelCategory';
|
|
|
|
|
} else {
|
|
|
|
|
$labelClass .= ' CategoryTreeLabelPage';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ( $ns % 2 ) > 0 ) $labelClass .= ' CategoryTreeLabelTalk';
|
|
|
|
|
|
2006-09-03 11:26:57 +00:00
|
|
|
|
$linkattr= array( 'href' => '#' );
|
2006-08-24 17:12:13 +00:00
|
|
|
|
|
|
|
|
|
if ( $load ) $linkattr[ 'id' ] = $load;
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
|
if ( !$children ) {
|
|
|
|
|
$txt = '+';
|
2006-09-04 12:17:40 +00:00
|
|
|
|
$linkattr[ 'onclick' ] = "this.href='javascript:void(0)'; categoryTreeExpandNode('".Xml::escapeJsString($key)."','".$mode."',this);";
|
2006-08-24 17:12:13 +00:00
|
|
|
|
# Don't load this message for ajax requests, so that we don't have to initialise $wgLang
|
2006-09-04 11:39:45 +00:00
|
|
|
|
$linkattr[ 'title' ] = $this->mIsAjaxRequest ? '##LOAD##' : self::msg('expand');
|
2006-08-24 17:12:13 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$txt = '–'; #NOTE: that's not a minus but a unicode ndash!
|
2006-09-04 12:17:40 +00:00
|
|
|
|
$linkattr[ 'onclick' ] = "this.href='javascript:void(0)'; categoryTreeCollapseNode('".Xml::escapeJsString($key)."','".$mode."',this);";
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$linkattr[ 'title' ] = self::msg('collapse');
|
|
|
|
|
$linkattr[ 'class' ] = 'CategoryTreeLoaded';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$s = '';
|
2007-03-13 22:24:38 +00:00
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
|
#NOTE: things in CategoryTree.js rely on the exact order of tags!
|
|
|
|
|
# Specifically, the CategoryTreeChildren div must be the first
|
|
|
|
|
# sibling with nodeName = DIV of the grandparent of the expland link.
|
|
|
|
|
|
|
|
|
|
$s .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeSection' ) );
|
|
|
|
|
$s .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeItem' ) );
|
|
|
|
|
|
|
|
|
|
if ( $ns == NS_CATEGORY ) {
|
2007-03-30 13:28:59 +00:00
|
|
|
|
$s .= wfOpenElement( 'span', array( 'class' => 'CategoryTreeBullet' ) );
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$s .= '[' . wfElement( 'a', $linkattr, $txt ) . '] ';
|
2007-03-30 13:28:59 +00:00
|
|
|
|
$s .= wfCloseElement( 'span' );
|
2006-08-24 17:12:13 +00:00
|
|
|
|
} else {
|
|
|
|
|
$s .= ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$s .= wfOpenElement( 'a', array( 'class' => $labelClass, 'href' => $wikiLink ) ) . $label . wfCloseElement( 'a' );
|
|
|
|
|
$s .= wfCloseElement( 'div' );
|
|
|
|
|
$s .= "\n\t\t";
|
|
|
|
|
$s .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeChildren', 'style' => $children ? "display:block" : "display:none" ) );
|
2007-03-13 22:24:38 +00:00
|
|
|
|
//HACK here?
|
|
|
|
|
if ( $children ) $s .= $this->renderChildren( $title, $mode, $depth );
|
2006-08-24 17:12:13 +00:00
|
|
|
|
$s .= wfCloseElement( 'div' );
|
|
|
|
|
$s .= wfCloseElement( 'div' );
|
|
|
|
|
|
|
|
|
|
if ( $load ) {
|
|
|
|
|
$s .= "\n\t\t";
|
|
|
|
|
$s .= wfOpenElement( 'script', array( 'type' => 'text/javascript' ) );
|
|
|
|
|
$s .= 'categoryTreeExpandNode("'.Xml::escapeJsString($key).'", "'.$mode.'", document.getElementById("'.$load.'") );';
|
|
|
|
|
$s .= wfCloseElement( 'script' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$s .= "\n\t\t";
|
|
|
|
|
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a Title object from a user provided (and thus unsafe) string
|
|
|
|
|
*/
|
|
|
|
|
static function makeTitle( $title ) {
|
|
|
|
|
global $wgContLang, $wgCanonicalNamespaceNames;
|
|
|
|
|
|
|
|
|
|
$title = trim($title);
|
|
|
|
|
|
|
|
|
|
if ( $title === NULL || $title === '' || $title === false ) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* load the CategoryTree internationalization file
|
|
|
|
|
*/
|
|
|
|
|
static function loadMessages() {
|
|
|
|
|
global $wgLang;
|
|
|
|
|
|
|
|
|
|
$messages= array();
|
|
|
|
|
|
|
|
|
|
$f= dirname( __FILE__ ) . '/CategoryTree.i18n.php';
|
|
|
|
|
include( $f );
|
|
|
|
|
|
|
|
|
|
$f= dirname( __FILE__ ) . '/CategoryTree.i18n.' . $wgLang->getCode() . '.php';
|
|
|
|
|
if ( file_exists( $f ) ) include( $f );
|
|
|
|
|
|
|
|
|
|
return $messages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a CategoryTree message, "categorytree-" prefix added automatically
|
|
|
|
|
*/
|
|
|
|
|
static function msg( $msg /*, ...*/ ) {
|
|
|
|
|
static $initialized = false;
|
|
|
|
|
global $wgMessageCache;
|
|
|
|
|
if ( !$initialized ) {
|
|
|
|
|
$wgMessageCache->addMessages( self::loadMessages() );
|
2006-09-03 23:17:36 +00:00
|
|
|
|
$initialized = true;
|
2006-08-24 17:12:13 +00:00
|
|
|
|
}
|
|
|
|
|
if ( $msg === false ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
$args = func_get_args();
|
|
|
|
|
$msg = array_shift( $args );
|
|
|
|
|
if ( $msg == '' ) {
|
|
|
|
|
return wfMsgReal( $msg, $args );
|
|
|
|
|
} else {
|
|
|
|
|
return wfMsgReal( "categorytree-$msg", $args );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-06-29 01:36:09 +00:00
|
|
|
|
|