MediaWiki REL1_35
SpecialRedirectWithAction.php
Go to the documentation of this file.
1<?php
27 protected $action, $msgPrefix;
28
36 public function __construct( $name, $action, $msgPrefix ) {
37 parent::__construct( $name );
38 $this->action = $action;
39 $this->msgPrefix = $msgPrefix;
40 }
41
45 public function getRedirect( $subpage ) {
46 if ( $subpage === null || $subpage === '' ) {
47 return false;
48 }
49 $this->mAddedRedirectParams['title'] = $subpage;
50 $this->mAddedRedirectParams['action'] = $this->action;
51 return true;
52 }
53
57 protected function showNoRedirectPage() {
58 $this->setHeaders();
59 $this->outputHeader();
60 $this->showForm();
61 }
62
63 private function showForm() {
64 // Dynamic messages used:
65 // 'special' . $this->msgPrefix . '-page'
66 // 'special' . $this->msgPrefix . '-submit'
67 // Each special page that extends this should include those as comments for grep
68 $form = HTMLForm::factory( 'ooui', [
69 'page' => [
70 'type' => 'text',
71 'name' => 'page',
72 'label-message' => 'special' . $this->msgPrefix . '-page',
73 'required' => true,
74 ],
75 ], $this->getContext(), $this->msgPrefix );
76 $form->setSubmitTextMsg( 'special' . $this->msgPrefix . '-submit' );
77 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
78 $form->show();
79 }
80
88 public function onFormSubmit( $formData ) {
89 $title = $formData['page'];
90 try {
91 $page = Title::newFromTextThrow( $title );
92 } catch ( MalformedTitleException $e ) {
93 return Status::newFatal( $e->getMessageObject() );
94 }
95 $query = [ 'action' => $this->action ];
96 $url = $page->getFullUrlForRedirect( $query );
97 $this->getOutput()->redirect( $url );
98 }
99
104 public function isListed() {
105 return true;
106 }
107
112 protected function getGroupName() {
113 return 'redirects';
114 }
115}
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Shortcut to construct a special page alias.
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.
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.False otherwise....
__construct( $name, $action, $msgPrefix)
Stable to call.
onFormSubmit( $formData)
Stable to override.