MediaWiki 1.40.4
SpecialWantedFiles.php
Go to the documentation of this file.
1<?php
27namespace MediaWiki\Specials;
28
32use RepoGroup;
35
42
44 private $repoGroup;
45
51 public function __construct(
52 RepoGroup $repoGroup,
53 ILoadBalancer $loadBalancer,
54 LinkBatchFactory $linkBatchFactory
55 ) {
56 parent::__construct( 'Wantedfiles' );
57 $this->repoGroup = $repoGroup;
58 $this->setDBLoadBalancer( $loadBalancer );
59 $this->setLinkBatchFactory( $linkBatchFactory );
60 }
61
62 protected function getPageHeader() {
63 # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
64 # category would be used on main namespace pages, for those tricky wikipedia
65 # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
66 $catMessage = $this->msg( 'broken-file-category' )
67 ->page( PageReferenceValue::localReference( NS_MAIN, "Wanted Files" ) )
68 ->inContentLanguage();
69
70 if ( !$catMessage->isDisabled() ) {
71 $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
72 } else {
73 $category = false;
74 }
75
76 $noForeign = '';
77 if ( !$this->likelyToHaveFalsePositives() ) {
78 // Additional messages for grep:
79 // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
80 $noForeign = '-noforeign';
81 }
82
83 if ( $category ) {
84 return $this
85 ->msg( 'wantedfiletext-cat' . $noForeign )
86 ->params( $category->getFullText() )
87 ->parseAsBlock();
88 } else {
89 return $this
90 ->msg( 'wantedfiletext-nocat' . $noForeign )
91 ->parseAsBlock();
92 }
93 }
94
103 protected function likelyToHaveFalsePositives() {
104 return $this->repoGroup->hasForeignRepos();
105 }
106
117 protected function forceExistenceCheck() {
118 return true;
119 }
120
130 protected function existenceCheck( Title $title ) {
131 return (bool)$this->repoGroup->findFile( $title );
132 }
133
134 public function getQueryInfo() {
135 return [
136 'tables' => [
137 'imagelinks',
138 'page',
139 'redirect',
140 'img1' => 'image',
141 'img2' => 'image',
142 ],
143 'fields' => [
144 'namespace' => NS_FILE,
145 'title' => 'il_to',
146 'value' => 'COUNT(*)'
147 ],
148 'conds' => [
149 'img1.img_name' => null,
150 // We also need to exclude file redirects
151 'img2.img_name' => null,
152 ],
153 'options' => [ 'GROUP BY' => 'il_to' ],
154 'join_conds' => [
155 'img1' => [ 'LEFT JOIN',
156 'il_to = img1.img_name'
157 ],
158 'page' => [ 'LEFT JOIN', [
159 'il_to = page_title',
160 'page_namespace' => NS_FILE,
161 ] ],
162 'redirect' => [ 'LEFT JOIN', [
163 'page_id = rd_from',
164 'rd_namespace' => NS_FILE,
165 'rd_interwiki' => ''
166 ] ],
167 'img2' => [ 'LEFT JOIN',
168 'rd_title = img2.img_name'
169 ]
170 ]
171 ];
172 }
173
174 protected function getGroupName() {
175 return 'maintenance';
176 }
177}
178
183class_alias( SpecialWantedFiles::class, 'WantedFilesPage' );
const NS_FILE
Definition Defines.php:70
const NS_MAIN
Definition Defines.php:64
const NS_CATEGORY
Definition Defines.php:78
Immutable value object representing a page reference.
Querypage that lists the most wanted files.
getPageHeader()
The content returned by this function will be output before any result.
__construct(RepoGroup $repoGroup, ILoadBalancer $loadBalancer, 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...
makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Represents a title within MediaWiki.
Definition Title.php:82
setDBLoadBalancer(ILoadBalancer $loadBalancer)
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Prioritized list of file repositories.
Definition RepoGroup.php:30
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Class definition for a wanted query page like WantedPages, WantedTemplates, etc.
This class is a delegate to ILBFactory for a given database cluster.