MediaWiki REL1_35
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 {
68 $page = Title::newFromTextThrow( $title );
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}
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Shortcut to construct a special page alias.
showNoRedirectPage()
Stable to override.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.False otherwise....
isListed()
Whether this special page is listed in Special:SpecialPages Stable to override.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!...
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.