SpecialPageAction.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  16. *
  17. * @file
  18. * @ingroup Actions
  19. */
  20. use MediaWiki\MediaWikiServices;
  21. /**
  22. * An action that just passes the request to the relevant special page
  23. *
  24. * @ingroup Actions
  25. * @since 1.25
  26. */
  27. class SpecialPageAction extends FormlessAction {
  28. /**
  29. * @var array A mapping of action names to special page names.
  30. */
  31. public static $actionToSpecialPageMapping = [
  32. 'revisiondelete' => 'Revisiondelete',
  33. 'editchangetags' => 'EditTags',
  34. ];
  35. /**
  36. * @inheritDoc
  37. */
  38. public function getName() {
  39. $request = $this->getRequest();
  40. $actionName = $request->getVal( 'action', 'view' );
  41. // TODO: Shouldn't need to copy-paste this code from Action::getActionName!
  42. if ( $actionName === 'historysubmit' ) {
  43. if ( $request->getBool( 'revisiondelete' ) ) {
  44. $actionName = 'revisiondelete';
  45. } elseif ( $request->getBool( 'editchangetags' ) ) {
  46. $actionName = 'editchangetags';
  47. }
  48. }
  49. if ( isset( self::$actionToSpecialPageMapping[$actionName] ) ) {
  50. return $actionName;
  51. }
  52. return 'nosuchaction';
  53. }
  54. public function requiresUnblock() {
  55. return false;
  56. }
  57. public function getDescription() {
  58. return '';
  59. }
  60. public function onView() {
  61. return '';
  62. }
  63. public function show() {
  64. $special = $this->getSpecialPage();
  65. if ( !$special ) {
  66. throw new ErrorPageError(
  67. $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
  68. }
  69. $special->setContext( $this->getContext() );
  70. $special->getContext()->setTitle( $special->getPageTitle() );
  71. $special->run( '' );
  72. }
  73. public function doesWrites() {
  74. $special = $this->getSpecialPage();
  75. return $special ? $special->doesWrites() : false;
  76. }
  77. /**
  78. * @return SpecialPage|null
  79. */
  80. protected function getSpecialPage() {
  81. $action = $this->getName();
  82. if ( $action === 'nosuchaction' ) {
  83. return null;
  84. }
  85. // map actions to (whitelisted) special pages
  86. return MediaWikiServices::getInstance()->getSpecialPageFactory()->
  87. getPage( self::$actionToSpecialPageMapping[$action] );
  88. }
  89. }