MediaWiki REL1_40
SpecialNewSection.php
Go to the documentation of this file.
1<?php
2
4
28
30 private $searchEngineFactory;
31
35 public function __construct(
36 SearchEngineFactory $searchEngineFactory
37 ) {
38 parent::__construct( 'NewSection' );
39 $this->mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro',
40 'preload', 'preloadparams', 'summary' ];
41 $this->searchEngineFactory = $searchEngineFactory;
42 }
43
47 public function getRedirect( $subpage ) {
48 if ( $subpage === null || $subpage === '' ) {
49 return false;
50 }
51 $this->mAddedRedirectParams['title'] = $subpage;
52 $this->mAddedRedirectParams['action'] = 'edit';
53 $this->mAddedRedirectParams['section'] = 'new';
54 return true;
55 }
56
57 protected function showNoRedirectPage() {
58 $this->setHeaders();
59 $this->outputHeader();
60 $this->addHelpLink( 'Help:New section' );
61 $this->showForm();
62 }
63
64 private function showForm() {
65 $form = HTMLForm::factory( 'ooui', [
66 'page' => [
67 'type' => 'title',
68 'name' => 'page',
69 'label-message' => 'newsection-page',
70 'required' => true,
71 'creatable' => true,
72 ],
73 ], $this->getContext(), 'newsection' );
74 $form->setSubmitTextMsg( 'newsection-submit' );
75 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
76 $form->show();
77 }
78
79 public function onFormSubmit( $formData ) {
80 $title = $formData['page'];
81 $page = Title::newFromTextThrow( $title );
82 $query = [ 'action' => 'edit', 'section' => 'new' ];
83 $url = $page->getFullUrlForRedirect( $query );
84 $this->getOutput()->redirect( $url );
85 }
86
87 public function isListed() {
88 return true;
89 }
90
99 public function prefixSearchSubpages( $search, $limit, $offset ) {
100 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
101 }
102
103 protected function getGroupName() {
104 return 'redirects';
105 }
106}
Represents a title within MediaWiki.
Definition Title.php:82
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.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(SearchEngineFactory $searchEngineFactory)
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.