MediaWiki master
BlockActionInfo.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Block;
22
25use UnexpectedValueException;
26
41 private HookRunner $hookRunner;
42
44 public const ACTION_UPLOAD = 1;
45
47 public const ACTION_MOVE = 2;
48
50 public const ACTION_CREATE = 3;
51
65 private const CORE_BLOCK_ACTIONS = [
66 'upload' => self::ACTION_UPLOAD,
67 'move' => self::ACTION_MOVE,
68 'create' => self::ACTION_CREATE,
69 ];
70
71 public function __construct( HookContainer $hookContainer ) {
72 $this->hookRunner = new HookRunner( $hookContainer );
73 }
74
79 private $allBlockActions = null;
80
84 public function getAllBlockActions(): array {
85 // Don't run the hook multiple times in the same request
86 if ( !$this->allBlockActions ) {
87 $this->allBlockActions = self::CORE_BLOCK_ACTIONS;
88 $this->hookRunner->onGetAllBlockActions( $this->allBlockActions );
89 }
90 if ( count( $this->allBlockActions ) !== count( array_unique( $this->allBlockActions ) ) ) {
91 throw new UnexpectedValueException( 'Blockable action IDs not unique' );
92 }
93 return $this->allBlockActions;
94 }
95
100 public function getActionFromId( int $actionId ) {
101 return array_search( $actionId, $this->getAllBlockActions() );
102 }
103
108 public function getIdFromAction( string $action ) {
109 return $this->getAllBlockActions()[$action] ?? false;
110 }
111
112}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
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...