$fld_rights = isset( $prop['rights'] );
$fld_registration = isset( $prop['registration'] );
$fld_implicitgroups = isset( $prop['implicitgroups'] );
+ $fld_centralids = isset( $prop['centralids'] );
} else {
$fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration =
- $fld_rights = $fld_implicitgroups = false;
+ $fld_rights = $fld_implicitgroups = $fld_centralids = false;
}
$limit = $params['limit'];
'name' => $row->user_name,
);
+ if ( $fld_centralids ) {
+ $data += ApiQueryUserInfo::getCentralUserInfo(
+ $this->getConfig(), User::newFromId( $row->user_id ), $params['attachedwiki']
+ );
+ }
+
if ( $fld_blockinfo && !is_null( $row->ipb_by_text ) ) {
$data['blockid'] = (int)$row->ipb_id;
$data['blockedby'] = $row->ipb_by_text;
'implicitgroups',
'rights',
'editcount',
- 'registration'
+ 'registration',
+ 'centralids',
),
ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
),
$this->getConfig()->get( 'ActiveUserDays' )
),
),
+ 'attachedwiki' => null,
);
}
$data['favicon'] = wfExpandUrl( $favicon, PROTO_RELATIVE );
}
+ $data['centralidlookupprovider'] = $this->getConfig()->get( 'CentralIdLookupProvider' );
+ $providerIds = array_keys( $this->getConfig()->get( 'CentralIdLookupProviders' ) );
+ $data['allcentralidlookupproviders'] = $providerIds;
+
Hooks::run( 'APIQuerySiteInfoGeneralInfo', array( $this, &$data ) );
return $this->getResult()->addValue( 'query', $property, $data );
const WL_UNREAD_LIMIT = 1000;
+ private $params = array();
private $prop = array();
public function __construct( ApiQuery $query, $moduleName ) {
}
public function execute() {
- $params = $this->extractRequestParams();
+ $this->params = $this->extractRequestParams();
$result = $this->getResult();
- if ( !is_null( $params['prop'] ) ) {
- $this->prop = array_flip( $params['prop'] );
+ if ( !is_null( $this->params['prop'] ) ) {
+ $this->prop = array_flip( $this->params['prop'] );
}
$r = $this->getCurrentUserInfo();
return $vals;
}
+ /**
+ * Get central user info
+ * @param Config $config
+ * @param User $user
+ * @param string|null $attachedWiki
+ * @return array Central user info
+ * - centralids: Array mapping non-local Central ID provider names to IDs
+ * - attachedlocal: Array mapping Central ID provider names to booleans
+ * indicating whether the local user is attached.
+ * - attachedwiki: Array mapping Central ID provider names to booleans
+ * indicating whether the user is attached to $attachedWiki.
+ */
+ public static function getCentralUserInfo( Config $config, User $user, $attachedWiki = null ) {
+ $providerIds = array_keys( $config->get( 'CentralIdLookupProviders' ) );
+
+ $ret = array(
+ 'centralids' => array(),
+ 'attachedlocal' => array(),
+ );
+ ApiResult::setArrayType( $ret['centralids'], 'assoc' );
+ ApiResult::setArrayType( $ret['attachedlocal'], 'assoc' );
+ if ( $attachedWiki ) {
+ $ret['attachedwiki'] = array();
+ ApiResult::setArrayType( $ret['attachedwiki'], 'assoc' );
+ }
+
+ $name = $user->getName();
+ foreach ( $providerIds as $providerId ) {
+ $provider = CentralIdLookup::factory( $providerId );
+ $ret['centralids'][$providerId] = $provider->centralIdFromName( $name );
+ $ret['attachedlocal'][$providerId] = $provider->isAttached( $user );
+ if ( $attachedWiki ) {
+ $ret['attachedwiki'][$providerId] = $provider->isAttached( $user, $attachedWiki );
+ }
+ }
+
+ return $ret;
+ }
+
protected function getCurrentUserInfo() {
$user = $this->getUser();
$vals = array();
}
}
+ if ( isset( $this->prop['centralids'] ) ) {
+ $vals += self::getCentralUserInfo(
+ $this->getConfig(), $this->getUser(), $this->params['attachedwiki']
+ );
+ }
+
return $vals;
}
'acceptlang',
'registrationdate',
'unreadcount',
+ 'centralids',
),
ApiBase::PARAM_HELP_MSG_PER_VALUE => array(
'unreadcount' => array(
self::WL_UNREAD_LIMIT . '+',
),
),
- )
+ ),
+ 'attachedwiki' => null,
);
}
'registration',
'emailable',
'gender',
+ 'centralids',
);
public function __construct( ApiQuery $query, $moduleName ) {
$data[$name]['gender'] = $gender;
}
+ if ( isset( $this->prop['centralids'] ) ) {
+ $data[$name] += ApiQueryUserInfo::getCentralUserInfo(
+ $this->getConfig(), $user, $params['attachedwiki']
+ );
+ }
+
if ( !is_null( $params['token'] ) ) {
$tokenFunctions = $this->getTokenFunctions();
foreach ( $params['token'] as $t ) {
'registration',
'emailable',
'gender',
+ 'centralids',
),
ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
),
+ 'attachedwiki' => null,
'users' => array(
ApiBase::PARAM_ISMULTI => true
),
"apihelp-query+allusers-paramvalue-prop-rights": "Lists rights that the user has.",
"apihelp-query+allusers-paramvalue-prop-editcount": "Adds the edit count of the user.",
"apihelp-query+allusers-paramvalue-prop-registration": "Adds the timestamp of when the user registered if available (may be blank).",
+ "apihelp-query+allusers-paramvalue-prop-centralids": "Adds the central IDs and attachment status for the user.",
"apihelp-query+allusers-param-limit": "How many total user names to return.",
"apihelp-query+allusers-param-witheditsonly": "Only list users who have made edits.",
"apihelp-query+allusers-param-activeusers": "Only list users active in the last $1 {{PLURAL:$1|day|days}}.",
+ "apihelp-query+allusers-param-attachedwiki": "With <kbd>$1prop=centralids</kbd>, also indicate whether the user is attached with the wiki identified by this ID.",
"apihelp-query+allusers-example-Y": "List users starting at <kbd>Y</kbd>.",
"apihelp-query+backlinks-description": "Find all pages that link to the given page.",
"apihelp-query+userinfo-paramvalue-prop-acceptlang": "Echoes the <code>Accept-Language</code> header sent by the client in a structured format.",
"apihelp-query+userinfo-paramvalue-prop-registrationdate": "Adds the user's registration date.",
"apihelp-query+userinfo-paramvalue-prop-unreadcount": "Adds the count of unread pages on the user's watchlist (maximum $1; returns <samp>$2</samp> if more).",
+ "apihelp-query+userinfo-paramvalue-prop-centralids": "Adds the central IDs and attachment status for the user.",
+ "apihelp-query+userinfo-param-attachedwiki": "With <kbd>$1prop=centralids</kbd>, indicate whether the user is attached with the wiki identified by this ID.",
"apihelp-query+userinfo-example-simple": "Get information about the current user.",
"apihelp-query+userinfo-example-data": "Get additional information about the current user.",
"apihelp-query+users-paramvalue-prop-registration": "Adds the user's registration timestamp.",
"apihelp-query+users-paramvalue-prop-emailable": "Tags if the user can and wants to receive email through [[Special:Emailuser]].",
"apihelp-query+users-paramvalue-prop-gender": "Tags the gender of the user. Returns \"male\", \"female\", or \"unknown\".",
+ "apihelp-query+users-paramvalue-prop-centralids": "Adds the central IDs and attachment status for the user.",
+ "apihelp-query+users-param-attachedwiki": "With <kbd>$1prop=centralids</kbd>, indicate whether the user is attached with the wiki identified by this ID.",
"apihelp-query+users-param-users": "A list of users to obtain information for.",
"apihelp-query+users-param-token": "Use <kbd>[[Special:ApiHelp/query+tokens|action=query&meta=tokens]]</kbd> instead.",
"apihelp-query+users-example-simple": "Return information for user <kbd>Example</kbd>.",
"apihelp-query+allusers-paramvalue-prop-rights": "{{doc-apihelp-paramvalue|query+allusers|prop|rights}}",
"apihelp-query+allusers-paramvalue-prop-editcount": "{{doc-apihelp-paramvalue|query+allusers|prop|editcount}}",
"apihelp-query+allusers-paramvalue-prop-registration": "{{doc-apihelp-paramvalue|query+allusers|prop|registration}}",
+ "apihelp-query+allusers-paramvalue-prop-centralids": "{{doc-apihelp-paramvalue|query+allusers|prop|centralids}}",
+ "apihelp-query+allusers-param-attachedwiki": "{{doc-apihelp-param|query+allusers|attachedwiki}}",
"apihelp-query+allusers-param-limit": "{{doc-apihelp-param|query+allusers|limit}}",
"apihelp-query+allusers-param-witheditsonly": "{{doc-apihelp-param|query+allusers|witheditsonly}}",
"apihelp-query+allusers-param-activeusers": "{{doc-apihelp-param|query+allusers|activeusers|params=* $1 - Value of [[mw:Manual:$wgActiveUserDays]]|paramstart=2}}",
"apihelp-query+userinfo-paramvalue-prop-acceptlang": "{{doc-apihelp-paramvalue|query+userinfo|prop|acceptlang}}",
"apihelp-query+userinfo-paramvalue-prop-registrationdate": "{{doc-apihelp-paramvalue|query+userinfo|prop|registrationdate}}",
"apihelp-query+userinfo-paramvalue-prop-unreadcount": "{{doc-apihelp-paramvalue|query+userinfo|prop|unreadcount|params=* $1 - Maximum value for the \"unreadcount\" property.\n* $2 - Return value when there are more unread pages.|paramstart=3}}",
+ "apihelp-query+userinfo-paramvalue-prop-centralids": "{{doc-apihelp-paramvalue|query+userinfo|prop|centralids}}",
+ "apihelp-query+userinfo-param-attachedwiki": "{{doc-apihelp-param|query+userinfo|attachedwiki}}",
"apihelp-query+userinfo-example-simple": "{{doc-apihelp-example|query+userinfo}}",
"apihelp-query+userinfo-example-data": "{{doc-apihelp-example|query+userinfo}}",
"apihelp-query+users-description": "{{doc-apihelp-description|query+users}}",
"apihelp-query+users-paramvalue-prop-registration": "{{doc-apihelp-paramvalue|query+users|prop|registration}}",
"apihelp-query+users-paramvalue-prop-emailable": "{{doc-apihelp-paramvalue|query+users|prop|emailable}}",
"apihelp-query+users-paramvalue-prop-gender": "{{doc-apihelp-paramvalue|query+users|prop|gender}}",
+ "apihelp-query+users-paramvalue-prop-centralids": "{{doc-apihelp-paramvalue|query+users|prop|centralids}}",
+ "apihelp-query+users-param-attachedwiki": "{{doc-apihelp-param|query+users|attachedwiki}}",
"apihelp-query+users-param-users": "{{doc-apihelp-param|query+users|users}}",
"apihelp-query+users-param-token": "{{doc-apihelp-param|query+users|token}}",
"apihelp-query+users-example-simple": "{{doc-apihelp-example|query+users}}",