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