MediaWiki  master
BlockActionInfo.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Block;
22 
25 use MWException;
26 
42  private $hookRunner;
43 
45  private const ACTION_UPLOAD = 1;
46 
48  private const ACTION_MOVE = 2;
49 
51  private const ACTION_CREATE = 3;
52 
68  private const CORE_BLOCK_ACTIONS = [
69  'upload' => self::ACTION_UPLOAD,
70  'move' => self::ACTION_MOVE,
71  'create' => self::ACTION_CREATE,
72  ];
73 
77  public function __construct( HookContainer $hookContainer ) {
78  $this->hookRunner = new HookRunner( $hookContainer );
79  }
80 
85  private $allBlockActions = null;
86 
90  public function getAllBlockActions(): array {
91  // Don't run the hook multiple times in the same request
92  if ( !$this->allBlockActions ) {
93  $this->allBlockActions = self::CORE_BLOCK_ACTIONS;
94  $this->hookRunner->onGetAllBlockActions( $this->allBlockActions );
95  }
96  if ( count( $this->allBlockActions ) !== count( array_unique( $this->allBlockActions ) ) ) {
97  throw new MWException( 'Blockable action IDs not unique' );
98  }
100  }
101 
106  public function getActionFromId( int $actionId ) {
107  return array_search( $actionId, $this->getAllBlockActions() );
108  }
109 
114  public function getIdFromAction( string $action ) {
115  return $this->getAllBlockActions()[$action] ?? false;
116  }
117 
118 }
MediaWiki\Block\BlockActionInfo\getActionFromId
getActionFromId(int $actionId)
Definition: BlockActionInfo.php:106
MediaWiki\Block
Definition: AbstractBlock.php:21
MediaWiki\Block\BlockActionInfo\getIdFromAction
getIdFromAction(string $action)
Definition: BlockActionInfo.php:114
MediaWiki\Block\BlockActionInfo\__construct
__construct(HookContainer $hookContainer)
Definition: BlockActionInfo.php:77
MWException
MediaWiki exception.
Definition: MWException.php:29
MediaWiki\Block\BlockActionInfo
Defines the actions that can be blocked by a partial block.
Definition: BlockActionInfo.php:40
MediaWiki\Block\BlockActionInfo\$hookRunner
HookRunner $hookRunner
Definition: BlockActionInfo.php:42
MediaWiki\$action
string $action
Cache what action this request is.
Definition: MediaWiki.php:45
MediaWiki\Block\BlockActionInfo\getAllBlockActions
getAllBlockActions()
Definition: BlockActionInfo.php:90
MediaWiki\Block\BlockActionInfo\$allBlockActions
int[] null $allBlockActions
Cache the array of actions.
Definition: BlockActionInfo.php:85
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:45
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:556