Merge "Remove useless test in getParamValue function of mediawiki.util.js"
[lhc/web/wiklou.git] / includes / api / ApiQueryRecentChanges.php
index d955aaa..f9025c4 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * A query action to enumerate the recent changes that were done to the wiki.
  * Various filters are supported.
@@ -52,7 +47,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
         * Get an array mapping token names to their handler functions.
         * The prototype for a token function is func($pageid, $title, $rc)
         * it should return a token or false (permission denied)
-        * @return array(tokenname => function)
+        * @return array array(tokenname => function)
         */
        protected function getTokenFunctions() {
                // Don't call the hooks twice
@@ -75,24 +70,37 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
        /**
         * @param  $pageid
         * @param  $title
-        * @param $rc RecentChange
+        * @param $rc RecentChange (optional)
         * @return bool|String
         */
-       public static function getPatrolToken( $pageid, $title, $rc ) {
+       public static function getPatrolToken( $pageid, $title, $rc = null ) {
                global $wgUser;
-               if ( !$wgUser->useRCPatrol() && ( !$wgUser->useNPPatrol() ||
-                               $rc->getAttribute( 'rc_type' ) != RC_NEW ) )
-               {
-                       return false;
+
+               $validTokenUser = false;
+
+               if ( $rc ) {
+                       if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) ||
+                               ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW ) )
+                       {
+                               $validTokenUser = true;
+                       }
+               } else {
+                       if ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
+                               $validTokenUser = true;
+                       }
                }
 
-               // The patrol token is always the same, let's exploit that
-               static $cachedPatrolToken = null;
-               if ( is_null( $cachedPatrolToken ) ) {
-                       $cachedPatrolToken = $wgUser->editToken( 'patrol' );
+               if ( $validTokenUser ) {
+                       // The patrol token is always the same, let's exploit that
+                       static $cachedPatrolToken = null;
+                       if ( is_null( $cachedPatrolToken ) ) {
+                               $cachedPatrolToken = $wgUser->getEditToken( 'patrol' );
+                       }
+                       return $cachedPatrolToken;
+               } else {
+                       return false;
                }
 
-               return $cachedPatrolToken;
        }
 
        /**
@@ -129,14 +137,14 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
         * @param $resultPageSet ApiPageSet
         */
        public function run( $resultPageSet = null ) {
-               global $wgUser;
+               $user = $this->getUser();
                /* Get the parameters of the request. */
                $params = $this->extractRequestParams();
 
                /* Build our basic query. Namely, something along the lines of:
                 * SELECT * FROM recentchanges WHERE rc_timestamp > $start
                 *              AND rc_timestamp < $end AND rc_namespace = $namespace
-                *              AND rc_deleted = '0'
+                *              AND rc_deleted = 0
                 */
                $this->addTables( 'recentchanges' );
                $index = array( 'recentchanges' => 'rc_timestamp' ); // May change
@@ -163,7 +171,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
 
                        // Check permissions
                        if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
-                               if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
+                               if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
                                        $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
                                }
                        }
@@ -219,7 +227,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                        /* Set up internal members based upon params. */
                        $this->initProperties( $prop );
 
-                       if ( $this->fld_patrolled && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
+                       if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
                                $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
                        }
 
@@ -309,7 +317,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
         * Extracts from a single sql row the data needed to describe one recent change.
         *
         * @param $row The row from which to extract the data.
-        * @return An array mapping strings (descriptors) to their respective string values.
+        * @return array An array mapping strings (descriptors) to their respective string values.
         * @access public
         */
        public function extractRowInfo( $row ) {
@@ -428,13 +436,14 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                        $vals['logid'] = intval( $row->rc_logid );
                        $vals['logtype'] = $row->rc_log_type;
                        $vals['logaction'] = $row->rc_log_action;
+                       $logEntry = DatabaseLogEntry::newFromRow( (array)$row );
                        ApiQueryLogEvents::addLogParams(
                                $this->getResult(),
                                $vals,
-                               $row->rc_params,
-                               $row->rc_log_action,
-                               $row->rc_log_type,
-                               $row->rc_timestamp
+                               $logEntry->getParameters(),
+                               $logEntry->getType(),
+                               $logEntry->getSubtype(),
+                               $logEntry->getTimestamp()
                        );
                }
 
@@ -620,6 +629,97 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                );
        }
 
+       public function getResultProperties() {
+               global $wgLogTypes;
+               $props = array(
+                       '' => array(
+                               'type' => array(
+                                       ApiBase::PROP_TYPE => array(
+                                               'edit',
+                                               'new',
+                                               'move',
+                                               'log',
+                                               'move over redirect'
+                                       )
+                               )
+                       ),
+                       'title' => array(
+                               'ns' => 'namespace',
+                               'title' => 'string',
+                               'new_ns' => array(
+                                       ApiBase::PROP_TYPE => 'namespace',
+                                       Apibase::PROP_NULLABLE => true
+                               ),
+                               'new_title' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       Apibase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'ids' => array(
+                               'rcid' => 'integer',
+                               'pageid' => 'integer',
+                               'revid' => 'integer',
+                               'old_revid' => 'integer'
+                       ),
+                       'user' => array(
+                               'user' => 'string',
+                               'anon' => 'boolean'
+                       ),
+                       'userid' => array(
+                               'userid' => 'integer',
+                               'anon' => 'boolean'
+                       ),
+                       'flags' => array(
+                               'bot' => 'boolean',
+                               'new' => 'boolean',
+                               'minor' => 'boolean'
+                       ),
+                       'sizes' => array(
+                               'oldlen' => 'integer',
+                               'newlen' => 'integer'
+                       ),
+                       'timestamp' => array(
+                               'timestamp' => 'timestamp'
+                       ),
+                       'comment' => array(
+                               'comment' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       Apibase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'parsedcomment' => array(
+                               'parsedcomment' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       Apibase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'redirect' => array(
+                               'redirect' => 'boolean'
+                       ),
+                       'patrolled' => array(
+                               'patrolled' => 'boolean'
+                       ),
+                       'loginfo' => array(
+                               'logid' => array(
+                                       ApiBase::PROP_TYPE => 'integer',
+                                       Apibase::PROP_NULLABLE => true
+                               ),
+                               'logtype' => array(
+                                       ApiBase::PROP_TYPE => $wgLogTypes,
+                                       Apibase::PROP_NULLABLE => true
+                               ),
+                               'logaction' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       Apibase::PROP_NULLABLE => true
+                               )
+                       )
+               );
+
+               self::addTokenProperties( $props, $this->getTokenFunctions() );
+
+               return $props;
+       }
+
        public function getDescription() {
                return 'Enumerate recent changes';
        }
@@ -639,7 +739,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
        }
 
        public function getHelpUrls() {
-               return 'http://www.mediawiki.org/wiki/API:Recentchanges';
+               return 'https://www.mediawiki.org/wiki/API:Recentchanges';
        }
 
        public function getVersion() {