merging latest master
[lhc/web/wiklou.git] / includes / api / ApiQueryWatchlist.php
index f2d9f66..a1a3372 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Created on Sep 25, 2006
  *
- * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * This query action allows clients to retrieve a list of recently modified pages
  * that are part of the logged-in user's watchlist.
@@ -101,7 +96,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                                'rc_last_oldid',
                        ) );
 
-                       $this->addFieldsIf( array( 'rc_new', 'rc_minor', 'rc_bot' ), $this->fld_flags );
+                       $this->addFieldsIf( array( 'rc_type', 'rc_minor', 'rc_bot' ), $this->fld_flags );
                        $this->addFieldsIf( 'rc_user', $this->fld_user || $this->fld_userid );
                        $this->addFieldsIf( 'rc_user_text', $this->fld_user );
                        $this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment );
@@ -134,9 +129,8 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
 
                $db = $this->getDB();
 
-               $this->addWhereRange( 'rc_timestamp', $params['dir'],
-                       $db->timestamp( $params['start'] ),
-                       $db->timestamp( $params['end'] ) );
+               $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'],
+                       $params['start'], $params['end'] );
                $this->addWhereFld( 'wl_namespace', $params['namespace'] );
 
                if ( !$params['allrev'] ) {
@@ -160,8 +154,8 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
 
                        // Check permissions.
                        if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
-                               global $wgUser;
-                               if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
+                               $user = $this->getUser();
+                               if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
                                        $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
                                }
                        }
@@ -260,7 +254,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                }
 
                if ( $this->fld_flags ) {
-                       if ( $row->rc_new ) {
+                       if ( $row->rc_type == RC_NEW ) {
                                $vals['new'] = '';
                        }
                        if ( $row->rc_minor ) {
@@ -295,20 +289,21 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                }
 
                if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) {
-                       $vals['parsedcomment'] = $this->getSkin()->formatComment( $row->rc_comment, $title );
+                       $vals['parsedcomment'] = Linker::formatComment( $row->rc_comment, $title );
                }
 
                if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
                        $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_type,
-                               $row->rc_log_action,
-                               $row->rc_timestamp
+                               $logEntry->getParameters(),
+                               $logEntry->getType(),
+                               $logEntry->getSubtype(),
+                               $logEntry->getTimestamp()
                        );
                }
 
@@ -410,7 +405,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                                ' parsedcomment          - Adds parsed comment of the edit',
                                ' timestamp              - Adds timestamp of the edit',
                                ' patrol                 - Tags edits that are patrolled',
-                               ' size                   - Adds the old and new lengths of the page',
+                               ' sizes                  - Adds the old and new lengths of the page',
                                ' notificationtimestamp  - Adds timestamp of when the user was last notified about the edit',
                                ' loginfo                - Adds log information where appropriate',
                        ),
@@ -423,6 +418,76 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                );
        }
 
+       public function getResultProperties() {
+               global $wgLogTypes;
+               return array(
+                       'ids' => array(
+                               'pageid' => 'integer',
+                               'revid' => 'integer',
+                               'old_revid' => 'integer'
+                       ),
+                       'title' => array(
+                               'ns' => 'namespace',
+                               'title' => 'string'
+                       ),
+                       'user' => array(
+                               'user' => 'string',
+                               'anon' => 'boolean'
+                       ),
+                       'userid' => array(
+                               'userid' => 'integer',
+                               'anon' => 'boolean'
+                       ),
+                       'flags' => array(
+                               'new' => 'boolean',
+                               'minor' => 'boolean',
+                               'bot' => 'boolean'
+                       ),
+                       'patrol' => array(
+                               'patrolled' => 'boolean'
+                       ),
+                       'timestamp' => array(
+                               'timestamp' => 'timestamp'
+                       ),
+                       'sizes' => array(
+                               'oldlen' => 'integer',
+                               'newlen' => 'integer'
+                       ),
+                       'notificationtimestamp' => array(
+                               'notificationtimestamp' => array(
+                                       ApiBase::PROP_TYPE => 'timestamp',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'comment' => array(
+                               'comment' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'parsedcomment' => array(
+                               'parsedcomment' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       '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
+                               )
+                       )
+               );
+       }
+
        public function getDescription() {
                return "Get all recent changes to pages in the logged in user's watchlist";
        }
@@ -451,7 +516,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
        }
 
        public function getHelpUrls() {
-               return 'http://www.mediawiki.org/wiki/API:Watchlist';
+               return 'https://www.mediawiki.org/wiki/API:Watchlist';
        }
 
        public function getVersion() {