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