Merge ".mailmap: Correct two contributor names"
[mediawiki.git] / includes / specialpage / DisabledSpecialPage.php
blob8bddbc2a90f39c58fe5d6a29c03d17f1f35eb532
1 <?php
2 /**
3 * Special page for replacing manually disabled special pages
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.
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.
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
20 * @file
21 * @ingroup SpecialPage
24 namespace MediaWiki\SpecialPage;
26 use Closure;
27 use MediaWiki\Html\Html;
28 use MediaWiki\Message\Message;
30 /**
31 * This class is a drop-in replacement for other special pages that need to be manually
32 * disabled. To use it, just put something like
34 * $wgSpecialPages['Name'] = DisabledSpecialPage::getCallback( 'Name', 'message' );
36 * in the local configuration (where 'Name' is the canonical name of the special page
37 * to be disabled, and 'message' is a message key for explaining the reason for disabling).
39 * @since 1.33
41 class DisabledSpecialPage extends UnlistedSpecialPage {
43 /** @var Message|string */
44 protected $errorMessage;
46 /**
47 * Create a callback suitable for use in $wgSpecialPages.
48 * @param string $name Canonical name of the special page that's being replaced.
49 * @param Message|string|null $errorMessage Error message to show when users try to use the page.
50 * @return Closure
52 public static function getCallback( $name, $errorMessage = null ) {
53 return static function () use ( $name, $errorMessage ) {
54 return new DisabledSpecialPage( $name, $errorMessage );
58 /**
59 * @param string $name Canonical name of the special page that's being replaced.
60 * @param Message|string|null $errorMessage Error message to show when users try to use the page.
62 public function __construct( $name, $errorMessage = null ) {
63 parent::__construct( $name );
64 $this->errorMessage = $errorMessage ?: 'disabledspecialpage-disabled';
67 public function execute( $subPage ) {
68 $this->setHeaders();
69 $this->outputHeader();
71 $this->getOutput()->addModuleStyles( 'mediawiki.codex.messagebox.styles' );
72 $this->getOutput()->addHTML( Html::errorBox(
73 $this->msg( $this->errorMessage )->parse()
74 ) );
79 /** @deprecated class alias since 1.41 */
80 class_alias( DisabledSpecialPage::class, 'DisabledSpecialPage' );