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