MediaWiki master
SpecialWantedFiles.php
Go to the documentation of this file.
1<?php
8
9namespace MediaWiki\Specials;
10
11use MediaWiki\FileRepo\RepoGroup;
12use MediaWiki\Page\LinkBatchFactory;
13use MediaWiki\Page\PageReferenceValue;
14use MediaWiki\SpecialPage\WantedQueryPage;
15use MediaWiki\Title\Title;
16use Wikimedia\Rdbms\IConnectionProvider;
17
25
26 public function __construct(
27 private readonly RepoGroup $repoGroup,
28 IConnectionProvider $dbProvider,
29 LinkBatchFactory $linkBatchFactory,
30 ) {
31 parent::__construct( 'Wantedfiles' );
32 $this->setDatabaseProvider( $dbProvider );
33 $this->setLinkBatchFactory( $linkBatchFactory );
34 }
35
37 protected function getPageHeader() {
38 # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
39 # category would be used on main namespace pages, for those tricky wikipedia
40 # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
41 $catMessage = $this->msg( 'broken-file-category' )
42 ->page( PageReferenceValue::localReference( NS_MAIN, "Wanted Files" ) )
43 ->inContentLanguage();
44
45 if ( !$catMessage->isDisabled() ) {
46 $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
47 } else {
48 $category = false;
49 }
50
51 $noForeign = '';
52 if ( !$this->likelyToHaveFalsePositives() ) {
53 // Additional messages for grep:
54 // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
55 $noForeign = '-noforeign';
56 }
57
58 if ( $category ) {
59 return $this
60 ->msg( 'wantedfiletext-cat' . $noForeign, $category->getFullText() )
61 ->parseAsBlock();
62 } else {
63 return $this
64 ->msg( 'wantedfiletext-nocat' . $noForeign )
65 ->parseAsBlock();
66 }
67 }
68
77 protected function likelyToHaveFalsePositives() {
78 return $this->repoGroup->hasForeignRepos();
79 }
80
91 protected function forceExistenceCheck() {
92 return true;
93 }
94
104 protected function existenceCheck( Title $title ) {
105 return (bool)$this->repoGroup->findFile( $title );
106 }
107
109 public function getQueryInfo() {
110 return [
111 'tables' => [
112 'imagelinks',
113 'linktarget',
114 'page',
115 'redirect',
116 ],
117 'fields' => [
118 'namespace' => NS_FILE,
119 'title' => 'lt_title',
120 'value' => 'COUNT(*)'
121 ],
122 'conds' => [
123 'page_title' => null,
124 // We also need to exclude file redirects
125 'rd_from' => null,
126 ],
127 'options' => [ 'GROUP BY' => 'lt_title' ],
128 'join_conds' => [
129 'linktarget' => [ 'JOIN', [ 'il_target_id = lt_id' ] ],
130 'page' => [ 'LEFT JOIN', [
131 'lt_title = page_title',
132 'page_namespace' => NS_FILE,
133 ] ],
134 'redirect' => [ 'LEFT JOIN', [
135 'page_id = rd_from',
136 'rd_namespace' => NS_FILE,
137 'rd_interwiki' => ''
138 ] ],
139 ]
140 ];
141 }
142
144 protected function getGroupName() {
145 return 'maintenance';
146 }
147}
148
149// @codeCoverageIgnoreStart
154class_alias( SpecialWantedFiles::class, 'WantedFilesPage' );
155// @codeCoverageIgnoreEnd
const NS_FILE
Definition Defines.php:57
const NS_MAIN
Definition Defines.php:51
const NS_CATEGORY
Definition Defines.php:65
Prioritized list of file repositories.
Definition RepoGroup.php:30
Factory for LinkBatch objects to batch query page metadata.
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.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.