<?php
/**
- * Special handling for category description pages
- * Modelled after ImagePage.php
+ * Special handling for category description pages.
+ * Modelled after ImagePage.php.
*
+ * @file
*/
if ( !defined( 'MEDIAWIKI' ) )
die( 1 );
/**
+ * Special handling for category description pages, showing pages,
+ * subcategories and file that belong to the category
*/
class CategoryPage extends Article {
+ # Subclasses can change this to override the viewer class.
+ protected $mCategoryViewerClass = 'CategoryViewer';
+
function view() {
global $wgRequest, $wgUser;
$diff = $wgRequest->getVal( 'diff' );
$diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
- if ( isset( $diff ) && $diffOnly )
+ if ( isset( $diff ) && $diffOnly ) {
return parent::view();
+ }
- if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) )
+ if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) ) {
return;
+ }
if ( NS_CATEGORY == $this->mTitle->getNamespace() ) {
$this->openShowCategory();
}
function closeShowCategory() {
- global $wgOut, $wgRequest;
+ global $wgOut;
$from = $until = array();
foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
$until[$type] = isset( $_GET["{$type}until"] ) ? $_GET["{$type}until"] : null;
}
- $viewer = new CategoryViewer( $this->mTitle, $from, $until, $_GET );
+ $viewer = new $this->mCategoryViewerClass( $this->mTitle, $from, $until, $_GET );
$wgOut->addHTML( $viewer->getHTML() );
}
}
* Format the category data list.
*
* @return string HTML output
- * @private
*/
- function getHTML() {
+ public function getHTML() {
global $wgOut, $wgCategoryMagicGallery, $wgContLang;
wfProfileIn( __METHOD__ );
/**
* Add a subcategory to the internal lists, using a Category object
*/
- function addSubcategoryObject( $cat, $sortkey, $pageLength ) {
- $title = $cat->getTitle();
- $this->addSubcategory( $title, $sortkey, $pageLength );
- }
-
- /**
- * Add a subcategory to the internal lists, using a title object
- * @deprecated kept for compatibility, please use addSubcategoryObject instead
- */
- function addSubcategory( $title, $sortkey, $pageLength ) {
+ function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) {
// Subcategory; strip the 'Category' namespace from the link text.
$this->children[] = $this->getSkin()->link(
- $title,
+ $cat->getTitle(),
null,
array(),
array(),
array( 'known', 'noclasses' )
);
- $this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey );
+ $this->children_start_char[] =
+ $this->getSubcategorySortChar( $cat->getTitle(), $sortkey );
+ }
+
+ /**
+ * Add a subcategory to the internal lists, using a title object
+ * @deprecated kept for compatibility, please use addSubcategoryObject instead
+ */
+ function addSubcategory( Title $title, $sortkey, $pageLength ) {
+ $this->addSubcategoryObject( Category::newFromTitle( $title ), $sortkey, $pageLength );
}
/**
$res = $dbr->select(
array( 'page', 'categorylinks', 'category' ),
- array( 'page_title', 'page_namespace', 'page_len',
+ array( 'page_id', 'page_title', 'page_namespace', 'page_len',
'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title',
'cat_subcats', 'cat_pages', 'cat_files', 'cl_sortkey_prefix' ),
array( 'cl_to' => $this->title->getDBkey() ) + $extraConds,
*/
function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
if ( count ( $articles ) > $cutoff ) {
- return $this->columnList( $articles, $articles_start_char );
+ return self::columnList( $articles, $articles_start_char );
} elseif ( count( $articles ) > 0 ) {
// for short lists of articles in categories.
- return $this->shortList( $articles, $articles_start_char );
+ return self::shortList( $articles, $articles_start_char );
}
return '';
}
* @return String
* @private
*/
- function columnList( $articles, $articles_start_char ) {
+ static function columnList( $articles, $articles_start_char ) {
$columns = array_combine( $articles, $articles_start_char );
# Split into three columns
$columns = array_chunk( $columns, ceil( count( $columns ) / 3 ), true /* preserve keys */ );
* @return String
* @private
*/
- function shortList( $articles, $articles_start_char ) {
+ static function shortList( $articles, $articles_start_char ) {
$r = '<h3>' . htmlspecialchars( $articles_start_char[0] ) . "</h3>\n";
$r .= '<ul><li>' . $articles[0] . '</li>';
for ( $index = 1; $index < count( $articles ); $index++ )
$totalrescnt = count( $this->articles ) + count( $this->children ) +
( $this->showGallery ? $this->gallery->count() : 0 );
- if ( $dbcnt == $rescnt || ( ( $totalrescnt == $this->limit || $this->from
- || $this->until ) && $dbcnt > $rescnt ) )
+ # Check if there's a "from" or "until" for anything
+ $fromOrUntil = false;
+ foreach ( array( 'page', 'subcat', 'file' ) as $t ) {
+ if ( $this->from[$t] !== null || $this->until[$t] !== null ) {
+ $fromOrUntil = true;
+ break;
+ }
+ }
+
+ if ( $dbcnt == $rescnt || ( ( $totalrescnt == $this->limit || $fromOrUntil )
+ && $dbcnt > $rescnt ) )
{
# Case 1: seems sane.
$totalcnt = $dbcnt;
- } elseif ( $totalrescnt < $this->limit && !$this->from && !$this->until ) {
+ } elseif ( $totalrescnt < $this->limit && !$fromOrUntil ) {
# Case 2: not sane, but salvageable. Use the number of results.
# Since there are fewer than 200, we can also take this opportunity
# to refresh the incorrect category table entry -- which should be