Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
SpecialUnusedImages | |
0.00% |
0 / 50 |
|
0.00% |
0 / 8 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
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 / 35 |
|
0.00% |
0 / 1 |
12 | |||
usesTimestamps | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPageHeader | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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 | namespace MediaWiki\Specials; |
22 | |
23 | use MediaWiki\MainConfigNames; |
24 | use MediaWiki\MediaWikiServices; |
25 | use MediaWiki\SpecialPage\ImageQueryPage; |
26 | use Wikimedia\Rdbms\IConnectionProvider; |
27 | |
28 | /** |
29 | * List of unused images |
30 | * |
31 | * @ingroup SpecialPage |
32 | */ |
33 | class SpecialUnusedImages extends ImageQueryPage { |
34 | private int $migrationStage; |
35 | |
36 | public function __construct( IConnectionProvider $dbProvider ) { |
37 | parent::__construct( 'Unusedimages' ); |
38 | $this->setDatabaseProvider( $dbProvider ); |
39 | $this->migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get( |
40 | MainConfigNames::FileSchemaMigrationStage |
41 | ); |
42 | } |
43 | |
44 | public function isExpensive() { |
45 | return true; |
46 | } |
47 | |
48 | protected function sortDescending() { |
49 | return false; |
50 | } |
51 | |
52 | public function isSyndicated() { |
53 | return false; |
54 | } |
55 | |
56 | public function getQueryInfo() { |
57 | if ( $this->migrationStage & SCHEMA_COMPAT_READ_OLD ) { |
58 | $tables = [ 'image' ]; |
59 | $nameField = 'img_name'; |
60 | $timestampField = 'img_timestamp'; |
61 | $extraConds = []; |
62 | $extraJoins = []; |
63 | } else { |
64 | $tables = [ 'file', 'filerevision' ]; |
65 | $nameField = 'file_name'; |
66 | $timestampField = 'fr_timestamp'; |
67 | $extraConds = [ 'file_deleted' => 0 ]; |
68 | $extraJoins = [ 'filerevision' => [ 'JOIN', 'file_latest = fr_id' ] ]; |
69 | } |
70 | |
71 | $retval = [ |
72 | 'tables' => array_merge( $tables, [ 'imagelinks' ] ), |
73 | 'fields' => [ |
74 | 'namespace' => NS_FILE, |
75 | 'title' => $nameField, |
76 | 'value' => $timestampField, |
77 | ], |
78 | 'conds' => array_merge( [ 'il_to' => null ], $extraConds ), |
79 | 'join_conds' => array_merge( |
80 | [ 'imagelinks' => [ 'LEFT JOIN', 'il_to = ' . $nameField ] ], |
81 | $extraJoins |
82 | ), |
83 | ]; |
84 | |
85 | if ( $this->getConfig()->get( MainConfigNames::CountCategorizedImagesAsUsed ) ) { |
86 | // Order is significant |
87 | $retval['tables'] = [ 'image', 'page', 'categorylinks', |
88 | 'imagelinks' ]; |
89 | $retval['conds']['page_namespace'] = NS_FILE; |
90 | $retval['conds']['cl_from'] = null; |
91 | $retval['conds'][] = $nameField . ' = page_title'; |
92 | $retval['join_conds']['categorylinks'] = [ |
93 | 'LEFT JOIN', 'cl_from = page_id' ]; |
94 | $retval['join_conds']['imagelinks'] = [ |
95 | 'LEFT JOIN', 'il_to = page_title' ]; |
96 | } |
97 | |
98 | return $retval; |
99 | } |
100 | |
101 | public function usesTimestamps() { |
102 | return true; |
103 | } |
104 | |
105 | protected function getPageHeader() { |
106 | if ( $this->getConfig()->get( MainConfigNames::CountCategorizedImagesAsUsed ) ) { |
107 | return $this->msg( |
108 | 'unusedimagestext-categorizedimgisused' |
109 | )->parseAsBlock(); |
110 | } |
111 | return $this->msg( 'unusedimagestext' )->parseAsBlock(); |
112 | } |
113 | |
114 | protected function getGroupName() { |
115 | return 'maintenance'; |
116 | } |
117 | } |
118 | |
119 | /** |
120 | * Retain the old class name for backwards compatibility. |
121 | * @deprecated since 1.41 |
122 | */ |
123 | class_alias( SpecialUnusedImages::class, 'SpecialUnusedImages' ); |