44 parent::__construct();
46 if ( !in_array( $action, self::cacheablePageActions() ) ) {
47 throw new InvalidArgumentException(
'Invalid file cache type given.' );
51 ?
$title->getPrefixedDBkey()
53 $this->mType = (string)$action;
62 return [
'view',
'history' ];
80 if ( $this->mType ===
'view' ) {
83 return $this->mType .
'/';
94 $config = MediaWikiServices::getInstance()->getMainConfig();
96 if ( !$config->get(
'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::cacheablePageActions() ) ) {
109 } elseif ( $query ===
'maxage' || $query ===
'smaxage' ) {
122 if ( $user->getId() ||
123 !$ulang->equals( MediaWikiServices::getInstance()->getContentLanguage() ) ) {
127 $userHasNewMessages = MediaWikiServices::getInstance()
128 ->getTalkPageNotificationManager()->userHasNewMessages( $user );
129 if ( ( $mode === self::MODE_NORMAL ) && $userHasNewMessages ) {
134 return Hooks::runner()->onHTMLFileCache__useFileCache( $context );
144 $config = MediaWikiServices::getInstance()->getMainConfig();
149 if ( $mode === self::MODE_OUTAGE ) {
151 $context->
getTitle()->resetArticleID( 0 );
154 $context->
getOutput()->sendCacheControl();
155 header(
"Content-Type: {$config->get( 'MimeType' )}; charset=UTF-8" );
156 header(
'Content-Language: ' .
157 MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
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' );
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(
'UseFileCache' ) ) {
232 foreach ( self::cacheablePageActions() as
$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.
loadFromFileCache(IContextSource $context, $mode=self::MODE_NORMAL)
Read from cache to context output.
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.
__construct( $title, $action)
static clearFileCache( $title)
Clear the file caches for a page for all actions.
Represents a title within MediaWiki.
Interface for objects which can provide a MediaWiki context on request.