diff --git a/RELEASE-NOTES-1.40 b/RELEASE-NOTES-1.40 index 5f052573be1..da37cff73a1 100644 --- a/RELEASE-NOTES-1.40 +++ b/RELEASE-NOTES-1.40 @@ -62,6 +62,8 @@ For notes on 1.39.x and older releases, see HISTORY. * (T277618) The @noVarDump annotation from the DebugInfoTrait tool can now be added to references to stop them from being expanded when their object is passed to var_dump(), to make its use for debugging more feasible. +* Added 'GetBlockErrorMessageKey' hook, allow extensions' + block error messages to be received and displayed by BlockErrorFormatter. * … === External library changes in 1.40 === diff --git a/includes/Hook/GetBlockErrorMessageKey.php b/includes/Hook/GetBlockErrorMessageKey.php new file mode 100644 index 00000000000..182c0d00eb0 --- /dev/null +++ b/includes/Hook/GetBlockErrorMessageKey.php @@ -0,0 +1,27 @@ +container->run( + 'GetBlockErrorMessageKey', + [ $block, &$key ] + ); + } + public function onModifyExportQuery( $db, &$tables, $cond, &$opts, &$join_conds, &$conds ) { diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index c4a45623a05..66eb6439b57 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -297,7 +297,8 @@ return [ 'BlockErrorFormatter' => static function ( MediaWikiServices $services ): BlockErrorFormatter { return new BlockErrorFormatter( - $services->getTitleFormatter() + $services->getTitleFormatter(), + $services->getHookContainer() ); }, diff --git a/includes/block/BlockErrorFormatter.php b/includes/block/BlockErrorFormatter.php index 9c70508cb80..4726cc82f41 100644 --- a/includes/block/BlockErrorFormatter.php +++ b/includes/block/BlockErrorFormatter.php @@ -22,6 +22,8 @@ namespace MediaWiki\Block; use CommentStoreComment; use Language; +use MediaWiki\HookContainer\HookContainer; +use MediaWiki\HookContainer\HookRunner; use MediaWiki\Page\PageReferenceValue; use MediaWiki\User\UserIdentity; use Message; @@ -38,13 +40,19 @@ class BlockErrorFormatter { /** @var TitleFormatter */ private $titleFormatter; + /** @var HookRunner */ + private $hookRunner; + /** * @param TitleFormatter $titleFormatter + * @param HookContainer $hookContainer */ public function __construct( - TitleFormatter $titleFormatter + TitleFormatter $titleFormatter, + HookContainer $hookContainer ) { $this->titleFormatter = $titleFormatter; + $this->hookRunner = new HookRunner( $hookContainer ); } /** @@ -186,6 +194,10 @@ class BlockErrorFormatter { } elseif ( $block instanceof CompositeBlock ) { $key = 'blockedtext-composite'; } + + // runs a hook that allows extensions to check block characteristics + $this->hookRunner->onGetBlockErrorMessageKey( $block, $key ); + return $key; }