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