From: Brad Jorsch Date: Tue, 6 Jun 2017 14:15:49 +0000 (-0400) Subject: API: Have generator=random set a non-continuation value X-Git-Tag: 1.31.0-rc.0~2949^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=4eb3d542ce0e165c67001cccb3850ec655677c84;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/api/ApiQueryRandom.php b/includes/api/ApiQueryRandom.php index cc1fc89f07..ce62226fc6 100644 --- a/includes/api/ApiQueryRandom.php +++ b/includes/api/ApiQueryRandom.php @@ -48,7 +48,7 @@ class ApiQueryRandom extends ApiQueryGeneratorBase { * @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 @@ class ApiQueryRandom extends ApiQueryGeneratorBase { 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 @@ class ApiQueryRandom extends ApiQueryGeneratorBase { } 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 ) {