42 private $titleFormatter;
50 private $userIdentityUtils;
62 $this->titleFormatter = $titleFormatter;
63 $this->hookRunner =
new HookRunner( $hookContainer );
64 $this->userIdentityUtils = $userIdentityUtils;
87 $key = $this->getBlockErrorMessageKey( $block, $user );
88 $params = $this->getBlockErrorMessageParams( $block, $user, $language, $ip );
89 return new Message( $key, $params );
109 foreach ( $block->
toArray() as $singleBlock ) {
110 $messages[] = $this->getMessage( $singleBlock, $user, $language, $ip );
128 private function getBlockErrorInfo( Block $block ) {
129 $blocker = $block->getBlocker();
131 'identifier' => $block->getIdentifier(),
132 'targetName' => $block->getTargetName(),
133 'blockerName' => $blocker ? $blocker->getName() :
'',
134 'reason' => $block->getReasonComment(),
135 'expiry' => $block->getExpiry(),
136 'timestamp' => $block->getTimestamp(),
150 private function getFormattedBlockErrorInfo(
155 $info = $this->getBlockErrorInfo( $block );
157 $info[
'expiry'] = $language->
formatExpiry( $info[
'expiry'],
true,
'infinity', $user );
158 $info[
'timestamp'] = $language->
userTimeAndDate( $info[
'timestamp'], $user );
159 $info[
'blockerName'] = $language->
embedBidi( $info[
'blockerName'] );
160 $info[
'targetName'] = $language->
embedBidi( $info[
'targetName'] );
162 $info[
'reason'] = $this->formatBlockReason( $info[
'reason'], $language );
174 private function formatBlockReason( CommentStoreComment $reason,
Language $language ) {
175 if ( $reason->text ===
'' ) {
176 $message =
new Message(
'blockednoreason', [], $language );
177 return $message->plain();
179 return $reason->message->inLanguage( $language )->plain();
191 private function formatBlockerLink( ?UserIdentity $blocker,
Language $language ) {
198 if ( $blocker->getId() === 0 ) {
203 return $language->
embedBidi( $blocker->getName() );
206 $blockerUserpage = PageReferenceValue::localReference(
NS_USER, $blocker->getName() );
208 $this->titleFormatter->getText( $blockerUserpage )
210 $prefixedText = $this->titleFormatter->getPrefixedText( $blockerUserpage );
211 return "[[{$prefixedText}|{$blockerText}]]";
221 private function getBlockErrorMessageKey( Block $block, UserIdentity $user ) {
222 $isTempUser = $this->userIdentityUtils->isTemp( $user );
223 $key = $isTempUser ?
'blockedtext-tempuser' :
'blockedtext';
224 if ( $block instanceof DatabaseBlock ) {
225 if ( $block->getType() === Block::TYPE_AUTO ) {
226 $key = $isTempUser ?
'autoblockedtext-tempuser' :
'autoblockedtext';
227 } elseif ( !$block->isSitewide() ) {
228 $key =
'blockedtext-partial';
230 } elseif ( $block instanceof SystemBlock ) {
231 $key =
'systemblockedtext';
232 } elseif ( $block instanceof CompositeBlock ) {
233 $key =
'blockedtext-composite';
237 $this->hookRunner->onGetBlockErrorMessageKey( $block, $key );
260 private function getBlockErrorMessageParams(
266 $info = $this->getFormattedBlockErrorInfo( $block, $user, $language );
270 $info[
'blockerLink'] = $this->formatBlockerLink(
271 $block->getBlocker(),
276 if ( $block instanceof CompositeBlock ) {
278 static function ( $id ) {
281 array_filter( $info[
'identifier'],
'is_int' )
284 $idsMsg =
new Message(
'blockedtext-composite-no-ids', [], $language );
286 $idsMsg =
new Message(
'blockedtext-composite-ids', [ $ids ], $language );
288 $info[
'identifier'] = $idsMsg->plain();
304 foreach ( $order as $item ) {
305 $params[] = $info[$item];
formatExpiry( $expiry, $format=true, $infinity='infinity', $user=null)
Decode an expiry (block, protection, etc.) which has come from the DB.