}
public function execute() {
- global $wgContLang;
-
$db = $this->getDB();
+ $commentStore = new CommentStore( 'ipb_reason' );
$params = $this->extractRequestParams();
$this->requireMaxOneParameter( $params, 'users', 'ip' );
$this->addFieldsIf( 'ipb_by_text', $fld_by );
$this->addFieldsIf( 'ipb_by', $fld_byid );
$this->addFieldsIf( 'ipb_expiry', $fld_expiry );
- $this->addFieldsIf( 'ipb_reason', $fld_reason );
$this->addFieldsIf( [ 'ipb_range_start', 'ipb_range_end' ], $fld_range );
$this->addFieldsIf( [ 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock',
'ipb_block_email', 'ipb_deleted', 'ipb_allow_usertalk' ],
$fld_flags );
+ if ( $fld_reason ) {
+ $commentQuery = $commentStore->getJoin();
+ $this->addTables( $commentQuery['tables'] );
+ $this->addFields( $commentQuery['fields'] );
+ $this->addJoinConds( $commentQuery['joins'] );
+ }
+
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$this->addTimestampWhereRange(
'ipb_timestamp',
$cidrLimit = $blockCIDRLimit['IPv6'];
$prefixLen = 3; // IP::toHex output is prefixed with "v6-"
} else {
- $this->dieUsage( 'IP parameter is not valid', 'param_ip' );
+ $this->dieWithError( 'apierror-badip', 'param_ip' );
}
# Check range validity, if it's a CIDR
list( $ip, $range ) = IP::parseCIDR( $params['ip'] );
if ( $ip !== false && $range !== false && $range < $cidrLimit ) {
- $this->dieUsage(
- "$type CIDR ranges broader than /$cidrLimit are not accepted",
- 'cidrtoobroad'
- );
+ $this->dieWithError( [ 'apierror-cidrtoobroad', $type, $cidrLimit ] );
}
# Let IP::parseRange handle calculating $upper, instead of duplicating the logic here.
|| ( isset( $show['range'] ) && isset( $show['!range'] ) )
|| ( isset( $show['temp'] ) && isset( $show['!temp'] ) )
) {
- $this->dieUsageMsg( 'show' );
+ $this->dieWithError( 'apierror-show' );
}
$this->addWhereIf( 'ipb_user = 0', isset( $show['!account'] ) );
$block['timestamp'] = wfTimestamp( TS_ISO_8601, $row->ipb_timestamp );
}
if ( $fld_expiry ) {
- $block['expiry'] = $wgContLang->formatExpiry( $row->ipb_expiry, TS_ISO_8601 );
+ $block['expiry'] = ApiResult::formatExpiry( $row->ipb_expiry );
}
if ( $fld_reason ) {
- $block['reason'] = $row->ipb_reason;
+ $block['reason'] = $commentStore->getComment( $row )->text;
}
if ( $fld_range && !$row->ipb_auto ) {
$block['rangestart'] = IP::formatHex( $row->ipb_range_start );
protected function prepareUsername( $user ) {
if ( !$user ) {
- $this->dieUsage( 'User parameter may not be empty', 'param_user' );
+ $encParamName = $this->encodeParamName( 'users' );
+ $this->dieWithError( [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $user ) ],
+ "baduser_{$encParamName}"
+ );
}
$name = User::isIP( $user )
? $user
: User::getCanonicalName( $user, 'valid' );
if ( $name === false ) {
- $this->dieUsage( "User name {$user} is not valid", 'param_user' );
+ $encParamName = $this->encodeParamName( 'users' );
+ $this->dieWithError( [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $user ) ],
+ "baduser_{$encParamName}"
+ );
}
return $name;
}
}
public function getHelpUrls() {
- return 'https://www.mediawiki.org/wiki/API:Blocks';
+ return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Blocks';
}
}