MediaWiki
REL1_40
SpecialFilepath.php
Go to the documentation of this file.
1
<?php
24
use
MediaWiki\Title\Title
;
25
31
class
SpecialFilepath
extends
RedirectSpecialPage
{
32
34
private
$searchEngineFactory;
35
39
public
function
__construct
(
40
SearchEngineFactory
$searchEngineFactory
41
) {
42
parent::__construct(
'Filepath'
);
43
$this->mAllowedRedirectParams = [
'width'
,
'height'
];
44
$this->searchEngineFactory = $searchEngineFactory;
45
}
46
53
public
function
getRedirect
( $par ) {
54
$file
= $par ?: $this->
getRequest
()->getText(
'file'
);
55
56
$redirect =
null
;
57
if
(
$file
) {
58
$redirect =
SpecialPage::getSafeTitleFor
(
'Redirect'
,
"file/$file"
);
59
}
60
if
( $redirect ===
null
) {
61
// The user input is empty or an invalid title,
62
// redirect to form of Special:Redirect with the invalid value prefilled
63
$this->mAddedRedirectParams[
'wpvalue'
] =
$file
;
64
$redirect =
SpecialPage::getSafeTitleFor
(
'Redirect'
,
'file'
);
65
}
66
// @phan-suppress-next-line PhanTypeMismatchReturnNullable Known to be valid
67
return
$redirect;
68
}
69
78
public
function
prefixSearchSubpages
( $search, $limit, $offset ) {
79
$title
= Title::newFromText( $search,
NS_FILE
);
80
if
( !
$title
||
$title
->getNamespace() !==
NS_FILE
) {
81
// No prefix suggestion outside of file namespace
82
return
[];
83
}
84
$searchEngine = $this->searchEngineFactory->create();
85
$searchEngine->setLimitOffset( $limit, $offset );
86
// Autocomplete subpage the same as a normal search, but just for files
87
$searchEngine->setNamespaces( [
NS_FILE
] );
88
$result = $searchEngine->defaultPrefixSearch( $search );
89
90
return
array_map(
static
function
(
Title
$t
) {
91
// Remove namespace in search suggestion
92
return
$t
->getText();
93
}, $result );
94
}
95
96
protected
function
getGroupName
() {
97
return
'media'
;
98
}
99
}
NS_FILE
const NS_FILE
Definition
Defines.php:70
MediaWiki\Title\Title
Represents a title within MediaWiki.
Definition
Title.php:82
RedirectSpecialPage
Shortcut to construct a special page alias.
Definition
RedirectSpecialPage.php:33
SearchEngineFactory
Factory class for SearchEngine.
Definition
SearchEngineFactory.php:12
SpecialFilepath
A special page that redirects to the URL of a given file.
Definition
SpecialFilepath.php:31
SpecialFilepath\__construct
__construct(SearchEngineFactory $searchEngineFactory)
Definition
SpecialFilepath.php:39
SpecialFilepath\prefixSearchSubpages
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Definition
SpecialFilepath.php:78
SpecialFilepath\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition
SpecialFilepath.php:96
SpecialFilepath\getRedirect
getRedirect( $par)
Implement by redirecting through Special:Redirect/file.
Definition
SpecialFilepath.php:53
SpecialPage\getSafeTitleFor
static getSafeTitleFor( $name, $subpage=false)
Get a localised Title object for a page name with a possibly unvalidated subpage.
Definition
SpecialPage.php:161
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition
SpecialPage.php:852
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition
router.php:42
$t
$t
Definition
testCompression.php:75
$title
$title
Definition
testCompression.php:39
includes
specials
SpecialFilepath.php
Generated on Thu Jun 27 2024 14:04:19 for MediaWiki by
1.10.0