SpecialNewSection.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. * @inheritDoc
  31. */
  32. public function getRedirect( $subpage ) {
  33. if ( $subpage === null || $subpage === '' ) {
  34. return false;
  35. }
  36. $this->mAddedRedirectParams['title'] = $subpage;
  37. $this->mAddedRedirectParams['action'] = 'edit';
  38. $this->mAddedRedirectParams['section'] = 'new';
  39. return true;
  40. }
  41. protected function showNoRedirectPage() {
  42. $this->setHeaders();
  43. $this->outputHeader();
  44. $this->addHelpLink( 'Help:New section' );
  45. $this->showForm();
  46. }
  47. private function showForm() {
  48. $form = HTMLForm::factory( 'ooui', [
  49. 'page' => [
  50. 'type' => 'text',
  51. 'name' => 'page',
  52. 'label-message' => 'newsection-page',
  53. 'required' => true,
  54. ],
  55. ], $this->getContext(), 'newsection' );
  56. $form->setSubmitTextMsg( 'newsection-submit' );
  57. $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
  58. $form->show();
  59. }
  60. public function onFormSubmit( $formData ) {
  61. $title = $formData['page'];
  62. try {
  63. $page = Title::newFromTextThrow( $title );
  64. } catch ( MalformedTitleException $e ) {
  65. return Status::newFatal( $e->getMessageObject() );
  66. }
  67. $query = [ 'action' => 'edit', 'section' => 'new' ];
  68. $url = $page->getFullUrlForRedirect( $query );
  69. $this->getOutput()->redirect( $url );
  70. }
  71. public function isListed() {
  72. return true;
  73. }
  74. protected function getGroupName() {
  75. return 'redirects';
  76. }
  77. }