MediaWiki  master
ApiBlockInfoTrait.php
Go to the documentation of this file.
1 <?php
27 
32 
50  private function getBlockDetails(
51  Block $block,
52  $language = null
53  ) {
54  $language ??= $this->getLanguage();
55 
56  $blocker = $block->getBlocker();
57 
58  $vals = [];
59  $vals['blockid'] = $block->getId();
60  $vals['blockedby'] = $blocker ? $blocker->getName() : '';
61  $vals['blockedbyid'] = $blocker ? $blocker->getId() : 0;
62  $vals['blockreason'] = $block->getReasonComment()
63  ->message->inLanguage( $language )->plain();
64  $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() );
65  $expiry = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
66  $vals['blockexpiry'] = $expiry;
67  $vals['blockpartial'] = !$block->isSitewide();
68  $vals['blocknocreate'] = $block->isCreateAccountBlocked();
69  $vals['blockanononly'] = !$block->isHardblock();
70  if ( $block instanceof AbstractBlock ) {
71  $vals['blockemail'] = $block->isEmailBlocked();
72  $vals['blockowntalk'] = !$block->isUsertalkEditAllowed();
73  }
74 
75  $user = $this->getUser();
76  // Formatted timestamps
77  $vals['blockedtimestampformatted'] = $language->formatExpiry(
78  $block->getTimestamp(), true, 'infinity', $user
79  );
80  if ( $expiry !== 'infinite' ) {
81  $vals['blockexpiryformatted'] = $language->formatExpiry(
82  $expiry, true, 'infinity', $user
83  );
84  $vals['blockexpiryrelative'] = $language->getHumanTimestamp(
85  new MWTimestamp( $expiry ), new MWTimestamp(), $user
86  );
87  }
88 
89  if ( $block instanceof SystemBlock ) {
90  $vals['systemblocktype'] = $block->getSystemBlockType();
91  }
92 
93  return $vals;
94  }
95 
101  private function getBlockCode( Block $block ): string {
102  if ( $block instanceof DatabaseBlock && $block->getType() === Block::TYPE_AUTO ) {
103  return 'autoblocked';
104  }
105  return 'blocked';
106  }
107 
108  // region Methods required from ApiBase
117  abstract public function getLanguage();
118 
123  abstract public function getUser();
124 
126  // endregion -- end of methods required from ApiBase
127 
128 }
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
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
System blocks are temporary blocks that are created on enforcement (e.g.
Definition: SystemBlock.php:35
internal since 1.36
Definition: User.php:98
Library for creating and parsing MW-style timestamps.
Definition: MWTimestamp.php:48
trait ApiBlockInfoTrait
Represents a block that may prevent users from performing specific operations.
Definition: Block.php:41
isSitewide()
Get whether the block is a sitewide block.
isHardblock()
Get whether the block is a hard block (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.
getType()
Get the type of target for this particular block.
getExpiry()
Get the block expiry time.