From 018f7d985497329b2e766e7e29af6daa77e5be67 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 18 Oct 2008 10:14:02 +0000 Subject: [PATCH] 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 --- RELEASE-NOTES | 2 ++ includes/api/ApiQueryUserContributions.php | 32 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 268c2b6f32..80b0e8a3a1 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -347,6 +347,8 @@ The following extensions are migrated into MediaWiki 1.14: 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 === diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index 966a047662..da832c9d01 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -62,6 +62,7 @@ class ApiQueryContributions extends ApiQueryBase { if(isset($this->params['userprefix'])) { $this->prefixMode = true; + $this->multiUserMode = true; $this->userprefix = $this->params['userprefix']; } else @@ -72,6 +73,7 @@ class ApiQueryContributions extends ApiQueryBase { 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 @@ class ApiQueryContributions extends ApiQueryBase { 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 @@ class ApiQueryContributions extends ApiQueryBase { //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 @@ class ApiQueryContributions extends ApiQueryBase { 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 @@ class ApiQueryContributions extends ApiQueryBase { 'end' => array ( ApiBase :: PARAM_TYPE => 'timestamp' ), + 'continue' => null, 'user' => array ( ApiBase :: PARAM_ISMULTI => true ), @@ -269,6 +296,7 @@ class ApiQueryContributions extends ApiQueryBase { '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).', -- 2.20.1