From 95b257375c73e533b4e40303845b76a6a3fc41c4 Mon Sep 17 00:00:00 2001 From: DannyS712 Date: Sun, 23 Jun 2019 02:17:38 +0000 Subject: [PATCH] Create Special:NewSection special page Bug: T207577 Change-Id: If69a8e13b524f55f78b2f61aadf1f9045fda5ff2 --- RELEASE-NOTES-1.34 | 5 ++ autoload.php | 1 + includes/specialpage/SpecialPageFactory.php | 1 + includes/specials/SpecialNewSection.php | 76 +++++++++++++++++++++ languages/i18n/en.json | 4 ++ languages/i18n/qqq.json | 4 ++ languages/messages/MessagesEn.php | 1 + 7 files changed, 92 insertions(+) create mode 100644 includes/specials/SpecialNewSection.php diff --git a/RELEASE-NOTES-1.34 b/RELEASE-NOTES-1.34 index 549f7e8228..95db78afdd 100644 --- a/RELEASE-NOTES-1.34 +++ b/RELEASE-NOTES-1.34 @@ -62,6 +62,11 @@ For notes on 1.33.x and older releases, see HISTORY. === New user-facing features in 1.34 === * Special:Mute has been added as a quick way for users to block unwanted emails from other users originating from Special:EmailUser. +* (T207577) Special:NewSection has been created as a shortcut to creating a new + section on a page. When linked to, its subpage is used as the target + ([[Special:NewSection/Test]] redirects to creating a new section in "Test"). + Otherwise, it displays a basic interface to allow the end user to specify + the target manually. === New developer features in 1.34 === * Language::formatTimePeriod now supports the new 'avoidhours' option to output diff --git a/autoload.php b/autoload.php index 0b93f49758..5fde3410e4 100644 --- a/autoload.php +++ b/autoload.php @@ -1395,6 +1395,7 @@ $wgAutoloadLocalClasses = [ 'SpecialMytalk' => __DIR__ . '/includes/specials/redirects/SpecialMytalk.php', 'SpecialMyuploads' => __DIR__ . '/includes/specials/redirects/SpecialMyuploads.php', 'SpecialNewFiles' => __DIR__ . '/includes/specials/SpecialNewimages.php', + 'SpecialNewSection' => __DIR__ . '/includes/specials/SpecialNewSection.php', 'SpecialNewpages' => __DIR__ . '/includes/specials/SpecialNewpages.php', 'SpecialPage' => __DIR__ . '/includes/specialpage/SpecialPage.php', 'SpecialPageAction' => __DIR__ . '/includes/actions/SpecialPageAction.php', diff --git a/includes/specialpage/SpecialPageFactory.php b/includes/specialpage/SpecialPageFactory.php index 40172ab693..051926d7b7 100644 --- a/includes/specialpage/SpecialPageFactory.php +++ b/includes/specialpage/SpecialPageFactory.php @@ -200,6 +200,7 @@ class SpecialPageFactory { 'Mytalk' => \SpecialMytalk::class, 'Myuploads' => \SpecialMyuploads::class, 'AllMyUploads' => \SpecialAllMyUploads::class, + 'NewSection' => \SpecialNewSection::class, 'PermanentLink' => \SpecialPermanentLink::class, 'Redirect' => \SpecialRedirect::class, 'Revisiondelete' => \SpecialRevisionDelete::class, diff --git a/includes/specials/SpecialNewSection.php b/includes/specials/SpecialNewSection.php new file mode 100644 index 0000000000..b503141d7b --- /dev/null +++ b/includes/specials/SpecialNewSection.php @@ -0,0 +1,76 @@ +mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro', + 'preload', 'preloadparams[]', 'summary' ]; + } + + /** + * @inheritDoc + */ + public function getRedirect( $subpage ) { + if ( $subpage === null || $subpage === '' ) { + return false; + } + $this->mAddedRedirectParams['title'] = $subpage; + $this->mAddedRedirectParams['action'] = 'edit'; + $this->mAddedRedirectParams['section'] = 'new'; + return true; + } + + protected function showNoRedirectPage() { + $this->setHeaders(); + $this->outputHeader(); + $this->showForm(); + } + + private function showForm() { + $form = HTMLForm::factory( 'ooui', [ + 'page' => [ + 'type' => 'text', + 'name' => 'page', + 'label-message' => 'newsection-page', + ], + ], $this->getContext(), 'newsection' ); + $form->setSubmitTextMsg( 'newsection-submit' ); + $form->setSubmitCallback( [ $this, 'onFormSubmit' ] ); + $form->show(); + } + + public function onFormSubmit( $formData ) { + $page = $formData['page']; + $query = [ 'action' => 'edit', 'section' => 'new' ]; + $url = $page->getFullUrlForRedirect( $query ); + $this->getOutput()->redirect( $url ); + } + + public function isListed() { + return true; + } + + protected function getGroupName() { + return 'redirects'; + } +} diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 244b281bdd..6d324f6696 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3758,6 +3758,10 @@ "permanentlink-revid": "Revision ID", "permanentlink-submit": "Go to revision", "permanentlink-summary": "", + "newsection": "New section", + "newsection-page": "Target page", + "newsection-submit": "Go to page", + "newsection-summary": "", "dberr-problems": "Sorry! This site is experiencing technical difficulties.", "dberr-again": "Try waiting a few minutes and reloading.", "dberr-info": "(Cannot access the database: $1)", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 63ff3759d6..14df22cbe9 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3966,6 +3966,10 @@ "permanentlink-revid": "Label for the field for the revision ID in [[Special:PermanentLink]]\n{{Identical|Revision ID}}", "permanentlink-submit": "Submit button on [[Special:PermanentLink]]", "permanentlink-summary": "{{doc-specialpagesummary|permanentlink}}", + "newsection": "The title of [[Special:NewSection]]", + "newsection-page": "Label for the field for the target page in [[Special:NewSection]]", + "newsection-submit": "Submit button on [[Special:NewSection]]", + "newsection-summary": "{{doc-specialpagessummary|newsection}}", "dberr-problems": "This message does not allow any wiki nor html markup.", "dberr-again": "This message does not allow any wiki nor html markup.", "dberr-info": "This message does not allow any wiki nor html markup. Parameters:\n* $1 - database server name\nSee also:\n* {{msg-mw|Dberr-info-hidden}} - hides database server name", diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 22313a439f..fc218436b0 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -454,6 +454,7 @@ $specialPageAliases = [ 'Mytalk' => [ 'MyTalk' ], 'Myuploads' => [ 'MyUploads', 'MyFiles' ], 'Newimages' => [ 'NewFiles', 'NewImages' ], + 'NewSection' => [ 'NewSection', 'Newsection' ], 'Newpages' => [ 'NewPages' ], 'PagesWithProp' => [ 'PagesWithProp', 'Pageswithprop', 'PagesByProp', 'Pagesbyprop' ], 'PageData' => [ 'PageData' ], -- 2.20.1