Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialListDuplicatedFiles
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 8
72
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 isExpensive
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isSyndicated
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getQueryInfo
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 preprocessResults
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 formatResult
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
27namespace MediaWiki\Specials;
28
29use MediaWiki\Cache\LinkBatchFactory;
30use MediaWiki\SpecialPage\QueryPage;
31use MediaWiki\SpecialPage\SpecialPage;
32use MediaWiki\Title\Title;
33use Skin;
34use stdClass;
35use Wikimedia\Rdbms\IConnectionProvider;
36use Wikimedia\Rdbms\IDatabase;
37use Wikimedia\Rdbms\IResultWrapper;
38
39/**
40 * Special:ListDuplicatedFiles Lists all files where the current version is
41 *   a duplicate of the current version of some other file.
42 * @ingroup SpecialPage
43 */
44class SpecialListDuplicatedFiles extends QueryPage {
45
46    /**
47     * @param IConnectionProvider $dbProvider
48     * @param LinkBatchFactory $linkBatchFactory
49     */
50    public function __construct(
51        IConnectionProvider $dbProvider,
52        LinkBatchFactory $linkBatchFactory
53    ) {
54        parent::__construct( 'ListDuplicatedFiles' );
55        $this->setDatabaseProvider( $dbProvider );
56        $this->setLinkBatchFactory( $linkBatchFactory );
57    }
58
59    public function isExpensive() {
60        return true;
61    }
62
63    public function isSyndicated() {
64        return false;
65    }
66
67    /**
68     * Get all the duplicates by grouping on sha1s.
69     *
70     * A cheaper (but less useful) version of this
71     * query would be to not care how many duplicates a
72     * particular file has, and do a self-join on image table.
73     * However this version should be no more expensive then
74     * Special:MostLinked, which seems to get handled fine
75     * with however we are doing cached special pages.
76     * @return array
77     */
78    public function getQueryInfo() {
79        return [
80            'tables' => [ 'image' ],
81            'fields' => [
82                'namespace' => NS_FILE,
83                'title' => 'MIN(img_name)',
84                'value' => 'count(*)'
85            ],
86            'options' => [
87                'GROUP BY' => 'img_sha1',
88                'HAVING' => 'count(*) > 1',
89            ],
90        ];
91    }
92
93    /**
94     * Pre-fill the link cache
95     *
96     * @param IDatabase $db
97     * @param IResultWrapper $res
98     */
99    public function preprocessResults( $db, $res ) {
100        $this->executeLBFromResultWrapper( $res );
101    }
102
103    /**
104     * @param Skin $skin
105     * @param stdClass $result Result row
106     * @return string
107     */
108    public function formatResult( $skin, $result ) {
109        // Future version might include a list of the first 5 duplicates
110        // perhaps separated by an "↔".
111        $image1 = Title::makeTitle( $result->namespace, $result->title );
112        $dupeSearch = SpecialPage::getTitleFor( 'FileDuplicateSearch', $image1->getDBkey() );
113
114        $msg = $this->msg( 'listduplicatedfiles-entry' )
115            ->params( $image1->getText() )
116            ->numParams( $result->value - 1 )
117            ->params( $dupeSearch->getPrefixedDBkey() );
118
119        return $msg->parse();
120    }
121
122    public function execute( $par ) {
123        $this->addHelpLink( 'Help:Managing_files' );
124        parent::execute( $par );
125    }
126
127    protected function getGroupName() {
128        return 'media';
129    }
130}
131
132/** @deprecated class alias since 1.41 */
133class_alias( SpecialListDuplicatedFiles::class, 'SpecialListDuplicatedFiles' );