42 private $titleFormatter;
50 private $userIdentityUtils;
62 $this->titleFormatter = $titleFormatter;
63 $this->hookRunner =
new HookRunner( $hookContainer );
64 $this->userIdentityUtils = $userIdentityUtils;
84 $key = $this->getBlockErrorMessageKey( $block, $user );
85 $params = $this->getBlockErrorMessageParams( $block, $user, $language, $ip );
86 return new Message( $key, $params );
101 private function getBlockErrorInfo(
Block $block ) {
106 'blockerName' => $blocker ? $blocker->getName() :
'',
123 private function getFormattedBlockErrorInfo(
128 $info = $this->getBlockErrorInfo( $block );
130 $info[
'expiry'] = $language->
formatExpiry( $info[
'expiry'],
true,
'infinity', $user );
131 $info[
'timestamp'] = $language->
userTimeAndDate( $info[
'timestamp'], $user );
132 $info[
'blockerName'] = $language->
embedBidi( $info[
'blockerName'] );
133 $info[
'targetName'] = $language->
embedBidi( $info[
'targetName'] );
135 $info[
'reason'] = $this->formatBlockReason( $info[
'reason'], $language );
147 private function formatBlockReason( CommentStoreComment $reason,
Language $language ) {
148 if ( $reason->text ===
'' ) {
149 $message =
new Message(
'blockednoreason', [], $language );
150 return $message->plain();
152 return $reason->message->inLanguage( $language )->plain();
164 private function formatBlockerLink( ?UserIdentity $blocker,
Language $language ) {
171 if ( $blocker->getId() === 0 ) {
176 return $language->
embedBidi( $blocker->getName() );
179 $blockerUserpage = PageReferenceValue::localReference(
NS_USER, $blocker->getName() );
181 $this->titleFormatter->getText( $blockerUserpage )
183 $prefixedText = $this->titleFormatter->getPrefixedText( $blockerUserpage );
184 return "[[{$prefixedText}|{$blockerText}]]";
194 private function getBlockErrorMessageKey( Block $block, UserIdentity $user ) {
195 $isTempUser = $this->userIdentityUtils->isTemp( $user );
196 $key = $isTempUser ?
'blockedtext-tempuser' :
'blockedtext';
197 if ( $block instanceof DatabaseBlock ) {
199 $key = $isTempUser ?
'autoblockedtext-tempuser' :
'autoblockedtext';
200 } elseif ( !$block->isSitewide() ) {
201 $key =
'blockedtext-partial';
203 } elseif ( $block instanceof SystemBlock ) {
204 $key =
'systemblockedtext';
205 } elseif ( $block instanceof CompositeBlock ) {
206 $key =
'blockedtext-composite';
210 $this->hookRunner->onGetBlockErrorMessageKey( $block, $key );
233 private function getBlockErrorMessageParams(
239 $info = $this->getFormattedBlockErrorInfo( $block, $user, $language );
243 $info[
'blockerLink'] = $this->formatBlockerLink(
244 $block->getBlocker(),
249 if ( $block instanceof CompositeBlock ) {
251 static function ( $id ) {
254 array_filter( $info[
'identifier'],
'is_int' )
257 $idsMsg =
new Message(
'blockedtext-composite-no-ids', [], $language );
259 $idsMsg =
new Message(
'blockedtext-composite-ids', [ $ids ], $language );
261 $info[
'identifier'] = $idsMsg->plain();
277 foreach ( $order as $item ) {
278 $params[] = $info[$item];
Base class for language-specific code.
formatExpiry( $expiry, $format=true, $infinity='infinity', $user=null)
Decode an expiry (block, protection, etc.) which has come from the DB.
embedBidi( $text='')
Wraps argument with unicode control characters for directionality safety.
userTimeAndDate( $ts, UserIdentity $user, array $options=[])
Get the formatted date and time for the given timestamp and formatted for the given user.
commaList(array $list)
Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separa...
The Message class deals with fetching and processing of interface message into a variety of formats.