From d797477d7b329c84c48dd9dc03622b091125239b Mon Sep 17 00:00:00 2001 From: kaligula Date: Tue, 30 Apr 2013 18:01:00 +0200 Subject: [PATCH] (bug 47219) Allow specifying change type of Wikipedia feed items 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 | 1 + includes/api/ApiFeedWatchlist.php | 6 +++ includes/api/ApiQueryWatchlist.php | 78 ++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index aad11a010b..ebff9d4a90 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -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=== diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php index ddcd6ac4b8..9f6b8b4794 100644 --- a/includes/api/ApiFeedWatchlist.php +++ b/includes/api/ApiFeedWatchlist.php @@ -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'], ); } diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 3ee15f638a..22843f50a1 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -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', -- 2.20.1