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 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @ingroup SpecialPage |
| 8 | */ |
| 9 | |
| 10 | namespace MediaWiki\SpecialPage; |
| 11 | |
| 12 | use Closure; |
| 13 | use MediaWiki\Html\Html; |
| 14 | use MediaWiki\Message\Message; |
| 15 | |
| 16 | /** |
| 17 | * This class is a drop-in replacement for other special pages that need to be manually |
| 18 | * disabled. To use it, just put something like |
| 19 | * |
| 20 | * $wgSpecialPages['Name'] = DisabledSpecialPage::getCallback( 'Name', 'message' ); |
| 21 | * |
| 22 | * in the local configuration (where 'Name' is the canonical name of the special page |
| 23 | * to be disabled, and 'message' is a message key for explaining the reason for disabling). |
| 24 | * |
| 25 | * @since 1.33 |
| 26 | */ |
| 27 | class DisabledSpecialPage extends UnlistedSpecialPage { |
| 28 | |
| 29 | /** @var Message|string */ |
| 30 | protected $errorMessage; |
| 31 | |
| 32 | /** |
| 33 | * Create a callback suitable for use in $wgSpecialPages. |
| 34 | * @param string $name Canonical name of the special page that's being replaced. |
| 35 | * @param Message|string|null $errorMessage Error message to show when users try to use the page. |
| 36 | * @return Closure |
| 37 | */ |
| 38 | public static function getCallback( $name, $errorMessage = null ) { |
| 39 | return static function () use ( $name, $errorMessage ) { |
| 40 | return new DisabledSpecialPage( $name, $errorMessage ); |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @param string $name Canonical name of the special page that's being replaced. |
| 46 | * @param Message|string|null $errorMessage Error message to show when users try to use the page. |
| 47 | */ |
| 48 | public function __construct( $name, $errorMessage = null ) { |
| 49 | parent::__construct( $name ); |
| 50 | $this->errorMessage = $errorMessage ?: 'disabledspecialpage-disabled'; |
| 51 | } |
| 52 | |
| 53 | /** @inheritDoc */ |
| 54 | public function execute( $subPage ) { |
| 55 | $this->setHeaders(); |
| 56 | $this->outputHeader(); |
| 57 | |
| 58 | $this->getOutput()->addModuleStyles( 'mediawiki.codex.messagebox.styles' ); |
| 59 | $this->getOutput()->addHTML( Html::errorBox( |
| 60 | $this->msg( $this->errorMessage )->parse() |
| 61 | ) ); |
| 62 | } |
| 63 | |
| 64 | } |
| 65 | |
| 66 | /** @deprecated class alias since 1.41 */ |
| 67 | class_alias( DisabledSpecialPage::class, 'DisabledSpecialPage' ); |