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 {
|
2006-01-05 04:26:52 +00:00
|
|
|
/**
|
|
|
|
|
* Get an instance of this object
|
|
|
|
|
*/
|
2006-07-10 15:41:30 +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.
|
|
|
|
|
*
|
|
|
|
|
* @param object $memCached
|
|
|
|
|
*/
|
2007-01-20 13:34:31 +00:00
|
|
|
function __construct( &$memCached ) {
|
2004-11-22 01:16:44 +00:00
|
|
|
$this->mMemc =& $memCached;
|
|
|
|
|
}
|
2005-07-01 00:03:31 +00:00
|
|
|
|
2008-06-11 02:51:30 +00:00
|
|
|
function getKey( &$article, &$user ) {
|
2006-10-04 09:06:18 +00:00
|
|
|
global $action;
|
2008-06-11 02:51:30 +00:00
|
|
|
$hash = $user->getPageRenderingHash();
|
Revert r38196, r38204 -- "(bugs 6089, 13079) Show edit section links for transcluded template if, and only if the user can edit it, made Title::getUserPermissionsErrorsInternal() public so that it can be used in Parser and it can pass the User object from ParserOptions. " & co
Cause regression in 19 parser test cases, looks like messing up the tooltips for section edit links.
19 previously failing test(s) now PASSING! :)
* Bug 6563: Edit link generation for section shown by <includeonly> [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Bug 6563: Edit link generation for section suppressed by <includeonly> [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Basic section headings [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Section headings with TOC [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Handling of sections up to level 6 and beyond [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC regression (bug 9764) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC with wgMaxTocLevel=3 (bug 6204) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Resolving duplicate section names [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Resolving duplicate section names with differing case (bug 10721) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Template with sections, __NOTOC__ [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Link inside a section heading [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* TOC regression (bug 12077) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Fuzz testing: Parser14 [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Fuzz testing: Parser14-table [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Inclusion of !userCanEdit() content [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Out-of-order TOC heading levels [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* -{}- tags within headlines (within html for parserConvert()) [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* Morwen/13: Unclosed link followed by heading [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
* HHP2.2: Heuristics for headings in preprocessor parenthetical structures [Fixed between 29-Jul-2008 22:42:06, 1.14alpha (r38207) and 29-Jul-2008 23:54:51, 1.14alpha (r38207)]
2008-07-29 23:56:30 +00:00
|
|
|
if( !$article->mTitle->quickUserCan( 'edit' ) ) {
|
2005-12-28 22:28:04 +00:00
|
|
|
// section edit links are suppressed even if the user has them on
|
|
|
|
|
$edit = '!edit=0';
|
|
|
|
|
} else {
|
|
|
|
|
$edit = '';
|
|
|
|
|
}
|
2004-05-27 15:24:04 +00:00
|
|
|
$pageid = intval( $article->getID() );
|
2005-07-03 07:27:43 +00:00
|
|
|
$renderkey = (int)($action == 'render');
|
2006-10-04 09:06:18 +00:00
|
|
|
$key = wfMemcKey( 'pcache', 'idhash', "$pageid-$renderkey!$hash$edit" );
|
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
|
|
|
|
|
|
|
|
function getETag( &$article, &$user ) {
|
|
|
|
|
return 'W/"' . $this->getKey($article, $user) . "--" . $article->mTouched. '"';
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-27 15:24:04 +00:00
|
|
|
function get( &$article, &$user ) {
|
2004-11-22 01:16:44 +00:00
|
|
|
global $wgCacheEpoch;
|
2004-08-22 17:24:50 +00:00
|
|
|
$fname = 'ParserCache::get';
|
2004-05-28 05:45:13 +00:00
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
|
2004-05-27 15:24:04 +00:00
|
|
|
$key = $this->getKey( $article, $user );
|
2005-01-04 12:54:07 +00:00
|
|
|
|
2004-05-30 08:18:40 +00:00
|
|
|
wfDebug( "Trying parser cache $key\n" );
|
2004-11-22 01:16:44 +00:00
|
|
|
$value = $this->mMemc->get( $key );
|
2004-10-23 08:23:13 +00:00
|
|
|
if ( is_object( $value ) ) {
|
2004-05-30 08:18:40 +00:00
|
|
|
wfDebug( "Found.\n" );
|
2004-05-27 15:24:04 +00:00
|
|
|
# Delete if article has changed since the cache was made
|
2004-06-04 10:40:44 +00:00
|
|
|
$canCache = $article->checkTouched();
|
2004-05-30 08:18:40 +00:00
|
|
|
$cacheTime = $value->getCacheTime();
|
2004-06-04 12:31:32 +00:00
|
|
|
$touched = $article->mTouched;
|
2004-11-25 22:02:30 +00:00
|
|
|
if ( !$canCache || $value->expired( $touched ) ) {
|
2004-06-04 10:40:44 +00:00
|
|
|
if ( !$canCache ) {
|
2005-06-19 03:05:51 +00:00
|
|
|
wfIncrStats( "pcache_miss_invalid" );
|
2004-06-04 10:40:44 +00:00
|
|
|
wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
|
|
|
|
|
} else {
|
2005-06-19 03:05:51 +00:00
|
|
|
wfIncrStats( "pcache_miss_expired" );
|
2004-06-04 10:40:44 +00:00
|
|
|
wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" );
|
|
|
|
|
}
|
2004-11-22 01:16:44 +00:00
|
|
|
$this->mMemc->delete( $key );
|
2004-05-27 15:24:04 +00:00
|
|
|
$value = false;
|
2005-01-04 12:54:07 +00:00
|
|
|
} else {
|
2006-03-16 02:57:44 +00:00
|
|
|
if ( isset( $value->mTimestamp ) ) {
|
|
|
|
|
$article->mTimestamp = $value->mTimestamp;
|
|
|
|
|
}
|
2005-06-19 03:05:51 +00:00
|
|
|
wfIncrStats( "pcache_hit" );
|
2004-05-27 15:24:04 +00:00
|
|
|
}
|
2004-02-26 13:37:26 +00:00
|
|
|
} else {
|
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" );
|
2004-05-27 15:24:04 +00:00
|
|
|
$value = false;
|
2004-02-26 13:37:26 +00:00
|
|
|
}
|
2004-05-28 05:45:13 +00:00
|
|
|
|
|
|
|
|
wfProfileOut( $fname );
|
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
|
|
|
|
2008-06-11 02:51:30 +00:00
|
|
|
function save( $parserOutput, &$article, &$user ){
|
2006-03-07 01:10:39 +00:00
|
|
|
global $wgParserCacheExpireTime;
|
2008-06-11 02:51:30 +00:00
|
|
|
$key = $this->getKey( $article, $user );
|
2007-04-21 21:35:21 +00:00
|
|
|
|
2006-05-13 17:40:59 +00:00
|
|
|
if( $parserOutput->getCacheTime() != -1 ) {
|
2007-04-21 21:35:21 +00:00
|
|
|
|
2006-05-13 17:40:59 +00:00
|
|
|
$now = wfTimestampNow();
|
|
|
|
|
$parserOutput->setCacheTime( $now );
|
2007-04-21 21:35:21 +00:00
|
|
|
|
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
|
|
|
|
2006-05-13 17:40:59 +00:00
|
|
|
$parserOutput->mText .= "\n<!-- Saved in parser cache with key $key and timestamp $now -->\n";
|
|
|
|
|
wfDebug( "Saved in parser cache with key $key and timestamp $now\n" );
|
2007-04-21 21:35:21 +00:00
|
|
|
|
2006-05-13 17:40:59 +00:00
|
|
|
if( $parserOutput->containsOldMagic() ){
|
|
|
|
|
$expire = 3600; # 1 hour
|
|
|
|
|
} else {
|
|
|
|
|
$expire = $wgParserCacheExpireTime;
|
|
|
|
|
}
|
|
|
|
|
$this->mMemc->set( $key, $parserOutput, $expire );
|
2007-04-21 21:35:21 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
2007-04-21 21:35:21 +00:00
|
|
|
|
2004-02-26 13:37:26 +00:00
|
|
|
}
|