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;
21 $this->mHeaders
= $this->mCookies
= $this->mMetatags
=
22 $this->mKeywords
= $this->mLinktags
= array();
23 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
24 $this->mRedirect
= $this->mLastModified
=
25 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
26 $this->mOnloadHandler
= "";
27 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
28 $this->mSuppressQuickbar
= $this->mPrintable
= false;
29 $this->mLanguageLinks
= array();
30 $this->mCategoryLinks
= array() ;
31 $this->mDoNothing
= false;
32 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
35 function addHeader( $name, $val ) { array_push( $this->mHeaders
, "$name: $val" ) ; }
36 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
37 function redirect( $url ) { $this->mRedirect
= $url; }
39 # To add an http-equiv meta tag, precede the name with "http:"
40 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
41 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
42 function addLink( $rel, $rev, $target ) { array_push( $this->mLinktags
, array( $rel, $rev, $target ) ); }
44 # checkLastModified tells the client to use the client-cached page if
45 # possible. If sucessful, the OutputPage is disabled so that
46 # any future call to OutputPage->output() have no effect. The method
47 # returns true iff cache-ok headers was sent.
48 function checkLastModified ( $timestamp )
50 global $wgLang, $wgCachePages, $wgUser;
51 if( !$wgCachePages ) {
52 wfDebug( "CACHE DISABLED\n", false );
55 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
56 # IE 5.0 has probs with our caching
57 wfDebug( "-- bad client, not caching\n", false );
60 if( $wgUser->getOption( "nocache" ) ) {
61 wfDebug( "USER DISABLED CACHE\n", false );
65 $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
66 max( $timestamp, $wgUser->mTouched
) ) ) . " GMT";
68 if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
69 # IE sends sizes after the date like this:
70 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
71 # this breaks strtotime().
72 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
73 $ismodsince = wfUnix2Timestamp( strtotime( $modsince ) );
74 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
75 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
77 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
78 # Make sure you're in a place you can leave when you call us!
79 header( "HTTP/1.0 304 Not Modified" );
80 $this->mLastModified
= $lastmod;
81 $this->sendCacheControl();
82 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
86 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
87 $this->mLastModified
= $lastmod;
90 wfDebug( "We're confused.\n", false );
91 $this->mLastModified
= $lastmod;
95 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
96 function setHTMLtitle( $name ) { $this->mHTMLtitle
= $name; }
97 function setPageTitle( $name ) { $this->mPagetitle
= $name; }
98 function getPageTitle() { return $this->mPagetitle
; }
99 function setSubtitle( $str ) { $this->mSubtitle
= $str; }
100 function getSubtitle() { return $this->mSubtitle
; }
101 function isArticle() { return $this->mIsarticle
; }
102 function setPrintable() { $this->mPrintable
= true; }
103 function isPrintable() { return $this->mPrintable
; }
104 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
105 function getOnloadHandler() { return $this->mOnloadHandler
; }
106 function disable() { $this->mDoNothing
= true; }
108 function setArticleRelated( $v )
110 $this->mIsArticleRelated
= $v;
112 $this->mIsarticle
= false;
115 function setArticleFlag( $v ) {
116 $this->mIsarticle
= $v;
118 $this->mIsArticleRelated
= $v;
122 function isArticleRelated()
124 return $this->mIsArticleRelated
;
127 function getLanguageLinks() {
128 global $wgTitle, $wgLanguageCode;
129 global $wgDBconnection, $wgDBname;
130 return $this->mLanguageLinks
;
132 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
133 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
135 function addHTML( $text ) { $this->mBodytext
.= $text; }
136 function addHeadtext( $text ) { $this->mHeadtext
.= $text; }
137 function debug( $text ) { $this->mDebugtext
.= $text; }
139 # First pass--just handle <nowiki> sections, pass the rest off
140 # to doWikiPass2() which does all the real work.
142 # $cacheArticle - assume this text is the main text for the given article
144 function addWikiText( $text, $linestart = true, $cacheArticle = NULL )
146 global $wgParser, $wgParserCache, $wgUser;
148 $parserOutput = false;
149 if ( $cacheArticle ) {
150 $parserOutput = $wgParserCache->get( $cacheArticle, $wgUser );
153 if ( $parserOutput === false ) {
154 $parserOutput = $wgParser->parse( $text, $linestart );
155 if ( $cacheArticle ) {
156 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
160 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
161 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
163 $this->addHTML( $parserOutput->getText() );
167 # Set the maximum cache time on the Squid in seconds
168 function setSquidMaxage( $maxage ) {
169 global $wgSquidMaxage;
170 $wgSquidMaxage = $maxage;
173 function sendCacheControl() {
174 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
175 # FIXME: This header may cause trouble with some versions of Internet Explorer
176 header( "Vary: Accept-Encoding, Cookie" );
177 if( $this->mLastModified
!= "" ) {
178 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( "session.name") ] ) &&
179 ! $this->isPrintable() )
182 # We'll purge the proxy cache explicitly, but require end user agents
183 # to revalidate against the proxy on each visit.
184 # Surrogate-Control controls our Squid, Cache-Control downstream caches
185 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
186 # start with a shorter timeout for initial testing
187 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
188 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$wgSquidMaxage.', content="ESI/1.0"');
189 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
191 # We'll purge the proxy cache for anons explicitly, but require end user agents
192 # to revalidate against the proxy on each visit.
193 # IMPORTANT! The Squid needs to replace the Cache-Control header with
194 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
195 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
196 # start with a shorter timeout for initial testing
197 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
198 header( 'Cache-Control: s-maxage='.$wgSquidMaxage.', must-revalidate, max-age=0' );
201 # We do want clients to cache if they can, but they *must* check for updates
202 # on revisiting the page.
203 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
204 header( "Expires: -1" );
205 header( "Cache-Control: private, must-revalidate, max-age=0" );
207 header( "Last-modified: {$this->mLastModified}" );
209 wfDebug( "** no caching **\n", false );
210 header( "Expires: -1" );
211 header( "Cache-Control: no-cache" );
212 header( "Pragma: no-cache" );
213 header( "Last-modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
217 # Finally, all the text has been munged and accumulated into
218 # the object, let's actually output it:
222 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
223 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
224 if( $this->mDoNothing
){
227 $fname = "OutputPage::output";
228 wfProfileIn( $fname );
230 $sk = $wgUser->getSkin();
232 $this->sendCacheControl();
234 header( "Content-type: text/html; charset={$wgOutputEncoding}" );
235 header( "Content-language: {$wgLanguageCode}" );
237 if ( "" != $this->mRedirect
) {
238 if( substr( $this->mRedirect
, 0, 4 ) != "http" ) {
239 # Standards require redirect URLs to be absolute
241 $this->mRedirect
= $wgServer . $this->mRedirect
;
243 header( "Location: {$this->mRedirect}" );
247 $exp = time() +
$wgCookieExpiration;
248 foreach( $this->mCookies
as $name => $val ) {
249 setcookie( $name, $val, $exp, "/" );
252 $sk->outputPage( $this );
258 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
259 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
262 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
263 if ( false === $outs ) { $outs = $ins; }
268 function setEncodings()
270 global $wgInputEncoding, $wgOutputEncoding;
271 global $wgUser, $wgLang;
273 $wgInputEncoding = strtolower( $wgInputEncoding );
275 if( $wgUser->getOption( 'altencoding' ) ) {
276 $wgLang->setAltEncoding();
280 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
281 $wgOutputEncoding = strtolower( $wgOutputEncoding );
286 # This code is unused anyway!
287 # Commenting out. --bv 2003-11-15
289 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
293 foreach ( $a as $s ) {
294 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
306 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
307 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
308 $wgOutputEncoding = strtolower( $bestset );
313 $wgOutputEncoding = $wgInputEncoding;
316 # Returns a HTML comment with the elapsed time since request.
317 # This method has no side effects.
318 function reportTime()
320 global $wgRequestTime;
323 list( $usec, $sec ) = explode( " ", $wgRequestTime );
324 $start = (float)$sec +
(float)$usec;
325 $elapsed = $now - $start;
326 $com = sprintf( "<!-- Time since request: %01.2f secs. -->",
331 # Note: these arguments are keys into wfMsg(), not text!
333 function errorpage( $title, $msg )
337 $this->mDebugtext
.= "Original title: " .
338 $wgTitle->getPrefixedText() . "\n";
339 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
340 $this->setPageTitle( wfMsg( $title ) );
341 $this->setRobotpolicy( "noindex,nofollow" );
342 $this->setArticleRelated( false );
344 $this->mBodytext
= "";
345 $this->addHTML( "<p>" . wfMsg( $msg ) . "\n" );
346 $this->returnToMain( false );
352 function sysopRequired()
356 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
357 $this->setPageTitle( wfMsg( "sysoptitle" ) );
358 $this->setRobotpolicy( "noindex,nofollow" );
359 $this->setArticleRelated( false );
360 $this->mBodytext
= "";
362 $sk = $wgUser->getSkin();
363 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
364 $this->addHTML( wfMsg( "sysoptext", $ap ) );
365 $this->returnToMain();
368 function developerRequired()
372 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
373 $this->setPageTitle( wfMsg( "developertitle" ) );
374 $this->setRobotpolicy( "noindex,nofollow" );
375 $this->setArticleRelated( false );
376 $this->mBodytext
= "";
378 $sk = $wgUser->getSkin();
379 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
380 $this->addHTML( wfMsg( "developertext", $ap ) );
381 $this->returnToMain();
384 function databaseError( $fname, &$conn )
386 global $wgUser, $wgCommandLineMode;
388 $this->setPageTitle( wfMsgNoDB( "databaseerror" ) );
389 $this->setRobotpolicy( "noindex,nofollow" );
390 $this->setArticleRelated( false );
392 if ( $wgCommandLineMode ) {
393 $msg = wfMsgNoDB( "dberrortextcl" );
395 $msg = wfMsgNoDB( "dberrortext" );
398 $msg = str_replace( "$1", htmlspecialchars( $conn->lastQuery() ), $msg );
399 $msg = str_replace( "$2", htmlspecialchars( $fname ), $msg );
400 $msg = str_replace( "$3", $conn->lastErrno(), $msg );
401 $msg = str_replace( "$4", htmlspecialchars( $conn->lastError() ), $msg );
403 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
407 $sk = $wgUser->getSkin();
408 $shlink = $sk->makeKnownLink( wfMsgNoDB( "searchhelppage" ),
409 wfMsgNoDB( "searchingwikipedia" ) );
410 $msg = str_replace( "$5", $shlink, $msg );
411 $this->mBodytext
= $msg;
416 function readOnlyPage( $source = "", $protected = false )
418 global $wgUser, $wgReadOnlyFile;
420 $this->setRobotpolicy( "noindex,nofollow" );
421 $this->setArticleRelated( false );
424 $this->setPageTitle( wfMsg( "viewsource" ) );
425 $this->addWikiText( wfMsg( "protectedtext" ) );
427 $this->setPageTitle( wfMsg( "readonly" ) );
428 $reason = file_get_contents( $wgReadOnlyFile );
429 $this->addHTML( wfMsg( "readonlytext", $reason ) );
433 $rows = $wgUser->getOption( "rows" );
434 $cols = $wgUser->getOption( "cols" );
435 $text .= "</p>\n<textarea cols='$cols' rows='$rows' readonly>" .
436 htmlspecialchars( $source ) . "\n</textarea>";
437 $this->addHTML( $text );
440 $this->returnToMain( false );
443 function fatalError( $message )
445 $this->setPageTitle( wfMsg( "internalerror" ) );
446 $this->setRobotpolicy( "noindex,nofollow" );
447 $this->setArticleRelated( false );
449 $this->mBodytext
= $message;
454 function unexpectedValueError( $name, $val )
456 $this->fatalError( wfMsg( "unexpected", $name, $val ) );
459 function fileCopyError( $old, $new )
461 $this->fatalError( wfMsg( "filecopyerror", $old, $new ) );
464 function fileRenameError( $old, $new )
466 $this->fatalError( wfMsg( "filerenameerror", $old, $new ) );
469 function fileDeleteError( $name )
471 $this->fatalError( wfMsg( "filedeleteerror", $name ) );
474 function fileNotFoundError( $name )
476 $this->fatalError( wfMsg( "filenotfound", $name ) );
479 function returnToMain( $auto = true )
481 global $wgUser, $wgOut, $returnto;
483 $sk = $wgUser->getSkin();
484 if ( "" == $returnto ) {
485 $returnto = wfMsg( "mainpage" );
487 $link = $sk->makeKnownLink( $returnto, "" );
489 $r = wfMsg( "returnto", $link );
491 $wgOut->addMeta( "http:Refresh", "10;url=" .
492 wfLocalUrlE( wfUrlencode( $returnto ) ) );
494 $wgOut->addHTML( "\n<p>$r\n" );
497 /* private */ function headElement()
499 global $wgDocType, $wgDTD, $wgUser, $wgLanguageCode, $wgOutputEncoding, $wgLang;
501 $ret = "<!DOCTYPE HTML PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
503 if ( "" == $this->mHTMLtitle
) {
504 $this->mHTMLtitle
= $this->mPagetitle
;
506 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : "";
507 $ret .= "<html lang=\"$wgLanguageCode\"$rtl><head><title>{$this->mHTMLtitle}</title>\n";
508 array_push( $this->mMetatags
, array( "http:Content-type", "text/html; charset={$wgOutputEncoding}" ) );
509 foreach ( $this->mMetatags
as $tag ) {
510 if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
512 $tag[0] = substr( $tag[0], 5 );
516 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\">\n";
518 $p = $this->mRobotpolicy
;
519 if ( "" == $p ) { $p = "index,follow"; }
520 $ret .= "<meta name=\"robots\" content=\"$p\">\n";
522 if ( count( $this->mKeywords
) > 0 ) {
523 $ret .= "<meta name=\"keywords\" content=\"" .
524 implode( ",", $this->mKeywords
) . "\">\n";
526 foreach ( $this->mLinktags
as $tag ) {
528 if ( "" != $tag[0] ) { $ret .= "rel=\"{$tag[0]}\" "; }
529 if ( "" != $tag[1] ) { $ret .= "rev=\"{$tag[1]}\" "; }
530 $ret .= "href=\"{$tag[2]}\">\n";
532 $sk = $wgUser->getSkin();
533 $ret .= $sk->getHeadScripts();
534 $ret .= $sk->getUserStyles();