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