Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
10 / 30 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| WikiCategoryPage | |
34.48% |
10 / 29 |
|
50.00% |
2 / 4 |
31.78 | |
0.00% |
0 / 1 |
| hasViewableContent | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
30 | |||
| isHidden | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| isExpectedUnusedCategory | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| doPurge | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Page; |
| 8 | |
| 9 | use MediaWiki\Category\Category; |
| 10 | use MediaWiki\Deferred\DeferredUpdates; |
| 11 | use MediaWiki\MediaWikiServices; |
| 12 | |
| 13 | /** |
| 14 | * Special handling for representing category pages. |
| 15 | */ |
| 16 | class WikiCategoryPage extends WikiPage { |
| 17 | |
| 18 | /** |
| 19 | * Don't return a 404 for categories in use. |
| 20 | * In use defined as: either the actual page exists |
| 21 | * or the category currently has members. |
| 22 | * |
| 23 | * @return bool |
| 24 | */ |
| 25 | public function hasViewableContent() { |
| 26 | if ( parent::hasViewableContent() ) { |
| 27 | return true; |
| 28 | } else { |
| 29 | $cat = Category::newFromTitle( $this->mTitle ); |
| 30 | // If any of these are not 0, then has members |
| 31 | if ( $cat->getMemberCount() |
| 32 | || $cat->getSubcatCount() |
| 33 | || $cat->getFileCount() |
| 34 | ) { |
| 35 | return true; |
| 36 | } |
| 37 | } |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Checks if a category is hidden. |
| 43 | * |
| 44 | * @since 1.27 |
| 45 | * @return bool |
| 46 | */ |
| 47 | public function isHidden() { |
| 48 | $pageId = $this->getTitle()->getArticleID(); |
| 49 | $pageProps = MediaWikiServices::getInstance() |
| 50 | ->getPageProps() |
| 51 | ->getProperties( $this->getTitle(), 'hiddencat' ); |
| 52 | |
| 53 | return isset( $pageProps[$pageId] ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Checks if a category is expected to be an unused category. |
| 58 | * |
| 59 | * @since 1.33 |
| 60 | * @return bool |
| 61 | */ |
| 62 | public function isExpectedUnusedCategory() { |
| 63 | $pageId = $this->getTitle()->getArticleID(); |
| 64 | $pageProps = MediaWikiServices::getInstance() |
| 65 | ->getPageProps() |
| 66 | ->getProperties( $this->getTitle(), 'expectunusedcategory' ); |
| 67 | |
| 68 | return isset( $pageProps[$pageId] ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Update category counts on purge (T85696) |
| 73 | * |
| 74 | * @return bool |
| 75 | */ |
| 76 | public function doPurge() { |
| 77 | if ( !parent::doPurge() ) { |
| 78 | // Aborted by hook most likely |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | $title = $this->mTitle; |
| 83 | DeferredUpdates::addCallableUpdate( |
| 84 | static function () use ( $title ) { |
| 85 | $cat = Category::newFromTitle( $title ); |
| 86 | // If the category has less than 5000 pages, refresh the counts. |
| 87 | // 5000 was chosen based on the discussion at T85696. |
| 88 | $cat->refreshCountsIfSmall( 5000 ); |
| 89 | }, |
| 90 | // Explicitly PRESEND so that counts are correct before we try to |
| 91 | // re-render the page on the next load so {{PAGESINCAT:...}} will |
| 92 | // be using the correct new values, not the old ones. |
| 93 | DeferredUpdates::PRESEND |
| 94 | ); |
| 95 | |
| 96 | return true; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /** @deprecated class alias since 1.44 */ |
| 101 | class_alias( WikiCategoryPage::class, 'WikiCategoryPage' ); |