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