MediaWiki  1.23.2
HTMLFileCache.php
Go to the documentation of this file.
1 <?php
39  public static function newFromTitle( $title, $action ) {
40  $cache = new self();
41 
42  $allowedTypes = self::cacheablePageActions();
43  if ( !in_array( $action, $allowedTypes ) ) {
44  throw new MWException( "Invalid filecache type given." );
45  }
46  $cache->mKey = ( $title instanceof Title )
47  ? $title->getPrefixedDBkey()
48  : (string)$title;
49  $cache->mType = (string)$action;
50  $cache->mExt = 'html';
51 
52  return $cache;
53  }
54 
59  protected static function cacheablePageActions() {
60  return array( 'view', 'history' );
61  }
62 
67  protected function cacheDirectory() {
68  return $this->baseCacheDirectory(); // no subdir for b/c with old cache files
69  }
70 
77  protected function typeSubdirectory() {
78  if ( $this->mType === 'view' ) {
79  return ''; // b/c to not skip existing cache
80  } else {
81  return $this->mType . '/';
82  }
83  }
84 
90  public static function useFileCache( IContextSource $context ) {
91  global $wgUseFileCache, $wgShowIPinHeader, $wgDebugToolbar, $wgContLang;
92  if ( !$wgUseFileCache ) {
93  return false;
94  }
95  if ( $wgShowIPinHeader || $wgDebugToolbar ) {
96  wfDebug( "HTML file cache skipped. Either \$wgShowIPinHeader and/or \$wgDebugToolbar on\n" );
97 
98  return false;
99  }
100 
101  // Get all query values
102  $queryVals = $context->getRequest()->getValues();
103  foreach ( $queryVals as $query => $val ) {
104  if ( $query === 'title' || $query === 'curid' ) {
105  continue; // note: curid sets title
106  // Normal page view in query form can have action=view.
107  } elseif ( $query === 'action' && in_array( $val, self::cacheablePageActions() ) ) {
108  continue;
109  // Below are header setting params
110  } elseif ( $query === 'maxage' || $query === 'smaxage' ) {
111  continue;
112  }
113 
114  return false;
115  }
116  $user = $context->getUser();
117  // Check for non-standard user language; this covers uselang,
118  // and extensions for auto-detecting user language.
119  $ulang = $context->getLanguage()->getCode();
120  $clang = $wgContLang->getCode();
121 
122  // Check that there are no other sources of variation
123  return !$user->getId() && !$user->getNewtalk() && $ulang == $clang;
124  }
125 
131  public function loadFromFileCache( IContextSource $context ) {
132  global $wgMimeType, $wgLanguageCode;
133 
134  wfDebug( __METHOD__ . "()\n" );
135  $filename = $this->cachePath();
136 
137  $context->getOutput()->sendCacheControl();
138  header( "Content-Type: $wgMimeType; charset=UTF-8" );
139  header( "Content-Language: $wgLanguageCode" );
140  if ( $this->useGzip() ) {
141  if ( wfClientAcceptsGzip() ) {
142  header( 'Content-Encoding: gzip' );
143  readfile( $filename );
144  } else {
145  /* Send uncompressed */
146  wfDebug( __METHOD__ . " uncompressing cache file and sending it\n" );
147  readgzfile( $filename );
148  }
149  } else {
150  readfile( $filename );
151  }
152  $context->getOutput()->disable(); // tell $wgOut that output is taken care of
153  }
154 
161  public function saveToFileCache( $text ) {
162  global $wgUseFileCache;
163 
164  if ( !$wgUseFileCache || strlen( $text ) < 512 ) {
165  // Disabled or empty/broken output (OOM and PHP errors)
166  return $text;
167  }
168 
169  wfDebug( __METHOD__ . "()\n", 'log' );
170 
171  $now = wfTimestampNow();
172  if ( $this->useGzip() ) {
173  $text = str_replace(
174  '</html>', '<!-- Cached/compressed ' . $now . " -->\n</html>", $text );
175  } else {
176  $text = str_replace(
177  '</html>', '<!-- Cached ' . $now . " -->\n</html>", $text );
178  }
179 
180  // Store text to FS...
181  $compressed = $this->saveText( $text );
182  if ( $compressed === false ) {
183  return $text; // error
184  }
185 
186  // gzip output to buffer as needed and set headers...
187  if ( $this->useGzip() ) {
188  // @todo Ugly wfClientAcceptsGzip() function - use context!
189  if ( wfClientAcceptsGzip() ) {
190  header( 'Content-Encoding: gzip' );
191 
192  return $compressed;
193  } else {
194  return $text;
195  }
196  } else {
197  return $text;
198  }
199  }
200 
206  public static function clearFileCache( Title $title ) {
207  global $wgUseFileCache;
208 
209  if ( !$wgUseFileCache ) {
210  return false;
211  }
212 
213  foreach ( self::cacheablePageActions() as $type ) {
214  $fc = self::newFromTitle( $title, $type );
215  $fc->clearCache();
216  }
217 
218  return true;
219  }
220 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
FileCacheBase\saveText
saveText( $text)
Save and compress text to the cache.
Definition: FileCacheBase.php:159
HTMLFileCache\clearFileCache
static clearFileCache(Title $title)
Clear the file caches for a page for all actions.
Definition: HTMLFileCache.php:206
HTMLFileCache
Page view caching in the file system.
Definition: HTMLFileCache.php:31
HTMLFileCache\typeSubdirectory
typeSubdirectory()
Get the cache type subdirectory (with the trailing slash) or the empty string Alter the type -> direc...
Definition: HTMLFileCache.php:77
HTMLFileCache\cacheablePageActions
static cacheablePageActions()
Cacheable actions.
Definition: HTMLFileCache.php:59
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
HTMLFileCache\saveToFileCache
saveToFileCache( $text)
Save this cache object with the given text.
Definition: HTMLFileCache.php:161
HTMLFileCache\loadFromFileCache
loadFromFileCache(IContextSource $context)
Read from cache to context output.
Definition: HTMLFileCache.php:131
MWException
MediaWiki exception.
Definition: MWException.php:26
HTMLFileCache\useFileCache
static useFileCache(IContextSource $context)
Check if pages can be cached for this request/user.
Definition: HTMLFileCache.php:90
FileCacheBase\useGzip
useGzip()
Check if the cache is gzipped.
Definition: FileCacheBase.php:136
FileCacheBase\baseCacheDirectory
baseCacheDirectory()
Get the base file cache directory.
Definition: FileCacheBase.php:52
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2514
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
wfClientAcceptsGzip
wfClientAcceptsGzip( $force=false)
Definition: GlobalFunctions.php:2029
HTMLFileCache\newFromTitle
static newFromTitle( $title, $action)
Construct an ObjectFileCache from a Title and an action.
Definition: HTMLFileCache.php:39
IContextSource\getUser
getUser()
Get the User object.
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
IContextSource
Interface for objects which can provide a context on request.
Definition: IContextSource.php:29
Title
Represents a title within MediaWiki.
Definition: Title.php:35
$cache
$cache
Definition: mcc.php:32
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
FileCacheBase\cachePath
cachePath()
Get the path to the cache file.
Definition: FileCacheBase.php:68
IContextSource\getRequest
getRequest()
Get the WebRequest object.
HTMLFileCache\cacheDirectory
cacheDirectory()
Get the base file cache directory.
Definition: HTMLFileCache.php:67
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
IContextSource\getOutput
getOutput()
Get the OutputPage object.
IContextSource\getLanguage
getLanguage()
Get the Language object.
FileCacheBase
Base class for data storage in the file system.
Definition: FileCacheBase.php:29
$type
$type
Definition: testCompression.php:46