45 $this->mUseGzip = (bool)$wgUseGzip;
69 if ( $this->mFilePath !== null ) {
74 # Build directories (methods include the trailing "/")
76 # Avoid extension confusion
77 $key = str_replace(
'.',
'%2E', urlencode( $this->mKey ) );
78 # Build the full file path
79 $this->mFilePath =
"{$dir}/{$subDirs}{$key}.{$this->mExt}";
81 $this->mFilePath .=
'.gz';
92 if ( $this->mCached === null ) {
93 $this->mCached = file_exists( $this->
cachePath() );
125 $good = (
$timestamp <= $cachetime && $wgCacheEpoch <= $cachetime );
127 ": cachetime $cachetime, touched '{$timestamp}' epoch {$wgCacheEpoch}, good $good\n" );
146 $fh = gzopen( $this->
cachePath(),
'rb' );
148 return stream_get_contents( $fh );
150 return file_get_contents( $this->
cachePath() );
162 if ( !$wgUseFileCache ) {
167 $text = gzencode( $text );
171 if ( !file_put_contents( $this->
cachePath(), $text, LOCK_EX ) ) {
173 $this->mCached = null;
178 $this->mCached =
true;
188 MediaWiki\suppressWarnings();
190 MediaWiki\restoreWarnings();
191 $this->mCached =
false;
210 return $this->mType .
'/';
222 if ( $wgFileCacheDepth > 0 ) {
223 $hash = md5( $this->mKey );
225 $subdir .= substr( $hash, 0, $i ) .
'/';
238 if ( mt_rand( 0, self::MISS_FACTOR - 1 ) == 0 ) {
240 # Get a large IP range that should include the user even if that
241 # person's IP address changes
242 $ip = $request->
getIP();
250 # Bail out if a request already came from this range...
251 $key =
wfMemcKey( get_class( $this ),
'attempt', $this->mType, $this->mKey, $ip );
257 # Increment the number of cache misses...
281 return wfMemcKey( get_class( $this ),
'misses', $this->mType, $this->mKey );
saveText($text)
Save and compress text to the cache.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
getIP()
Work out the IP address based on various globals For trusted proxies, use the XFF client IP (first of...
static sanitizeRange($range)
Gets rid of unneeded numbers in quad-dotted/octet IP strings For example, 127.111.113.151/24 -> 127.111.113.0/24.
wfMkdirParents($dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
processing should stop and the error should be shown to the user * false
incrMissesRecent(WebRequest $request)
Roughly increments the cache misses in the last hour by unique visitors.
baseCacheDirectory()
Get the base file cache directory.
static getLocalClusterInstance()
Get the main cluster-local cache object.
$wgFileCacheDepth
Depth of the subdirectory hierarchy to be created under $wgFileCacheDirectory.
static isIPv6($ip)
Given a string, determine if it as valid IP in IPv6 only.
when a variable name is used in a it is silently declared as a new local masking the global
isCacheGood($timestamp= '')
Check if up to date cache file exists.
cacheTimestamp()
Get the last-modified timestamp of the cache file.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
isCached()
Check if the cache file exists.
typeSubdirectory()
Get the cache type subdirectory (with trailing slash) An extending class could use that method to alt...
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites...
static isValid($ip)
Validate an IP address.
Base class for data storage in the file system.
$wgUseGzip
When using the file cache, we can store the cached HTML gzipped to save disk space.
cachePath()
Get the path to the cache file.
hashSubdirectory()
Return relative multi-level hash subdirectory (with trailing slash) or the empty string if not $wgFil...
cacheDirectory()
Get the base cache directory (not specific to this file)
fetchText()
Get the uncompressed text from the cache.
getMissesRecent()
Roughly gets the cache misses in the last hour by unique visitors.
clearCache()
Clear the cache for this page.
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
error also a ContextSource you ll probably need to make sure the header is varied on $request
useGzip()
Check if the cache is gzipped.
wfMemcKey()
Make a cache key for the local wiki.
checkCacheDirs()
Create parent directors of $this->cachePath()
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
$wgFileCacheDirectory
Directory where the cached page will be saved.