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