MediaWiki master
SpecialRedirectWithAction.php
Go to the documentation of this file.
1<?php
2
4
11
38 protected $action;
39
41 protected $msgPrefix;
42
44 private $searchEngineFactory;
45
55 public function __construct(
56 $name,
57 $action,
59 SearchEngineFactory $searchEngineFactory = null
60 ) {
61 parent::__construct( $name );
62 $this->action = $action;
63 $this->msgPrefix = $msgPrefix;
64 if ( !$searchEngineFactory ) {
65 // Fallback to global state if the new parameter was not provided
66 wfDeprecated( __METHOD__ . ' without providing SearchEngineFactory', '1.39' );
67 $searchEngineFactory = MediaWikiServices::getInstance()->getSearchEngineFactory();
68 }
69 $this->searchEngineFactory = $searchEngineFactory;
70 }
71
75 public function getRedirect( $subpage ) {
76 if ( $subpage === null || $subpage === '' ) {
77 return false;
78 }
79 $this->mAddedRedirectParams['title'] = $subpage;
80 $this->mAddedRedirectParams['action'] = $this->action;
81 return true;
82 }
83
87 protected function showNoRedirectPage() {
88 $this->setHeaders();
89 $this->outputHeader();
90 $this->showForm();
91 }
92
93 private function showForm() {
94 // Dynamic messages used:
95 // 'special' . $this->msgPrefix . '-page'
96 // 'special' . $this->msgPrefix . '-submit'
97 // Each special page that extends this should include those as comments for grep
98 $form = HTMLForm::factory( 'ooui', [
99 'page' => [
100 'type' => 'text',
101 'name' => 'page',
102 'label-message' => 'special' . $this->msgPrefix . '-page',
103 'required' => true,
104 ],
105 ], $this->getContext(), $this->msgPrefix );
106 $form->setSubmitTextMsg( 'special' . $this->msgPrefix . '-submit' );
107 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
108 $form->show();
109 }
110
118 public function onFormSubmit( $formData ) {
119 $title = $formData['page'];
120 try {
121 $page = Title::newFromTextThrow( $title );
122 } catch ( MalformedTitleException $e ) {
123 return Status::newFatal( $e->getMessageObject() );
124 }
125 $query = [ 'action' => $this->action ];
126 $url = $page->getFullUrlForRedirect( $query );
127 $this->getOutput()->redirect( $url );
128 }
129
134 public function isListed() {
135 return true;
136 }
137
146 public function prefixSearchSubpages( $search, $limit, $offset ) {
147 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
148 }
149
154 protected function getGroupName() {
155 return 'redirects';
156 }
157}
158
160class_alias( SpecialRedirectWithAction::class, 'SpecialRedirectWithAction' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:206
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Shortcut to construct a special page alias.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
prefixSearchString( $search, $limit, $offset, SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
getContext()
Gets the context this SpecialPage is executed in.
getOutput()
Get the OutputPage being used for this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.False otherwise....
__construct( $name, $action, $msgPrefix, SearchEngineFactory $searchEngineFactory=null)
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Represents a title within MediaWiki.
Definition Title.php:78
Factory class for SearchEngine.