Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
SpecialGloballyUnusedFiles | |
0.00% |
0 / 37 |
|
0.00% |
0 / 12 |
272 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isOnGlobalUsageDatabase | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
execute | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
isCacheable | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isListed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isExpensive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
sortDescending | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isSyndicated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
12 | |||
usesTimestamps | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPageHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Implements Special:GloballyUnusedFiles, the global equivalent to |
4 | * Special:UnusedFiles |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; if not, write to the Free Software Foundation, Inc., |
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | * http://www.gnu.org/copyleft/gpl.html |
20 | * |
21 | * @file |
22 | * @ingroup SpecialPage |
23 | */ |
24 | |
25 | namespace MediaWiki\Extension\GlobalUsage; |
26 | |
27 | use ErrorPageError; |
28 | use MediaWiki\SpecialPage\ImageQueryPage; |
29 | use MediaWiki\WikiMap\WikiMap; |
30 | use RuntimeException; |
31 | |
32 | /** |
33 | * A special page that lists globally unused files |
34 | * |
35 | * @ingroup SpecialPage |
36 | */ |
37 | class SpecialGloballyUnusedFiles extends ImageQueryPage { |
38 | public function __construct( $name = 'GloballyUnusedFiles' ) { |
39 | parent::__construct( $name ); |
40 | } |
41 | |
42 | /** |
43 | * Check if we are on wiki with globalimagelinks table in database. |
44 | * @return bool |
45 | */ |
46 | private function isOnGlobalUsageDatabase() { |
47 | global $wgGlobalUsageDatabase; |
48 | return !$wgGlobalUsageDatabase || $wgGlobalUsageDatabase === WikiMap::getCurrentWikiId(); |
49 | } |
50 | |
51 | /** |
52 | * Main execution function. Use the parent if we're on the right wiki. |
53 | * @param string $par |
54 | * @throws ErrorPageError if we are not on a wiki with GlobalUsage database |
55 | */ |
56 | public function execute( $par ) { |
57 | if ( $this->isOnGlobalUsageDatabase() ) { |
58 | parent::execute( $par ); |
59 | } else { |
60 | throw new ErrorPageError( 'globallyunusedfiles', 'globallyunusedfiles-error-nonsharedrepo' ); |
61 | } |
62 | } |
63 | |
64 | /** |
65 | * Allow to cache only if globalimagelinks table exists in database. |
66 | * @return bool |
67 | */ |
68 | public function isCacheable() { |
69 | return $this->isOnGlobalUsageDatabase(); |
70 | } |
71 | |
72 | /** |
73 | * Only list this special page on the wiki that has globalimagelinks table. |
74 | * @return bool Should this be listed in Special:SpecialPages |
75 | */ |
76 | public function isListed() { |
77 | return $this->isOnGlobalUsageDatabase(); |
78 | } |
79 | |
80 | public function isExpensive() { |
81 | return true; |
82 | } |
83 | |
84 | public function sortDescending() { |
85 | return false; |
86 | } |
87 | |
88 | public function isSyndicated() { |
89 | return false; |
90 | } |
91 | |
92 | public function getQueryInfo() { |
93 | if ( !$this->isOnGlobalUsageDatabase() ) { |
94 | throw new RuntimeException( "This wiki is not on shared repo" ); |
95 | } |
96 | |
97 | $retval = [ |
98 | 'tables' => [ 'image', 'globalimagelinks' ], |
99 | 'fields' => [ |
100 | 'namespace' => NS_FILE, |
101 | 'title' => 'img_name', |
102 | 'value' => 'img_timestamp', |
103 | ], |
104 | 'conds' => [ 'gil_to' => null ], |
105 | 'join_conds' => [ 'globalimagelinks' => [ 'LEFT JOIN', 'gil_to = img_name' ] ] |
106 | ]; |
107 | |
108 | if ( $this->getConfig()->get( 'CountCategorizedImagesAsUsed' ) ) { |
109 | // Order is significant |
110 | $retval['tables'] = [ 'image', 'page', 'categorylinks', |
111 | 'globalimagelinks' ]; |
112 | $retval['conds']['page_namespace'] = NS_FILE; |
113 | $retval['conds']['cl_from'] = null; |
114 | $retval['conds'][] = 'img_name = page_title'; |
115 | $retval['join_conds']['categorylinks'] = [ |
116 | 'LEFT JOIN', 'cl_from = page_id' ]; |
117 | $retval['join_conds']['globalimagelinks'] = [ |
118 | 'LEFT JOIN', 'gil_to = page_title' ]; |
119 | } |
120 | |
121 | return $retval; |
122 | } |
123 | |
124 | public function usesTimestamps() { |
125 | return true; |
126 | } |
127 | |
128 | public function getPageHeader() { |
129 | return $this->msg( 'globallyunusedfilestext' )->parseAsBlock(); |
130 | } |
131 | |
132 | protected function getGroupName() { |
133 | return 'maintenance'; |
134 | } |
135 | } |