MediaWiki REL1_40
SpecialFilepath.php
Go to the documentation of this file.
1<?php
25
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}
const NS_FILE
Definition Defines.php:70
Represents a title within MediaWiki.
Definition Title.php:82
Shortcut to construct a special page alias.
Factory class for SearchEngine.
A special page that redirects to the URL of a given file.
__construct(SearchEngineFactory $searchEngineFactory)
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getRedirect( $par)
Implement by redirecting through Special:Redirect/file.
static getSafeTitleFor( $name, $subpage=false)
Get a localised Title object for a page name with a possibly unvalidated subpage.
getRequest()
Get the WebRequest being used for this instance.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42