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.
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.
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
21 use MediaWiki\MediaWikiServices
;
24 * An action that just passes the request to the relevant special page
29 class SpecialPageAction
extends FormlessAction
{
31 * @var array A mapping of action names to special page names.
33 public static $actionToSpecialPageMapping = [
34 'revisiondelete' => 'Revisiondelete',
35 'editchangetags' => 'EditTags',
41 public function getName() {
42 $request = $this->getRequest();
43 $actionName = $request->getVal( 'action', 'view' );
44 // TODO: Shouldn't need to copy-paste this code from Action::getActionName!
45 if ( $actionName === 'historysubmit' ) {
46 if ( $request->getBool( 'revisiondelete' ) ) {
47 $actionName = 'revisiondelete';
48 } elseif ( $request->getBool( 'editchangetags' ) ) {
49 $actionName = 'editchangetags';
53 if ( isset( self
::$actionToSpecialPageMapping[$actionName] ) ) {
57 return 'nosuchaction';
60 public function requiresUnblock() {
64 public function getDescription() {
68 public function onView() {
72 public function show() {
73 $special = $this->getSpecialPage();
75 throw new ErrorPageError(
76 $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
79 $special->setContext( $this->getContext() );
80 $special->getContext()->setTitle( $special->getPageTitle() );
84 public function doesWrites() {
85 $special = $this->getSpecialPage();
87 return $special ?
$special->doesWrites() : false;
91 * @return SpecialPage|null
93 protected function getSpecialPage() {
94 $action = $this->getName();
95 if ( $action === 'nosuchaction' ) {
99 // map actions to (whitelisted) special pages
100 return MediaWikiServices
::getInstance()->getSpecialPageFactory()->
101 getPage( self
::$actionToSpecialPageMapping[$action] );