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