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 
40 
42  private $actionName;
43 
50  public function __construct(
51  Page $page,
54  string $actionName
55  ) {
56  parent::__construct( $page, $context );
57  $this->specialPageFactory = $specialPageFactory;
58  if ( !isset( self::$actionToSpecialPageMapping[$actionName] ) ) {
59  throw new InvalidArgumentException(
60  __CLASS__ . " does not support the action $actionName"
61  );
62  }
63  $this->actionName = $actionName;
64  }
65 
69  public function getName() {
70  return $this->actionName;
71  }
72 
73  public function requiresUnblock() {
74  return false;
75  }
76 
77  public function getDescription() {
78  return '';
79  }
80 
81  public function onView() {
82  return '';
83  }
84 
85  public function show() {
86  $special = $this->getSpecialPage();
87  if ( !$special ) {
88  throw new ErrorPageError(
89  $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
90  }
91 
92  $special->setContext( $this->getContext() );
93  $special->getContext()->setTitle( $special->getPageTitle() );
94  $special->run( '' );
95  }
96 
97  public function doesWrites() {
98  $special = $this->getSpecialPage();
99 
100  return $special ? $special->doesWrites() : false;
101  }
102 
106  protected function getSpecialPage() {
107  // map actions to (allowed) special pages
108  return $this->specialPageFactory->getPage(
109  self::$actionToSpecialPageMapping[$this->actionName]
110  );
111  }
112 }
Page
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition: Page.php:29
FormlessAction
An action which just does something, without showing a form first.
Definition: FormlessAction.php:30
SpecialPageAction\onView
onView()
Show something on GET request.
Definition: SpecialPageAction.php:81
MediaWiki\SpecialPage\SpecialPageFactory
Factory for handling the special page list and generating SpecialPage objects.
Definition: SpecialPageFactory.php:64
Action\getContext
getContext()
Get the IContextSource in use here.
Definition: Action.php:132
SpecialPageAction
An action that just passes the request to the relevant special page.
Definition: SpecialPageAction.php:29
SpecialPageAction\$specialPageFactory
SpecialPageFactory $specialPageFactory
Definition: SpecialPageAction.php:39
SpecialPageAction\getName
getName()
Return the name of the action this object responds to.1.17string Lowercase name
Definition: SpecialPageAction.php:69
Action\$context
IContextSource $context
IContextSource if specified; otherwise we'll use the Context from the Page.
Definition: Action.php:66
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:73
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
SpecialPageAction\doesWrites
doesWrites()
Indicates whether this action may perform database writes.
Definition: SpecialPageAction.php:97
SpecialPageAction\__construct
__construct(Page $page, IContextSource $context, SpecialPageFactory $specialPageFactory, string $actionName)
Definition: SpecialPageAction.php:50
Action\$page
WikiPage Article ImagePage CategoryPage Page $page
Page on which we're performing the action.
Definition: Action.php:53
Action\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:228
SpecialPageAction\getSpecialPage
getSpecialPage()
Definition: SpecialPageAction.php:106
SpecialPageAction\$actionName
string $actionName
Name of this action, must exist as a key in $actionToSpecialPageMapping.
Definition: SpecialPageAction.php:42
SpecialPageAction\show
show()
Definition: SpecialPageAction.php:85
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:30
SpecialPageAction\getDescription
getDescription()
Returns the description that goes below the <h1> tag.
Definition: SpecialPageAction.php:77