Merge "Fix relayPurge() IDEA warnings"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 2 Dec 2015 22:41:43 +0000 (22:41 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 2 Dec 2015 22:41:43 +0000 (22:41 +0000)
includes/api/ApiQueryAllUsers.php
includes/api/ApiQuerySiteinfo.php
includes/api/ApiQueryUserInfo.php
includes/api/ApiQueryUsers.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json
includes/libs/objectcache/WANObjectCache.php

index ffcb2f5..9ea1b1e 100644 (file)
@@ -59,9 +59,10 @@ class ApiQueryAllUsers extends ApiQueryBase {
                        $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'];
@@ -239,6 +240,12 @@ class ApiQueryAllUsers extends ApiQueryBase {
                                '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;
@@ -338,7 +345,8 @@ class ApiQueryAllUsers extends ApiQueryBase {
                                        'implicitgroups',
                                        'rights',
                                        'editcount',
-                                       'registration'
+                                       'registration',
+                                       'centralids',
                                ),
                                ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
                        ),
@@ -357,6 +365,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
                                        $this->getConfig()->get( 'ActiveUserDays' )
                                ),
                        ),
+                       'attachedwiki' => null,
                );
        }
 
index 7047339..1c031ff 100644 (file)
@@ -265,6 +265,10 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                        $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 );
index 93c0dd0..27663a1 100644 (file)
@@ -33,6 +33,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
 
        const WL_UNREAD_LIMIT = 1000;
 
+       private $params = array();
        private $prop = array();
 
        public function __construct( ApiQuery $query, $moduleName ) {
@@ -40,11 +41,11 @@ class ApiQueryUserInfo extends ApiQueryBase {
        }
 
        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();
@@ -76,6 +77,45 @@ class ApiQueryUserInfo extends ApiQueryBase {
                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();
@@ -205,6 +245,12 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        }
                }
 
+               if ( isset( $this->prop['centralids'] ) ) {
+                       $vals += self::getCentralUserInfo(
+                               $this->getConfig(), $this->getUser(), $this->params['attachedwiki']
+                       );
+               }
+
                return $vals;
        }
 
@@ -267,6 +313,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                        'acceptlang',
                                        'registrationdate',
                                        'unreadcount',
+                                       'centralids',
                                ),
                                ApiBase::PARAM_HELP_MSG_PER_VALUE => array(
                                        'unreadcount' => array(
@@ -275,7 +322,8 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                                self::WL_UNREAD_LIMIT . '+',
                                        ),
                                ),
-                       )
+                       ),
+                       'attachedwiki' => null,
                );
        }
 
index a826c1b..db5fb65 100644 (file)
@@ -48,6 +48,7 @@ class ApiQueryUsers extends ApiQueryBase {
                'registration',
                'emailable',
                'gender',
+               'centralids',
        );
 
        public function __construct( ApiQuery $query, $moduleName ) {
@@ -213,6 +214,12 @@ class ApiQueryUsers extends ApiQueryBase {
                                        $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 ) {
@@ -304,9 +311,11 @@ class ApiQueryUsers extends ApiQueryBase {
                                        'registration',
                                        'emailable',
                                        'gender',
+                                       'centralids',
                                ),
                                ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
                        ),
+                       'attachedwiki' => null,
                        'users' => array(
                                ApiBase::PARAM_ISMULTI => true
                        ),
index 4c2d0be..897c05e 100644 (file)
        "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>.",
index 047a806..f4ec177 100644 (file)
        "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}}",
index 8b22e9e..e1ac56e 100644 (file)
@@ -560,17 +560,18 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         * @see WANObjectCache::resetCheckKey()
         *
         * @param string $key Cache key
+        * @param int $holdoff HOLDOFF_TTL or HOLDOFF_NONE constant
         * @return bool True if the item was purged or not found, false on failure
         */
-       final public function touchCheckKey( $key ) {
+       final public function touchCheckKey( $key, $holdoff = self::HOLDOFF_TTL ) {
                $key = self::TIME_KEY_PREFIX . $key;
                // Update the local datacenter immediately
                $ok = $this->cache->set( $key,
-                       $this->makePurgeValue( microtime( true ), self::HOLDOFF_TTL ),
+                       $this->makePurgeValue( microtime( true ), $holdoff ),
                        self::CHECK_KEY_TTL
                );
                // Publish the purge to all datacenters
-               return $this->relayPurge( $key, self::CHECK_KEY_TTL, self::HOLDOFF_TTL ) && $ok;
+               return $this->relayPurge( $key, self::CHECK_KEY_TTL, $holdoff ) && $ok;
        }
 
        /**