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