Whitespace fixes

This commit is contained in:
Siebrand Mazeland 2008-02-04 09:22:12 +00:00
parent a412c359d4
commit bce152a958
8 changed files with 203 additions and 210 deletions

View file

@ -13,55 +13,55 @@ class CategoryTreeCategoryPage extends CategoryPage {
class CategoryTreeCategoryViewer extends CategoryViewer {
var $child_titles;
/**
* Add a subcategory to the internal lists
*/
function addSubcategory( $title, $sortkey, $pageLength ) {
global $wgContLang, $wgOut, $wgRequest, $wgCategoryTreeCategoryPageMode;
if ( $wgRequest->getCheck( 'notree' ) ) {
return parent::addSubcategory( $title, $sortkey, $pageLength );
}
if ( ! $GLOBALS['wgCategoryTreeUnifiedView'] ) {
$this->child_titles[] = $title;
return parent::addSubcategory( $title, $sortkey, $pageLength );
}
if ( ! isset($this->categorytree) ) {
CategoryTree::setHeaders( $wgOut );
$this->categorytree = new CategoryTree;
}
$this->children[] = $this->categorytree->renderNode( $title, $wgCategoryTreeCategoryPageMode );
$this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey );
}
function getSubcategorySection() {
global $wgOut, $wgRequest, $wgCookiePrefix, $wgCategoryTreeCategoryPageMode;
if ( $wgRequest->getCheck( 'notree' ) ) {
return parent::getSubcategorySection();
}
if ( $GLOBALS['wgCategoryTreeUnifiedView'] ) {
return parent::getSubcategorySection();
}
if( count( $this->children ) == 0 ) {
return '';
}
$r = '<h2>' . wfMsg( 'subcategories' ) . "</h2>\n" .
wfMsgExt( 'subcategorycount', array( 'parse' ), count( $this->children) );
# Use a cookie to save the user's last selection, so that AJAX doesn't
# keep coming back to haunt them.
#
# FIXME: This doesn't work very well with IMS handling in
# OutputPage::checkLastModified, because when the cookie changes, the
# FIXME: This doesn't work very well with IMS handling in
# OutputPage::checkLastModified, because when the cookie changes, the
# category pages are not, at present, invalidated.
$cookieName = $wgCookiePrefix.'ShowSubcatAs';
$cookieVal = @$_COOKIE[$cookieName];
@ -81,9 +81,9 @@ class CategoryTreeCategoryViewer extends CategoryViewer {
$exp = time() + $wgCookieExpiration;
setcookie( $cookieName, $showAs, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
}
if ( $showAs == 'tree' && count( $this->children ) > $this->limit ) {
# Tree doesn't page properly
# Tree doesn't page properly
$showAs = 'list';
$r .= self::msg( 'too-many-subcats' );
} else {
@ -94,7 +94,7 @@ class CategoryTreeCategoryViewer extends CategoryViewer {
$this->makeShowAsLink( 'list', $showAs ) .
'</p>';
}
if ( $showAs == 'list' ) {
$r .= $this->formatList( $this->children, $this->children_start_char );
} else {
@ -107,7 +107,7 @@ class CategoryTreeCategoryViewer extends CategoryViewer {
}
return $r;
}
function makeShowAsLink( $targetValue, $currentValue ) {
$msg = htmlspecialchars( CategoryTree::msg( "show-$targetValue" ) );
@ -122,7 +122,7 @@ class CategoryTreeCategoryViewer extends CategoryViewer {
$this->child_titles = array();
parent::clearCategoryState();
}
function finaliseCategoryState() {
if( $this->flip ) {
$this->child_titles = array_reverse( $this->child_titles );
@ -130,4 +130,3 @@ class CategoryTreeCategoryViewer extends CategoryViewer {
parent::finaliseCategoryState();
}
}

View file

@ -1,5 +1,5 @@
/*
* Stylesheet for the CategoryTree extension, an AJAX based gadget
* Stylesheet for the CategoryTree extension, an AJAX based gadget
* to display the category structure of a wiki
*
* @package MediaWiki

View file

@ -1,5 +1,5 @@
/*
* JavaScript functions for the CategoryTree extension, an AJAX based gadget
* JavaScript functions for the CategoryTree extension, an AJAX based gadget
* to display the category structure of a wiki
*
* @package MediaWiki
@ -10,7 +10,7 @@
*/
// Default messages if new code loaded with old cached page
var categoryTreeErrorMsg = "Problem loading data.";
var categoryTreeErrorMsg = "Problem loading data.";
var categoryTreeRetryMsg = "Please wait a moment and try again.";
function categoryTreeNextDiv(e) {
@ -19,32 +19,32 @@ var categoryTreeRetryMsg = "Please wait a moment and try again.";
//alert('nodeType: ' + n.nodeType + '; nodeName: ' + n.nodeName);
n= n.nextSibling;
}
return n;
}
function categoryTreeExpandNode(cat, mode, lnk) {
var div= categoryTreeNextDiv( lnk.parentNode.parentNode );
div.style.display= 'block';
lnk.innerHTML= '&ndash;';
lnk.title= categoryTreeCollapseMsg;
lnk.onclick= function() { categoryTreeCollapseNode(cat, mode, lnk) }
if (lnk.className != "CategoryTreeLoaded") {
categoryTreeLoadNode(cat, mode, lnk, div);
}
}
function categoryTreeCollapseNode(cat, mode, lnk) {
var div= categoryTreeNextDiv( lnk.parentNode.parentNode );
div.style.display= 'none';
lnk.innerHTML= '+';
lnk.title= categoryTreeExpandMsg;
lnk.onclick= function() { categoryTreeExpandNode(cat, mode, lnk) }
}
function categoryTreeLoadNode(cat, mode, lnk, div) {
div.style.display= 'block';
lnk.className= 'CategoryTreeLoaded';
@ -54,10 +54,10 @@ var categoryTreeRetryMsg = "Please wait a moment and try again.";
categoryTreeLoadChildren(cat, mode, div)
}
function categoryTreeLoadChildren(cat, mode, div) {
div.innerHTML= '<i class="CategoryTreeNotice">' + categoryTreeLoadingMsg + '</i>';
function f( request ) {
if (request.status != 200) {
div.innerHTML = '<i class="CategoryTreeNotice">' + categoryTreeErrorMsg + ' </i>';
@ -72,21 +72,20 @@ var categoryTreeRetryMsg = "Please wait a moment and try again.";
result= request.responseText;
result= result.replace(/^\s+|\s+$/, '');
if ( result == '' ) {
result= '<i class="CategoryTreeNotice">';
if ( mode == 0 ) result= categoryTreeNoSubcategoriesMsg;
else if ( mode == 10 ) result= categoryTreeNoPagesMsg;
else result= categoryTreeNothingFoundMsg;
result+= '</i>';
}
result = result.replace(/##LOAD##/g, categoryTreeExpandMsg);
div.innerHTML= result;
}
sajax_do_call( "efCategoryTreeAjaxWrapper", [cat, mode] , f );
}

View file

@ -1,7 +1,7 @@
<?php
/**
* Setup and Hooks for the CategoryTree extension, an AJAX based gadget
* Setup and Hooks for the CategoryTree extension, an AJAX based gadget
* to display the category structure of a wiki
*
* @addtogroup Extensions
@ -9,7 +9,7 @@
* @copyright © 2006-2007 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 );
@ -35,10 +35,10 @@ define('CT_MODE_ALL', 20);
* $wgCategoryTreeUnifiedView - use unified view on category pages, instead of "tree" or "traditional list". Default is true.
* $wgCategoryTreeOmitNamespace - never show namespace prefix. Default is false
* $wgCategoryTreeMaxDepth - maximum value for depth argument; An array that maps mode values to
* the maximum depth acceptable for the depth option.
* the maximum depth acceptable for the depth option.
* Per default, the "categories" mode has a max depth of 2,
* all other modes have a max depth of 1.
*/
*/
$wgCategoryTreeMaxChildren = 200;
$wgCategoryTreeAllowTag = true;
@ -57,16 +57,16 @@ $wgCategoryTreeVersion = '1';
* Register extension setup hook and credits
*/
$wgExtensionFunctions[] = 'efCategoryTree';
$wgExtensionCredits['specialpage'][] = array(
'name' => 'CategoryTree',
'author' => 'Daniel Kinzler',
$wgExtensionCredits['specialpage'][] = array(
'name' => 'CategoryTree',
'author' => 'Daniel Kinzler',
'url' => 'http://www.mediawiki.org/wiki/Extension:CategoryTree',
'description' => 'AJAX based gadget to display the category structure of a wiki',
'descriptionmsg' => 'categorytree-desc',
);
$wgExtensionCredits['parserhook'][] = array(
'name' => 'CategoryTree',
'author' => 'Daniel Kinzler',
$wgExtensionCredits['parserhook'][] = array(
'name' => 'CategoryTree',
'author' => 'Daniel Kinzler',
'url' => 'http://www.mediawiki.org/wiki/Extension:CategoryTree',
'description' => 'AJAX based gadget to display the category structure of a wiki',
);
@ -126,10 +126,10 @@ function efCategoryTreeGetMagic( &$magicWords, $langCode ) {
*/
function efCategoryTreeAjaxWrapper( $category, $mode ) {
global $wgCategoryTreeHTTPCache, $wgSquidMaxAge, $wgUseSquid;
$ct = new CategoryTree;
$response = $ct->ajax( $category, $mode ); //FIXME: would need to pass on depth parameter here.
if ( $wgCategoryTreeHTTPCache && $wgSquidMaxAge && $wgUseSquid ) {
$response->setCacheDuration( $wgSquidMaxAge );
$response->setVary( 'Accept-Encoding, Cookie' ); #cache for anons only
@ -158,7 +158,7 @@ function efCategoryTreeCapDepth( $mode, $depth ) {
wfDebug( 'efCategoryTreeCapDepth: $wgCategoryTreeMaxDepth is invalid.' );
$max = 1;
}
return min($depth, $max);
}
@ -221,16 +221,16 @@ function efCategoryTreeParserHook( $cat, $argv, &$parser ) {
global $wgCategoryTreeDefaultMode;
$parser->mOutput->mCategoryTreeTag = true; # flag for use by efCategoryTreeParserOutput
static $initialized = false;
$divAttribs = Sanitizer::validateTagAttributes( $argv, 'div' );
$style = isset( $divAttribs['style'] ) ? $divAttribs['style'] : null;
$mode = isset( $argv[ 'mode' ] ) ? $argv[ 'mode' ] : null;
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;
@ -238,13 +238,13 @@ function efCategoryTreeParserHook( $cat, $argv, &$parser ) {
else {
$mode = $wgCategoryTreeDefaultMode;
}
$hideroot = isset( $argv[ 'hideroot' ] ) ? efCategoryTreeAsBool( $argv[ 'hideroot' ] ) : null;
$onlyroot = isset( $argv[ 'onlyroot' ] ) ? efCategoryTreeAsBool( $argv[ 'onlyroot' ] ) : null;
$depthArg = isset( $argv[ 'depth' ] ) ? $argv[ 'depth' ] : null;
$depth = efCategoryTreeCapDepth($mode, $depthArg);
if ( $onlyroot ) $depth = 0;
$ct = new CategoryTree;
@ -257,15 +257,15 @@ function efCategoryTreeParserHook( $cat, $argv, &$parser ) {
/*
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,
'text' => htmlspecialchars( CategoryTree::msg( 'tab' ) ),
'href' => $special->getLocalUrl() . '/' . $wgTitle->getPartialURL() );
'href' => $special->getLocalUrl() . '/' . $wgTitle->getPartialURL() );
return true;
}*/
@ -297,5 +297,3 @@ function efCategoryTreeArticleFromTitle( &$title, &$article ) {
}
return true;
}

View file

@ -1,7 +1,7 @@
<?php
/**
* Core functions for the CategoryTree extension, an AJAX based gadget
* Core functions for the CategoryTree extension, an AJAX based gadget
* to display the category structure of a wiki
*
* @addtogroup Extensions
@ -9,7 +9,7 @@
* @copyright © 2006-2007 Daniel Kinzler
* @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 );
@ -17,103 +17,103 @@ if( !defined( 'MEDIAWIKI' ) ) {
class CategoryTree {
var $mIsAjaxRequest = false;
/**
* Set the script tags in an OutputPage object
* @param OutputPage $outputPage
* @param OutputPage $outputPage
*/
static function setHeaders( &$outputPage ) {
global $wgJsMimeType, $wgScriptPath, $wgContLang, $wgCategoryTreeExtPath, $wgCategoryTreeVersion;
efInjectCategoryTreeMessages();
# Register css file for CategoryTree
$outputPage->addLink(
array(
'rel' => 'stylesheet',
'type' => 'text/css',
$outputPage->addLink(
array(
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => "$wgScriptPath$wgCategoryTreeExtPath/CategoryTree.css?$wgCategoryTreeVersion",
)
)
);
# Register css RTL file for CategoryTree
if( $wgContLang->isRTL() ) {
$outputPage->addLink(
array(
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => "$wgScriptPath$wgCategoryTreeExtPath/CategoryTree.rtl.css?$wgCategoryTreeVersion"
)
$outputPage->addLink(
array(
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => "$wgScriptPath$wgCategoryTreeExtPath/CategoryTree.rtl.css?$wgCategoryTreeVersion"
)
);
}
# Register main js file for CategoryTree
$outputPage->addScript(
$outputPage->addScript(
"<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.js?{$wgCategoryTreeVersion}\">" .
"</script>\n"
"</script>\n"
);
# Add messages
$outputPage->addScript(
" <script type=\"{$wgJsMimeType}\">
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'))."\";
var categoryTreeErrorMsg = \"".Xml::escapeJsString(self::msg('error'))."\";
var categoryTreeRetryMsg = \"".Xml::escapeJsString(self::msg('retry'))."\";
</script>\n"
# Add messages
$outputPage->addScript(
" <script type=\"{$wgJsMimeType}\">
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'))."\";
var categoryTreeErrorMsg = \"".Xml::escapeJsString(self::msg('error'))."\";
var categoryTreeRetryMsg = \"".Xml::escapeJsString(self::msg('retry'))."\";
</script>\n"
);
}
}
/**
* Ajax call. This is called by efCategoryTreeAjaxWrapper, which is used to
* Ajax call. This is called by efCategoryTreeAjaxWrapper, which is used to
* load CategoryTreeFunctions.php on demand.
*/
function ajax( $category, $mode ) {
global $wgDBname;
$title = self::makeTitle( $category );
if ( ! $title ) return false; #TODO: error message?
$this->mIsAjaxRequest = true;
# Retrieve page_touched for the category
$dbkey = $title->getDBkey();
$dbr =& wfGetDB( DB_SLAVE );
$touched = $dbr->selectField( 'page', 'page_touched',
array(
$touched = $dbr->selectField( 'page', 'page_touched',
array(
'page_namespace' => NS_CATEGORY,
'page_title' => $dbkey,
), __METHOD__ );
$mckey = "$wgDBname:categorytree($mode):$dbkey"; //FIXME: would need to add depth parameter.
$response = new AjaxResponse();
if ( $response->checkLastModified( $touched ) ) {
return $response;
}
if ( $response->loadFromMemcached( $mckey, $touched ) ) {
return $response;
}
$html = $this->renderChildren( $title, $mode ); //FIXME: would need to pass depth parameter.
if ( $html == '' ) $html = ' '; #HACK: Safari doesn't like empty responses.
if ( $html == '' ) $html = ' '; #HACK: Safari doesn't like empty responses.
#see Bug 7219 and http://bugzilla.opendarwin.org/show_bug.cgi?id=10716
$response->addText( $html );
$response->storeInMemcached( $mckey, 86400 );
return $response;
}
/**
* Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to
* Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to
* load CategoryTreeFunctions.php on demand.
*/
function getTag( &$parser, $category, $mode, $hideroot = false, $style = '', $depth=1 ) {
@ -129,12 +129,12 @@ class CategoryTree {
$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 ) );
@ -146,16 +146,16 @@ class CategoryTree {
else { //FIXME: depth would need to be propagated here. this would imact the cache key, too
$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' );
}
}
$html .= wfCloseElement( 'div' );
$html .= "\n\t\t";
return $html;
}
@ -165,12 +165,12 @@ class CategoryTree {
*/
function renderChildren( &$title, $mode = NULL, $depth=0 ) {
global $wgCategoryTreeMaxChildren, $wgCategoryTreeDefaultMode;
if( $title->getNamespace() != NS_CATEGORY ) {
// Non-categories can't have children. :)
return '';
}
$dbr =& wfGetDB( DB_SLAVE );
#additional stuff to be used if "transaltion" by interwiki-links is desired
@ -179,21 +179,21 @@ class CategoryTree {
$transWhere = '';
if ( $mode === NULL ) $wgCategoryTreeDefaultMode;
#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;
$page = $dbr->tableName( 'page' );
$categorylinks = $dbr->tableName( 'categorylinks' );
$sql = "SELECT cat.page_namespace, cat.page_title
$transFields
FROM $page as cat
JOIN $categorylinks ON cl_from = cat.page_id
$transJoin
WHERE cl_to = " . $dbr->addQuotes( $title->getDBkey() ) . "
WHERE cl_to = " . $dbr->addQuotes( $title->getDBkey() ) . "
$nsmatch
"./*AND cat.page_is_redirect = 0*/"
$transWhere
@ -201,11 +201,11 @@ class CategoryTree {
LIMIT " . (int)$wgCategoryTreeMaxChildren;
$res = $dbr->query( $sql, __METHOD__ );
#collect categories separately from other pages
$categories= '';
$other= '';
while ( $row = $dbr->fetchRow( $res ) ) {
#TODO: translation support; ideally added to Title object
$t = Title::makeTitle( $row['page_namespace'], $row['page_title'] );
@ -216,9 +216,9 @@ class CategoryTree {
if ($row['page_namespace'] == NS_CATEGORY) $categories .= $s;
else $other .= $s;
}
$dbr->freeResult( $res );
return $categories . $other;
}
@ -228,53 +228,53 @@ class CategoryTree {
*/
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() . "
WHERE cl_from = " . $title->getArticleID() . "
$transWhere
ORDER BY cl_to
LIMIT " . (int)$wgCategoryTreeMaxChildren;
$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;
}
@ -285,10 +285,10 @@ class CategoryTree {
function renderNode( &$title, $mode = NULL, $children = false, $loadchildren = false, $depth = 1 ) {
global $wgCategoryTreeOmitNamespace, $wgCategoryTreeDefaultMode;
static $uniq = 0;
if ( $mode === NULL ) $wgCategoryTreeDefaultMode;
$load = false;
if ( $children && $loadchildren ) {
$uniq += 1;
@ -298,55 +298,55 @@ class CategoryTree {
$ns = $title->getNamespace();
$key = $title->getDBkey();
#$trans = $title->getLocalizedText();
$trans = ''; #place holder for when translated titles are available
#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() );
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';
$linkattr= array( 'href' => '#' );
if ( $load ) $linkattr[ 'id' ] = $load;
if ( !$children ) {
$txt = '+';
$linkattr[ 'onclick' ] = "this.href='javascript:void(0)'; categoryTreeExpandNode('".Xml::escapeJsString($key)."','".$mode."',this);";
# Don't load this message for ajax requests, so that we don't have to initialise $wgLang
$linkattr[ 'title' ] = $this->mIsAjaxRequest ? '##LOAD##' : self::msg('expand');
$linkattr[ 'title' ] = $this->mIsAjaxRequest ? '##LOAD##' : self::msg('expand');
}
else {
$txt = ''; #NOTE: that's not a minus but a unicode ndash!
$linkattr[ 'onclick' ] = "this.href='javascript:void(0)'; categoryTreeCollapseNode('".Xml::escapeJsString($key)."','".$mode."',this);";
$linkattr[ 'title' ] = self::msg('collapse');
$linkattr[ 'title' ] = self::msg('collapse');
$linkattr[ 'class' ] = 'CategoryTreeLoaded';
}
$s = '';
#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 ) {
$s .= wfOpenElement( 'span', array( 'class' => 'CategoryTreeBullet' ) );
$s .= '[' . wfElement( 'a', $linkattr, $txt ) . '] ';
@ -354,16 +354,16 @@ class CategoryTree {
} 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" ) );
//HACK here?
if ( $children ) $s .= $this->renderChildren( $title, $mode, $depth );
if ( $children ) $s .= $this->renderChildren( $title, $mode, $depth );
$s .= wfCloseElement( 'div' );
$s .= wfCloseElement( 'div' );
if ( $load ) {
$s .= "\n\t\t";
$s .= wfOpenElement( 'script', array( 'type' => 'text/javascript' ) );
@ -372,7 +372,7 @@ class CategoryTree {
}
$s .= "\n\t\t";
return $s;
}
@ -381,9 +381,9 @@ class CategoryTree {
*/
static function makeTitle( $title ) {
global $wgContLang, $wgCanonicalNamespaceNames;
$title = trim($title);
if ( $title === NULL || $title === '' || $title === false ) {
return NULL;
}
@ -403,15 +403,15 @@ class CategoryTree {
*/
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;
}
@ -437,4 +437,3 @@ class CategoryTree {
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* Special page for the CategoryTree extension, an AJAX based gadget
* Special page for the CategoryTree extension, an AJAX based gadget
* to display the category structure of a wiki
*
* @addtogroup Extensions
@ -15,10 +15,10 @@ if( !defined( 'MEDIAWIKI' ) ) {
}
class CategoryTreePage extends SpecialPage {
var $target = '';
var $mode = CT_MODE_CATEGORIES;
/**
* Constructor
*/
@ -29,56 +29,56 @@ class CategoryTreePage extends SpecialPage {
#inject messages
efInjectCategoryTreeMessages();
}
/**
* Main execution function
* @param $par Parameters passed to the page
*/
function execute( $par ) {
global $wgRequest, $wgOut, $wgMakeBotPrivileged, $wgUser;
$this->setHeaders();
if ( $par ) $this->target = $par;
else $this->target = $wgRequest->getVal( 'target', wfMsg( 'rootcategory') );
$this->target = trim( $this->target );
#HACK for undefined root category
if ( $this->target == '<rootcategory>' || $this->target == '&lt;rootcategory&gt;' ) $this->target = NULL;
if ( $this->target == '<rootcategory>' || $this->target == '&lt;rootcategory&gt;' ) $this->target = NULL;
$this->mode = $wgRequest->getVal( 'mode', CT_MODE_CATEGORIES );
if ( $this->mode == 'all' ) $this->mode = CT_MODE_ALL;
else if ( $this->mode == 'pages' ) $this->mode = CT_MODE_PAGES;
else if ( $this->mode == 'categories' ) $this->mode = CT_MODE_CATEGORIES;
$this->mode = (int)$this->mode;
$wgOut->addWikiText( wfMsgNoTrans( 'categorytree-header' ) );
$wgOut->addHtml( $this->makeInputForm() );
if( $this->target !== '' && $this->target !== NULL ) {
CategoryTree::setHeaders( $wgOut );
$title = CategoryTree::makeTitle( $this->target );
if ( $title && $title->getArticleID() ) {
$html = '';
$html .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeParents' ) );
$html .= wfElement( 'span',
array( 'class' => 'CategoryTreeParents' ),
$html .= wfElement( 'span',
array( 'class' => 'CategoryTreeParents' ),
wfMsg( 'categorytree-parents' ) ) . ': ';
$ct = new CategoryTree;
$parents = $ct->renderParents( $title, $this->mode );
if ( $parents == '' ) $html .= wfMsg( 'categorytree-nothing-found' );
else $html .= $parents;
$html .= wfCloseElement( 'div' );
$html .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeResult' ) );
$html .= $ct->renderNode( $title, $this->mode, true, false );
$html .= wfCloseElement( 'div' );
@ -90,9 +90,9 @@ class CategoryTreePage extends SpecialPage {
$wgOut->addHtml( wfCloseElement( 'div' ) );
}
}
}
/**
* Input form for entering a category
*/
@ -114,5 +114,3 @@ class CategoryTreePage extends SpecialPage {
return $form;
}
}

28
README
View file

@ -11,7 +11,7 @@ structure as a tree. It uses AJAX to load parts of the tree on demand.
<http://meta.wikimedia.org/wiki/CategoryTree_extension>
The CategoryTree extension was originally written by Daniel Kinzler in
2006 and is released under the GNU General Public Licence (GPL). The
2006 and is released under the GNU General Public Licence (GPL). The
internationalization files contain contributions by several people;
they are mentioned in each file individually. Also thanks to Tim Starling
for his contributions.
@ -20,13 +20,13 @@ for his contributions.
INSTALLING
--------------------------------------------------------------------------
Copy the CategoryTree directory into the extensions folder of your
Copy the CategoryTree directory into the extensions folder of your
MediaWiki installation. Then add the following lines to your
LocalSettings.php file (near the end):
$wgUseAjax = true;
require_once( "{$IP}/extensions/CategoryTree/CategoryTree.php" );
Note that $wgUseAjax = true; will enable the Ajax framework in MediaWiki,
which is required by the CategoryTree extension. Ajax is a term for using
JavaScript to load parts of a page on demand. It is supported by all
@ -38,7 +38,7 @@ USAGE
--------------------------------------------------------------------------
CategoryTree can be used in three ways: directly on the category pages,
as a "custom tag" to show a category structure inline on a wiki page,
as a "custom tag" to show a category structure inline on a wiki page,
and as a special page.
The CategoryTree extension replaces the subcategory section of category
@ -54,14 +54,14 @@ the following attributes, using a HTML-like syntax:
* hideroot - set this to "on" to hide the "root" node of the tree, i.e.
the mention of category Foo from the example.
* onlyroot - set this to "on" show only the "root" node of the tree initially
* mode - can be "categories", "pages" or "all". See the Modes section below.
The default for this attribute is controlled by
The default for this attribute is controlled by
$wgCategoryTreeDefaultMode, and is initially set to CT_MODE_CATEGORIES,
the equivalent of setting the mode attribute to "categories".
* style - can be used to specify any CSS styles you would like for the
tree.
@ -73,7 +73,7 @@ The special page is called Special:CategoryTree; there you can enter the
name of a category and then browse it's content. The CategoryTree
extension also adds a tab for this special page to every category page.
MODES
--------------------------------------------------------------------------
@ -92,13 +92,13 @@ There are some options you can specify in your LocalSettings.php file:
$wgCategoryTreeMaxChildren - maximum number of children shown in a tree
node. Default is 200
$wgCategoryTreeAllowTag - enable <categorytree> tag. Default is true.
$wgCategoryTreeDynamicTag - loads the first level of the tree in a
$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
$wgCategoryTreeDisableCache - disabled the parser cache for pages with a
<categorytree> tag. Default is true.
@ -119,12 +119,12 @@ $wgCategoryTreeExtPath - the (URL-) path where the extension is installed,
relative to $wgScriptPath, with leading "/". Default is
"/extensions/CategoryTree".
$wgCategoryTreeDefaultMode - the default mode to use when no mode attribute
$wgCategoryTreeDefaultMode - the default mode to use when no mode attribute
is specified in a <categorytree> tag. May be
CT_MODE_CATEGORIES (the default), CT_MODE_PAGES, or
CT_MODE_ALL.
$wgCategoryTreeCategoryPageMode - the mode to use when rendering trees on
$wgCategoryTreeCategoryPageMode - the mode to use when rendering trees on
category pages. May be CT_MODE_CATEGORIES (the default),
CT_MODE_PAGES, or CT_MODE_ALL.

View file

@ -1,2 +1,2 @@
$wgUseAjax = true;
require_once( "{{path}}/CategoryTree.php" );
require_once( "{{path}}/CategoryTree.php" );