MediaWiki REL1_41
SpecialNewSection.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Specials;
4
5use HTMLForm;
9
33
34 private SearchEngineFactory $searchEngineFactory;
35
39 public function __construct(
40 SearchEngineFactory $searchEngineFactory
41 ) {
42 parent::__construct( 'NewSection' );
43 $this->mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro',
44 'preload', 'preloadparams', 'summary' ];
45 $this->searchEngineFactory = $searchEngineFactory;
46 }
47
51 public function getRedirect( $subpage ) {
52 if ( $subpage === null || $subpage === '' ) {
53 return false;
54 }
55 $this->mAddedRedirectParams['title'] = $subpage;
56 $this->mAddedRedirectParams['action'] = 'edit';
57 $this->mAddedRedirectParams['section'] = 'new';
58 return true;
59 }
60
61 protected function showNoRedirectPage() {
62 $this->setHeaders();
63 $this->outputHeader();
64 $this->addHelpLink( 'Help:New section' );
65 $this->showForm();
66 }
67
68 private function showForm() {
69 $form = HTMLForm::factory( 'ooui', [
70 'page' => [
71 'type' => 'title',
72 'name' => 'page',
73 'label-message' => 'newsection-page',
74 'required' => true,
75 'creatable' => true,
76 ],
77 ], $this->getContext(), 'newsection' );
78 $form->setSubmitTextMsg( 'newsection-submit' );
79 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
80 $form->show();
81 }
82
83 public function onFormSubmit( $formData ) {
84 $title = $formData['page'];
85 $page = Title::newFromTextThrow( $title );
86 $query = [ 'action' => 'edit', 'section' => 'new' ];
87 $url = $page->getFullUrlForRedirect( $query );
88 $this->getOutput()->redirect( $url );
89 }
90
91 public function isListed() {
92 return true;
93 }
94
103 public function prefixSearchSubpages( $search, $limit, $offset ) {
104 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
105 }
106
107 protected function getGroupName() {
108 return 'redirects';
109 }
110}
111
116class_alias( SpecialNewSection::class, 'SpecialNewSection' );
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:158
Shortcut to construct a special page alias.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
prefixSearchString( $search, $limit, $offset, SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
getContext()
Gets the context this SpecialPage is executed in.
getOutput()
Get the OutputPage being used for this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
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:76
Factory class for SearchEngine.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...