X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiContinuationManager.php;h=7da8ed9a5b196de6ee1fdb5c4439dacb1e8c1b04;hb=b9333ae6557b86e4b074025c43e77e745610b345;hp=6601fb7463e18b95c19bf8dc17d5c08b05e6dba2;hpb=fe79bc528b0e054aa630bd4fcfcdd4a9804892da;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiContinuationManager.php b/includes/api/ApiContinuationManager.php index 6601fb7463..7da8ed9a5b 100644 --- a/includes/api/ApiContinuationManager.php +++ b/includes/api/ApiContinuationManager.php @@ -31,6 +31,7 @@ class ApiContinuationManager { private $continuationData = []; private $generatorContinuationData = []; + private $generatorNonContinuationData = []; private $generatorParams = []; private $generatorDone = false; @@ -39,7 +40,7 @@ class ApiContinuationManager { * @param ApiBase $module Module starting the continuation * @param ApiBase[] $allModules Contains ApiBase instances that will be executed * @param array $generatedModules Names of modules that depend on the generator - * @throws UsageException + * @throws ApiUsageException */ public function __construct( ApiBase $module, array $allModules = [], array $generatedModules = [] @@ -56,10 +57,7 @@ class ApiContinuationManager { if ( $continue !== '' ) { $continue = explode( '||', $continue ); if ( count( $continue ) !== 2 ) { - throw new UsageException( - 'Invalid continue param. You should pass the original value returned by the previous query', - 'badcontinue' - ); + throw ApiUsageException::newWithMessage( $module->getMain(), 'apierror-badcontinue' ); } $this->generatorDone = ( $continue[0] === '-' ); $skip = explode( '|', $continue[1] ); @@ -142,6 +140,26 @@ class ApiContinuationManager { $this->continuationData[$name][$paramName] = $paramValue; } + /** + * Set the non-continuation parameter for the generator module + * + * In case the generator isn't going to be continued, this sets the fields + * to return. + * + * @since 1.28 + * @param ApiBase $module + * @param string $paramName + * @param string|array $paramValue + */ + public function addGeneratorNonContinueParam( ApiBase $module, $paramName, $paramValue ) { + $name = $module->getModuleName(); + $paramName = $module->encodeParamName( $paramName ); + if ( is_array( $paramValue ) ) { + $paramValue = implode( '|', $paramValue ); + } + $this->generatorNonContinuationData[$name][$paramName] = $paramValue; + } + /** * Set the continuation parameter for the generator module * @param ApiBase $module @@ -165,6 +183,15 @@ class ApiContinuationManager { return array_merge_recursive( $this->continuationData, $this->generatorContinuationData ); } + /** + * Fetch raw non-continuation data + * @since 1.28 + * @return array + */ + public function getRawNonContinuation() { + return $this->generatorNonContinuationData; + } + /** * Fetch continuation result data * @return array [ (array)$data, (bool)$batchcomplete ] @@ -192,8 +219,13 @@ class ApiContinuationManager { foreach ( $continuationData as $module => $kvp ) { $data += $kvp; } - $data += $this->generatorParams; - $generatorKeys = implode( '|', array_keys( $this->generatorParams ) ); + $generatorParams = []; + foreach ( $this->generatorNonContinuationData as $kvp ) { + $generatorParams += $kvp; + } + $generatorParams += $this->generatorParams; + $data += $generatorParams; + $generatorKeys = implode( '|', array_keys( $generatorParams ) ); } elseif ( $this->generatorContinuationData ) { // All the generator-using modules are complete, but the // generator isn't. Continue the generator and restart the