var $mOut, $mTitle;
var $mStyleName = 'monobook';
var $mCompiling = false;
+ var $mFunctionCache = array();
/******************************************************
* General functions *
global $wgDBname, $wgMemc, $wgRequest, $wgUser, $parserMemc;
$fname = 'SkinMonoBookCBT::getCompiledTemplate';
+ $expiry = 3600;
+
// Sandbox template execution
if ( $this->mCompiling ) {
return;
$cacheKey = "$wgDBname:monobookcbt:$type:" . $wgUser->getId();
$recompile = $wgRequest->getVal( 'recompile' );
- if ( !$recompile ) {
+ if ( $recompile == 'user' ) {
+ $recompileUser = true;
+ $recompileGeneric = false;
+ } elseif ( $recompile ) {
+ $recompileUser = true;
+ $recompileGeneric = true;
+ } else {
+ $recompileUser = false;
+ $recompileGeneric = false;
+ }
+
+ if ( !$recompileUser ) {
$php = $parserMemc->get( $cacheKey );
}
- if ( $recompile || !$php ) {
- $template = file_get_contents( $sourceFile );
+ if ( $recompileUser || !$php ) {
+ if ( $wgUser->isLoggedIn() ) {
+ // Perform staged compilation
+ // First compile a generic template for all logged-in users
+ $genericKey = "$wgDBname:monobookcbt:$type:loggedin";
+ if ( !$recompileGeneric ) {
+ $template = $parserMemc->get( $genericKey );
+ }
+ if ( $recompileGeneric || !$template ) {
+ $template = file_get_contents( $sourceFile );
+ $ignore = array( 'loggedin', '!loggedin dynamic' );
+ if ( $type == 'view' ) {
+ $ignore[] = 'nonview dynamic';
+ }
+ $template = $this->compileTemplate( $template, $ignore );
+ $parserMemc->set( $genericKey, $template, $expiry );
+ }
+ } else {
+ $template = file_get_contents( $sourceFile );
+ }
$ignore = array( 'lang', 'loggedin', 'user' );
if ( $wgUser->isLoggedIn() ) {
if ( $type == 'view' ) {
$ignore[] = 'nonview dynamic';
}
- $tp = new CBTProcessor( $template, $this, $ignore );
- $this->mCompiling = true;
- $compiled = $tp->compile();
- $this->mCompiling = false;
- if ( $tp->getLastError() ) {
- // If there was a compile error, don't save the template
- // Instead just print the error and exit
- echo $compiled;
- wfErrorExit();
- }
+ $compiled = $this->compileTemplate( $template, $ignore );
// Reduce whitespace
// This is done here instead of in CBTProcessor because we can be
}
$php = $compiler->generatePHP( '$this' );
- $parserMemc->set( $cacheKey, $php, 3600 );
+ $parserMemc->set( $cacheKey, $php, $expiry );
}
wfProfileOut( $fname );
return $php;
}
+ function compileTemplate( $template, $ignore ) {
+ $tp = new CBTProcessor( $template, $this, $ignore );
+ $tp->mFunctionCache = $this->mFunctionCache;
+
+ $this->mCompiling = true;
+ $compiled = $tp->compile();
+ $this->mCompiling = false;
+
+ if ( $tp->getLastError() ) {
+ // If there was a compile error, don't save the template
+ // Instead just print the error and exit
+ echo $compiled;
+ wfErrorExit();
+ }
+ $this->mFunctionCache = $tp->mFunctionCache;
+ return $compiled;
+ }
+
function executeTemplate( $template ) {
$fname = 'SkinMonoBookCBT::executeTemplate';
wfProfileIn( $fname );
$tp = new CBTProcessor( $template, $this );
+ $tp->mFunctionCache = $this->mFunctionCache;
+
$this->mCompiling = true;
$text = $tp->execute();
$this->mCompiling = false;
+
+ $this->mFunctionCache = $tp->mFunctionCache;
wfProfileOut( $fname );
return $text;
}
}
function catlinks() {
- return cbt_value( $this->getCategories(), 'dynamic' );
+ if ( !isset( $this->mCatlinks ) ) {
+ $this->mCatlinks = $this->getCategories();
+ }
+ return cbt_value( $this->mCatlinks, 'dynamic' );
}
function extratabs( $itemTemplate ) {
global $wgMaxCredits;
if ( $wgMaxCredits ) return '';
- if ( $this->isCurrentArticleView() ) {
- $s = $this->lastModified();
- } else {
- $s = '';
+ if ( !isset( $this->mLastmod ) ) {
+ if ( $this->isCurrentArticleView() ) {
+ $this->mLastmod = $this->lastModified();
+ } else {
+ $this->mLastmod = '';
+ }
}
- return cbt_value( $s, 'dynamic' );
+ return cbt_value( $this->mLastmod, 'dynamic' );
}
function viewcount() {