MediaWiki  master
SpecialNewSection.php
Go to the documentation of this file.
1 <?php
25  public function __construct() {
26  parent::__construct( 'NewSection' );
27  $this->mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro',
28  'preload', 'preloadparams', 'summary' ];
29  }
30 
34  public function getRedirect( $subpage ) {
35  if ( $subpage === null || $subpage === '' ) {
36  return false;
37  }
38  $this->mAddedRedirectParams['title'] = $subpage;
39  $this->mAddedRedirectParams['action'] = 'edit';
40  $this->mAddedRedirectParams['section'] = 'new';
41  return true;
42  }
43 
44  protected function showNoRedirectPage() {
45  $this->setHeaders();
46  $this->outputHeader();
47  $this->addHelpLink( 'Help:New section' );
48  $this->showForm();
49  }
50 
51  private function showForm() {
52  $form = HTMLForm::factory( 'ooui', [
53  'page' => [
54  'type' => 'text',
55  'name' => 'page',
56  'label-message' => 'newsection-page',
57  'required' => true,
58  ],
59  ], $this->getContext(), 'newsection' );
60  $form->setSubmitTextMsg( 'newsection-submit' );
61  $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
62  $form->show();
63  }
64 
65  public function onFormSubmit( $formData ) {
66  $title = $formData['page'];
67  try {
69  } catch ( MalformedTitleException $e ) {
70  return Status::newFatal( $e->getMessageObject() );
71  }
72  $query = [ 'action' => 'edit', 'section' => 'new' ];
73  $url = $page->getFullUrlForRedirect( $query );
74  $this->getOutput()->redirect( $url );
75  }
76 
77  public function isListed() {
78  return true;
79  }
80 
81  protected function getGroupName() {
82  return 'redirects';
83  }
84 }
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:716
MalformedTitleException\getMessageObject
getMessageObject()
Definition: MalformedTitleException.php:80
RedirectSpecialPage
Shortcut to construct a special page alias.
Definition: RedirectSpecialPage.php:29
SpecialNewSection\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialNewSection.php:81
SpecialNewSection\__construct
__construct()
Definition: SpecialNewSection.php:25
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:836
SpecialNewSection
Definition: SpecialNewSection.php:24
$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:551
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:689
Title\newFromTextThrow
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:367
SpecialNewSection\showForm
showForm()
Definition: SpecialNewSection.php:51
MalformedTitleException
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Definition: MalformedTitleException.php:25
SpecialNewSection\onFormSubmit
onFormSubmit( $formData)
Definition: SpecialNewSection.php:65
SpecialNewSection\getRedirect
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.False otherwise....
Definition: SpecialNewSection.php:34
SpecialNewSection\isListed
isListed()
Whether this special page is listed in Special:SpecialPages.
Definition: SpecialNewSection.php:77
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:311
SpecialNewSection\showNoRedirectPage
showNoRedirectPage()
Definition: SpecialNewSection.php:44
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:636