48 parent::__construct();
50 if ( !in_array( $action, self::cacheablePageActions() ) ) {
51 throw new InvalidArgumentException(
'Invalid file cache type given.' );
54 $this->mKey = CacheKeyHelper::getKeyForPage( $page );
55 $this->mType = (string)$action;
64 return [
'view',
'history' ];
82 if ( $this->mType ===
'view' ) {
85 return $this->mType .
'/';
96 $config = MediaWikiServices::getInstance()->getMainConfig();
98 if ( !$config->get( MainConfigNames::UseFileCache ) && $mode !== self::MODE_REBUILD ) {
103 $queryVals = $context->
getRequest()->getValues();
104 foreach ( $queryVals as $query => $val ) {
105 if ( $query ===
'title' || $query ===
'curid' ) {
108 } elseif ( $query ===
'action' && in_array( $val, self::cacheablePageActions() ) ) {
111 } elseif ( $query ===
'maxage' || $query ===
'smaxage' ) {
114 } elseif ( $query ===
'uselang' ) {
127 if ( $user->isRegistered() ||
128 !$ulang->equals( MediaWikiServices::getInstance()->getContentLanguage() ) ) {
132 $userHasNewMessages = MediaWikiServices::getInstance()
133 ->getTalkPageNotificationManager()->userHasNewMessages( $user );
134 if ( ( $mode === self::MODE_NORMAL ) && $userHasNewMessages ) {
139 return Hooks::runner()->onHTMLFileCache__useFileCache( $context );
152 if ( $mode === self::MODE_OUTAGE ) {
154 $context->
getTitle()->resetArticleID( 0 );
157 $context->
getOutput()->sendCacheControl();
158 header(
"Content-Type: {$this->options->get( MainConfigNames::MimeType )}; charset=UTF-8" );
159 header(
'Content-Language: ' .
160 MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
163 header(
'Content-Encoding: gzip' );
164 readfile( $filename );
167 wfDebug( __METHOD__ .
" uncompressing cache file and sending it" );
168 readgzfile( $filename );
171 readfile( $filename );
190 if ( strlen( $text ) < 512 ) {
195 wfDebug( __METHOD__ .
"()\n",
'private' );
200 '</html>',
'<!-- Cached/compressed ' . $now .
" -->\n</html>", $text );
203 '</html>',
'<!-- Cached ' . $now .
" -->\n</html>", $text );
207 $compressed = $this->
saveText( $text );
208 if ( $compressed ===
false ) {
215 header(
'Content-Encoding: gzip' );
230 $config = MediaWikiServices::getInstance()->getMainConfig();
231 if ( !$config->get( MainConfigNames::UseFileCache ) ) {
235 foreach ( self::cacheablePageActions() as
$type ) {
236 $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...
static cacheablePageActions()
Cacheable actions.
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
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.