MediaWiki master
SpecialListDuplicatedFiles.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Specials;
10
18use stdClass;
22
31 private readonly int $migrationStage;
32
33 public function __construct(
34 IConnectionProvider $dbProvider,
35 LinkBatchFactory $linkBatchFactory
36 ) {
37 parent::__construct( 'ListDuplicatedFiles' );
38 $this->setDatabaseProvider( $dbProvider );
39 $this->setLinkBatchFactory( $linkBatchFactory );
40 $this->migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get(
42 );
43 }
44
46 public function isExpensive() {
47 return true;
48 }
49
51 public function isSyndicated() {
52 return false;
53 }
54
66 public function getQueryInfo() {
67 if ( $this->migrationStage & SCHEMA_COMPAT_READ_OLD ) {
68 $tables = [ 'image' ];
69 $nameField = 'img_name';
70 $hashField = 'img_sha1';
71 $conds = [];
72 $joins = [];
73 } else {
74 $tables = [ 'file', 'filerevision' ];
75 $nameField = 'file_name';
76 $hashField = 'fr_sha1';
77 $conds = [ 'file_deleted' => 0 ];
78 $joins = [ 'filerevision' => [ 'JOIN', 'file_latest = fr_id' ] ];
79 }
80 return [
81 'tables' => $tables,
82 'fields' => [
83 'namespace' => NS_FILE,
84 'title' => "MIN($nameField)",
85 'value' => 'count(*)'
86 ],
87 'conds' => $conds,
88 'join_conds' => $joins,
89 'options' => [
90 'GROUP BY' => $hashField,
91 'HAVING' => 'count(*) > 1',
92 ],
93 ];
94 }
95
102 public function preprocessResults( $db, $res ) {
103 $this->executeLBFromResultWrapper( $res );
104 }
105
111 public function formatResult( $skin, $result ) {
112 // Future version might include a list of the first 5 duplicates
113 // perhaps separated by an "↔".
114 $image1 = Title::makeTitle( $result->namespace, $result->title );
115 $dupeSearch = SpecialPage::getTitleFor( 'FileDuplicateSearch', $image1->getDBkey() );
116
117 $msg = $this->msg( 'listduplicatedfiles-entry' )
118 ->params( $image1->getText() )
119 ->numParams( $result->value - 1 )
120 ->params( $dupeSearch->getPrefixedDBkey() );
121
122 return $msg->parse();
123 }
124
126 public function execute( $par ) {
127 $this->addHelpLink( 'Help:Managing_files' );
128 parent::execute( $par );
129 }
130
132 protected function getGroupName() {
133 return 'media';
134 }
135}
136
138class_alias( SpecialListDuplicatedFiles::class, 'SpecialListDuplicatedFiles' );
const NS_FILE
Definition Defines.php:57
const SCHEMA_COMPAT_READ_OLD
Definition Defines.php:294
makeTitle( $linkId)
Convert a link ID to a Title.to override Title
A class containing constants representing the names of configuration variables.
const FileSchemaMigrationStage
Name constant for the FileSchemaMigrationStage setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Factory for LinkBatch objects to batch query page metadata.
The base class for all skins.
Definition Skin.php:54
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition QueryPage.php:77
setDatabaseProvider(IConnectionProvider $databaseProvider)
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
List all files where the current version is a duplicate of the current version of another file.
getQueryInfo()
Get all the duplicates by grouping on sha1s.
isSyndicated()
Sometimes we don't want to build rss / atom feeds.to override bool
isExpensive()
Should this query page only be updated offline on large wikis?If the query for this page is considere...
execute( $par)
This is the actual workhorse.It does everything needed to make a real, honest-to-gosh query page....
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Represents a title within MediaWiki.
Definition Title.php:69
Provide primary and replica IDatabase connections.
A database connection without write operations.
Result wrapper for grabbing data queried from an IDatabase object.