12use InvalidArgumentException;
31 private const CACHEABLE_ACTIONS = [
41 parent::__construct();
43 if ( !in_array( $action, self::CACHEABLE_ACTIONS ) ) {
44 throw new InvalidArgumentException(
'Invalid file cache type given.' );
47 $this->mKey = CacheKeyHelper::getKeyForPage( $page );
48 $this->mType = (string)$action;
67 if ( $this->mType ===
'view' ) {
70 return $this->mType .
'/';
82 $config = $services->getMainConfig();
89 $queryVals = $context->
getRequest()->getValues();
90 foreach ( $queryVals as $query => $val ) {
91 if ( $query ===
'title' || $query ===
'curid' ) {
94 } elseif ( $query ===
'action' && in_array( $val, self::CACHEABLE_ACTIONS ) ) {
97 } elseif ( $query ===
'maxage' || $query ===
'smaxage' ) {
100 } elseif ( $query ===
'uselang' ) {
113 if ( $user->isRegistered() ||
114 !$ulang->equals( $services->getContentLanguage() ) ) {
118 $userHasNewMessages = $services->getTalkPageNotificationManager()->userHasNewMessages( $user );
119 if ( ( $mode === self::MODE_NORMAL ) && $userHasNewMessages ) {
124 return (
new HookRunner( $services->getHookContainer() ) )->onHTMLFileCache__useFileCache( $context );
137 if ( $mode === self::MODE_OUTAGE ) {
139 $context->
getTitle()->resetArticleID( 0 );
142 $context->
getOutput()->sendCacheControl();
143 header(
"Content-Type: {$this->options->get( MainConfigNames::MimeType )}; charset=UTF-8" );
144 header(
'Content-Language: ' .
148 header(
'Content-Encoding: gzip' );
149 readfile( $filename );
152 wfDebug( __METHOD__ .
" uncompressing cache file and sending it" );
153 readgzfile( $filename );
156 readfile( $filename );
175 if ( strlen( $text ) < 512 ) {
180 wfDebug( __METHOD__ .
"()\n",
'private' );
185 '</html>',
'<!-- Cached/compressed ' . $now .
" -->\n</html>", $text );
188 '</html>',
'<!-- Cached ' . $now .
" -->\n</html>", $text );
192 $compressed = $this->
saveText( $text );
193 if ( $compressed ===
false ) {
200 header(
'Content-Encoding: gzip' );
220 foreach ( self::CACHEABLE_ACTIONS as $type ) {
221 $fc =
new self( $page, $type );
230class_alias( HTMLFileCache::class,
'HTMLFileCache' );
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.
A class containing constants representing the names of configuration variables.
const UseFileCache
Name constant for the UseFileCache setting, for use with Config::get()
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing an editable wiki page.