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