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