/** * Query execution happens in the following steps: * #1 Create a PageSet object with any pages requested by the user * #2 If using a generator, execute it to get a new ApiPageSet object * #3 Instantiate all requested modules. * This way the PageSet object will know what shared data is required, * and minimize DB calls. * #4 Output all normalization and redirect resolution information * #5 Execute all requested modules */ public function execute() { $this->mParams = $this->extractRequestParams(); // Instantiate requested modules $allModules = array(); $this->instantiateModules($allModules, 'prop'); $propModules = array_keys($allModules); $this->instantiateModules($allModules, 'list'); $this->instantiateModules($allModules, 'meta'); // Filter modules based on continue parameter $continuationManager = new ApiContinuationManager($this, $allModules, $propModules); $this->setContinuationManager($continuationManager); $modules = $continuationManager->getRunModules(); if (!$continuationManager->isGeneratorDone()) { // Query modules may optimize data requests through the $this->getPageSet() // object by adding extra fields from the page table. foreach ($modules as $module) { $module->requestExtraData($this->mPageSet); } // Populate page/revision information $this->mPageSet->execute(); // Record page information (title, namespace, if exists, etc) $this->outputGeneralPageInfo(); } else { $this->mPageSet->executeDryRun(); } $cacheMode = $this->mPageSet->getCacheMode(); // Execute all unfinished modules /** @var $module ApiQueryBase */ foreach ($modules as $module) { $params = $module->extractRequestParams(); $cacheMode = $this->mergeCacheMode($cacheMode, $module->getCacheMode($params)); $module->execute(); Hooks::run('APIQueryAfterExecute', array(&$module)); } // Set the cache mode $this->getMain()->setCacheMode($cacheMode); // Write the continuation data into the result $this->setContinuationManager(null); if ($this->mParams['rawcontinue']) { $data = $continuationManager->getRawContinuation(); if ($data) { $this->getResult()->addValue(null, 'query-continue', $data, ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK); } } else { $continuationManager->setContinuationIntoResult($this->getResult()); } /// @todo: Remove this after a suitable period of time. When REL1_26 is cut, if not before. if ($this->mParams['continue'] === null && !$this->mParams['rawcontinue'] && $this->getResult()->getResultData('continue') !== null) { $this->setWarning('Formatting of continuation data has changed. ' . 'To receive raw query-continue data, use the \'rawcontinue\' parameter. ' . 'To silence this warning, pass an empty string for \'continue\' in the initial query.'); } }
/** * Query execution happens in the following steps: * #1 Create a PageSet object with any pages requested by the user * #2 If using a generator, execute it to get a new ApiPageSet object * #3 Instantiate all requested modules. * This way the PageSet object will know what shared data is required, * and minimize DB calls. * #4 Output all normalization and redirect resolution information * #5 Execute all requested modules */ public function execute() { $this->mParams = $this->extractRequestParams(); // Instantiate requested modules $allModules = []; $this->instantiateModules($allModules, 'prop'); $propModules = array_keys($allModules); $this->instantiateModules($allModules, 'list'); $this->instantiateModules($allModules, 'meta'); // Filter modules based on continue parameter $continuationManager = new ApiContinuationManager($this, $allModules, $propModules); $this->setContinuationManager($continuationManager); $modules = $continuationManager->getRunModules(); if (!$continuationManager->isGeneratorDone()) { // Query modules may optimize data requests through the $this->getPageSet() // object by adding extra fields from the page table. foreach ($modules as $module) { $module->requestExtraData($this->mPageSet); } // Populate page/revision information $this->mPageSet->execute(); // Record page information (title, namespace, if exists, etc) $this->outputGeneralPageInfo(); } else { $this->mPageSet->executeDryRun(); } $cacheMode = $this->mPageSet->getCacheMode(); // Execute all unfinished modules /** @var $module ApiQueryBase */ foreach ($modules as $module) { $params = $module->extractRequestParams(); $cacheMode = $this->mergeCacheMode($cacheMode, $module->getCacheMode($params)); $module->execute(); Hooks::run('APIQueryAfterExecute', [&$module]); } // Set the cache mode $this->getMain()->setCacheMode($cacheMode); // Write the continuation data into the result $this->setContinuationManager(null); if ($this->mParams['rawcontinue']) { $data = $continuationManager->getRawNonContinuation(); if ($data) { $this->getResult()->addValue(null, 'query-noncontinue', $data, ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK); } $data = $continuationManager->getRawContinuation(); if ($data) { $this->getResult()->addValue(null, 'query-continue', $data, ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK); } } else { $continuationManager->setContinuationIntoResult($this->getResult()); } }
/** * Query execution happens in the following steps: * #1 Create a PageSet object with any pages requested by the user * #2 If using a generator, execute it to get a new ApiPageSet object * #3 Instantiate all requested modules. * This way the PageSet object will know what shared data is required, * and minimize DB calls. * #4 Output all normalization and redirect resolution information * #5 Execute all requested modules */ public function execute() { $this->mParams = $this->extractRequestParams(); // Instantiate requested modules $allModules = array(); $this->instantiateModules($allModules, 'prop'); $propModules = array_keys($allModules); $this->instantiateModules($allModules, 'list'); $this->instantiateModules($allModules, 'meta'); // Filter modules based on continue parameter list($generatorDone, $modules) = $this->getResult()->beginContinuation($this->mParams['continue'], $allModules, $propModules); if (!$generatorDone) { // Query modules may optimize data requests through the $this->getPageSet() // object by adding extra fields from the page table. foreach ($modules as $module) { $module->requestExtraData($this->mPageSet); } // Populate page/revision information $this->mPageSet->execute(); // Record page information (title, namespace, if exists, etc) $this->outputGeneralPageInfo(); } else { $this->mPageSet->executeDryRun(); } $cacheMode = $this->mPageSet->getCacheMode(); // Execute all unfinished modules /** @var $module ApiQueryBase */ foreach ($modules as $module) { $params = $module->extractRequestParams(); $cacheMode = $this->mergeCacheMode($cacheMode, $module->getCacheMode($params)); $module->profileIn(); $module->execute(); wfRunHooks('APIQueryAfterExecute', array(&$module)); $module->profileOut(); } // Set the cache mode $this->getMain()->setCacheMode($cacheMode); // Write the continuation data into the result $this->getResult()->endContinuation($this->mParams['continue'] === null ? 'raw' : 'standard'); }
/** * Query execution happens in the following steps: * #1 Create a PageSet object with any pages requested by the user * #2 If using a generator, execute it to get a new ApiPageSet object * #3 Instantiate all requested modules. * This way the PageSet object will know what shared data is required, * and minimize DB calls. * #4 Output all normalization and redirect resolution information * #5 Execute all requested modules */ public function execute() { $this->mParams = $this->extractRequestParams(); // $pagesetParams is a array of parameter names used by the pageset generator // or null if pageset has already finished and is no longer needed // $completeModules is a set of complete modules with the name as key $this->initContinue($pagesetParams, $completeModules); // Instantiate requested modules $allModules = array(); $this->instantiateModules($allModules, 'prop'); $propModules = $allModules; // Keep a copy $this->instantiateModules($allModules, 'list'); $this->instantiateModules($allModules, 'meta'); // Filter modules based on continue parameter $modules = $this->initModules($allModules, $completeModules, $pagesetParams !== null); // Execute pageset if in legacy mode or if pageset is not done if ($completeModules === null || $pagesetParams !== null) { // Populate page/revision information $this->mPageSet->execute(); // Record page information (title, namespace, if exists, etc) $this->outputGeneralPageInfo(); } else { $this->mPageSet->executeDryRun(); } $cacheMode = $this->mPageSet->getCacheMode(); // Execute all unfinished modules /** @var $module ApiQueryBase */ foreach ($modules as $module) { $params = $module->extractRequestParams(); $cacheMode = $this->mergeCacheMode($cacheMode, $module->getCacheMode($params)); $module->profileIn(); $module->execute(); wfRunHooks('APIQueryAfterExecute', array(&$module)); $module->profileOut(); } // Set the cache mode $this->getMain()->setCacheMode($cacheMode); if ($completeModules === null) { return; // Legacy continue, we are done } // Reformat query-continue result section $result = $this->getResult(); $qc = $result->getData(); if (isset($qc['query-continue'])) { $qc = $qc['query-continue']; $result->unsetValue(null, 'query-continue'); } elseif ($this->mGeneratorContinue !== null) { $qc = array(); } else { // no more "continue"s, we are done! return; } // we are done with all the modules that do not have result in query-continue $completeModules = array_merge($completeModules, array_diff_key($modules, $qc)); if ($pagesetParams !== null) { // The pageset is still in use, check if all props have finished $incompleteProps = array_intersect_key($propModules, $qc); if (count($incompleteProps) > 0) { // Properties are not done, continue with the same pageset state - copy current parameters $main = $this->getMain(); $contValues = array(); foreach ($pagesetParams as $param) { // The param name is already prefix-encoded $contValues[$param] = $main->getVal($param); } } elseif ($this->mGeneratorContinue !== null) { // Move to the next set of pages produced by pageset, properties need to be restarted $contValues = $this->mGeneratorContinue; $pagesetParams = array_keys($contValues); $completeModules = array_diff_key($completeModules, $propModules); } else { // Done with the pageset, finish up with the the lists and meta modules $pagesetParams = null; } } $continue = '||' . implode('|', array_keys($completeModules)); if ($pagesetParams !== null) { // list of all pageset parameters to use in the next request $continue = implode('|', $pagesetParams) . $continue; } else { // we are done with the pageset $contValues = array(); $continue = '-' . $continue; } $contValues['continue'] = $continue; foreach ($qc as $qcModule) { foreach ($qcModule as $qcKey => $qcValue) { $contValues[$qcKey] = $qcValue; } } $this->getResult()->addValue(null, 'continue', $contValues); }