MediaWiki master
SpecialFilepath.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
13
23
24 public function __construct(
25 private readonly SearchEngineFactory $searchEngineFactory,
26 ) {
27 parent::__construct( 'Filepath' );
28 $this->mAllowedRedirectParams = [ 'width', 'height' ];
29 }
30
37 public function getRedirect( $par ) {
38 $file = $par ?: $this->getRequest()->getText( 'file' );
39
40 $redirect = null;
41 if ( $file ) {
42 $redirect = SpecialPage::getSafeTitleFor( 'Redirect', "file/$file" );
43 }
44 if ( $redirect === null ) {
45 // The user input is empty or an invalid title,
46 // redirect to form of Special:Redirect with the invalid value prefilled
47 $this->mAddedRedirectParams['wpvalue'] = $file;
48 $redirect = SpecialPage::getSafeTitleFor( 'Redirect', 'file' );
49 }
50 // @phan-suppress-next-line PhanTypeMismatchReturnNullable Known to be valid
51 return $redirect;
52 }
53
62 public function prefixSearchSubpages( $search, $limit, $offset ) {
63 $title = Title::newFromText( $search, NS_FILE );
64 if ( !$title || $title->getNamespace() !== NS_FILE ) {
65 // No prefix suggestion outside of file namespace
66 return [];
67 }
68 $searchEngine = $this->searchEngineFactory->create();
69 $searchEngine->setLimitOffset( $limit, $offset );
70 // Autocomplete subpage the same as a normal search, but just for files
71 $searchEngine->setNamespaces( [ NS_FILE ] );
72 $result = $searchEngine->defaultPrefixSearch( $search );
73
74 return array_map( static function ( Title $t ) {
75 // Remove namespace in search suggestion
76 return $t->getText();
77 }, $result );
78 }
79
81 protected function getGroupName() {
82 return 'media';
83 }
84}
85
86// @codeCoverageIgnoreStart
88class_alias( SpecialFilepath::class, 'SpecialFilepath' );
89// @codeCoverageIgnoreEnd
const NS_FILE
Definition Defines.php:57
Factory class for SearchEngine.
Base class for redirect shortcuts.
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.
Redirect to the thumbnail URL of a given filename.
__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