Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
34.48% |
10 / 29 |
|
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 | * 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. |
7 | * |
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. |
12 | * |
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 |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | use MediaWiki\Category\Category; |
22 | use MediaWiki\Deferred\DeferredUpdates; |
23 | use MediaWiki\MediaWikiServices; |
24 | |
25 | /** |
26 | * Special handling for representing category pages. |
27 | */ |
28 | class WikiCategoryPage extends WikiPage { |
29 | |
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. |
34 | * |
35 | * @return bool |
36 | */ |
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; |
48 | } |
49 | } |
50 | return false; |
51 | } |
52 | |
53 | /** |
54 | * Checks if a category is hidden. |
55 | * |
56 | * @since 1.27 |
57 | * @return bool |
58 | */ |
59 | public function isHidden() { |
60 | $pageId = $this->getTitle()->getArticleID(); |
61 | $pageProps = MediaWikiServices::getInstance() |
62 | ->getPageProps() |
63 | ->getProperties( $this->getTitle(), 'hiddencat' ); |
64 | |
65 | return isset( $pageProps[$pageId] ); |
66 | } |
67 | |
68 | /** |
69 | * Checks if a category is expected to be an unused category. |
70 | * |
71 | * @since 1.33 |
72 | * @return bool |
73 | */ |
74 | public function isExpectedUnusedCategory() { |
75 | $pageId = $this->getTitle()->getArticleID(); |
76 | $pageProps = MediaWikiServices::getInstance() |
77 | ->getPageProps() |
78 | ->getProperties( $this->getTitle(), 'expectunusedcategory' ); |
79 | |
80 | return isset( $pageProps[$pageId] ); |
81 | } |
82 | |
83 | /** |
84 | * Update category counts on purge (T85696) |
85 | * |
86 | * @return bool |
87 | */ |
88 | public function doPurge() { |
89 | if ( !parent::doPurge() ) { |
90 | // Aborted by hook most likely |
91 | return false; |
92 | } |
93 | |
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 ); |
101 | }, |
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 |
106 | ); |
107 | |
108 | return true; |
109 | } |
110 | } |