2004-02-26 13:37:26 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Cache Parser
|
2007-04-04 05:22:37 +00:00
|
|
|
* @todo document
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-11-22 01:16:44 +00:00
|
|
|
class ParserCache {
|
2010-07-30 19:51:39 +00:00
|
|
|
private $mMemc;
|
|
|
|
|
|
2006-01-05 04:26:52 +00:00
|
|
|
/**
|
|
|
|
|
* Get an instance of this object
|
|
|
|
|
*/
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
public static function singleton() {
|
2006-01-05 04:26:52 +00:00
|
|
|
static $instance;
|
|
|
|
|
if ( !isset( $instance ) ) {
|
|
|
|
|
global $parserMemc;
|
|
|
|
|
$instance = new ParserCache( $parserMemc );
|
|
|
|
|
}
|
|
|
|
|
return $instance;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-11-22 01:16:44 +00:00
|
|
|
/**
|
|
|
|
|
* Setup a cache pathway with a given back-end storage mechanism.
|
|
|
|
|
* May be a memcached client or a BagOStuff derivative.
|
|
|
|
|
*
|
2010-05-15 20:16:26 +00:00
|
|
|
* @param $memCached Object
|
2004-11-22 01:16:44 +00:00
|
|
|
*/
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
function __construct( $memCached ) {
|
2010-07-30 19:51:39 +00:00
|
|
|
if ( !$memCached ) {
|
|
|
|
|
global $parserMemc;
|
|
|
|
|
$parserMemc = $memCached = wfGetParserCacheStorage();
|
|
|
|
|
}
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
$this->mMemc = $memCached;
|
2004-11-22 01:16:44 +00:00
|
|
|
}
|
2010-08-09 21:53:21 +00:00
|
|
|
|
|
|
|
|
protected function getParserOutputKey( $article, $hash ) {
|
2009-03-18 23:27:48 +00:00
|
|
|
global $wgRequest;
|
2010-08-05 14:37:50 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
// idhash seem to mean 'page id' + 'rendering hash' (r3710)
|
2008-12-10 05:33:57 +00:00
|
|
|
$pageid = $article->getID();
|
2009-03-18 23:27:48 +00:00
|
|
|
$renderkey = (int)($wgRequest->getVal('action') == 'render');
|
2010-08-09 21:53:21 +00:00
|
|
|
|
|
|
|
|
$key = wfMemcKey( 'pcache', 'idhash', "{$pageid}-{$renderkey}!{$hash}" );
|
2004-05-27 15:24:04 +00:00
|
|
|
return $key;
|
2004-02-26 13:37:26 +00:00
|
|
|
}
|
2005-07-01 00:03:31 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
protected function getOptionsKey( $article ) {
|
|
|
|
|
$pageid = $article->getID();
|
|
|
|
|
return wfMemcKey( 'pcache', 'idoptions', "{$pageid}" );
|
|
|
|
|
}
|
|
|
|
|
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
function getETag( $article, $popts ) {
|
2010-08-09 21:53:21 +00:00
|
|
|
return 'W/"' . $this->getParserOutputKey( $article,
|
|
|
|
|
$popts->optionsHash( ParserOptions::legacyOptions() ) ) .
|
|
|
|
|
"--" . $article->mTouched . '"';
|
2005-07-01 00:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
/**
|
|
|
|
|
* Retrieve the ParserOutput from ParserCache, even if it's outdated.
|
|
|
|
|
*/
|
|
|
|
|
public function getDirty( $article, $popts ) {
|
|
|
|
|
$value = $this->mMemc->get( $article, $popts, true );
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
return is_object( $value ) ? $value : false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
/**
|
|
|
|
|
* Used to provide a unique id for the PoolCounter.
|
|
|
|
|
* It would be preferable to have this code in get()
|
|
|
|
|
* instead of having Article looking in our internals.
|
|
|
|
|
*
|
|
|
|
|
* Precondition: $article->checkTouched() has been called.
|
|
|
|
|
*/
|
|
|
|
|
public function getKey( $article, $popts, $useOutdated = true ) {
|
|
|
|
|
global $wgCacheEpoch;
|
|
|
|
|
|
|
|
|
|
// Determine the options which affect this article
|
|
|
|
|
$optionsKey = $this->mMemc->get( $this->getOptionsKey( $article ) );
|
|
|
|
|
if ( $optionsKey !== false ) {
|
|
|
|
|
if ( !$useOutdated && $optionsKey->expired( $article->mTouched ) ) {
|
|
|
|
|
wfIncrStats( "pcache_miss_expired" );
|
|
|
|
|
$cacheTime = $optionsKey->getCacheTime();
|
|
|
|
|
wfDebug( "Parser options key expired, touched {$article->mTouched}, epoch $wgCacheEpoch, cached $cacheTime\n" );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$usedOptions = $optionsKey->mUsedOptions;
|
|
|
|
|
wfDebug( "Parser cache options found.\n" );
|
|
|
|
|
} else {
|
|
|
|
|
# TODO: Fail here $wgParserCacheExpireTime after deployment unless $useOutdated
|
|
|
|
|
|
|
|
|
|
$usedOptions = ParserOptions::legacyOptions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->getParserOutputKey( $article, $popts->optionsHash( $usedOptions ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the ParserOutput from ParserCache.
|
|
|
|
|
* false if not found or outdated.
|
|
|
|
|
*/
|
|
|
|
|
public function get( $article, $popts, $useOutdated = false ) {
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
global $wgCacheEpoch;
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
$canCache = $article->checkTouched();
|
|
|
|
|
if ( !$canCache ) {
|
|
|
|
|
// It's a redirect now
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Having called checkTouched() ensures this will be loaded
|
|
|
|
|
$touched = $article->mTouched;
|
|
|
|
|
|
|
|
|
|
$parserOutputKey = $this->getKey( $article, $popts, $useOutdated );
|
|
|
|
|
if ( $parserOutputKey === false ) {
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$value = $this->mMemc->get( $parserOutputKey );
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
if ( !$value ) {
|
2004-10-23 10:22:38 +00:00
|
|
|
wfDebug( "Parser cache miss.\n" );
|
2005-06-19 03:05:51 +00:00
|
|
|
wfIncrStats( "pcache_miss_absent" );
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wfDebug( "Found.\n" );
|
2010-08-09 21:53:21 +00:00
|
|
|
|
|
|
|
|
if ( !$useOutdated && $value->expired( $touched ) ) {
|
|
|
|
|
wfIncrStats( "pcache_miss_expired" );
|
|
|
|
|
wfDebug( "ParserOutput key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
|
2004-05-27 15:24:04 +00:00
|
|
|
$value = false;
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
} else {
|
|
|
|
|
if ( isset( $value->mTimestamp ) ) {
|
|
|
|
|
$article->mTimestamp = $value->mTimestamp;
|
|
|
|
|
}
|
|
|
|
|
wfIncrStats( "pcache_hit" );
|
2004-02-26 13:37:26 +00:00
|
|
|
}
|
2004-05-28 05:45:13 +00:00
|
|
|
|
Implemented the PoolCounter feature and did some general refactoring in the areas that it touched.
* Renamed Article::outputFromWikitext() to Article::getOutputFromWikitext()
* Factored out cascade protection updates
* Removed recently-added Article::tryParserCache(): misnamed, can be done in one line of code in the caller. Deprecated OutputPage::tryParserCache().
* Made some functions public instead of protected when they could be useful from hooks.
* In ParserCache, removed PHP 4-style ampersands
In Article::view():
* Factored out robot policy logic, "redirected from" header, patrol footer, diff page, revdelete header, CSS/JS formatting, footer, namespace header, missing article error
* Removed some variables, renamed some others, fixed incorrect use of empty()
* Used the refactored footer section to do a couple of early returns and unindent a massive if(!$outputDone) block
* Removed fantasy interpretation of $this->getContent()===false in comment
* Don't try the parser cache when ArticleViewHeader specified $outputDone=true
* Move timing hack to getOutputFromWikitext()
* Stop using $wgOut->parserOptions() with save/restore nonsense every time you want to change something in it. This is meant to be OOP.
* Don't overwrite the article text with an error message and then pretend to write it to the cache, that's confusing
2009-07-08 08:12:35 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2004-05-27 15:24:04 +00:00
|
|
|
return $value;
|
2004-02-26 13:37:26 +00:00
|
|
|
}
|
2005-07-01 00:03:31 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
|
|
|
|
|
public function save( $parserOutput, $article, $popts ) {
|
2010-06-01 14:28:51 +00:00
|
|
|
$expire = $parserOutput->getCacheExpiry();
|
2007-04-21 21:35:21 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
if( $expire > 0 ) {
|
2006-05-13 17:40:59 +00:00
|
|
|
$now = wfTimestampNow();
|
2010-08-09 21:53:21 +00:00
|
|
|
|
|
|
|
|
$optionsKey = new CacheTime;
|
|
|
|
|
$optionsKey->mUsedOptions = $popts->usedOptions();
|
|
|
|
|
$optionsKey->updateCacheExpiry( $expire );
|
|
|
|
|
|
|
|
|
|
$optionsKey->setCacheTime( $now );
|
2006-05-13 17:40:59 +00:00
|
|
|
$parserOutput->setCacheTime( $now );
|
2007-04-21 21:35:21 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
$optionsKey->setContainsOldMagic( $parserOutput->containsOldMagic() );
|
|
|
|
|
|
|
|
|
|
$parserOutputKey = $this->getParserOutputKey( $article, $popts->optionsHash( $optionsKey->mUsedOptions ) );
|
|
|
|
|
|
2006-05-13 17:40:59 +00:00
|
|
|
// Save the timestamp so that we don't have to load the revision row on view
|
|
|
|
|
$parserOutput->mTimestamp = $article->getTimestamp();
|
2007-04-21 21:35:21 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
$parserOutput->mText .= "\n<!-- Saved in parser cache with key $parserOutputKey and timestamp $now -->\n";
|
|
|
|
|
wfDebug( "Saved in parser cache with key $parserOutputKey and timestamp $now\n" );
|
2007-04-21 21:35:21 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
// Save the parser output
|
|
|
|
|
$this->mMemc->set( $parserOutputKey, $parserOutput, $expire );
|
2007-04-21 21:35:21 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
// ...and its pointer
|
|
|
|
|
$this->mMemc->set( $this->getOptionsKey( $article ), $optionsKey, $expire );
|
2004-02-26 13:37:26 +00:00
|
|
|
} else {
|
2006-05-13 17:40:59 +00:00
|
|
|
wfDebug( "Parser output was marked as uncacheable and has not been saved.\n" );
|
2004-02-26 13:37:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|