MediaWiki REL1_39
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 }
99 return $this->allBlockActions;
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(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition WebStart.php:82
MediaWiki exception.
Defines the actions that can be blocked by a partial block.
__construct(HookContainer $hookContainer)
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...