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