reimplement r73652 having actually read coding conventions this time
[lhc/web/wiklou.git] / includes / api / ApiQueryRecentChanges.php
index 797ca89..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();
 
@@ -116,7 +119,6 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                 *              AND rc_timestamp < $end AND rc_namespace = $namespace
                 *              AND rc_deleted = '0'
                 */
-               $db = $this->getDB();
                $this->addTables( 'recentchanges' );
                $index = array( 'recentchanges' => 'rc_timestamp' ); // May change
                $this->addWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
@@ -142,10 +144,10 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        }
 
                        // Check permissions
-                       global $wgUser;
-                       if ( ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() )
-                       {
-                               $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
+                       if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
+                               if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
+                                       $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
+                               }
                        }
 
                        /* Add additional conditions to query depending upon parameters. */
@@ -163,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' );
                }
 
@@ -197,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' );
                        }
 
@@ -209,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 );
@@ -220,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' );
@@ -248,7 +247,6 @@ class ApiQueryRecentChanges extends ApiQueryBase {
 
                $count = 0;
                /* Perform the actual query. */
-               $db = $this->getDB();
                $res = $this->select( __METHOD__ );
 
                /* Iterate through the rows, adding data extracted from them to our query result. */
@@ -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'] = '';
                        }
@@ -445,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(
@@ -476,6 +500,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                                ApiBase::PARAM_DFLT => 'title|timestamp|ids',
                                ApiBase::PARAM_TYPE => array(
                                        'user',
+                                       'userid',
                                        'comment',
                                        'parsedcomment',
                                        'flags',
@@ -534,7 +559,22 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        'namespace' => 'Filter log entries to only this namespace(s)',
                        'user' => 'Only list changes by this user',
                        'excludeuser' => 'Don\'t list changes by this user',
-                       'prop' => 'Include additional pieces of information',
+                       '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',
+                               ' timestamp      - Adds timestamp of the edit',
+                               ' title          - Adds the page title of the edit',
+                               ' ids            - Adds the page id, recent changes id and the new and old revision id',
+                               ' sizes          - Adds the new and old page length in bytes',
+                               ' redirect       - Tags edit if page is a redirect',
+                               ' patrolled      - Tags edits have have been patrolled',
+                               ' loginfo        - Adds log information (logid, logtype, etc) to log entries',
+                               ' tags           - Lists tags for the entry',
+                       ),
                        'token' => 'Which tokens to obtain for each change',
                        'show' => array(
                                'Show only items that meet this criteria.',