$res['expiry'] = $block->mExpiry == wfGetDB( DB_SLAVE )->getInfinity()
? 'infinite'
: wfTimestamp( TS_ISO_8601, $block->mExpiry );
+ $res['id'] = $block->getId();
} else {
# should be unreachable
$res['expiry'] = '';
+ $res['id'] = '';
}
$res['reason'] = $params['reason'];
ApiBase::PARAM_REQUIRED => true
),
'token' => null,
- 'gettoken' => false,
+ 'gettoken' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_DEPRECATED => true,
+ ),
'expiry' => 'never',
'reason' => null,
'anononly' => false,
public function getParamDescription() {
return array(
'user' => 'Username, IP address or IP range you want to block',
- 'token' => 'A block token previously obtained through the gettoken parameter or prop=info',
+ 'token' => 'A block token previously obtained through prop=info',
'gettoken' => 'If set, a block token will be returned, and no other action will be taken',
'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.',
'reason' => 'Reason for block (optional)',
parent::__construct( $query, $moduleName, 'au' );
}
+ /**
+ * This function converts the user name to a canonical form
+ * which is stored in the database.
+ * @param String $name
+ * @return String
+ */
+ private function getCanonicalUserName( $name ) {
+ return str_replace( '_', ' ', $name );
+ }
+
public function execute() {
$db = $this->getDB();
$params = $this->extractRequestParams();
$useIndex = true;
$dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' );
- $from = is_null( $params['from'] ) ? null : $this->keyToTitle( $params['from'] );
- $to = is_null( $params['to'] ) ? null : $this->keyToTitle( $params['to'] );
+ $from = is_null( $params['from'] ) ? null : $this->getCanonicalUserName( $params['from'] );
+ $to = is_null( $params['to'] ) ? null : $this->getCanonicalUserName( $params['to'] );
# MySQL doesn't seem to use 'equality propagation' here, so like the
# ActiveUsers special page, we have to use rc_user_text for some cases.
if ( !is_null( $params['prefix'] ) ) {
$this->addWhere( $userFieldToSort .
- $db->buildLike( $this->keyToTitle( $params['prefix'] ), $db->anyString() ) );
+ $db->buildLike( $this->getCanonicalUserName( $params['prefix'] ), $db->anyString() ) );
}
if ( !is_null( $params['rights'] ) ) {
$lastUserData = null;
if ( !$fit ) {
- $this->setContinueEnumParameter( 'from',
- $this->keyToTitle( $lastUserData['name'] ) );
+ $this->setContinueEnumParameter( 'from', $lastUserData['name'] );
break;
}
}
if ( $count > $limit ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
- $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->user_name ) );
+ $this->setContinueEnumParameter( 'from', $row->user_name );
break;
}
'name' => $lastUser,
);
if ( $fld_blockinfo && !is_null( $row->ipb_by_text ) ) {
+ $lastUserData['blockid'] = $row->ipb_id;
$lastUserData['blockedby'] = $row->ipb_by_text;
+ $lastUserData['blockedbyid'] = $row->ipb_by;
$lastUserData['blockreason'] = $row->ipb_reason;
$lastUserData['blockexpiry'] = $row->ipb_expiry;
}
'MediaWiki configuration error: the database contains more user groups than known to User::getAllGroups() function' );
}
- $lastUserObj = User::newFromName( $lastUser );
+ $lastUserObj = User::newFromId( $row->user_id );
// Add user's group info
if ( $fld_groups ) {
- if ( !isset( $lastUserData['groups'] ) && $lastUserObj ) {
- $lastUserData['groups'] = ApiQueryUsers::getAutoGroups( $lastUserObj );
+ if ( !isset( $lastUserData['groups'] ) ) {
+ if ( $lastUserObj ) {
+ $lastUserData['groups'] = ApiQueryUsers::getAutoGroups( $lastUserObj );
+ } else {
+ // This should not normally happen
+ $lastUserData['groups'] = array();
+ }
}
if ( !is_null( $row->ug_group2 ) ) {
$lastUserData['groups'][] = $row->ug_group2;
}
+
$result->setIndexedTagName( $lastUserData['groups'], 'g' );
}
$result->setIndexedTagName( $lastUserData['implicitgroups'], 'g' );
}
if ( $fld_rights ) {
- if ( !isset( $lastUserData['rights'] ) && $lastUserObj ) {
- $lastUserData['rights'] = User::getGroupPermissions( $lastUserObj->getAutomaticGroups() );
+ if ( !isset( $lastUserData['rights'] ) ) {
+ if ( $lastUserObj ) {
+ $lastUserData['rights'] = User::getGroupPermissions( $lastUserObj->getAutomaticGroups() );
+ } else {
+ // This should not normally happen
+ $lastUserData['rights'] = array();
+ }
}
+
if ( !is_null( $row->ug_group2 ) ) {
$lastUserData['rights'] = array_unique( array_merge( $lastUserData['rights'],
User::getGroupPermissions( array( $row->ug_group2 ) ) ) );
}
+
$result->setIndexedTagName( $lastUserData['rights'], 'r' );
}
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ),
null, $lastUserData );
if ( !$fit ) {
- $this->setContinueEnumParameter( 'from',
- $this->keyToTitle( $lastUserData['name'] ) );
+ $this->setContinueEnumParameter( 'from', $lastUserData['name'] );
}
}
}
protected function getCurrentUserInfo() {
- global $wgRequest, $wgHiddenPrefs;
+ global $wgHiddenPrefs;
$user = $this->getUser();
$result = $this->getResult();
$vals = array();
if ( isset( $this->prop['blockinfo'] ) ) {
if ( $user->isBlocked() ) {
- $vals['blockedby'] = User::whoIs( $user->blockedBy() );
+ $block = $user->getBlock();
+ $vals['blockid'] = $block->getId();
+ $vals['blockedby'] = $block->getByName();
+ $vals['blockedbyid'] = $block->getBy();
$vals['blockreason'] = $user->blockedFor();
}
}
}
if ( isset( $this->prop['acceptlang'] ) ) {
- $langs = $wgRequest->getAcceptLang();
+ $langs = $this->getRequest()->getAcceptLang();
$acceptLang = array();
foreach ( $langs as $lang => $val ) {
$r = array( 'q' => $val );
}
$res['id'] = $block->getId();
- $res['user'] = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
+ $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
+ $res['user'] = $target;
+ $res['userid'] = $target instanceof User ? $target->getId() : 0;
$res['reason'] = $params['reason'];
$this->getResult()->addValue( null, $this->getModuleName(), $res );
}
),
'user' => null,
'token' => null,
- 'gettoken' => false,
+ 'gettoken' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_DEPRECATED => true,
+ ),
'reason' => null,
);
}
return array(
'id' => "ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with {$p}user",
'user' => "Username, IP address or IP range you want to unblock. Cannot be used together with {$p}id",
- 'token' => "An unblock token previously obtained through the gettoken parameter or {$p}prop=info",
+ 'token' => "An unblock token previously obtained through prop=info",
'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
'reason' => 'Reason for unblock (optional)',
);