summaryrefslogtreecommitdiff
path: root/includes/CategoryPage.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
committerPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
commitca32f08966f1b51fcb19460f0996bb0c4048e6fe (patch)
treeec04cc15b867bc21eedca904cea9af0254531a11 /includes/CategoryPage.php
parenta22fbfc60f36f5f7ee10d5ae6fe347340c2ee67c (diff)
Update to MediaWiki 1.18.0
* also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing
Diffstat (limited to 'includes/CategoryPage.php')
-rw-r--r--includes/CategoryPage.php197
1 files changed, 135 insertions, 62 deletions
diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php
index f990b79b..6a0f6132 100644
--- a/includes/CategoryPage.php
+++ b/includes/CategoryPage.php
@@ -1,6 +1,6 @@
<?php
/**
- * Special handling for category description pages.
+ * Class for viewing MediaWiki category description pages.
* Modelled after ImagePage.php.
*
* @file
@@ -17,6 +17,22 @@ class CategoryPage extends Article {
# 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;
@@ -42,27 +58,6 @@ class CategoryPage extends Article {
}
}
- /**
- * 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
}
@@ -70,27 +65,77 @@ class CategoryPage extends Article {
function closeShowCategory() {
global $wgOut, $wgRequest;
+ // Use these as defaults for back compat --catrope
+ $oldFrom = $wgRequest->getVal( 'from' );
+ $oldUntil = $wgRequest->getVal( 'until' );
+
+ $reqArray = $wgRequest->getValues();
+
$from = $until = array();
foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
- $from[$type] = $wgRequest->getVal( "{$type}from" );
- $until[$type] = $wgRequest->getVal( "{$type}until" );
+ $from[$type] = $wgRequest->getVal( "{$type}from", $oldFrom );
+ $until[$type] = $wgRequest->getVal( "{$type}until", $oldUntil );
+
+ // Do not want old-style from/until propagating in nav links.
+ if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
+ $reqArray["{$type}from"] = $reqArray["from"];
+ }
+ if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
+ $reqArray["{$type}to"] = $reqArray["to"];
+ }
}
- $viewer = new $this->mCategoryViewerClass( $this->mTitle, $from, $until, $wgRequest->getValues() );
+ unset( $reqArray["from"] );
+ unset( $reqArray["to"] );
+
+ $viewer = new $this->mCategoryViewerClass( $this->mTitle, $from, $until, $reqArray );
$wgOut->addHTML( $viewer->getHTML() );
}
}
class CategoryViewer {
- var $title, $limit, $from, $until,
+ var $limit, $from, $until,
$articles, $articles_start_char,
$children, $children_start_char,
- $showGallery, $gallery,
- $imgsNoGalley, $imgsNoGallery_start_char,
- $skin, $collation;
- # Category object for this page
+ $showGallery, $imgsNoGalley,
+ $imgsNoGallery_start_char,
+ $imgsNoGallery;
+
+ /**
+ * @var
+ */
+ var $nextPage;
+
+ /**
+ * @var Array
+ */
+ var $flip;
+
+ /**
+ * @var Title
+ */
+ var $title;
+
+ /**
+ * @var Collation
+ */
+ var $collation;
+
+ /**
+ * @var ImageGallery
+ */
+ var $gallery;
+
+ /**
+ * Category object for this page
+ * @var Category
+ */
private $cat;
- # The original query array, to be used in generating paging links.
+
+ /**
+ * The original query array, to be used in generating paging links.
+ * @var array
+ */
private $query;
function __construct( $title, $from = '', $until = '', $query = array() ) {
@@ -111,7 +156,7 @@ class CategoryViewer {
* @return string HTML output
*/
public function getHTML() {
- global $wgOut, $wgCategoryMagicGallery, $wgContLang;
+ global $wgOut, $wgCategoryMagicGallery, $wgLang, $wgContLang;
wfProfileIn( __METHOD__ );
$this->showGallery = $wgCategoryMagicGallery && !$wgOut->mNoGallery;
@@ -127,7 +172,7 @@ class CategoryViewer {
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();
@@ -142,6 +187,12 @@ class CategoryViewer {
$r = wfMsgExt( 'category-empty', array( 'parse' ) );
}
+ $pageLang = $this->title->getPageLanguage();
+ $langAttribs = array( 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() );
+ # close the previous div, show the headings in user language,
+ # then open a new div with the page content language again
+ $r = Html::openElement( 'div', $langAttribs ) . $r . '</div>';
+
wfProfileOut( __METHOD__ );
return $wgContLang->convert( $r );
}
@@ -160,14 +211,6 @@ class CategoryViewer {
}
}
- function getSkin() {
- if ( !$this->skin ) {
- global $wgUser;
- $this->skin = $wgUser->getSkin();
- }
- return $this->skin;
- }
-
/**
* Add a subcategory to the internal lists, using a Category object
*/
@@ -175,7 +218,7 @@ class CategoryViewer {
// Subcategory; strip the 'Category' namespace from the link text.
$title = $cat->getTitle();
- $link = $this->getSkin()->link( $title, $title->getText() );
+ $link = Linker::link( $title, htmlspecialchars( $title->getText() ) );
if ( $title->isRedirect() ) {
// This didn't used to add redirect-in-category, but might
// as well be consistent with the rest of the sections
@@ -190,7 +233,7 @@ class CategoryViewer {
/**
* 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 );
@@ -233,7 +276,7 @@ class CategoryViewer {
$this->gallery->add( $title );
}
} else {
- $link = $this->getSkin()->link( $title );
+ $link = Linker::link( $title );
if ( $isRedirect ) {
// This seems kind of pointless given 'mw-redirect' class,
// but keeping for back-compatibility with user css.
@@ -252,7 +295,7 @@ class CategoryViewer {
function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
global $wgContLang;
- $link = $this->getSkin()->link( $title );
+ $link = Linker::link( $title );
if ( $isRedirect ) {
// This seems kind of pointless given 'mw-redirect' class,
// but keeping for back-compatiability with user css.
@@ -309,7 +352,7 @@ class CategoryViewer {
'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title',
'cat_subcats', 'cat_pages', 'cat_files',
'cl_sortkey_prefix', 'cl_collation' ),
- array( 'cl_to' => $this->title->getDBkey() ) + $extraConds,
+ array_merge( array( 'cl_to' => $this->title->getDBkey() ), $extraConds ),
__METHOD__,
array(
'USE INDEX' => array( 'categorylinks' => 'cl_sortkey' ),
@@ -385,7 +428,7 @@ class CategoryViewer {
# 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.
@@ -460,13 +503,20 @@ class CategoryViewer {
* @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 '';
+
+ $pageLang = $this->title->getPageLanguage();
+ $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
+ 'class' => 'mw-content-'.$pageLang->getDir() );
+ $list = Html::rawElement( 'div', $attribs, $list );
+
+ return $list;
}
/**
@@ -539,10 +589,8 @@ class CategoryViewer {
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++ )
- {
- if ( $articles_start_char[$index] != $articles_start_char[$index - 1] )
- {
+ for ( $index = 1; $index < count( $articles ); $index++ ) {
+ if ( $articles_start_char[$index] != $articles_start_char[$index - 1] ) {
$r .= "</ul><h3>" . htmlspecialchars( $articles_start_char[$index] ) . "</h3>\n<ul>";
}
@@ -563,7 +611,7 @@ class CategoryViewer {
*/
private function pagingLinks( $first, $last, $type = '' ) {
global $wgLang;
- $sk = $this->getSkin();
+
$limitText = $wgLang->formatNum( $this->limit );
$prevLink = wfMsgExt( 'prevn', array( 'escape', 'parsemag' ), $limitText );
@@ -572,8 +620,8 @@ class CategoryViewer {
$prevQuery = $this->query;
$prevQuery["{$type}until"] = $first;
unset( $prevQuery["{$type}from"] );
- $prevLink = $sk->linkKnown(
- $this->title,
+ $prevLink = Linker::linkKnown(
+ $this->addFragmentToTitle( $this->title, $type ),
$prevLink,
array(),
$prevQuery
@@ -586,8 +634,8 @@ class CategoryViewer {
$lastQuery = $this->query;
$lastQuery["{$type}from"] = $last;
unset( $lastQuery["{$type}until"] );
- $nextLink = $sk->linkKnown(
- $this->title,
+ $nextLink = Linker::linkKnown(
+ $this->addFragmentToTitle( $this->title, $type ),
$nextLink,
array(),
$lastQuery
@@ -598,8 +646,34 @@ class CategoryViewer {
}
/**
+ * 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 independantly
+ * returned? This function says what. Each type is considered independently
* of the other types.
*
* Note for grepping: uses the messages category-article-count,
@@ -640,8 +714,7 @@ class CategoryViewer {
}
if ( $dbcnt == $rescnt || ( ( $rescnt == $this->limit || $fromOrUntil )
- && $dbcnt > $rescnt ) )
- {
+ && $dbcnt > $rescnt ) ) {
# Case 1: seems sane.
$totalcnt = $dbcnt;
} elseif ( $rescnt < $this->limit && !$fromOrUntil ) {