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