MediaWiki REL1_39
ApiBlockInfoTrait.php
Go to the documentation of this file.
1<?php
23
28
46 private function getBlockDetails(
47 Block $block,
48 $language = null
49 ) {
50 if ( $language === null ) {
51 $language = $this->getLanguage();
52 }
53
54 $blocker = $block->getBlocker();
55
56 $vals = [];
57 $vals['blockid'] = $block->getId();
58 $vals['blockedby'] = $blocker ? $blocker->getName() : '';
59 $vals['blockedbyid'] = $blocker ? $blocker->getId() : 0;
60 $vals['blockreason'] = $block->getReasonComment()
61 ->message->inLanguage( $language )->plain();
62 $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() );
63 $expiry = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
64 $vals['blockexpiry'] = $expiry;
65 $vals['blockpartial'] = !$block->isSitewide();
66 $vals['blocknocreate'] = $block->isCreateAccountBlocked();
67 $vals['blockanononly'] = !$block->isHardblock();
68
69 $user = $this->getUser();
70 // Formatted timestamps
71 $vals['blockedtimestampformatted'] = $language->formatExpiry(
72 $block->getTimestamp(), true, 'infinity', $user
73 );
74 if ( $expiry !== 'infinite' ) {
75 $vals['blockexpiryformatted'] = $language->formatExpiry(
76 $expiry, true, 'infinity', $user
77 );
78 $vals['blockexpiryrelative'] = $language->getHumanTimestamp(
79 new MWTimestamp( $expiry ), new MWTimestamp(), $user
80 );
81 }
82
83 if ( $block instanceof SystemBlock ) {
84 $vals['systemblocktype'] = $block->getSystemBlockType();
85 }
86
87 return $vals;
88 }
89
90 // region Methods required from ApiBase
99 abstract public function getLanguage();
100
105 abstract public function getUser();
106
108 // endregion -- end of methods required from ApiBase
109
110}
getUser()
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Library for creating and parsing MW-style timestamps.
System blocks are temporary blocks that are created on enforcement (e.g.
trait ApiBlockInfoTrait
Represents a block that may prevent users from performing specific operations.
Definition Block.php:40
isSitewide()
Indicates that the block is a sitewide block.
isHardblock()
Returns whether the block is a hardblock (affects logged-in users on a given IP/range)
getBlocker()
Get the user who applied this block.
getTimestamp()
Get the timestamp indicating when the block was created.
getId( $wikiId=self::LOCAL)
Get the block ID.
getReasonComment()
Get the reason for creating the block.
isCreateAccountBlocked()
Get the flag indicating whether this block blocks the target from creating an account.
getExpiry()
Get the block expiry time.