MediaWiki master
SpecialRedirectWithAction.php
Go to the documentation of this file.
1<?php
2
9
13
22 protected $action;
23
25 protected $msgPrefix;
26
28 private $searchEngineFactory;
29
39 public function __construct(
40 $name,
41 $action,
43 SearchEngineFactory $searchEngineFactory
44 ) {
45 parent::__construct( $name );
46 $this->action = $action;
47 $this->msgPrefix = $msgPrefix;
48 $this->searchEngineFactory = $searchEngineFactory;
49 }
50
54 public function getRedirect( $subpage ) {
55 if ( $subpage === null || $subpage === '' ) {
56 return false;
57 }
58 $this->mAddedRedirectParams['title'] = $subpage;
59 $this->mAddedRedirectParams['action'] = $this->action;
60 return true;
61 }
62
66 protected function showNoRedirectPage() {
67 $this->setHeaders();
68 $this->outputHeader();
69 $this->showForm();
70 }
71
72 private function showForm() {
73 // Dynamic messages used:
74 // 'special' . $this->msgPrefix . '-page'
75 // 'special' . $this->msgPrefix . '-submit'
76 // Each special page that extends this should include those as comments for grep
77 $form = HTMLForm::factory( 'ooui', [
78 'page' => [
79 'type' => 'title',
80 'name' => 'page',
81 'label-message' => 'special' . $this->msgPrefix . '-page',
82 'required' => true,
83 'creatable' => true,
84 ],
85 ], $this->getContext(), $this->msgPrefix );
86 $form->setSubmitTextMsg( 'special' . $this->msgPrefix . '-submit' );
87 $form->setSubmitCallback( $this->onFormSubmit( ... ) );
88 $form->show();
89 }
90
96 public function onFormSubmit( $formData ) {
97 $title = $formData['page'];
98 $page = Title::newFromText( $title );
99 $query = [ 'action' => $this->action ];
100 $url = $page->getFullUrlForRedirect( $query );
101 $this->getOutput()->redirect( $url );
102 }
103
108 public function isListed() {
109 return true;
110 }
111
120 public function prefixSearchSubpages( $search, $limit, $offset ) {
121 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
122 }
123
128 protected function getGroupName() {
129 return 'redirects';
130 }
131}
132
134class_alias( SpecialRedirectWithAction::class, 'SpecialRedirectWithAction' );
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:195
Factory class for SearchEngine.
Shortcut to construct a special page alias.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getContext()
Gets the context this SpecialPage is executed in.
getOutput()
Get the OutputPage being used for this instance.
prefixSearchString( $search, $limit, $offset, ?SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
Abstract to simplify creation of redirect special pages.
__construct( $name, $action, $msgPrefix, SearchEngineFactory $searchEngineFactory)
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.
Represents a title within MediaWiki.
Definition Title.php:69