return;
}
- if ( !isset( $oldid ) ) {
- if( $this->checkTouched() ) {
- $wgOut->checkLastModified( $this->mTouched );
- $this->tryFileCache();
+ if ( !isset( $oldid ) and $this->checkTouched() ) {
+ if( $wgOut->checkLastModified( $this->mTouched ) ){
+ return;
+ } else if ( $this->tryFileCache() ) {
+ # tell wgOut that output is taken care of
+ $wgOut->disable();
+ return;
}
}
$s = wfMsg( "redirectedfrom", $redir );
$wgOut->setSubtitle( $s );
}
+
$wgLinkCache->preFill( $this->mTitle );
$wgOut->addWikiText( $text );
# If page hasn't changed, client can cache this
- $wgOut->checkLastModified( $this->getTimestamp() );
+ if( $wgOut->checkLastModified( $this->getTimestamp() ) ){
+ # Client cache fresh and headers sent, nothing more to do.
+ return;
+ }
$fname = "Article::history";
wfProfileIn( $fname );
}
/* Caching functions */
-
+
+ # checkLastModified returns true iff it has taken care of all
+ # output to the client that is necessary for this request.
+ # (that is, it has sent a cached version of the page)
function tryFileCache() {
static $called = false;
if( $called ) {
global $wgOut;
wfDebug( " tryFileCache() - about to load\n" );
$cache->loadFromFileCache();
- $wgOut->reportTime(); # For profiling
- wfAbruptExit();
+ return true;
} else {
wfDebug( " tryFileCache() - starting buffer\n" );
if($cache->useGzip() && wfClientAcceptsGzip()) {
}
}
+function logProfilingData()
+{
+ global $wgRequestTime, $wgDebugLogFile;
+ global $wgProfiling, $wgProfileStack, $wgProfileLimit, $wgUser;
+ list( $usec, $sec ) = explode( " ", microtime() );
+ $now = (float)$sec + (float)$usec;
+
+ list( $usec, $sec ) = explode( " ", $wgRequestTime );
+ $start = (float)$sec + (float)$usec;
+ $elapsed = $now - $start;
+ if ( "" != $wgDebugLogFile ) {
+ $prof = wfGetProfilingOutput( $start, $elapsed );
+ if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
+ $forward = " forwarded for " . $_SERVER['HTTP_X_FORWARDED_FOR'];
+ if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) )
+ $forward .= " client IP " . $_SERVER['HTTP_CLIENT_IP'];
+ if( !empty( $_SERVER['HTTP_FROM'] ) )
+ $forward .= " from " . $_SERVER['HTTP_FROM'];
+ if( $forward )
+ $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
+ if($wgUser->getId() == 0)
+ $forward .= " anon";
+ $log = sprintf( "%s\t%04.3f\t%s\n",
+ gmdate( "YmdHis" ), $elapsed,
+ urldecode( $_SERVER['REQUEST_URI'] . $forward ) );
+ error_log( "TJOHEJ". $log . $prof, 3, $wgDebugLogFile );
+ }
+}
+
+
function wfReadOnly()
{
global $wgReadOnlyFile;
$wgAbruptExitCalled = true;
$bt = debug_backtrace();
- $file = $bt[0]["file"];
- $line = $bt[0]["line"];
- wfDebug("WARNING: Abrupt exit in $file at line $line\n");
+ for($i = 0; $i < count($bt) ; $i++){
+ $file = $bt[$i]["file"];
+ $line = $bt[$i]["line"];
+ wfDebug("WARNING: Abrupt exit in $file at line $line\n");
+ }
exit();
}
function showAsDisabledPage( $rawhtml = true )
{
global $wgLang, $wgOut;
- $wgOut->checkLastModified( $this->getTimestamp() );
+ if( $wgOut->checkLastModified( $this->getTimestamp() ) ){
+ # Client cache fresh and headers sent, nothing more to do.
+ return;
+ }
$func = ( $rawhtml ? "addHTML" : "addWikiText" );
$wgOut->$func(
"<p>" . wfMsg( "perfdisabled" ) . "</p>\n\n" .
var $mDTopen, $mLastSection; # Used for processing DL, PRE
var $mLanguageLinks, $mSupressQuickbar;
var $mOnloadHandler;
+ var $mDoNothing;
function OutputPage()
{
$this->mLanguageLinks = array();
$this->mCategoryLinks = array() ;
$this->mAutonumber = 0;
+ $this->mDoNothing = false;
}
function addHeader( $name, $val ) { array_push( $this->mHeaders, "$name: $val" ) ; }
function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
function addLink( $rel, $rev, $target ) { array_push( $this->mLinktags, array( $rel, $rev, $target ) ); }
+ # checkLastModified tells the client to use the client-cached page if
+ # possible. If sucessful, the OutputPage is disabled so that
+ # any future call to OutputPage->output() have no effect. The method
+ # returns true iff cache-ok headers was sent.
function checkLastModified ( $timestamp )
{
global $wgLang, $wgCachePages, $wgUser;
header( "Cache-Control: private, must-revalidate, max-age=0" );
header( "Last-Modified: {$lastmod}" );
wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
- $this->reportTime(); # For profiling
- wfAbruptExit();
+ $this->disable();
+ return true;
} else {
wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
$this->mLastModified = $lastmod;
function isPrintable() { return $this->mPrintable; }
function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
function getOnloadHandler() { return $this->mOnloadHandler; }
+ function disable() { $this->mDoNothing = true; }
function getLanguageLinks() {
global $wgTitle, $wgLanguageCode;
{
global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
-
+ if( $this->mDoNothing ){
+ return;
+ }
$fname = "OutputPage::output";
wfProfileIn( $fname );
$wgOutputEncoding = $wgInputEncoding;
}
+ # Returns a HTML comment with the elapsed time since request.
+ # This method has no side effects.
function reportTime()
{
- global $wgRequestTime, $wgDebugLogFile;
- global $wgProfiling, $wgProfileStack, $wgProfileLimit, $wgUser;
+ global $wgRequestTime;
list( $usec, $sec ) = explode( " ", microtime() );
$now = (float)$sec + (float)$usec;
list( $usec, $sec ) = explode( " ", $wgRequestTime );
$start = (float)$sec + (float)$usec;
$elapsed = $now - $start;
-
- if ( "" != $wgDebugLogFile ) {
- $prof = wfGetProfilingOutput( $start, $elapsed );
- if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
- $forward = " forwarded for " . $_SERVER['HTTP_X_FORWARDED_FOR'];
- if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) )
- $forward .= " client IP " . $_SERVER['HTTP_CLIENT_IP'];
- if( !empty( $_SERVER['HTTP_FROM'] ) )
- $forward .= " from " . $_SERVER['HTTP_FROM'];
- if( $forward )
- $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
- if($wgUser->getId() == 0)
- $forward .= " anon";
- $log = sprintf( "%s\t%04.3f\t%s\n",
- gmdate( "YmdHis" ), $elapsed,
- urldecode( $_SERVER['REQUEST_URI'] . $forward ) );
- error_log( $log . $prof, 3, $wgDebugLogFile );
- }
$com = sprintf( "<!-- Time since request: %01.2f secs. -->",
$elapsed );
return $com;
$sql = "SELECT MAX(rc_timestamp) AS lastmod FROM recentchanges";
$res = wfQuery( $sql, DB_READ, $fname );
$s = wfFetchObject( $res );
- $wgOut->checkLastModified( $s->lastmod );
+ if( $wgOut->checkLastModified( $s->lastmod ) ){
+ # Client cache fresh and headers sent, nothing more to do.
+ return;
+ }
$rctext = wfMsg( "recentchangestext" );
$wgOut->output();
foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
-
+logProfilingData();
+wfDebug( "Request ended normally\n" );
?>