MediaWiki  master
SpecialNewSection.php
Go to the documentation of this file.
1 <?php
25 
28 
32  public function __construct(
34  ) {
35  parent::__construct( 'NewSection' );
36  $this->mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro',
37  'preload', 'preloadparams', 'summary' ];
38  $this->searchEngineFactory = $searchEngineFactory;
39  }
40 
44  public function getRedirect( $subpage ) {
45  if ( $subpage === null || $subpage === '' ) {
46  return false;
47  }
48  $this->mAddedRedirectParams['title'] = $subpage;
49  $this->mAddedRedirectParams['action'] = 'edit';
50  $this->mAddedRedirectParams['section'] = 'new';
51  return true;
52  }
53 
54  protected function showNoRedirectPage() {
55  $this->setHeaders();
56  $this->outputHeader();
57  $this->addHelpLink( 'Help:New section' );
58  $this->showForm();
59  }
60 
61  private function showForm() {
62  $form = HTMLForm::factory( 'ooui', [
63  'page' => [
64  'type' => 'title',
65  'name' => 'page',
66  'label-message' => 'newsection-page',
67  'required' => true,
68  'creatable' => true,
69  ],
70  ], $this->getContext(), 'newsection' );
71  $form->setSubmitTextMsg( 'newsection-submit' );
72  $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
73  $form->show();
74  }
75 
76  public function onFormSubmit( $formData ) {
77  $title = $formData['page'];
79  $query = [ 'action' => 'edit', 'section' => 'new' ];
80  $url = $page->getFullUrlForRedirect( $query );
81  $this->getOutput()->redirect( $url );
82  }
83 
84  public function isListed() {
85  return true;
86  }
87 
96  public function prefixSearchSubpages( $search, $limit, $offset ) {
97  return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
98  }
99 
100  protected function getGroupName() {
101  return 'redirects';
102  }
103 }
static factory( $displayFormat, $descriptor, IContextSource $context, $messagePrefix='')
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:338
Shortcut to construct a special page alias.
Factory class for SearchEngine.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
SearchEngineFactory $searchEngineFactory
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(SearchEngineFactory $searchEngineFactory)
onFormSubmit( $formData)
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.
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.
prefixSearchString( $search, $limit, $offset, SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
static newFromTextThrow( $text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid,...
Definition: Title.php:404