MediaWiki  master
SpecialListDuplicatedFiles.php
Go to the documentation of this file.
1 <?php
27 namespace MediaWiki\Specials;
28 
33 use Skin;
34 use stdClass;
38 
45 
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 
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 
99  public function preprocessResults( $db, $res ) {
100  $this->executeLBFromResultWrapper( $res );
101  }
102 
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 
135 class_alias( SpecialListDuplicatedFiles::class, 'SpecialListDuplicatedFiles' );
const NS_FILE
Definition: Defines.php:70
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:88
setDatabaseProvider(IConnectionProvider $databaseProvider)
Definition: QueryPage.php:985
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
Definition: QueryPage.php:946
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:185
Parent class for all special pages.
Definition: SpecialPage.php:66
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.
Special:ListDuplicatedFiles Lists all files where the current version is a duplicate of the current v...
getQueryInfo()
Get all the duplicates by grouping on sha1s.
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
isExpensive()
Should this query page only be updated offline on large wikis?
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
preprocessResults( $db, $res)
Pre-fill the link cache.
Represents a title within MediaWiki.
Definition: Title.php:76
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:624
The base class for all skins.
Definition: Skin.php:60
Provide primary and replica IDatabase connections.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:36
Result wrapper for grabbing data queried from an IDatabase object.