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