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;
22 $this->mHeaders
= $this->mCookies
= $this->mMetatags
=
23 $this->mKeywords
= $this->mLinktags
= array();
24 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
25 $this->mRedirect
= $this->mLastModified
=
26 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
27 $this->mOnloadHandler
= "";
28 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
29 $this->mSuppressQuickbar
= $this->mPrintable
= false;
30 $this->mLanguageLinks
= array();
31 $this->mCategoryLinks
= array() ;
32 $this->mDoNothing
= false;
33 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
34 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
37 function addHeader( $name, $val ) { array_push( $this->mHeaders
, "$name: $val" ) ; }
38 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
39 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
41 # To add an http-equiv meta tag, precede the name with "http:"
42 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
43 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
44 function addLink( $rel, $rev, $target ) { array_push( $this->mLinktags
, array( $rel, $rev, $target ) ); }
46 # checkLastModified tells the client to use the client-cached page if
47 # possible. If sucessful, the OutputPage is disabled so that
48 # any future call to OutputPage->output() have no effect. The method
49 # returns true iff cache-ok headers was sent.
50 function checkLastModified ( $timestamp )
52 global $wgLang, $wgCachePages, $wgUser;
53 if( !$wgCachePages ) {
54 wfDebug( "CACHE DISABLED\n", false );
57 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
58 # IE 5.0 has probs with our caching
59 wfDebug( "-- bad client, not caching\n", false );
62 if( $wgUser->getOption( "nocache" ) ) {
63 wfDebug( "USER DISABLED CACHE\n", false );
67 $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
68 max( $timestamp, $wgUser->mTouched
) ) ) . " GMT";
70 if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
71 # IE sends sizes after the date like this:
72 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
73 # this breaks strtotime().
74 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
75 $ismodsince = wfUnix2Timestamp( strtotime( $modsince ) );
76 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
77 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
79 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
80 # Make sure you're in a place you can leave when you call us!
81 header( "HTTP/1.0 304 Not Modified" );
82 $this->mLastModified
= $lastmod;
83 $this->sendCacheControl();
84 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
88 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
89 $this->mLastModified
= $lastmod;
92 wfDebug( "We're confused.\n", false );
93 $this->mLastModified
= $lastmod;
97 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
98 function setHTMLtitle( $name ) { $this->mHTMLtitle
= $name; }
99 function setPageTitle( $name ) { $this->mPagetitle
= $name; }
100 function getPageTitle() { return $this->mPagetitle
; }
101 function setSubtitle( $str ) { $this->mSubtitle
= $str; }
102 function getSubtitle() { return $this->mSubtitle
; }
103 function isArticle() { return $this->mIsarticle
; }
104 function setPrintable() { $this->mPrintable
= true; }
105 function isPrintable() { return $this->mPrintable
; }
106 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
107 function getOnloadHandler() { return $this->mOnloadHandler
; }
108 function disable() { $this->mDoNothing
= true; }
110 function setArticleRelated( $v )
112 $this->mIsArticleRelated
= $v;
114 $this->mIsarticle
= false;
117 function setArticleFlag( $v ) {
118 $this->mIsarticle
= $v;
120 $this->mIsArticleRelated
= $v;
124 function isArticleRelated()
126 return $this->mIsArticleRelated
;
129 function getLanguageLinks() {
130 global $wgTitle, $wgLanguageCode;
131 global $wgDBconnection, $wgDBname;
132 return $this->mLanguageLinks
;
134 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
135 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
137 function addHTML( $text ) { $this->mBodytext
.= $text; }
138 function addHeadtext( $text ) { $this->mHeadtext
.= $text; }
139 function debug( $text ) { $this->mDebugtext
.= $text; }
141 function setParserOptions( $options )
143 return wfSetVar( $this->mParserOptions
, $options );
146 # First pass--just handle <nowiki> sections, pass the rest off
147 # to doWikiPass2() which does all the real work.
149 # $cacheArticle - assume this text is the main text for the given article
151 function addWikiText( $text, $linestart = true, $cacheArticle = NULL )
153 global $wgParser, $wgParserCache, $wgUser, $wgTitle;
155 $parserOutput = false;
156 if ( $cacheArticle ) {
157 $parserOutput = $wgParserCache->get( $cacheArticle, $wgUser );
160 if ( $parserOutput === false ) {
161 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
162 if ( $cacheArticle ) {
163 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
167 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
168 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
170 $this->addHTML( $parserOutput->getText() );
174 # Set the maximum cache time on the Squid in seconds
175 function setSquidMaxage( $maxage ) {
176 global $wgSquidMaxage;
177 $wgSquidMaxage = $maxage;
180 function sendCacheControl() {
181 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
182 # FIXME: This header may cause trouble with some versions of Internet Explorer
183 header( "Vary: Accept-Encoding, Cookie" );
184 if( $this->mLastModified
!= "" ) {
185 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( "session.name") ] ) &&
186 ! $this->isPrintable() )
189 # We'll purge the proxy cache explicitly, but require end user agents
190 # to revalidate against the proxy on each visit.
191 # Surrogate-Control controls our Squid, Cache-Control downstream caches
192 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
193 # start with a shorter timeout for initial testing
194 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
195 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$wgSquidMaxage.', content="ESI/1.0"');
196 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
198 # We'll purge the proxy cache for anons explicitly, but require end user agents
199 # to revalidate against the proxy on each visit.
200 # IMPORTANT! The Squid needs to replace the Cache-Control header with
201 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
202 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
203 # start with a shorter timeout for initial testing
204 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
205 header( 'Cache-Control: s-maxage='.$wgSquidMaxage.', must-revalidate, max-age=0' );
208 # We do want clients to cache if they can, but they *must* check for updates
209 # on revisiting the page.
210 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
211 header( "Expires: -1" );
212 header( "Cache-Control: private, must-revalidate, max-age=0" );
214 header( "Last-modified: {$this->mLastModified}" );
216 wfDebug( "** no caching **\n", false );
217 header( "Expires: -1" );
218 header( "Cache-Control: no-cache" );
219 header( "Pragma: no-cache" );
220 header( "Last-modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
224 # Finally, all the text has been munged and accumulated into
225 # the object, let's actually output it:
229 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
230 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
231 global $wgDebugRedirects;
232 if( $this->mDoNothing
){
235 $fname = "OutputPage::output";
236 wfProfileIn( $fname );
238 $sk = $wgUser->getSkin();
240 if ( "" != $this->mRedirect
) {
241 if( substr( $this->mRedirect
, 0, 4 ) != "http" ) {
242 # Standards require redirect URLs to be absolute
244 $this->mRedirect
= $wgServer . $this->mRedirect
;
246 if( $this->mRedirectCode
== '301') {
247 if( !$wgDebugRedirects ) {
248 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
250 $this->mLastModified
= gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
251 max( $timestamp, $wgUser->mTouched
) ) ) . " GMT";
254 $this->sendCacheControl();
256 if( $wgDebugRedirects ) {
257 $url = htmlspecialchars( $this->mRedirect
);
258 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
259 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
260 print "</body>\n</html>\n";
262 header( "Location: {$this->mRedirect}" );
268 $this->sendCacheControl();
270 header( "Content-type: text/html; charset={$wgOutputEncoding}" );
271 header( "Content-language: {$wgLanguageCode}" );
273 $exp = time() +
$wgCookieExpiration;
274 foreach( $this->mCookies
as $name => $val ) {
275 setcookie( $name, $val, $exp, "/" );
278 $sk->outputPage( $this );
284 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
285 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
288 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
289 if ( false === $outs ) { $outs = $ins; }
294 function setEncodings()
296 global $wgInputEncoding, $wgOutputEncoding;
297 global $wgUser, $wgLang;
299 $wgInputEncoding = strtolower( $wgInputEncoding );
301 if( $wgUser->getOption( 'altencoding' ) ) {
302 $wgLang->setAltEncoding();
306 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
307 $wgOutputEncoding = strtolower( $wgOutputEncoding );
312 # This code is unused anyway!
313 # Commenting out. --bv 2003-11-15
315 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
319 foreach ( $a as $s ) {
320 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
332 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
333 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
334 $wgOutputEncoding = strtolower( $bestset );
339 $wgOutputEncoding = $wgInputEncoding;
342 # Returns a HTML comment with the elapsed time since request.
343 # This method has no side effects.
344 function reportTime()
346 global $wgRequestTime;
349 list( $usec, $sec ) = explode( " ", $wgRequestTime );
350 $start = (float)$sec +
(float)$usec;
351 $elapsed = $now - $start;
352 $com = sprintf( "<!-- Time since request: %01.2f secs. -->",
357 # Note: these arguments are keys into wfMsg(), not text!
359 function errorpage( $title, $msg )
363 $this->mDebugtext
.= "Original title: " .
364 $wgTitle->getPrefixedText() . "\n";
365 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
366 $this->setPageTitle( wfMsg( $title ) );
367 $this->setRobotpolicy( "noindex,nofollow" );
368 $this->setArticleRelated( false );
370 $this->mBodytext
= "";
371 $this->addHTML( "<p>" . wfMsg( $msg ) . "\n" );
372 $this->returnToMain( false );
378 function sysopRequired()
382 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
383 $this->setPageTitle( wfMsg( "sysoptitle" ) );
384 $this->setRobotpolicy( "noindex,nofollow" );
385 $this->setArticleRelated( false );
386 $this->mBodytext
= "";
388 $sk = $wgUser->getSkin();
389 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
390 $this->addHTML( wfMsg( "sysoptext", $ap ) );
391 $this->returnToMain();
394 function developerRequired()
398 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
399 $this->setPageTitle( wfMsg( "developertitle" ) );
400 $this->setRobotpolicy( "noindex,nofollow" );
401 $this->setArticleRelated( false );
402 $this->mBodytext
= "";
404 $sk = $wgUser->getSkin();
405 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
406 $this->addHTML( wfMsg( "developertext", $ap ) );
407 $this->returnToMain();
410 function databaseError( $fname, &$conn )
412 global $wgUser, $wgCommandLineMode;
414 $this->setPageTitle( wfMsgNoDB( "databaseerror" ) );
415 $this->setRobotpolicy( "noindex,nofollow" );
416 $this->setArticleRelated( false );
418 if ( $wgCommandLineMode ) {
419 $msg = wfMsgNoDB( "dberrortextcl" );
421 $msg = wfMsgNoDB( "dberrortext" );
424 $msg = str_replace( "$1", htmlspecialchars( $conn->lastQuery() ), $msg );
425 $msg = str_replace( "$2", htmlspecialchars( $fname ), $msg );
426 $msg = str_replace( "$3", $conn->lastErrno(), $msg );
427 $msg = str_replace( "$4", htmlspecialchars( $conn->lastError() ), $msg );
429 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
433 $sk = $wgUser->getSkin();
434 $shlink = $sk->makeKnownLink( wfMsgNoDB( "searchhelppage" ),
435 wfMsgNoDB( "searchingwikipedia" ) );
436 $msg = str_replace( "$5", $shlink, $msg );
437 $this->mBodytext
= $msg;
442 function readOnlyPage( $source = "", $protected = false )
444 global $wgUser, $wgReadOnlyFile;
446 $this->setRobotpolicy( "noindex,nofollow" );
447 $this->setArticleRelated( false );
450 $this->setPageTitle( wfMsg( "viewsource" ) );
451 $this->addWikiText( wfMsg( "protectedtext" ) );
453 $this->setPageTitle( wfMsg( "readonly" ) );
454 $reason = file_get_contents( $wgReadOnlyFile );
455 $this->addHTML( wfMsg( "readonlytext", $reason ) );
459 $rows = $wgUser->getOption( "rows" );
460 $cols = $wgUser->getOption( "cols" );
461 $text .= "</p>\n<textarea cols='$cols' rows='$rows' readonly>" .
462 htmlspecialchars( $source ) . "\n</textarea>";
463 $this->addHTML( $text );
466 $this->returnToMain( false );
469 function fatalError( $message )
471 $this->setPageTitle( wfMsg( "internalerror" ) );
472 $this->setRobotpolicy( "noindex,nofollow" );
473 $this->setArticleRelated( false );
475 $this->mBodytext
= $message;
480 function unexpectedValueError( $name, $val )
482 $this->fatalError( wfMsg( "unexpected", $name, $val ) );
485 function fileCopyError( $old, $new )
487 $this->fatalError( wfMsg( "filecopyerror", $old, $new ) );
490 function fileRenameError( $old, $new )
492 $this->fatalError( wfMsg( "filerenameerror", $old, $new ) );
495 function fileDeleteError( $name )
497 $this->fatalError( wfMsg( "filedeleteerror", $name ) );
500 function fileNotFoundError( $name )
502 $this->fatalError( wfMsg( "filenotfound", $name ) );
505 function returnToMain( $auto = true )
507 global $wgUser, $wgOut, $returnto;
509 $sk = $wgUser->getSkin();
510 if ( "" == $returnto ) {
511 $returnto = wfMsg( "mainpage" );
513 $link = $sk->makeKnownLink( $returnto, "" );
515 $r = wfMsg( "returnto", $link );
517 $wgOut->addMeta( "http:Refresh", "10;url=" .
518 wfLocalUrlE( wfUrlencode( $returnto ) ) );
520 $wgOut->addHTML( "\n<p>$r\n" );
523 /* private */ function headElement()
525 global $wgDocType, $wgDTD, $wgUser, $wgLanguageCode, $wgOutputEncoding, $wgLang;
527 $ret = "<!DOCTYPE HTML PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
529 if ( "" == $this->mHTMLtitle
) {
530 $this->mHTMLtitle
= $this->mPagetitle
;
532 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : "";
533 $ret .= "<html lang=\"$wgLanguageCode\"$rtl><head><title>{$this->mHTMLtitle}</title>\n";
534 array_push( $this->mMetatags
, array( "http:Content-type", "text/html; charset={$wgOutputEncoding}" ) );
535 foreach ( $this->mMetatags
as $tag ) {
536 if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
538 $tag[0] = substr( $tag[0], 5 );
542 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\">\n";
544 $p = $this->mRobotpolicy
;
545 if ( "" == $p ) { $p = "index,follow"; }
546 $ret .= "<meta name=\"robots\" content=\"$p\">\n";
548 if ( count( $this->mKeywords
) > 0 ) {
549 $ret .= "<meta name=\"keywords\" content=\"" .
550 implode( ",", $this->mKeywords
) . "\">\n";
552 foreach ( $this->mLinktags
as $tag ) {
554 if ( "" != $tag[0] ) { $ret .= "rel=\"{$tag[0]}\" "; }
555 if ( "" != $tag[1] ) { $ret .= "rev=\"{$tag[1]}\" "; }
556 $ret .= "href=\"{$tag[2]}\">\n";
558 $sk = $wgUser->getSkin();
559 $ret .= $sk->getHeadScripts();
560 $ret .= $sk->getUserStyles();