-(bug 24484) Add prop=pageprops module
[lhc/web/wiklou.git] / includes / api / ApiQueryUsers.php
index 947838e..4fd256f 100644 (file)
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  */
 
@@ -73,7 +73,6 @@ if ( !defined( 'MEDIAWIKI' ) ) {
        public function execute() {
                $params = $this->extractRequestParams();
                $result = $this->getResult();
-               $r = array();
 
                if ( !is_null( $params['prop'] ) ) {
                        $this->prop = array_flip( $params['prop'] );
@@ -104,7 +103,6 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                }
 
                if ( count( $goodNames ) ) {
-                       $db = $this->getDb();
                        $this->addTables( 'user', 'u1' );
                        $this->addFields( 'u1.*' );
                        $this->addWhereFld( 'u1.user_name', $goodNames );
@@ -126,24 +124,29 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 
                        $data = array();
                        $res = $this->select( __METHOD__ );
-                       while ( ( $r = $db->fetchObject( $res ) ) ) {
-                               $user = User::newFromRow( $r );
+                       foreach ( $res as $row ) {
+                               $user = User::newFromRow( $row );
                                $name = $user->getName();
                                $data[$name]['name'] = $name;
+
                                if ( isset( $this->prop['editcount'] ) ) {
                                        $data[$name]['editcount'] = intval( $user->getEditCount() );
                                }
+
                                if ( isset( $this->prop['registration'] ) ) {
                                        $data[$name]['registration'] = wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
                                }
-                               if ( isset( $this->prop['groups'] ) && !is_null( $r->ug_group ) ) {
+
+                               if ( isset( $this->prop['groups'] ) && !is_null( $row->ug_group ) ) {
                                        // This row contains only one group, others will be added from other rows
-                                       $data[$name]['groups'][] = $r->ug_group;
+                                       $data[$name]['groups'][] = $row->ug_group;
                                }
-                               if ( isset( $this->prop['blockinfo'] ) && !is_null( $r->blocker_name ) ) {
-                                       $data[$name]['blockedby'] = $r->blocker_name;
-                                       $data[$name]['blockreason'] = $r->ipb_reason;
+
+                               if ( isset( $this->prop['blockinfo'] ) && !is_null( $row->blocker_name ) ) {
+                                       $data[$name]['blockedby'] = $row->blocker_name;
+                                       $data[$name]['blockreason'] = $row->ipb_reason;
                                }
+
                                if ( isset( $this->prop['emailable'] ) && $user->canReceiveEmail() ) {
                                        $data[$name]['emailable'] = '';
                                }
@@ -175,10 +178,13 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                                $data[$u] = array( 'name' => $u );
                                $urPage = new UserrightsPage;
                                $iwUser = $urPage->fetchUser( $u );
+
                                if ( $iwUser instanceof UserRightsProxy ) {
                                        $data[$u]['interwiki'] = '';
+
                                        if ( !is_null( $params['token'] ) ) {
                                                $tokenFunctions = $this->getTokenFunctions();
+
                                                foreach ( $params['token'] as $t ) {
                                                        $val = call_user_func( $tokenFunctions[$t], $iwUser );
                                                        if ( $val === false ) {
@@ -192,8 +198,11 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                                        $data[$u]['missing'] = '';
                                }
                        } else {
-                               if ( isset( $this->prop['groups'] ) && isset( $data[$u]['groups'] ) )
-                               {
+                               if ( isset( $this->prop['groups'] ) && isset( $data[$u]['groups'] ) ) {
+                                       $autolist = ApiQueryUsers::getAutoGroups( User::newFromName( $u ) );
+
+                                       $data[$u]['groups'] = array_merge( $autolist, $data[$u]['groups'] );
+
                                        $this->getResult()->setIndexedTagName( $data[$u]['groups'], 'g' );
                                }
                        }
@@ -209,6 +218,28 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                return $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'user' );
        }
 
+       /**
+       * Gets all the groups that a user is automatically a member of
+       * @return array
+       */
+       public static function getAutoGroups( $user ) {
+               $groups = array( '*' );
+
+               if ( !$user->isAnon() ) {
+                       $groups[] = 'user';
+               }
+
+               return array_merge( $groups, Autopromote::getAutopromoteGroups( $user ) );
+       }
+
+       public function getCacheMode( $params ) {
+               if ( isset( $params['token'] ) ) {
+                       return 'private';
+               } else {
+                       return 'public';
+               }
+       }
+
        public function getAllowedParams() {
                return array(
                        'prop' => array(