MediaWiki master
ApiBlockInfoTrait.php
Go to the documentation of this file.
1<?php
28
33
53 private function getBlockDetails(
54 Block $block,
55 $language = null
56 ) {
57 $language ??= $this->getLanguage();
58
59 $blocker = $block->getBlocker();
60
61 $vals = [];
62 $vals['blockid'] = $block->getId();
63 $vals['blockedby'] = $blocker ? $blocker->getName() : '';
64 $vals['blockedbyid'] = $blocker ? $blocker->getId() : 0;
65 $vals['blockreason'] = $block->getReasonComment()
66 ->message->inLanguage( $language )->plain();
67 $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->getTimestamp() );
68 $expiry = ApiResult::formatExpiry( $block->getExpiry(), 'infinite' );
69 $vals['blockexpiry'] = $expiry;
70 $vals['blockpartial'] = !$block->isSitewide();
71 $vals['blocknocreate'] = $block->isCreateAccountBlocked();
72 $vals['blockanononly'] = !$block->isHardblock();
73 if ( $block instanceof AbstractBlock ) {
74 $vals['blockemail'] = $block->isEmailBlocked();
75 $vals['blockowntalk'] = !$block->isUsertalkEditAllowed();
76 }
77
78 $user = $this->getUser();
79 // Formatted timestamps
80 $vals['blockedtimestampformatted'] = $language->formatExpiry(
81 $block->getTimestamp(), true, 'infinity', $user
82 );
83 if ( $expiry !== 'infinite' ) {
84 $vals['blockexpiryformatted'] = $language->formatExpiry(
85 $expiry, true, 'infinity', $user
86 );
87 $vals['blockexpiryrelative'] = $language->getHumanTimestamp(
88 new MWTimestamp( $expiry ), new MWTimestamp(), $user
89 );
90 }
91
92 if ( $block instanceof SystemBlock ) {
93 $vals['systemblocktype'] = $block->getSystemBlockType();
94 }
95
96 if ( $block instanceof CompositeBlock ) {
97 $components = [];
98 foreach ( $block->getOriginalBlocks() as $singleBlock ) {
99 $components[] = $this->getBlockDetails( $singleBlock, $language );
100 }
101 $vals['blockcomponents'] = $components;
102 }
103
104 return $vals;
105 }
106
112 private function getBlockCode( Block $block ): string {
113 if ( $block instanceof DatabaseBlock && $block->getType() === Block::TYPE_AUTO ) {
114 return 'autoblocked';
115 }
116 return 'blocked';
117 }
118
119 // region Methods required from ApiBase
128 abstract public function getLanguage();
129
134 abstract public function getUser();
135
137 // endregion -- end of methods required from ApiBase
138
139}
getUser()
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
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.
internal since 1.36
Definition User.php:93
Library for creating and parsing MW-style timestamps.
trait ApiBlockInfoTrait
Represents a block that may prevent users from performing specific operations.
Definition Block.php:45
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.