MediaWiki REL1_31
CacheDependency.php
Go to the documentation of this file.
1<?php
24
32 private $value;
34 private $deps;
35
41 function __construct( $value = false, $deps = [] ) {
42 $this->value = $value;
43
44 if ( !is_array( $deps ) ) {
45 $deps = [ $deps ];
46 }
47
48 $this->deps = $deps;
49 }
50
56 function isExpired() {
57 foreach ( $this->deps as $dep ) {
58 if ( $dep->isExpired() ) {
59 return true;
60 }
61 }
62
63 return false;
64 }
65
70 function initialiseDeps() {
71 foreach ( $this->deps as $dep ) {
72 $dep->loadDependencyValues();
73 }
74 }
75
80 function getValue() {
81 return $this->value;
82 }
83
91 function storeToCache( $cache, $key, $expiry = 0 ) {
92 $this->initialiseDeps();
93 $cache->set( $key, $this, $expiry );
94 }
95
113 static function getValueFromCache( $cache, $key, $expiry = 0, $callback = false,
114 $callbackParams = [], $deps = []
115 ) {
116 $obj = $cache->get( $key );
117
118 if ( is_object( $obj ) && $obj instanceof DependencyWrapper && !$obj->isExpired() ) {
119 $value = $obj->value;
120 } elseif ( $callback ) {
121 $value = call_user_func_array( $callback, $callbackParams );
122 # Cache the newly-generated value
123 $wrapper = new DependencyWrapper( $value, $deps );
124 $wrapper->storeToCache( $cache, $key, $expiry );
125 } else {
126 $value = null;
127 }
128
129 return $value;
130 }
131}
132
136abstract class CacheDependency {
140 abstract function isExpired();
141
146 }
147}
148
153 private $filename;
154 private $timestamp;
155
168 function __construct( $filename, $timestamp = null ) {
169 $this->filename = $filename;
170 $this->timestamp = $timestamp;
171 }
172
176 function __sleep() {
177 $this->loadDependencyValues();
178
179 return [ 'filename', 'timestamp' ];
180 }
181
183 if ( is_null( $this->timestamp ) ) {
184 Wikimedia\suppressWarnings();
185 # Dependency on a non-existent file stores "false"
186 # This is a valid concept!
187 $this->timestamp = filemtime( $this->filename );
188 Wikimedia\restoreWarnings();
189 }
190 }
191
195 function isExpired() {
196 Wikimedia\suppressWarnings();
197 $lastmod = filemtime( $this->filename );
198 Wikimedia\restoreWarnings();
199 if ( $lastmod === false ) {
200 if ( $this->timestamp === false ) {
201 # Still nonexistent
202 return false;
203 } else {
204 # Deleted
205 wfDebug( "Dependency triggered: {$this->filename} deleted.\n" );
206
207 return true;
208 }
209 } else {
210 if ( $lastmod > $this->timestamp ) {
211 # Modified or created
212 wfDebug( "Dependency triggered: {$this->filename} changed.\n" );
213
214 return true;
215 } else {
216 # Not modified
217 return false;
218 }
219 }
220 }
221}
222
227 private $name;
228 private $value;
229
230 function __construct( $name ) {
231 $this->name = $name;
232 $this->value = $GLOBALS[$name];
233 }
234
238 function isExpired() {
239 if ( !isset( $GLOBALS[$this->name] ) ) {
240 return true;
241 }
242
244 }
245}
246
251 private $name;
252 private $value;
253
254 function __construct( $name ) {
255 $this->name = $name;
256 $this->value = $this->getConfig()->get( $this->name );
257 }
258
259 private function getConfig() {
260 return MediaWikiServices::getInstance()->getMainConfig();
261 }
262
266 function isExpired() {
267 if ( !$this->getConfig()->has( $this->name ) ) {
268 return true;
269 }
270
271 return $this->getConfig()->get( $this->name ) != $this->value;
272 }
273}
274
279 private $name;
280 private $value;
281
282 function __construct( $name ) {
283 $this->name = $name;
284 $this->value = constant( $name );
285 }
286
290 function isExpired() {
291 return constant( $this->name ) != $this->value;
292 }
293}
$GLOBALS['IP']
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
loadDependencyValues()
Hook to perform any expensive pre-serialize loading of dependency values.
isExpired()
Returns true if the dependency is expired, false otherwise.
This class stores an arbitrary value along with its dependencies.
__construct( $value=false, $deps=[])
initialiseDeps()
Initialise dependency values in preparation for storing.
static getValueFromCache( $cache, $key, $expiry=0, $callback=false, $callbackParams=[], $deps=[])
Attempt to get a value from the cache.
CacheDependency[] $deps
storeToCache( $cache, $key, $expiry=0)
Store the wrapper to a cache.
getValue()
Get the user-defined value.
isExpired()
Returns true if any of the dependencies have expired.
__construct( $filename, $timestamp=null)
Create a file dependency.
loadDependencyValues()
Hook to perform any expensive pre-serialize loading of dependency values.
MediaWikiServices is the service locator for the application scope of MediaWiki.
> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) name
Definition hooks.txt:1840
$cache
Definition mcc.php:33