* @ingroup Cache
*/
class HTMLFileCache extends FileCacheBase {
+ const MODE_NORMAL = 0; // normal cache mode
+ const MODE_OUTAGE = 1; // fallback cache for DB outages
+
/**
- * Construct an ObjectFileCache from a Title and an action
+ * Construct an HTMLFileCache object from a Title and an action
+ *
+ * @deprecated since 1.24, instantiate this class directly
* @param Title|string $title Title object or prefixed DB key string
* @param string $action
* @throws MWException
* @return HTMLFileCache
- *
- * @deprecated Since 1.24, instantiate this class directly
*/
public static function newFromTitle( $title, $action ) {
return new self( $title, $action );
/**
* Check if pages can be cached for this request/user
* @param IContextSource $context
+ * @param integer $mode One of the HTMLFileCache::MODE_* constants
* @return bool
*/
- public static function useFileCache( IContextSource $context ) {
+ public static function useFileCache( IContextSource $context, $mode = self::MODE_NORMAL ) {
global $wgUseFileCache, $wgDebugToolbar, $wgContLang;
+
if ( !$wgUseFileCache ) {
return false;
}
return false;
}
+
$user = $context->getUser();
// Check for non-standard user language; this covers uselang,
// and extensions for auto-detecting user language.
- $ulang = $context->getLanguage()->getCode();
- $clang = $wgContLang->getCode();
+ $ulang = $context->getLanguage();
// Check that there are no other sources of variation
- if ( $user->getId() || $user->getNewtalk() || $ulang != $clang ) {
+ if ( $user->getId() || !$ulang->equals( $wgContLang ) ) {
return false;
}
+
+ if ( $mode === self::MODE_NORMAL ) {
+ if ( $user->getNewtalk() ) {
+ return false;
+ }
+ }
+
// Allow extensions to disable caching
return Hooks::run( 'HTMLFileCache::useFileCache', [ $context ] );
}
/**
* Read from cache to context output
* @param IContextSource $context
+ * @param integer $mode One of the HTMLFileCache::MODE_* constants
* @return void
*/
- public function loadFromFileCache( IContextSource $context ) {
- global $wgMimeType, $wgLanguageCode;
+ public function loadFromFileCache( IContextSource $context, $mode = self::MODE_NORMAL ) {
+ global $wgMimeType, $wgContLang;
wfDebug( __METHOD__ . "()\n" );
$filename = $this->cachePath();
+ if ( $mode === self::MODE_OUTAGE ) {
+ // Avoid DB errors for queries in sendCacheControl()
+ $context->getTitle()->resetArticleID( 0 );
+ }
+
$context->getOutput()->sendCacheControl();
header( "Content-Type: $wgMimeType; charset=UTF-8" );
- header( "Content-Language: $wgLanguageCode" );
+ header( 'Content-Language: ' . $wgContLang->getHtmlCode() );
if ( $this->useGzip() ) {
if ( wfClientAcceptsGzip() ) {
header( 'Content-Encoding: gzip' );