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