diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2010-07-28 10:05:59 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2010-07-28 10:05:59 +0200 |
commit | 00ab76a6b686e98a914afc1975812d2b1aaa7016 (patch) | |
tree | 0509bcf2b8a30056833a289e3717b55bdb189835 /includes/api | |
parent | a5be612e4169e11b51647cbaa2abc976de00d671 (diff) |
update to MediaWiki 1.15.5
Diffstat (limited to 'includes/api')
43 files changed, 439 insertions, 90 deletions
diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php index f4e6212a..afb11402 100644 --- a/includes/api/ApiExpandTemplates.php +++ b/includes/api/ApiExpandTemplates.php @@ -42,6 +42,9 @@ class ApiExpandTemplates extends ApiBase { } public function execute() { + // Cache may vary on $wgUser because ParserOptions gets data from it + $this->getMain()->setCacheMode( 'anon-public-user-private' ); + // Get parameters $params = $this->extractRequestParams(); @@ -105,6 +108,6 @@ class ApiExpandTemplates extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiExpandTemplates.php 44719 2008-12-17 16:34:01Z catrope $'; + return __CLASS__ . ': $Id: ApiExpandTemplates.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 1d2c3436..8f1fb834 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -91,8 +91,11 @@ class ApiLogin extends ApiBase { break; case LoginForm::NEED_TOKEN: + global $wgCookiePrefix; $result['result'] = 'NeedToken'; $result['token'] = $loginForm->getLoginToken(); + $result['cookieprefix'] = $wgCookiePrefix; + $result['sessionid'] = session_id(); break; case LoginForm::WRONG_TOKEN: @@ -174,6 +177,6 @@ class ApiLogin extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiLogin.php 64680 2010-04-07 00:13:46Z tstarling $'; + return __CLASS__ . ': $Id: ApiLogin.php 69990 2010-07-27 08:44:08Z tstarling $'; } } diff --git a/includes/api/ApiLogout.php b/includes/api/ApiLogout.php index 0af579ca..aa9f2829 100644 --- a/includes/api/ApiLogout.php +++ b/includes/api/ApiLogout.php @@ -75,6 +75,6 @@ class ApiLogout extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiLogout.php 48091 2009-03-06 13:49:44Z catrope $'; + return __CLASS__ . ': $Id: ApiLogout.php 69579 2010-07-20 02:49:55Z tstarling $'; } } diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index ffdeb1e8..063e3574 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -121,7 +121,9 @@ class ApiMain extends ApiBase { private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames; - private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest, $mInternalMode, $mSquidMaxage; + private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest, $mInternalMode; + private $mCacheMode = 'private'; + private $mCacheControl = array(); /** * Constructs an instance of ApiMain that utilizes the module and format specified by $request. @@ -164,7 +166,6 @@ class ApiMain extends ApiBase { $this->mRequest = & $request; - $this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling() $this->mCommit = false; } @@ -193,13 +194,100 @@ class ApiMain extends ApiBase { * Only kept for backwards compatibility * @deprecated Use isWriteMode() instead */ - public function requestWriteMode() {} + public function requestWriteMode() { + if (!$this->mEnableWrite) + $this->dieUsageMsg(array('writedisabled')); + if (wfReadOnly()) + $this->dieUsageMsg(array('readonlytext')); + } /** * Set how long the response should be cached. */ public function setCacheMaxAge($maxage) { - $this->mSquidMaxage = $maxage; + $this->setCacheControl( array( + 'max-age' => $maxage, + 's-maxage' => $maxage + ) ); + } + + /** + * Set the type of caching headers which will be sent. + * + * @param $mode One of: + * - 'public': Cache this object in public caches, if the maxage or smaxage + * parameter is set, or if setCacheMaxAge() was called. If a maximum age is + * not provided by any of these means, the object will be private. + * - 'private': Cache this object only in private client-side caches. + * - 'anon-public-user-private': Make this object cacheable for logged-out + * users, but private for logged-in users. IMPORTANT: If this is set, it must be + * set consistently for a given URL, it cannot be set differently depending on + * things like the contents of the database, or whether the user is logged in. + * + * If the wiki does not allow anonymous users to read it, the mode set here + * will be ignored, and private caching headers will always be sent. In other words, + * the "public" mode is equivalent to saying that the data sent is as public as a page + * view. + * + * For user-dependent data, the private mode should generally be used. The + * anon-public-user-private mode should only be used where there is a particularly + * good performance reason for caching the anonymous response, but where the + * response to logged-in users may differ, or may contain private data. + * + * If this function is never called, then the default will be the private mode. + */ + public function setCacheMode( $mode ) { + if ( !in_array( $mode, array( 'private', 'public', 'anon-public-user-private' ) ) ) { + wfDebug( __METHOD__.": unrecognised cache mode \"$mode\"\n" ); + // Ignore for forwards-compatibility + return; + } + + if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) { + // Private wiki, only private headers + if ( $mode !== 'private' ) { + wfDebug( __METHOD__.": ignoring request for $mode cache mode, private wiki\n" ); + return; + } + } + + wfDebug( __METHOD__.": setting cache mode $mode\n" ); + $this->mCacheMode = $mode; + } + + /** + * @deprecated Private caching is now the default, so there is usually no + * need to call this function. If there is a need, you can use + * $this->setCacheMode('private') + */ + public function setCachePrivate() { + $this->setCacheMode( 'private' ); + } + + /** + * Set directives (key/value pairs) for the Cache-Control header. + * Boolean values will be formatted as such, by including or omitting + * without an equals sign. + * + * Cache control values set here will only be used if the cache mode is not + * private, see setCacheMode(). + */ + public function setCacheControl( $directives ) { + $this->mCacheControl = $directives + $this->mCacheControl; + } + + /** + * Make sure Vary: Cookie and friends are set. Use this when the output of a request + * may be cached for anons but may not be cached for logged-in users. + * + * WARNING: This function must be called CONSISTENTLY for a given URL. This means that a + * given URL must either always or never call this function; if it sometimes does and + * sometimes doesn't, stuff will break. + * + * @deprecated Use setCacheMode( 'anon-public-user-private' ) + */ + public function setVaryCookie() { + $this->setCacheMode( 'anon-public-user-private' ); } /** @@ -251,7 +339,7 @@ class ApiMain extends ApiBase { $errCode = $this->substituteResultWithError($e); // Error results should not be cached - $this->setCacheMaxAge(0); + $this->setCacheMode( 'private' ); $headerStr = 'MediaWiki-API-Error: ' . $errCode; if ($e->getCode() === 0) @@ -267,21 +355,9 @@ class ApiMain extends ApiBase { $this->printResult(true); } - if($this->mSquidMaxage == -1) - { - # Nobody called setCacheMaxAge(), use the (s)maxage parameters - $smaxage = $this->getParameter('smaxage'); - $maxage = $this->getParameter('maxage'); - } - else - $smaxage = $maxage = $this->mSquidMaxage; - - // Set the cache expiration at the last moment, as any errors may change the expiration. - // if $this->mSquidMaxage == 0, the expiry time is set to the first second of unix epoch - $exp = min($smaxage, $maxage); - $expires = ($exp == 0 ? 1 : time() + $exp); - header('Expires: ' . wfTimestamp(TS_RFC2822, $expires)); - header('Cache-Control: s-maxage=' . $smaxage . ', must-revalidate, max-age=' . $maxage); + // Send cache headers after any code which might generate an error, to + // avoid sending public cache headers for errors. + $this->sendCacheHeaders(); if($this->mPrinter->getIsHtml()) echo wfReportTime(); @@ -289,6 +365,71 @@ class ApiMain extends ApiBase { ob_end_flush(); } + protected function sendCacheHeaders() { + if ( $this->mCacheMode == 'private' ) { + header( 'Cache-Control: private' ); + return; + } + + if ( $this->mCacheMode == 'anon-public-user-private' ) { + global $wgOut; + header( 'Vary: Accept-Encoding, Cookie' ); + header( $wgOut->getXVO() ); + if ( session_id() != '' || $wgOut->haveCacheVaryCookies() ) { + // Logged in, mark this request private + header( 'Cache-Control: private' ); + return; + } + // Logged out, send normal public headers below + } else /* if public */ { + // Give a debugging message if the user object is unstubbed on a public request + global $wgUser; + if ( !( $wgUser instanceof StubUser ) ) { + wfDebug( __METHOD__." \$wgUser is unstubbed on a public request!\n" ); + } + } + + // If nobody called setCacheMaxAge(), use the (s)maxage parameters + if ( !isset( $this->mCacheControl['s-maxage'] ) ) { + $this->mCacheControl['s-maxage'] = $this->getParameter( 'smaxage' ); + } + if ( !isset( $this->mCacheControl['max-age'] ) ) { + $this->mCacheControl['max-age'] = $this->getParameter( 'maxage' ); + } + + if ( !$this->mCacheControl['s-maxage'] && !$this->mCacheControl['max-age'] ) { + // Public cache not requested + // Sending a Vary header in this case is harmless, and protects us + // against conditional calls of setCacheMaxAge(). + header( 'Cache-Control: private' ); + return; + } + + $this->mCacheControl['public'] = true; + + // Send an Expires header + $maxAge = min( $this->mCacheControl['s-maxage'], $this->mCacheControl['max-age'] ); + $expiryUnixTime = ( $maxAge == 0 ? 1 : time() + $maxAge ); + header( 'Expires: ' . wfTimestamp( TS_RFC2822, $expiryUnixTime ) ); + + // Construct the Cache-Control header + $ccHeader = ''; + $separator = ''; + foreach ( $this->mCacheControl as $name => $value ) { + if ( is_bool( $value ) ) { + if ( $value ) { + $ccHeader .= $separator . $name; + $separator = ', '; + } + } else { + $ccHeader .= $separator . "$name=$value"; + $separator = ', '; + } + } + + header( "Cache-Control: $ccHeader" ); + } + /** * Replace the result data with the information about an exception. * Returns the error code @@ -654,7 +795,7 @@ class ApiMain extends ApiBase { public function getVersion() { $vers = array (); $vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/"; - $vers[] = __CLASS__ . ': $Id: ApiMain.php 50834 2009-05-20 20:10:47Z catrope $'; + $vers[] = __CLASS__ . ': $Id: ApiMain.php 69990 2010-07-27 08:44:08Z tstarling $'; $vers[] = ApiBase :: getBaseVersion(); $vers[] = ApiFormatBase :: getBaseVersion(); $vers[] = ApiQueryBase :: getBaseVersion(); diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index 8fc1f32b..d2e6ea21 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -53,6 +53,7 @@ class ApiOpenSearch extends ApiBase { // Open search results may be stored for a very long time $this->getMain()->setCacheMaxAge(1200); + $this->getMain()->setCacheMode( 'public' ); $srchres = PrefixSearch::titleSearch( $search, $limit, $namespaces ); @@ -101,6 +102,6 @@ class ApiOpenSearch extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiOpenSearch.php 47188 2009-02-12 17:27:05Z catrope $'; + return __CLASS__ . ': $Id: ApiOpenSearch.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 8f4b70bf..c8cd07fe 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -38,6 +38,9 @@ class ApiParse extends ApiBase { } public function execute() { + // The data is hot but user-dependent, like page views, so we set vary cookies + $this->getMain()->setCacheMode( 'anon-public-user-private' ); + // Get parameters $params = $this->extractRequestParams(); $text = $params['text']; @@ -277,6 +280,6 @@ class ApiParse extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiParse.php 48544 2009-03-18 23:27:48Z aboostani $'; + return __CLASS__ . ': $Id: ApiParse.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiPatrol.php b/includes/api/ApiPatrol.php index 2c9d1ecf..a6f25af2 100644 --- a/includes/api/ApiPatrol.php +++ b/includes/api/ApiPatrol.php @@ -97,6 +97,6 @@ class ApiPatrol extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiPatrol.php 48122 2009-03-07 12:58:41Z catrope $'; + return __CLASS__ . ': $Id: ApiPatrol.php 69579 2010-07-20 02:49:55Z tstarling $'; } } diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index 27d5cac6..d1e6824d 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -110,6 +110,6 @@ class ApiPurge extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiPurge.php 48091 2009-03-06 13:49:44Z catrope $'; + return __CLASS__ . ': $Id: ApiPurge.php 69579 2010-07-20 02:49:55Z tstarling $'; } } 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 +} diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php index e835c042..fca92c4b 100644 --- a/includes/api/ApiQueryAllCategories.php +++ b/includes/api/ApiQueryAllCategories.php @@ -44,6 +44,10 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { $this->run(); } + public function getCacheMode( $params ) { + return 'public'; + } + public function executeGenerator($resultPageSet) { $this->run($resultPageSet); } @@ -175,6 +179,6 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryAllCategories.php 47865 2009-02-27 16:03:01Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryAllCategories.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryAllLinks.php b/includes/api/ApiQueryAllLinks.php index 7ae24665..73788aa6 100644 --- a/includes/api/ApiQueryAllLinks.php +++ b/includes/api/ApiQueryAllLinks.php @@ -43,6 +43,10 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { $this->run(); } + public function getCacheMode( $params ) { + return 'public'; + } + public function executeGenerator($resultPageSet) { $this->run($resultPageSet); } @@ -196,6 +200,6 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryAllLinks.php 47865 2009-02-27 16:03:01Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryAllLinks.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index 76d97abd..c18f6dd1 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -181,6 +181,10 @@ class ApiQueryAllUsers extends ApiQueryBase { $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'u'); } + public function getCacheMode( $params ) { + return 'public'; + } + public function getAllowedParams() { return array ( 'from' => null, @@ -232,6 +236,6 @@ class ApiQueryAllUsers extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryAllUsers.php 66948 2010-05-27 07:47:39Z tstarling $'; + return __CLASS__ . ': $Id: ApiQueryAllUsers.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQueryAllimages.php b/includes/api/ApiQueryAllimages.php index 76d5d238..983c6469 100644 --- a/includes/api/ApiQueryAllimages.php +++ b/includes/api/ApiQueryAllimages.php @@ -44,6 +44,10 @@ class ApiQueryAllimages extends ApiQueryGeneratorBase { $this->run(); } + public function getCacheMode( $params ) { + return 'public'; + } + public function executeGenerator($resultPageSet) { if ($resultPageSet->isResolvingRedirects()) $this->dieUsage('Use "gaifilterredir=nonredirects" option instead of "redirects" when using allimages as a generator', 'params'); @@ -205,6 +209,6 @@ class ApiQueryAllimages extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryAllimages.php 46845 2009-02-05 14:30:59Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryAllimages.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQueryAllmessages.php b/includes/api/ApiQueryAllmessages.php index b19dc8fb..c615daf4 100644 --- a/includes/api/ApiQueryAllmessages.php +++ b/includes/api/ApiQueryAllmessages.php @@ -104,6 +104,16 @@ class ApiQueryAllmessages extends ApiQueryBase { $result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'message'); } + public function getCacheMode( $params ) { + if ( is_null( $params['lang'] ) ) { + // Language not specified, will be fetched from preferences + return 'anon-public-user-private'; + } else { + // OK to cache + return 'public'; + } + } + public function getAllowedParams() { return array ( 'messages' => array ( @@ -136,6 +146,6 @@ class ApiQueryAllmessages extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryAllmessages.php 47048 2009-02-09 19:24:28Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryAllmessages.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index 3d30aba9..e123e8fe 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -43,6 +43,10 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { $this->run(); } + public function getCacheMode( $params ) { + return 'public'; + } + public function executeGenerator($resultPageSet) { if ($resultPageSet->isResolvingRedirects()) $this->dieUsage('Use "gapfilterredir=nonredirects" option instead of "redirects" when using allpages as a generator', 'params'); @@ -268,6 +272,6 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryAllpages.php 46845 2009-02-05 14:30:59Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryAllpages.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php index 95972392..1b1fe639 100644 --- a/includes/api/ApiQueryBacklinks.php +++ b/includes/api/ApiQueryBacklinks.php @@ -92,6 +92,10 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { $this->run(); } + public function getCacheMode( $params ) { + return 'public'; + } + public function executeGenerator($resultPageSet) { $this->run($resultPageSet); } @@ -457,6 +461,6 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryBacklinks.php 50217 2009-05-05 13:12:16Z tstarling $'; + return __CLASS__ . ': $Id: ApiQueryBacklinks.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 9d1cbcea..7e2b1d5e 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -47,6 +47,17 @@ abstract class ApiQueryBase extends ApiBase { } /** + * Get the cache mode for the data generated by this module. Override this + * in the module subclass. + * + * Public caching will only be allowed if *all* the modules that supply + * data for a given request return a cache mode of public. + */ + public function getCacheMode( $params ) { + return 'private'; + } + + /** * Blank the internal arrays with query parameters */ protected function resetQueryParams() { @@ -414,7 +425,7 @@ abstract class ApiQueryBase extends ApiBase { * @return string */ public static function getBaseVersion() { - return __CLASS__ . ': $Id: ApiQueryBase.php 47450 2009-02-18 15:26:09Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryBase.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQueryBlocks.php b/includes/api/ApiQueryBlocks.php index c5ffc37b..64790037 100644 --- a/includes/api/ApiQueryBlocks.php +++ b/includes/api/ApiQueryBlocks.php @@ -263,6 +263,6 @@ class ApiQueryBlocks extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryBlocks.php 48213 2009-03-09 10:01:00Z aaron $'; + return __CLASS__ . ': $Id: ApiQueryBlocks.php 69579 2010-07-20 02:49:55Z tstarling $'; } }
\ No newline at end of file diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php index f91a04e5..15e1ce13 100644 --- a/includes/api/ApiQueryCategories.php +++ b/includes/api/ApiQueryCategories.php @@ -43,6 +43,10 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { $this->run(); } + public function getCacheMode( $params ) { + return 'public'; + } + public function executeGenerator($resultPageSet) { $this->run($resultPageSet); } @@ -237,6 +241,6 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryCategories.php 50097 2009-05-01 06:35:57Z tstarling $'; + return __CLASS__ . ': $Id: ApiQueryCategories.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQueryCategoryInfo.php b/includes/api/ApiQueryCategoryInfo.php index 49e4554e..f3d45ccf 100644 --- a/includes/api/ApiQueryCategoryInfo.php +++ b/includes/api/ApiQueryCategoryInfo.php @@ -97,6 +97,10 @@ class ApiQueryCategoryInfo extends ApiQueryBase { $db->freeResult($res); } + public function getCacheMode( $params ) { + return 'public'; + } + public function getAllowedParams() { return array ( 'continue' => null, @@ -118,6 +122,6 @@ class ApiQueryCategoryInfo extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryCategoryInfo.php 47865 2009-02-27 16:03:01Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryCategoryInfo.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryCategoryMembers.php b/includes/api/ApiQueryCategoryMembers.php index dc5a8265..45461abd 100644 --- a/includes/api/ApiQueryCategoryMembers.php +++ b/includes/api/ApiQueryCategoryMembers.php @@ -43,6 +43,10 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { $this->run(); } + public function getCacheMode( $params ) { + return 'public'; + } + public function executeGenerator($resultPageSet) { $this->run($resultPageSet); } @@ -262,6 +266,6 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryCategoryMembers.php 47865 2009-02-27 16:03:01Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryCategoryMembers.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index bdbe05e8..bd767b1b 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -335,6 +335,6 @@ class ApiQueryDeletedrevs extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 50220 2009-05-05 14:07:59Z tstarling $'; + return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 69579 2010-07-20 02:49:55Z tstarling $'; } }
\ No newline at end of file diff --git a/includes/api/ApiQueryDuplicateFiles.php b/includes/api/ApiQueryDuplicateFiles.php index 84a8a96d..a59ee356 100644 --- a/includes/api/ApiQueryDuplicateFiles.php +++ b/includes/api/ApiQueryDuplicateFiles.php @@ -43,6 +43,10 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { $this->run(); } + public function getCacheMode( $params ) { + return 'public'; + } + public function executeGenerator($resultPageSet) { $this->run($resultPageSet); } @@ -153,6 +157,6 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryDuplicateFiles.php 48215 2009-03-09 10:44:34Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryDuplicateFiles.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQueryExtLinksUsage.php b/includes/api/ApiQueryExtLinksUsage.php index 0ba2767a..08f6ab1f 100644 --- a/includes/api/ApiQueryExtLinksUsage.php +++ b/includes/api/ApiQueryExtLinksUsage.php @@ -41,6 +41,10 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { $this->run(); } + public function getCacheMode( $params ) { + return 'public'; + } + public function executeGenerator($resultPageSet) { $this->run($resultPageSet); } @@ -209,6 +213,6 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryExtLinksUsage.php 47865 2009-02-27 16:03:01Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryExtLinksUsage.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryExternalLinks.php b/includes/api/ApiQueryExternalLinks.php index 7a91f432..0bddd6df 100644 --- a/includes/api/ApiQueryExternalLinks.php +++ b/includes/api/ApiQueryExternalLinks.php @@ -81,6 +81,10 @@ class ApiQueryExternalLinks extends ApiQueryBase { $db->freeResult($res); } + public function getCacheMode( $params ) { + return 'public'; + } + public function getAllowedParams() { return array( 'limit' => array( @@ -113,6 +117,6 @@ class ApiQueryExternalLinks extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryExternalLinks.php 46845 2009-02-05 14:30:59Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryExternalLinks.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 7d880456..c4c71075 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -239,6 +239,10 @@ class ApiQueryImageInfo extends ApiQueryBase { return $retval; } + public function getCacheMode( $params ) { + return 'public'; + } + private function getContinueStr($img) { return $img->getOriginalTitle()->getText() . @@ -315,6 +319,6 @@ class ApiQueryImageInfo extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryImageInfo.php 50097 2009-05-01 06:35:57Z tstarling $'; + return __CLASS__ . ': $Id: ApiQueryImageInfo.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQueryImages.php b/includes/api/ApiQueryImages.php index 69569e9b..9dbe08a6 100644 --- a/includes/api/ApiQueryImages.php +++ b/includes/api/ApiQueryImages.php @@ -121,6 +121,10 @@ class ApiQueryImages extends ApiQueryGeneratorBase { $db->freeResult($res); } + public function getCacheMode( $params ) { + return 'public'; + } + public function getAllowedParams() { return array( 'limit' => array( @@ -155,6 +159,6 @@ class ApiQueryImages extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryImages.php 46845 2009-02-05 14:30:59Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryImages.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index b7affabc..f78450b7 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -499,6 +499,26 @@ class ApiQueryInfo extends ApiQueryBase { } } + public function getCacheMode( $params ) { + $publicProps = array( + 'protection', + 'talkid', + 'subjectid', + 'url', + ); + if ( !is_null( $params['prop'] ) ) { + foreach ( $params['prop'] as $prop ) { + if ( !in_array( $prop, $publicProps ) ) { + return 'private'; + } + } + } + if ( !is_null( $params['token'] ) ) { + return 'private'; + } + return 'public'; + } + public function getAllowedParams() { return array ( 'prop' => array ( @@ -509,7 +529,9 @@ class ApiQueryInfo extends ApiQueryBase { 'talkid', 'subjectid', 'url', - 'readable', + 'readable', # private + // If you add more properties here, please consider whether they + // need to be added to getCacheMode() )), 'token' => array ( ApiBase :: PARAM_DFLT => NULL, @@ -545,6 +567,6 @@ class ApiQueryInfo extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryInfo.php 48488 2009-03-17 15:18:26Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryInfo.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php index 3abe5e3d..35f7e67c 100644 --- a/includes/api/ApiQueryLangLinks.php +++ b/includes/api/ApiQueryLangLinks.php @@ -92,6 +92,10 @@ class ApiQueryLangLinks extends ApiQueryBase { $db->freeResult($res); } + public function getCacheMode( $params ) { + return 'public'; + } + public function getAllowedParams() { return array( 'limit' => array( @@ -124,6 +128,6 @@ class ApiQueryLangLinks extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryLangLinks.php 46845 2009-02-05 14:30:59Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryLangLinks.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php index 40a7c114..94b7980c 100644 --- a/includes/api/ApiQueryLinks.php +++ b/includes/api/ApiQueryLinks.php @@ -64,6 +64,10 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { $this->run(); } + public function getCacheMode( $params ) { + return 'public'; + } + public function executeGenerator($resultPageSet) { $this->run($resultPageSet); } @@ -204,6 +208,6 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryLinks.php 46845 2009-02-05 14:30:59Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryLinks.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 864aaa03..7afed844 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -251,6 +251,10 @@ class ApiQueryLogEvents extends ApiQueryBase { } + public function getCacheMode( $params ) { + return 'public'; + } + public function getAllowedParams() { global $wgLogTypes; return array ( @@ -319,6 +323,6 @@ class ApiQueryLogEvents extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryLogEvents.php 47904 2009-03-01 11:02:49Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryLogEvents.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQueryProtectedTitles.php b/includes/api/ApiQueryProtectedTitles.php index 779deee5..67a2a829 100644 --- a/includes/api/ApiQueryProtectedTitles.php +++ b/includes/api/ApiQueryProtectedTitles.php @@ -118,6 +118,10 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { $resultPageSet->populateFromTitles($titles); } + public function getCacheMode( $params ) { + return 'public'; + } + public function getAllowedParams() { global $wgRestrictionLevels; return array ( @@ -186,6 +190,6 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryProtectedTitles.php 47235 2009-02-13 21:53:08Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryProtectedTitles.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryRandom.php b/includes/api/ApiQueryRandom.php index 73c4a81c..1811b7e8 100644 --- a/includes/api/ApiQueryRandom.php +++ b/includes/api/ApiQueryRandom.php @@ -121,6 +121,10 @@ if (!defined('MEDIAWIKI')) { return $vals; } + public function getCacheMode( $params ) { + return 'public'; + } + public function getAllowedParams() { return array ( 'namespace' => array( @@ -161,4 +165,4 @@ if (!defined('MEDIAWIKI')) { public function getVersion() { return __CLASS__ . ': $Id: ApiQueryRandom.php overlordq$'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 191eec28..b5a56864 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -353,6 +353,20 @@ class ApiQueryRecentChanges extends ApiQueryBase { } } + public function getCacheMode( $params ) { + if ( isset( $params['show'] ) ) { + foreach ( $params['show'] as $show ) { + if ( $show === 'patrolled' || $show === '!patrolled' ) { + return 'private'; + } + } + } + if ( isset( $params['token'] ) ) { + return 'private'; + } + return 'public'; + } + public function getAllowedParams() { return array ( 'start' => array ( @@ -453,6 +467,6 @@ class ApiQueryRecentChanges extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryRecentChanges.php 50094 2009-05-01 06:24:09Z tstarling $'; + return __CLASS__ . ': $Id: ApiQueryRecentChanges.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index ca9152ad..eba526a3 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -411,6 +411,17 @@ class ApiQueryRevisions extends ApiQueryBase { return $vals; } + public function getCacheMode( $params ) { + if ( isset( $params['token'] ) ) { + return 'private'; + } + if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) { + // formatComment() calls wfMsg() among other things + return 'anon-public-user-private'; + } + return 'public'; + } + public function getAllowedParams() { return array ( 'prop' => array ( @@ -519,6 +530,6 @@ class ApiQueryRevisions extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryRevisions.php 48642 2009-03-20 20:21:38Z midom $'; + return __CLASS__ . ': $Id: ApiQueryRevisions.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 668f00e5..a8f3fcc8 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -122,6 +122,10 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } } + public function getCacheMode( $params ) { + return 'public'; + } + public function getAllowedParams() { return array ( 'search' => null, @@ -173,6 +177,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQuerySearch.php 47865 2009-02-27 16:03:01Z catrope $'; + return __CLASS__ . ': $Id: ApiQuerySearch.php 69986 2010-07-27 03:57:39Z tstarling $'; } }
\ No newline at end of file diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 6b867abb..623855f6 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -373,6 +373,9 @@ class ApiQuerySiteinfo extends ApiQueryBase { return $this->getResult()->addValue( 'query', $property, $data ); } + public function getCacheMode( $params ) { + return 'public'; + } public function getAllowedParams() { return array( @@ -439,6 +442,6 @@ class ApiQuerySiteinfo extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQuerySiteinfo.php 48060 2009-03-05 13:52:14Z demon $'; + return __CLASS__ . ': $Id: ApiQuerySiteinfo.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index 24c73996..1c5cffa5 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -287,6 +287,12 @@ class ApiQueryContributions extends ApiQueryBase { wfTimestamp(TS_ISO_8601, $row->rev_timestamp); } + public function getCacheMode( $params ) { + // This module provides access to patrol flags if + // the requester is logged in + return 'anon-public-user-private'; + } + public function getAllowedParams() { return array ( 'limit' => array ( @@ -370,6 +376,6 @@ class ApiQueryContributions extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryUserContributions.php 47037 2009-02-09 14:07:18Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryUserContributions.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryUserInfo.php b/includes/api/ApiQueryUserInfo.php index ac99ad6d..e445c46e 100644 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@ -181,6 +181,6 @@ class ApiQueryUserInfo extends ApiQueryBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryUserInfo.php 47865 2009-02-27 16:03:01Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryUserInfo.php 69579 2010-07-20 02:49:55Z tstarling $'; } } diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index b8aa60e7..1e50c59a 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -138,6 +138,10 @@ if (!defined('MEDIAWIKI')) { return $this->getResult()->setIndexedTagName_internal(array('query', $this->getModuleName()), 'user'); } + public function getCacheMode( $params ) { + return 'public'; + } + public function getAllowedParams() { return array ( 'prop' => array ( @@ -180,6 +184,6 @@ if (!defined('MEDIAWIKI')) { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryUsers.php 50094 2009-05-01 06:24:09Z tstarling $'; + return __CLASS__ . ': $Id: ApiQueryUsers.php 69986 2010-07-27 03:57:39Z tstarling $'; } } diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index b3949102..eb5c531f 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -343,6 +343,6 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryWatchlist.php 47865 2009-02-27 16:03:01Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryWatchlist.php 69986 2010-07-27 03:57:39Z tstarling $'; } -}
\ No newline at end of file +} diff --git a/includes/api/ApiQueryWatchlistRaw.php b/includes/api/ApiQueryWatchlistRaw.php index 54bb5a35..f3982bcb 100644 --- a/includes/api/ApiQueryWatchlistRaw.php +++ b/includes/api/ApiQueryWatchlistRaw.php @@ -176,6 +176,6 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryWatchlistRaw.php 46845 2009-02-05 14:30:59Z catrope $'; + return __CLASS__ . ': $Id: ApiQueryWatchlistRaw.php 69579 2010-07-20 02:49:55Z tstarling $'; } }
\ No newline at end of file diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php index 1b98fb86..7901b6ac 100644 --- a/includes/api/ApiWatch.php +++ b/includes/api/ApiWatch.php @@ -96,6 +96,6 @@ class ApiWatch extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiWatch.php 48091 2009-03-06 13:49:44Z catrope $'; + return __CLASS__ . ': $Id: ApiWatch.php 69579 2010-07-20 02:49:55Z tstarling $'; } } |