userCan changes, which have been done for about 3 weeks. Still TODO includes making...
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4 /**
5 */
6
7 /**
8 * @todo document
9 */
10 class OutputPage {
11 var $mMetatags, $mKeywords;
12 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
13 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
14 var $mSubtitle, $mRedirect, $mStatusCode;
15 var $mLastModified, $mETag, $mCategoryLinks;
16 var $mScripts, $mLinkColours, $mPageLinkTitle;
17
18 var $mAllowUserJs;
19 var $mSuppressQuickbar;
20 var $mOnloadHandler;
21 var $mDoNothing;
22 var $mContainsOldMagic, $mContainsNewMagic;
23 var $mIsArticleRelated;
24 protected $mParserOptions; // lazy initialised, use parserOptions()
25 var $mShowFeedLinks = false;
26 var $mEnableClientCache = true;
27 var $mArticleBodyOnly = false;
28
29 var $mNewSectionLink = false;
30 var $mNoGallery = false;
31 var $mPageTitleActionText = '';
32
33 /**
34 * Constructor
35 * Initialise private variables
36 */
37 function __construct() {
38 global $wgAllowUserJs;
39 $this->mAllowUserJs = $wgAllowUserJs;
40 $this->mMetatags = $this->mKeywords = $this->mLinktags = array();
41 $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
42 $this->mRedirect = $this->mLastModified =
43 $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
44 $this->mOnloadHandler = $this->mPageLinkTitle = '';
45 $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
46 $this->mSuppressQuickbar = $this->mPrintable = false;
47 $this->mLanguageLinks = array();
48 $this->mCategoryLinks = array();
49 $this->mDoNothing = false;
50 $this->mContainsOldMagic = $this->mContainsNewMagic = 0;
51 $this->mParserOptions = null;
52 $this->mSquidMaxage = 0;
53 $this->mScripts = '';
54 $this->mHeadItems = array();
55 $this->mETag = false;
56 $this->mRevisionId = null;
57 $this->mNewSectionLink = false;
58 $this->mTemplateIds = array();
59 }
60
61 public function redirect( $url, $responsecode = '302' ) {
62 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
63 $this->mRedirect = str_replace( "\n", '', $url );
64 $this->mRedirectCode = $responsecode;
65 }
66
67 /**
68 * Set the HTTP status code to send with the output.
69 *
70 * @param int $statusCode
71 * @return nothing
72 */
73 function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; }
74
75 # To add an http-equiv meta tag, precede the name with "http:"
76 function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
77 function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
78 function addScript( $script ) { $this->mScripts .= "\t\t".$script; }
79 function addStyle( $style ) {
80 global $wgStylePath, $wgStyleVersion;
81 $this->addLink(
82 array(
83 'rel' => 'stylesheet',
84 'href' => $wgStylePath . '/' . $style . '?' . $wgStyleVersion ) );
85 }
86
87 /**
88 * Add a self-contained script tag with the given contents
89 * @param string $script JavaScript text, no <script> tags
90 */
91 function addInlineScript( $script ) {
92 global $wgJsMimeType;
93 $this->mScripts .= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
94 }
95
96 function getScript() {
97 return $this->mScripts . $this->getHeadItems();
98 }
99
100 function getHeadItems() {
101 $s = '';
102 foreach ( $this->mHeadItems as $item ) {
103 $s .= $item;
104 }
105 return $s;
106 }
107
108 function addHeadItem( $name, $value ) {
109 $this->mHeadItems[$name] = $value;
110 }
111
112 function setETag($tag) { $this->mETag = $tag; }
113 function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; }
114 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly; }
115
116 function addLink( $linkarr ) {
117 # $linkarr should be an associative array of attributes. We'll escape on output.
118 array_push( $this->mLinktags, $linkarr );
119 }
120
121 function addMetadataLink( $linkarr ) {
122 # note: buggy CC software only reads first "meta" link
123 static $haveMeta = false;
124 $linkarr['rel'] = ($haveMeta) ? 'alternate meta' : 'meta';
125 $this->addLink( $linkarr );
126 $haveMeta = true;
127 }
128
129 /**
130 * checkLastModified tells the client to use the client-cached page if
131 * possible. If sucessful, the OutputPage is disabled so that
132 * any future call to OutputPage->output() have no effect.
133 *
134 * @return bool True iff cache-ok headers was sent.
135 */
136 function checkLastModified ( $timestamp ) {
137 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
138 $fname = 'OutputPage::checkLastModified';
139
140 if ( !$timestamp || $timestamp == '19700101000000' ) {
141 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
142 return;
143 }
144 if( !$wgCachePages ) {
145 wfDebug( "$fname: CACHE DISABLED\n", false );
146 return;
147 }
148 if( $wgUser->getOption( 'nocache' ) ) {
149 wfDebug( "$fname: USER DISABLED CACHE\n", false );
150 return;
151 }
152
153 $timestamp=wfTimestamp(TS_MW,$timestamp);
154 $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched, $wgCacheEpoch ) );
155
156 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
157 # IE sends sizes after the date like this:
158 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
159 # this breaks strtotime().
160 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
161
162 wfSuppressWarnings(); // E_STRICT system time bitching
163 $modsinceTime = strtotime( $modsince );
164 wfRestoreWarnings();
165
166 $ismodsince = wfTimestamp( TS_MW, $modsinceTime ? $modsinceTime : 1 );
167 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
168 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
169 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
170 # Make sure you're in a place you can leave when you call us!
171 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
172 $this->mLastModified = $lastmod;
173 $this->sendCacheControl();
174 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
175 $this->disable();
176
177 // Don't output a compressed blob when using ob_gzhandler;
178 // it's technically against HTTP spec and seems to confuse
179 // Firefox when the response gets split over two packets.
180 wfClearOutputBuffers();
181
182 return true;
183 } else {
184 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
185 $this->mLastModified = $lastmod;
186 }
187 } else {
188 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
189 $this->mLastModified = $lastmod;
190 }
191 }
192
193 function setPageTitleActionText( $text ) {
194 $this->mPageTitleActionText = $text;
195 }
196
197 function getPageTitleActionText () {
198 if ( isset( $this->mPageTitleActionText ) ) {
199 return $this->mPageTitleActionText;
200 }
201 }
202
203 public function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
204 public function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
205 public function setPageTitle( $name ) {
206 global $action, $wgContLang;
207 $name = $wgContLang->convert($name, true);
208 $this->mPagetitle = $name;
209 if(!empty($action)) {
210 $taction = $this->getPageTitleActionText();
211 if( !empty( $taction ) ) {
212 $name .= ' - '.$taction;
213 }
214 }
215
216 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
217 }
218 public function getHTMLTitle() { return $this->mHTMLtitle; }
219 public function getPageTitle() { return $this->mPagetitle; }
220 public function setSubtitle( $str ) { $this->mSubtitle = /*$this->parse(*/$str/*)*/; } // @bug 2514
221 public function getSubtitle() { return $this->mSubtitle; }
222 public function isArticle() { return $this->mIsarticle; }
223 public function setPrintable() { $this->mPrintable = true; }
224 public function isPrintable() { return $this->mPrintable; }
225 public function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
226 public function isSyndicated() { return $this->mShowFeedLinks; }
227 public function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
228 public function getOnloadHandler() { return $this->mOnloadHandler; }
229 public function disable() { $this->mDoNothing = true; }
230
231 public function setArticleRelated( $v ) {
232 $this->mIsArticleRelated = $v;
233 if ( !$v ) {
234 $this->mIsarticle = false;
235 }
236 }
237 public function setArticleFlag( $v ) {
238 $this->mIsarticle = $v;
239 if ( $v ) {
240 $this->mIsArticleRelated = $v;
241 }
242 }
243
244 public function isArticleRelated() { return $this->mIsArticleRelated; }
245
246 public function getLanguageLinks() { return $this->mLanguageLinks; }
247 public function addLanguageLinks($newLinkArray) {
248 $this->mLanguageLinks += $newLinkArray;
249 }
250 public function setLanguageLinks($newLinkArray) {
251 $this->mLanguageLinks = $newLinkArray;
252 }
253
254 public function getCategoryLinks() {
255 return $this->mCategoryLinks;
256 }
257
258 /**
259 * Add an array of categories, with names in the keys
260 */
261 public function addCategoryLinks($categories) {
262 global $wgUser, $wgContLang;
263
264 if ( !is_array( $categories ) ) {
265 return;
266 }
267 # Add the links to the link cache in a batch
268 $arr = array( NS_CATEGORY => $categories );
269 $lb = new LinkBatch;
270 $lb->setArray( $arr );
271 $lb->execute();
272
273 $sk = $wgUser->getSkin();
274 foreach ( $categories as $category => $unused ) {
275 $title = Title::makeTitleSafe( NS_CATEGORY, $category );
276 $text = $wgContLang->convertHtml( $title->getText() );
277 $this->mCategoryLinks[] = $sk->makeLinkObj( $title, $text );
278 }
279 }
280
281 public function setCategoryLinks($categories) {
282 $this->mCategoryLinks = array();
283 $this->addCategoryLinks($categories);
284 }
285
286 public function suppressQuickbar() { $this->mSuppressQuickbar = true; }
287 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
288
289 public function disallowUserJs() { $this->mAllowUserJs = false; }
290 public function isUserJsAllowed() { return $this->mAllowUserJs; }
291
292 public function addHTML( $text ) { $this->mBodytext .= $text; }
293 public function clearHTML() { $this->mBodytext = ''; }
294 public function getHTML() { return $this->mBodytext; }
295 public function debug( $text ) { $this->mDebugtext .= $text; }
296
297 /* @deprecated */
298 public function setParserOptions( $options ) {
299 return $this->parserOptions( $options );
300 }
301
302 public function parserOptions( $options = null ) {
303 if ( !$this->mParserOptions ) {
304 $this->mParserOptions = new ParserOptions;
305 }
306 return wfSetVar( $this->mParserOptions, $options );
307 }
308
309 /**
310 * Set the revision ID which will be seen by the wiki text parser
311 * for things such as embedded {{REVISIONID}} variable use.
312 * @param mixed $revid an integer, or NULL
313 * @return mixed previous value
314 */
315 public function setRevisionId( $revid ) {
316 $val = is_null( $revid ) ? null : intval( $revid );
317 return wfSetVar( $this->mRevisionId, $val );
318 }
319
320 /**
321 * Convert wikitext to HTML and add it to the buffer
322 * Default assumes that the current page title will
323 * be used.
324 *
325 * @param string $text
326 * @param bool $linestart
327 */
328 public function addWikiText( $text, $linestart = true ) {
329 global $wgTitle;
330 $this->addWikiTextTitle($text, $wgTitle, $linestart);
331 }
332
333 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
334 $this->addWikiTextTitle($text, $title, $linestart);
335 }
336
337 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
338 $this->addWikiTextTitle( $text, $title, $linestart, true );
339 }
340
341 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
342 global $wgParser;
343
344 $fname = 'OutputPage:addWikiTextTitle';
345 wfProfileIn($fname);
346
347 wfIncrStats('pcache_not_possible');
348
349 $popts = $this->parserOptions();
350 $popts->setTidy($tidy);
351
352 $parserOutput = $wgParser->parse( $text, $title, $popts,
353 $linestart, true, $this->mRevisionId );
354
355 $this->addParserOutput( $parserOutput );
356
357 wfProfileOut($fname);
358 }
359
360 /**
361 * @todo document
362 * @param ParserOutput object &$parserOutput
363 */
364 public function addParserOutputNoText( &$parserOutput ) {
365 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
366 $this->addCategoryLinks( $parserOutput->getCategories() );
367 $this->mNewSectionLink = $parserOutput->getNewSection();
368 $this->addKeywords( $parserOutput );
369 if ( $parserOutput->getCacheTime() == -1 ) {
370 $this->enableClientCache( false );
371 }
372 $this->mNoGallery = $parserOutput->getNoGallery();
373 $this->mHeadItems = array_merge( $this->mHeadItems, (array)$parserOutput->mHeadItems );
374 // Versioning...
375 $this->mTemplateIds += (array)$parserOutput->mTemplateIds;
376
377 # Display title
378 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
379 $this->setPageTitle( $dt );
380
381 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
382 }
383
384 /**
385 * @todo document
386 * @param ParserOutput &$parserOutput
387 */
388 function addParserOutput( &$parserOutput ) {
389 $this->addParserOutputNoText( $parserOutput );
390 $text = $parserOutput->getText();
391 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
392 $this->addHTML( $text );
393 }
394
395 /**
396 * Add wikitext to the buffer, assuming that this is the primary text for a page view
397 * Saves the text into the parser cache if possible.
398 *
399 * @param string $text
400 * @param Article $article
401 * @param bool $cache
402 * @deprecated Use Article::outputWikitext
403 */
404 public function addPrimaryWikiText( $text, $article, $cache = true ) {
405 global $wgParser, $wgUser;
406
407 $popts = $this->parserOptions();
408 $popts->setTidy(true);
409 $parserOutput = $wgParser->parse( $text, $article->mTitle,
410 $popts, true, true, $this->mRevisionId );
411 $popts->setTidy(false);
412 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
413 $parserCache =& ParserCache::singleton();
414 $parserCache->save( $parserOutput, $article, $wgUser );
415 }
416
417 $this->addParserOutput( $parserOutput );
418 }
419
420 /**
421 * @deprecated use addWikiTextTidy()
422 */
423 public function addSecondaryWikiText( $text, $linestart = true ) {
424 global $wgTitle;
425 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
426 }
427
428 /**
429 * Add wikitext with tidy enabled
430 */
431 public function addWikiTextTidy( $text, $linestart = true ) {
432 global $wgTitle;
433 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
434 }
435
436
437 /**
438 * Add the output of a QuickTemplate to the output buffer
439 *
440 * @param QuickTemplate $template
441 */
442 public function addTemplate( &$template ) {
443 ob_start();
444 $template->execute();
445 $this->addHTML( ob_get_contents() );
446 ob_end_clean();
447 }
448
449 /**
450 * Parse wikitext and return the HTML.
451 *
452 * @param string $text
453 * @param bool $linestart Is this the start of a line?
454 * @param bool $interface ??
455 */
456 public function parse( $text, $linestart = true, $interface = false ) {
457 global $wgParser, $wgTitle;
458 $popts = $this->parserOptions();
459 if ( $interface) { $popts->setInterfaceMessage(true); }
460 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
461 $linestart, true, $this->mRevisionId );
462 if ( $interface) { $popts->setInterfaceMessage(false); }
463 return $parserOutput->getText();
464 }
465
466 /**
467 * @param Article $article
468 * @param User $user
469 *
470 * @return bool True if successful, else false.
471 */
472 public function tryParserCache( &$article, $user ) {
473 $parserCache =& ParserCache::singleton();
474 $parserOutput = $parserCache->get( $article, $user );
475 if ( $parserOutput !== false ) {
476 $this->addParserOutput( $parserOutput );
477 return true;
478 } else {
479 return false;
480 }
481 }
482
483 /**
484 * @param int $maxage Maximum cache time on the Squid, in seconds.
485 */
486 public function setSquidMaxage( $maxage ) {
487 $this->mSquidMaxage = $maxage;
488 }
489
490 /**
491 * Use enableClientCache(false) to force it to send nocache headers
492 * @param $state ??
493 */
494 public function enableClientCache( $state ) {
495 return wfSetVar( $this->mEnableClientCache, $state );
496 }
497
498 function uncacheableBecauseRequestvars() {
499 global $wgRequest;
500 return $wgRequest->getText('useskin', false) === false
501 && $wgRequest->getText('uselang', false) === false;
502 }
503
504 public function sendCacheControl() {
505 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
506 $fname = 'OutputPage::sendCacheControl';
507
508 if ($wgUseETag && $this->mETag)
509 $wgRequest->response()->header("ETag: $this->mETag");
510
511 # don't serve compressed data to clients who can't handle it
512 # maintain different caches for logged-in users and non-logged in ones
513 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
514 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache ) {
515 if( $wgUseSquid && session_id() == '' &&
516 ! $this->isPrintable() && $this->mSquidMaxage != 0 )
517 {
518 if ( $wgUseESI ) {
519 # We'll purge the proxy cache explicitly, but require end user agents
520 # to revalidate against the proxy on each visit.
521 # Surrogate-Control controls our Squid, Cache-Control downstream caches
522 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
523 # start with a shorter timeout for initial testing
524 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
525 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
526 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
527 } else {
528 # We'll purge the proxy cache for anons explicitly, but require end user agents
529 # to revalidate against the proxy on each visit.
530 # IMPORTANT! The Squid needs to replace the Cache-Control header with
531 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
532 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
533 # start with a shorter timeout for initial testing
534 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
535 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
536 }
537 } else {
538 # We do want clients to cache if they can, but they *must* check for updates
539 # on revisiting the page.
540 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
541 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
542 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
543 }
544 if($this->mLastModified) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
545 } else {
546 wfDebug( "$fname: no caching **\n", false );
547
548 # In general, the absence of a last modified header should be enough to prevent
549 # the client from using its cache. We send a few other things just to make sure.
550 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
551 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
552 $wgRequest->response()->header( 'Pragma: no-cache' );
553 }
554 }
555
556 /**
557 * Finally, all the text has been munged and accumulated into
558 * the object, let's actually output it:
559 */
560 public function output() {
561 global $wgUser, $wgOutputEncoding, $wgRequest;
562 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
563 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
564 global $wgServer, $wgStyleVersion;
565
566 if( $this->mDoNothing ){
567 return;
568 }
569 $fname = 'OutputPage::output';
570 wfProfileIn( $fname );
571 $sk = $wgUser->getSkin();
572
573 if ( $wgUseAjax ) {
574 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
575
576 wfRunHooks( 'AjaxAddScript', array( &$this ) );
577
578 if( $wgAjaxSearch ) {
579 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
580 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
581 }
582
583 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
584 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
585 }
586 }
587
588 if ( '' != $this->mRedirect ) {
589 if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
590 # Standards require redirect URLs to be absolute
591 global $wgServer;
592 $this->mRedirect = $wgServer . $this->mRedirect;
593 }
594 if( $this->mRedirectCode == '301') {
595 if( !$wgDebugRedirects ) {
596 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
597 }
598 $this->mLastModified = wfTimestamp( TS_RFC2822 );
599 }
600
601 $this->sendCacheControl();
602
603 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
604 if( $wgDebugRedirects ) {
605 $url = htmlspecialchars( $this->mRedirect );
606 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
607 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
608 print "</body>\n</html>\n";
609 } else {
610 $wgRequest->response()->header( 'Location: '.$this->mRedirect );
611 }
612 wfProfileOut( $fname );
613 return;
614 }
615 elseif ( $this->mStatusCode )
616 {
617 $statusMessage = array(
618 100 => 'Continue',
619 101 => 'Switching Protocols',
620 102 => 'Processing',
621 200 => 'OK',
622 201 => 'Created',
623 202 => 'Accepted',
624 203 => 'Non-Authoritative Information',
625 204 => 'No Content',
626 205 => 'Reset Content',
627 206 => 'Partial Content',
628 207 => 'Multi-Status',
629 300 => 'Multiple Choices',
630 301 => 'Moved Permanently',
631 302 => 'Found',
632 303 => 'See Other',
633 304 => 'Not Modified',
634 305 => 'Use Proxy',
635 307 => 'Temporary Redirect',
636 400 => 'Bad Request',
637 401 => 'Unauthorized',
638 402 => 'Payment Required',
639 403 => 'Forbidden',
640 404 => 'Not Found',
641 405 => 'Method Not Allowed',
642 406 => 'Not Acceptable',
643 407 => 'Proxy Authentication Required',
644 408 => 'Request Timeout',
645 409 => 'Conflict',
646 410 => 'Gone',
647 411 => 'Length Required',
648 412 => 'Precondition Failed',
649 413 => 'Request Entity Too Large',
650 414 => 'Request-URI Too Large',
651 415 => 'Unsupported Media Type',
652 416 => 'Request Range Not Satisfiable',
653 417 => 'Expectation Failed',
654 422 => 'Unprocessable Entity',
655 423 => 'Locked',
656 424 => 'Failed Dependency',
657 500 => 'Internal Server Error',
658 501 => 'Not Implemented',
659 502 => 'Bad Gateway',
660 503 => 'Service Unavailable',
661 504 => 'Gateway Timeout',
662 505 => 'HTTP Version Not Supported',
663 507 => 'Insufficient Storage'
664 );
665
666 if ( $statusMessage[$this->mStatusCode] )
667 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] );
668 }
669
670 # Buffer output; final headers may depend on later processing
671 ob_start();
672
673 # Disable temporary placeholders, so that the skin produces HTML
674 $sk->postParseLinkColour( false );
675
676 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
677 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
678
679 if ($this->mArticleBodyOnly) {
680 $this->out($this->mBodytext);
681 } else {
682 wfProfileIn( 'Output-skin' );
683 $sk->outputPage( $this );
684 wfProfileOut( 'Output-skin' );
685 }
686
687 $this->sendCacheControl();
688 ob_end_flush();
689 wfProfileOut( $fname );
690 }
691
692 /**
693 * @todo document
694 * @param string $ins
695 */
696 public function out( $ins ) {
697 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
698 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
699 $outs = $ins;
700 } else {
701 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
702 if ( false === $outs ) { $outs = $ins; }
703 }
704 print $outs;
705 }
706
707 /**
708 * @todo document
709 */
710 public static function setEncodings() {
711 global $wgInputEncoding, $wgOutputEncoding;
712 global $wgUser, $wgContLang;
713
714 $wgInputEncoding = strtolower( $wgInputEncoding );
715
716 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
717 $wgOutputEncoding = strtolower( $wgOutputEncoding );
718 return;
719 }
720 $wgOutputEncoding = $wgInputEncoding;
721 }
722
723 /**
724 * Deprecated, use wfReportTime() instead.
725 * @return string
726 * @deprecated
727 */
728 public function reportTime() {
729 $time = wfReportTime();
730 return $time;
731 }
732
733 /**
734 * Produce a "user is blocked" page.
735 *
736 * @param bool $return Whether to have a "return to $wgTitle" message or not.
737 * @return nothing
738 */
739 function blockedPage( $return = true ) {
740 global $wgUser, $wgContLang, $wgTitle, $wgLang;
741
742 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
743 $this->setRobotpolicy( 'noindex,nofollow' );
744 $this->setArticleRelated( false );
745
746 $id = $wgUser->blockedBy();
747 $reason = $wgUser->blockedFor();
748 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $wgUser->mBlock->mTimestamp ), true );
749 $ip = wfGetIP();
750
751 if ( is_numeric( $id ) ) {
752 $name = User::whoIs( $id );
753 } else {
754 $name = $id;
755 }
756 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
757
758 $blockid = $wgUser->mBlock->mId;
759
760 $blockExpiry = $wgUser->mBlock->mExpiry;
761 if ( $blockExpiry == 'infinity' ) {
762 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
763 // Search for localization in 'ipboptions'
764 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
765 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
766 if ( strpos( $option, ":" ) === false )
767 continue;
768 list( $show, $value ) = explode( ":", $option );
769 if ( $value == 'infinite' || $value == 'indefinite' ) {
770 $blockExpiry = $show;
771 break;
772 }
773 }
774 } else {
775 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
776 }
777
778 if ( $wgUser->mBlock->mAuto ) {
779 $msg = 'autoblockedtext';
780 } else {
781 $msg = 'blockedtext';
782 }
783
784 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
785 * This could be a username, an ip range, or a single ip. */
786 $intended = $wgUser->mBlock->mAddress;
787
788 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp ) );
789
790 # Don't auto-return to special pages
791 if( $return ) {
792 $return = $wgTitle->getNamespace() > -1 ? $wgTitle->getPrefixedText() : NULL;
793 $this->returnToMain( false, $return );
794 }
795 }
796
797 /**
798 * Output a standard error page
799 *
800 * @param string $title Message key for page title
801 * @param string $msg Message key for page text
802 * @param array $params Message parameters
803 */
804 public function showErrorPage( $title, $msg, $params = array() ) {
805 global $wgTitle;
806
807 $this->mDebugtext .= 'Original title: ' .
808 $wgTitle->getPrefixedText() . "\n";
809 $this->setPageTitle( wfMsg( $title ) );
810 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
811 $this->setRobotpolicy( 'noindex,nofollow' );
812 $this->setArticleRelated( false );
813 $this->enableClientCache( false );
814 $this->mRedirect = '';
815 $this->mBodytext = '';
816
817 array_unshift( $params, $msg );
818 $message = call_user_func_array( 'wfMsg', $params );
819 $this->addWikiText( $message );
820
821 $this->returnToMain( false );
822 }
823
824 public function showPermissionsErrorPage( $title, $errors )
825 {
826 global $wgTitle;
827
828 $this->mDebugtext .= 'Original title: ' .
829 $wgTitle->getPrefixedText() . "\n";
830 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
831 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
832 $this->setRobotpolicy( 'noindex,nofollow' );
833 $this->setArticleRelated( false );
834 $this->enableClientCache( false );
835 $this->mRedirect = '';
836 $this->mBodytext = '';
837
838 $this->addWikiText( wfMsg('permissionserrorstext') );
839 $this->addHtml( '<ul class="permissions-errors">' . "\n" );
840
841 foreach( $errors as $error )
842 {
843 $this->addHtml( '<li>' );
844 $this->addWikiText( call_user_func_array( 'wfMsg', $error ) );
845 $this->addHtml( '</li>');
846 }
847 $this->addHtml( '</ul>' );
848
849 }
850
851 /** @deprecated */
852 public function errorpage( $title, $msg ) {
853 throw new ErrorPageError( $title, $msg );
854 }
855
856 /**
857 * Display an error page indicating that a given version of MediaWiki is
858 * required to use it
859 *
860 * @param mixed $version The version of MediaWiki needed to use the page
861 */
862 public function versionRequired( $version ) {
863 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
864 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
865 $this->setRobotpolicy( 'noindex,nofollow' );
866 $this->setArticleRelated( false );
867 $this->mBodytext = '';
868
869 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
870 $this->returnToMain();
871 }
872
873 /**
874 * Display an error page noting that a given permission bit is required.
875 *
876 * @param string $permission key required
877 */
878 public function permissionRequired( $permission ) {
879 global $wgGroupPermissions, $wgUser;
880
881 $this->setPageTitle( wfMsg( 'badaccess' ) );
882 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
883 $this->setRobotpolicy( 'noindex,nofollow' );
884 $this->setArticleRelated( false );
885 $this->mBodytext = '';
886
887 $groups = array();
888 foreach( $wgGroupPermissions as $key => $value ) {
889 if( isset( $value[$permission] ) && $value[$permission] == true ) {
890 $groupName = User::getGroupName( $key );
891 $groupPage = User::getGroupPage( $key );
892 if( $groupPage ) {
893 $skin = $wgUser->getSkin();
894 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
895 } else {
896 $groups[] = $groupName;
897 }
898 }
899 }
900 $n = count( $groups );
901 $groups = implode( ', ', $groups );
902 switch( $n ) {
903 case 0:
904 case 1:
905 case 2:
906 $message = wfMsgHtml( "badaccess-group$n", $groups );
907 break;
908 default:
909 $message = wfMsgHtml( 'badaccess-groups', $groups );
910 }
911 $this->addHtml( $message );
912 $this->returnToMain( false );
913 }
914
915 /**
916 * Use permissionRequired.
917 * @deprecated
918 */
919 public function sysopRequired() {
920 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
921 }
922
923 /**
924 * Use permissionRequired.
925 * @deprecated
926 */
927 public function developerRequired() {
928 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
929 }
930
931 /**
932 * Produce the stock "please login to use the wiki" page
933 */
934 public function loginToUse() {
935 global $wgUser, $wgTitle, $wgContLang;
936
937 if( $wgUser->isLoggedIn() ) {
938 $this->permissionRequired( 'read' );
939 return;
940 }
941
942 $skin = $wgUser->getSkin();
943
944 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
945 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
946 $this->setRobotPolicy( 'noindex,nofollow' );
947 $this->setArticleFlag( false );
948
949 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
950 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
951 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
952 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
953
954 # Don't return to the main page if the user can't read it
955 # otherwise we'll end up in a pointless loop
956 $mainPage = Title::newMainPage();
957 if( $mainPage->userCanRead() )
958 $this->returnToMain( true, $mainPage );
959 }
960
961 /** @deprecated */
962 public function databaseError( $fname, $sql, $error, $errno ) {
963 throw new MWException( "OutputPage::databaseError is obsolete\n" );
964 }
965
966 /**
967 * @todo document
968 * @param bool $protected Is the reason the page can't be reached because it's protected?
969 * @param mixed $source
970 */
971 public function readOnlyPage( $source = null, $protected = false ) {
972 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
973 $skin = $wgUser->getSkin();
974
975 $this->setRobotpolicy( 'noindex,nofollow' );
976 $this->setArticleRelated( false );
977
978 if( $protected ) {
979 $this->setPageTitle( wfMsg( 'viewsource' ) );
980 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
981 list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources();
982
983 // Show an appropriate explanation depending upon the reason
984 // for the protection...all of these should be moved to the
985 // callers
986 if( $wgTitle->getNamespace() == NS_MEDIAWIKI ) {
987 // User isn't allowed to edit the interface
988 $this->addWikiText( wfMsg( 'protectedinterface' ) );
989 } elseif( $cascadeSources && ( $count = count( $cascadeSources ) ) > 0 ) {
990 // Cascading protection
991 $titles = '';
992 foreach( $cascadeSources as $title )
993 $titles .= "* [[:" . $title->getPrefixedText() . "]]\n";
994 $this->addWikiText( wfMsgExt( 'cascadeprotected', 'parsemag', $count ) . "\n{$titles}" );
995 } elseif( !$wgTitle->isProtected( 'edit' ) && $wgTitle->isNamespaceProtected() ) {
996 // Namespace protection
997 global $wgNamespaceProtection;
998 $ns = $wgTitle->getNamespace() == NS_MAIN
999 ? wfMsg( 'nstab-main' )
1000 : $wgTitle->getNsText();
1001 $this->addWikiText( wfMsg( 'namespaceprotected', $ns ) );
1002 } else {
1003 // Standard protection
1004 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
1005 }
1006 } else {
1007 $this->setPageTitle( wfMsg( 'readonly' ) );
1008 if ( $wgReadOnly ) {
1009 $reason = $wgReadOnly;
1010 } else {
1011 $reason = file_get_contents( $wgReadOnlyFile );
1012 }
1013 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
1014 }
1015
1016 if( is_string( $source ) ) {
1017 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
1018 $rows = $wgUser->getIntOption( 'rows' );
1019 $cols = $wgUser->getIntOption( 'cols' );
1020 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
1021 htmlspecialchars( $source ) . "\n</textarea>";
1022 $this->addHTML( $text );
1023 }
1024 $article = new Article( $wgTitle );
1025 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1026
1027 $this->returnToMain( false );
1028 }
1029
1030 /** @deprecated */
1031 public function fatalError( $message ) {
1032 throw new FatalError( $message );
1033 }
1034
1035 /** @deprecated */
1036 public function unexpectedValueError( $name, $val ) {
1037 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1038 }
1039
1040 /** @deprecated */
1041 public function fileCopyError( $old, $new ) {
1042 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1043 }
1044
1045 /** @deprecated */
1046 public function fileRenameError( $old, $new ) {
1047 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1048 }
1049
1050 /** @deprecated */
1051 public function fileDeleteError( $name ) {
1052 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1053 }
1054
1055 /** @deprecated */
1056 public function fileNotFoundError( $name ) {
1057 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1058 }
1059
1060 public function showFatalError( $message ) {
1061 $this->setPageTitle( wfMsg( "internalerror" ) );
1062 $this->setRobotpolicy( "noindex,nofollow" );
1063 $this->setArticleRelated( false );
1064 $this->enableClientCache( false );
1065 $this->mRedirect = '';
1066 $this->mBodytext = $message;
1067 }
1068
1069 public function showUnexpectedValueError( $name, $val ) {
1070 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1071 }
1072
1073 public function showFileCopyError( $old, $new ) {
1074 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1075 }
1076
1077 public function showFileRenameError( $old, $new ) {
1078 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1079 }
1080
1081 public function showFileDeleteError( $name ) {
1082 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1083 }
1084
1085 public function showFileNotFoundError( $name ) {
1086 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1087 }
1088
1089 /**
1090 * Add a "return to" link pointing to a specified title
1091 *
1092 * @param Title $title Title to link
1093 */
1094 public function addReturnTo( $title ) {
1095 global $wgUser;
1096 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1097 $this->addHtml( "<p>{$link}</p>\n" );
1098 }
1099
1100 /**
1101 * Add a "return to" link pointing to a specified title,
1102 * or the title indicated in the request, or else the main page
1103 *
1104 * @param null $unused No longer used
1105 * @param Title $returnto Title to return to
1106 */
1107 public function returnToMain( $unused = null, $returnto = NULL ) {
1108 global $wgRequest;
1109
1110 if ( $returnto == NULL ) {
1111 $returnto = $wgRequest->getText( 'returnto' );
1112 }
1113
1114 if ( '' === $returnto ) {
1115 $returnto = Title::newMainPage();
1116 }
1117
1118 if ( is_object( $returnto ) ) {
1119 $titleObj = $returnto;
1120 } else {
1121 $titleObj = Title::newFromText( $returnto );
1122 }
1123 if ( !is_object( $titleObj ) ) {
1124 $titleObj = Title::newMainPage();
1125 }
1126
1127 $this->addReturnTo( $titleObj );
1128 }
1129
1130 /**
1131 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1132 * and uses the first 10 of them for META keywords
1133 *
1134 * @param ParserOutput &$parserOutput
1135 */
1136 private function addKeywords( &$parserOutput ) {
1137 global $wgTitle;
1138 $this->addKeyword( $wgTitle->getPrefixedText() );
1139 $count = 1;
1140 $links2d =& $parserOutput->getLinks();
1141 if ( !is_array( $links2d ) ) {
1142 return;
1143 }
1144 foreach ( $links2d as $dbkeys ) {
1145 foreach( $dbkeys as $dbkey => $unused ) {
1146 $this->addKeyword( $dbkey );
1147 if ( ++$count > 10 ) {
1148 break 2;
1149 }
1150 }
1151 }
1152 }
1153
1154 /**
1155 * @return string The doctype, opening <html>, and head element.
1156 */
1157 public function headElement() {
1158 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1159 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1160 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1161
1162 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
1163 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1164 } else {
1165 $ret = '';
1166 }
1167
1168 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1169
1170 if ( '' == $this->getHTMLTitle() ) {
1171 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1172 }
1173
1174 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
1175 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1176 foreach($wgXhtmlNamespaces as $tag => $ns) {
1177 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1178 }
1179 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1180 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1181 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1182
1183 $ret .= $this->getHeadLinks();
1184 global $wgStylePath;
1185 if( $this->isPrintable() ) {
1186 $media = '';
1187 } else {
1188 $media = "media='print'";
1189 }
1190 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1191 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1192
1193 $sk = $wgUser->getSkin();
1194 $ret .= $sk->getHeadScripts( $this->mAllowUserJs );
1195 $ret .= $this->mScripts;
1196 $ret .= $sk->getUserStyles();
1197 $ret .= $this->getHeadItems();
1198
1199 if ($wgUseTrackbacks && $this->isArticleRelated())
1200 $ret .= $wgTitle->trackbackRDF();
1201
1202 $ret .= "</head>\n";
1203 return $ret;
1204 }
1205
1206 /**
1207 * @return string HTML tag links to be put in the header.
1208 */
1209 public function getHeadLinks() {
1210 global $wgRequest;
1211 $ret = '';
1212 foreach ( $this->mMetatags as $tag ) {
1213 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1214 $a = 'http-equiv';
1215 $tag[0] = substr( $tag[0], 5 );
1216 } else {
1217 $a = 'name';
1218 }
1219 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1220 }
1221
1222 $p = $this->mRobotpolicy;
1223 if( $p !== '' && $p != 'index,follow' ) {
1224 // http://www.robotstxt.org/wc/meta-user.html
1225 // Only show if it's different from the default robots policy
1226 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1227 }
1228
1229 if ( count( $this->mKeywords ) > 0 ) {
1230 $strip = array(
1231 "/<.*?>/" => '',
1232 "/_/" => ' '
1233 );
1234 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1235 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
1236 }
1237 foreach ( $this->mLinktags as $tag ) {
1238 $ret .= "\t\t<link";
1239 foreach( $tag as $attr => $val ) {
1240 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1241 }
1242 $ret .= " />\n";
1243 }
1244 if( $this->isSyndicated() ) {
1245 # FIXME: centralize the mime-type and name information in Feed.php
1246 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1247 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1248 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1249 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 1.0' href='$link' />\n";
1250 }
1251
1252 return $ret;
1253 }
1254
1255 /**
1256 * Turn off regular page output and return an error reponse
1257 * for when rate limiting has triggered.
1258 * @todo i18n
1259 */
1260 public function rateLimited() {
1261 global $wgOut;
1262 $wgOut->disable();
1263 wfHttpError( 500, 'Internal Server Error',
1264 'Sorry, the server has encountered an internal error. ' .
1265 'Please wait a moment and hit "refresh" to submit the request again.' );
1266 }
1267
1268 /**
1269 * Show an "add new section" link?
1270 *
1271 * @return bool True if the parser output instructs us to add one
1272 */
1273 public function showNewSectionLink() {
1274 return $this->mNewSectionLink;
1275 }
1276
1277 /**
1278 * Show a warning about slave lag
1279 *
1280 * If the lag is higher than 30 seconds, then the warning is
1281 * a bit more obvious
1282 *
1283 * @param int $lag Slave lag
1284 */
1285 public function showLagWarning( $lag ) {
1286 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1287
1288 if ($lag < $wgSlaveLagWarning)
1289 return;
1290
1291 $message = ($lag >= $wgSlaveLagCritical) ? 'lag-warn-high' : 'lag-warn-normal';
1292 $warning = wfMsgHtml( $message, htmlspecialchars( $lag ) );
1293 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );
1294 }
1295
1296 }
1297
1298