(bug 47219) Allow specifying change type of Wikipedia feed items
authorkaligula <winne2i@gmail.com>
Tue, 30 Apr 2013 16:01:00 +0000 (18:01 +0200)
committerkaligula <winne2i@gmail.com>
Tue, 30 Apr 2013 16:52:56 +0000 (18:52 +0200)
It exposes field /rc_type/ as ApiQueryRecentChanges does thus allowing
user to define which (edit, external, new, log) changes to show in feed.

Bug: 47219
Change-Id: If22827129b04d423711f921307dc820d4840d9d1

RELEASE-NOTES-1.22
includes/api/ApiFeedWatchlist.php
includes/api/ApiQueryWatchlist.php

index aad11a0..ebff9d4 100644 (file)
@@ -95,6 +95,7 @@ production.
 * BREAKING CHANGE: list=allpages, list=langbacklinks, and prop=langlinks do not
   apply the new LanguageLinks hook, and thus only consider language links
   stored in the database.
+* (bug 47219) Allow specifying change type of Wikipedia feed items
 
 === Languages updated in 1.22===
 
index ddcd6ac..9f6b8b4 100644 (file)
@@ -91,6 +91,9 @@ class ApiFeedWatchlist extends ApiBase {
                        if ( $params['wlshow'] !== null ) {
                                $fauxReqArr['wlshow'] = $params['wlshow'];
                        }
+                       if ( $params['wltype'] !== null ) {
+                               $fauxReqArr['wltype'] = $params['wltype'];
+                       }
 
                        // Support linking to diffs instead of article
                        if ( $params['linktodiffs'] ) {
@@ -222,12 +225,14 @@ class ApiFeedWatchlist extends ApiBase {
                        $ret['wlowner'] = $wlparams['owner'];
                        $ret['wltoken'] = $wlparams['token'];
                        $ret['wlshow'] = $wlparams['show'];
+                       $ret['wltype'] = $wlparams['type'];
                        $ret['wlexcludeuser'] = $wlparams['excludeuser'];
                } else {
                        $ret['allrev'] = null;
                        $ret['wlowner'] = null;
                        $ret['wltoken'] = null;
                        $ret['wlshow'] = null;
+                       $ret['wltype'] = null;
                        $ret['wlexcludeuser'] = null;
                }
                return $ret;
@@ -244,6 +249,7 @@ class ApiFeedWatchlist extends ApiBase {
                        'wlowner' => $wldescr['owner'],
                        'wltoken' => $wldescr['token'],
                        'wlshow' => $wldescr['show'],
+                       'wltype' => $wldescr['type'],
                        'wlexcludeuser' => $wldescr['excludeuser'],
                );
        }
index 3ee15f6..22843f5 100644 (file)
@@ -170,6 +170,10 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                        $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
                }
 
+               if ( !is_null( $params['type'] ) ) {
+                       $this->addWhereFld( 'rc_type', $this->parseRCType( $params['type'] ) );
+               }
+
                if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
                        $this->dieUsage( 'user and excludeuser cannot be used together', 'user-excludeuser' );
                }
@@ -225,6 +229,32 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
        private function extractRowInfo( $row ) {
                $vals = array();
 
+               $type = intval( $row->rc_type );
+
+               /* Determine what kind of change this was. */
+               switch ( $type ) {
+                       case RC_EDIT:
+                               $vals['type'] = 'edit';
+                               break;
+                       case RC_NEW:
+                               $vals['type'] = 'new';
+                               break;
+                       case RC_MOVE:
+                               $vals['type'] = 'move';
+                               break;
+                       case RC_LOG:
+                               $vals['type'] = 'log';
+                               break;
+                       case RC_EXTERNAL:
+                               $vals['type'] = 'external';
+                               break;
+                       case RC_MOVE_OVER_REDIRECT:
+                               $vals['type'] = 'move over redirect';
+                               break;
+                       default:
+                               $vals['type'] = $type;
+               }
+
                if ( $this->fld_ids ) {
                        $vals['pageid'] = intval( $row->rc_cur_id );
                        $vals['revid'] = intval( $row->rc_this_oldid );
@@ -311,6 +341,27 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                return $vals;
        }
 
+       /* Copied from ApiQueryRecentChanges. */
+       private function parseRCType( $type ) {
+               if ( is_array( $type ) ) {
+                       $retval = array();
+                       foreach ( $type as $t ) {
+                               $retval[] = $this->parseRCType( $t );
+                       }
+                       return $retval;
+               }
+               switch ( $type ) {
+                       case 'edit':
+                               return RC_EDIT;
+                       case 'new':
+                               return RC_NEW;
+                       case 'log':
+                               return RC_LOG;
+                       case 'external':
+                               return RC_EXTERNAL;
+               }
+       }
+
        public function getAllowedParams() {
                return array(
                        'allrev' => false,
@@ -375,6 +426,15 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                                        '!patrolled',
                                )
                        ),
+                       'type' => array(
+                               ApiBase::PARAM_ISMULTI => true,
+                               ApiBase::PARAM_TYPE => array(
+                                       'edit',
+                                       'external',
+                                       'new',
+                                       'log',
+                               )
+                       ),
                        'owner' => array(
                                ApiBase::PARAM_TYPE => 'user'
                        ),
@@ -414,6 +474,13 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
                                'Show only items that meet this criteria.',
                                "For example, to see only minor edits done by logged-in users, set {$p}show=minor|!anon"
                        ),
+                       'type' => array(
+                               'Which types of changes to show',
+                               ' edit           - Regular page edits',
+                               ' external       - External changes',
+                               ' new            - Page creations',
+                               ' log            - Log entries',
+                       ),
                        'owner' => 'The name of the user whose watchlist you\'d like to access',
                        'token' => 'Give a security token (settable in preferences) to allow access to another user\'s watchlist'
                );
@@ -422,6 +489,17 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
        public function getResultProperties() {
                global $wgLogTypes;
                return array(
+                       '' => array(
+                               'type' => array(
+                                       ApiBase::PROP_TYPE => array(
+                                               'edit',
+                                               'new',
+                                               'move',
+                                               'log',
+                                               'move over redirect'
+                                       )
+                               )
+                       ),
                        'ids' => array(
                                'pageid' => 'integer',
                                'revid' => 'integer',