Merge "Drop index oi_name_archive_name on table oldimage"
[lhc/web/wiklou.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
29 /**
30 * Special:ListDuplicatedFiles Lists all files where the current version is
31 * a duplicate of the current version of some other file.
32 * @ingroup SpecialPage
33 */
34 class ListDuplicatedFilesPage extends QueryPage {
35 function __construct( $name = 'ListDuplicatedFiles' ) {
36 parent::__construct( $name );
37 }
38
39 public function isExpensive() {
40 return true;
41 }
42
43 function isSyndicated() {
44 return false;
45 }
46
47 /**
48 * Get all the duplicates by grouping on sha1s.
49 *
50 * A cheaper (but less useful) version of this
51 * query would be to not care how many duplicates a
52 * particular file has, and do a self-join on image table.
53 * However this version should be no more expensive then
54 * Special:MostLinked, which seems to get handled fine
55 * with however we are doing cached special pages.
56 * @return array
57 */
58 public function getQueryInfo() {
59 return [
60 'tables' => [ 'image' ],
61 'fields' => [
62 'namespace' => NS_FILE,
63 'title' => 'MIN(img_name)',
64 'value' => 'count(*)'
65 ],
66 'options' => [
67 'GROUP BY' => 'img_sha1',
68 'HAVING' => 'count(*) > 1',
69 ],
70 ];
71 }
72
73 /**
74 * Pre-fill the link cache
75 *
76 * @param IDatabase $db
77 * @param ResultWrapper $res
78 */
79 function preprocessResults( $db, $res ) {
80 $this->executeLBFromResultWrapper( $res );
81 }
82
83 /**
84 * @param Skin $skin
85 * @param object $result Result row
86 * @return string
87 */
88 function formatResult( $skin, $result ) {
89 // Future version might include a list of the first 5 duplicates
90 // perhaps separated by an "↔".
91 $image1 = Title::makeTitle( $result->namespace, $result->title );
92 $dupeSearch = SpecialPage::getTitleFor( 'FileDuplicateSearch', $image1->getDBkey() );
93
94 $msg = $this->msg( 'listduplicatedfiles-entry' )
95 ->params( $image1->getText() )
96 ->numParams( $result->value - 1 )
97 ->params( $dupeSearch->getPrefixedDBkey() );
98
99 return $msg->parse();
100 }
101
102 protected function getGroupName() {
103 return 'media';
104 }
105 }