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;
23 $this->mHeaders
= $this->mCookies
= $this->mMetatags
=
24 $this->mKeywords
= $this->mLinktags
= array();
25 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
26 $this->mRedirect
= $this->mLastModified
=
27 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
28 $this->mOnloadHandler
= "";
29 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
30 $this->mSuppressQuickbar
= $this->mPrintable
= false;
31 $this->mLanguageLinks
= array();
32 $this->mCategoryLinks
= array() ;
33 $this->mDoNothing
= false;
34 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
35 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
36 $this->mSquidMaxage
= 0;
39 function addHeader( $name, $val ) { array_push( $this->mHeaders
, "$name: $val" ) ; }
40 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
41 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
43 # To add an http-equiv meta tag, precede the name with "http:"
44 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
45 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
46 function addLink( $rel, $rev, $target ) { array_push( $this->mLinktags
, array( $rel, $rev, $target ) ); }
48 # checkLastModified tells the client to use the client-cached page if
49 # possible. If sucessful, the OutputPage is disabled so that
50 # any future call to OutputPage->output() have no effect. The method
51 # returns true iff cache-ok headers was sent.
52 function checkLastModified ( $timestamp )
54 global $wgLang, $wgCachePages, $wgUser;
55 if( !$wgCachePages ) {
56 wfDebug( "CACHE DISABLED\n", false );
59 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
60 # IE 5.0 has probs with our caching
61 wfDebug( "-- bad client, not caching\n", false );
64 if( $wgUser->getOption( "nocache" ) ) {
65 wfDebug( "USER DISABLED CACHE\n", false );
69 $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
70 max( $timestamp, $wgUser->mTouched
) ) ) . " GMT";
72 if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
73 # IE sends sizes after the date like this:
74 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
75 # this breaks strtotime().
76 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
77 $ismodsince = wfUnix2Timestamp( strtotime( $modsince ) );
78 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
79 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
81 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
82 # Make sure you're in a place you can leave when you call us!
83 header( "HTTP/1.0 304 Not Modified" );
84 $this->mLastModified
= $lastmod;
85 $this->sendCacheControl();
86 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
90 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
91 $this->mLastModified
= $lastmod;
94 wfDebug( "We're confused.\n", false );
95 $this->mLastModified
= $lastmod;
99 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
100 function setHTMLtitle( $name ) { $this->mHTMLtitle
= $name; }
101 function setPageTitle( $name ) { $this->mPagetitle
= $name; }
102 function getPageTitle() { return $this->mPagetitle
; }
103 function setSubtitle( $str ) { $this->mSubtitle
= $str; }
104 function getSubtitle() { return $this->mSubtitle
; }
105 function isArticle() { return $this->mIsarticle
; }
106 function setPrintable() { $this->mPrintable
= true; }
107 function isPrintable() { return $this->mPrintable
; }
108 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
109 function isSyndicated() { return $this->mShowFeedLinks
; }
110 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
111 function getOnloadHandler() { return $this->mOnloadHandler
; }
112 function disable() { $this->mDoNothing
= true; }
114 function setArticleRelated( $v )
116 $this->mIsArticleRelated
= $v;
118 $this->mIsarticle
= false;
121 function setArticleFlag( $v ) {
122 $this->mIsarticle
= $v;
124 $this->mIsArticleRelated
= $v;
128 function isArticleRelated()
130 return $this->mIsArticleRelated
;
133 function getLanguageLinks() {
134 global $wgTitle, $wgLanguageCode;
135 global $wgDBconnection, $wgDBname;
136 return $this->mLanguageLinks
;
138 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
139 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
141 function addHTML( $text ) { $this->mBodytext
.= $text; }
142 function addHeadtext( $text ) { $this->mHeadtext
.= $text; }
143 function debug( $text ) { $this->mDebugtext
.= $text; }
145 function setParserOptions( $options )
147 return wfSetVar( $this->mParserOptions
, $options );
150 # First pass--just handle <nowiki> sections, pass the rest off
151 # to doWikiPass2() which does all the real work.
153 # $cacheArticle - assume this text is the main text for the given article
155 function addWikiText( $text, $linestart = true, $cacheArticle = NULL )
157 global $wgParser, $wgParserCache, $wgUser, $wgTitle;
159 $parserOutput = false;
160 if ( $cacheArticle ) {
161 $parserOutput = $wgParserCache->get( $cacheArticle, $wgUser );
164 if ( $parserOutput === false ) {
165 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
166 if ( $cacheArticle ) {
167 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
171 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
172 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
174 $this->addHTML( $parserOutput->getText() );
178 # Set the maximum cache time on the Squid in seconds
179 function setSquidMaxage( $maxage ) {
180 $this->mSquidMaxage
= $maxage;
183 function sendCacheControl() {
184 global $wgUseSquid, $wgUseESI;
185 # FIXME: This header may cause trouble with some versions of Internet Explorer
186 header( "Vary: Accept-Encoding, Cookie" );
187 if( $this->mLastModified
!= "" ) {
188 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( "session.name") ] ) &&
189 ! $this->isPrintable() )
192 # We'll purge the proxy cache explicitly, but require end user agents
193 # to revalidate against the proxy on each visit.
194 # Surrogate-Control controls our Squid, Cache-Control downstream caches
195 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
196 # start with a shorter timeout for initial testing
197 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
198 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
199 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
201 # We'll purge the proxy cache for anons explicitly, but require end user agents
202 # to revalidate against the proxy on each visit.
203 # IMPORTANT! The Squid needs to replace the Cache-Control header with
204 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
205 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
206 # start with a shorter timeout for initial testing
207 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
208 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
211 # We do want clients to cache if they can, but they *must* check for updates
212 # on revisiting the page.
213 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
214 header( "Expires: -1" );
215 header( "Cache-Control: private, must-revalidate, max-age=0" );
217 header( "Last-modified: {$this->mLastModified}" );
219 wfDebug( "** no caching **\n", false );
220 header( "Expires: -1" );
221 header( "Cache-Control: no-cache" );
222 header( "Pragma: no-cache" );
223 header( "Last-modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
227 # Finally, all the text has been munged and accumulated into
228 # the object, let's actually output it:
232 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
233 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
234 global $wgDebugRedirects;
235 if( $this->mDoNothing
){
238 $fname = "OutputPage::output";
239 wfProfileIn( $fname );
241 $sk = $wgUser->getSkin();
243 if ( "" != $this->mRedirect
) {
244 if( substr( $this->mRedirect
, 0, 4 ) != "http" ) {
245 # Standards require redirect URLs to be absolute
247 $this->mRedirect
= $wgServer . $this->mRedirect
;
249 if( $this->mRedirectCode
== '301') {
250 if( !$wgDebugRedirects ) {
251 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
253 $this->mLastModified
= gmdate( "D, j M Y H:i:s" ) . " GMT";
256 $this->sendCacheControl();
258 if( $wgDebugRedirects ) {
259 $url = htmlspecialchars( $this->mRedirect
);
260 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
261 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
262 print "</body>\n</html>\n";
264 header( "Location: {$this->mRedirect}" );
270 $this->sendCacheControl();
272 header( "Content-type: text/html; charset={$wgOutputEncoding}" );
273 header( "Content-language: {$wgLanguageCode}" );
275 $exp = time() +
$wgCookieExpiration;
276 foreach( $this->mCookies
as $name => $val ) {
277 setcookie( $name, $val, $exp, "/" );
280 $sk->outputPage( $this );
286 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
287 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
290 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
291 if ( false === $outs ) { $outs = $ins; }
296 function setEncodings()
298 global $wgInputEncoding, $wgOutputEncoding;
299 global $wgUser, $wgLang;
301 $wgInputEncoding = strtolower( $wgInputEncoding );
303 if( $wgUser->getOption( 'altencoding' ) ) {
304 $wgLang->setAltEncoding();
308 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
309 $wgOutputEncoding = strtolower( $wgOutputEncoding );
314 # This code is unused anyway!
315 # Commenting out. --bv 2003-11-15
317 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
321 foreach ( $a as $s ) {
322 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
334 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
335 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
336 $wgOutputEncoding = strtolower( $bestset );
341 $wgOutputEncoding = $wgInputEncoding;
344 # Returns a HTML comment with the elapsed time since request.
345 # This method has no side effects.
346 function reportTime()
348 global $wgRequestTime;
351 list( $usec, $sec ) = explode( " ", $wgRequestTime );
352 $start = (float)$sec +
(float)$usec;
353 $elapsed = $now - $start;
354 $com = sprintf( "<!-- Time since request: %01.2f secs. -->",
359 # Note: these arguments are keys into wfMsg(), not text!
361 function errorpage( $title, $msg )
365 $this->mDebugtext
.= "Original title: " .
366 $wgTitle->getPrefixedText() . "\n";
367 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
368 $this->setPageTitle( wfMsg( $title ) );
369 $this->setRobotpolicy( "noindex,nofollow" );
370 $this->setArticleRelated( false );
372 $this->mBodytext
= "";
373 $this->addHTML( "<p>" . wfMsg( $msg ) . "\n" );
374 $this->returnToMain( false );
380 function sysopRequired()
384 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
385 $this->setPageTitle( wfMsg( "sysoptitle" ) );
386 $this->setRobotpolicy( "noindex,nofollow" );
387 $this->setArticleRelated( false );
388 $this->mBodytext
= "";
390 $sk = $wgUser->getSkin();
391 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
392 $this->addHTML( wfMsg( "sysoptext", $ap ) );
393 $this->returnToMain();
396 function developerRequired()
400 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
401 $this->setPageTitle( wfMsg( "developertitle" ) );
402 $this->setRobotpolicy( "noindex,nofollow" );
403 $this->setArticleRelated( false );
404 $this->mBodytext
= "";
406 $sk = $wgUser->getSkin();
407 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
408 $this->addHTML( wfMsg( "developertext", $ap ) );
409 $this->returnToMain();
412 function loginToUse()
414 global $wgUser, $wgTitle, $wgLang;
416 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
417 $this->setPageTitle( wfMsg( "loginreqtitle" ) );
418 $this->setRobotpolicy( "noindex,nofollow" );
419 $this->setArticleFlag( false );
420 $this->mBodytext
= "";
421 $this->addWikiText( wfMsg( "loginreqtext" ) );
423 # We put a comment in the .html file so a Sysop can diagnose the page the
425 $this->addHTML( "\n<!--" .
426 $wgLang->getNsText( $wgTitle->getNamespace() ) .
428 $wgTitle->getDBkey() . "-->" );
429 $this->returnToMain(); # Flip back to the main page after 10 seconds.
432 function databaseError( $fname, &$conn )
434 global $wgUser, $wgCommandLineMode;
436 $this->setPageTitle( wfMsgNoDB( "databaseerror" ) );
437 $this->setRobotpolicy( "noindex,nofollow" );
438 $this->setArticleRelated( false );
440 if ( $wgCommandLineMode ) {
441 $msg = wfMsgNoDB( "dberrortextcl" );
443 $msg = wfMsgNoDB( "dberrortext" );
446 $msg = str_replace( "$1", htmlspecialchars( $conn->lastQuery() ), $msg );
447 $msg = str_replace( "$2", htmlspecialchars( $fname ), $msg );
448 $msg = str_replace( "$3", $conn->lastErrno(), $msg );
449 $msg = str_replace( "$4", htmlspecialchars( $conn->lastError() ), $msg );
451 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
455 $sk = $wgUser->getSkin();
456 $shlink = $sk->makeKnownLink( wfMsgNoDB( "searchhelppage" ),
457 wfMsgNoDB( "searchingwikipedia" ) );
458 $msg = str_replace( "$5", $shlink, $msg );
459 $this->mBodytext
= $msg;
464 function readOnlyPage( $source = "", $protected = false )
466 global $wgUser, $wgReadOnlyFile;
468 $this->setRobotpolicy( "noindex,nofollow" );
469 $this->setArticleRelated( false );
472 $this->setPageTitle( wfMsg( "viewsource" ) );
473 $this->addWikiText( wfMsg( "protectedtext" ) );
475 $this->setPageTitle( wfMsg( "readonly" ) );
476 $reason = file_get_contents( $wgReadOnlyFile );
477 $this->addHTML( wfMsg( "readonlytext", $reason ) );
481 $rows = $wgUser->getOption( "rows" );
482 $cols = $wgUser->getOption( "cols" );
483 $text .= "</p>\n<textarea cols='$cols' rows='$rows' readonly>" .
484 htmlspecialchars( $source ) . "\n</textarea>";
485 $this->addHTML( $text );
488 $this->returnToMain( false );
491 function fatalError( $message )
493 $this->setPageTitle( wfMsg( "internalerror" ) );
494 $this->setRobotpolicy( "noindex,nofollow" );
495 $this->setArticleRelated( false );
497 $this->mBodytext
= $message;
502 function unexpectedValueError( $name, $val )
504 $this->fatalError( wfMsg( "unexpected", $name, $val ) );
507 function fileCopyError( $old, $new )
509 $this->fatalError( wfMsg( "filecopyerror", $old, $new ) );
512 function fileRenameError( $old, $new )
514 $this->fatalError( wfMsg( "filerenameerror", $old, $new ) );
517 function fileDeleteError( $name )
519 $this->fatalError( wfMsg( "filedeleteerror", $name ) );
522 function fileNotFoundError( $name )
524 $this->fatalError( wfMsg( "filenotfound", $name ) );
527 function returnToMain( $auto = true )
529 global $wgUser, $wgOut, $returnto;
531 $sk = $wgUser->getSkin();
532 if ( "" == $returnto ) {
533 $returnto = wfMsg( "mainpage" );
535 $link = $sk->makeKnownLink( $returnto, "" );
537 $r = wfMsg( "returnto", $link );
539 $titleObj = Title
::newFromText( $returnto );
540 $wgOut->addMeta( "http:Refresh", "10;url=" . $titleObj->escapeFullURL() );
542 $wgOut->addHTML( "\n<p>$r\n" );
545 /* private */ function headElement()
547 global $wgDocType, $wgDTD, $wgUser, $wgLanguageCode, $wgOutputEncoding, $wgLang;
549 $ret = "<!DOCTYPE HTML PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
551 if ( "" == $this->mHTMLtitle
) {
552 $this->mHTMLtitle
= $this->mPagetitle
;
554 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : "";
555 $ret .= "<html lang=\"$wgLanguageCode\"$rtl><head><title>{$this->mHTMLtitle}</title>\n";
556 array_push( $this->mMetatags
, array( "http:Content-type", "text/html; charset={$wgOutputEncoding}" ) );
557 foreach ( $this->mMetatags
as $tag ) {
558 if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
560 $tag[0] = substr( $tag[0], 5 );
564 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\">\n";
566 $p = $this->mRobotpolicy
;
567 if ( "" == $p ) { $p = "index,follow"; }
568 $ret .= "<meta name=\"robots\" content=\"$p\">\n";
570 if ( count( $this->mKeywords
) > 0 ) {
571 $ret .= "<meta name=\"keywords\" content=\"" .
572 implode( ",", $this->mKeywords
) . "\">\n";
574 foreach ( $this->mLinktags
as $tag ) {
576 if ( "" != $tag[0] ) { $ret .= "rel=\"{$tag[0]}\" "; }
577 if ( "" != $tag[1] ) { $ret .= "rev=\"{$tag[1]}\" "; }
578 $ret .= "href=\"{$tag[2]}\">\n";
580 $sk = $wgUser->getSkin();
581 $ret .= $sk->getHeadScripts();
582 $ret .= $sk->getUserStyles();