with formatversion=2.
* Various other output from meta=siteinfo will now always be arrays instead of
sometimes being numerically-indexed objects with formatversion=2.
+* When errors about users being blocked are returned, they now include
+ information about the relevant block.
=== Action API internal changes in 1.26 ===
if ( $user->isBlocked() ) {
$status = SpecialBlock::checkUnblockSelf( $params['user'], $user );
if ( $status !== true ) {
- $this->dieUsageMsg( array( $status ) );
+ $msg = $this->parseMsg( $status );
+ $this->dieUsage(
+ $msg['info'],
+ $msg['code'],
+ 0,
+ array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) )
+ );
}
}
);
}
if ( $this->getUser()->isBlockedFromCreateAccount() ) {
- $this->dieUsage( 'You cannot create a new account because you are blocked', 'blocked' );
+ $this->dieUsage(
+ 'You cannot create a new account because you are blocked',
+ 'blocked',
+ 0,
+ array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $this->getUser()->getBlock() ) )
+ );
}
$params = $this->extractRequestParams();
$errors = array_merge( $errors, $titleObj->getUserPermissionsErrors( 'create', $user ) );
}
if ( count( $errors ) ) {
- $this->dieUsageMsg( $errors[0] );
+ if ( is_array( $errors[0] ) ) {
+ switch ( $errors[0][0] ) {
+ case 'blockedtext':
+ $this->dieUsage(
+ 'You have been blocked from editing',
+ 'blocked',
+ 0,
+ array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) )
+ );
+ break;
+ case 'autoblockedtext':
+ $this->dieUsage(
+ 'Your IP address has been blocked automatically, because it was used by a blocked user',
+ 'autoblocked',
+ 0,
+ array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) )
+ );
+ break;
+ default:
+ $this->dieUsageMsg( $errors[0] );
+ }
+ } else {
+ $this->dieUsageMsg( $errors[0] );
+ }
}
$toMD5 = $params['text'];
$this->dieUsageMsg( array( 'spamdetected', $result['spam'] ) );
case EditPage::AS_BLOCKED_PAGE_FOR_USER:
- $this->dieUsageMsg( 'blockedtext' );
+ $this->dieUsage(
+ 'You have been blocked from editing',
+ 'blocked',
+ 0,
+ array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) )
+ );
case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
case EditPage::AS_CONTENT_TOO_BIG:
case LoginForm::CREATE_BLOCKED:
$result['result'] = 'CreateBlocked';
$result['details'] = 'Your IP address is blocked from account creation';
+ $result = array_merge(
+ $result,
+ ApiQueryUserInfo::getBlockInfo( $context->getUser()->getBlock() )
+ );
break;
case LoginForm::THROTTLED:
case LoginForm::USER_BLOCKED:
$result['result'] = 'Blocked';
+ $result = array_merge(
+ $result,
+ ApiQueryUserInfo::getBlockInfo( User::newFromName( $params['name'] )->getBlock() )
+ );
break;
case LoginForm::ABORTED:
$result->addValue( 'query', $this->getModuleName(), $r );
}
- protected function getCurrentUserInfo() {
+ /**
+ * Get basic info about a given block
+ * @param Block $block
+ * @return array Array containing several keys:
+ * - blockid - ID of the block
+ * - blockedby - username of the blocker
+ * - blockedbyid - user ID of the blocker
+ * - blockreason - reason provided for the block
+ * - blockedtimestamp - timestamp for when the block was placed/modified
+ * - blockexpiry - expiry time of the block
+ */
+ public static function getBlockInfo( Block $block ) {
global $wgContLang;
+ $vals = array();
+ $vals['blockid'] = $block->getId();
+ $vals['blockedby'] = $block->getByName();
+ $vals['blockedbyid'] = $block->getBy();
+ $vals['blockreason'] = $block->mReason;
+ $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->mTimestamp );
+ $vals['blockexpiry'] = $wgContLang->formatExpiry(
+ $block->getExpiry(), TS_ISO_8601, 'infinite'
+ );
+ return $vals;
+ }
+ protected function getCurrentUserInfo() {
$user = $this->getUser();
$result = $this->getResult();
$vals = array();
$vals['anon'] = true;
}
- if ( isset( $this->prop['blockinfo'] ) ) {
- if ( $user->isBlocked() ) {
- $block = $user->getBlock();
- $vals['blockid'] = $block->getId();
- $vals['blockedby'] = $block->getByName();
- $vals['blockedbyid'] = $block->getBy();
- $vals['blockreason'] = $user->blockedFor();
- $vals['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $block->mTimestamp );
- $vals['blockexpiry'] = $wgContLang->formatExpiry(
- $block->getExpiry(), TS_ISO_8601, 'infinite'
- );
- }
+ if ( isset( $this->prop['blockinfo'] ) && $user->isBlocked() ) {
+ $vals = array_merge( $vals, self::getBlockInfo( $user->getBlock() ) );
}
if ( isset( $this->prop['hasmsg'] ) ) {
if ( $user->isBlocked() ) {
$status = SpecialBlock::checkUnblockSelf( $params['user'], $user );
if ( $status !== true ) {
- $this->dieUsageMsg( $status );
+ $msg = $this->parseMsg( $status );
+ $this->dieUsage(
+ $msg['info'],
+ $msg['code'],
+ 0,
+ array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) )
+ );
}
}
}
if ( $this->getUser()->isBlocked() ) {
- $this->dieUsageMsg( 'blockedtext' );
+ $this->dieUsage(
+ 'You have been blocked from editing',
+ 'blocked',
+ 0,
+ array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $this->getUser()->getBlock() ) )
+ );
}
$titleObj = Title::newFromText( $params['title'] );