X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=e859ed222996baa040b5f0ad366745e8f0f41c2b;hb=0fb5ad60b1104980f96073e25608729f0eb6eaf4;hp=cdd84c2dcaddd78817205208252b83cd659f3919;hpb=03022828cec84831a82d9ef147687b299b67268e;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index cdd84c2dca..e859ed2229 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -1,43 +1,67 @@
-
+mHeaders = $this->mCookies = $this->mMetatags =
$this->mKeywords = $this->mLinktags = array();
$this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
- $this->mLastSection = $this->mRedirect = $this->mLastModified =
+ $this->mRedirect = $this->mLastModified =
$this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
$this->mOnloadHandler = "";
- $this->mIsarticle = $this->mPrintable = true;
- $this->mSupressQuickbar = $this->mDTopen = $this->mPrintable = false;
+ $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
+ $this->mSuppressQuickbar = $this->mPrintable = false;
$this->mLanguageLinks = array();
- $this->mCategoryLinks = array() ;
- $this->mAutonumber = 0;
+ $this->mCategoryLinks = array() ;
+ $this->mDoNothing = false;
+ $this->mContainsOldMagic = $this->mContainsNewMagic = 0;
+ $this->mParserOptions = ParserOptions::newFromUser( $temp = NULL );
+ $this->mSquidMaxage = 0;
}
function addHeader( $name, $val ) { array_push( $this->mHeaders, "$name: $val" ) ; }
function addCookie( $name, $val ) { array_push( $this->mCookies, array( $name, $val ) ); }
- function redirect( $url ) { $this->mRedirect = $url; }
+ function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $url; $this->mRedirectCode = $responsecode; }
# To add an http-equiv meta tag, precede the name with "http:"
function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
- function addLink( $rel, $rev, $target ) { array_push( $this->mLinktags, array( $rel, $rev, $target ) ); }
+
+ function addLink( $linkarr ) {
+ # $linkarr should be an associative array of attributes. We'll escape on output.
+ array_push( $this->mLinktags, $linkarr );
+ }
+
+ function addMetadataLink( $linkarr ) {
+ # note: buggy CC software only reads first "meta" link
+ static $haveMeta = false;
+ $linkarr["rel"] = ($haveMeta) ? "alternate meta" : "meta";
+ $this->addLink( $linkarr );
+ $haveMeta = true;
+ }
+ # 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;
@@ -56,9 +80,9 @@ class OutputPage {
}
$lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
- max( $timestamp, $wgUser->mTouched ) ) ) . " GMT";
-
- if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
+ max( $timestamp, $wgUser->mTouched ) ) ) . " GMT";
+
+ if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
# IE sends sizes after the date like this:
# Wed, 20 Aug 2003 06:51:19 GMT; length=5202
# this breaks strtotime().
@@ -70,12 +94,11 @@ class OutputPage {
if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
# Make sure you're in a place you can leave when you call us!
header( "HTTP/1.0 304 Not Modified" );
- header( "Expires: Mon, 15 Jan 2001 00:00:00 GMT" ); # Cachers always validate the page!
- header( "Cache-Control: private, must-revalidate, max-age=0" );
- header( "Last-Modified: {$lastmod}" );
+ $this->mLastModified = $lastmod;
+ $this->sendCacheControl();
wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
- $this->reportTime(); # For profiling
- exit;
+ $this->disable();
+ return true;
} else {
wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
$this->mLastModified = $lastmod;
@@ -86,136 +109,173 @@ class OutputPage {
}
}
+ function getPageTitleActionText () {
+ global $action;
+ switch($action) {
+ case 'edit':
+ return wfMsg('edit');
+ case 'history':
+ return wfMsg('history_short');
+ case 'protect':
+ return wfMsg('unprotect');
+ case 'unprotect':
+ return wfMsg('unprotect');
+ case 'delete':
+ return wfMsg('delete');
+ case 'watch':
+ return wfMsg('watch');
+ case 'unwatch':
+ return wfMsg('unwatch');
+ case 'submit':
+ return wfMsg('preview');
+ default:
+ return '';
+ }
+ }
function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
- function setHTMLtitle( $name ) { $this->mHTMLtitle = $name; }
- function setPageTitle( $name ) { $this->mPagetitle = $name; }
+ function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
+ function setPageTitle( $name ) {
+ global $action;
+ $this->mPagetitle = $name;
+ if(!empty($action)) {
+ $taction = $this->getPageTitleActionText();
+ if( !empty( $taction ) ) {
+ $name .= " - $taction";
+ }
+ }
+ $this->setHTMLTitle( $name . " - " . wfMsg( "wikititlesuffix" ) );
+ }
+ function getHTMLTitle() { return $this->mHTMLtitle; }
function getPageTitle() { return $this->mPagetitle; }
function setSubtitle( $str ) { $this->mSubtitle = $str; }
function getSubtitle() { return $this->mSubtitle; }
- function setArticleFlag( $v ) { $this->mIsarticle = $v; }
function isArticle() { return $this->mIsarticle; }
function setPrintable() { $this->mPrintable = true; }
function isPrintable() { return $this->mPrintable; }
+ function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
+ function isSyndicated() { return $this->mShowFeedLinks; }
function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
function getOnloadHandler() { return $this->mOnloadHandler; }
+ function disable() { $this->mDoNothing = true; }
+ function setArticleRelated( $v )
+ {
+ $this->mIsArticleRelated = $v;
+ if ( !$v ) {
+ $this->mIsarticle = false;
+ }
+ }
+ function setArticleFlag( $v ) {
+ $this->mIsarticle = $v;
+ if ( $v ) {
+ $this->mIsArticleRelated = $v;
+ }
+ }
+
+ function isArticleRelated()
+ {
+ return $this->mIsArticleRelated;
+ }
+
function getLanguageLinks() {
global $wgTitle, $wgLanguageCode;
global $wgDBconnection, $wgDBname;
return $this->mLanguageLinks;
}
- function supressQuickbar() { $this->mSupressQuickbar = true; }
- function isQuickbarSupressed() { return $this->mSupressQuickbar; }
+ function suppressQuickbar() { $this->mSuppressQuickbar = true; }
+ function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
function addHTML( $text ) { $this->mBodytext .= $text; }
function addHeadtext( $text ) { $this->mHeadtext .= $text; }
function debug( $text ) { $this->mDebugtext .= $text; }
+ function setParserOptions( $options )
+ {
+ return wfSetVar( $this->mParserOptions, $options );
+ }
+
# First pass--just handle Location: $url " . wfMsg( $msg ) . "\n" );
+ $this->addHTML( " " . wfMsg( $msg ) . "". wfEscapeHTMLTagsOnly($q[0]). "
";
- $stripped3 .= $unique3 . $presecs . "s";
- $stripped2 = $q[1];
+ if ( $parserOutput === false ) {
+ $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
+ if ( $cacheArticle ) {
+ $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
}
}
-
- $text = $this->doWikiPass2( $stripped3, $linestart );
- $specialChars = array("\\", "$");
- $escapedChars = array("\\\\", "\\$");
- for ( $i = 1; $i <= $presecs; ++$i ) {
- $text = preg_replace( "/{$unique3}{$i}s/", str_replace( $specialChars,
- $escapedChars, $prelist[$i] ), $text );
- }
-
- for ( $i = 1; $i <= $mathsecs; ++$i ) {
- $text = preg_replace( "/{$unique2}{$i}s/", str_replace( $specialChars,
- $escapedChars, $mathlist[$i] ), $text );
- }
-
- for ( $i = 1; $i <= $nwsecs; ++$i ) {
- $text = preg_replace( "/{$unique}{$i}s/", str_replace( $specialChars,
- $escapedChars, $nwlist[$i] ), $text );
- }
- $this->addHTML( $text );
- wfProfileOut( $fname );
+ $this->mLanguageLinks += $parserOutput->getLanguageLinks();
+ $this->mCategoryLinks += $parserOutput->getCategoryLinks();
+
+ $this->addHTML( $parserOutput->getText() );
+
}
+ # Set the maximum cache time on the Squid in seconds
+ function setSquidMaxage( $maxage ) {
+ $this->mSquidMaxage = $maxage;
+ }
+
+ # Use enableClientCache(false) to force it to send nocache headers
+ function enableClientCache( $state ) {
+ return wfSetVar( $this->mEnableClientCache, $state );
+ }
+
function sendCacheControl() {
- global $wgUseGzip;
- if( $this->mLastModified != "" ) {
- wfDebug( "** private caching; {$this->mLastModified} **\n", false );
- header( "Cache-Control: private, must-revalidate, max-age=0" );
- header( "Last-modified: {$this->mLastModified}" );
- if( $wgUseGzip ) {
- # We should put in Accept-Encoding, but IE chokes on anything but
- # User-Agent in a Vary: header (at least through 6.0)
- header( "Vary: User-Agent" );
+ global $wgUseSquid, $wgUseESI;
+ # FIXME: This header may cause trouble with some versions of Internet Explorer
+ header( "Vary: Accept-Encoding, Cookie" );
+ if( $this->mEnableClientCache && $this->mLastModified != "" ) {
+ if( $wgUseSquid && ! isset( $_COOKIE[ini_get( "session.name") ] ) &&
+ ! $this->isPrintable() )
+ {
+ if ( $wgUseESI ) {
+ # We'll purge the proxy cache explicitly, but require end user agents
+ # to revalidate against the proxy on each visit.
+ # Surrogate-Control controls our Squid, Cache-Control downstream caches
+ wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
+ # start with a shorter timeout for initial testing
+ # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
+ header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
+ header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
+ } else {
+ # We'll purge the proxy cache for anons explicitly, but require end user agents
+ # to revalidate against the proxy on each visit.
+ # IMPORTANT! The Squid needs to replace the Cache-Control header with
+ # Cache-Control: s-maxage=0, must-revalidate, max-age=0
+ wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
+ # start with a shorter timeout for initial testing
+ # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
+ header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
+ }
+ } else {
+ # We do want clients to cache if they can, but they *must* check for updates
+ # on revisiting the page.
+ wfDebug( "** private caching; {$this->mLastModified} **\n", false );
+ header( "Expires: -1" );
+ header( "Cache-Control: private, must-revalidate, max-age=0" );
}
+ header( "Last-modified: {$this->mLastModified}" );
} else {
wfDebug( "** no caching **\n", false );
- header( "Cache-Control: no-cache" ); # Experimental - see below
+
+ # In general, the absence of a last modified header should be enough to prevent
+ # the client from using its cache. We send a few other things just to make sure.
+ header( "Expires: -1" );
+ header( "Cache-Control: no-cache, no-store, max-age=0, must-revalidate" );
header( "Pragma: no-cache" );
- header( "Last-modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
}
- header( "Expires: Mon, 15 Jan 2001 00:00:00 GMT" ); # Cachers always validate the page!
}
# Finally, all the text has been munged and accumulated into
@@ -225,29 +285,54 @@ class OutputPage {
{
global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
-
+ global $wgDebugRedirects, $wgMimeType;
+ if( $this->mDoNothing ){
+ return;
+ }
$fname = "OutputPage::output";
wfProfileIn( $fname );
$sk = $wgUser->getSkin();
- $this->sendCacheControl();
-
- header( "Content-type: text/html; charset={$wgOutputEncoding}" );
- header( "Content-language: {$wgLanguageCode}" );
-
if ( "" != $this->mRedirect ) {
- header( "Location: {$this->mRedirect}" );
+ if( substr( $this->mRedirect, 0, 4 ) != "http" ) {
+ # Standards require redirect URLs to be absolute
+ global $wgServer;
+ $this->mRedirect = $wgServer . $this->mRedirect;
+ }
+ if( $this->mRedirectCode == '301') {
+ if( !$wgDebugRedirects ) {
+ header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
+ }
+ $this->mLastModified = gmdate( "D, j M Y H:i:s" ) . " GMT";
+ }
+
+ $this->sendCacheControl();
+
+ if( $wgDebugRedirects ) {
+ $url = htmlspecialchars( $this->mRedirect );
+ print "\n\n