* @return bool
*/
public static function useFileCache( IContextSource $context, $mode = self::MODE_NORMAL ) {
- global $wgContLang;
$config = MediaWikiServices::getInstance()->getMainConfig();
if ( !$config->get( 'UseFileCache' ) && $mode !== self::MODE_REBUILD ) {
$ulang = $context->getLanguage();
// Check that there are no other sources of variation
- if ( $user->getId() || !$ulang->equals( $wgContLang ) ) {
+ if ( $user->getId() ||
+ !$ulang->equals( MediaWikiServices::getInstance()->getContentLanguage() ) ) {
return false;
}
- if ( $mode === self::MODE_NORMAL ) {
- if ( $user->getNewtalk() ) {
- return false;
- }
+ if ( ( $mode === self::MODE_NORMAL ) && $user->getNewtalk() ) {
+ return false;
}
// Allow extensions to disable caching
* @return void
*/
public function loadFromFileCache( IContextSource $context, $mode = self::MODE_NORMAL ) {
- global $wgContLang;
$config = MediaWikiServices::getInstance()->getMainConfig();
wfDebug( __METHOD__ . "()\n" );
$context->getOutput()->sendCacheControl();
header( "Content-Type: {$config->get( 'MimeType' )}; charset=UTF-8" );
- header( "Content-Language: {$wgContLang->getHtmlCode()}" );
+ header( 'Content-Language: ' .
+ MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
if ( $this->useGzip() ) {
if ( wfClientAcceptsGzip() ) {
header( 'Content-Encoding: gzip' );
}
// gzip output to buffer as needed and set headers...
- if ( $this->useGzip() ) {
- // @todo Ugly wfClientAcceptsGzip() function - use context!
- if ( wfClientAcceptsGzip() ) {
- header( 'Content-Encoding: gzip' );
+ // @todo Ugly wfClientAcceptsGzip() function - use context!
+ if ( $this->useGzip() && wfClientAcceptsGzip() ) {
+ header( 'Content-Encoding: gzip' );
- return $compressed;
- } else {
- return $text;
+ return $compressed;
+ }
+
+ return $text;
+ }
+
+ /**
+ * @param string[] $prefixedDbKeys List of prefixed DB keys for pages to purge
+ * @since 1.34
+ */
+ public static function purge( array $prefixedDbKeys ) {
+ foreach ( $prefixedDbKeys as $prefixedDbKey ) {
+ foreach ( self::cacheablePageActions() as $type ) {
+ $fc = new self( $prefixedDbKey, $type );
+ $fc->clearCache();
}
- } else {
- return $text;
}
}
/**
* Clear the file caches for a page for all actions
- * @param Title $title
+ * @param Traversable|Title[]|Title $titles
* @return bool Whether $wgUseFileCache is enabled
*/
- public static function clearFileCache( Title $title ) {
+ public static function clearFileCache( $titles ) {
$config = MediaWikiServices::getInstance()->getMainConfig();
-
if ( !$config->get( 'UseFileCache' ) ) {
return false;
}
- foreach ( self::cacheablePageActions() as $type ) {
- $fc = new self( $title, $type );
- $fc->clearCache();
+ $titleIterator = ( $titles instanceof Title ) ? [ $titles ] : $titles;
+ foreach ( $titleIterator as $title ) {
+ self::purge( [ $title->getPrefixedDBkey() ] );
}
return true;