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