MediaWiki master
SpecialWantedFiles.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Specials;
10
11use MediaWiki\Cache\LinkBatchFactory;
19
27
28 private RepoGroup $repoGroup;
29 private int $migrationStage;
30
31 public function __construct(
32 RepoGroup $repoGroup,
33 IConnectionProvider $dbProvider,
34 LinkBatchFactory $linkBatchFactory
35 ) {
36 parent::__construct( 'Wantedfiles' );
37 $this->repoGroup = $repoGroup;
38 $this->setDatabaseProvider( $dbProvider );
39 $this->setLinkBatchFactory( $linkBatchFactory );
40 $this->migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get(
42 );
43 }
44
46 protected function getPageHeader() {
47 # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
48 # category would be used on main namespace pages, for those tricky wikipedia
49 # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
50 $catMessage = $this->msg( 'broken-file-category' )
51 ->page( PageReferenceValue::localReference( NS_MAIN, "Wanted Files" ) )
52 ->inContentLanguage();
53
54 if ( !$catMessage->isDisabled() ) {
55 $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
56 } else {
57 $category = false;
58 }
59
60 $noForeign = '';
61 if ( !$this->likelyToHaveFalsePositives() ) {
62 // Additional messages for grep:
63 // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
64 $noForeign = '-noforeign';
65 }
66
67 if ( $category ) {
68 return $this
69 ->msg( 'wantedfiletext-cat' . $noForeign )
70 ->params( $category->getFullText() )
71 ->parseAsBlock();
72 } else {
73 return $this
74 ->msg( 'wantedfiletext-nocat' . $noForeign )
75 ->parseAsBlock();
76 }
77 }
78
87 protected function likelyToHaveFalsePositives() {
88 return $this->repoGroup->hasForeignRepos();
89 }
90
101 protected function forceExistenceCheck() {
102 return true;
103 }
104
114 protected function existenceCheck( Title $title ) {
115 return (bool)$this->repoGroup->findFile( $title );
116 }
117
119 public function getQueryInfo() {
120 if ( $this->migrationStage & SCHEMA_COMPAT_READ_OLD ) {
121 $fileTable = 'image';
122 $nameField = 'img_name';
123 $extraConds1 = [];
124 $extraConds2 = [];
125 } else {
126 $fileTable = 'file';
127 $nameField = 'file_name';
128 $extraConds1 = [ 'img1.file_deleted' => 0 ];
129 $extraConds2 = [ 'img2.file_deleted' => 0 ];
130 }
131 return [
132 'tables' => [
133 'imagelinks',
134 'page',
135 'redirect',
136 'img1' => $fileTable,
137 'img2' => $fileTable,
138 ],
139 'fields' => [
140 'namespace' => NS_FILE,
141 'title' => 'il_to',
142 'value' => 'COUNT(*)'
143 ],
144 'conds' => [
145 'img1.' . $nameField => null,
146 // We also need to exclude file redirects
147 'img2.' . $nameField => null,
148 ],
149 'options' => [ 'GROUP BY' => 'il_to' ],
150 'join_conds' => [
151 'img1' => [ 'LEFT JOIN',
152 array_merge( [ 'il_to = img1.' . $nameField ], $extraConds1 ),
153 ],
154 'page' => [ 'LEFT JOIN', [
155 'il_to = page_title',
156 'page_namespace' => NS_FILE,
157 ] ],
158 'redirect' => [ 'LEFT JOIN', [
159 'page_id = rd_from',
160 'rd_namespace' => NS_FILE,
161 'rd_interwiki' => ''
162 ] ],
163 'img2' => [ 'LEFT JOIN',
164 array_merge( [ 'rd_title = img2.' . $nameField ], $extraConds2 ),
165 ]
166 ]
167 ];
168 }
169
171 protected function getGroupName() {
172 return 'maintenance';
173 }
174}
175
180class_alias( SpecialWantedFiles::class, 'WantedFilesPage' );
const NS_FILE
Definition Defines.php:57
const NS_MAIN
Definition Defines.php:51
const SCHEMA_COMPAT_READ_OLD
Definition Defines.php:294
const NS_CATEGORY
Definition Defines.php:65
Prioritized list of file repositories.
Definition RepoGroup.php:29
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.
Immutable value object representing a page reference.
setDatabaseProvider(IConnectionProvider $databaseProvider)
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Base class for a "wanted" query page like WantedPages, WantedTemplates, etc.
List of the most linked non-existent files.
getPageHeader()
The content returned by this function will be output before any result.to override string
__construct(RepoGroup $repoGroup, IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory)
existenceCheck(Title $title)
Does the file exist?
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
forceExistenceCheck()
KLUGE: The results may contain false positives for files that exist e.g.
likelyToHaveFalsePositives()
Whether foreign repos are likely to cause false positives.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Represents a title within MediaWiki.
Definition Title.php:69
Provide primary and replica IDatabase connections.