jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/357389 )

Change subject: API: Have generator=random set a non-continuation value
......................................................................


API: Have generator=random set a non-continuation value

When used as a generator, it needs a non-continuation value for
continuation to work properly. As a list it doesn't matter because lists
never non-continue.

Bug: T167141
Change-Id: I7b8ddaf73f918b31414e22fc3a13e6245c2d57d7
---
M includes/api/ApiQueryRandom.php
1 file changed, 13 insertions(+), 4 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/api/ApiQueryRandom.php b/includes/api/ApiQueryRandom.php
index cc1fc89..ce62226 100644
--- a/includes/api/ApiQueryRandom.php
+++ b/includes/api/ApiQueryRandom.php
@@ -48,7 +48,7 @@
         * @param ApiPageSet|null $resultPageSet
         * @param int $limit Number of pages to fetch
         * @param string|null $start Starting page_random
-        * @param int|null $startId Starting page_id
+        * @param int $startId Starting page_id
         * @param string|null $end Ending page_random
         * @return array (int, string|null) Number of pages left to query and 
continuation string
         */
@@ -75,8 +75,8 @@
 
                if ( $start !== null ) {
                        $start = $this->getDB()->addQuotes( $start );
-                       if ( $startId !== null ) {
-                               $startId = (int)$startId;
+                       if ( $startId > 0 ) {
+                               $startId = (int)$startId; // safety
                                $this->addWhere( "page_random = $start AND 
page_id >= $startId OR page_random > $start" );
                        } else {
                                $this->addWhere( "page_random >= $start" );
@@ -144,10 +144,19 @@
                } else {
                        $rand = wfRandom();
                        $start = $rand;
-                       $startId = null;
+                       $startId = 0;
                        $end = null;
                }
 
+               // Set the non-continue if this is being used as a generator
+               // (as a list it doesn't matter because lists never 
non-continue)
+               if ( $resultPageSet !== null ) {
+                       $endFlag = $end === null ? 0 : 1;
+                       
$this->getContinuationManager()->addGeneratorNonContinueParam(
+                               $this, 'continue', 
"$rand|$start|$startId|$endFlag"
+                       );
+               }
+
                list( $left, $continue ) =
                        $this->runQuery( $resultPageSet, $params['limit'], 
$start, $startId, $end );
                if ( $end === null && $continue === null ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/357389
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7b8ddaf73f918b31414e22fc3a13e6245c2d57d7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to