MediaWiki  1.23.2
SpecialCachedPage.php
Go to the documentation of this file.
1 <?php
2 
40 abstract class SpecialCachedPage extends SpecialPage implements ICacheHelper {
41 
49  protected $cacheHelper;
50 
57  protected $cacheEnabled = true;
58 
66  protected function afterExecute( $subPage ) {
67  $this->saveCache();
68 
69  parent::afterExecute( $subPage );
70  }
71 
78  public function setCacheEnabled( $cacheEnabled ) {
79  $this->cacheHelper->setCacheEnabled( $cacheEnabled );
80  }
81 
91  public function startCache( $cacheExpiry = null, $cacheEnabled = null ) {
92  if ( !isset( $this->cacheHelper ) ) {
93  $this->cacheHelper = new CacheHelper();
94 
95  $this->cacheHelper->setCacheEnabled( $this->cacheEnabled );
96  $this->cacheHelper->setOnInitializedHandler( array( $this, 'onCacheInitialized' ) );
97 
98  $keyArgs = $this->getCacheKey();
99 
100  if ( array_key_exists( 'action', $keyArgs ) && $keyArgs['action'] === 'purge' ) {
101  unset( $keyArgs['action'] );
102  }
103 
104  $this->cacheHelper->setCacheKey( $keyArgs );
105 
106  if ( $this->getRequest()->getText( 'action' ) === 'purge' ) {
107  $this->cacheHelper->rebuildOnDemand();
108  }
109  }
110 
111  $this->cacheHelper->startCache( $cacheExpiry, $cacheEnabled );
112  }
113 
128  public function getCachedValue( $computeFunction, $args = array(), $key = null ) {
129  return $this->cacheHelper->getCachedValue( $computeFunction, $args, $key );
130  }
131 
144  public function addCachedHTML( $computeFunction, $args = array(), $key = null ) {
145  $this->getOutput()->addHTML( $this->cacheHelper->getCachedValue( $computeFunction, $args, $key ) );
146  }
147 
154  public function saveCache() {
155  if ( isset( $this->cacheHelper ) ) {
156  $this->cacheHelper->saveCache();
157  }
158  }
159 
167  public function setExpiry( $cacheExpiry ) {
168  $this->cacheHelper->setExpiry( $cacheExpiry );
169  }
170 
178  protected function getCacheKey() {
179  return array(
180  $this->mName,
181  $this->getLanguage()->getCode()
182  );
183  }
184 
192  public function onCacheInitialized( $hasCached ) {
193  if ( $hasCached ) {
194  $this->getOutput()->setSubtitle( $this->cacheHelper->getCachedNotice( $this->getContext() ) );
195  }
196  }
197 }
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
SpecialCachedPage\addCachedHTML
addCachedHTML( $computeFunction, $args=array(), $key=null)
Add some HTML to be cached.
Definition: SpecialCachedPage.php:142
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:535
SpecialCachedPage\onCacheInitialized
onCacheInitialized( $hasCached)
Gets called after the cache got initialized.
Definition: SpecialCachedPage.php:190
ICacheHelper
Interface for all classes implementing CacheHelper functionality.
Definition: CacheHelper.php:30
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:578
SpecialCachedPage
Definition: SpecialCachedPage.php:40
SpecialCachedPage\setCacheEnabled
setCacheEnabled( $cacheEnabled)
Sets if the cache should be enabled or not.
Definition: SpecialCachedPage.php:76
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialCachedPage\setExpiry
setExpiry( $cacheExpiry)
Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry.
Definition: SpecialCachedPage.php:165
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:33
SpecialCachedPage\saveCache
saveCache()
Saves the HTML to the cache in case it got recomputed.
Definition: SpecialCachedPage.php:152
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:525
SpecialCachedPage\$cacheEnabled
boolean $cacheEnabled
If the cache is enabled or not.
Definition: SpecialCachedPage.php:55
CacheHelper
Helper class for caching various elements in a single cache entry.
Definition: CacheHelper.php:103
$args
if( $line===false) $args
Definition: cdb.php:62
SpecialCachedPage\afterExecute
afterExecute( $subPage)
Gets called after.
Definition: SpecialCachedPage.php:64
SpecialCachedPage\getCachedValue
getCachedValue( $computeFunction, $args=array(), $key=null)
Get a cached value if available or compute it if not and then cache it if possible.
Definition: SpecialCachedPage.php:126
SpecialCachedPage\startCache
startCache( $cacheExpiry=null, $cacheEnabled=null)
Initializes the caching.
Definition: SpecialCachedPage.php:89
SpecialCachedPage\getCacheKey
getCacheKey()
Returns the variables used to constructed the cache key in an array.
Definition: SpecialCachedPage.php:176
SpecialCachedPage\$cacheHelper
CacheHelper $cacheHelper
CacheHelper object to which we forward the non-SpecialPage specific caching work.
Definition: SpecialCachedPage.php:48