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