X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=0e8d5338442ed299f22ebfcc5de7a6236a887867;hb=3285ea4627979a52c3aa81ff42de3d483770c440;hp=1285ebcf5613be28d273274e59c9f4d02ce773c6;hpb=0332f4c59809e5a89f626e8969cd76261819f432;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 1285ebcf56..0e8d533844 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -1,55 +1,95 @@
mHeaders = $this->mCookies = $this->mMetatags =
$this->mKeywords = $this->mLinktags = array();
$this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
- $this->mLastSection = $this->mRedirect = $this->mLastModified =
- $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
- $this->mOnloadHandler = "";
+ $this->mRedirect = $this->mLastModified =
+ $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
+ $this->mOnloadHandler = '';
$this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
- $this->mSupressQuickbar = $this->mDTopen = $this->mPrintable = false;
+ $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;
+ $this->mScripts = '';
}
- function addHeader( $name, $val ) { array_push( $this->mHeaders, "$name: $val" ) ; }
+ 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 ) ); }
-
- # 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 )
- {
+ function addScript( $script ) { $this->mScripts .= $script; }
+ function getScript() { return $this->mScripts; }
+
+ 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;
+ $timestamp=wfTimestamp(TS_MW,$timestamp);
if( !$wgCachePages ) {
wfDebug( "CACHE DISABLED\n", false );
return;
@@ -59,23 +99,21 @@ class OutputPage {
wfDebug( "-- bad client, not caching\n", false );
return;
}
- if( $wgUser->getOption( "nocache" ) ) {
+ if( $wgUser->getOption( 'nocache' ) ) {
wfDebug( "USER DISABLED CACHE\n", false );
return;
}
-
- $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
- max( $timestamp, $wgUser->mTouched ) ) ) . " GMT";
-
- if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
+
+ $lastmod = gmdate( 'D, j M Y H:i:s', wfTimestamp(TS_UNIX, 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().
$modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
- $ismodsince = wfUnix2Timestamp( strtotime( $modsince ) );
+ $ismodsince = wfTimestamp( TS_MW, strtotime( $modsince ) );
wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
- wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
-
+ wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
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" );
@@ -94,171 +132,184 @@ class OutputPage {
}
}
+ function getPageTitleActionText () {
+ global $action;
+ switch($action) {
+ case 'edit':
+ return wfMsg('edit');
+ case 'history':
+ return wfMsg('history_short');
+ case 'protect':
+ return wfMsg('protect');
+ 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');
+ case 'info':
+ return wfMsg('info_short');
+ 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, $wgContLang;
+ $name = $wgContLang->autoConvert($name);
+ $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 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 )
- {
+ function setArticleRelated( $v ) {
$this->mIsArticleRelated = $v;
if ( !$v ) {
$this->mIsarticle = false;
}
}
- function setArticleFlag( $v ) {
- $this->mIsarticle = $v;
+ function setArticleFlag( $v ) {
+ $this->mIsarticle = $v;
if ( $v ) {
$this->mIsArticleRelated = $v;
}
}
- function isArticleRelated()
- {
- return $this->mIsArticleRelated;
+ function isArticleRelated() { return $this->mIsArticleRelated; }
+
+ function getLanguageLinks() { return $this->mLanguageLinks; }
+ function addLanguageLinks($newLinkArray) {
+ $this->mLanguageLinks += $newLinkArray;
}
-
- function getLanguageLinks() {
- global $wgTitle, $wgLanguageCode;
- global $wgDBconnection, $wgDBname;
- return $this->mLanguageLinks;
+ function setLanguageLinks($newLinkArray) {
+ $this->mLanguageLinks = $newLinkArray;
}
- function supressQuickbar() { $this->mSupressQuickbar = true; }
- function isQuickbarSupressed() { return $this->mSupressQuickbar; }
+
+ function getCategoryLinks() {
+ return $this->mCategoryLinks;
+ }
+ function addCategoryLinks($newLinkArray) {
+ $this->mCategoryLinks += $newLinkArray;
+ }
+ function setCategoryLinks($newLinkArray) {
+ $this->mCategoryLinks += $newLinkArray;
+ }
+
+ function suppressQuickbar() { $this->mSuppressQuickbar = true; }
+ function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
function addHTML( $text ) { $this->mBodytext .= $text; }
- function addHeadtext( $text ) { $this->mHeadtext .= $text; }
+ function clearHTML() { $this->mBodytext = ''; }
function debug( $text ) { $this->mDebugtext .= $text; }
- # First pass--just handle Location: $url " . wfMsg( $msg ) . "\n" );
+ $this->mBodytext = '';
+ $this->addHTML( ' ' . wfMsg( $msg ) . "". wfEscapeHTMLTagsOnly($q[0]). "
\n";
- $stripped3 .= $unique3 . $presecs . "s";
- $stripped2 = $q[1];
- }
+ $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
+ if ($wgUseTidy) {
+ $text = Parser::tidy($text);
}
+ $this->mLanguageLinks += $parserOutput->getLanguageLinks();
+ $this->mCategoryLinks += $parserOutput->getCategoryLinks();
+ $this->addHTML( $parserOutput->getText() );
+ }
- $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 );
- }
+ /**
+ * Add wikitext to the buffer, assuming that this is the primary text for a page view
+ * Saves the text into the parser cache if possible
+ */
+ function addPrimaryWikiText( $text, $cacheArticle ) {
+ global $wgParser, $wgParserCache, $wgUser, $wgTitle, $wgUseTidy;
- for ( $i = 1; $i <= $mathsecs; ++$i ) {
- $text = preg_replace( "/{$unique2}{$i}s/", str_replace( $specialChars,
- $escapedChars, $mathlist[$i] ), $text );
- }
+ $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, true );
- for ( $i = 1; $i <= $nwsecs; ++$i ) {
- $text = preg_replace( "/{$unique}{$i}s/", str_replace( $specialChars,
- $escapedChars, $nwlist[$i] ), $text );
+ # Replace link holders
+ $text = $parserOutput->getText();
+ $this->replaceLinkHolders( $text );
+ if ($wgUseTidy) {
+ $text = Parser::tidy($text);
}
+ $parserOutput->setText( $text );
+
+ if ( $cacheArticle ) {
+ $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
+ }
+
+ $this->mLanguageLinks += $parserOutput->getLanguageLinks();
+ $this->mCategoryLinks += $parserOutput->getCategoryLinks();
$this->addHTML( $text );
+ }
- if($use_parser_cache ){
- $this->saveParserCache( $text );
+ /**
+ * @param $article
+ * @param $user
+ */
+ function tryParserCache( $article, $user ) {
+ global $wgParserCache;
+ $parserOutput = $wgParserCache->get( $article, $user );
+ if ( $parserOutput !== false ) {
+ $this->mLanguageLinks += $parserOutput->getLanguageLinks();
+ $this->mCategoryLinks += $parserOutput->getCategoryLinks();
+ $this->addHTML( $parserOutput->getText() );
+ return true;
+ } else {
+ return false;
}
- wfProfileOut( $fname );
}
- # Set the maximum cache time on the Squid in seconds
+ /**
+ * Set the maximum cache time on the Squid in seconds
+ * @param $maxage
+ */
function setSquidMaxage( $maxage ) {
- global $wgSquidMaxage;
- $wgSquidMaxage = $maxage;
+ $this->mSquidMaxage = $maxage;
}
-
+
+ /**
+ * Use enableClientCache(false) to force it to send nocache headers
+ * @param $state
+ */
+ function enableClientCache( $state ) {
+ return wfSetVar( $this->mEnableClientCache, $state );
+ }
+
function sendCacheControl() {
- global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
+ global $wgUseSquid, $wgUseESI;
# FIXME: This header may cause trouble with some versions of Internet Explorer
- header( "Vary: Accept-Encoding, Cookie" );
- if( $this->mLastModified != "" ) {
- if( $wgUseSquid && ! isset( $_COOKIE[ini_get( "session.name") ] ) &&
- ! $this->isPrintable() )
+ header( 'Vary: Accept-Encoding, Cookie' );
+ if( $this->mEnableClientCache ) {
+ if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
+ ! $this->isPrintable() && $this->mSquidMaxage != 0 )
{
if ( $wgUseESI ) {
# We'll purge the proxy cache explicitly, but require end user agents
@@ -267,17 +318,17 @@ class OutputPage {
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.'+'.$wgSquidMaxage.', 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
+ # 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='.$wgSquidMaxage.', 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
@@ -286,76 +337,101 @@ class OutputPage {
header( "Expires: -1" );
header( "Cache-Control: private, must-revalidate, max-age=0" );
}
- header( "Last-modified: {$this->mLastModified}" );
+ if($this->mLastModified) header( "Last-modified: {$this->mLastModified}" );
} else {
wfDebug( "** no caching **\n", false );
- header( "Expires: -1" );
- header( "Cache-Control: no-cache" );
- header( "Pragma: no-cache" );
- header( "Last-modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
+
+ # 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' );
}
}
-
- # Finally, all the text has been munged and accumulated into
- # the object, let's actually output it:
- #
- function output()
- {
+
+ /**
+ * Finally, all the text has been munged and accumulated into
+ * the object, let's actually output it:
+ */
+ function output() {
global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
- global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
+ global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
+ global $wgDebugRedirects, $wgMimeType, $wgProfiler;
+
if( $this->mDoNothing ){
return;
}
- $fname = "OutputPage::output";
+ $fname = 'OutputPage::output';
wfProfileIn( $fname );
-
$sk = $wgUser->getSkin();
- $this->sendCacheControl();
-
- header( "Content-type: text/html; charset={$wgOutputEncoding}" );
- header( "Content-language: {$wgLanguageCode}" );
-
- if ( "" != $this->mRedirect ) {
- if( substr( $this->mRedirect, 0, 4 ) != "http" ) {
+ if ( '' != $this->mRedirect ) {
+ if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
# Standards require redirect URLs to be absolute
global $wgServer;
$this->mRedirect = $wgServer . $this->mRedirect;
}
- header( "Location: {$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