MediaWiki
master
Toggle main menu visibility
SpecialWantedFiles.php
Go to the documentation of this file.
1
<?php
8
9
namespace
MediaWiki\Specials;
10
11
use MediaWiki\FileRepo\RepoGroup;
12
use MediaWiki\Page\LinkBatchFactory;
13
use MediaWiki\Page\PageReferenceValue;
14
use MediaWiki\SpecialPage\WantedQueryPage;
15
use MediaWiki\Title\Title;
16
use Wikimedia\Rdbms\IConnectionProvider;
17
24
class
SpecialWantedFiles
extends
WantedQueryPage
{
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
154
class_alias( SpecialWantedFiles::class,
'WantedFilesPage'
);
155
// @codeCoverageIgnoreEnd
NS_FILE
const NS_FILE
Definition
Defines.php:57
NS_MAIN
const NS_MAIN
Definition
Defines.php:51
NS_CATEGORY
const NS_CATEGORY
Definition
Defines.php:65
MediaWiki\FileRepo\RepoGroup
Prioritized list of file repositories.
Definition
RepoGroup.php:30
MediaWiki\Page\LinkBatchFactory
Factory for LinkBatch objects to batch query page metadata.
Definition
LinkBatchFactory.php:29
MediaWiki\SpecialPage\QueryPage\setDatabaseProvider
setDatabaseProvider(IConnectionProvider $databaseProvider)
Definition
QueryPage.php:1049
MediaWiki\SpecialPage\QueryPage\setLinkBatchFactory
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition
QueryPage.php:177
MediaWiki\SpecialPage\SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition
SpecialPage.php:971
MediaWiki\SpecialPage\WantedQueryPage
Base class for a "wanted" query page like WantedPages, WantedTemplates, etc.
Definition
WantedQueryPage.php:21
MediaWiki\Specials\SpecialWantedFiles
List of the most linked non-existent files.
Definition
SpecialWantedFiles.php:24
MediaWiki\Specials\SpecialWantedFiles\getPageHeader
getPageHeader()
The content returned by this function will be output before any result.to override string
Definition
SpecialWantedFiles.php:37
MediaWiki\Specials\SpecialWantedFiles\__construct
__construct(private readonly RepoGroup $repoGroup, IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory,)
Definition
SpecialWantedFiles.php:26
MediaWiki\Specials\SpecialWantedFiles\existenceCheck
existenceCheck(Title $title)
Does the file exist?
Definition
SpecialWantedFiles.php:104
MediaWiki\Specials\SpecialWantedFiles\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition
SpecialWantedFiles.php:144
MediaWiki\Specials\SpecialWantedFiles\forceExistenceCheck
forceExistenceCheck()
KLUGE: The results may contain false positives for files that exist e.g.
Definition
SpecialWantedFiles.php:91
MediaWiki\Specials\SpecialWantedFiles\likelyToHaveFalsePositives
likelyToHaveFalsePositives()
Whether foreign repos are likely to cause false positives.
Definition
SpecialWantedFiles.php:77
MediaWiki\Specials\SpecialWantedFiles\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition
SpecialWantedFiles.php:109
MediaWiki\Title\Title
Represents a title within MediaWiki.
Definition
Title.php:69
Wikimedia\Rdbms\IConnectionProvider
Provide primary and replica IDatabase connections.
Definition
IConnectionProvider.php:21
includes
Specials
SpecialWantedFiles.php
Generated on
for MediaWiki by
1.18.0