aboutsummaryrefslogtreecommitdiffstats
path: root/includes/block/BlockErrorFormatter.php
diff options
context:
space:
mode:
authorThalia <thalia.e.chan@googlemail.com>2023-10-26 15:38:48 +0100
committerThalia <thalia.e.chan@googlemail.com>2023-10-27 13:05:08 +0100
commite521abbcd8d102aa6a3f722f2bd9f649bfd0210c (patch)
treec7c48cb2c16031a5d2eb6bf026d1afd438ed7496 /includes/block/BlockErrorFormatter.php
parent24a3dc58d6bba1844e9f30ba52bdb18ff58fc54c (diff)
downloadmediawikicore-e521abbcd8d102aa6a3f722f2bd9f649bfd0210c.tar.gz
mediawikicore-e521abbcd8d102aa6a3f722f2bd9f649bfd0210c.zip
Display all error messages for a CompositeBlock
* Add getMessages method to BlockErrorFormatter that will get error messages for all the applicable blocks. * Call getMessages from PermissionManager, UserAuthority and EditPage. * ApiBase and UserBlockedError still call getMessage since they work with a single message. Bug: T344463 Change-Id: If240562dd25435d9c6c824dd595d58bb8672de2b
Diffstat (limited to 'includes/block/BlockErrorFormatter.php')
-rw-r--r--includes/block/BlockErrorFormatter.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/includes/block/BlockErrorFormatter.php b/includes/block/BlockErrorFormatter.php
index c7b699cbf92e..afcfae73e5fe 100644
--- a/includes/block/BlockErrorFormatter.php
+++ b/includes/block/BlockErrorFormatter.php
@@ -69,6 +69,9 @@ class BlockErrorFormatter {
* block features. Message parameters are formatted for the specified user and
* language.
*
+ * If passed a CompositeBlock, will get a generic message stating that there are
+ * multiple blocks. To get all the block messages, use getMessages instead.
+ *
* @param Block $block
* @param UserIdentity $user
* @param Language $language
@@ -87,6 +90,30 @@ class BlockErrorFormatter {
}
/**
+ * Get block error messages for all of the blocks that apply to a user.
+ *
+ * @since 1.42
+ * @param Block $block
+ * @param UserIdentity $user
+ * @param Language $language
+ * @param string $ip
+ * @return Message[]
+ */
+ public function getMessages(
+ Block $block,
+ UserIdentity $user,
+ Language $language,
+ string $ip
+ ): array {
+ $messages = [];
+ foreach ( $block->toArray() as $singleBlock ) {
+ $messages[] = $this->getMessage( $singleBlock, $user, $language, $ip );
+ }
+
+ return $messages;
+ }
+
+ /**
* Get a standard set of block details for building a block error message.
*
* @param Block $block