MediaWiki master
SpecialWantedFiles.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Specials;
10
18
26 private readonly int $fileMigrationStage;
27
28 public function __construct(
29 private readonly RepoGroup $repoGroup,
30 IConnectionProvider $dbProvider,
31 LinkBatchFactory $linkBatchFactory,
32 ) {
33 parent::__construct( 'Wantedfiles' );
34 $this->setDatabaseProvider( $dbProvider );
35 $this->setLinkBatchFactory( $linkBatchFactory );
36 $this->fileMigrationStage = $this->getConfig()->get( MainConfigNames::FileSchemaMigrationStage );
37 }
38
40 protected function getPageHeader() {
41 # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
42 # category would be used on main namespace pages, for those tricky wikipedia
43 # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
44 $catMessage = $this->msg( 'broken-file-category' )
45 ->page( PageReferenceValue::localReference( NS_MAIN, "Wanted Files" ) )
46 ->inContentLanguage();
47
48 if ( !$catMessage->isDisabled() ) {
49 $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
50 } else {
51 $category = false;
52 }
53
54 $noForeign = '';
55 if ( !$this->likelyToHaveFalsePositives() ) {
56 // Additional messages for grep:
57 // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
58 $noForeign = '-noforeign';
59 }
60
61 if ( $category ) {
62 return $this
63 ->msg( 'wantedfiletext-cat' . $noForeign, $category->getFullText() )
64 ->parseAsBlock();
65 } else {
66 return $this
67 ->msg( 'wantedfiletext-nocat' . $noForeign )
68 ->parseAsBlock();
69 }
70 }
71
80 protected function likelyToHaveFalsePositives() {
81 return $this->repoGroup->hasForeignRepos();
82 }
83
94 protected function forceExistenceCheck() {
95 return true;
96 }
97
107 protected function existenceCheck( Title $title ) {
108 return (bool)$this->repoGroup->findFile( $title );
109 }
110
112 public function getQueryInfo() {
113 if ( $this->fileMigrationStage & SCHEMA_COMPAT_READ_OLD ) {
114 $fileTable = 'image';
115 $nameField = 'img_name';
116 $extraConds1 = [];
117 $extraConds2 = [];
118 } else {
119 $fileTable = 'file';
120 $nameField = 'file_name';
121 $extraConds1 = [ 'img1.file_deleted' => 0 ];
122 $extraConds2 = [ 'img2.file_deleted' => 0 ];
123 }
124
125 return [
126 'tables' => [
127 'imagelinks',
128 'linktarget',
129 'page',
130 'redirect',
131 'img1' => $fileTable,
132 'img2' => $fileTable,
133 ],
134 'fields' => [
135 'namespace' => NS_FILE,
136 'title' => 'lt_title',
137 'value' => 'COUNT(*)'
138 ],
139 'conds' => [
140 'img1.' . $nameField => null,
141 // We also need to exclude file redirects
142 'img2.' . $nameField => null,
143 ],
144 'options' => [ 'GROUP BY' => 'lt_title' ],
145 'join_conds' => [
146 'linktarget' => [ 'JOIN', [ 'il_target_id = lt_id' ] ],
147 'img1' => [ 'LEFT JOIN',
148 array_merge( [ 'lt_title = img1.' . $nameField, 'lt_namespace' => NS_FILE ], $extraConds1 ),
149 ],
150 'page' => [ 'LEFT JOIN', [
151 'lt_title = page_title',
152 'page_namespace' => NS_FILE,
153 ] ],
154 'redirect' => [ 'LEFT JOIN', [
155 'page_id = rd_from',
156 'rd_namespace' => NS_FILE,
157 'rd_interwiki' => ''
158 ] ],
159 'img2' => [ 'LEFT JOIN',
160 array_merge( [ 'rd_title = img2.' . $nameField ], $extraConds2 ),
161 ]
162 ]
163 ];
164 }
165
167 protected function getGroupName() {
168 return 'maintenance';
169 }
170}
171
176class_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:30
A class containing constants representing the names of configuration variables.
const FileSchemaMigrationStage
Name constant for the FileSchemaMigrationStage setting, for use with Config::get()
Factory for LinkBatch objects to batch query page metadata.
Immutable value object representing a page reference.
setDatabaseProvider(IConnectionProvider $databaseProvider)
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
getConfig()
Shortcut to get main config object.
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(private readonly 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.