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