Add special page class for disabling special pages
authorGergő Tisza <gtisza@wikimedia.org>
Fri, 16 Nov 2018 02:22:26 +0000 (18:22 -0800)
committerLegoktm <legoktm@member.fsf.org>
Sat, 12 Jan 2019 18:46:36 +0000 (18:46 +0000)
Similar to the ApiDisabled class, but for special pages.

Change-Id: Ib56860bc3f8a14fd332b775b1e7f50953641ee82

autoload.php
includes/specialpage/DisabledSpecialPage.php [new file with mode: 0644]
languages/i18n/en.json
languages/i18n/qqq.json

index 02e35a8..6f253bb 100644 (file)
@@ -408,6 +408,7 @@ $wgAutoloadLocalClasses = [
        'DifferenceEngine' => __DIR__ . '/includes/diff/DifferenceEngine.php',
        'DifferenceEngineSlotDiffRenderer' => __DIR__ . '/includes/diff/DifferenceEngineSlotDiffRenderer.php',
        'Digit2Html' => __DIR__ . '/maintenance/language/digit2html.php',
+       'DisabledSpecialPage' => __DIR__ . '/includes/specialpage/DisabledSpecialPage.php',
        'DjVuHandler' => __DIR__ . '/includes/media/DjVuHandler.php',
        'DjVuImage' => __DIR__ . '/includes/media/DjVuImage.php',
        'DnsSrvDiscoverer' => __DIR__ . '/includes/libs/DnsSrvDiscoverer.php',
diff --git a/includes/specialpage/DisabledSpecialPage.php b/includes/specialpage/DisabledSpecialPage.php
new file mode 100644 (file)
index 0000000..ebcd8e5
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+/**
+ * Special page for replacing manually disabled special pages
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
+ */
+
+/**
+ * This class is a drop-in replacement for other special pages that need to be manually
+ * disabled. To use it, just put something like
+ *
+ *     $wgSpecialPages['Name'] = DisabledSpecialPage::getCallback( 'Name', 'message' );
+ *
+ * in the local configuration (where 'Name' is the canonical name of the special page
+ * to be disabled, and 'message' is a message key for explaining the reason for disabling).
+ *
+ * @since 1.33
+ */
+class DisabledSpecialPage extends UnlistedSpecialPage {
+
+       /** @var Message */
+       protected $errorMessage;
+
+       /**
+        * Create a callback suitable for use in $wgSpecialPages.
+        * @param string $name Canonical name of the special page that's being replaced.
+        * @param Message|string|null $errorMessage Error message to show when users try to use the page.
+        * @return Closure
+        */
+       public static function getCallback( $name, $errorMessage = null ) {
+               return function () use ( $name, $errorMessage ) {
+                       return new DisabledSpecialPage( $name, $errorMessage );
+               };
+       }
+
+       /**
+        * @param string $name Canonical name of the special page that's being replaced.
+        * @param Message|string|null $errorMessage Error message to show when users try to use the page.
+        */
+       public function __construct( $name, $errorMessage = null ) {
+               parent::__construct( $name );
+               $this->errorMessage = $errorMessage ?: 'disabledspecialpage-disabled';
+       }
+
+       public function execute( $subPage ) {
+               $this->setHeaders();
+               $this->outputHeader();
+
+               $error = Html::rawElement( 'div', [
+                       'class' => 'error',
+               ], $this->msg( $this->errorMessage )->parseAsBlock() );
+               $this->getOutput()->addHTML( $error );
+       }
+
+}
index ba6353f..28fae1e 100644 (file)
        "specialpages-group-developer": "Developer tools",
        "blankpage": "Blank page",
        "intentionallyblankpage": "This page is intentionally left blank.",
+       "disabledspecialpage-disabled": "This page has been disabled by a system administrator.",
        "external_image_whitelist": " #Leave this line exactly as it is<pre>\n#Put regular expression fragments (just the part that goes between the //) below\n#These will be matched with the URLs of external (hotlinked) images\n#Those that match will be displayed as images, otherwise only a link to the image will be shown\n#Lines beginning with # are treated as comments\n#This is case-insensitive\n\n#Put all regex fragments above this line. Leave this line exactly as it is</pre>",
        "tags": "Valid change tags",
        "tags-summary": "",
index 1d05889..7261aff 100644 (file)
        "specialpages-group-developer": "{{doc-special-group|that=are related to tools for developers}}",
        "blankpage": "{{doc-special|BlankPage|unlisted=1}}\nSee also:\n* {{msg-mw|Intentionallyblankpage|text}}",
        "intentionallyblankpage": "Text displayed in [[Special:BlankPage]].\n\nSee also:\n* {{msg-mw|Intentionallyblankpage|page title}}",
+       "disabledspecialpage-disabled": "Default message used on disabled special pages.",
        "external_image_whitelist": "As usual please leave all the wiki markup, including the spaces, as they are. You can translate the text, including 'Leave this line exactly as it is'. The first line of this messages has one (1) leading space.\n\nSee definition of [[w:Regular_expression|regular expression]] on Wikipedia.",
        "tags": "Shown on [[Special:Specialpages]] for page listing the tags that the software may mark an edit with, and their meaning. For more information on tags see [[mw:Manual:Tags|MediaWiki]].\n\nIt appears that the word 'valid' describes 'tags', not 'change'. It also appears that you could use the term 'defined' instead of 'valid', or perhaps use a phrase meaning 'The change tags that are in use'.",
        "tags-summary": "{{doc-specialpagesummary|tags}}",