Suppress some more warnings on separate execution of files. Shouldn't
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 if( defined( "MEDIAWIKI" ) ) {
3
4 # See design.doc
5
6 if($wgUseTeX) require_once( "Math.php" );
7
8 class OutputPage {
9 var $mHeaders, $mCookies, $mMetatags, $mKeywords;
10 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
11 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
12 var $mSubtitle, $mRedirect;
13 var $mLastModified, $mCategoryLinks;
14 var $mScripts;
15
16 var $mSuppressQuickbar;
17 var $mOnloadHandler;
18 var $mDoNothing;
19 var $mContainsOldMagic, $mContainsNewMagic;
20 var $mIsArticleRelated;
21 var $mParserOptions;
22 var $mShowFeedLinks = false;
23 var $mEnableClientCache = true;
24
25 function OutputPage()
26 {
27 $this->mHeaders = $this->mCookies = $this->mMetatags =
28 $this->mKeywords = $this->mLinktags = array();
29 $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
30 $this->mRedirect = $this->mLastModified =
31 $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
32 $this->mOnloadHandler = "";
33 $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
34 $this->mSuppressQuickbar = $this->mPrintable = false;
35 $this->mLanguageLinks = array();
36 $this->mCategoryLinks = array() ;
37 $this->mDoNothing = false;
38 $this->mContainsOldMagic = $this->mContainsNewMagic = 0;
39 $this->mParserOptions = ParserOptions::newFromUser( $temp = NULL );
40 $this->mSquidMaxage = 0;
41 $this->mScripts = "";
42 }
43
44 function addHeader( $name, $val ) { array_push( $this->mHeaders, "$name: $val" ) ; }
45 function addCookie( $name, $val ) { array_push( $this->mCookies, array( $name, $val ) ); }
46 function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $url; $this->mRedirectCode = $responsecode; }
47
48 # To add an http-equiv meta tag, precede the name with "http:"
49 function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
50 function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
51 function addScript( $script ) { $this->mScripts .= $script; }
52 function getScript() { return $this->mScripts; }
53
54 function addLink( $linkarr ) {
55 # $linkarr should be an associative array of attributes. We'll escape on output.
56 array_push( $this->mLinktags, $linkarr );
57 }
58
59 function addMetadataLink( $linkarr ) {
60 # note: buggy CC software only reads first "meta" link
61 static $haveMeta = false;
62 $linkarr["rel"] = ($haveMeta) ? "alternate meta" : "meta";
63 $this->addLink( $linkarr );
64 $haveMeta = true;
65 }
66
67 # checkLastModified tells the client to use the client-cached page if
68 # possible. If sucessful, the OutputPage is disabled so that
69 # any future call to OutputPage->output() have no effect. The method
70 # returns true iff cache-ok headers was sent.
71 function checkLastModified ( $timestamp )
72 {
73 global $wgLang, $wgCachePages, $wgUser;
74 if( !$wgCachePages ) {
75 wfDebug( "CACHE DISABLED\n", false );
76 return;
77 }
78 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
79 # IE 5.0 has probs with our caching
80 wfDebug( "-- bad client, not caching\n", false );
81 return;
82 }
83 if( $wgUser->getOption( "nocache" ) ) {
84 wfDebug( "USER DISABLED CACHE\n", false );
85 return;
86 }
87
88 $lastmod = gmdate( "D, j M Y H:i:s", wfTimestamp2Unix( max( $timestamp, $wgUser->mTouched ) ) ) . " GMT";
89
90 if( !empty( $_SERVER["HTTP_IF_MODIFIED_SINCE"] ) ) {
91 # IE sends sizes after the date like this:
92 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
93 # this breaks strtotime().
94 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
95 $ismodsince = wfUnix2Timestamp( strtotime( $modsince ) );
96 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
97 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
98
99 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
100 # Make sure you're in a place you can leave when you call us!
101 header( "HTTP/1.0 304 Not Modified" );
102 $this->mLastModified = $lastmod;
103 $this->sendCacheControl();
104 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
105 $this->disable();
106 return true;
107 } else {
108 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
109 $this->mLastModified = $lastmod;
110 }
111 } else {
112 wfDebug( "We're confused.\n", false );
113 $this->mLastModified = $lastmod;
114 }
115 }
116
117 function getPageTitleActionText () {
118 global $action;
119 switch($action) {
120 case 'edit':
121 return wfMsg('edit');
122 case 'history':
123 return wfMsg('history_short');
124 case 'protect':
125 return wfMsg('protect');
126 case 'unprotect':
127 return wfMsg('unprotect');
128 case 'delete':
129 return wfMsg('delete');
130 case 'watch':
131 return wfMsg('watch');
132 case 'unwatch':
133 return wfMsg('unwatch');
134 case 'submit':
135 return wfMsg('preview');
136 case 'info':
137 return wfMsg('info_short');
138 default:
139 return '';
140 }
141 }
142 function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
143 function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
144 function setPageTitle( $name ) {
145 global $action;
146 $this->mPagetitle = $name;
147 if(!empty($action)) {
148 $taction = $this->getPageTitleActionText();
149 if( !empty( $taction ) ) {
150 $name .= " - $taction";
151 }
152 }
153 $this->setHTMLTitle( $name . " - " . wfMsg( "wikititlesuffix" ) );
154 }
155 function getHTMLTitle() { return $this->mHTMLtitle; }
156 function getPageTitle() { return $this->mPagetitle; }
157 function setSubtitle( $str ) { $this->mSubtitle = $str; }
158 function getSubtitle() { return $this->mSubtitle; }
159 function isArticle() { return $this->mIsarticle; }
160 function setPrintable() { $this->mPrintable = true; }
161 function isPrintable() { return $this->mPrintable; }
162 function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
163 function isSyndicated() { return $this->mShowFeedLinks; }
164 function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
165 function getOnloadHandler() { return $this->mOnloadHandler; }
166 function disable() { $this->mDoNothing = true; }
167
168 function setArticleRelated( $v )
169 {
170 $this->mIsArticleRelated = $v;
171 if ( !$v ) {
172 $this->mIsarticle = false;
173 }
174 }
175 function setArticleFlag( $v ) {
176 $this->mIsarticle = $v;
177 if ( $v ) {
178 $this->mIsArticleRelated = $v;
179 }
180 }
181
182 function isArticleRelated()
183 {
184 return $this->mIsArticleRelated;
185 }
186
187 function getLanguageLinks() {
188 return $this->mLanguageLinks;
189 }
190 function addLanguageLinks($newLinkArray) {
191 $this->mLanguageLinks += $newLinkArray;
192 }
193 function setLanguageLinks($newLinkArray) {
194 $this->mLanguageLinks = $newLinkArray;
195 }
196 function getCategoryLinks() {
197 return $this->mCategoryLinks;
198 }
199 function addCategoryLinks($newLinkArray) {
200 $this->mCategoryLinks += $newLinkArray;
201 }
202 function setCategoryLinks($newLinkArray) {
203 $this->mCategoryLinks += $newLinkArray;
204 }
205
206 function suppressQuickbar() { $this->mSuppressQuickbar = true; }
207 function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
208
209 function addHTML( $text ) { $this->mBodytext .= $text; }
210 function debug( $text ) { $this->mDebugtext .= $text; }
211
212 function setParserOptions( $options )
213 {
214 return wfSetVar( $this->mParserOptions, $options );
215 }
216
217 # First pass--just handle <nowiki> sections, pass the rest off
218 # to doWikiPass2() which does all the real work.
219 #
220 # $cacheArticle - assume this text is the main text for the given article
221 #
222 function addWikiText( $text, $linestart = true, $cacheArticle = NULL )
223 {
224 global $wgParser, $wgParserCache, $wgUser, $wgTitle;
225
226 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
227 if ( $cacheArticle ) {
228 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
229 }
230
231 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
232 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
233 $this->addHTML( $parserOutput->getText() );
234 }
235
236 function tryParserCache( $article, $user ) {
237 global $wgParserCache;
238 $parserOutput = $wgParserCache->get( $article, $user );
239 if ( $parserOutput !== false ) {
240 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
241 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
242 $this->addHTML( $parserOutput->getText() );
243 return true;
244 } else {
245 return false;
246 }
247 }
248
249 # Set the maximum cache time on the Squid in seconds
250 function setSquidMaxage( $maxage ) {
251 $this->mSquidMaxage = $maxage;
252 }
253
254 # Use enableClientCache(false) to force it to send nocache headers
255 function enableClientCache( $state ) {
256 return wfSetVar( $this->mEnableClientCache, $state );
257 }
258
259 function sendCacheControl() {
260 global $wgUseSquid, $wgUseESI;
261 # FIXME: This header may cause trouble with some versions of Internet Explorer
262 header( "Vary: Accept-Encoding, Cookie" );
263 if( $this->mEnableClientCache ) {
264 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( "session.name") ] ) &&
265 ! $this->isPrintable() && $this->mSquidMaxage != 0 )
266 {
267 if ( $wgUseESI ) {
268 # We'll purge the proxy cache explicitly, but require end user agents
269 # to revalidate against the proxy on each visit.
270 # Surrogate-Control controls our Squid, Cache-Control downstream caches
271 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
272 # start with a shorter timeout for initial testing
273 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
274 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
275 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
276 } else {
277 # We'll purge the proxy cache for anons explicitly, but require end user agents
278 # to revalidate against the proxy on each visit.
279 # IMPORTANT! The Squid needs to replace the Cache-Control header with
280 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
281 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
282 # start with a shorter timeout for initial testing
283 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
284 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
285 }
286 } else {
287 # We do want clients to cache if they can, but they *must* check for updates
288 # on revisiting the page.
289 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
290 header( "Expires: -1" );
291 header( "Cache-Control: private, must-revalidate, max-age=0" );
292 }
293 if($this->mLastModified) header( "Last-modified: {$this->mLastModified}" );
294 } else {
295 wfDebug( "** no caching **\n", false );
296
297 # In general, the absence of a last modified header should be enough to prevent
298 # the client from using its cache. We send a few other things just to make sure.
299 header( "Expires: -1" );
300 header( "Cache-Control: no-cache, no-store, max-age=0, must-revalidate" );
301 header( "Pragma: no-cache" );
302 }
303 }
304
305 # Finally, all the text has been munged and accumulated into
306 # the object, let's actually output it:
307 #
308 function output()
309 {
310 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
311 global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
312 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
313 if( $this->mDoNothing ){
314 return;
315 }
316 $fname = "OutputPage::output";
317 wfProfileIn( $fname );
318
319 $sk = $wgUser->getSkin();
320
321 if ( "" != $this->mRedirect ) {
322 if( substr( $this->mRedirect, 0, 4 ) != "http" ) {
323 # Standards require redirect URLs to be absolute
324 global $wgServer;
325 $this->mRedirect = $wgServer . $this->mRedirect;
326 }
327 if( $this->mRedirectCode == '301') {
328 if( !$wgDebugRedirects ) {
329 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
330 }
331 $this->mLastModified = gmdate( "D, j M Y H:i:s" ) . " GMT";
332 }
333
334 $this->sendCacheControl();
335
336 if( $wgDebugRedirects ) {
337 $url = htmlspecialchars( $this->mRedirect );
338 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
339 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
340 print "</body>\n</html>\n";
341 } else {
342 header( "Location: {$this->mRedirect}" );
343 }
344 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
345 return;
346 }
347
348
349 $this->sendCacheControl();
350 # Perform link colouring
351 $this->mBodytext = $this->parseLinkHolders();
352
353 # Disable temporary placeholders, so that the skin produces HTML
354 $sk->postParseLinkColour( false );
355
356 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
357 header( "Content-language: {$wgLanguageCode}" );
358
359 $exp = time() + $wgCookieExpiration;
360 foreach( $this->mCookies as $name => $val ) {
361 setcookie( $name, $val, $exp, "/" );
362 }
363
364 $sk->outputPage( $this );
365 # flush();
366 }
367
368 function out( $ins )
369 {
370 global $wgInputEncoding, $wgOutputEncoding, $wgLang;
371 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
372 $outs = $ins;
373 } else {
374 $outs = $wgLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
375 if ( false === $outs ) { $outs = $ins; }
376 }
377 print $outs;
378 }
379
380 function setEncodings()
381 {
382 global $wgInputEncoding, $wgOutputEncoding;
383 global $wgUser, $wgLang;
384
385 $wgInputEncoding = strtolower( $wgInputEncoding );
386
387 if( $wgUser->getOption( 'altencoding' ) ) {
388 $wgLang->setAltEncoding();
389 return;
390 }
391
392 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
393 $wgOutputEncoding = strtolower( $wgOutputEncoding );
394 return;
395 }
396
397 /*
398 # This code is unused anyway!
399 # Commenting out. --bv 2003-11-15
400
401 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
402 $best = 0.0;
403 $bestset = "*";
404
405 foreach ( $a as $s ) {
406 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
407 $set = $m[1];
408 $q = (float)($m[2]);
409 } else {
410 $set = $s;
411 $q = 1.0;
412 }
413 if ( $q > $best ) {
414 $bestset = $set;
415 $best = $q;
416 }
417 }
418 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
419 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
420 $wgOutputEncoding = strtolower( $bestset );
421
422 # Disable for now
423 #
424 */
425 $wgOutputEncoding = $wgInputEncoding;
426 }
427
428 # Returns a HTML comment with the elapsed time since request.
429 # This method has no side effects.
430 function reportTime()
431 {
432 global $wgRequestTime;
433
434 $now = wfTime();
435 list( $usec, $sec ) = explode( " ", $wgRequestTime );
436 $start = (float)$sec + (float)$usec;
437 $elapsed = $now - $start;
438
439 # Use real server name if available, so we know which machine
440 # in a server farm generated the current page.
441 if ( function_exists( "posix_uname" ) ) {
442 $uname = @posix_uname();
443 } else {
444 $uname = false;
445 }
446 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
447 $hostname = $uname['nodename'];
448 } else {
449 # This may be a virtual server.
450 $hostname = $_SERVER['SERVER_NAME'];
451 }
452 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
453 $hostname, $elapsed );
454 return $com;
455 }
456
457 # Note: these arguments are keys into wfMsg(), not text!
458 #
459 function errorpage( $title, $msg )
460 {
461 global $wgTitle;
462
463 $this->mDebugtext .= "Original title: " .
464 $wgTitle->getPrefixedText() . "\n";
465 $this->setPageTitle( wfMsg( $title ) );
466 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
467 $this->setRobotpolicy( "noindex,nofollow" );
468 $this->setArticleRelated( false );
469 $this->enableClientCache( false );
470 $this->mRedirect = "";
471
472 $this->mBodytext = "";
473 $this->addHTML( "<p>" . wfMsg( $msg ) . "</p>\n" );
474 $this->returnToMain( false );
475
476 $this->output();
477 wfErrorExit();
478 }
479
480 function sysopRequired()
481 {
482 global $wgUser;
483
484 $this->setPageTitle( wfMsg( "sysoptitle" ) );
485 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
486 $this->setRobotpolicy( "noindex,nofollow" );
487 $this->setArticleRelated( false );
488 $this->mBodytext = "";
489
490 $sk = $wgUser->getSkin();
491 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
492 $this->addHTML( wfMsg( "sysoptext", $ap ) );
493 $this->returnToMain();
494 }
495
496 function developerRequired()
497 {
498 global $wgUser;
499
500 $this->setPageTitle( wfMsg( "developertitle" ) );
501 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
502 $this->setRobotpolicy( "noindex,nofollow" );
503 $this->setArticleRelated( false );
504 $this->mBodytext = "";
505
506 $sk = $wgUser->getSkin();
507 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
508 $this->addHTML( wfMsg( "developertext", $ap ) );
509 $this->returnToMain();
510 }
511
512 function loginToUse()
513 {
514 global $wgUser, $wgTitle, $wgLang;
515
516 $this->setPageTitle( wfMsg( "loginreqtitle" ) );
517 $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
518 $this->setRobotpolicy( "noindex,nofollow" );
519 $this->setArticleFlag( false );
520 $this->mBodytext = "";
521 $this->addWikiText( wfMsg( "loginreqtext" ) );
522
523 # We put a comment in the .html file so a Sysop can diagnose the page the
524 # user can't see.
525 $this->addHTML( "\n<!--" .
526 $wgLang->getNsText( $wgTitle->getNamespace() ) .
527 ":" .
528 $wgTitle->getDBkey() . "-->" );
529 $this->returnToMain(); # Flip back to the main page after 10 seconds.
530 }
531
532 function databaseError( $fname, $sql, $error, $errno )
533 {
534 global $wgUser, $wgCommandLineMode;
535
536 $this->setPageTitle( wfMsgNoDB( "databaseerror" ) );
537 $this->setRobotpolicy( "noindex,nofollow" );
538 $this->setArticleRelated( false );
539 $this->enableClientCache( false );
540 $this->mRedirect = "";
541
542 if ( $wgCommandLineMode ) {
543 $msg = wfMsgNoDB( "dberrortextcl", htmlspecialchars( $sql ),
544 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
545 } else {
546 $msg = wfMsgNoDB( "dberrortext", htmlspecialchars( $sql ),
547 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
548 }
549
550 if ( $wgCommandLineMode || !is_object( $wgUser )) {
551 print "$msg\n";
552 wfErrorExit();
553 }
554 $sk = $wgUser->getSkin();
555 $shlink = $sk->makeKnownLink( wfMsgNoDB( "searchhelppage" ),
556 wfMsgNoDB( "searchingwikipedia" ) );
557 $msg = str_replace( "$5", $shlink, $msg );
558 $this->mBodytext = $msg;
559 $this->output();
560 wfErrorExit();
561 }
562
563 function readOnlyPage( $source = null, $protected = false )
564 {
565 global $wgUser, $wgReadOnlyFile;
566
567 $this->setRobotpolicy( "noindex,nofollow" );
568 $this->setArticleRelated( false );
569
570 if( $protected ) {
571 $this->setPageTitle( wfMsg( "viewsource" ) );
572 $this->addWikiText( wfMsg( "protectedtext" ) );
573 } else {
574 $this->setPageTitle( wfMsg( "readonly" ) );
575 $reason = file_get_contents( $wgReadOnlyFile );
576 $this->addWikiText( wfMsg( "readonlytext", $reason ) );
577 }
578
579 if( is_string( $source ) ) {
580 if( strcmp( $source, "" ) == 0 ) {
581 $source = wfMsg( "noarticletext" );
582 }
583 $rows = $wgUser->getOption( "rows" );
584 $cols = $wgUser->getOption( "cols" );
585 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
586 htmlspecialchars( $source ) . "\n</textarea>";
587 $this->addHTML( $text );
588 }
589
590 $this->returnToMain( false );
591 }
592
593 function fatalError( $message )
594 {
595 $this->setPageTitle( wfMsg( "internalerror" ) );
596 $this->setRobotpolicy( "noindex,nofollow" );
597 $this->setArticleRelated( false );
598 $this->enableClientCache( false );
599 $this->mRedirect = "";
600
601 $this->mBodytext = $message;
602 $this->output();
603 wfErrorExit();
604 }
605
606 function unexpectedValueError( $name, $val )
607 {
608 $this->fatalError( wfMsg( "unexpected", $name, $val ) );
609 }
610
611 function fileCopyError( $old, $new )
612 {
613 $this->fatalError( wfMsg( "filecopyerror", $old, $new ) );
614 }
615
616 function fileRenameError( $old, $new )
617 {
618 $this->fatalError( wfMsg( "filerenameerror", $old, $new ) );
619 }
620
621 function fileDeleteError( $name )
622 {
623 $this->fatalError( wfMsg( "filedeleteerror", $name ) );
624 }
625
626 function fileNotFoundError( $name )
627 {
628 $this->fatalError( wfMsg( "filenotfound", $name ) );
629 }
630
631 // return from error messages or notes
632 // auto: automatically redirect the user after 10 seconds
633 // returnto: page title to return to. Default is Main Page.
634 function returnToMain( $auto = true, $returnto = NULL )
635 {
636 global $wgUser, $wgOut, $wgRequest;
637
638 if ( $returnto == NULL ) {
639 $returnto = $wgRequest->getText( 'returnto' );
640 }
641
642 $sk = $wgUser->getSkin();
643 if ( "" == $returnto ) {
644 $returnto = wfMsg( "mainpage" );
645 }
646 $link = $sk->makeKnownLink( $returnto, "" );
647
648 $r = wfMsg( "returnto", $link );
649 if ( $auto ) {
650 $titleObj = Title::newFromText( $returnto );
651 $wgOut->addMeta( "http:Refresh", "10;url=" . $titleObj->escapeFullURL() );
652 }
653 $wgOut->addHTML( "\n<p>$r</p>\n" );
654 }
655
656 # This function takes the existing and broken links for the page
657 # and uses the first 10 of them for META keywords
658 function addMetaTags ()
659 {
660 global $wgLinkCache , $wgOut ;
661 $good = array_keys ( $wgLinkCache->mGoodLinks ) ;
662 $bad = array_keys ( $wgLinkCache->mBadLinks ) ;
663 $a = array_merge ( $good , $bad ) ;
664 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
665 $a = implode ( "," , $a ) ;
666 $strip = array(
667 "/<.*?>/" => '',
668 "/[_]/" => ' '
669 );
670 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
671
672 $wgOut->addMeta ( "KEYWORDS" , $a ) ;
673 }
674
675 /* private */ function headElement()
676 {
677 global $wgDocType, $wgDTD, $wgLanguageCode, $wgOutputEncoding, $wgMimeType;
678 global $wgUser, $wgLang, $wgRequest;
679
680 $xml = ($wgMimeType == 'text/xml');
681 if( $xml ) {
682 $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
683 } else {
684 $ret = "";
685 }
686
687 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
688
689 if ( "" == $this->mHTMLtitle ) {
690 $this->mHTMLtitle = wfMsg( "pagetitle", $this->mPagetitle );
691 }
692 if( $xml ) {
693 $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
694 } else {
695 $xmlbits = "";
696 }
697 $rtl = $wgLang->isRTL() ? " dir='RTL'" : "";
698 $ret .= "<html $xmlbits lang=\"$wgLanguageCode\" $rtl>\n";
699 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle ) . "</title>\n";
700 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
701
702 $ret .= $this->getHeadLinks();
703 global $wgStylePath;
704 if( $this->isPrintable() ) {
705 $media = "";
706 } else {
707 $media = "media='print'";
708 }
709 $printsheet = htmlspecialchars( "$wgStylePath/wikiprintable.css" );
710 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
711
712 $sk = $wgUser->getSkin();
713 $ret .= $sk->getHeadScripts();
714 $ret .= $this->mScripts;
715 $ret .= $sk->getUserStyles();
716
717 $ret .= "</head>\n";
718 return $ret;
719 }
720
721 function getHeadLinks() {
722 global $wgRequest, $wgStylePath;
723 $ret = "";
724 foreach ( $this->mMetatags as $tag ) {
725 if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
726 $a = "http-equiv";
727 $tag[0] = substr( $tag[0], 5 );
728 } else {
729 $a = "name";
730 }
731 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
732 }
733 $p = $this->mRobotpolicy;
734 if ( "" == $p ) { $p = "index,follow"; }
735 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
736
737 if ( count( $this->mKeywords ) > 0 ) {
738 $strip = array(
739 "/<.*?>/" => '',
740 "/[_]/" => ' '
741 );
742 $ret .= "<meta name=\"keywords\" content=\"" .
743 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
744 }
745 foreach ( $this->mLinktags as $tag ) {
746 $ret .= "<link";
747 foreach( $tag as $attr => $val ) {
748 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
749 }
750 $ret .= " />\n";
751 }
752 if( $this->isSyndicated() ) {
753 # FIXME: centralize the mime-type and name information in Feed.php
754 $link = $wgRequest->escapeAppendQuery( "feed=rss" );
755 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
756 $link = $wgRequest->escapeAppendQuery( "feed=atom" );
757 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
758 }
759 # FIXME: get these working
760 # $fix = htmlspecialchars( $wgStylePath . "/ie-png-fix.js" );
761 # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'>< /script><![endif]-->";
762 return $ret;
763 }
764
765 # Parse <!--LINK--> link placeholders to avoid using linkcache
766 # Placeholders created in Skin::makeLinkObj()
767 function parseLinkHolders()
768 {
769 global $wgUser;
770
771 $fname = 'OutputPage::parseLinkHolders';
772 wfProfileIn( $fname );
773
774 # Get placeholders from body
775 preg_match_all( "/<!--LINK (.*?) (.*?) (.*?) (.*?)-->/", $this->mBodytext, $tmpLinks );
776
777 if ( !empty( $tmpLinks[0] ) ) {
778 $dbr =& wfGetDB( DB_SLAVE );
779 $cur = $dbr->tableName( 'cur' );
780 $sk = $wgUser->getSkin();
781 $threshold = $wgUser->getOption('stubthreshold');
782
783 $namespaces =& $tmpLinks[1];
784 $dbkeys =& $tmpLinks[2];
785 $queries =& $tmpLinks[3];
786 $texts =& $tmpLinks[4];
787
788 # Sort by namespace
789 asort( $namespaces );
790
791 # Generate query
792 foreach ( $namespaces as $key => $val ) {
793 if ( !isset( $current ) ) {
794 $current = $val;
795 $query = "SELECT cur_namespace, cur_title";
796 if ( $threshold > 0 ) {
797 $query .= ", LENGTH(cur_text) AS cur_len, cur_is_redirect";
798 }
799 $query .= " FROM $cur WHERE (cur_namespace=$val AND cur_title IN(";
800 } elseif ( $current != $val ) {
801 $current = $val;
802 $query .= ")) OR (cur_namespace=$val AND cur_title IN(";
803 } else {
804 $query .= ", ";
805 }
806
807 $query .= $dbr->addQuotes( $dbkeys[$key] );
808 }
809
810 $query .= "))";
811
812 $res = $dbr->query( $query, $fname );
813
814 # Fetch data and form into an associative array
815 # non-existent = broken
816 # 1 = known
817 # 2 = stub
818 $colours = array();
819 while ( $s = $dbr->fetchObject($res) ) {
820 $key = $s->cur_namespace . ' ' . $s->cur_title;
821 if ( $threshold > 0 ) {
822 $size = $s->cur_len;
823 if ( $s->cur_is_redirect || $s->cur_namespace != 0 || $length < $threshold ) {
824 $colours[$key] = 1;
825 } else {
826 $colours[$key] = 2;
827 }
828 $colours[$key] = array( $s->cur_len, $s->cur_is_redirect );
829 } else {
830 $colours[$key] = 1;
831 }
832 }
833
834 # Construct search and replace arrays
835 $search = $replace = array();
836 foreach ( $namespaces as $key => $ns ) {
837 $cKey = $ns . ' ' . $dbkeys[$key];
838 $search[] = $tmpLinks[0][$key];
839 $title = Title::makeTitle( $ns, $dbkeys[$key] );
840 if ( empty( $colours[$cKey] ) ) {
841 $replace[] = $sk->makeBrokenLinkObj( $title, $texts[$key], $queries[$key] );
842 } elseif ( $colours[$cKey] == 1 ) {
843 $replace[] = $sk->makeKnownLinkObj( $title, $texts[$key], $queries[$key] );
844 } elseif ( $colours[$cKey] == 2 ) {
845 $replace[] = $sk->makeStubLinkObj( $title, $texts[$key], $queries[$key] );
846 }
847 }
848
849 # Do the thing
850 $out = str_replace( $search, $replace, $this->mBodytext );
851 } else {
852 $out = $this->mBodytext;
853 }
854
855 wfProfileOut( $fname );
856 return ( $out );
857 }
858 }
859
860 }
861 ?>