r42198 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r42197 | r42198 (on ViewVC) | r42199 >
Date:10:14, 18 October 2008
Author:ialex
Status:deferred
Tags:api 
Comment:Per Catrope's request, commiting patch on bug 16018:
* (bug 16018) Added uccontinue parameter to list=usercontribs so paging works properly when multiple users are queried or a userprefix is used
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryUserContributions.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryUserContributions.php	(revision 42197)
+++ trunk/phase3/includes/api/ApiQueryUserContributions.php	(revision 42198)
@@ -62,6 +62,7 @@
 		if(isset($this->params['userprefix']))
 		{
 			$this->prefixMode = true;
+			$this->multiUserMode = true;
 			$this->userprefix = $this->params['userprefix'];
 		}
 		else
@@ -72,6 +73,7 @@
 			foreach($this->params['user'] as $u)
 				$this->prepareUsername($u);
 			$this->prefixMode = false;
+			$this->multiUserMode = (count($this->params['user']) > 1);
 		}
 		$this->prepareQuery();
 
@@ -87,7 +89,10 @@
 		while ( $row = $db->fetchObject( $res ) ) {
 			if (++ $count > $limit) {
 				// We've reached the one extra which shows that there are additional pages to be had. Stop here...
-				$this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->rev_timestamp));
+				if($this->multiUserMode)
+					$this->setContinueEnumParameter('continue', $this->continueStr($row));
+				else
+					$this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->rev_timestamp));
 				break;
 			}
 
@@ -132,13 +137,28 @@
 		//anything we retrieve.
 		$this->addTables(array('revision', 'page'));
 		$this->addWhere('page_id=rev_page');
+		
+		// Handle continue parameter
+		if($this->multiUserMode && !is_null($this->params['continue']))
+		{
+			$continue = explode('|', $this->params['continue']);
+			if(count($continue) != 2)
+				$this->dieUsage("Invalid continue param. You should pass the original " .
+					"value returned by the previous query", "_badcontinue");
+			$encUser = $this->getDB()->strencode($continue[0]);
+			$encTS = wfTimestamp(TS_MW, $continue[1]);
+			$op = ($this->params['dir'] == 'older' ? '<' : '>');
+			$this->addWhere("rev_user_text $op '$encUser' OR " .
+					"(rev_user_text = '$encUser' AND " .
+					"rev_timestamp $op= '$encTS')");
+		}
 
 		$this->addWhereFld('rev_deleted', 0);
 		// We only want pages by the specified users.
 		if($this->prefixMode)
 			$this->addWhere("rev_user_text LIKE '" . $this->getDb()->escapeLike($this->userprefix) . "%'");
 		else
-			$this->addWhereFld( 'rev_user_text', $this->usernames );
+			$this->addWhereFld('rev_user_text', $this->usernames);
 		// ... and in the specified timeframe.
 		// Ensure the same sort order for rev_user_text and rev_timestamp
 		// so our query is indexed
@@ -212,6 +232,12 @@
 
 		return $vals;
 	}
+	
+	private function continueStr($row)
+	{
+		return $row->rev_user_text . '|' .
+			wfTimestamp(TS_ISO_8601, $row->rev_timestamp);
+	}
 
 	public function getAllowedParams() {
 		return array (
@@ -228,6 +254,7 @@
 			'end' => array (
 				ApiBase :: PARAM_TYPE => 'timestamp'
 			),
+			'continue' => null,
 			'user' => array (
 				ApiBase :: PARAM_ISMULTI => true
 			),
@@ -269,6 +296,7 @@
 			'limit' => 'The maximum number of contributions to return.',
 			'start' => 'The start timestamp to return from.',
 			'end' => 'The end timestamp to return to.',
+			'continue' => 'When more results are available, use this to continue.',
 			'user' => 'The user to retrieve contributions for.',
 			'userprefix' => 'Retrieve contibutions for all users whose names begin with this value. Overrides ucuser.',
 			'dir' => 'The direction to search (older or newer).',
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 42197)
+++ trunk/phase3/RELEASE-NOTES	(revision 42198)
@@ -347,6 +347,8 @@
   list=categorymembers
 * (bug 16017) list=categorymembers sets invalid continue parameters for
   sortkeys containing pipes
+* (bug 16018) Added uccontinue parameter to list=usercontribs so paging
+  works properly when multiple users are queried or a userprefix is used
 
 === Languages updated in 1.14 ===
 
Views
Toolbox