MediaWiki master
SpecialNewSection.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
13
21
22 public function __construct(
23 private readonly SearchEngineFactory $searchEngineFactory,
24 ) {
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' => 'title',
54 'name' => 'page',
55 'label-message' => 'newsection-page',
56 'required' => true,
57 'creatable' => true,
58 ],
59 ], $this->getContext(), 'newsection' );
60 $form->setSubmitTextMsg( 'newsection-submit' );
61 $form->setSubmitCallback( $this->onFormSubmit( ... ) );
62 $form->show();
63 }
64
68 private function onFormSubmit( $formData ) {
69 $title = $formData['page'];
70 $page = Title::newFromTextThrow( $title );
71 $query = [ 'action' => 'edit', 'section' => 'new' ];
72 $url = $page->getFullUrlForRedirect( $query );
73 $this->getOutput()->redirect( $url );
74 }
75
77 public function isListed() {
78 return true;
79 }
80
89 public function prefixSearchSubpages( $search, $limit, $offset ) {
90 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
91 }
92
94 protected function getGroupName() {
95 return 'redirects';
96 }
97}
98
103class_alias( SpecialNewSection::class, 'SpecialNewSection' );
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:207
Factory class for SearchEngine.
Shortcut to construct a special page alias.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getContext()
Gets the context this SpecialPage is executed in.
getOutput()
Get the OutputPage being used for this instance.
prefixSearchString( $search, $limit, $offset, ?SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Redirect from Special:NewSection/$1 to index.php?title=$1&action=edit&section=new.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
isListed()
Whether this special page is listed in Special:SpecialPages.to override 1.3 (r3583) bool
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
__construct(private readonly SearchEngineFactory $searchEngineFactory,)
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.False otherwise....
Represents a title within MediaWiki.
Definition Title.php:69