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

Revision: 88788
Author:   jeroendedauw
Date:     2011-05-25 14:01:03 +0000 (Wed, 25 May 2011)
Log Message:
-----------
added option to query watchlist data based on group ids instead of user id

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

Modified: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
===================================================================
--- trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php       
2011-05-25 13:48:19 UTC (rev 88787)
+++ trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php       
2011-05-25 14:01:03 UTC (rev 88788)
@@ -63,6 +63,9 @@
        'swl-prefs-namespace-label' => "'''$1''': 
{{PLURAL:$2|property|properties}} $3 from namespace ''$4''",
        'swl-prefs-concept-label' => "'''$1''': 
{{PLURAL:$2|property|properties}} $3 from concept ''$4''",
        'swl-prefs-emailnofity' => 'E-mail me on changes to properties I am 
watching',
+
+       // API
+       'swl-err-userid-xor-groupids' => 'Either the userid or the groupids 
parameter needs to be specified, but not both.',
 );
 
 /** Message documentation (Message documentation)

Modified: trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php
===================================================================
--- trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php  
2011-05-25 13:48:19 UTC (rev 88787)
+++ trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php  
2011-05-25 14:01:03 UTC (rev 88788)
@@ -11,6 +11,8 @@
  *
  * @licence GNU GPL v3+
  * @author Jeroen De Dauw < [email protected] >
+ * 
+ * TODO: delete changes
  */
 class ApiDeleteWatchlistGroup extends ApiBase {
        
@@ -63,6 +65,22 @@
                        )
                );
                
+               foreach ( $setsForGroup as $set ) {
+                       $changes = $dbr->select(
+                               'swl_changes',
+                               array( 'change_id' ),
+                               array( 'change_set_id' => $set->spg_set_id )
+                       );
+                       
+                       foreach ( $changes as $change ) {
+                               $dbr->select( // TODO
+                                       'swl_changes_per_set',
+                                       array( 'change_id' ),
+                                       array( 'change_set_id' => 
$set->spg_set_id )
+                               );
+                       }
+               }
+               
                // Find all edits linked to this group.
                $editsForGroup = $dbr->select(
                        array( 'swl_sets_per_group', 'swl_sets_per_edit' ),

Modified: trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php
===================================================================
--- trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php        
2011-05-25 13:48:19 UTC (rev 88787)
+++ trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php        
2011-05-25 14:01:03 UTC (rev 88788)
@@ -24,8 +24,15 @@
                // Get the requests parameters.
                $params = $this->extractRequestParams();
                
-               $this->setupChangeSetQuery( $params['userid'], 
$params['limit'], $params['continue'] );         
+               if ( !( isset( $params['userid'] ) XOR isset( 
$params['groupids'] ) ) ) {
+                       $this->dieUsage( wfMsgExt( 
'swl-err-userid-xor-groupids' ), 'userid-xor-groupids' );
+               }
                
+               $isUserFilter = isset( $params['userid'] );
+               $filter = $isUserFilter ? $params['userid'] : 
$params['groupids'];
+               
+               $this->setupChangeSetQuery( $filter, $isUserFilter, 
$params['limit'], $params['continue'] );            
+               
                $sets = $this->select( __METHOD__ );
                $count = 0;     
                $resultSets = array();  
@@ -60,19 +67,31 @@
         * Gets a list of change sets belonging to any of the watchlist groups
         * watched by the user, newest first.
         * 
-        * @param integer $userId
+        * @param mixed $filter User ID or array of group IDs
+        * @param boolean $isUserFilter
         * @param integer $limit
         * @param string $continue
         */
-       protected function setupChangeSetQuery( $userId, $limit, $continue ) {
-               $this->addTables( array( 'swl_edits', 'swl_sets_per_edit', 
'swl_sets_per_group', 'swl_users_per_group' ) );
+       protected function setupChangeSetQuery( $filter, $isUserFilter, $limit, 
$continue ) {
+               $tables = array( 'swl_edits', 'swl_sets_per_edit', 
'swl_sets_per_group' );
+               
+               if ( $isUserFilter ) {
+                       $tables[] = 'swl_users_per_group';
+               }
+               
+               $this->addTables( $tables );
 
                $this->addJoinConds( array(
                        'swl_sets_per_edit' => array( 'INNER JOIN', array( 
'edit_id=spe_edit_id' ) ),
                        'swl_sets_per_group' => array( 'INNER JOIN', array( 
'spe_set_id=spg_set_id' ) ),
-                       'swl_users_per_group' => array( 'INNER JOIN', array( 
'spg_group_id=upg_group_id' ) ),
                ) );
                
+               if ( $isUserFilter ) {
+                       $this->addJoinConds( array(
+                               'swl_users_per_group' => array( 'INNER JOIN', 
array( 'spg_group_id=upg_group_id' ) ),
+                       ) );
+               }
+               
                $this->addFields( array(
                        'spe_set_id',
                        'edit_user_name',
@@ -82,7 +101,7 @@
                ) );
                
                $this->addWhere( array(
-                       'upg_user_id' => $userId
+                       ( $isUserFilter ? 'upg_user_id' : 'spg_group_id' ) => 
$filter
                ) );
                
                $this->addOption( 'DISTINCT' );
@@ -111,15 +130,18 @@
                return array (
                        'userid' => array(
                                ApiBase::PARAM_TYPE => 'integer',
-                               ApiBase::PARAM_REQUIRED => true,
                        ),
+                       'groupids' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ),
                        'limit' => array(
                                ApiBase :: PARAM_DFLT => 20,
                                ApiBase :: PARAM_TYPE => 'limit',
                                ApiBase :: PARAM_MIN => 1,
                                ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
                                ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
-                       ),                      
+                       ),
                        'continue' => null,
                );
        }
@@ -131,6 +153,7 @@
        public function getParamDescription() {
                return array (
                        'userid' => 'The ID of the user for which to return 
semantic watchlist data.',
+                       'groupids' => 'The IDs of the groups for which to 
return semantic watchlist data.',
                        'continue' => 'Offset number from where to continue the 
query',
                        'limit'   => 'Max amount of words to return',
                );
@@ -141,7 +164,7 @@
         * @see includes/api/ApiBase#getDescription()
         */
        public function getDescription() {
-               return 'Returns a list of modified properties per page for a 
persons semantic watchlist.';
+               return 'Returns a list of sets of changes for the either 
specified user of specified group(s).';
        }
        
        /**
@@ -162,6 +185,8 @@
                return array (
                        
'api.php?action=query&list=semanticwatchlist&swuserid=1',
                        
'api.php?action=query&list=semanticwatchlist&swuserid=1&swlimit=42&swcontinue=20110514143957-9001',
+                       
'api.php?action=query&list=semanticwatchlist&swgroupids=1',
+                       
'api.php?action=query&list=semanticwatchlist&swgroupids=1|42&swlimit=34',
                );
        }
 


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

Reply via email to