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