MediaWiki master
SpecialNewSection.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
27
35
36 private SearchEngineFactory $searchEngineFactory;
37
41 public function __construct(
42 SearchEngineFactory $searchEngineFactory
43 ) {
44 parent::__construct( 'NewSection' );
45 $this->mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro',
46 'preload', 'preloadparams', 'summary' ];
47 $this->searchEngineFactory = $searchEngineFactory;
48 }
49
53 public function getRedirect( $subpage ) {
54 if ( $subpage === null || $subpage === '' ) {
55 return false;
56 }
57 $this->mAddedRedirectParams['title'] = $subpage;
58 $this->mAddedRedirectParams['action'] = 'edit';
59 $this->mAddedRedirectParams['section'] = 'new';
60 return true;
61 }
62
63 protected function showNoRedirectPage() {
64 $this->setHeaders();
65 $this->outputHeader();
66 $this->addHelpLink( 'Help:New section' );
67 $this->showForm();
68 }
69
70 private function showForm() {
71 $form = HTMLForm::factory( 'ooui', [
72 'page' => [
73 'type' => 'title',
74 'name' => 'page',
75 'label-message' => 'newsection-page',
76 'required' => true,
77 'creatable' => true,
78 ],
79 ], $this->getContext(), 'newsection' );
80 $form->setSubmitTextMsg( 'newsection-submit' );
81 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
82 $form->show();
83 }
84
85 public function onFormSubmit( $formData ) {
86 $title = $formData['page'];
87 $page = Title::newFromTextThrow( $title );
88 $query = [ 'action' => 'edit', 'section' => 'new' ];
89 $url = $page->getFullUrlForRedirect( $query );
90 $this->getOutput()->redirect( $url );
91 }
92
93 public function isListed() {
94 return true;
95 }
96
105 public function prefixSearchSubpages( $search, $limit, $offset ) {
106 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
107 }
108
109 protected function getGroupName() {
110 return 'redirects';
111 }
112}
113
118class_alias( SpecialNewSection::class, 'SpecialNewSection' );
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:209
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.
__construct(SearchEngineFactory $searchEngineFactory)
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
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:78
Factory class for SearchEngine.