MediaWiki master
SpecialWantedFiles.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Specials;
24
33
41
42 private RepoGroup $repoGroup;
43 private int $migrationStage;
44
45 public function __construct(
46 RepoGroup $repoGroup,
47 IConnectionProvider $dbProvider,
48 LinkBatchFactory $linkBatchFactory
49 ) {
50 parent::__construct( 'Wantedfiles' );
51 $this->repoGroup = $repoGroup;
52 $this->setDatabaseProvider( $dbProvider );
53 $this->setLinkBatchFactory( $linkBatchFactory );
54 $this->migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get(
56 );
57 }
58
59 protected function getPageHeader() {
60 # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
61 # category would be used on main namespace pages, for those tricky wikipedia
62 # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
63 $catMessage = $this->msg( 'broken-file-category' )
64 ->page( PageReferenceValue::localReference( NS_MAIN, "Wanted Files" ) )
65 ->inContentLanguage();
66
67 if ( !$catMessage->isDisabled() ) {
68 $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
69 } else {
70 $category = false;
71 }
72
73 $noForeign = '';
74 if ( !$this->likelyToHaveFalsePositives() ) {
75 // Additional messages for grep:
76 // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
77 $noForeign = '-noforeign';
78 }
79
80 if ( $category ) {
81 return $this
82 ->msg( 'wantedfiletext-cat' . $noForeign )
83 ->params( $category->getFullText() )
84 ->parseAsBlock();
85 } else {
86 return $this
87 ->msg( 'wantedfiletext-nocat' . $noForeign )
88 ->parseAsBlock();
89 }
90 }
91
100 protected function likelyToHaveFalsePositives() {
101 return $this->repoGroup->hasForeignRepos();
102 }
103
114 protected function forceExistenceCheck() {
115 return true;
116 }
117
127 protected function existenceCheck( Title $title ) {
128 return (bool)$this->repoGroup->findFile( $title );
129 }
130
131 public function getQueryInfo() {
132 if ( $this->migrationStage & SCHEMA_COMPAT_READ_OLD ) {
133 $fileTable = 'image';
134 $nameField = 'img_name';
135 $extraConds1 = [];
136 $extraConds2 = [];
137 } else {
138 $fileTable = 'file';
139 $nameField = 'file_name';
140 $extraConds1 = [ 'img1.file_deleted' => 0 ];
141 $extraConds2 = [ 'img2.file_deleted' => 0 ];
142 }
143 return [
144 'tables' => [
145 'imagelinks',
146 'page',
147 'redirect',
148 'img1' => $fileTable,
149 'img2' => $fileTable,
150 ],
151 'fields' => [
152 'namespace' => NS_FILE,
153 'title' => 'il_to',
154 'value' => 'COUNT(*)'
155 ],
156 'conds' => [
157 'img1.' . $nameField => null,
158 // We also need to exclude file redirects
159 'img2.' . $nameField => null,
160 ],
161 'options' => [ 'GROUP BY' => 'il_to' ],
162 'join_conds' => [
163 'img1' => [ 'LEFT JOIN',
164 array_merge( [ 'il_to = img1.' . $nameField ], $extraConds1 ),
165 ],
166 'page' => [ 'LEFT JOIN', [
167 'il_to = page_title',
168 'page_namespace' => NS_FILE,
169 ] ],
170 'redirect' => [ 'LEFT JOIN', [
171 'page_id = rd_from',
172 'rd_namespace' => NS_FILE,
173 'rd_interwiki' => ''
174 ] ],
175 'img2' => [ 'LEFT JOIN',
176 array_merge( [ 'rd_title = img2.' . $nameField ], $extraConds2 ),
177 ]
178 ]
179 ];
180 }
181
182 protected function getGroupName() {
183 return 'maintenance';
184 }
185}
186
191class_alias( SpecialWantedFiles::class, 'WantedFilesPage' );
const NS_FILE
Definition Defines.php:71
const NS_MAIN
Definition Defines.php:65
const SCHEMA_COMPAT_READ_OLD
Definition Defines.php:304
const NS_CATEGORY
Definition Defines.php:79
Prioritized list of file repositories.
Definition RepoGroup.php:38
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.
__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:78
Provide primary and replica IDatabase connections.