MediaWiki  master
SpecialRedirectWithAction.php
Go to the documentation of this file.
1 <?php
25  protected $action, $msgPrefix;
26 
27  public function __construct( $name, $action, $msgPrefix ) {
28  parent::__construct( $name );
29  $this->action = $action;
30  $this->msgPrefix = $msgPrefix;
31  }
32 
36  public function getRedirect( $subpage ) {
37  if ( $subpage === null || $subpage === '' ) {
38  return false;
39  }
40  $this->mAddedRedirectParams['title'] = $subpage;
41  $this->mAddedRedirectParams['action'] = $this->action;
42  return true;
43  }
44 
45  protected function showNoRedirectPage() {
46  $this->setHeaders();
47  $this->outputHeader();
48  $this->showForm();
49  }
50 
51  private function showForm() {
52  // Dynamic messages used:
53  // 'special' . $this->msgPrefix . '-page'
54  // 'special' . $this->msgPrefix . '-submit'
55  // Each special page that extends this should include those as comments for grep
56  $form = HTMLForm::factory( 'ooui', [
57  'page' => [
58  'type' => 'text',
59  'name' => 'page',
60  'label-message' => 'special' . $this->msgPrefix . '-page',
61  'required' => true,
62  ],
63  ], $this->getContext(), $this->msgPrefix );
64  $form->setSubmitTextMsg( 'special' . $this->msgPrefix . '-submit' );
65  $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
66  $form->show();
67  }
68 
69  public function onFormSubmit( $formData ) {
70  $title = $formData['page'];
71  try {
73  } catch ( MalformedTitleException $e ) {
74  return Status::newFatal( $e->getMessageObject() );
75  }
76  $query = [ 'action' => $this->action ];
77  $url = $page->getFullUrlForRedirect( $query );
78  $this->getOutput()->redirect( $url );
79  }
80 
81  public function isListed() {
82  return true;
83  }
84 
85  protected function getGroupName() {
86  return 'redirects';
87  }
88 }
SpecialRedirectWithAction\getRedirect
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.False otherwise....
Definition: SpecialRedirectWithAction.php:36
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:69
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:726
SpecialRedirectWithAction
Definition: SpecialRedirectWithAction.php:24
MalformedTitleException\getMessageObject
getMessageObject()
Definition: MalformedTitleException.php:80
RedirectSpecialPage
Shortcut to construct a special page alias.
Definition: RedirectSpecialPage.php:29
SpecialRedirectWithAction\showForm
showForm()
Definition: SpecialRedirectWithAction.php:51
SpecialRedirectWithAction\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialRedirectWithAction.php:85
SpecialRedirectWithAction\__construct
__construct( $name, $action, $msgPrefix)
Definition: SpecialRedirectWithAction.php:27
$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:544
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:699
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:367
SpecialRedirectWithAction\onFormSubmit
onFormSubmit( $formData)
Definition: SpecialRedirectWithAction.php:69
SpecialRedirectWithAction\$action
$action
Definition: SpecialRedirectWithAction.php:25
MalformedTitleException
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Definition: MalformedTitleException.php:25
SpecialRedirectWithAction\$msgPrefix
$msgPrefix
Definition: SpecialRedirectWithAction.php:25
SpecialRedirectWithAction\isListed
isListed()
Whether this special page is listed in Special:SpecialPages.
Definition: SpecialRedirectWithAction.php:81
SpecialRedirectWithAction\showNoRedirectPage
showNoRedirectPage()
Definition: SpecialRedirectWithAction.php:45
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:307
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:646