MediaWiki REL1_39
SpecialRedirectWithAction.php
Go to the documentation of this file.
1<?php
2
4
31 protected $action;
32
34 protected $msgPrefix;
35
37 private $searchEngineFactory;
38
48 public function __construct(
49 $name,
50 $action,
52 SearchEngineFactory $searchEngineFactory = null
53 ) {
54 parent::__construct( $name );
55 $this->action = $action;
56 $this->msgPrefix = $msgPrefix;
57 if ( !$searchEngineFactory ) {
58 // Fallback to global state if the new parameter was not provided
59 wfDeprecated( __METHOD__ . ' without providing SearchEngineFactory', '1.39' );
60 $searchEngineFactory = MediaWikiServices::getInstance()->getSearchEngineFactory();
61 }
62 $this->searchEngineFactory = $searchEngineFactory;
63 }
64
68 public function getRedirect( $subpage ) {
69 if ( $subpage === null || $subpage === '' ) {
70 return false;
71 }
72 $this->mAddedRedirectParams['title'] = $subpage;
73 $this->mAddedRedirectParams['action'] = $this->action;
74 return true;
75 }
76
80 protected function showNoRedirectPage() {
81 $this->setHeaders();
82 $this->outputHeader();
83 $this->showForm();
84 }
85
86 private function showForm() {
87 // Dynamic messages used:
88 // 'special' . $this->msgPrefix . '-page'
89 // 'special' . $this->msgPrefix . '-submit'
90 // Each special page that extends this should include those as comments for grep
91 $form = HTMLForm::factory( 'ooui', [
92 'page' => [
93 'type' => 'text',
94 'name' => 'page',
95 'label-message' => 'special' . $this->msgPrefix . '-page',
96 'required' => true,
97 ],
98 ], $this->getContext(), $this->msgPrefix );
99 $form->setSubmitTextMsg( 'special' . $this->msgPrefix . '-submit' );
100 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
101 $form->show();
102 }
103
111 public function onFormSubmit( $formData ) {
112 $title = $formData['page'];
113 try {
114 $page = Title::newFromTextThrow( $title );
115 } catch ( MalformedTitleException $e ) {
116 return Status::newFatal( $e->getMessageObject() );
117 }
118 $query = [ 'action' => $this->action ];
119 $url = $page->getFullUrlForRedirect( $query );
120 $this->getOutput()->redirect( $url );
121 }
122
127 public function isListed() {
128 return true;
129 }
130
139 public function prefixSearchSubpages( $search, $limit, $offset ) {
140 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
141 }
142
147 protected function getGroupName() {
148 return 'redirects';
149 }
150}
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Service locator for MediaWiki core services.
Shortcut to construct a special page alias.
Factory class for SearchEngine.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
prefixSearchString( $search, $limit, $offset, SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
__construct( $name, $action, $msgPrefix, SearchEngineFactory $searchEngineFactory=null)
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.False otherwise....
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.