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
21 use MediaWiki\Category\Category
;
22 use MediaWiki\Deferred\DeferredUpdates
;
23 use MediaWiki\MediaWikiServices
;
26 * Special handling for representing category pages.
28 class WikiCategoryPage
extends WikiPage
{
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.
37 public function hasViewableContent() {
38 if ( parent
::hasViewableContent() ) {
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()
54 * Checks if a category is hidden.
59 public function isHidden() {
60 $pageId = $this->getTitle()->getArticleID();
61 $pageProps = MediaWikiServices
::getInstance()
63 ->getProperties( $this->getTitle(), 'hiddencat' );
65 return isset( $pageProps[$pageId] );
69 * Checks if a category is expected to be an unused category.
74 public function isExpectedUnusedCategory() {
75 $pageId = $this->getTitle()->getArticleID();
76 $pageProps = MediaWikiServices
::getInstance()
78 ->getProperties( $this->getTitle(), 'expectunusedcategory' );
80 return isset( $pageProps[$pageId] );
84 * Update category counts on purge (T85696)
88 public function doPurge() {
89 if ( !parent
::doPurge() ) {
90 // Aborted by hook most likely
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