MediaWiki REL1_39
SpecialFilepath.php
Go to the documentation of this file.
1<?php
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}
const NS_FILE
Definition Defines.php:70
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.
Represents a title within MediaWiki.
Definition Title.php:49
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42