1<?php 2/** 3 * Redirect from Special:NewSection/$1 to index.php?title=$1&action=edit§ion=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 * @author DannyS712 23 */ 24class SpecialNewSection extends RedirectSpecialPage { 25 public function __construct() { 26 parent::__construct( 'NewSection' ); 27 $this->mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro', 28 'preload', 'preloadparams', 'summary' ]; 29 } 30 31 /** 32 * @inheritDoc 33 */ 34 public function getRedirect( $subpage ) { 35 if ( $subpage === null || $subpage === '' ) { 36 return false; 37 } 38 $this->mAddedRedirectParams['title'] = $subpage; 39 $this->mAddedRedirectParams['action'] = 'edit'; 40 $this->mAddedRedirectParams['section'] = 'new'; 41 return true; 42 } 43 44 protected function showNoRedirectPage() { 45 $this->setHeaders(); 46 $this->outputHeader(); 47 $this->addHelpLink( 'Help:New section' ); 48 $this->showForm(); 49 } 50 51 private function showForm() { 52 $form = HTMLForm::factory( 'ooui', [ 53 'page' => [ 54 'type' => 'text', 55 'name' => 'page', 56 'label-message' => 'newsection-page', 57 'required' => true, 58 ], 59 ], $this->getContext(), 'newsection' ); 60 $form->setSubmitTextMsg( 'newsection-submit' ); 61 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] ); 62 $form->show(); 63 } 64 65 public function onFormSubmit( $formData ) { 66 $title = $formData['page']; 67 try { 68 $page = Title::newFromTextThrow( $title ); 69 } catch ( MalformedTitleException $e ) { 70 return Status::newFatal( $e->getMessageObject() ); 71 } 72 $query = [ 'action' => 'edit', 'section' => 'new' ]; 73 $url = $page->getFullUrlForRedirect( $query ); 74 $this->getOutput()->redirect( $url ); 75 } 76 77 public function isListed() { 78 return true; 79 } 80 81 protected function getGroupName() { 82 return 'redirects'; 83 } 84} 85