MediaWiki REL1_37
BlockActionInfo.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Block;
22
25use 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}
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Definition Setup.php:88
MediaWiki exception.
Defines the actions that can be blocked by a partial block.
int[] null $allBlockActions
Cache the array of actions.
__construct(HookContainer $hookContainer)
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...