]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialListDuplicatedFiles.php
MediaWiki 1.30.2 renames
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialListDuplicatedFiles.php
1 <?php
2 /**
3  * Implements Special:ListDuplicatedFiles
4  *
5  * Copyright © 2013 Brian Wolff
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  * http://www.gnu.org/copyleft/gpl.html
21  *
22  * @file
23  * @ingroup SpecialPage
24  * @author Brian Wolff
25  */
26
27 use Wikimedia\Rdbms\ResultWrapper;
28 use Wikimedia\Rdbms\IDatabase;
29
30 /**
31  * Special:ListDuplicatedFiles Lists all files where the current version is
32  *   a duplicate of the current version of some other file.
33  * @ingroup SpecialPage
34  */
35 class ListDuplicatedFilesPage extends QueryPage {
36         function __construct( $name = 'ListDuplicatedFiles' ) {
37                 parent::__construct( $name );
38         }
39
40         public function isExpensive() {
41                 return true;
42         }
43
44         function isSyndicated() {
45                 return false;
46         }
47
48         /**
49          * Get all the duplicates by grouping on sha1s.
50          *
51          * A cheaper (but less useful) version of this
52          * query would be to not care how many duplicates a
53          * particular file has, and do a self-join on image table.
54          * However this version should be no more expensive then
55          * Special:MostLinked, which seems to get handled fine
56          * with however we are doing cached special pages.
57          * @return array
58          */
59         public function getQueryInfo() {
60                 return [
61                         'tables' => [ 'image' ],
62                         'fields' => [
63                                 'namespace' => NS_FILE,
64                                 'title' => 'MIN(img_name)',
65                                 'value' => 'count(*)'
66                         ],
67                         'options' => [
68                                 'GROUP BY' => 'img_sha1',
69                                 'HAVING' => 'count(*) > 1',
70                         ],
71                 ];
72         }
73
74         /**
75          * Pre-fill the link cache
76          *
77          * @param IDatabase $db
78          * @param ResultWrapper $res
79          */
80         function preprocessResults( $db, $res ) {
81                 $this->executeLBFromResultWrapper( $res );
82         }
83
84         /**
85          * @param Skin $skin
86          * @param object $result Result row
87          * @return string
88          */
89         function formatResult( $skin, $result ) {
90                 // Future version might include a list of the first 5 duplicates
91                 // perhaps separated by an "↔".
92                 $image1 = Title::makeTitle( $result->namespace, $result->title );
93                 $dupeSearch = SpecialPage::getTitleFor( 'FileDuplicateSearch', $image1->getDBkey() );
94
95                 $msg = $this->msg( 'listduplicatedfiles-entry' )
96                         ->params( $image1->getText() )
97                         ->numParams( $result->value - 1 )
98                         ->params( $dupeSearch->getPrefixedDBkey() );
99
100                 return $msg->parse();
101         }
102
103         protected function getGroupName() {
104                 return 'media';
105         }
106 }