MediaWiki
REL1_39
SpecialFilepath.php
Go to the documentation of this file.
1
<?php
29
class
SpecialFilepath
extends
RedirectSpecialPage
{
30
32
private
$searchEngineFactory;
33
37
public
function
__construct
(
38
SearchEngineFactory
$searchEngineFactory
39
) {
40
parent::__construct(
'Filepath'
);
41
$this->mAllowedRedirectParams = [
'width'
,
'height'
];
42
$this->searchEngineFactory = $searchEngineFactory;
43
}
44
51
public
function
getRedirect
( $par ) {
52
$file
= $par ?: $this->
getRequest
()->getText(
'file'
);
53
54
$redirect =
null
;
55
if
(
$file
) {
56
$redirect =
SpecialPage::getSafeTitleFor
(
'Redirect'
,
"file/$file"
);
57
}
58
if
( $redirect ===
null
) {
59
// The user input is empty or an invalid title,
60
// redirect to form of Special:Redirect with the invalid value prefilled
61
$this->mAddedRedirectParams[
'wpvalue'
] =
$file
;
62
$redirect =
SpecialPage::getSafeTitleFor
(
'Redirect'
,
'file'
);
63
}
64
// @phan-suppress-next-line PhanTypeMismatchReturnNullable Known to be valid
65
return
$redirect;
66
}
67
76
public
function
prefixSearchSubpages
( $search, $limit, $offset ) {
77
$title
= Title::newFromText( $search,
NS_FILE
);
78
if
( !
$title
||
$title
->getNamespace() !==
NS_FILE
) {
79
// No prefix suggestion outside of file namespace
80
return
[];
81
}
82
$searchEngine = $this->searchEngineFactory->create();
83
$searchEngine->setLimitOffset( $limit, $offset );
84
// Autocomplete subpage the same as a normal search, but just for files
85
$searchEngine->setNamespaces( [
NS_FILE
] );
86
$result = $searchEngine->defaultPrefixSearch( $search );
87
88
return
array_map(
static
function
(
Title
$t
) {
89
// Remove namespace in search suggestion
90
return
$t
->getText();
91
}, $result );
92
}
93
94
protected
function
getGroupName
() {
95
return
'media'
;
96
}
97
}
NS_FILE
const NS_FILE
Definition
Defines.php:70
RedirectSpecialPage
Shortcut to construct a special page alias.
Definition
RedirectSpecialPage.php:31
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:29
SpecialFilepath\__construct
__construct(SearchEngineFactory $searchEngineFactory)
Definition
SpecialFilepath.php:37
SpecialFilepath\prefixSearchSubpages
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Definition
SpecialFilepath.php:76
SpecialFilepath\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition
SpecialFilepath.php:94
SpecialFilepath\getRedirect
getRedirect( $par)
Implement by redirecting through Special:Redirect/file.
Definition
SpecialFilepath.php:51
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
Title
Represents a title within MediaWiki.
Definition
Title.php:49
$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:74
$title
$title
Definition
testCompression.php:38
includes
specials
SpecialFilepath.php
Generated on Mon Dec 23 2024 06:24:50 for MediaWiki by
1.10.0