API: Add type filtering to list=recentchanges
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 12 Oct 2007 14:03:43 +0000 (14:03 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 12 Oct 2007 14:03:43 +0000 (14:03 +0000)
RELEASE-NOTES
includes/api/ApiQueryRecentChanges.php

index e0e635c..1ad1b68 100644 (file)
@@ -124,6 +124,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API
 * (bug 11632) Breaking change: Specify the type of a change in the recentchanges list
   as 'edit', 'new', 'log' instead of 0, 1, 2, respectively.
 * Compatibility fix for PHP 5.0.x.
+* Add rctype parameter to list=recentchanges that filters by type
 
 === Languages updated in 1.12 ===
 
index 6809840..a80b6c7 100644 (file)
@@ -49,7 +49,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
         */
        public function execute() {
                /* Initialize vars */
-               $limit = $prop = $namespace = $show = $dir = $start = $end = null;
+               $limit = $prop = $namespace = $show = $type = $dir = $start = $end = null;
                
                /* Get the parameters of the request. */
                extract($this->extractRequestParams());
@@ -63,6 +63,8 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                $this->addWhereRange('rc_timestamp', $dir, $start, $end);
                $this->addWhereFld('rc_namespace', $namespace);
                $this->addWhereFld('rc_deleted', 0);
+               if(!is_null($type))
+                               $this->addWhereFld('rc_type', $this->parseRCType($type));
 
                if (!is_null($show)) {
                        $show = array_flip($show);
@@ -240,6 +242,23 @@ class ApiQueryRecentChanges extends ApiQueryBase {
 
                return $vals;
        }
+       
+       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;
+                       }
+       }                       
 
        protected function getAllowedParams() {
                return array (
@@ -290,6 +309,14 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                                ApiBase :: PARAM_MIN => 1,
                                ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
                                ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+                       ),
+                       'type' => array (
+                               ApiBase :: PARAM_ISMULTI => true,
+                               ApiBase :: PARAM_TYPE => array (
+                                       'edit',
+                                       'new', 
+                                       'log'
+                               )
                        )
                );
        }
@@ -305,6 +332,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
                                'Show only items that meet this criteria.',
                                'For example, to see only minor edits done by logged-in users, set show=minor|!anon'
                        ),
+                       'type' => 'Which types of changes to show.',
                        'limit' => 'How many total pages to return.'
                );
        }