r88788 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88787‎ | r88788 | r88789 >
Date:14:01, 25 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added option to query watchlist data based on group ids instead of user id
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/api/ApiDeleteWatchlistGroup.php
@@ -11,6 +11,8 @@
1212 *
1313 * @licence GNU GPL v3+
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ *
 16+ * TODO: delete changes
1517 */
1618 class ApiDeleteWatchlistGroup extends ApiBase {
1719
@@ -63,6 +65,22 @@
6466 )
6567 );
6668
 69+ foreach ( $setsForGroup as $set ) {
 70+ $changes = $dbr->select(
 71+ 'swl_changes',
 72+ array( 'change_id' ),
 73+ array( 'change_set_id' => $set->spg_set_id )
 74+ );
 75+
 76+ foreach ( $changes as $change ) {
 77+ $dbr->select( // TODO
 78+ 'swl_changes_per_set',
 79+ array( 'change_id' ),
 80+ array( 'change_set_id' => $set->spg_set_id )
 81+ );
 82+ }
 83+ }
 84+
6785 // Find all edits linked to this group.
6886 $editsForGroup = $dbr->select(
6987 array( 'swl_sets_per_group', 'swl_sets_per_edit' ),
Index: trunk/extensions/SemanticWatchlist/api/ApiQuerySemanticWatchlist.php
@@ -24,8 +24,15 @@
2525 // Get the requests parameters.
2626 $params = $this->extractRequestParams();
2727
28 - $this->setupChangeSetQuery( $params['userid'], $params['limit'], $params['continue'] );
 28+ if ( !( isset( $params['userid'] ) XOR isset( $params['groupids'] ) ) ) {
 29+ $this->dieUsage( wfMsgExt( 'swl-err-userid-xor-groupids' ), 'userid-xor-groupids' );
 30+ }
2931
 32+ $isUserFilter = isset( $params['userid'] );
 33+ $filter = $isUserFilter ? $params['userid'] : $params['groupids'];
 34+
 35+ $this->setupChangeSetQuery( $filter, $isUserFilter, $params['limit'], $params['continue'] );
 36+
3037 $sets = $this->select( __METHOD__ );
3138 $count = 0;
3239 $resultSets = array();
@@ -60,19 +67,31 @@
6168 * Gets a list of change sets belonging to any of the watchlist groups
6269 * watched by the user, newest first.
6370 *
64 - * @param integer $userId
 71+ * @param mixed $filter User ID or array of group IDs
 72+ * @param boolean $isUserFilter
6573 * @param integer $limit
6674 * @param string $continue
6775 */
68 - protected function setupChangeSetQuery( $userId, $limit, $continue ) {
69 - $this->addTables( array( 'swl_edits', 'swl_sets_per_edit', 'swl_sets_per_group', 'swl_users_per_group' ) );
 76+ protected function setupChangeSetQuery( $filter, $isUserFilter, $limit, $continue ) {
 77+ $tables = array( 'swl_edits', 'swl_sets_per_edit', 'swl_sets_per_group' );
 78+
 79+ if ( $isUserFilter ) {
 80+ $tables[] = 'swl_users_per_group';
 81+ }
 82+
 83+ $this->addTables( $tables );
7084
7185 $this->addJoinConds( array(
7286 'swl_sets_per_edit' => array( 'INNER JOIN', array( 'edit_id=spe_edit_id' ) ),
7387 'swl_sets_per_group' => array( 'INNER JOIN', array( 'spe_set_id=spg_set_id' ) ),
74 - 'swl_users_per_group' => array( 'INNER JOIN', array( 'spg_group_id=upg_group_id' ) ),
7588 ) );
7689
 90+ if ( $isUserFilter ) {
 91+ $this->addJoinConds( array(
 92+ 'swl_users_per_group' => array( 'INNER JOIN', array( 'spg_group_id=upg_group_id' ) ),
 93+ ) );
 94+ }
 95+
7796 $this->addFields( array(
7897 'spe_set_id',
7998 'edit_user_name',
@@ -82,7 +101,7 @@
83102 ) );
84103
85104 $this->addWhere( array(
86 - 'upg_user_id' => $userId
 105+ ( $isUserFilter ? 'upg_user_id' : 'spg_group_id' ) => $filter
87106 ) );
88107
89108 $this->addOption( 'DISTINCT' );
@@ -111,15 +130,18 @@
112131 return array (
113132 'userid' => array(
114133 ApiBase::PARAM_TYPE => 'integer',
115 - ApiBase::PARAM_REQUIRED => true,
116134 ),
 135+ 'groupids' => array(
 136+ ApiBase::PARAM_TYPE => 'integer',
 137+ ApiBase::PARAM_ISMULTI => true,
 138+ ),
117139 'limit' => array(
118140 ApiBase :: PARAM_DFLT => 20,
119141 ApiBase :: PARAM_TYPE => 'limit',
120142 ApiBase :: PARAM_MIN => 1,
121143 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
122144 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
123 - ),
 145+ ),
124146 'continue' => null,
125147 );
126148 }
@@ -131,6 +153,7 @@
132154 public function getParamDescription() {
133155 return array (
134156 'userid' => 'The ID of the user for which to return semantic watchlist data.',
 157+ 'groupids' => 'The IDs of the groups for which to return semantic watchlist data.',
135158 'continue' => 'Offset number from where to continue the query',
136159 'limit' => 'Max amount of words to return',
137160 );
@@ -141,7 +164,7 @@
142165 * @see includes/api/ApiBase#getDescription()
143166 */
144167 public function getDescription() {
145 - return 'Returns a list of modified properties per page for a persons semantic watchlist.';
 168+ return 'Returns a list of sets of changes for the either specified user of specified group(s).';
146169 }
147170
148171 /**
@@ -162,6 +185,8 @@
163186 return array (
164187 'api.php?action=query&list=semanticwatchlist&swuserid=1',
165188 'api.php?action=query&list=semanticwatchlist&swuserid=1&swlimit=42&swcontinue=20110514143957-9001',
 189+ 'api.php?action=query&list=semanticwatchlist&swgroupids=1',
 190+ 'api.php?action=query&list=semanticwatchlist&swgroupids=1|42&swlimit=34',
166191 );
167192 }
168193
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
@@ -63,6 +63,9 @@
6464 'swl-prefs-namespace-label' => "'''$1''': {{PLURAL:$2|property|properties}} $3 from namespace ''$4''",
6565 'swl-prefs-concept-label' => "'''$1''': {{PLURAL:$2|property|properties}} $3 from concept ''$4''",
6666 'swl-prefs-emailnofity' => 'E-mail me on changes to properties I am watching',
 67+
 68+ // API
 69+ 'swl-err-userid-xor-groupids' => 'Either the userid or the groupids parameter needs to be specified, but not both.',
6770 );
6871
6972 /** Message documentation (Message documentation)

Status & tagging log