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 function addMetadataLink( $type, $target ) {
50 static $haveMeta = false;
51 $this->addLink( ($haveMeta) ?
"alternate meta" : "meta", "", $target, $type );
55 # checkLastModified tells the client to use the client-cached page if
56 # possible. If sucessful, the OutputPage is disabled so that
57 # any future call to OutputPage->output() have no effect. The method
58 # returns true iff cache-ok headers was sent.
59 function checkLastModified ( $timestamp )
61 global $wgLang, $wgCachePages, $wgUser;
62 if( !$wgCachePages ) {
63 wfDebug( "CACHE DISABLED\n", false );
66 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
67 # IE 5.0 has probs with our caching
68 wfDebug( "-- bad client, not caching\n", false );
71 if( $wgUser->getOption( "nocache" ) ) {
72 wfDebug( "USER DISABLED CACHE\n", false );
76 $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
77 max( $timestamp, $wgUser->mTouched
) ) ) . " GMT";
79 if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
80 # IE sends sizes after the date like this:
81 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
82 # this breaks strtotime().
83 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
84 $ismodsince = wfUnix2Timestamp( strtotime( $modsince ) );
85 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
86 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
88 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
89 # Make sure you're in a place you can leave when you call us!
90 header( "HTTP/1.0 304 Not Modified" );
91 $this->mLastModified
= $lastmod;
92 $this->sendCacheControl();
93 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
97 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
98 $this->mLastModified
= $lastmod;
101 wfDebug( "We're confused.\n", false );
102 $this->mLastModified
= $lastmod;
106 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
107 function setHTMLtitle( $name ) { $this->mHTMLtitle
= $name; }
108 function setPageTitle( $name ) { $this->mPagetitle
= $name; }
109 function getPageTitle() { return $this->mPagetitle
; }
110 function setSubtitle( $str ) { $this->mSubtitle
= $str; }
111 function getSubtitle() { return $this->mSubtitle
; }
112 function isArticle() { return $this->mIsarticle
; }
113 function setPrintable() { $this->mPrintable
= true; }
114 function isPrintable() { return $this->mPrintable
; }
115 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
116 function isSyndicated() { return $this->mShowFeedLinks
; }
117 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
118 function getOnloadHandler() { return $this->mOnloadHandler
; }
119 function disable() { $this->mDoNothing
= true; }
121 function setArticleRelated( $v )
123 $this->mIsArticleRelated
= $v;
125 $this->mIsarticle
= false;
128 function setArticleFlag( $v ) {
129 $this->mIsarticle
= $v;
131 $this->mIsArticleRelated
= $v;
135 function isArticleRelated()
137 return $this->mIsArticleRelated
;
140 function getLanguageLinks() {
141 global $wgTitle, $wgLanguageCode;
142 global $wgDBconnection, $wgDBname;
143 return $this->mLanguageLinks
;
145 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
146 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
148 function addHTML( $text ) { $this->mBodytext
.= $text; }
149 function addHeadtext( $text ) { $this->mHeadtext
.= $text; }
150 function debug( $text ) { $this->mDebugtext
.= $text; }
152 function setParserOptions( $options )
154 return wfSetVar( $this->mParserOptions
, $options );
157 # First pass--just handle <nowiki> sections, pass the rest off
158 # to doWikiPass2() which does all the real work.
160 # $cacheArticle - assume this text is the main text for the given article
162 function addWikiText( $text, $linestart = true, $cacheArticle = NULL )
164 global $wgParser, $wgParserCache, $wgUser, $wgTitle;
166 $parserOutput = false;
167 if ( $cacheArticle ) {
168 $parserOutput = $wgParserCache->get( $cacheArticle, $wgUser );
171 if ( $parserOutput === false ) {
172 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
173 if ( $cacheArticle ) {
174 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
178 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
179 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
181 $this->addHTML( $parserOutput->getText() );
185 # Set the maximum cache time on the Squid in seconds
186 function setSquidMaxage( $maxage ) {
187 $this->mSquidMaxage
= $maxage;
190 # Use enableClientCache(false) to force it to send nocache headers
191 function enableClientCache( $state ) {
192 return wfSetVar( $this->mEnableClientCache
, $state );
195 function sendCacheControl() {
196 global $wgUseSquid, $wgUseESI;
197 # FIXME: This header may cause trouble with some versions of Internet Explorer
198 header( "Vary: Accept-Encoding, Cookie" );
199 if( $this->mEnableClientCache
&& $this->mLastModified
!= "" ) {
200 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( "session.name") ] ) &&
201 ! $this->isPrintable() )
204 # We'll purge the proxy cache explicitly, but require end user agents
205 # to revalidate against the proxy on each visit.
206 # Surrogate-Control controls our Squid, Cache-Control downstream caches
207 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
208 # start with a shorter timeout for initial testing
209 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
210 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
211 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
213 # We'll purge the proxy cache for anons explicitly, but require end user agents
214 # to revalidate against the proxy on each visit.
215 # IMPORTANT! The Squid needs to replace the Cache-Control header with
216 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
217 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
218 # start with a shorter timeout for initial testing
219 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
220 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
223 # We do want clients to cache if they can, but they *must* check for updates
224 # on revisiting the page.
225 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
226 header( "Expires: -1" );
227 header( "Cache-Control: private, must-revalidate, max-age=0" );
229 header( "Last-modified: {$this->mLastModified}" );
231 wfDebug( "** no caching **\n", false );
233 # In general, the absence of a last modified header should be enough to prevent
234 # the client from using its cache. We send a few other things just to make sure.
235 header( "Expires: -1" );
236 header( "Cache-Control: no-cache, no-store, max-age=0, must-revalidate" );
237 header( "Pragma: no-cache" );
241 # Finally, all the text has been munged and accumulated into
242 # the object, let's actually output it:
246 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
247 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
248 global $wgDebugRedirects, $wgMimeType;
249 if( $this->mDoNothing
){
252 $fname = "OutputPage::output";
253 wfProfileIn( $fname );
255 $sk = $wgUser->getSkin();
257 if ( "" != $this->mRedirect
) {
258 if( substr( $this->mRedirect
, 0, 4 ) != "http" ) {
259 # Standards require redirect URLs to be absolute
261 $this->mRedirect
= $wgServer . $this->mRedirect
;
263 if( $this->mRedirectCode
== '301') {
264 if( !$wgDebugRedirects ) {
265 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
267 $this->mLastModified
= gmdate( "D, j M Y H:i:s" ) . " GMT";
270 $this->sendCacheControl();
272 if( $wgDebugRedirects ) {
273 $url = htmlspecialchars( $this->mRedirect
);
274 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
275 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
276 print "</body>\n</html>\n";
278 header( "Location: {$this->mRedirect}" );
284 $this->sendCacheControl();
286 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
287 header( "Content-language: {$wgLanguageCode}" );
289 $exp = time() +
$wgCookieExpiration;
290 foreach( $this->mCookies
as $name => $val ) {
291 setcookie( $name, $val, $exp, "/" );
294 $sk->outputPage( $this );
300 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
301 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
304 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
305 if ( false === $outs ) { $outs = $ins; }
310 function setEncodings()
312 global $wgInputEncoding, $wgOutputEncoding;
313 global $wgUser, $wgLang;
315 $wgInputEncoding = strtolower( $wgInputEncoding );
317 if( $wgUser->getOption( 'altencoding' ) ) {
318 $wgLang->setAltEncoding();
322 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
323 $wgOutputEncoding = strtolower( $wgOutputEncoding );
328 # This code is unused anyway!
329 # Commenting out. --bv 2003-11-15
331 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
335 foreach ( $a as $s ) {
336 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
348 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
349 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
350 $wgOutputEncoding = strtolower( $bestset );
355 $wgOutputEncoding = $wgInputEncoding;
358 # Returns a HTML comment with the elapsed time since request.
359 # This method has no side effects.
360 function reportTime()
362 global $wgRequestTime;
365 list( $usec, $sec ) = explode( " ", $wgRequestTime );
366 $start = (float)$sec +
(float)$usec;
367 $elapsed = $now - $start;
368 $com = sprintf( "<!-- Time since request: %01.2f secs. -->",
373 # Note: these arguments are keys into wfMsg(), not text!
375 function errorpage( $title, $msg )
379 $this->mDebugtext
.= "Original title: " .
380 $wgTitle->getPrefixedText() . "\n";
381 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
382 $this->setPageTitle( wfMsg( $title ) );
383 $this->setRobotpolicy( "noindex,nofollow" );
384 $this->setArticleRelated( false );
385 $this->enableClientCache( false );
387 $this->mBodytext
= "";
388 $this->addHTML( "<p>" . wfMsg( $msg ) . "\n" );
389 $this->returnToMain( false );
395 function sysopRequired()
399 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
400 $this->setPageTitle( wfMsg( "sysoptitle" ) );
401 $this->setRobotpolicy( "noindex,nofollow" );
402 $this->setArticleRelated( false );
403 $this->mBodytext
= "";
405 $sk = $wgUser->getSkin();
406 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
407 $this->addHTML( wfMsg( "sysoptext", $ap ) );
408 $this->returnToMain();
411 function developerRequired()
415 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
416 $this->setPageTitle( wfMsg( "developertitle" ) );
417 $this->setRobotpolicy( "noindex,nofollow" );
418 $this->setArticleRelated( false );
419 $this->mBodytext
= "";
421 $sk = $wgUser->getSkin();
422 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
423 $this->addHTML( wfMsg( "developertext", $ap ) );
424 $this->returnToMain();
427 function loginToUse()
429 global $wgUser, $wgTitle, $wgLang;
431 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
432 $this->setPageTitle( wfMsg( "loginreqtitle" ) );
433 $this->setRobotpolicy( "noindex,nofollow" );
434 $this->setArticleFlag( false );
435 $this->mBodytext
= "";
436 $this->addWikiText( wfMsg( "loginreqtext" ) );
438 # We put a comment in the .html file so a Sysop can diagnose the page the
440 $this->addHTML( "\n<!--" .
441 $wgLang->getNsText( $wgTitle->getNamespace() ) .
443 $wgTitle->getDBkey() . "-->" );
444 $this->returnToMain(); # Flip back to the main page after 10 seconds.
447 function databaseError( $fname, &$conn )
449 global $wgUser, $wgCommandLineMode;
451 $this->setPageTitle( wfMsgNoDB( "databaseerror" ) );
452 $this->setRobotpolicy( "noindex,nofollow" );
453 $this->setArticleRelated( false );
454 $this->enableClientCache( false );
456 if ( $wgCommandLineMode ) {
457 $msg = wfMsgNoDB( "dberrortextcl" );
459 $msg = wfMsgNoDB( "dberrortext" );
462 $msg = str_replace( "$1", htmlspecialchars( $conn->lastQuery() ), $msg );
463 $msg = str_replace( "$2", htmlspecialchars( $fname ), $msg );
464 $msg = str_replace( "$3", $conn->lastErrno(), $msg );
465 $msg = str_replace( "$4", htmlspecialchars( $conn->lastError() ), $msg );
467 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
471 $sk = $wgUser->getSkin();
472 $shlink = $sk->makeKnownLink( wfMsgNoDB( "searchhelppage" ),
473 wfMsgNoDB( "searchingwikipedia" ) );
474 $msg = str_replace( "$5", $shlink, $msg );
475 $this->mBodytext
= $msg;
480 function readOnlyPage( $source = "", $protected = false )
482 global $wgUser, $wgReadOnlyFile;
484 $this->setRobotpolicy( "noindex,nofollow" );
485 $this->setArticleRelated( false );
488 $this->setPageTitle( wfMsg( "viewsource" ) );
489 $this->addWikiText( wfMsg( "protectedtext" ) );
491 $this->setPageTitle( wfMsg( "readonly" ) );
492 $reason = file_get_contents( $wgReadOnlyFile );
493 $this->addHTML( wfMsg( "readonlytext", $reason ) );
497 $rows = $wgUser->getOption( "rows" );
498 $cols = $wgUser->getOption( "cols" );
499 $text .= "</p>\n<textarea cols='$cols' rows='$rows' readonly>" .
500 htmlspecialchars( $source ) . "\n</textarea>";
501 $this->addHTML( $text );
504 $this->returnToMain( false );
507 function fatalError( $message )
509 $this->setPageTitle( wfMsg( "internalerror" ) );
510 $this->setRobotpolicy( "noindex,nofollow" );
511 $this->setArticleRelated( false );
512 $this->enableClientCache( false );
514 $this->mBodytext
= $message;
519 function unexpectedValueError( $name, $val )
521 $this->fatalError( wfMsg( "unexpected", $name, $val ) );
524 function fileCopyError( $old, $new )
526 $this->fatalError( wfMsg( "filecopyerror", $old, $new ) );
529 function fileRenameError( $old, $new )
531 $this->fatalError( wfMsg( "filerenameerror", $old, $new ) );
534 function fileDeleteError( $name )
536 $this->fatalError( wfMsg( "filedeleteerror", $name ) );
539 function fileNotFoundError( $name )
541 $this->fatalError( wfMsg( "filenotfound", $name ) );
544 function returnToMain( $auto = true, $returnto = NULL )
546 global $wgUser, $wgOut, $wgRequest;
548 if ( $returnto == NULL ) {
549 $returnto = $wgRequest->getText( 'returnto' );
552 $sk = $wgUser->getSkin();
553 if ( "" == $returnto ) {
554 $returnto = wfMsg( "mainpage" );
556 $link = $sk->makeKnownLink( $returnto, "" );
558 $r = wfMsg( "returnto", $link );
560 $titleObj = Title
::newFromText( $returnto );
561 $wgOut->addMeta( "http:Refresh", "10;url=" . $titleObj->escapeFullURL() );
563 $wgOut->addHTML( "\n<p>$r</p>\n" );
566 # This function takes the existing and broken links for the page
567 # and uses the first 10 of them for META keywords
568 function addMetaTags ()
570 global $wgLinkCache , $wgOut ;
571 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
572 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
573 $a = array_merge ( $good , $bad ) ;
574 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
575 $a = implode ( "," , $a ) ;
576 $wgOut->addMeta ( "KEYWORDS" , $a ) ;
579 /* private */ function headElement()
581 global $wgDocType, $wgDTD, $wgLanguageCode, $wgOutputEncoding, $wgMimeType;
582 global $wgUser, $wgLang, $wgRequest;
584 $xml = ($wgMimeType == 'text/xml');
586 $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
591 $ret .= "<!DOCTYPE HTML PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
593 if ( "" == $this->mHTMLtitle
) {
594 $this->mHTMLtitle
= $this->mPagetitle
;
597 $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
601 $rtl = $wgLang->isRTL() ?
" dir='RTL'" : "";
602 $ret .= "<html $xmlbits lang=\"$wgLanguageCode\" $rtl>\n";
603 $ret .= "<head>\n<title>{$this->mHTMLtitle}</title>\n";
604 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
605 foreach ( $this->mMetatags
as $tag ) {
606 if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
608 $tag[0] = substr( $tag[0], 5 );
612 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
614 $p = $this->mRobotpolicy
;
615 if ( "" == $p ) { $p = "index,follow"; }
616 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
618 if ( count( $this->mKeywords
) > 0 ) {
619 $ret .= "<meta name=\"keywords\" content=\"" .
620 implode( ",", $this->mKeywords
) . "\" />\n";
622 foreach ( $this->mLinktags
as $tag ) {
624 if ( "" != $tag[0] ) { $ret .= "rel=\"{$tag[0]}\" "; }
625 if ( "" != $tag[1] ) { $ret .= "rev=\"{$tag[1]}\" "; }
626 if ( !empty( $tag[3] ) ) { $ret .= "type=\"{$tag[3]}\" "; }
627 if ( !empty( $tag[4] ) ) { $ret .= "media=\"{$tag[4]}\" "; }
628 $ret .= "href=\"{$tag[2]}\" />\n";
630 if( $this->isSyndicated() ) {
631 $link = $wgRequest->escapeAppendQuery( "feed=rss" );
632 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS' href='$link' />\n";
634 global $wgStyleSheetPath;
635 if( $this->isPrintable() ) {
638 $media = "media='print'";
640 $printsheet = htmlspecialchars( "$wgStyleSheetPath/wikiprintable.css" );
641 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
643 $sk = $wgUser->getSkin();
644 $ret .= $sk->getHeadScripts();
645 $ret .= $sk->getUserStyles();