DisabledSpecialPage.php 2.4 KB

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