* @ingroup Cache
*/
class HTMLFileCache {
- var $mTitle, $mFileCache, $mType;
+
+ /**
+ * @var Title
+ */
+ var $mTitle;
+ var $mFileCache, $mType;
public function __construct( &$title, $type = 'view' ) {
$this->mTitle = $title;
public function fileCacheName() {
if( !$this->mFileCache ) {
- global $wgCacheDirectory, $wgFileCacheDirectory, $wgRequest;
+ global $wgCacheDirectory, $wgFileCacheDirectory, $wgFileCacheDepth;
if ( $wgFileCacheDirectory ) {
$dir = $wgFileCacheDirectory;
# Store raw pages (like CSS hits) elsewhere
$subdir = ($this->mType === 'raw') ? 'raw/' : '';
+
$key = $this->mTitle->getPrefixedDbkey();
- $hash = md5( $key );
+ if ( $wgFileCacheDepth > 0 ) {
+ $hash = md5( $key );
+ for ( $i = 1; $i <= $wgFileCacheDepth; $i++ ) {
+ $subdir .= substr( $hash, 0, $i ) . '/';
+ }
+ }
# Avoid extension confusion
$key = str_replace( '.', '%2E', urlencode( $key ) );
-
- $hash1 = substr( $hash, 0, 1 );
- $hash2 = substr( $hash, 0, 2 );
- $this->mFileCache = "{$wgFileCacheDirectory}/{$subdir}{$hash1}/{$hash2}/{$key}.html";
+ $this->mFileCache = "{$dir}/{$subdir}{$key}.html";
- if( $this->useGzip() )
+ if( $this->useGzip() ) {
$this->mFileCache .= '.gz';
+ }
wfDebug( __METHOD__ . ": {$this->mFileCache}\n" );
}
}
public function isFileCached() {
- if( $this->mType === false ) return false;
+ if( $this->mType === false ) {
+ return false;
+ }
return file_exists( $this->fileCacheName() );
}
*/
public static function useFileCache() {
global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang;
- if( !$wgUseFileCache ) return false;
+ if( !$wgUseFileCache ) {
+ return false;
+ }
// Get all query values
$queryVals = $wgRequest->getValues();
foreach( $queryVals as $query => $val ) {
- if( $query == 'title' || $query == 'curid' ) continue;
+ if( $query == 'title' || $query == 'curid' ) {
+ continue;
+ }
// Normal page view in query form can have action=view.
// Raw hits for pages also stored, like .css pages for example.
- else if( $query == 'action' && ($val == 'view' || $val == 'raw') ) continue;
- else if( $query == 'usemsgcache' && $val == 'yes' ) continue;
+ else if( $query == 'action' && ($val == 'view' || $val == 'raw') ) {
+ continue;
+ } else if( $query == 'usemsgcache' && $val == 'yes' ) {
+ continue;
+ }
// Below are header setting params
- else if( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' )
+ else if( $query == 'maxage' || $query == 'smaxage' || $query == 'ctype' || $query == 'gen' ) {
continue;
- else
+ } else {
return false;
+ }
}
// Check for non-standard user language; this covers uselang,
// and extensions for auto-detecting user language.
public function isFileCacheGood( $timestamp = '' ) {
global $wgCacheEpoch;
- if( !$this->isFileCached() ) return false;
+ if( !$this->isFileCached() ) {
+ return false;
+ }
$cachetime = $this->fileCacheTime();
$good = $timestamp <= $cachetime && $wgCacheEpoch <= $cachetime;
/* Working directory to/from output */
public function loadFromFileCache() {
- global $wgOut, $wgMimeType, $wgOutputEncoding, $wgContLanguageCode;
+ global $wgOut, $wgMimeType, $wgOutputEncoding, $wgLanguageCode;
wfDebug( __METHOD__ . "()\n");
$filename = $this->fileCacheName();
// Raw pages should handle cache control on their own,
if( $this->mType !== 'raw' ) {
$wgOut->sendCacheControl();
header( "Content-Type: $wgMimeType; charset={$wgOutputEncoding}" );
- header( "Content-Language: $wgContLanguageCode" );
+ header( "Content-Language: $wgLanguageCode" );
}
if( $this->useGzip() ) {