Explicit variable definition, tweak documentation
[lhc/web/wiklou.git] / includes / api / ApiQueryRecentChanges.php
index 877901e..2e9f9b7 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,12 @@ 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;
+
+       private $tokenFunctions;
+
        /**
         * Get an array mapping token names to their handler functions.
         * The prototype for a token function is func($pageid, $title, $rc)
@@ -75,24 +79,18 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        return false;
                }
 
-               // The patrol token is always the same, let's exploit that
-               static $cachedPatrolToken = null;
-               if ( !is_null( $cachedPatrolToken ) ) {
-                       return $cachedPatrolToken;
-               }
-
-               $cachedPatrolToken = $wgUser->editToken();
-               return $cachedPatrolToken;
+               return $wgUser->editToken( $rc->getAttribute( 'rc_id' ) );
        }
 
        /**
         * Sets internal state to include the desired properties in the output.
-        * @param $prop associative array of properties, only keys are used here
+        * @param $prop Array associative array of properties, only keys are used here
         */
        public function initProperties( $prop ) {
                $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'] );
@@ -163,7 +161,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' );
                }
 
@@ -187,7 +185,8 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                        'rc_cur_id',
                        'rc_type',
                        'rc_moved_to_ns',
-                       'rc_moved_to_title'
+                       'rc_moved_to_title',
+                       'rc_deleted'
                ) );
 
                /* Determine what properties we need to display. */
@@ -207,7 +206,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 );
@@ -334,8 +333,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'] = '';
                        }
@@ -490,6 +497,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                                ApiBase::PARAM_DFLT => 'title|timestamp|ids',
                                ApiBase::PARAM_TYPE => array(
                                        'user',
+                                       'userid',
                                        'comment',
                                        'parsedcomment',
                                        'flags',
@@ -551,6 +559,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',