Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
DisabledSpecialPage | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
getCallback | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
execute | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
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 | namespace MediaWiki\SpecialPage; |
25 | |
26 | use Closure; |
27 | use MediaWiki\Html\Html; |
28 | use MediaWiki\Message\Message; |
29 | |
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 |
33 | * |
34 | * $wgSpecialPages['Name'] = DisabledSpecialPage::getCallback( 'Name', 'message' ); |
35 | * |
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). |
38 | * |
39 | * @since 1.33 |
40 | */ |
41 | class DisabledSpecialPage extends UnlistedSpecialPage { |
42 | |
43 | /** @var Message */ |
44 | protected $errorMessage; |
45 | |
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 |
51 | */ |
52 | public static function getCallback( $name, $errorMessage = null ) { |
53 | return static function () use ( $name, $errorMessage ) { |
54 | return new DisabledSpecialPage( $name, $errorMessage ); |
55 | }; |
56 | } |
57 | |
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. |
61 | */ |
62 | public function __construct( $name, $errorMessage = null ) { |
63 | parent::__construct( $name ); |
64 | $this->errorMessage = $errorMessage ?: 'disabledspecialpage-disabled'; |
65 | } |
66 | |
67 | public function execute( $subPage ) { |
68 | $this->setHeaders(); |
69 | $this->outputHeader(); |
70 | |
71 | $error = Html::rawElement( 'div', [ |
72 | 'class' => 'error', |
73 | ], $this->msg( $this->errorMessage )->parseAsBlock() ); |
74 | $this->getOutput()->addHTML( $error ); |
75 | } |
76 | |
77 | } |
78 | |
79 | /** @deprecated class alias since 1.41 */ |
80 | class_alias( DisabledSpecialPage::class, 'DisabledSpecialPage' ); |