MediaWiki master
SpecialNewSection.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
27
35
36 private SearchEngineFactory $searchEngineFactory;
37
38 public function __construct(
39 SearchEngineFactory $searchEngineFactory
40 ) {
41 parent::__construct( 'NewSection' );
42 $this->mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro',
43 'preload', 'preloadparams', 'summary' ];
44 $this->searchEngineFactory = $searchEngineFactory;
45 }
46
50 public function getRedirect( $subpage ) {
51 if ( $subpage === null || $subpage === '' ) {
52 return false;
53 }
54 $this->mAddedRedirectParams['title'] = $subpage;
55 $this->mAddedRedirectParams['action'] = 'edit';
56 $this->mAddedRedirectParams['section'] = 'new';
57 return true;
58 }
59
60 protected function showNoRedirectPage() {
61 $this->setHeaders();
62 $this->outputHeader();
63 $this->addHelpLink( 'Help:New section' );
64 $this->showForm();
65 }
66
67 private function showForm() {
68 $form = HTMLForm::factory( 'ooui', [
69 'page' => [
70 'type' => 'title',
71 'name' => 'page',
72 'label-message' => 'newsection-page',
73 'required' => true,
74 'creatable' => true,
75 ],
76 ], $this->getContext(), 'newsection' );
77 $form->setSubmitTextMsg( 'newsection-submit' );
78 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
79 $form->show();
80 }
81
82 public function onFormSubmit( $formData ) {
83 $title = $formData['page'];
84 $page = Title::newFromTextThrow( $title );
85 $query = [ 'action' => 'edit', 'section' => 'new' ];
86 $url = $page->getFullUrlForRedirect( $query );
87 $this->getOutput()->redirect( $url );
88 }
89
90 public function isListed() {
91 return true;
92 }
93
102 public function prefixSearchSubpages( $search, $limit, $offset ) {
103 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
104 }
105
106 protected function getGroupName() {
107 return 'redirects';
108 }
109}
110
115class_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.

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant