2004-02-26 13:37:26 +00:00
|
|
|
<?php
|
2010-08-22 14:31:05 +00:00
|
|
|
/**
|
|
|
|
|
* Cache for outputs of the PHP parser
|
|
|
|
|
*
|
2012-04-30 09:22:16 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-08-22 14:31:05 +00:00
|
|
|
* @file
|
2012-04-30 09:22:16 +00:00
|
|
|
* @ingroup Cache Parser
|
2010-08-22 14:31:05 +00:00
|
|
|
*/
|
|
|
|
|
|
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;
|
2011-03-07 19:13:19 +00:00
|
|
|
const try116cache = false; /* Only useful $wgParserCacheExpireTime after updating to 1.17 */
|
2010-07-30 19:51:39 +00:00
|
|
|
|
2006-01-05 04:26:52 +00:00
|
|
|
/**
|
|
|
|
|
* Get an instance of this object
|
2011-07-24 21:36:04 +00:00
|
|
|
*
|
|
|
|
|
* @return ParserCache
|
2006-01-05 04:26:52 +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
|
|
|
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
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException
|
2004-11-22 01:16:44 +00:00
|
|
|
*/
|
2011-04-15 22:58:00 +00:00
|
|
|
protected function __construct( $memCached ) {
|
2010-07-30 19:51:39 +00:00
|
|
|
if ( !$memCached ) {
|
2010-12-05 00:37:44 +00:00
|
|
|
throw new MWException( "Tried to create a ParserCache with an invalid memcached" );
|
2010-07-30 19:51:39 +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
|
|
|
$this->mMemc = $memCached;
|
2004-11-22 01:16:44 +00:00
|
|
|
}
|
2010-09-12 19:26:01 +00:00
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
|
|
|
|
* @param $article Article
|
2011-04-15 22:58:00 +00:00
|
|
|
* @param $hash string
|
2011-02-19 01:02:56 +00:00
|
|
|
* @return mixed|string
|
|
|
|
|
*/
|
2010-08-09 21:53:21 +00:00
|
|
|
protected function getParserOutputKey( $article, $hash ) {
|
2009-03-18 23:27:48 +00:00
|
|
|
global $wgRequest;
|
2010-09-12 19:26:01 +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();
|
2013-04-20 15:38:24 +00:00
|
|
|
$renderkey = (int)( $wgRequest->getVal( 'action' ) == 'render' );
|
2010-09-12 19:26:01 +00:00
|
|
|
|
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
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
|
|
|
|
* @param $article Article
|
|
|
|
|
* @return mixed|string
|
|
|
|
|
*/
|
2010-08-09 21:53:21 +00:00
|
|
|
protected function getOptionsKey( $article ) {
|
|
|
|
|
$pageid = $article->getID();
|
|
|
|
|
return wfMemcKey( 'pcache', 'idoptions', "{$pageid}" );
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-10 12:10:49 +00:00
|
|
|
/**
|
2010-09-12 19:26:01 +00:00
|
|
|
* Provides an E-Tag suitable for the whole page. Note that $article
|
|
|
|
|
* is just the main wikitext. The E-Tag has to be unique to the whole
|
|
|
|
|
* page, even if the article itself is the same, so it uses the
|
|
|
|
|
* complete set of user options. We don't want to use the preference
|
|
|
|
|
* of a different user on a message just because it wasn't used in
|
|
|
|
|
* $article. For example give a Chinese interface to a user with
|
|
|
|
|
* English preferences. That's why we take into account *all* user
|
2010-08-23 21:54:45 +00:00
|
|
|
* options. (r70809 CR)
|
2011-02-19 01:02:56 +00:00
|
|
|
*
|
|
|
|
|
* @param $article Article
|
|
|
|
|
* @param $popts ParserOptions
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return string
|
2010-08-10 12:10:49 +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 getETag( $article, $popts ) {
|
2010-09-12 19:26:01 +00:00
|
|
|
return 'W/"' . $this->getParserOutputKey( $article,
|
2011-09-20 15:58:01 +00:00
|
|
|
$popts->optionsHash( ParserOptions::legacyOptions(), $article->getTitle() ) ) .
|
2010-12-14 17:49:01 +00:00
|
|
|
"--" . $article->getTouched() . '"';
|
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.
|
2011-04-15 22:58:00 +00:00
|
|
|
* @param $article Article
|
|
|
|
|
* @param $popts ParserOptions
|
2012-02-10 15:37:33 +00:00
|
|
|
* @return ParserOutput|bool False on failure
|
2010-08-09 21:53:21 +00:00
|
|
|
*/
|
|
|
|
|
public function getDirty( $article, $popts ) {
|
2010-09-15 16:58:44 +00:00
|
|
|
$value = $this->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.
|
2010-09-12 19:26:01 +00:00
|
|
|
* It would be preferable to have this code in get()
|
2010-08-09 21:53:21 +00:00
|
|
|
* instead of having Article looking in our internals.
|
2011-02-19 01:02:56 +00:00
|
|
|
*
|
2012-02-01 20:53:38 +00:00
|
|
|
* @todo Document parameter $useOutdated
|
|
|
|
|
*
|
2012-07-10 14:58:52 +00:00
|
|
|
* @param $article Article
|
|
|
|
|
* @param $popts ParserOptions
|
|
|
|
|
* @param $useOutdated Boolean (default true)
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool|mixed|string
|
2010-08-09 21:53:21 +00:00
|
|
|
*/
|
|
|
|
|
public function getKey( $article, $popts, $useOutdated = true ) {
|
|
|
|
|
global $wgCacheEpoch;
|
2010-09-12 19:26:01 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $popts instanceof User ) {
|
2010-08-10 19:32:49 +00:00
|
|
|
wfWarn( "Use of outdated prototype ParserCache::getKey( &\$article, &\$user )\n" );
|
2010-08-10 14:11:51 +00:00
|
|
|
$popts = ParserOptions::newFromUser( $popts );
|
|
|
|
|
}
|
2010-09-12 19:26:01 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
// Determine the options which affect this article
|
|
|
|
|
$optionsKey = $this->mMemc->get( $this->getOptionsKey( $article ) );
|
2010-08-10 12:10:49 +00:00
|
|
|
if ( $optionsKey != false ) {
|
2010-12-14 17:49:01 +00:00
|
|
|
if ( !$useOutdated && $optionsKey->expired( $article->getTouched() ) ) {
|
2010-08-09 21:53:21 +00:00
|
|
|
wfIncrStats( "pcache_miss_expired" );
|
|
|
|
|
$cacheTime = $optionsKey->getCacheTime();
|
2010-12-14 17:49:01 +00:00
|
|
|
wfDebug( "Parser options key expired, touched " . $article->getTouched() . ", epoch $wgCacheEpoch, cached $cacheTime\n" );
|
2010-08-09 21:53:21 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-09-12 19:26:01 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
$usedOptions = $optionsKey->mUsedOptions;
|
|
|
|
|
wfDebug( "Parser cache options found.\n" );
|
|
|
|
|
} else {
|
2011-03-07 19:13:19 +00:00
|
|
|
if ( !$useOutdated && !self::try116cache ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-08-09 21:53:21 +00:00
|
|
|
$usedOptions = ParserOptions::legacyOptions();
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-20 15:58:01 +00:00
|
|
|
return $this->getParserOutputKey( $article, $popts->optionsHash( $usedOptions, $article->getTitle() ) );
|
2010-08-09 21:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the ParserOutput from ParserCache.
|
|
|
|
|
* false if not found or outdated.
|
2011-05-28 18:59:42 +00:00
|
|
|
*
|
2012-07-10 14:58:52 +00:00
|
|
|
* @param $article Article
|
|
|
|
|
* @param $popts ParserOptions
|
|
|
|
|
* @param $useOutdated Boolean (default false)
|
2011-05-28 18:59:42 +00:00
|
|
|
*
|
2012-02-10 15:37:33 +00:00
|
|
|
* @return ParserOutput|bool False on failure
|
2010-08-09 21:53:21 +00:00
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 17:49:01 +00:00
|
|
|
$touched = $article->getTouched();
|
2010-09-12 19:26:01 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
$parserOutputKey = $this->getKey( $article, $popts, $useOutdated );
|
|
|
|
|
if ( $parserOutputKey === false ) {
|
2012-01-23 16:27:13 +00:00
|
|
|
wfIncrStats( 'pcache_miss_absent' );
|
2010-08-09 21:53:21 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$value = $this->mMemc->get( $parserOutputKey );
|
2011-03-07 19:13:19 +00:00
|
|
|
if ( self::try116cache && !$value && strpos( $value, '*' ) !== -1 ) {
|
|
|
|
|
wfDebug( "New format parser cache miss.\n" );
|
2011-09-20 15:58:01 +00:00
|
|
|
$parserOutputKey = $this->getParserOutputKey( $article,
|
|
|
|
|
$popts->optionsHash( ParserOptions::legacyOptions(), $article->getTitle() ) );
|
2011-03-07 19:13:19 +00:00
|
|
|
$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 ) {
|
2011-11-08 09:08:15 +00:00
|
|
|
wfDebug( "ParserOutput 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;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-08 09:08:15 +00:00
|
|
|
wfDebug( "ParserOutput cache found.\n" );
|
|
|
|
|
|
2012-10-10 18:13:40 +00:00
|
|
|
// The edit section preference may not be the appropiate one in
|
|
|
|
|
// the ParserOutput, as we are not storing it in the parsercache
|
2011-10-07 20:50:10 +00:00
|
|
|
// key. Force it here. See bug 31445.
|
|
|
|
|
$value->setEditSectionTokens( $popts->getEditSection() );
|
2010-09-12 19:26:01 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
if ( !$useOutdated && $value->expired( $touched ) ) {
|
|
|
|
|
wfIncrStats( "pcache_miss_expired" );
|
2010-08-10 14:11:51 +00:00
|
|
|
$cacheTime = $value->getCacheTime();
|
2010-08-09 21:53:21 +00:00
|
|
|
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 {
|
|
|
|
|
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
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
|
|
|
|
* @param $parserOutput ParserOutput
|
|
|
|
|
* @param $article Article
|
|
|
|
|
* @param $popts ParserOptions
|
|
|
|
|
*/
|
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
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $expire > 0 ) {
|
2006-05-13 17:40:59 +00:00
|
|
|
$now = wfTimestampNow();
|
2010-08-09 21:53:21 +00:00
|
|
|
|
2010-09-12 19:26:01 +00:00
|
|
|
$optionsKey = new CacheTime;
|
2010-12-26 19:21:45 +00:00
|
|
|
$optionsKey->mUsedOptions = $parserOutput->getUsedOptions();
|
2010-08-09 21:53:21 +00:00
|
|
|
$optionsKey->updateCacheExpiry( $expire );
|
2010-09-12 19:26:01 +00:00
|
|
|
|
2010-08-09 21:53:21 +00:00
|
|
|
$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() );
|
|
|
|
|
|
2011-04-15 22:58:00 +00:00
|
|
|
$parserOutputKey = $this->getParserOutputKey( $article,
|
2011-09-20 15:58:01 +00:00
|
|
|
$popts->optionsHash( $optionsKey->mUsedOptions, $article->getTitle() ) );
|
2010-08-09 21:53: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
|
2011-12-10 16:30:40 +00:00
|
|
|
$parserOutput->setTimestamp( $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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|