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,
);
}