Add rate limiter to Special:ConfirmEmail
[lhc/web/wiklou.git] / includes / specials / SpecialNewSection.php
1 <?php
2 /**
3 * Redirect from Special:NewSection/$1 to index.php?title=$1&action=edit&section=new.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23 class SpecialNewSection extends RedirectSpecialPage {
24 public function __construct() {
25 parent::__construct( 'NewSection' );
26 $this->mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro',
27 'preload', 'preloadparams[]', 'summary' ];
28 }
29
30 /**
31 * @inheritDoc
32 */
33 public function getRedirect( $subpage ) {
34 if ( $subpage === null || $subpage === '' ) {
35 return false;
36 }
37 $this->mAddedRedirectParams['title'] = $subpage;
38 $this->mAddedRedirectParams['action'] = 'edit';
39 $this->mAddedRedirectParams['section'] = 'new';
40 return true;
41 }
42
43 protected function showNoRedirectPage() {
44 $this->setHeaders();
45 $this->outputHeader();
46 $this->showForm();
47 }
48
49 private function showForm() {
50 $form = HTMLForm::factory( 'ooui', [
51 'page' => [
52 'type' => 'text',
53 'name' => 'page',
54 'label-message' => 'newsection-page',
55 'required' => true,
56 ],
57 ], $this->getContext(), 'newsection' );
58 $form->setSubmitTextMsg( 'newsection-submit' );
59 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
60 $form->show();
61 }
62
63 public function onFormSubmit( $formData ) {
64 $title = $formData['page'];
65 try {
66 $page = Title::newFromTextThrow( $title );
67 } catch ( MalformedTitleException $e ) {
68 return Status::newFatal( $e->getMessageObject() );
69 }
70 $query = [ 'action' => 'edit', 'section' => 'new' ];
71 $url = $page->getFullUrlForRedirect( $query );
72 $this->getOutput()->redirect( $url );
73 }
74
75 public function isListed() {
76 return true;
77 }
78
79 protected function getGroupName() {
80 return 'redirects';
81 }
82 }