SpecialPageAction.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. public function getName() {
  36. $request = $this->getRequest();
  37. $actionName = $request->getVal( 'action', 'view' );
  38. // TODO: Shouldn't need to copy-paste this code from Action::getActionName!
  39. if ( $actionName === 'historysubmit' ) {
  40. if ( $request->getBool( 'revisiondelete' ) ) {
  41. $actionName = 'revisiondelete';
  42. } elseif ( $request->getBool( 'editchangetags' ) ) {
  43. $actionName = 'editchangetags';
  44. }
  45. }
  46. if ( isset( self::$actionToSpecialPageMapping[$actionName] ) ) {
  47. return $actionName;
  48. }
  49. return 'nosuchaction';
  50. }
  51. public function requiresUnblock() {
  52. return false;
  53. }
  54. public function getDescription() {
  55. return '';
  56. }
  57. public function onView() {
  58. return '';
  59. }
  60. public function show() {
  61. $special = $this->getSpecialPage();
  62. if ( !$special ) {
  63. throw new ErrorPageError(
  64. $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
  65. }
  66. $special->setContext( $this->getContext() );
  67. $special->getContext()->setTitle( $special->getPageTitle() );
  68. $special->run( '' );
  69. }
  70. public function doesWrites() {
  71. $special = $this->getSpecialPage();
  72. return $special ? $special->doesWrites() : false;
  73. }
  74. /**
  75. * @return SpecialPage|null
  76. */
  77. protected function getSpecialPage() {
  78. $action = $this->getName();
  79. if ( $action === 'nosuchaction' ) {
  80. return null;
  81. }
  82. // map actions to (whitelisted) special pages
  83. return MediaWikiServices::getInstance()->getSpecialPageFactory()->
  84. getPage( self::$actionToSpecialPageMapping[$action] );
  85. }
  86. }