summaryrefslogtreecommitdiff
path: root/includes/api/ApiQuery.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQuery.php')
-rw-r--r--includes/api/ApiQuery.php59
1 files changed, 48 insertions, 11 deletions
diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php
index 149e4082..49ddcdd3 100644
--- a/includes/api/ApiQuery.php
+++ b/includes/api/ApiQuery.php
@@ -209,11 +209,17 @@ class ApiQuery extends ApiBase {
$this->InstantiateModules($modules, 'list', $this->mQueryListModules);
$this->InstantiateModules($modules, 'meta', $this->mQueryMetaModules);
+ $cacheMode = 'public';
+
//
// If given, execute generator to substitute user supplied data with generated data.
//
- if (isset ($this->params['generator'])) {
- $this->executeGeneratorModule($this->params['generator'], $modules);
+ if ( isset ( $this->params['generator'] ) ) {
+ $generator = $this->newGenerator( $this->params['generator'] );
+ $params = $generator->extractRequestParams();
+ $cacheMode = $this->mergeCacheMode( $cacheMode,
+ $generator->getCacheMode( $params ) );
+ $this->executeGeneratorModule( $generator, $modules );
} else {
// Append custom fields and populate page/revision information
$this->addCustomFldsToPageSet($modules, $this->mPageSet);
@@ -229,11 +235,35 @@ class ApiQuery extends ApiBase {
// Execute all requested modules.
//
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 );
+ }
+
+ /**
+ * Update a cache mode string, applying the cache mode of a new module to it.
+ * The cache mode may increase in the level of privacy, but public modules
+ * added to private data do not decrease the level of privacy.
+ */
+ protected function mergeCacheMode( $cacheMode, $modCacheMode ) {
+ if ( $modCacheMode === 'anon-public-user-private' ) {
+ if ( $cacheMode !== 'private' ) {
+ $cacheMode = 'anon-public-user-private';
+ }
+ } elseif ( $modCacheMode === 'public' ) {
+ // do nothing, if it's public already it will stay public
+ } else { // private
+ $cacheMode = 'private';
+ }
+ return $cacheMode;
}
/**
@@ -409,13 +439,9 @@ class ApiQuery extends ApiBase {
}
/**
- * For generator mode, execute generator, and use its output as new
- * ApiPageSet
- * @param $generatorName string Module name
- * @param $modules array of module objects
+ * Create a generator object of the given type and return it
*/
- protected function executeGeneratorModule($generatorName, $modules) {
-
+ public function newGenerator( $generatorName ) {
// Find class that implements requested generator
if (isset ($this->mQueryListModules[$generatorName])) {
$className = $this->mQueryListModules[$generatorName];
@@ -432,8 +458,19 @@ class ApiQuery extends ApiBase {
$generator = new $className ($this, $generatorName);
if (!$generator instanceof ApiQueryGeneratorBase)
$this->dieUsage("Module $generatorName cannot be used as a generator", "badgenerator");
-
$generator->setGeneratorMode();
+ return $generator;
+ }
+
+ /**
+ * For generator mode, execute generator, and use its output as new
+ * ApiPageSet
+ * @param $generatorName string Module name
+ * @param $modules array of module objects
+ */
+ protected function executeGeneratorModule( $generator, $modules ) {
+ // Generator results
+ $resultPageSet = new ApiPageSet( $this, $this->redirects, $this->convertTitles );
// Add any additional fields modules may need
$generator->requestExtraData($this->mPageSet);
@@ -580,8 +617,8 @@ class ApiQuery extends ApiBase {
public function getVersion() {
$psModule = new ApiPageSet($this);
$vers = array ();
- $vers[] = __CLASS__ . ': $Id: ApiQuery.php 48629 2009-03-20 11:40:54Z catrope $';
+ $vers[] = __CLASS__ . ': $Id: ApiQuery.php 69986 2010-07-27 03:57:39Z tstarling $';
$vers[] = $psModule->getVersion();
return $vers;
}
-} \ No newline at end of file
+}