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