2006-08-24 18:11:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CategoryTreeCategoryPage extends CategoryPage {
|
|
|
|
function closeShowCategory() {
|
|
|
|
global $wgOut, $wgRequest;
|
|
|
|
$from = $wgRequest->getVal( 'from' );
|
|
|
|
$until = $wgRequest->getVal( 'until' );
|
|
|
|
|
|
|
|
$viewer = new CategoryTreeCategoryViewer( $this->mTitle, $from, $until );
|
|
|
|
$wgOut->addHTML( $viewer->getHTML() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CategoryTreeCategoryViewer extends CategoryViewer {
|
|
|
|
var $child_titles;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-09-02 12:14:12 +00:00
|
|
|
/**
|
|
|
|
* Add a subcategory to the internal lists
|
|
|
|
*/
|
|
|
|
function addSubcategory( $title, $sortkey, $pageLength ) {
|
2007-04-30 21:18:56 +00:00
|
|
|
global $wgContLang, $wgOut, $wgRequest, $wgCategoryTreeCategoryPageMode;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-09-02 12:55:29 +00:00
|
|
|
if ( $wgRequest->getCheck( 'notree' ) ) {
|
|
|
|
return parent::addSubcategory( $title, $sortkey, $pageLength );
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-09-03 09:15:52 +00:00
|
|
|
if ( ! $GLOBALS['wgCategoryTreeUnifiedView'] ) {
|
2006-09-02 12:14:12 +00:00
|
|
|
$this->child_titles[] = $title;
|
|
|
|
return parent::addSubcategory( $title, $sortkey, $pageLength );
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-09-02 12:14:12 +00:00
|
|
|
if ( ! isset($this->categorytree) ) {
|
|
|
|
CategoryTree::setHeaders( $wgOut );
|
|
|
|
$this->categorytree = new CategoryTree;
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2007-04-30 21:18:56 +00:00
|
|
|
$this->children[] = $this->categorytree->renderNode( $title, $wgCategoryTreeCategoryPageMode );
|
2006-09-02 12:14:12 +00:00
|
|
|
|
|
|
|
$this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey );
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 18:11:35 +00:00
|
|
|
function getSubcategorySection() {
|
2007-04-30 21:18:56 +00:00
|
|
|
global $wgOut, $wgRequest, $wgCookiePrefix, $wgCategoryTreeCategoryPageMode;
|
2006-08-24 18:11:35 +00:00
|
|
|
|
2006-09-02 12:55:29 +00:00
|
|
|
if ( $wgRequest->getCheck( 'notree' ) ) {
|
|
|
|
return parent::getSubcategorySection();
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-09-03 09:15:52 +00:00
|
|
|
if ( $GLOBALS['wgCategoryTreeUnifiedView'] ) {
|
2006-09-02 12:14:12 +00:00
|
|
|
return parent::getSubcategorySection();
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 18:11:35 +00:00
|
|
|
if( count( $this->children ) == 0 ) {
|
|
|
|
return '';
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 18:11:35 +00:00
|
|
|
$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.
|
|
|
|
#
|
2008-02-04 09:22:12 +00:00
|
|
|
# FIXME: This doesn't work very well with IMS handling in
|
|
|
|
# OutputPage::checkLastModified, because when the cookie changes, the
|
2006-08-24 18:11:35 +00:00
|
|
|
# category pages are not, at present, invalidated.
|
|
|
|
$cookieName = $wgCookiePrefix.'ShowSubcatAs';
|
|
|
|
$cookieVal = @$_COOKIE[$cookieName];
|
2006-09-01 17:33:14 +00:00
|
|
|
$reqShowAs = $wgRequest->getVal( 'showas' );
|
|
|
|
if ( $reqShowAs == 'list' ) {
|
2006-08-24 18:11:35 +00:00
|
|
|
$showAs = 'list';
|
2006-09-01 17:33:14 +00:00
|
|
|
} elseif ( $reqShowAs == 'tree' ) {
|
2006-08-24 18:11:35 +00:00
|
|
|
$showAs = 'tree';
|
|
|
|
} elseif ( $cookieVal == 'list' || $cookieVal == 'tree' ) {
|
|
|
|
$showAs = $cookieVal;
|
|
|
|
} else {
|
|
|
|
$showAs = 'tree';
|
|
|
|
}
|
|
|
|
|
2006-09-01 17:33:14 +00:00
|
|
|
if ( !is_null( $reqShowAs ) ) {
|
2006-08-24 18:11:35 +00:00
|
|
|
global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgCookieSecure;
|
|
|
|
$exp = time() + $wgCookieExpiration;
|
2006-09-01 17:33:14 +00:00
|
|
|
setcookie( $cookieName, $showAs, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
|
2006-08-24 18:11:35 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 18:11:35 +00:00
|
|
|
if ( $showAs == 'tree' && count( $this->children ) > $this->limit ) {
|
2008-02-04 09:22:12 +00:00
|
|
|
# Tree doesn't page properly
|
2006-08-24 18:11:35 +00:00
|
|
|
$showAs = 'list';
|
|
|
|
$r .= self::msg( 'too-many-subcats' );
|
|
|
|
} else {
|
|
|
|
$sk = $this->getSkin();
|
|
|
|
$r .= '<p>' .
|
|
|
|
$this->makeShowAsLink( 'tree', $showAs ) .
|
|
|
|
' | ' .
|
|
|
|
$this->makeShowAsLink( 'list', $showAs ) .
|
|
|
|
'</p>';
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 18:11:35 +00:00
|
|
|
if ( $showAs == 'list' ) {
|
|
|
|
$r .= $this->formatList( $this->children, $this->children_start_char );
|
|
|
|
} else {
|
|
|
|
CategoryTree::setHeaders( $wgOut );
|
|
|
|
$ct = new CategoryTree;
|
|
|
|
|
|
|
|
foreach ( $this->child_titles as $title ) {
|
2007-04-30 21:18:56 +00:00
|
|
|
$r .= $ct->renderNode( $title, $wgCategoryTreeCategoryPageMode );
|
2006-08-24 18:11:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 18:11:35 +00:00
|
|
|
function makeShowAsLink( $targetValue, $currentValue ) {
|
|
|
|
$msg = htmlspecialchars( CategoryTree::msg( "show-$targetValue" ) );
|
|
|
|
|
|
|
|
if ( $targetValue == $currentValue ) {
|
|
|
|
return "<strong>$msg</strong>";
|
|
|
|
} else {
|
|
|
|
return $this->getSkin()->makeKnownLinkObj( $this->title, $msg, "showas=$targetValue" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearCategoryState() {
|
|
|
|
$this->child_titles = array();
|
|
|
|
parent::clearCategoryState();
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 18:11:35 +00:00
|
|
|
function finaliseCategoryState() {
|
|
|
|
if( $this->flip ) {
|
|
|
|
$this->child_titles = array_reverse( $this->child_titles );
|
|
|
|
}
|
|
|
|
parent::finaliseCategoryState();
|
|
|
|
}
|
|
|
|
}
|