include_once -> require_once
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 # See design.doc
3
4 if($wgUseTeX) require_once( "Math.php" );
5
6 class OutputPage {
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;
12
13 var $mSuppressQuickbar;
14 var $mOnloadHandler;
15 var $mDoNothing;
16 var $mContainsOldMagic, $mContainsNewMagic;
17 var $mIsArticleRelated;
18 var $mParserOptions;
19 var $mShowFeedLinks = false;
20 var $mEnableClientCache = true;
21
22 function OutputPage()
23 {
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;
38 }
39
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; }
43
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
48 function addLink( $linkarr ) {
49 # $linkarr should be an associative array of attributes. We'll escape on output.
50 array_push( $this->mLinktags, $linkarr );
51 }
52
53 function addMetadataLink( $linkarr ) {
54 # note: buggy CC software only reads first "meta" link
55 static $haveMeta = false;
56 $linkarr["rel"] = ($haveMeta) ? "alternate meta" : "meta";
57 $this->addLink( $linkarr );
58 $haveMeta = true;
59 }
60
61 # checkLastModified tells the client to use the client-cached page if
62 # possible. If sucessful, the OutputPage is disabled so that
63 # any future call to OutputPage->output() have no effect. The method
64 # returns true iff cache-ok headers was sent.
65 function checkLastModified ( $timestamp )
66 {
67 global $wgLang, $wgCachePages, $wgUser;
68 if( !$wgCachePages ) {
69 wfDebug( "CACHE DISABLED\n", false );
70 return;
71 }
72 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
73 # IE 5.0 has probs with our caching
74 wfDebug( "-- bad client, not caching\n", false );
75 return;
76 }
77 if( $wgUser->getOption( "nocache" ) ) {
78 wfDebug( "USER DISABLED CACHE\n", false );
79 return;
80 }
81
82 $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix(
83 max( $timestamp, $wgUser->mTouched ) ) ) . " GMT";
84
85 if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
86 # IE sends sizes after the date like this:
87 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
88 # this breaks strtotime().
89 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
90 $ismodsince = wfUnix2Timestamp( strtotime( $modsince ) );
91 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
92 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
93
94 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
95 # Make sure you're in a place you can leave when you call us!
96 header( "HTTP/1.0 304 Not Modified" );
97 $this->mLastModified = $lastmod;
98 $this->sendCacheControl();
99 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
100 $this->disable();
101 return true;
102 } else {
103 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
104 $this->mLastModified = $lastmod;
105 }
106 } else {
107 wfDebug( "We're confused.\n", false );
108 $this->mLastModified = $lastmod;
109 }
110 }
111
112 function getPageTitleActionText () {
113 global $action;
114 switch($action) {
115 case 'edit':
116 return wfMsg('edit');
117 case 'history':
118 return wfMsg('history_short');
119 case 'protect':
120 return wfMsg('unprotect');
121 case 'unprotect':
122 return wfMsg('unprotect');
123 case 'delete':
124 return wfMsg('delete');
125 case 'watch':
126 return wfMsg('watch');
127 case 'unwatch':
128 return wfMsg('unwatch');
129 case 'submit':
130 return wfMsg('preview');
131 default:
132 return '';
133 }
134 }
135 function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
136 function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
137 function setPageTitle( $name ) {
138 global $action;
139 $this->mPagetitle = $name;
140 if(!empty($action)) {
141 $taction = $this->getPageTitleActionText();
142 if( !empty( $taction ) ) {
143 $name .= " - $taction";
144 }
145 }
146 $this->setHTMLTitle( $name . " - " . wfMsg( "wikititlesuffix" ) );
147 }
148 function getHTMLTitle() { return $this->mHTMLtitle; }
149 function getPageTitle() { return $this->mPagetitle; }
150 function setSubtitle( $str ) { $this->mSubtitle = $str; }
151 function getSubtitle() { return $this->mSubtitle; }
152 function isArticle() { return $this->mIsarticle; }
153 function setPrintable() { $this->mPrintable = true; }
154 function isPrintable() { return $this->mPrintable; }
155 function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
156 function isSyndicated() { return $this->mShowFeedLinks; }
157 function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
158 function getOnloadHandler() { return $this->mOnloadHandler; }
159 function disable() { $this->mDoNothing = true; }
160
161 function setArticleRelated( $v )
162 {
163 $this->mIsArticleRelated = $v;
164 if ( !$v ) {
165 $this->mIsarticle = false;
166 }
167 }
168 function setArticleFlag( $v ) {
169 $this->mIsarticle = $v;
170 if ( $v ) {
171 $this->mIsArticleRelated = $v;
172 }
173 }
174
175 function isArticleRelated()
176 {
177 return $this->mIsArticleRelated;
178 }
179
180 function getLanguageLinks() {
181 global $wgTitle, $wgLanguageCode;
182 global $wgDBconnection, $wgDBname;
183 return $this->mLanguageLinks;
184 }
185 function suppressQuickbar() { $this->mSuppressQuickbar = true; }
186 function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
187
188 function addHTML( $text ) { $this->mBodytext .= $text; }
189 function addHeadtext( $text ) { $this->mHeadtext .= $text; }
190 function debug( $text ) { $this->mDebugtext .= $text; }
191
192 function setParserOptions( $options )
193 {
194 return wfSetVar( $this->mParserOptions, $options );
195 }
196
197 # First pass--just handle <nowiki> sections, pass the rest off
198 # to doWikiPass2() which does all the real work.
199 #
200 # $cacheArticle - assume this text is the main text for the given article
201 #
202 function addWikiText( $text, $linestart = true, $cacheArticle = NULL )
203 {
204 global $wgParser, $wgParserCache, $wgUser, $wgTitle;
205
206 $parserOutput = false;
207 if ( $cacheArticle ) {
208 $parserOutput = $wgParserCache->get( $cacheArticle, $wgUser );
209 }
210
211 if ( $parserOutput === false ) {
212 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
213 if ( $cacheArticle ) {
214 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
215 }
216 }
217
218 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
219 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
220
221 $this->addHTML( $parserOutput->getText() );
222
223 }
224
225 # Set the maximum cache time on the Squid in seconds
226 function setSquidMaxage( $maxage ) {
227 $this->mSquidMaxage = $maxage;
228 }
229
230 # Use enableClientCache(false) to force it to send nocache headers
231 function enableClientCache( $state ) {
232 return wfSetVar( $this->mEnableClientCache, $state );
233 }
234
235 function sendCacheControl() {
236 global $wgUseSquid, $wgUseESI;
237 # FIXME: This header may cause trouble with some versions of Internet Explorer
238 header( "Vary: Accept-Encoding, Cookie" );
239 if( $this->mEnableClientCache && $this->mLastModified != "" ) {
240 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( "session.name") ] ) &&
241 ! $this->isPrintable() )
242 {
243 if ( $wgUseESI ) {
244 # We'll purge the proxy cache explicitly, but require end user agents
245 # to revalidate against the proxy on each visit.
246 # Surrogate-Control controls our Squid, Cache-Control downstream caches
247 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
248 # start with a shorter timeout for initial testing
249 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
250 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
251 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
252 } else {
253 # We'll purge the proxy cache for anons explicitly, but require end user agents
254 # to revalidate against the proxy on each visit.
255 # IMPORTANT! The Squid needs to replace the Cache-Control header with
256 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
257 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
258 # start with a shorter timeout for initial testing
259 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
260 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
261 }
262 } else {
263 # We do want clients to cache if they can, but they *must* check for updates
264 # on revisiting the page.
265 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
266 header( "Expires: -1" );
267 header( "Cache-Control: private, must-revalidate, max-age=0" );
268 }
269 header( "Last-modified: {$this->mLastModified}" );
270 } else {
271 wfDebug( "** no caching **\n", false );
272
273 # In general, the absence of a last modified header should be enough to prevent
274 # the client from using its cache. We send a few other things just to make sure.
275 header( "Expires: -1" );
276 header( "Cache-Control: no-cache, no-store, max-age=0, must-revalidate" );
277 header( "Pragma: no-cache" );
278 }
279 }
280
281 # Finally, all the text has been munged and accumulated into
282 # the object, let's actually output it:
283 #
284 function output()
285 {
286 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
287 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
288 global $wgDebugRedirects, $wgMimeType;
289 if( $this->mDoNothing ){
290 return;
291 }
292 $fname = "OutputPage::output";
293 wfProfileIn( $fname );
294
295 $sk = $wgUser->getSkin();
296
297 if ( "" != $this->mRedirect ) {
298 if( substr( $this->mRedirect, 0, 4 ) != "http" ) {
299 # Standards require redirect URLs to be absolute
300 global $wgServer;
301 $this->mRedirect = $wgServer . $this->mRedirect;
302 }
303 if( $this->mRedirectCode == '301') {
304 if( !$wgDebugRedirects ) {
305 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
306 }
307 $this->mLastModified = gmdate( "D, j M Y H:i:s" ) . " GMT";
308 }
309
310 $this->sendCacheControl();
311
312 if( $wgDebugRedirects ) {
313 $url = htmlspecialchars( $this->mRedirect );
314 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
315 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
316 print "</body>\n</html>\n";
317 } else {
318 header( "Location: {$this->mRedirect}" );
319 }
320 return;
321 }
322
323
324 $this->sendCacheControl();
325
326 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
327 header( "Content-language: {$wgLanguageCode}" );
328
329 $exp = time() + $wgCookieExpiration;
330 foreach( $this->mCookies as $name => $val ) {
331 setcookie( $name, $val, $exp, "/" );
332 }
333
334 $sk->outputPage( $this );
335 # flush();
336 }
337
338 function out( $ins )
339 {
340 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
341 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
342 $outs = $ins;
343 } else {
344 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
345 if ( false === $outs ) { $outs = $ins; }
346 }
347 print $outs;
348 }
349
350 function setEncodings()
351 {
352 global $wgInputEncoding, $wgOutputEncoding;
353 global $wgUser, $wgLang;
354
355 $wgInputEncoding = strtolower( $wgInputEncoding );
356
357 if( $wgUser->getOption( 'altencoding' ) ) {
358 $wgLang->setAltEncoding();
359 return;
360 }
361
362 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
363 $wgOutputEncoding = strtolower( $wgOutputEncoding );
364 return;
365 }
366
367 /*
368 # This code is unused anyway!
369 # Commenting out. --bv 2003-11-15
370
371 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
372 $best = 0.0;
373 $bestset = "*";
374
375 foreach ( $a as $s ) {
376 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
377 $set = $m[1];
378 $q = (float)($m[2]);
379 } else {
380 $set = $s;
381 $q = 1.0;
382 }
383 if ( $q > $best ) {
384 $bestset = $set;
385 $best = $q;
386 }
387 }
388 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
389 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
390 $wgOutputEncoding = strtolower( $bestset );
391
392 # Disable for now
393 #
394 */
395 $wgOutputEncoding = $wgInputEncoding;
396 }
397
398 # Returns a HTML comment with the elapsed time since request.
399 # This method has no side effects.
400 function reportTime()
401 {
402 global $wgRequestTime;
403
404 $now = wfTime();
405 list( $usec, $sec ) = explode( " ", $wgRequestTime );
406 $start = (float)$sec + (float)$usec;
407 $elapsed = $now - $start;
408 $com = sprintf( "<!-- Time since request: %01.2f secs. -->",
409 $elapsed );
410 return $com;
411 }
412
413 # Note: these arguments are keys into wfMsg(), not text!
414 #
415 function errorpage( $title, $msg )
416 {
417 global $wgTitle;
418
419 $this->mDebugtext .= "Original title: " .
420 $wgTitle->getPrefixedText() . "\n";
421 $this->setPageTitle( wfMsg( $title ) );
422 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
423 $this->setRobotpolicy( "noindex,nofollow" );
424 $this->setArticleRelated( false );
425 $this->enableClientCache( false );
426
427 $this->mBodytext = "";
428 $this->addHTML( "<p>" . wfMsg( $msg ) . "</p>\n" );
429 $this->returnToMain( false );
430
431 $this->output();
432 wfAbruptExit();
433 }
434
435 function sysopRequired()
436 {
437 global $wgUser;
438
439 $this->setPageTitle( wfMsg( "sysoptitle" ) );
440 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
441 $this->setRobotpolicy( "noindex,nofollow" );
442 $this->setArticleRelated( false );
443 $this->mBodytext = "";
444
445 $sk = $wgUser->getSkin();
446 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
447 $this->addHTML( wfMsg( "sysoptext", $ap ) );
448 $this->returnToMain();
449 }
450
451 function developerRequired()
452 {
453 global $wgUser;
454
455 $this->setPageTitle( wfMsg( "developertitle" ) );
456 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
457 $this->setRobotpolicy( "noindex,nofollow" );
458 $this->setArticleRelated( false );
459 $this->mBodytext = "";
460
461 $sk = $wgUser->getSkin();
462 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
463 $this->addHTML( wfMsg( "developertext", $ap ) );
464 $this->returnToMain();
465 }
466
467 function loginToUse()
468 {
469 global $wgUser, $wgTitle, $wgLang;
470
471 $this->setPageTitle( wfMsg( "loginreqtitle" ) );
472 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
473 $this->setRobotpolicy( "noindex,nofollow" );
474 $this->setArticleFlag( false );
475 $this->mBodytext = "";
476 $this->addWikiText( wfMsg( "loginreqtext" ) );
477
478 # We put a comment in the .html file so a Sysop can diagnose the page the
479 # user can't see.
480 $this->addHTML( "\n<!--" .
481 $wgLang->getNsText( $wgTitle->getNamespace() ) .
482 ":" .
483 $wgTitle->getDBkey() . "-->" );
484 $this->returnToMain(); # Flip back to the main page after 10 seconds.
485 }
486
487 function databaseError( $fname, &$conn )
488 {
489 global $wgUser, $wgCommandLineMode;
490
491 $this->setPageTitle( wfMsgNoDB( "databaseerror" ) );
492 $this->setRobotpolicy( "noindex,nofollow" );
493 $this->setArticleRelated( false );
494 $this->enableClientCache( false );
495
496 if ( $wgCommandLineMode ) {
497 $msg = wfMsgNoDB( "dberrortextcl" );
498 } else {
499 $msg = wfMsgNoDB( "dberrortext" );
500 }
501
502 $msg = str_replace( "$1", htmlspecialchars( $conn->lastQuery() ), $msg );
503 $msg = str_replace( "$2", htmlspecialchars( $fname ), $msg );
504 $msg = str_replace( "$3", $conn->lastErrno(), $msg );
505 $msg = str_replace( "$4", htmlspecialchars( $conn->lastError() ), $msg );
506
507 if ( $wgCommandLineMode || !is_object( $wgUser )) {
508 print "$msg\n";
509 wfAbruptExit();
510 }
511 $sk = $wgUser->getSkin();
512 $shlink = $sk->makeKnownLink( wfMsgNoDB( "searchhelppage" ),
513 wfMsgNoDB( "searchingwikipedia" ) );
514 $msg = str_replace( "$5", $shlink, $msg );
515 $this->mBodytext = $msg;
516 $this->output();
517 wfAbruptExit();
518 }
519
520 function readOnlyPage( $source = null, $protected = false )
521 {
522 global $wgUser, $wgReadOnlyFile;
523
524 $this->setRobotpolicy( "noindex,nofollow" );
525 $this->setArticleRelated( false );
526
527 if( $protected ) {
528 $this->setPageTitle( wfMsg( "viewsource" ) );
529 $this->addWikiText( wfMsg( "protectedtext" ) );
530 } else {
531 $this->setPageTitle( wfMsg( "readonly" ) );
532 $reason = file_get_contents( $wgReadOnlyFile );
533 $this->addWikiText( wfMsg( "readonlytext", $reason ) );
534 }
535
536 if( is_string( $source ) ) {
537 if( strcmp( $source, "" ) == 0 ) {
538 $source = wfMsg( "noarticletext" );
539 }
540 $rows = $wgUser->getOption( "rows" );
541 $cols = $wgUser->getOption( "cols" );
542 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
543 htmlspecialchars( $source ) . "\n</textarea>";
544 $this->addHTML( $text );
545 }
546
547 $this->returnToMain( false );
548 }
549
550 function fatalError( $message )
551 {
552 $this->setPageTitle( wfMsg( "internalerror" ) );
553 $this->setRobotpolicy( "noindex,nofollow" );
554 $this->setArticleRelated( false );
555 $this->enableClientCache( false );
556
557 $this->mBodytext = $message;
558 $this->output();
559 wfAbruptExit();
560 }
561
562 function unexpectedValueError( $name, $val )
563 {
564 $this->fatalError( wfMsg( "unexpected", $name, $val ) );
565 }
566
567 function fileCopyError( $old, $new )
568 {
569 $this->fatalError( wfMsg( "filecopyerror", $old, $new ) );
570 }
571
572 function fileRenameError( $old, $new )
573 {
574 $this->fatalError( wfMsg( "filerenameerror", $old, $new ) );
575 }
576
577 function fileDeleteError( $name )
578 {
579 $this->fatalError( wfMsg( "filedeleteerror", $name ) );
580 }
581
582 function fileNotFoundError( $name )
583 {
584 $this->fatalError( wfMsg( "filenotfound", $name ) );
585 }
586
587 function returnToMain( $auto = true, $returnto = NULL )
588 {
589 global $wgUser, $wgOut, $wgRequest;
590
591 if ( $returnto == NULL ) {
592 $returnto = $wgRequest->getText( 'returnto' );
593 }
594
595 $sk = $wgUser->getSkin();
596 if ( "" == $returnto ) {
597 $returnto = wfMsg( "mainpage" );
598 }
599 $link = $sk->makeKnownLink( $returnto, "" );
600
601 $r = wfMsg( "returnto", $link );
602 if ( $auto ) {
603 $titleObj = Title::newFromText( $returnto );
604 $wgOut->addMeta( "http:Refresh", "10;url=" . $titleObj->escapeFullURL() );
605 }
606 $wgOut->addHTML( "\n<p>$r</p>\n" );
607 }
608
609 # This function takes the existing and broken links for the page
610 # and uses the first 10 of them for META keywords
611 function addMetaTags ()
612 {
613 global $wgLinkCache , $wgOut ;
614 $good = array_keys ( $wgLinkCache->mGoodLinks ) ;
615 $bad = array_keys ( $wgLinkCache->mBadLinks ) ;
616 $a = array_merge ( $good , $bad ) ;
617 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
618 $a = implode ( "," , $a ) ;
619 $strip = array(
620 "/<.*?>/" => '',
621 "/[_]/" => ' '
622 );
623 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
624
625 $wgOut->addMeta ( "KEYWORDS" , $a ) ;
626 }
627
628 /* private */ function headElement()
629 {
630 global $wgDocType, $wgDTD, $wgLanguageCode, $wgOutputEncoding, $wgMimeType;
631 global $wgUser, $wgLang, $wgRequest;
632
633 $xml = ($wgMimeType == 'text/xml');
634 if( $xml ) {
635 $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
636 } else {
637 $ret = "";
638 }
639
640 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
641
642 if ( "" == $this->mHTMLtitle ) {
643 $this->mHTMLtitle = wfMsg( "pagetitle", $this->mPagetitle );
644 }
645 if( $xml ) {
646 $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
647 } else {
648 $xmlbits = "";
649 }
650 $rtl = $wgLang->isRTL() ? " dir='RTL'" : "";
651 $ret .= "<html $xmlbits lang=\"$wgLanguageCode\" $rtl>\n";
652 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle ) . "</title>\n";
653 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
654
655 $ret .= $this->getHeadLinks();
656 global $wgStylePath;
657 if( $this->isPrintable() ) {
658 $media = "";
659 } else {
660 $media = "media='print'";
661 }
662 $printsheet = htmlspecialchars( "$wgStylePath/wikiprintable.css" );
663 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
664
665 $sk = $wgUser->getSkin();
666 $ret .= $sk->getHeadScripts();
667 $ret .= $sk->getUserStyles();
668
669 $ret .= "</head>\n";
670 return $ret;
671 }
672
673 function getHeadLinks() {
674 global $wgRequest, $wgStylePath;
675 $ret = "";
676 foreach ( $this->mMetatags as $tag ) {
677 if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
678 $a = "http-equiv";
679 $tag[0] = substr( $tag[0], 5 );
680 } else {
681 $a = "name";
682 }
683 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
684 }
685 $p = $this->mRobotpolicy;
686 if ( "" == $p ) { $p = "index,follow"; }
687 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
688
689 if ( count( $this->mKeywords ) > 0 ) {
690 $strip = array(
691 "/<.*?>/" => '',
692 "/[_]/" => ' '
693 );
694 $ret .= "<meta name=\"keywords\" content=\"" .
695 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
696 }
697 foreach ( $this->mLinktags as $tag ) {
698 $ret .= "<link";
699 foreach( $tag as $attr => $val ) {
700 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
701 }
702 $ret .= " />\n";
703 }
704 if( $this->isSyndicated() ) {
705 # FIXME: centralize the mime-type and name information in Feed.php
706 $link = $wgRequest->escapeAppendQuery( "feed=rss" );
707 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
708 $link = $wgRequest->escapeAppendQuery( "feed=atom" );
709 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
710 }
711 # FIXME: get these working
712 # $fix = htmlspecialchars( $wgStylePath . "/ie-png-fix.js" );
713 # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'></script><![endif]-->";
714 return $ret;
715 }
716 }
717 ?>