4 if($wgUseTeX) include_once( "Math.php" );
7 var $mHeaders, $mCookies, $mMetatags, $mKeywords;
8 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
9 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
10 var $mSubtitle, $mRedirect, $mHeadtext;
11 var $mLastModified, $mCategoryLinks;
13 var $mSuppressQuickbar;
16 var $mContainsOldMagic, $mContainsNewMagic;
17 var $mIsArticleRelated;
19 var $mShowFeedLinks = false;
20 var $mEnableClientCache = true;
24 $this->mHeaders
= $this->mCookies
= $this->mMetatags
=
25 $this->mKeywords
= $this->mLinktags
= array();
26 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
27 $this->mRedirect
= $this->mLastModified
=
28 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
29 $this->mOnloadHandler
= "";
30 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
31 $this->mSuppressQuickbar
= $this->mPrintable
= false;
32 $this->mLanguageLinks
= array();
33 $this->mCategoryLinks
= array() ;
34 $this->mDoNothing
= false;
35 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
36 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
37 $this->mSquidMaxage
= 0;
40 function addHeader( $name, $val ) { array_push( $this->mHeaders
, "$name: $val" ) ; }
41 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
42 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
44 # To add an http-equiv meta tag, precede the name with "http:"
45 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
46 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
47 function addLink( $rel, $rev, $target, $type="", $media="" ) { array_push( $this->mLinktags
, array( $rel, $rev, $target, $type, $media ) ); }
49 # checkLastModified tells the client to use the client-cached page if
50 # possible. If sucessful, the OutputPage is disabled so that
51 # any future call to OutputPage->output() have no effect. The method
52 # returns true iff cache-ok headers was sent.
53 function checkLastModified ( $timestamp )
55 global $wgLang, $wgCachePages, $wgUser;
56 if( !$wgCachePages ) {
57 wfDebug( "CACHE DISABLED\n", false );
60 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
61 # IE 5.0 has probs with our caching
62 wfDebug( "-- bad client, not caching\n", false );
65 if( $wgUser->getOption( "nocache" ) ) {
66 wfDebug( "USER DISABLED CACHE\n", false );
70 $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
71 max( $timestamp, $wgUser->mTouched
) ) ) . " GMT";
73 if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
74 # IE sends sizes after the date like this:
75 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
76 # this breaks strtotime().
77 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
78 $ismodsince = wfUnix2Timestamp( strtotime( $modsince ) );
79 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
80 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
82 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
83 # Make sure you're in a place you can leave when you call us!
84 header( "HTTP/1.0 304 Not Modified" );
85 $this->mLastModified
= $lastmod;
86 $this->sendCacheControl();
87 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
91 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
92 $this->mLastModified
= $lastmod;
95 wfDebug( "We're confused.\n", false );
96 $this->mLastModified
= $lastmod;
100 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
101 function setHTMLtitle( $name ) { $this->mHTMLtitle
= $name; }
102 function setPageTitle( $name ) { $this->mPagetitle
= $name; }
103 function getPageTitle() { return $this->mPagetitle
; }
104 function setSubtitle( $str ) { $this->mSubtitle
= $str; }
105 function getSubtitle() { return $this->mSubtitle
; }
106 function isArticle() { return $this->mIsarticle
; }
107 function setPrintable() { $this->mPrintable
= true; }
108 function isPrintable() { return $this->mPrintable
; }
109 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
110 function isSyndicated() { return $this->mShowFeedLinks
; }
111 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
112 function getOnloadHandler() { return $this->mOnloadHandler
; }
113 function disable() { $this->mDoNothing
= true; }
115 function setArticleRelated( $v )
117 $this->mIsArticleRelated
= $v;
119 $this->mIsarticle
= false;
122 function setArticleFlag( $v ) {
123 $this->mIsarticle
= $v;
125 $this->mIsArticleRelated
= $v;
129 function isArticleRelated()
131 return $this->mIsArticleRelated
;
134 function getLanguageLinks() {
135 global $wgTitle, $wgLanguageCode;
136 global $wgDBconnection, $wgDBname;
137 return $this->mLanguageLinks
;
139 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
140 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
142 function addHTML( $text ) { $this->mBodytext
.= $text; }
143 function addHeadtext( $text ) { $this->mHeadtext
.= $text; }
144 function debug( $text ) { $this->mDebugtext
.= $text; }
146 function setParserOptions( $options )
148 return wfSetVar( $this->mParserOptions
, $options );
151 # First pass--just handle <nowiki> sections, pass the rest off
152 # to doWikiPass2() which does all the real work.
154 # $cacheArticle - assume this text is the main text for the given article
156 function addWikiText( $text, $linestart = true, $cacheArticle = NULL )
158 global $wgParser, $wgParserCache, $wgUser, $wgTitle;
160 $parserOutput = false;
161 if ( $cacheArticle ) {
162 $parserOutput = $wgParserCache->get( $cacheArticle, $wgUser );
165 if ( $parserOutput === false ) {
166 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
167 if ( $cacheArticle ) {
168 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
172 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
173 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
175 $this->addHTML( $parserOutput->getText() );
179 # Set the maximum cache time on the Squid in seconds
180 function setSquidMaxage( $maxage ) {
181 $this->mSquidMaxage
= $maxage;
184 # Use enableClientCache(false) to force it to send nocache headers
185 function enableClientCache( $state ) {
186 return wfSetVar( $this->mEnableClientCache
, $state );
189 function sendCacheControl() {
190 global $wgUseSquid, $wgUseESI;
191 # FIXME: This header may cause trouble with some versions of Internet Explorer
192 header( "Vary: Accept-Encoding, Cookie" );
193 if( $this->mEnableClientCache
&& $this->mLastModified
!= "" ) {
194 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( "session.name") ] ) &&
195 ! $this->isPrintable() )
198 # We'll purge the proxy cache explicitly, but require end user agents
199 # to revalidate against the proxy on each visit.
200 # Surrogate-Control controls our Squid, Cache-Control downstream caches
201 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
202 # start with a shorter timeout for initial testing
203 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
204 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
205 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
207 # We'll purge the proxy cache for anons explicitly, but require end user agents
208 # to revalidate against the proxy on each visit.
209 # IMPORTANT! The Squid needs to replace the Cache-Control header with
210 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
211 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
212 # start with a shorter timeout for initial testing
213 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
214 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
217 # We do want clients to cache if they can, but they *must* check for updates
218 # on revisiting the page.
219 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
220 header( "Expires: -1" );
221 header( "Cache-Control: private, must-revalidate, max-age=0" );
223 header( "Last-modified: {$this->mLastModified}" );
225 wfDebug( "** no caching **\n", false );
227 # In general, the absence of a last modified header should be enough to prevent
228 # the client from using its cache. We send a few other things just to make sure.
229 header( "Expires: -1" );
230 header( "Cache-Control: no-cache, no-store, max-age=0, must-revalidate" );
231 header( "Pragma: no-cache" );
235 # Finally, all the text has been munged and accumulated into
236 # the object, let's actually output it:
240 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
241 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
242 global $wgDebugRedirects;
243 if( $this->mDoNothing
){
246 $fname = "OutputPage::output";
247 wfProfileIn( $fname );
249 $sk = $wgUser->getSkin();
251 if ( "" != $this->mRedirect
) {
252 if( substr( $this->mRedirect
, 0, 4 ) != "http" ) {
253 # Standards require redirect URLs to be absolute
255 $this->mRedirect
= $wgServer . $this->mRedirect
;
257 if( $this->mRedirectCode
== '301') {
258 if( !$wgDebugRedirects ) {
259 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
261 $this->mLastModified
= gmdate( "D, j M Y H:i:s" ) . " GMT";
264 $this->sendCacheControl();
266 if( $wgDebugRedirects ) {
267 $url = htmlspecialchars( $this->mRedirect
);
268 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
269 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
270 print "</body>\n</html>\n";
272 header( "Location: {$this->mRedirect}" );
278 $this->sendCacheControl();
280 header( "Content-type: text/html; charset={$wgOutputEncoding}" );
281 header( "Content-language: {$wgLanguageCode}" );
283 $exp = time() +
$wgCookieExpiration;
284 foreach( $this->mCookies
as $name => $val ) {
285 setcookie( $name, $val, $exp, "/" );
288 $sk->outputPage( $this );
294 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
295 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
298 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
299 if ( false === $outs ) { $outs = $ins; }
304 function setEncodings()
306 global $wgInputEncoding, $wgOutputEncoding;
307 global $wgUser, $wgLang;
309 $wgInputEncoding = strtolower( $wgInputEncoding );
311 if( $wgUser->getOption( 'altencoding' ) ) {
312 $wgLang->setAltEncoding();
316 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
317 $wgOutputEncoding = strtolower( $wgOutputEncoding );
322 # This code is unused anyway!
323 # Commenting out. --bv 2003-11-15
325 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
329 foreach ( $a as $s ) {
330 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
342 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
343 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
344 $wgOutputEncoding = strtolower( $bestset );
349 $wgOutputEncoding = $wgInputEncoding;
352 # Returns a HTML comment with the elapsed time since request.
353 # This method has no side effects.
354 function reportTime()
356 global $wgRequestTime;
359 list( $usec, $sec ) = explode( " ", $wgRequestTime );
360 $start = (float)$sec +
(float)$usec;
361 $elapsed = $now - $start;
362 $com = sprintf( "<!-- Time since request: %01.2f secs. -->",
367 # Note: these arguments are keys into wfMsg(), not text!
369 function errorpage( $title, $msg )
373 $this->mDebugtext
.= "Original title: " .
374 $wgTitle->getPrefixedText() . "\n";
375 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
376 $this->setPageTitle( wfMsg( $title ) );
377 $this->setRobotpolicy( "noindex,nofollow" );
378 $this->setArticleRelated( false );
379 $this->enableClientCache( false );
381 $this->mBodytext
= "";
382 $this->addHTML( "<p>" . wfMsg( $msg ) . "\n" );
383 $this->returnToMain( false );
389 function sysopRequired()
393 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
394 $this->setPageTitle( wfMsg( "sysoptitle" ) );
395 $this->setRobotpolicy( "noindex,nofollow" );
396 $this->setArticleRelated( false );
397 $this->mBodytext
= "";
399 $sk = $wgUser->getSkin();
400 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
401 $this->addHTML( wfMsg( "sysoptext", $ap ) );
402 $this->returnToMain();
405 function developerRequired()
409 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
410 $this->setPageTitle( wfMsg( "developertitle" ) );
411 $this->setRobotpolicy( "noindex,nofollow" );
412 $this->setArticleRelated( false );
413 $this->mBodytext
= "";
415 $sk = $wgUser->getSkin();
416 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
417 $this->addHTML( wfMsg( "developertext", $ap ) );
418 $this->returnToMain();
421 function loginToUse()
423 global $wgUser, $wgTitle, $wgLang;
425 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
426 $this->setPageTitle( wfMsg( "loginreqtitle" ) );
427 $this->setRobotpolicy( "noindex,nofollow" );
428 $this->setArticleFlag( false );
429 $this->mBodytext
= "";
430 $this->addWikiText( wfMsg( "loginreqtext" ) );
432 # We put a comment in the .html file so a Sysop can diagnose the page the
434 $this->addHTML( "\n<!--" .
435 $wgLang->getNsText( $wgTitle->getNamespace() ) .
437 $wgTitle->getDBkey() . "-->" );
438 $this->returnToMain(); # Flip back to the main page after 10 seconds.
441 function databaseError( $fname, &$conn )
443 global $wgUser, $wgCommandLineMode;
445 $this->setPageTitle( wfMsgNoDB( "databaseerror" ) );
446 $this->setRobotpolicy( "noindex,nofollow" );
447 $this->setArticleRelated( false );
448 $this->enableClientCache( false );
450 if ( $wgCommandLineMode ) {
451 $msg = wfMsgNoDB( "dberrortextcl" );
453 $msg = wfMsgNoDB( "dberrortext" );
456 $msg = str_replace( "$1", htmlspecialchars( $conn->lastQuery() ), $msg );
457 $msg = str_replace( "$2", htmlspecialchars( $fname ), $msg );
458 $msg = str_replace( "$3", $conn->lastErrno(), $msg );
459 $msg = str_replace( "$4", htmlspecialchars( $conn->lastError() ), $msg );
461 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
465 $sk = $wgUser->getSkin();
466 $shlink = $sk->makeKnownLink( wfMsgNoDB( "searchhelppage" ),
467 wfMsgNoDB( "searchingwikipedia" ) );
468 $msg = str_replace( "$5", $shlink, $msg );
469 $this->mBodytext
= $msg;
474 function readOnlyPage( $source = "", $protected = false )
476 global $wgUser, $wgReadOnlyFile;
478 $this->setRobotpolicy( "noindex,nofollow" );
479 $this->setArticleRelated( false );
482 $this->setPageTitle( wfMsg( "viewsource" ) );
483 $this->addWikiText( wfMsg( "protectedtext" ) );
485 $this->setPageTitle( wfMsg( "readonly" ) );
486 $reason = file_get_contents( $wgReadOnlyFile );
487 $this->addHTML( wfMsg( "readonlytext", $reason ) );
491 $rows = $wgUser->getOption( "rows" );
492 $cols = $wgUser->getOption( "cols" );
493 $text .= "</p>\n<textarea cols='$cols' rows='$rows' readonly>" .
494 htmlspecialchars( $source ) . "\n</textarea>";
495 $this->addHTML( $text );
498 $this->returnToMain( false );
501 function fatalError( $message )
503 $this->setPageTitle( wfMsg( "internalerror" ) );
504 $this->setRobotpolicy( "noindex,nofollow" );
505 $this->setArticleRelated( false );
506 $this->enableClientCache( false );
508 $this->mBodytext
= $message;
513 function unexpectedValueError( $name, $val )
515 $this->fatalError( wfMsg( "unexpected", $name, $val ) );
518 function fileCopyError( $old, $new )
520 $this->fatalError( wfMsg( "filecopyerror", $old, $new ) );
523 function fileRenameError( $old, $new )
525 $this->fatalError( wfMsg( "filerenameerror", $old, $new ) );
528 function fileDeleteError( $name )
530 $this->fatalError( wfMsg( "filedeleteerror", $name ) );
533 function fileNotFoundError( $name )
535 $this->fatalError( wfMsg( "filenotfound", $name ) );
538 function returnToMain( $auto = true, $returnto = NULL )
540 global $wgUser, $wgOut, $wgRequest;
542 if ( $returnto == NULL ) {
543 $returnto = $wgRequest->getText( 'returnto' );
546 $sk = $wgUser->getSkin();
547 if ( "" == $returnto ) {
548 $returnto = wfMsg( "mainpage" );
550 $link = $sk->makeKnownLink( $returnto, "" );
552 $r = wfMsg( "returnto", $link );
554 $titleObj = Title
::newFromText( $returnto );
555 $wgOut->addMeta( "http:Refresh", "10;url=" . $titleObj->escapeFullURL() );
557 $wgOut->addHTML( "\n<p>$r\n" );
560 # This function takes the existing and broken links for the page
561 # and uses the first 10 of them for META keywords
562 function addMetaTags ()
564 global $wgLinkCache , $wgOut ;
565 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
566 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
567 $a = array_merge ( $good , $bad ) ;
568 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
569 $a = implode ( "," , $a ) ;
570 $wgOut->addMeta ( "KEYWORDS" , $a ) ;
573 /* private */ function headElement()
575 global $wgDocType, $wgDTD, $wgUser, $wgLanguageCode, $wgOutputEncoding, $wgLang, $wgRequest;
577 $ret = "<!DOCTYPE HTML PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
579 if ( "" == $this->mHTMLtitle
) {
580 $this->mHTMLtitle
= $this->mPagetitle
;
582 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : "";
583 $ret .= "<html lang=\"$wgLanguageCode\"$rtl><head><title>{$this->mHTMLtitle}</title>\n";
584 array_push( $this->mMetatags
, array( "http:Content-type", "text/html; charset={$wgOutputEncoding}" ) );
585 foreach ( $this->mMetatags
as $tag ) {
586 if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
588 $tag[0] = substr( $tag[0], 5 );
592 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\">\n";
594 $p = $this->mRobotpolicy
;
595 if ( "" == $p ) { $p = "index,follow"; }
596 $ret .= "<meta name=\"robots\" content=\"$p\">\n";
598 if ( count( $this->mKeywords
) > 0 ) {
599 $ret .= "<meta name=\"keywords\" content=\"" .
600 implode( ",", $this->mKeywords
) . "\">\n";
602 foreach ( $this->mLinktags
as $tag ) {
604 if ( "" != $tag[0] ) { $ret .= "rel=\"{$tag[0]}\" "; }
605 if ( "" != $tag[1] ) { $ret .= "rev=\"{$tag[1]}\" "; }
606 if ( !empty( $tag[3] ) ) { $ret .= "type=\"{$tag[3]}\" "; }
607 if ( !empty( $tag[4] ) ) { $ret .= "media=\"{$tag[4]}\" "; }
608 $ret .= "href=\"{$tag[2]}\">\n";
610 if( $this->isSyndicated() ) {
611 $link = $wgRequest->escapeAppendQuery( "feed=rss" );
612 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS' href='$link'>\n";
614 global $wgStyleSheetPath;
615 if( $this->isPrintable() ) {
618 $media = "media='print'";
620 $printsheet = htmlspecialchars( "$wgStyleSheetPath/wikiprintable.css" );
621 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet'>\n";
623 $sk = $wgUser->getSkin();
624 $ret .= $sk->getHeadScripts();
625 $ret .= $sk->getUserStyles();