diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2014-12-27 15:41:37 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2014-12-31 11:43:28 +0100 |
commit | c1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch) | |
tree | 2b38796e738dd74cb42ecd9bfd151803108386bc /includes/CategoryViewer.php | |
parent | b88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff) |
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/CategoryViewer.php')
-rw-r--r-- | includes/CategoryViewer.php | 203 |
1 files changed, 116 insertions, 87 deletions
diff --git a/includes/CategoryViewer.php b/includes/CategoryViewer.php index 55d9c1e5..7581ae40 100644 --- a/includes/CategoryViewer.php +++ b/includes/CategoryViewer.php @@ -21,68 +21,77 @@ */ class CategoryViewer extends ContextSource { - var $limit, $from, $until, - $articles, $articles_start_char, - $children, $children_start_char, - $showGallery, $imgsNoGalley, - $imgsNoGallery_start_char, - $imgsNoGallery; + /** @var int */ + public $limit; - /** - * @var Array - */ - var $nextPage; + /** @var array */ + public $from; - /** - * @var Array - */ - var $flip; + /** @var array */ + public $until; - /** - * @var Title - */ - var $title; + /** @var string[] */ + public $articles; - /** - * @var Collation - */ - var $collation; + /** @var array */ + public $articles_start_char; - /** - * @var ImageGallery - */ - var $gallery; + /** @var array */ + public $children; - /** - * Category object for this page - * @var Category - */ + /** @var array */ + public $children_start_char; + + /** @var bool */ + public $showGallery; + + /** @var array */ + public $imgsNoGallery_start_char; + + /** @var array */ + public $imgsNoGallery; + + /** @var array */ + public $nextPage; + + /** @var array */ + protected $prevPage; + + /** @var array */ + public $flip; + + /** @var Title */ + public $title; + + /** @var Collation */ + public $collation; + + /** @var ImageGallery */ + public $gallery; + + /** @var Category Category object for this page. */ private $cat; - /** - * The original query array, to be used in generating paging links. - * @var array - */ + /** @var array The original query array, to be used in generating paging links. */ private $query; /** - * Constructor - * * @since 1.19 $context is a second, required parameter - * @param $title Title - * @param $context IContextSource + * @param Title $title + * @param IContextSource $context * @param array $from An array with keys page, subcat, * and file for offset of results of each section (since 1.17) * @param array $until An array with 3 keys for until of each section (since 1.17) - * @param $query Array + * @param array $query */ - function __construct( $title, IContextSource $context, $from = array(), $until = array(), $query = array() ) { - global $wgCategoryPagingLimit; + function __construct( $title, IContextSource $context, $from = array(), + $until = array(), $query = array() + ) { $this->title = $title; $this->setContext( $context ); $this->from = $from; $this->until = $until; - $this->limit = $wgCategoryPagingLimit; + $this->limit = $context->getConfig()->get( 'CategoryPagingLimit' ); $this->cat = Category::newFromTitle( $title ); $this->query = $query; $this->collation = Collation::singleton(); @@ -95,10 +104,10 @@ class CategoryViewer extends ContextSource { * @return string HTML output */ public function getHTML() { - global $wgCategoryMagicGallery; wfProfileIn( __METHOD__ ); - $this->showGallery = $wgCategoryMagicGallery && !$this->getOutput()->mNoGallery; + $this->showGallery = $this->getConfig()->get( 'CategoryMagicGallery' ) + && !$this->getOutput()->mNoGallery; $this->clearCategoryState(); $this->doCategoryQuery(); @@ -144,14 +153,13 @@ class CategoryViewer extends ContextSource { // Note that null for mode is taken to mean use default. $mode = $this->getRequest()->getVal( 'gallerymode', null ); try { - $this->gallery = ImageGalleryBase::factory( $mode ); + $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() ); } catch ( MWException $e ) { // User specified something invalid, fallback to default. - $this->gallery = ImageGalleryBase::factory(); + $this->gallery = ImageGalleryBase::factory( false, $this->getContext() ); } $this->gallery->setHideBadImages(); - $this->gallery->setContext( $this->getContext() ); } else { $this->imgsNoGallery = array(); $this->imgsNoGallery_start_char = array(); @@ -160,9 +168,9 @@ class CategoryViewer extends ContextSource { /** * Add a subcategory to the internal lists, using a Category object - * @param $cat Category - * @param $sortkey - * @param $pageLength + * @param Category $cat + * @param string $sortkey + * @param int $pageLength */ function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) { // Subcategory; strip the 'Category' namespace from the link text. @@ -182,15 +190,6 @@ class CategoryViewer extends ContextSource { } /** - * Add a subcategory to the internal lists, using a title object - * @deprecated since 1.17 kept for compatibility, use addSubcategoryObject instead - */ - function addSubcategory( Title $title, $sortkey, $pageLength ) { - wfDeprecated( __METHOD__, '1.17' ); - $this->addSubcategoryObject( Category::newFromTitle( $title ), $sortkey, $pageLength ); - } - - /** * Get the character to be used for sorting subcategories. * If there's a link from Category:A to Category:B, the sortkey of the resulting * entry in the categorylinks table is Category:A, not A, which it SHOULD be. @@ -217,10 +216,10 @@ class CategoryViewer extends ContextSource { /** * Add a page in the image namespace - * @param $title Title - * @param $sortkey - * @param $pageLength - * @param $isRedirect bool + * @param Title $title + * @param string $sortkey + * @param int $pageLength + * @param bool $isRedirect */ function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) { global $wgContLang; @@ -247,10 +246,10 @@ class CategoryViewer extends ContextSource { /** * Add a miscellaneous page - * @param $title - * @param $sortkey - * @param $pageLength - * @param $isRedirect bool + * @param Title $title + * @param string $sortkey + * @param int $pageLength + * @param bool $isRedirect */ function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) { global $wgContLang; @@ -290,6 +289,12 @@ class CategoryViewer extends ContextSource { 'subcat' => null, 'file' => null, ); + $this->prevPage = array( + 'page' => null, + 'subcat' => null, + 'file' => null, + ); + $this->flip = array( 'page' => false, 'subcat' => false, 'file' => false ); foreach ( array( 'page', 'subcat', 'file' ) as $type ) { @@ -346,6 +351,9 @@ class CategoryViewer extends ContextSource { $this->nextPage[$type] = $humanSortkey; break; } + if ( $count == $this->limit ) { + $this->prevPage[$type] = $humanSortkey; + } if ( $title->getNamespace() == NS_CATEGORY ) { $cat = Category::newFromRow( $row, $title ); @@ -432,7 +440,12 @@ class CategoryViewer extends ContextSource { $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' ); $r .= "<div id=\"mw-category-media\">\n"; - $r .= '<h2>' . $this->msg( 'category-media-header', wfEscapeWikiText( $this->title->getText() ) )->text() . "</h2>\n"; + $r .= '<h2>' . + $this->msg( + 'category-media-header', + wfEscapeWikiText( $this->title->getText() ) + )->text() . + "</h2>\n"; $r .= $countmsg; $r .= $this->getSectionPagingLinks( 'file' ); if ( $this->showGallery ) { @@ -451,12 +464,24 @@ class CategoryViewer extends ContextSource { * of the output. * * @param string $type 'page', 'subcat', or 'file' - * @return String: HTML output, possibly empty if there are no other pages + * @return string HTML output, possibly empty if there are no other pages */ private function getSectionPagingLinks( $type ) { if ( isset( $this->until[$type] ) && $this->until[$type] !== null ) { - return $this->pagingLinks( $this->nextPage[$type], $this->until[$type], $type ); - } elseif ( $this->nextPage[$type] !== null || ( isset( $this->from[$type] ) && $this->from[$type] !== null ) ) { + // The new value for the until parameter should be pointing to the first + // result displayed on the page which is the second last result retrieved + // from the database.The next link should have a from parameter pointing + // to the until parameter of the current page. + if ( $this->nextPage[$type] !== null ) { + return $this->pagingLinks( $this->prevPage[$type], $this->until[$type], $type ); + } else { + // If the nextPage variable is null, it means that we have reached the first page + // and therefore the previous link should be disabled. + return $this->pagingLinks( null, $this->until[$type], $type ); + } + } elseif ( $this->nextPage[$type] !== null + || ( isset( $this->from[$type] ) && $this->from[$type] !== null ) + ) { return $this->pagingLinks( $this->from[$type], $this->nextPage[$type], $type ); } else { return ''; @@ -474,10 +499,10 @@ class CategoryViewer extends ContextSource { * Format a list of articles chunked by letter, either as a * bullet list or a columnar format, depending on the length. * - * @param $articles Array - * @param $articles_start_char Array - * @param $cutoff Int - * @return String + * @param array $articles + * @param array $articles_start_char + * @param int $cutoff + * @return string * @private */ function formatList( $articles, $articles_start_char, $cutoff = 6 ) { @@ -507,9 +532,9 @@ class CategoryViewer extends ContextSource { * More distant TODO: Scrap this and use CSS columns, whenever IE finally * supports those. * - * @param $articles Array - * @param $articles_start_char Array - * @return String + * @param array $articles + * @param string[] $articles_start_char + * @return string * @private */ static function columnList( $articles, $articles_start_char ) { @@ -563,15 +588,16 @@ class CategoryViewer extends ContextSource { /** * Format a list of articles chunked by letter in a bullet list. - * @param $articles Array - * @param $articles_start_char Array - * @return String + * @param array $articles + * @param string[] $articles_start_char + * @return string * @private */ 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++ ) { + $articleCount = count( $articles ); + for ( $index = 1; $index < $articleCount; $index++ ) { if ( $articles_start_char[$index] != $articles_start_char[$index - 1] ) { $r .= "</ul><h3>" . htmlspecialchars( $articles_start_char[$index] ) . "</h3>\n<ul>"; } @@ -589,7 +615,7 @@ class CategoryViewer extends ContextSource { * @param string $last The 'from' parameter for the generated URL * @param string $type A prefix for parameters, 'page' or 'subcat' or * 'file' - * @return String HTML + * @return string HTML */ private function pagingLinks( $first, $last, $type = '' ) { $prevLink = $this->msg( 'prevn' )->numParams( $this->limit )->escaped(); @@ -627,8 +653,8 @@ class CategoryViewer extends ContextSource { * 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 + * @param Title $title The title (usually $this->title) + * @param string $section Which section * @throws MWException * @return Title */ @@ -660,7 +686,7 @@ class CategoryViewer extends ContextSource { * @param int $rescnt The number of items returned by our database query. * @param int $dbcnt The number of items according to the category table. * @param string $type 'subcat', 'article', or 'file' - * @return string: A message giving the number of items, to output to HTML. + * @return string A message giving the number of items, to output to HTML. */ private function getCountMessage( $rescnt, $dbcnt, $type ) { // There are three cases: @@ -701,7 +727,10 @@ class CategoryViewer extends ContextSource { // to refresh the incorrect category table entry -- which should be // quick due to the small number of entries. $totalcnt = $rescnt; - $this->cat->refreshCounts(); + $category = $this->cat; + wfGetDB( DB_MASTER )->onTransactionIdle( function () use ( $category ) { + $category->refreshCounts(); + } ); } else { // Case 3: hopeless. Don't give a total count at all. // Messages: category-subcat-count-limited, category-article-count-limited, |