MediaWiki master
SpecialRedirectWithAction.php
Go to the documentation of this file.
1<?php
2
9
13
22 protected $action;
23
25 protected $msgPrefix;
26
36 public function __construct(
37 $name,
38 $action,
40 private readonly SearchEngineFactory $searchEngineFactory,
41 ) {
42 parent::__construct( $name );
43 $this->action = $action;
44 $this->msgPrefix = $msgPrefix;
45 }
46
50 public function getRedirect( $subpage ) {
51 if ( $subpage === null || $subpage === '' ) {
52 return false;
53 }
54 $this->mAddedRedirectParams['title'] = $subpage;
55 $this->mAddedRedirectParams['action'] = $this->action;
56 return true;
57 }
58
62 protected function showNoRedirectPage() {
63 $this->setHeaders();
64 $this->outputHeader();
65 $this->showForm();
66 }
67
68 private function showForm() {
69 // Dynamic messages used:
70 // 'special' . $this->msgPrefix . '-page'
71 // 'special' . $this->msgPrefix . '-submit'
72 // Each special page that extends this should include those as comments for grep
73 $form = HTMLForm::factory( 'ooui', [
74 'page' => [
75 'type' => 'title',
76 'name' => 'page',
77 'label-message' => 'special' . $this->msgPrefix . '-page',
78 'required' => true,
79 'creatable' => true,
80 ],
81 ], $this->getContext(), $this->msgPrefix );
82 $form->setSubmitTextMsg( 'special' . $this->msgPrefix . '-submit' );
83 $form->setSubmitCallback( $this->onFormSubmit( ... ) );
84 $form->show();
85 }
86
92 public function onFormSubmit( $formData ) {
93 $title = $formData['page'];
94 $page = Title::newFromText( $title );
95 $query = [ 'action' => $this->action ];
96 $url = $page->getFullUrlForRedirect( $query );
97 $this->getOutput()->redirect( $url );
98 }
99
105 public function isListed() {
106 return true;
107 }
108
117 public function prefixSearchSubpages( $search, $limit, $offset ) {
118 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
119 }
120
126 protected function getGroupName() {
127 return 'redirects';
128 }
129}
130
131// @codeCoverageIgnoreStart
133class_alias( SpecialRedirectWithAction::class, 'SpecialRedirectWithAction' );
134// @codeCoverageIgnoreEnd
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:214
Factory class for SearchEngine.
Base class for redirect shortcuts.
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.
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.
__construct( $name, $action, $msgPrefix, private readonly SearchEngineFactory $searchEngineFactory,)
Represents a title within MediaWiki.
Definition Title.php:69