Update Codex from v1.20.0 to v1.20.1
[mediawiki.git] / includes / page / WikiCategoryPage.php
blob1d507e77c9fef22c0cef3a9099578f64af2a698b
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 use MediaWiki\Category\Category;
22 use MediaWiki\Deferred\DeferredUpdates;
23 use MediaWiki\MediaWikiServices;
25 /**
26 * Special handling for representing category pages.
28 class WikiCategoryPage extends WikiPage {
30 /**
31 * Don't return a 404 for categories in use.
32 * In use defined as: either the actual page exists
33 * or the category currently has members.
35 * @return bool
37 public function hasViewableContent() {
38 if ( parent::hasViewableContent() ) {
39 return true;
40 } else {
41 $cat = Category::newFromTitle( $this->mTitle );
42 // If any of these are not 0, then has members
43 if ( $cat->getMemberCount()
44 || $cat->getSubcatCount()
45 || $cat->getFileCount()
46 ) {
47 return true;
50 return false;
53 /**
54 * Checks if a category is hidden.
56 * @since 1.27
57 * @return bool
59 public function isHidden() {
60 $pageId = $this->getTitle()->getArticleID();
61 $pageProps = MediaWikiServices::getInstance()
62 ->getPageProps()
63 ->getProperties( $this->getTitle(), 'hiddencat' );
65 return isset( $pageProps[$pageId] );
68 /**
69 * Checks if a category is expected to be an unused category.
71 * @since 1.33
72 * @return bool
74 public function isExpectedUnusedCategory() {
75 $pageId = $this->getTitle()->getArticleID();
76 $pageProps = MediaWikiServices::getInstance()
77 ->getPageProps()
78 ->getProperties( $this->getTitle(), 'expectunusedcategory' );
80 return isset( $pageProps[$pageId] );
83 /**
84 * Update category counts on purge (T85696)
86 * @return bool
88 public function doPurge() {
89 if ( !parent::doPurge() ) {
90 // Aborted by hook most likely
91 return false;
94 $title = $this->mTitle;
95 DeferredUpdates::addCallableUpdate(
96 static function () use ( $title ) {
97 $cat = Category::newFromTitle( $title );
98 // If the category has less than 5000 pages, refresh the counts.
99 // 5000 was chosen based on the discussion at T85696.
100 $cat->refreshCountsIfSmall( 5000 );
102 // Explicitly PRESEND so that counts are correct before we try to
103 // re-render the page on the next load so {{PAGESINCAT:...}} will
104 // be using the correct new values, not the old ones.
105 DeferredUpdates::PRESEND
108 return true;