<?php
/**
- * Special handling for category description pages.
+ * Class for viewing MediaWiki category description pages.
* Modelled after ImagePage.php.
*
* @file
# Subclasses can change this to override the viewer class.
protected $mCategoryViewerClass = 'CategoryViewer';
+ protected function newPage( Title $title ) {
+ // Overload mPage with a category-specific page
+ return new WikiCategoryPage( $title );
+ }
+
+ /**
+ * Constructor from a page id
+ * @param $id Int article ID to load
+ */
+ public static function newFromID( $id ) {
+ $t = Title::newFromID( $id );
+ # @todo FIXME: Doesn't inherit right
+ return $t == null ? null : new self( $t );
+ # return $t == null ? null : new static( $t ); // PHP 5.3
+ }
+
function view() {
global $wgRequest, $wgUser;
}
}
- /**
- * Don't return a 404 for categories in use.
- * In use defined as: either the actual page exists
- * or the category currently has members.
- */
- function hasViewableContent() {
- if ( parent::hasViewableContent() ) {
- return true;
- } else {
- $cat = Category::newFromTitle( $this->mTitle );
- // If any of these are not 0, then has members
- if ( $cat->getPageCount()
- || $cat->getSubcatCount()
- || $cat->getFileCount()
- ) {
- return true;
- }
- }
- return false;
- }
-
function openShowCategory() {
# For overloading
}
if ( $r == '' ) {
// If there is no category content to display, only
// show the top part of the navigation links.
- // FIXME: cannot be completely suppressed because it
+ // @todo FIXME: Cannot be completely suppressed because it
// is unknown if 'until' or 'from' makes this
// give 0 results.
$r = $r . $this->getCategoryTop();
$r = wfMsgExt( 'category-empty', array( 'parse' ) );
}
+ global $wgBetterDirectionality, $wgTitle;
+ if( $wgBetterDirectionality ) {
+ $pageLang = $wgTitle->getPageLanguage();
+ $langAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
+ # close the previous div, show the headings in user language,
+ # then open a new div with the page content language again
+ $r = '</div>' . $r . Html::openElement( 'div', $langAttribs );
+ }
+
wfProfileOut( __METHOD__ );
return $wgContLang->convert( $r );
}
/**
* Add a subcategory to the internal lists, using a title object
- * @deprecated kept for compatibility, please use addSubcategoryObject instead
+ * @deprecated since 1.17 kept for compatibility, please use addSubcategoryObject instead
*/
function addSubcategory( Title $title, $sortkey, $pageLength ) {
$this->addSubcategoryObject( Category::newFromTitle( $title ), $sortkey, $pageLength );
# Don't show articles section if there are none.
$r = '';
- # FIXME, here and in the other two sections: we don't need to bother
+ # @todo FIXME: Here and in the other two sections: we don't need to bother
# with this rigamarole if the entire category contents fit on one page
# and have already been retrieved. We can just use $rescnt in that
# case and save a query and some logic.
* @private
*/
function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
+ $list = '';
if ( count ( $articles ) > $cutoff ) {
- return self::columnList( $articles, $articles_start_char );
+ $list = self::columnList( $articles, $articles_start_char );
} elseif ( count( $articles ) > 0 ) {
// for short lists of articles in categories.
- return self::shortList( $articles, $articles_start_char );
+ $list = self::shortList( $articles, $articles_start_char );
}
- return '';
+ global $wgBetterDirectionality, $wgTitle;
+ if( $wgBetterDirectionality ) {
+ $pageLang = $wgTitle->getPageLanguage();
+ $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
+ 'class' => 'mw-content-'.$pageLang->getDir() );
+ $list = Html::rawElement( 'div', $attribs, $list );
+ }
+
+ return $list;
}
/**
$prevQuery["{$type}until"] = $first;
unset( $prevQuery["{$type}from"] );
$prevLink = $sk->linkKnown(
- $this->title,
+ $this->addFragmentToTitle( $this->title, $type ),
$prevLink,
array(),
$prevQuery
$lastQuery["{$type}from"] = $last;
unset( $lastQuery["{$type}until"] );
$nextLink = $sk->linkKnown(
- $this->title,
+ $this->addFragmentToTitle( $this->title, $type ),
$nextLink,
array(),
$lastQuery
return "($prevLink) ($nextLink)";
}
+ /**
+ * Takes a title, and adds the fragment identifier that
+ * corresponds to the correct segment of the category.
+ *
+ * @param Title $title: The title (usually $this->title)
+ * @param String $section: Which section
+ */
+ private function addFragmentToTitle( $title, $section ) {
+ switch ( $section ) {
+ case 'page':
+ $fragment = 'mw-pages';
+ break;
+ case 'subcat':
+ $fragment = 'mw-subcategories';
+ break;
+ case 'file':
+ $fragment = 'mw-category-media';
+ break;
+ default:
+ throw new MWException( __METHOD__ .
+ " Invalid section $section." );
+ }
+
+ return Title::makeTitle( $title->getNamespace(),
+ $title->getDBkey(), $fragment );
+ }
/**
* What to do if the category table conflicts with the number of results
* returned? This function says what. Each type is considered independently