MediaWiki master
BlockActionInfo.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Block;
8
11use UnexpectedValueException;
12
27 private HookRunner $hookRunner;
28
30 public const ACTION_UPLOAD = 1;
31
33 public const ACTION_MOVE = 2;
34
36 public const ACTION_CREATE = 3;
37
51 private const CORE_BLOCK_ACTIONS = [
52 'upload' => self::ACTION_UPLOAD,
53 'move' => self::ACTION_MOVE,
54 'create' => self::ACTION_CREATE,
55 ];
56
57 public function __construct( HookContainer $hookContainer ) {
58 $this->hookRunner = new HookRunner( $hookContainer );
59 }
60
65 private $allBlockActions = null;
66
70 public function getAllBlockActions(): array {
71 // Don't run the hook multiple times in the same request
72 if ( !$this->allBlockActions ) {
73 $this->allBlockActions = self::CORE_BLOCK_ACTIONS;
74 $this->hookRunner->onGetAllBlockActions( $this->allBlockActions );
75 }
76 if ( count( $this->allBlockActions ) !== count( array_unique( $this->allBlockActions ) ) ) {
77 throw new UnexpectedValueException( 'Blockable action IDs not unique' );
78 }
79 return $this->allBlockActions;
80 }
81
86 public function getActionFromId( int $actionId ) {
87 return array_search( $actionId, $this->getAllBlockActions() );
88 }
89
94 public function getIdFromAction( string $action ) {
95 return $this->getAllBlockActions()[$action] ?? false;
96 }
97
98}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:69
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...