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 if( $this->mDoNothing
){
234 $fname = "OutputPage::output";
235 wfProfileIn( $fname );
237 $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->mRdirectCode
!= '302') {
247 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
248 $this->mLastModified
= gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
249 max( $timestamp, $wgUser->mTouched
) ) ) . " GMT";
252 $this->sendCacheControl();
254 header( "Location: {$this->mRedirect}" );
258 $this->sendCacheControl();
260 header( "Content-type: text/html; charset={$wgOutputEncoding}" );
261 header( "Content-language: {$wgLanguageCode}" );
263 $exp = time() +
$wgCookieExpiration;
264 foreach( $this->mCookies
as $name => $val ) {
265 setcookie( $name, $val, $exp, "/" );
268 $sk->outputPage( $this );
274 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
275 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
278 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
279 if ( false === $outs ) { $outs = $ins; }
284 function setEncodings()
286 global $wgInputEncoding, $wgOutputEncoding;
287 global $wgUser, $wgLang;
289 $wgInputEncoding = strtolower( $wgInputEncoding );
291 if( $wgUser->getOption( 'altencoding' ) ) {
292 $wgLang->setAltEncoding();
296 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
297 $wgOutputEncoding = strtolower( $wgOutputEncoding );
302 # This code is unused anyway!
303 # Commenting out. --bv 2003-11-15
305 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
309 foreach ( $a as $s ) {
310 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
322 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
323 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
324 $wgOutputEncoding = strtolower( $bestset );
329 $wgOutputEncoding = $wgInputEncoding;
332 # Returns a HTML comment with the elapsed time since request.
333 # This method has no side effects.
334 function reportTime()
336 global $wgRequestTime;
339 list( $usec, $sec ) = explode( " ", $wgRequestTime );
340 $start = (float)$sec +
(float)$usec;
341 $elapsed = $now - $start;
342 $com = sprintf( "<!-- Time since request: %01.2f secs. -->",
347 # Note: these arguments are keys into wfMsg(), not text!
349 function errorpage( $title, $msg )
353 $this->mDebugtext
.= "Original title: " .
354 $wgTitle->getPrefixedText() . "\n";
355 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
356 $this->setPageTitle( wfMsg( $title ) );
357 $this->setRobotpolicy( "noindex,nofollow" );
358 $this->setArticleRelated( false );
360 $this->mBodytext
= "";
361 $this->addHTML( "<p>" . wfMsg( $msg ) . "\n" );
362 $this->returnToMain( false );
368 function sysopRequired()
372 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
373 $this->setPageTitle( wfMsg( "sysoptitle" ) );
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( "sysoptext", $ap ) );
381 $this->returnToMain();
384 function developerRequired()
388 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
389 $this->setPageTitle( wfMsg( "developertitle" ) );
390 $this->setRobotpolicy( "noindex,nofollow" );
391 $this->setArticleRelated( false );
392 $this->mBodytext
= "";
394 $sk = $wgUser->getSkin();
395 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
396 $this->addHTML( wfMsg( "developertext", $ap ) );
397 $this->returnToMain();
400 function databaseError( $fname, &$conn )
402 global $wgUser, $wgCommandLineMode;
404 $this->setPageTitle( wfMsgNoDB( "databaseerror" ) );
405 $this->setRobotpolicy( "noindex,nofollow" );
406 $this->setArticleRelated( false );
408 if ( $wgCommandLineMode ) {
409 $msg = wfMsgNoDB( "dberrortextcl" );
411 $msg = wfMsgNoDB( "dberrortext" );
414 $msg = str_replace( "$1", htmlspecialchars( $conn->lastQuery() ), $msg );
415 $msg = str_replace( "$2", htmlspecialchars( $fname ), $msg );
416 $msg = str_replace( "$3", $conn->lastErrno(), $msg );
417 $msg = str_replace( "$4", htmlspecialchars( $conn->lastError() ), $msg );
419 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
423 $sk = $wgUser->getSkin();
424 $shlink = $sk->makeKnownLink( wfMsgNoDB( "searchhelppage" ),
425 wfMsgNoDB( "searchingwikipedia" ) );
426 $msg = str_replace( "$5", $shlink, $msg );
427 $this->mBodytext
= $msg;
432 function readOnlyPage( $source = "", $protected = false )
434 global $wgUser, $wgReadOnlyFile;
436 $this->setRobotpolicy( "noindex,nofollow" );
437 $this->setArticleRelated( false );
440 $this->setPageTitle( wfMsg( "viewsource" ) );
441 $this->addWikiText( wfMsg( "protectedtext" ) );
443 $this->setPageTitle( wfMsg( "readonly" ) );
444 $reason = file_get_contents( $wgReadOnlyFile );
445 $this->addHTML( wfMsg( "readonlytext", $reason ) );
449 $rows = $wgUser->getOption( "rows" );
450 $cols = $wgUser->getOption( "cols" );
451 $text .= "</p>\n<textarea cols='$cols' rows='$rows' readonly>" .
452 htmlspecialchars( $source ) . "\n</textarea>";
453 $this->addHTML( $text );
456 $this->returnToMain( false );
459 function fatalError( $message )
461 $this->setPageTitle( wfMsg( "internalerror" ) );
462 $this->setRobotpolicy( "noindex,nofollow" );
463 $this->setArticleRelated( false );
465 $this->mBodytext
= $message;
470 function unexpectedValueError( $name, $val )
472 $this->fatalError( wfMsg( "unexpected", $name, $val ) );
475 function fileCopyError( $old, $new )
477 $this->fatalError( wfMsg( "filecopyerror", $old, $new ) );
480 function fileRenameError( $old, $new )
482 $this->fatalError( wfMsg( "filerenameerror", $old, $new ) );
485 function fileDeleteError( $name )
487 $this->fatalError( wfMsg( "filedeleteerror", $name ) );
490 function fileNotFoundError( $name )
492 $this->fatalError( wfMsg( "filenotfound", $name ) );
495 function returnToMain( $auto = true )
497 global $wgUser, $wgOut, $returnto;
499 $sk = $wgUser->getSkin();
500 if ( "" == $returnto ) {
501 $returnto = wfMsg( "mainpage" );
503 $link = $sk->makeKnownLink( $returnto, "" );
505 $r = wfMsg( "returnto", $link );
507 $wgOut->addMeta( "http:Refresh", "10;url=" .
508 wfLocalUrlE( wfUrlencode( $returnto ) ) );
510 $wgOut->addHTML( "\n<p>$r\n" );
513 /* private */ function headElement()
515 global $wgDocType, $wgDTD, $wgUser, $wgLanguageCode, $wgOutputEncoding, $wgLang;
517 $ret = "<!DOCTYPE HTML PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
519 if ( "" == $this->mHTMLtitle
) {
520 $this->mHTMLtitle
= $this->mPagetitle
;
522 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : "";
523 $ret .= "<html lang=\"$wgLanguageCode\"$rtl><head><title>{$this->mHTMLtitle}</title>\n";
524 array_push( $this->mMetatags
, array( "http:Content-type", "text/html; charset={$wgOutputEncoding}" ) );
525 foreach ( $this->mMetatags
as $tag ) {
526 if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
528 $tag[0] = substr( $tag[0], 5 );
532 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\">\n";
534 $p = $this->mRobotpolicy
;
535 if ( "" == $p ) { $p = "index,follow"; }
536 $ret .= "<meta name=\"robots\" content=\"$p\">\n";
538 if ( count( $this->mKeywords
) > 0 ) {
539 $ret .= "<meta name=\"keywords\" content=\"" .
540 implode( ",", $this->mKeywords
) . "\">\n";
542 foreach ( $this->mLinktags
as $tag ) {
544 if ( "" != $tag[0] ) { $ret .= "rel=\"{$tag[0]}\" "; }
545 if ( "" != $tag[1] ) { $ret .= "rev=\"{$tag[1]}\" "; }
546 $ret .= "href=\"{$tag[2]}\">\n";
548 $sk = $wgUser->getSkin();
549 $ret .= $sk->getHeadScripts();
550 $ret .= $sk->getUserStyles();