MediaWiki REL1_39
SpecialWantedfiles.php
Go to the documentation of this file.
1<?php
31
38
40 private $repoGroup;
41
47 public function __construct(
48 $repoGroup,
49 ILoadBalancer $loadBalancer = null,
50 LinkBatchFactory $linkBatchFactory = null
51 ) {
52 parent::__construct( is_string( $repoGroup ) ? $repoGroup : 'Wantedfiles' );
53 // This class is extended and therefor fallback to global state - T265301
54 $services = MediaWikiServices::getInstance();
55 $this->repoGroup = $repoGroup instanceof RepoGroup
56 ? $repoGroup
57 : $services->getRepoGroup();
58 $this->setDBLoadBalancer( $loadBalancer ?? $services->getDBLoadBalancer() );
59 $this->setLinkBatchFactory( $linkBatchFactory ?? $services->getLinkBatchFactory() );
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}
const NS_FILE
Definition Defines.php:70
const NS_MAIN
Definition Defines.php:64
const NS_CATEGORY
Definition Defines.php:78
Service locator for MediaWiki core services.
Immutable value object representing a page reference.
setDBLoadBalancer(ILoadBalancer $loadBalancer)
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Prioritized list of file repositories.
Definition RepoGroup.php:29
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Represents a title within MediaWiki.
Definition Title.php:49
Querypage that lists the most wanted files.
__construct( $repoGroup, ILoadBalancer $loadBalancer=null, LinkBatchFactory $linkBatchFactory=null)
existenceCheck(Title $title)
Does the file exist?
getPageHeader()
The content returned by this function will be output before any result.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
likelyToHaveFalsePositives()
Whether foreign repos are likely to cause false positives.
forceExistenceCheck()
KLUGE: The results may contain false positives for files that exist e.g.
Class definition for a wanted query page like WantedPages, WantedTemplates, etc.
Create and track the database connections and transactions for a given database cluster.