Create Hook to check block's error messages from extensions
Bug: T317201 Change-Id: I1c20e7e62e0f2b453735689e3dc543164b5fd067
This commit is contained in:
parent
d96207ab86
commit
cc55e848e4
5 changed files with 52 additions and 2 deletions
|
|
@ -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 ===
|
||||
|
|
|
|||
27
includes/Hook/GetBlockErrorMessageKey.php
Normal file
27
includes/Hook/GetBlockErrorMessageKey.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Hook;
|
||||
|
||||
use MediaWiki\Block\Block;
|
||||
|
||||
/**
|
||||
* This is a hook handler interface, see docs/Hooks.md.
|
||||
* Use the hook name "GetBlockErrorMessageKey" to register handlers implementing this interface.
|
||||
*
|
||||
* @stable to implement
|
||||
* @ingroup Hooks
|
||||
*/
|
||||
interface GetBlockErrorMessageKey {
|
||||
/**
|
||||
* This hook is called in BlockErrorFormatter to allow
|
||||
* extensions to override the message that will be displayed
|
||||
* to the user.
|
||||
*
|
||||
* @since 1.40
|
||||
*
|
||||
* @param Block $block
|
||||
* @param string &$key
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public function onGetBlockErrorMessageKey( $block, &$key );
|
||||
}
|
||||
|
|
@ -182,6 +182,7 @@ class HookRunner implements
|
|||
\MediaWiki\Hook\FileUploadHook,
|
||||
\MediaWiki\Hook\FormatAutocommentsHook,
|
||||
\MediaWiki\Hook\GalleryGetModesHook,
|
||||
\MediaWiki\Hook\GetBlockErrorMessageKey,
|
||||
\MediaWiki\Hook\GetCacheVaryCookiesHook,
|
||||
\MediaWiki\Hook\GetCanonicalURLHook,
|
||||
\MediaWiki\Hook\GetDefaultSortkeyHook,
|
||||
|
|
@ -2589,6 +2590,13 @@ class HookRunner implements
|
|||
);
|
||||
}
|
||||
|
||||
public function onGetBlockErrorMessageKey( $block, &$key ) {
|
||||
return $this->container->run(
|
||||
'GetBlockErrorMessageKey',
|
||||
[ $block, &$key ]
|
||||
);
|
||||
}
|
||||
|
||||
public function onModifyExportQuery( $db, &$tables, $cond, &$opts,
|
||||
&$join_conds, &$conds
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -297,7 +297,8 @@ return [
|
|||
|
||||
'BlockErrorFormatter' => static function ( MediaWikiServices $services ): BlockErrorFormatter {
|
||||
return new BlockErrorFormatter(
|
||||
$services->getTitleFormatter()
|
||||
$services->getTitleFormatter(),
|
||||
$services->getHookContainer()
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue