MediaWiki  master
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  $language ??= $this->getLanguage();
51 
52  $blocker = $block->getBlocker();
53 
54  $vals = [];
55  $vals['blockid'] = $block->getId();
56  $vals['blockedby'] = $blocker ? $blocker->getName() : '';
57  $vals['blockedbyid'] = $blocker ? $blocker->getId() : 0;
58  $vals['blockreason'] = $block->getReasonComment()
59  ->message->inLanguage( $language )->plain();
60  $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() );
61  $expiry = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
62  $vals['blockexpiry'] = $expiry;
63  $vals['blockpartial'] = !$block->isSitewide();
64  $vals['blocknocreate'] = $block->isCreateAccountBlocked();
65  $vals['blockanononly'] = !$block->isHardblock();
66 
67  $user = $this->getUser();
68  // Formatted timestamps
69  $vals['blockedtimestampformatted'] = $language->formatExpiry(
70  $block->getTimestamp(), true, 'infinity', $user
71  );
72  if ( $expiry !== 'infinite' ) {
73  $vals['blockexpiryformatted'] = $language->formatExpiry(
74  $expiry, true, 'infinity', $user
75  );
76  $vals['blockexpiryrelative'] = $language->getHumanTimestamp(
77  new MWTimestamp( $expiry ), new MWTimestamp(), $user
78  );
79  }
80 
81  if ( $block instanceof SystemBlock ) {
82  $vals['systemblocktype'] = $block->getSystemBlockType();
83  }
84 
85  return $vals;
86  }
87 
88  // region Methods required from ApiBase
97  abstract public function getLanguage();
98 
103  abstract public function getUser();
104 
106  // endregion -- end of methods required from ApiBase
107 
108 }
getUser()
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static formatExpiry( $expiry, $infinity='infinity')
Format an expiry timestamp for API output.
Definition: ApiResult.php:1199
Library for creating and parsing MW-style timestamps.
Definition: MWTimestamp.php:40
System blocks are temporary blocks that are created on enforcement (e.g.
Definition: SystemBlock.php:36
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.