Merge "Remove redundant 'jquery.accessKeylabel' module alias"
[lhc/web/wiklou.git] / includes / specialpage / DisabledSpecialPage.php
1 <?php
2 /**
3 * Special page for replacing manually disabled special pages
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
24 /**
25 * This class is a drop-in replacement for other special pages that need to be manually
26 * disabled. To use it, just put something like
27 *
28 * $wgSpecialPages['Name'] = DisabledSpecialPage::getCallback( 'Name', 'message' );
29 *
30 * in the local configuration (where 'Name' is the canonical name of the special page
31 * to be disabled, and 'message' is a message key for explaining the reason for disabling).
32 *
33 * @since 1.33
34 */
35 class DisabledSpecialPage extends UnlistedSpecialPage {
36
37 /** @var Message */
38 protected $errorMessage;
39
40 /**
41 * Create a callback suitable for use in $wgSpecialPages.
42 * @param string $name Canonical name of the special page that's being replaced.
43 * @param Message|string|null $errorMessage Error message to show when users try to use the page.
44 * @return Closure
45 */
46 public static function getCallback( $name, $errorMessage = null ) {
47 return function () use ( $name, $errorMessage ) {
48 return new DisabledSpecialPage( $name, $errorMessage );
49 };
50 }
51
52 /**
53 * @param string $name Canonical name of the special page that's being replaced.
54 * @param Message|string|null $errorMessage Error message to show when users try to use the page.
55 */
56 public function __construct( $name, $errorMessage = null ) {
57 parent::__construct( $name );
58 $this->errorMessage = $errorMessage ?: 'disabledspecialpage-disabled';
59 }
60
61 public function execute( $subPage ) {
62 $this->setHeaders();
63 $this->outputHeader();
64
65 $error = Html::rawElement( 'div', [
66 'class' => 'error',
67 ], $this->msg( $this->errorMessage )->parseAsBlock() );
68 $this->getOutput()->addHTML( $error );
69 }
70
71 }