43 private const CACHEABLE_ACTIONS = [
53 parent::__construct();
55 if ( !in_array( $action, self::CACHEABLE_ACTIONS ) ) {
56 throw new InvalidArgumentException(
'Invalid file cache type given.' );
59 $this->mKey = CacheKeyHelper::getKeyForPage( $page );
60 $this->mType = (string)$action;
69 return $this->baseCacheDirectory();
79 if ( $this->mType ===
'view' ) {
82 return $this->mType .
'/';
93 $services = MediaWikiServices::getInstance();
94 $config = $services->getMainConfig();
96 if ( !$config->get( MainConfigNames::UseFileCache ) && $mode !== self::MODE_REBUILD ) {
101 $queryVals = $context->
getRequest()->getValues();
102 foreach ( $queryVals as $query => $val ) {
103 if ( $query ===
'title' || $query ===
'curid' ) {
106 } elseif ( $query ===
'action' && in_array( $val, self::CACHEABLE_ACTIONS ) ) {
109 } elseif ( $query ===
'maxage' || $query ===
'smaxage' ) {
112 } elseif ( $query ===
'uselang' ) {
125 if ( $user->isRegistered() ||
126 !$ulang->equals( $services->getContentLanguage() ) ) {
130 $userHasNewMessages = $services->getTalkPageNotificationManager()->userHasNewMessages( $user );
131 if ( ( $mode === self::MODE_NORMAL ) && $userHasNewMessages ) {
136 return (
new HookRunner( $services->getHookContainer() ) )->onHTMLFileCache__useFileCache( $context );
147 $filename = $this->cachePath();
149 if ( $mode === self::MODE_OUTAGE ) {
151 $context->
getTitle()->resetArticleID( 0 );
154 $context->
getOutput()->sendCacheControl();
155 header(
"Content-Type: {$this->options->get( MainConfigNames::MimeType )}; charset=UTF-8" );
156 header(
'Content-Language: ' .
157 MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
158 if ( $this->useGzip() ) {
160 header(
'Content-Encoding: gzip' );
161 readfile( $filename );
164 wfDebug( __METHOD__ .
" uncompressing cache file and sending it" );
165 readgzfile( $filename );
168 readfile( $filename );
187 if ( strlen( $text ) < 512 ) {
192 wfDebug( __METHOD__ .
"()\n",
'private' );
195 if ( $this->useGzip() ) {
197 '</html>',
'<!-- Cached/compressed ' . $now .
" -->\n</html>", $text );
200 '</html>',
'<!-- Cached ' . $now .
" -->\n</html>", $text );
204 $compressed = $this->saveText( $text );
205 if ( $compressed ===
false ) {
212 header(
'Content-Encoding: gzip' );
227 $config = MediaWikiServices::getInstance()->getMainConfig();
228 if ( !$config->get( MainConfigNames::UseFileCache ) ) {
232 foreach ( self::CACHEABLE_ACTIONS as $type ) {
233 $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.
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.