http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88272

Revision: 88272
Author:   jeroendedauw
Date:     2011-05-16 21:19:12 +0000 (Mon, 16 May 2011)
Log Message:
-----------
implemented API module to query change sets

Modified Paths:
--------------
    trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php

Modified: trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php        
2011-05-16 21:14:51 UTC (rev 88271)
+++ trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php        
2011-05-16 21:19:12 UTC (rev 88272)
@@ -23,10 +23,82 @@
                // Get the requests parameters.
                $params = $this->extractRequestParams();
                
-
+               $this->setupChangeSetQuery( $params['userid'], 
$params['limit'], $params['continue'] );         
+               
+               $sets = $this->select( __METHOD__ );
+               $count = 0;     
+               $resultSets = array();  
+               
+               foreach ( $sets as $set ) {
+                       if ( ++$count > $params['limit'] ) {
+                               // We've reached the one extra which shows that
+                               // there are additional pages to be had. Stop 
here...
+                               $this->setContinueEnumParameter( 'continue', 
$set->set_time . '-' . $set->set_id );
+                               break;
+                       }
+                       
+                       $resultSets[] = array(
+                               'id' => $set->set_id,
+                               'user_name' => $set->set_user_name,
+                               'page_id' => $set->set_page_id,
+                               'time' => $set->set_time,
+                       );
+               }
+               
+               $this->getResult()->setIndexedTagName( $resultSets, 'set' );
+               
+               $this->getResult()->addValue(
+                       null,
+                       'sets',
+                       $resultSets
+               );
        }
        
        /**
+        * Gets a list of change sets belonging to any of the watchlist groups
+        * watched by the user, newest first.
+        * 
+        * @param integer $userId
+        * @param integer $limit
+        * @param string $continue
+        */
+       protected function setupChangeSetQuery( $userId, $limit, $continue ) {
+               $this->addTables( array( 'swl_sets', 'swl_sets_per_group', 
'swl_users_per_group' ) );
+
+               $this->addJoinConds( array(
+                       'swl_sets_per_group' => array( 'INNER JOIN', array( 
'set_id=spg_set_id' ) ),
+                       'swl_users_per_group' => array( 'INNER JOIN', array( 
'spg_group_id=upg_group_id' ) ),
+               ) );            
+               
+               $this->addFields( array(
+               'set_id',
+               'set_user_name',
+               'set_page_id',
+               'set_time',
+               ) );
+               
+               $this->addWhere( array(
+                       'upg_user_id' => $userId
+               ) );
+               
+               $this->addOption( 'LIMIT', $limit + 1 );
+               $this->addOption( 'ORDER BY', 'set_time DESC, set_id DESC' );
+               
+               if ( !is_null( $continue ) ) {
+                       $continueParams = explode( '-', $continue );
+                       
+                       if ( count( $continueParams ) == 2 ) {
+                               $dbr = wfGetDB( DB_SLAVE );
+                               $this->addWhere( 'set_time <= ' . 
$dbr->addQuotes( $continueParams[0] ) );
+                               $this->addWhere( 'set_id <= ' . 
$dbr->addQuotes( $continueParams[1] ) );                                        
+                       }
+                       else {
+                               // TODO: error
+                       }
+               }               
+       }       
+       
+       /**
         * (non-PHPdoc)
         * @see includes/api/ApiBase#getAllowedParams()
         */
@@ -37,7 +109,7 @@
                                ApiBase::PARAM_REQUIRED => true,
                        ),
                        'limit' => array(
-                               ApiBase :: PARAM_DFLT => 500,
+                               ApiBase :: PARAM_DFLT => 20,
                                ApiBase :: PARAM_TYPE => 'limit',
                                ApiBase :: PARAM_MIN => 1,
                                ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
@@ -83,7 +155,8 @@
         */
        protected function getExamples() {
                return array (
-                       'api.php?action=query&list=semanticwatchlist',
+                       
'api.php?action=query&list=semanticwatchlist&swuserid=1',
+                       
'api.php?action=query&list=semanticwatchlist&swuserid=1&swlimit=42&swcontinue=20110514143957-9001',
                );
        }
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to