44 private const CACHEABLE_ACTIONS = [
54 parent::__construct();
56 if ( !in_array( $action, self::CACHEABLE_ACTIONS ) ) {
57 throw new InvalidArgumentException(
'Invalid file cache type given.' );
60 $this->mKey = CacheKeyHelper::getKeyForPage( $page );
61 $this->mType = (string)$action;
80 if ( $this->mType ===
'view' ) {
83 return $this->mType .
'/';
94 $services = MediaWikiServices::getInstance();
95 $config = $services->getMainConfig();
97 if ( !$config->get( MainConfigNames::UseFileCache ) && $mode !== self::MODE_REBUILD ) {
102 $queryVals = $context->
getRequest()->getValues();
103 foreach ( $queryVals as $query => $val ) {
104 if ( $query ===
'title' || $query ===
'curid' ) {
107 } elseif ( $query ===
'action' && in_array( $val, self::CACHEABLE_ACTIONS ) ) {
110 } elseif ( $query ===
'maxage' || $query ===
'smaxage' ) {
113 } elseif ( $query ===
'uselang' ) {
126 if ( $user->isRegistered() ||
127 !$ulang->equals( $services->getContentLanguage() ) ) {
131 $userHasNewMessages = $services->getTalkPageNotificationManager()->userHasNewMessages( $user );
132 if ( ( $mode === self::MODE_NORMAL ) && $userHasNewMessages ) {
137 return (
new HookRunner( $services->getHookContainer() ) )->onHTMLFileCache__useFileCache( $context );
150 if ( $mode === self::MODE_OUTAGE ) {
152 $context->
getTitle()->resetArticleID( 0 );
155 $context->
getOutput()->sendCacheControl();
156 header(
"Content-Type: {$this->options->get( MainConfigNames::MimeType )}; charset=UTF-8" );
157 header(
'Content-Language: ' .
158 MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
161 header(
'Content-Encoding: gzip' );
162 readfile( $filename );
165 wfDebug( __METHOD__ .
" uncompressing cache file and sending it" );
166 readgzfile( $filename );
169 readfile( $filename );
188 if ( strlen( $text ) < 512 ) {
193 wfDebug( __METHOD__ .
"()\n",
'private' );
198 '</html>',
'<!-- Cached/compressed ' . $now .
" -->\n</html>", $text );
201 '</html>',
'<!-- Cached ' . $now .
" -->\n</html>", $text );
205 $compressed = $this->
saveText( $text );
206 if ( $compressed ===
false ) {
213 header(
'Content-Encoding: gzip' );
228 $config = MediaWikiServices::getInstance()->getMainConfig();
229 if ( !$config->get( MainConfigNames::UseFileCache ) ) {
233 foreach ( self::CACHEABLE_ACTIONS as $type ) {
234 $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.