MediaWiki 1.42.1
SpecialWantedFiles.php
Go to the documentation of this file.
1<?php
27namespace MediaWiki\Specials;
28
33use RepoGroup;
35
42
43 private RepoGroup $repoGroup;
44
50 public function __construct(
51 RepoGroup $repoGroup,
52 IConnectionProvider $dbProvider,
53 LinkBatchFactory $linkBatchFactory
54 ) {
55 parent::__construct( 'Wantedfiles' );
56 $this->repoGroup = $repoGroup;
57 $this->setDatabaseProvider( $dbProvider );
58 $this->setLinkBatchFactory( $linkBatchFactory );
59 }
60
61 protected function getPageHeader() {
62 # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
63 # category would be used on main namespace pages, for those tricky wikipedia
64 # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
65 $catMessage = $this->msg( 'broken-file-category' )
66 ->page( PageReferenceValue::localReference( NS_MAIN, "Wanted Files" ) )
67 ->inContentLanguage();
68
69 if ( !$catMessage->isDisabled() ) {
70 $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
71 } else {
72 $category = false;
73 }
74
75 $noForeign = '';
76 if ( !$this->likelyToHaveFalsePositives() ) {
77 // Additional messages for grep:
78 // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
79 $noForeign = '-noforeign';
80 }
81
82 if ( $category ) {
83 return $this
84 ->msg( 'wantedfiletext-cat' . $noForeign )
85 ->params( $category->getFullText() )
86 ->parseAsBlock();
87 } else {
88 return $this
89 ->msg( 'wantedfiletext-nocat' . $noForeign )
90 ->parseAsBlock();
91 }
92 }
93
102 protected function likelyToHaveFalsePositives() {
103 return $this->repoGroup->hasForeignRepos();
104 }
105
116 protected function forceExistenceCheck() {
117 return true;
118 }
119
129 protected function existenceCheck( Title $title ) {
130 return (bool)$this->repoGroup->findFile( $title );
131 }
132
133 public function getQueryInfo() {
134 return [
135 'tables' => [
136 'imagelinks',
137 'page',
138 'redirect',
139 'img1' => 'image',
140 'img2' => 'image',
141 ],
142 'fields' => [
143 'namespace' => NS_FILE,
144 'title' => 'il_to',
145 'value' => 'COUNT(*)'
146 ],
147 'conds' => [
148 'img1.img_name' => null,
149 // We also need to exclude file redirects
150 'img2.img_name' => null,
151 ],
152 'options' => [ 'GROUP BY' => 'il_to' ],
153 'join_conds' => [
154 'img1' => [ 'LEFT JOIN',
155 'il_to = img1.img_name'
156 ],
157 'page' => [ 'LEFT JOIN', [
158 'il_to = page_title',
159 'page_namespace' => NS_FILE,
160 ] ],
161 'redirect' => [ 'LEFT JOIN', [
162 'page_id = rd_from',
163 'rd_namespace' => NS_FILE,
164 'rd_interwiki' => ''
165 ] ],
166 'img2' => [ 'LEFT JOIN',
167 'rd_title = img2.img_name'
168 ]
169 ]
170 ];
171 }
172
173 protected function getGroupName() {
174 return 'maintenance';
175 }
176}
177
182class_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.
setDatabaseProvider(IConnectionProvider $databaseProvider)
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Class definition for a wanted query page like WantedPages, WantedTemplates, etc.
Querypage that lists the most wanted 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.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...