Introduce OutputPage::addReturnTo(), with a view to replacing OutputPage::returnToMai...
[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 $ip = wfGetIP();
749
750 if ( is_numeric( $id ) ) {
751 $name = User::whoIs( $id );
752 } else {
753 $name = $id;
754 }
755 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
756
757 $blockid = $wgUser->mBlock->mId;
758
759 $blockExpiry = $wgUser->mBlock->mExpiry;
760 if ( $blockExpiry == 'infinity' ) {
761 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
762 // Search for localization in 'ipboptions'
763 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
764 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
765 if ( strpos( $option, ":" ) === false )
766 continue;
767 list( $show, $value ) = explode( ":", $option );
768 if ( $value == 'infinite' || $value == 'indefinite' ) {
769 $blockExpiry = $show;
770 break;
771 }
772 }
773 } else {
774 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
775 }
776
777 if ( $wgUser->mBlock->mAuto ) {
778 $msg = 'autoblockedtext';
779 } else {
780 $msg = 'blockedtext';
781 }
782
783 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
784 * This could be a username, an ip range, or a single ip. */
785 $intended = $wgUser->mBlock->mAddress;
786
787 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended ) );
788
789 # Don't auto-return to special pages
790 if( $return ) {
791 $return = $wgTitle->getNamespace() > -1 ? $wgTitle->getPrefixedText() : NULL;
792 $this->returnToMain( false, $return );
793 }
794 }
795
796 /**
797 * Output a standard error page
798 *
799 * @param string $title Message key for page title
800 * @param string $msg Message key for page text
801 * @param array $params Message parameters
802 */
803 public function showErrorPage( $title, $msg, $params = array() ) {
804 global $wgTitle;
805
806 $this->mDebugtext .= 'Original title: ' .
807 $wgTitle->getPrefixedText() . "\n";
808 $this->setPageTitle( wfMsg( $title ) );
809 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
810 $this->setRobotpolicy( 'noindex,nofollow' );
811 $this->setArticleRelated( false );
812 $this->enableClientCache( false );
813 $this->mRedirect = '';
814 $this->mBodytext = '';
815
816 array_unshift( $params, $msg );
817 $message = call_user_func_array( 'wfMsg', $params );
818 $this->addWikiText( $message );
819
820 $this->returnToMain( false );
821 }
822
823 /** @deprecated */
824 public function errorpage( $title, $msg ) {
825 throw new ErrorPageError( $title, $msg );
826 }
827
828 /**
829 * Display an error page indicating that a given version of MediaWiki is
830 * required to use it
831 *
832 * @param mixed $version The version of MediaWiki needed to use the page
833 */
834 public function versionRequired( $version ) {
835 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
836 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
837 $this->setRobotpolicy( 'noindex,nofollow' );
838 $this->setArticleRelated( false );
839 $this->mBodytext = '';
840
841 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
842 $this->returnToMain();
843 }
844
845 /**
846 * Display an error page noting that a given permission bit is required.
847 *
848 * @param string $permission key required
849 */
850 public function permissionRequired( $permission ) {
851 global $wgGroupPermissions, $wgUser;
852
853 $this->setPageTitle( wfMsg( 'badaccess' ) );
854 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
855 $this->setRobotpolicy( 'noindex,nofollow' );
856 $this->setArticleRelated( false );
857 $this->mBodytext = '';
858
859 $groups = array();
860 foreach( $wgGroupPermissions as $key => $value ) {
861 if( isset( $value[$permission] ) && $value[$permission] == true ) {
862 $groupName = User::getGroupName( $key );
863 $groupPage = User::getGroupPage( $key );
864 if( $groupPage ) {
865 $skin = $wgUser->getSkin();
866 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
867 } else {
868 $groups[] = $groupName;
869 }
870 }
871 }
872 $n = count( $groups );
873 $groups = implode( ', ', $groups );
874 switch( $n ) {
875 case 0:
876 case 1:
877 case 2:
878 $message = wfMsgHtml( "badaccess-group$n", $groups );
879 break;
880 default:
881 $message = wfMsgHtml( 'badaccess-groups', $groups );
882 }
883 $this->addHtml( $message );
884 $this->returnToMain( false );
885 }
886
887 /**
888 * Use permissionRequired.
889 * @deprecated
890 */
891 public function sysopRequired() {
892 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
893 }
894
895 /**
896 * Use permissionRequired.
897 * @deprecated
898 */
899 public function developerRequired() {
900 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
901 }
902
903 /**
904 * Produce the stock "please login to use the wiki" page
905 */
906 public function loginToUse() {
907 global $wgUser, $wgTitle, $wgContLang;
908
909 if( $wgUser->isLoggedIn() ) {
910 $this->permissionRequired( 'read' );
911 return;
912 }
913
914 $skin = $wgUser->getSkin();
915
916 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
917 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
918 $this->setRobotPolicy( 'noindex,nofollow' );
919 $this->setArticleFlag( false );
920
921 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
922 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
923 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
924 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
925
926 # Don't return to the main page if the user can't read it
927 # otherwise we'll end up in a pointless loop
928 $mainPage = Title::newMainPage();
929 if( $mainPage->userCanRead() )
930 $this->returnToMain( true, $mainPage );
931 }
932
933 /** @deprecated */
934 public function databaseError( $fname, $sql, $error, $errno ) {
935 throw new MWException( "OutputPage::databaseError is obsolete\n" );
936 }
937
938 /**
939 * @todo document
940 * @param bool $protected Is the reason the page can't be reached because it's protected?
941 * @param mixed $source
942 */
943 public function readOnlyPage( $source = null, $protected = false ) {
944 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
945 $skin = $wgUser->getSkin();
946
947 $this->setRobotpolicy( 'noindex,nofollow' );
948 $this->setArticleRelated( false );
949
950 if( $protected ) {
951 $this->setPageTitle( wfMsg( 'viewsource' ) );
952 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
953 list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources();
954
955 // Show an appropriate explanation depending upon the reason
956 // for the protection...all of these should be moved to the
957 // callers
958 if( $wgTitle->getNamespace() == NS_MEDIAWIKI ) {
959 // User isn't allowed to edit the interface
960 $this->addWikiText( wfMsg( 'protectedinterface' ) );
961 } elseif( $cascadeSources && ( $count = count( $cascadeSources ) ) > 0 ) {
962 // Cascading protection
963 $titles = '';
964 foreach( $cascadeSources as $title )
965 $titles .= "* [[:" . $title->getPrefixedText() . "]]\n";
966 $this->addWikiText( wfMsgExt( 'cascadeprotected', 'parsemag', $count ) . "\n{$titles}" );
967 } elseif( !$wgTitle->isProtected( 'edit' ) && $wgTitle->isNamespaceProtected() ) {
968 // Namespace protection
969 global $wgNamespaceProtection;
970 $ns = $wgTitle->getNamespace() == NS_MAIN
971 ? wfMsg( 'nstab-main' )
972 : $wgTitle->getNsText();
973 $this->addWikiText( wfMsg( 'namespaceprotected', $ns ) );
974 } else {
975 // Standard protection
976 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
977 }
978 } else {
979 $this->setPageTitle( wfMsg( 'readonly' ) );
980 if ( $wgReadOnly ) {
981 $reason = $wgReadOnly;
982 } else {
983 $reason = file_get_contents( $wgReadOnlyFile );
984 }
985 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
986 }
987
988 if( is_string( $source ) ) {
989 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
990 $rows = $wgUser->getIntOption( 'rows' );
991 $cols = $wgUser->getIntOption( 'cols' );
992 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
993 htmlspecialchars( $source ) . "\n</textarea>";
994 $this->addHTML( $text );
995 }
996 $article = new Article( $wgTitle );
997 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
998
999 $this->returnToMain( false );
1000 }
1001
1002 /** @deprecated */
1003 public function fatalError( $message ) {
1004 throw new FatalError( $message );
1005 }
1006
1007 /** @deprecated */
1008 public function unexpectedValueError( $name, $val ) {
1009 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1010 }
1011
1012 /** @deprecated */
1013 public function fileCopyError( $old, $new ) {
1014 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1015 }
1016
1017 /** @deprecated */
1018 public function fileRenameError( $old, $new ) {
1019 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1020 }
1021
1022 /** @deprecated */
1023 public function fileDeleteError( $name ) {
1024 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1025 }
1026
1027 /** @deprecated */
1028 public function fileNotFoundError( $name ) {
1029 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1030 }
1031
1032 public function showFatalError( $message ) {
1033 $this->setPageTitle( wfMsg( "internalerror" ) );
1034 $this->setRobotpolicy( "noindex,nofollow" );
1035 $this->setArticleRelated( false );
1036 $this->enableClientCache( false );
1037 $this->mRedirect = '';
1038 $this->mBodytext = $message;
1039 }
1040
1041 public function showUnexpectedValueError( $name, $val ) {
1042 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1043 }
1044
1045 public function showFileCopyError( $old, $new ) {
1046 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1047 }
1048
1049 public function showFileRenameError( $old, $new ) {
1050 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1051 }
1052
1053 public function showFileDeleteError( $name ) {
1054 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1055 }
1056
1057 public function showFileNotFoundError( $name ) {
1058 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1059 }
1060
1061 /**
1062 * Add a "return to" link pointing to a specified title
1063 *
1064 * @param Title $title Title to link
1065 */
1066 public function addReturnTo( $title ) {
1067 global $wgUser;
1068 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1069 $this->addHtml( "<p>{$link}</p>\n" );
1070 }
1071
1072 /**
1073 * Add a "return to" link pointing to a specified title,
1074 * or the title indicated in the request, or else the main page
1075 *
1076 * @param null $unused No longer used
1077 * @param Title $returnto Title to return to
1078 */
1079 public function returnToMain( $unused = null, $returnto = NULL ) {
1080 global $wgRequest;
1081
1082 if ( $returnto == NULL ) {
1083 $returnto = $wgRequest->getText( 'returnto' );
1084 }
1085
1086 if ( '' === $returnto ) {
1087 $returnto = Title::newMainPage();
1088 }
1089
1090 if ( is_object( $returnto ) ) {
1091 $titleObj = $returnto;
1092 } else {
1093 $titleObj = Title::newFromText( $returnto );
1094 }
1095 if ( !is_object( $titleObj ) ) {
1096 $titleObj = Title::newMainPage();
1097 }
1098
1099 $this->addReturnTo( $titleObj );
1100 }
1101
1102 /**
1103 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1104 * and uses the first 10 of them for META keywords
1105 *
1106 * @param ParserOutput &$parserOutput
1107 */
1108 private function addKeywords( &$parserOutput ) {
1109 global $wgTitle;
1110 $this->addKeyword( $wgTitle->getPrefixedText() );
1111 $count = 1;
1112 $links2d =& $parserOutput->getLinks();
1113 if ( !is_array( $links2d ) ) {
1114 return;
1115 }
1116 foreach ( $links2d as $dbkeys ) {
1117 foreach( $dbkeys as $dbkey => $unused ) {
1118 $this->addKeyword( $dbkey );
1119 if ( ++$count > 10 ) {
1120 break 2;
1121 }
1122 }
1123 }
1124 }
1125
1126 /**
1127 * @return string The doctype, opening <html>, and head element.
1128 */
1129 public function headElement() {
1130 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1131 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1132 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1133
1134 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
1135 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1136 } else {
1137 $ret = '';
1138 }
1139
1140 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1141
1142 if ( '' == $this->getHTMLTitle() ) {
1143 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1144 }
1145
1146 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
1147 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1148 foreach($wgXhtmlNamespaces as $tag => $ns) {
1149 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1150 }
1151 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1152 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1153 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1154
1155 $ret .= $this->getHeadLinks();
1156 global $wgStylePath;
1157 if( $this->isPrintable() ) {
1158 $media = '';
1159 } else {
1160 $media = "media='print'";
1161 }
1162 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1163 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1164
1165 $sk = $wgUser->getSkin();
1166 $ret .= $sk->getHeadScripts( $this->mAllowUserJs );
1167 $ret .= $this->mScripts;
1168 $ret .= $sk->getUserStyles();
1169 $ret .= $this->getHeadItems();
1170
1171 if ($wgUseTrackbacks && $this->isArticleRelated())
1172 $ret .= $wgTitle->trackbackRDF();
1173
1174 $ret .= "</head>\n";
1175 return $ret;
1176 }
1177
1178 /**
1179 * @return string HTML tag links to be put in the header.
1180 */
1181 public function getHeadLinks() {
1182 global $wgRequest;
1183 $ret = '';
1184 foreach ( $this->mMetatags as $tag ) {
1185 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1186 $a = 'http-equiv';
1187 $tag[0] = substr( $tag[0], 5 );
1188 } else {
1189 $a = 'name';
1190 }
1191 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1192 }
1193
1194 $p = $this->mRobotpolicy;
1195 if( $p !== '' && $p != 'index,follow' ) {
1196 // http://www.robotstxt.org/wc/meta-user.html
1197 // Only show if it's different from the default robots policy
1198 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1199 }
1200
1201 if ( count( $this->mKeywords ) > 0 ) {
1202 $strip = array(
1203 "/<.*?>/" => '',
1204 "/_/" => ' '
1205 );
1206 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1207 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
1208 }
1209 foreach ( $this->mLinktags as $tag ) {
1210 $ret .= "\t\t<link";
1211 foreach( $tag as $attr => $val ) {
1212 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1213 }
1214 $ret .= " />\n";
1215 }
1216 if( $this->isSyndicated() ) {
1217 # FIXME: centralize the mime-type and name information in Feed.php
1218 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1219 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1220 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1221 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 1.0' href='$link' />\n";
1222 }
1223
1224 return $ret;
1225 }
1226
1227 /**
1228 * Turn off regular page output and return an error reponse
1229 * for when rate limiting has triggered.
1230 * @todo i18n
1231 */
1232 public function rateLimited() {
1233 global $wgOut;
1234 $wgOut->disable();
1235 wfHttpError( 500, 'Internal Server Error',
1236 'Sorry, the server has encountered an internal error. ' .
1237 'Please wait a moment and hit "refresh" to submit the request again.' );
1238 }
1239
1240 /**
1241 * Show an "add new section" link?
1242 *
1243 * @return bool True if the parser output instructs us to add one
1244 */
1245 public function showNewSectionLink() {
1246 return $this->mNewSectionLink;
1247 }
1248
1249 /**
1250 * Show a warning about slave lag
1251 *
1252 * If the lag is higher than 30 seconds, then the warning is
1253 * a bit more obvious
1254 *
1255 * @param int $lag Slave lag
1256 */
1257 public function showLagWarning( $lag ) {
1258 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1259
1260 if ($lag < $wgSlaveLagWarning)
1261 return;
1262
1263 $message = ($lag >= $wgSlaveLagCritical) ? 'lag-warn-high' : 'lag-warn-normal';
1264 $warning = wfMsgHtml( $message, htmlspecialchars( $lag ) );
1265 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );
1266 }
1267
1268 }
1269
1270