Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 35
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialNewSection
0.00% covered (danger)
0.00%
0 / 34
0.00% covered (danger)
0.00%
0 / 8
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getRedirect
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 showNoRedirectPage
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 showForm
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 onFormSubmit
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 isListed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 prefixSearchSubpages
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\Specials;
22
23use MediaWiki\HTMLForm\HTMLForm;
24use MediaWiki\SpecialPage\RedirectSpecialPage;
25use MediaWiki\Title\Title;
26use SearchEngineFactory;
27
28/**
29 * Redirect from Special:NewSection/$1 to index.php?title=$1&action=edit&section=new.
30 *
31 * @ingroup SpecialPage
32 * @author DannyS712
33 */
34class SpecialNewSection extends RedirectSpecialPage {
35
36    private SearchEngineFactory $searchEngineFactory;
37
38    /**
39     * @param SearchEngineFactory $searchEngineFactory
40     */
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
50    /**
51     * @inheritDoc
52     */
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
97    /**
98     * Return an array of subpages beginning with $search that this special page will accept.
99     *
100     * @param string $search Prefix to search for
101     * @param int $limit Maximum number of results to return (usually 10)
102     * @param int $offset Number of results to skip (usually 0)
103     * @return string[] Matching subpages
104     */
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
114/**
115 * Retain the old class name for backwards compatibility.
116 * @deprecated since 1.41
117 */
118class_alias( SpecialNewSection::class, 'SpecialNewSection' );