42 private const CACHEABLE_ACTIONS = [
52 parent::__construct();
54 if ( !in_array( $action, self::CACHEABLE_ACTIONS ) ) {
55 throw new InvalidArgumentException(
'Invalid file cache type given.' );
58 $this->mKey = CacheKeyHelper::getKeyForPage( $page );
59 $this->mType = (string)$action;
78 if ( $this->mType ===
'view' ) {
81 return $this->mType .
'/';
92 $services = MediaWikiServices::getInstance();
93 $config = $services->getMainConfig();
95 if ( !$config->get( MainConfigNames::UseFileCache ) && $mode !== self::MODE_REBUILD ) {
100 $queryVals = $context->
getRequest()->getValues();
101 foreach ( $queryVals as $query => $val ) {
102 if ( $query ===
'title' || $query ===
'curid' ) {
105 } elseif ( $query ===
'action' && in_array( $val, self::CACHEABLE_ACTIONS ) ) {
108 } elseif ( $query ===
'maxage' || $query ===
'smaxage' ) {
111 } elseif ( $query ===
'uselang' ) {
124 if ( $user->isRegistered() ||
125 !$ulang->equals( $services->getContentLanguage() ) ) {
129 $userHasNewMessages = $services->getTalkPageNotificationManager()->userHasNewMessages( $user );
130 if ( ( $mode === self::MODE_NORMAL ) && $userHasNewMessages ) {
135 return (
new HookRunner( $services->getHookContainer() ) )->onHTMLFileCache__useFileCache( $context );
148 if ( $mode === self::MODE_OUTAGE ) {
150 $context->
getTitle()->resetArticleID( 0 );
153 $context->
getOutput()->sendCacheControl();
154 header(
"Content-Type: {$this->options->get( MainConfigNames::MimeType )}; charset=UTF-8" );
155 header(
'Content-Language: ' .
156 MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
159 header(
'Content-Encoding: gzip' );
160 readfile( $filename );
163 wfDebug( __METHOD__ .
" uncompressing cache file and sending it" );
164 readgzfile( $filename );
167 readfile( $filename );
186 if ( strlen( $text ) < 512 ) {
191 wfDebug( __METHOD__ .
"()\n",
'private' );
196 '</html>',
'<!-- Cached/compressed ' . $now .
" -->\n</html>", $text );
199 '</html>',
'<!-- Cached ' . $now .
" -->\n</html>", $text );
203 $compressed = $this->
saveText( $text );
204 if ( $compressed ===
false ) {
211 header(
'Content-Encoding: gzip' );
226 $config = MediaWikiServices::getInstance()->getMainConfig();
227 if ( !$config->get( MainConfigNames::UseFileCache ) ) {
231 foreach ( self::CACHEABLE_ACTIONS as $type ) {
232 $fc =
new self( $page, $type );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfClientAcceptsGzip( $force=false)
Whether the client accept gzip encoding.
Base class for data storage in the file system.
useGzip()
Check if the cache is gzipped.
cachePath()
Get the path to the cache file.
saveText( $text)
Save and compress text to the cache.
baseCacheDirectory()
Get the base file cache directory.
Page view caching in the file system.
static useFileCache(IContextSource $context, $mode=self::MODE_NORMAL)
Check if pages can be cached for this request/user.
__construct( $page, $action)
loadFromFileCache(IContextSource $context, $mode=self::MODE_NORMAL)
Read from cache to context output.
static clearFileCache( $page)
Clear the file caches for a page for all actions.
saveToFileCache( $text)
Save this cache object with the given text.
cacheDirectory()
Get the base file cache directory.
typeSubdirectory()
Get the cache type subdirectory (with the trailing slash) or the empty string Alter the type -> direc...
A class containing constants representing the names of configuration variables.
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing an editable wiki page.