MediaWiki  master
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 {
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 }
SpecialRedirectWithAction\getRedirect
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.False otherwise....
Definition: SpecialRedirectWithAction.php:45
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:70
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:744
SpecialRedirectWithAction
Definition: SpecialRedirectWithAction.php:26
MalformedTitleException\getMessageObject
getMessageObject()
Definition: MalformedTitleException.php:82
RedirectSpecialPage
Shortcut to construct a special page alias.
Definition: RedirectSpecialPage.php:31
SpecialRedirectWithAction\showForm
showForm()
Definition: SpecialRedirectWithAction.php:63
SpecialRedirectWithAction\getGroupName
getGroupName()
Stable to override.
Definition: SpecialRedirectWithAction.php:112
SpecialRedirectWithAction\__construct
__construct( $name, $action, $msgPrefix)
Stable to call.
Definition: SpecialRedirectWithAction.php:36
$title
$title
Definition: testCompression.php:38
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!...
Definition: SpecialPage.php:571
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:717
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:364
SpecialRedirectWithAction\onFormSubmit
onFormSubmit( $formData)
Stable to override.
Definition: SpecialRedirectWithAction.php:88
SpecialRedirectWithAction\$action
$action
Definition: SpecialRedirectWithAction.php:27
MalformedTitleException
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Definition: MalformedTitleException.php:26
SpecialRedirectWithAction\$msgPrefix
$msgPrefix
Definition: SpecialRedirectWithAction.php:27
SpecialRedirectWithAction\isListed
isListed()
Stable to override.
Definition: SpecialRedirectWithAction.php:104
SpecialRedirectWithAction\showNoRedirectPage
showNoRedirectPage()
Stable to override.
Definition: SpecialRedirectWithAction.php:57
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:315
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:662