reimplement r73652 having actually read coding conventions this time
[lhc/web/wiklou.git] / includes / api / ApiQueryRecentChanges.php
index b0d7e83..fe53b1a 100644 (file)
@@ -1,10 +1,9 @@
 <?php
-
 /**
- * Created on Oct 19, 2006
- *
  * API for MediaWiki 1.8+
  *
+ * Created on Oct 19, 2006
+ *
  * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
@@ -21,6 +20,8 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -40,9 +41,9 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                parent::__construct( $query, $moduleName, 'rc' );
        }
 
-       private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_flags = false,
-                       $fld_timestamp = false, $fld_title = false, $fld_ids = false,
-                       $fld_sizes = false;
+       private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
+                       $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false,
+                       $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false, $fld_tags = false;
        /**
         * Get an array mapping token names to their handler functions.
         * The prototype for a token function is func($pageid, $title, $rc)
@@ -93,6 +94,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                $this->fld_comment = isset( $prop['comment'] );
                $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
                $this->fld_user = isset( $prop['user'] );
+               $this->fld_userid = isset( $prop['userid'] );
                $this->fld_flags = isset( $prop['flags'] );
                $this->fld_timestamp = isset( $prop['timestamp'] );
                $this->fld_title = isset( $prop['title'] );
@@ -108,6 +110,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
         * Generates and outputs the result of this query based upon the provided parameters.
         */
        public function execute() {
+               global $wgUser;
                /* Get the parameters of the request. */
                $params = $this->extractRequestParams();
 
@@ -141,9 +144,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        }
 
                        // Check permissions
-                       global $wgUser;
                        if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
-                               $this->getMain()->setVaryCookie();
                                if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
                                        $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
                                }
@@ -164,7 +165,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        $this->addWhereIf( 'page_is_redirect = 0 OR page_is_redirect IS NULL', isset( $show['!redirect'] ) );
                }
 
-               if ( !is_null( $params['user'] ) && !is_null( $param['excludeuser'] ) ) {
+               if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
                        $this->dieUsage( 'user and excludeuser cannot be used together', 'user-excludeuser' );
                }
 
@@ -198,9 +199,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        /* Set up internal members based upon params. */
                        $this->initProperties( $prop );
 
-                       global $wgUser;
-                       if ( $this->fld_patrolled && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() )
-                       {
+                       if ( $this->fld_patrolled && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
                                $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
                        }
 
@@ -210,7 +209,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        $this->addFieldsIf( 'rc_last_oldid', $this->fld_ids );
                        $this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment );
                        $this->addFieldsIf( 'rc_user', $this->fld_user );
-                       $this->addFieldsIf( 'rc_user_text', $this->fld_user );
+                       $this->addFieldsIf( 'rc_user_text', $this->fld_user || $this->fld_userid );
                        $this->addFieldsIf( 'rc_minor', $this->fld_flags );
                        $this->addFieldsIf( 'rc_bot', $this->fld_flags );
                        $this->addFieldsIf( 'rc_new', $this->fld_flags );
@@ -221,8 +220,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        $this->addFieldsIf( 'rc_log_type', $this->fld_loginfo );
                        $this->addFieldsIf( 'rc_log_action', $this->fld_loginfo );
                        $this->addFieldsIf( 'rc_params', $this->fld_loginfo );
-                       if ( $this->fld_redirect || isset( $show['redirect'] ) || isset( $show['!redirect'] ) )
-                       {
+                       if ( $this->fld_redirect || isset( $show['redirect'] ) || isset( $show['!redirect'] ) ) {
                                $this->addTables( 'page' );
                                $this->addJoinConds( array( 'page' => array( 'LEFT JOIN', array( 'rc_namespace=page_namespace', 'rc_title=page_title' ) ) ) );
                                $this->addFields( 'page_is_redirect' );
@@ -338,8 +336,16 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                }
 
                /* Add user data and 'anon' flag, if use is anonymous. */
-               if ( $this->fld_user ) {
-                       $vals['user'] = $row->rc_user_text;
+               if ( $this->fld_user || $this->fld_userid ) {
+
+                       if ( $this->fld_user ) {
+                               $vals['user'] = $row->rc_user_text;
+                       }
+
+                       if ( $this->fld_userid ) {
+                               $vals['userid'] = $row->rc_user;
+                       }
+
                        if ( !$row->rc_user ) {
                                $vals['anon'] = '';
                        }
@@ -376,7 +382,6 @@ class ApiQueryRecentChanges extends ApiQueryBase {
 
                if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) {
                        global $wgUser;
-                       $this->getMain()->setVaryCookie();
                        $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rc_comment, $title );
                }
 
@@ -413,9 +418,6 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                }
 
                if ( !is_null( $this->token ) ) {
-                       // Don't cache tokens
-                       $this->getMain()->setCachePrivate();
-                       
                        $tokenFunctions = $this->getTokenFunctions();
                        foreach ( $this->token as $t ) {
                                $val = call_user_func( $tokenFunctions[$t], $row->rc_cur_id,
@@ -449,6 +451,24 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                }
        }
 
+       public function getCacheMode( $params ) {
+               if ( isset( $params['show'] ) ) {
+                       foreach ( $params['show'] as $show ) {
+                               if ( $show === 'patrolled' || $show === '!patrolled' ) {
+                                       return 'private';
+                               }
+                       }
+               }
+               if ( isset( $params['token'] ) ) {
+                       return 'private';
+               }
+               if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
+                       // formatComment() calls wfMsg() among other things
+                       return 'anon-public-user-private';
+               }
+               return 'public';
+       }
+
        public function getAllowedParams() {
                return array(
                        'start' => array(
@@ -480,6 +500,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                                ApiBase::PARAM_DFLT => 'title|timestamp|ids',
                                ApiBase::PARAM_TYPE => array(
                                        'user',
+                                       'userid',
                                        'comment',
                                        'parsedcomment',
                                        'flags',
@@ -541,6 +562,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        'prop' => array(
                                'Include additional pieces of information',
                                ' user           - Adds the user responsible for the edit and tags if they are an IP',
+                               ' userid         - Adds the user id responsible for the edit',
                                ' comment        - Adds the comment for the edit',
                                ' parsedcomment  - Adds the parsed comment for the edit',
                                ' flags          - Adds flags for the edit',