MediaWiki  master
SpecialPageAction.php
Go to the documentation of this file.
1 <?php
22 
33  public static $actionToSpecialPageMapping = [
34  'revisiondelete' => 'Revisiondelete',
35  'editchangetags' => 'EditTags',
36  ];
37 
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';
50  }
51  }
52 
53  if ( isset( self::$actionToSpecialPageMapping[$actionName] ) ) {
54  return $actionName;
55  }
56 
57  return 'nosuchaction';
58  }
59 
60  public function requiresUnblock() {
61  return false;
62  }
63 
64  public function getDescription() {
65  return '';
66  }
67 
68  public function onView() {
69  return '';
70  }
71 
72  public function show() {
73  $special = $this->getSpecialPage();
74  if ( !$special ) {
75  throw new ErrorPageError(
76  $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
77  }
78 
79  $special->setContext( $this->getContext() );
80  $special->getContext()->setTitle( $special->getPageTitle() );
81  $special->run( '' );
82  }
83 
84  public function doesWrites() {
85  $special = $this->getSpecialPage();
86 
87  return $special ? $special->doesWrites() : false;
88  }
89 
93  protected function getSpecialPage() {
94  $action = $this->getName();
95  if ( $action === 'nosuchaction' ) {
96  return null;
97  }
98 
99  // map actions to (whitelisted) special pages
100  return MediaWikiServices::getInstance()->getSpecialPageFactory()->
101  getPage( self::$actionToSpecialPageMapping[$action] );
102  }
103 }
FormlessAction
An action which just does something, without showing a form first.
Definition: FormlessAction.php:28
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:146
Action\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:227
SpecialPageAction\onView
onView()
Show something on GET request.
Definition: SpecialPageAction.php:68
Action\getContext
getContext()
Get the IContextSource in use here.
Definition: Action.php:213
SpecialPageAction
An action that just passes the request to the relevant special page.
Definition: SpecialPageAction.php:29
SpecialPageAction\getName
getName()
Return the name of the action this object responds to.1.17string Lowercase name
Definition: SpecialPageAction.php:41
SpecialPageAction\$actionToSpecialPageMapping
static array $actionToSpecialPageMapping
A mapping of action names to special page names.
Definition: SpecialPageAction.php:33
SpecialPageAction\requiresUnblock
requiresUnblock()
Whether this action can still be executed by a blocked user.
Definition: SpecialPageAction.php:60
SpecialPageAction\doesWrites
doesWrites()
Indicates whether this action may perform database writes.
Definition: SpecialPageAction.php:84
Action\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:309
SpecialPageAction\getSpecialPage
getSpecialPage()
Definition: SpecialPageAction.php:93
SpecialPageAction\show
show()
The main action entry point.
Definition: SpecialPageAction.php:72
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
SpecialPageAction\getDescription
getDescription()
Returns the description that goes below the <h1> tag.
Definition: SpecialPageAction.php:64