26use InvalidArgumentException;
45 private const CACHEABLE_ACTIONS = [
55 parent::__construct();
57 if ( !in_array( $action, self::CACHEABLE_ACTIONS ) ) {
58 throw new InvalidArgumentException(
'Invalid file cache type given.' );
62 $this->mType = (string)$action;
81 if ( $this->mType ===
'view' ) {
84 return $this->mType .
'/';
96 $config = $services->getMainConfig();
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::CACHEABLE_ACTIONS ) ) {
111 } elseif ( $query ===
'maxage' || $query ===
'smaxage' ) {
114 } elseif ( $query ===
'uselang' ) {
127 if ( $user->isRegistered() ||
128 !$ulang->equals( $services->getContentLanguage() ) ) {
132 $userHasNewMessages = $services->getTalkPageNotificationManager()->userHasNewMessages( $user );
133 if ( ( $mode === self::MODE_NORMAL ) && $userHasNewMessages ) {
138 return (
new HookRunner( $services->getHookContainer() ) )->onHTMLFileCache__useFileCache( $context );
151 if ( $mode === self::MODE_OUTAGE ) {
153 $context->
getTitle()->resetArticleID( 0 );
156 $context->
getOutput()->sendCacheControl();
157 header(
"Content-Type: {$this->options->get( MainConfigNames::MimeType )}; charset=UTF-8" );
158 header(
'Content-Language: ' .
162 header(
'Content-Encoding: gzip' );
163 readfile( $filename );
166 wfDebug( __METHOD__ .
" uncompressing cache file and sending it" );
167 readgzfile( $filename );
170 readfile( $filename );
189 if ( strlen( $text ) < 512 ) {
194 wfDebug( __METHOD__ .
"()\n",
'private' );
199 '</html>',
'<!-- Cached/compressed ' . $now .
" -->\n</html>", $text );
202 '</html>',
'<!-- Cached ' . $now .
" -->\n</html>", $text );
206 $compressed = $this->
saveText( $text );
207 if ( $compressed ===
false ) {
214 header(
'Content-Encoding: gzip' );
234 foreach ( self::CACHEABLE_ACTIONS as $type ) {
235 $fc =
new self( $page, $type );
244class_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.