MediaWiki  1.23.14
CachedAction.php
Go to the documentation of this file.
1 <?php
46 abstract class CachedAction extends FormlessAction implements ICacheHelper {
47 
55  protected $cacheHelper;
56 
63  protected $cacheEnabled = true;
64 
71  public function setCacheEnabled( $cacheEnabled ) {
72  $this->cacheHelper->setCacheEnabled( $cacheEnabled );
73  }
74 
84  public function startCache( $cacheExpiry = null, $cacheEnabled = null ) {
85  $this->cacheHelper = new CacheHelper();
86 
87  $this->cacheHelper->setCacheEnabled( $this->cacheEnabled );
88  $this->cacheHelper->setOnInitializedHandler( array( $this, 'onCacheInitialized' ) );
89 
90  $keyArgs = $this->getCacheKey();
91 
92  if ( array_key_exists( 'action', $keyArgs ) && $keyArgs['action'] === 'purge' ) {
93  unset( $keyArgs['action'] );
94  }
95 
96  $this->cacheHelper->setCacheKey( $keyArgs );
97 
98  if ( $this->getRequest()->getText( 'action' ) === 'purge' ) {
99  $this->cacheHelper->rebuildOnDemand();
100  }
101 
102  $this->cacheHelper->startCache( $cacheExpiry, $cacheEnabled );
103  }
104 
119  public function getCachedValue( $computeFunction, $args = array(), $key = null ) {
120  return $this->cacheHelper->getCachedValue( $computeFunction, $args, $key );
121  }
122 
135  public function addCachedHTML( $computeFunction, $args = array(), $key = null ) {
136  $html = $this->cacheHelper->getCachedValue( $computeFunction, $args, $key );
137  $this->getOutput()->addHTML( $html );
138  }
139 
146  public function saveCache() {
147  $this->cacheHelper->saveCache();
148  }
149 
158  public function setExpiry( $cacheExpiry ) {
159  $this->cacheHelper->setExpiry( $cacheExpiry );
160  }
161 
169  protected function getCacheKey() {
170  return array(
171  get_class( $this->page ),
172  $this->getName(),
173  $this->getLanguage()->getCode()
174  );
175  }
176 
184  public function onCacheInitialized( $hasCached ) {
185  if ( $hasCached ) {
186  $this->getOutput()->setSubtitle( $this->cacheHelper->getCachedNotice( $this->getContext() ) );
187  }
188  }
189 }
CachedAction\addCachedHTML
addCachedHTML( $computeFunction, $args=array(), $key=null)
Add some HTML to be cached.
Definition: CachedAction.php:133
CachedAction\onCacheInitialized
onCacheInitialized( $hasCached)
Gets called after the cache got initialized.
Definition: CachedAction.php:182
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
CachedAction\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: CachedAction.php:117
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1530
CachedAction\saveCache
saveCache()
Saves the HTML to the cache in case it got recomputed.
Definition: CachedAction.php:144
FormlessAction
An action which just does something, without showing a form first.
Definition: FormlessAction.php:29
Action\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:182
CachedAction\getCacheKey
getCacheKey()
Returns the variables used to constructed the cache key in an array.
Definition: CachedAction.php:167
CachedAction\setCacheEnabled
setCacheEnabled( $cacheEnabled)
Sets if the cache should be enabled or not.
Definition: CachedAction.php:69
Action\getName
getName()
Return the name of the action this object responds to.
ICacheHelper
Interface for all classes implementing CacheHelper functionality.
Definition: CacheHelper.php:30
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
CachedAction
Abstract action class with scaffolding for caching HTML and other values in a single blob.
Definition: CachedAction.php:46
CachedAction\$cacheEnabled
bool $cacheEnabled
If the cache is enabled or not.
Definition: CachedAction.php:61
CachedAction\setExpiry
setExpiry( $cacheExpiry)
Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry.
Definition: CachedAction.php:156
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
CachedAction\$cacheHelper
CacheHelper $cacheHelper
CacheHelper object to which we forward the non-SpecialPage specific caching work.
Definition: CachedAction.php:54
Action\getLanguage
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition: Action.php:218
CachedAction\startCache
startCache( $cacheExpiry=null, $cacheEnabled=null)
Initializes the caching.
Definition: CachedAction.php:82
Action\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:191
page
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values my talk page
Definition: hooks.txt:1961