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