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