MediaWiki master
SpecialWantedFiles.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Specials;
24
29use RepoGroup;
31
39
40 private RepoGroup $repoGroup;
41
47 public function __construct(
48 RepoGroup $repoGroup,
49 IConnectionProvider $dbProvider,
50 LinkBatchFactory $linkBatchFactory
51 ) {
52 parent::__construct( 'Wantedfiles' );
53 $this->repoGroup = $repoGroup;
54 $this->setDatabaseProvider( $dbProvider );
55 $this->setLinkBatchFactory( $linkBatchFactory );
56 }
57
58 protected function getPageHeader() {
59 # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
60 # category would be used on main namespace pages, for those tricky wikipedia
61 # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
62 $catMessage = $this->msg( 'broken-file-category' )
63 ->page( PageReferenceValue::localReference( NS_MAIN, "Wanted Files" ) )
64 ->inContentLanguage();
65
66 if ( !$catMessage->isDisabled() ) {
67 $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
68 } else {
69 $category = false;
70 }
71
72 $noForeign = '';
73 if ( !$this->likelyToHaveFalsePositives() ) {
74 // Additional messages for grep:
75 // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
76 $noForeign = '-noforeign';
77 }
78
79 if ( $category ) {
80 return $this
81 ->msg( 'wantedfiletext-cat' . $noForeign )
82 ->params( $category->getFullText() )
83 ->parseAsBlock();
84 } else {
85 return $this
86 ->msg( 'wantedfiletext-nocat' . $noForeign )
87 ->parseAsBlock();
88 }
89 }
90
99 protected function likelyToHaveFalsePositives() {
100 return $this->repoGroup->hasForeignRepos();
101 }
102
113 protected function forceExistenceCheck() {
114 return true;
115 }
116
126 protected function existenceCheck( Title $title ) {
127 return (bool)$this->repoGroup->findFile( $title );
128 }
129
130 public function getQueryInfo() {
131 return [
132 'tables' => [
133 'imagelinks',
134 'page',
135 'redirect',
136 'img1' => 'image',
137 'img2' => 'image',
138 ],
139 'fields' => [
140 'namespace' => NS_FILE,
141 'title' => 'il_to',
142 'value' => 'COUNT(*)'
143 ],
144 'conds' => [
145 'img1.img_name' => null,
146 // We also need to exclude file redirects
147 'img2.img_name' => null,
148 ],
149 'options' => [ 'GROUP BY' => 'il_to' ],
150 'join_conds' => [
151 'img1' => [ 'LEFT JOIN',
152 'il_to = img1.img_name'
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 'rd_title = img2.img_name'
165 ]
166 ]
167 ];
168 }
169
170 protected function getGroupName() {
171 return 'maintenance';
172 }
173}
174
179class_alias( SpecialWantedFiles::class, 'WantedFilesPage' );
const NS_FILE
Definition Defines.php:71
const NS_MAIN
Definition Defines.php:65
const NS_CATEGORY
Definition Defines.php:79
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
Prioritized list of file repositories.
Definition RepoGroup.php:30
Provide primary and replica IDatabase connections.