MediaWiki master
SpecialFilepath.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
13
20
21 public function __construct(
22 private readonly SearchEngineFactory $searchEngineFactory,
23 ) {
24 parent::__construct( 'Filepath' );
25 $this->mAllowedRedirectParams = [ 'width', 'height' ];
26 }
27
34 public function getRedirect( $par ) {
35 $file = $par ?: $this->getRequest()->getText( 'file' );
36
37 $redirect = null;
38 if ( $file ) {
39 $redirect = SpecialPage::getSafeTitleFor( 'Redirect', "file/$file" );
40 }
41 if ( $redirect === null ) {
42 // The user input is empty or an invalid title,
43 // redirect to form of Special:Redirect with the invalid value prefilled
44 $this->mAddedRedirectParams['wpvalue'] = $file;
45 $redirect = SpecialPage::getSafeTitleFor( 'Redirect', 'file' );
46 }
47 // @phan-suppress-next-line PhanTypeMismatchReturnNullable Known to be valid
48 return $redirect;
49 }
50
59 public function prefixSearchSubpages( $search, $limit, $offset ) {
60 $title = Title::newFromText( $search, NS_FILE );
61 if ( !$title || $title->getNamespace() !== NS_FILE ) {
62 // No prefix suggestion outside of file namespace
63 return [];
64 }
65 $searchEngine = $this->searchEngineFactory->create();
66 $searchEngine->setLimitOffset( $limit, $offset );
67 // Autocomplete subpage the same as a normal search, but just for files
68 $searchEngine->setNamespaces( [ NS_FILE ] );
69 $result = $searchEngine->defaultPrefixSearch( $search );
70
71 return array_map( static function ( Title $t ) {
72 // Remove namespace in search suggestion
73 return $t->getText();
74 }, $result );
75 }
76
78 protected function getGroupName() {
79 return 'media';
80 }
81}
82
84class_alias( SpecialFilepath::class, 'SpecialFilepath' );
const NS_FILE
Definition Defines.php:57
Factory class for SearchEngine.
Shortcut to construct a special page alias.
Parent class for all special pages.
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.
Redirects to the URL of a thumbnail for the given file.
__construct(private readonly SearchEngineFactory $searchEngineFactory,)
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.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Represents a title within MediaWiki.
Definition Title.php:69