Made OutputPage::tryParserCache() use addParserOutputNoText(), this fixes {{DISPLAYTI...
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4 /**
5 * @package MediaWiki
6 */
7
8 /**
9 * @todo document
10 * @package MediaWiki
11 */
12 class OutputPage {
13 var $mMetatags, $mKeywords;
14 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
15 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
16 var $mSubtitle, $mRedirect, $mStatusCode;
17 var $mLastModified, $mETag, $mCategoryLinks;
18 var $mScripts, $mLinkColours, $mPageLinkTitle;
19
20 var $mSuppressQuickbar;
21 var $mOnloadHandler;
22 var $mDoNothing;
23 var $mContainsOldMagic, $mContainsNewMagic;
24 var $mIsArticleRelated;
25 var $mParserOptions;
26 var $mShowFeedLinks = false;
27 var $mEnableClientCache = true;
28 var $mArticleBodyOnly = false;
29
30 var $mNewSectionLink = false;
31 var $mNoGallery = false;
32
33 /**
34 * Constructor
35 * Initialise private variables
36 */
37 function OutputPage() {
38 $this->mMetatags = $this->mKeywords = $this->mLinktags = array();
39 $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
40 $this->mRedirect = $this->mLastModified =
41 $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
42 $this->mOnloadHandler = $this->mPageLinkTitle = '';
43 $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
44 $this->mSuppressQuickbar = $this->mPrintable = false;
45 $this->mLanguageLinks = array();
46 $this->mCategoryLinks = array();
47 $this->mDoNothing = false;
48 $this->mContainsOldMagic = $this->mContainsNewMagic = 0;
49 $this->mParserOptions = ParserOptions::newFromUser( NULL );
50 $this->mSquidMaxage = 0;
51 $this->mScripts = '';
52 $this->mETag = false;
53 $this->mRevisionId = null;
54 $this->mNewSectionLink = false;
55 }
56
57 function redirect( $url, $responsecode = '302' ) {
58 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
59 $this->mRedirect = str_replace( "\n", '', $url );
60 $this->mRedirectCode = $responsecode;
61 }
62
63 function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; }
64
65 # To add an http-equiv meta tag, precede the name with "http:"
66 function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
67 function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
68 function addScript( $script ) { $this->mScripts .= $script; }
69 function getScript() { return $this->mScripts; }
70
71 function setETag($tag) { $this->mETag = $tag; }
72 function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; }
73 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly; }
74
75 function addLink( $linkarr ) {
76 # $linkarr should be an associative array of attributes. We'll escape on output.
77 array_push( $this->mLinktags, $linkarr );
78 }
79
80 function addMetadataLink( $linkarr ) {
81 # note: buggy CC software only reads first "meta" link
82 static $haveMeta = false;
83 $linkarr['rel'] = ($haveMeta) ? 'alternate meta' : 'meta';
84 $this->addLink( $linkarr );
85 $haveMeta = true;
86 }
87
88 /**
89 * checkLastModified tells the client to use the client-cached page if
90 * possible. If sucessful, the OutputPage is disabled so that
91 * any future call to OutputPage->output() have no effect. The method
92 * returns true iff cache-ok headers was sent.
93 */
94 function checkLastModified ( $timestamp ) {
95 global $wgCachePages, $wgCacheEpoch, $wgUser;
96 $fname = 'OutputPage::checkLastModified';
97
98 if ( !$timestamp || $timestamp == '19700101000000' ) {
99 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
100 return;
101 }
102 if( !$wgCachePages ) {
103 wfDebug( "$fname: CACHE DISABLED\n", false );
104 return;
105 }
106 if( $wgUser->getOption( 'nocache' ) ) {
107 wfDebug( "$fname: USER DISABLED CACHE\n", false );
108 return;
109 }
110
111 $timestamp=wfTimestamp(TS_MW,$timestamp);
112 $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched, $wgCacheEpoch ) );
113
114 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
115 # IE sends sizes after the date like this:
116 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
117 # this breaks strtotime().
118 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
119 $modsinceTime = strtotime( $modsince );
120 $ismodsince = wfTimestamp( TS_MW, $modsinceTime ? $modsinceTime : 1 );
121 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
122 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
123 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
124 # Make sure you're in a place you can leave when you call us!
125 header( "HTTP/1.0 304 Not Modified" );
126 $this->mLastModified = $lastmod;
127 $this->sendCacheControl();
128 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
129 $this->disable();
130 @ob_end_clean(); // Don't output compressed blob
131 return true;
132 } else {
133 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
134 $this->mLastModified = $lastmod;
135 }
136 } else {
137 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
138 $this->mLastModified = $lastmod;
139 }
140 }
141
142 function getPageTitleActionText () {
143 global $action;
144 switch($action) {
145 case 'edit':
146 case 'delete':
147 case 'protect':
148 case 'unprotect':
149 case 'watch':
150 case 'unwatch':
151 // Display title is already customized
152 return '';
153 case 'history':
154 return wfMsg('history_short');
155 case 'submit':
156 // FIXME: bug 2735; not correct for special pages etc
157 return wfMsg('preview');
158 case 'info':
159 return wfMsg('info_short');
160 default:
161 return '';
162 }
163 }
164
165 function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
166 function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
167 function setPageTitle( $name ) {
168 global $action, $wgContLang;
169 $name = $wgContLang->convert($name, true);
170 $this->mPagetitle = $name;
171 if(!empty($action)) {
172 $taction = $this->getPageTitleActionText();
173 if( !empty( $taction ) ) {
174 $name .= ' - '.$taction;
175 }
176 }
177
178 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
179 }
180 function getHTMLTitle() { return $this->mHTMLtitle; }
181 function getPageTitle() { return $this->mPagetitle; }
182 function setSubtitle( $str ) { $this->mSubtitle = /*$this->parse(*/$str/*)*/; } // @bug 2514
183 function getSubtitle() { return $this->mSubtitle; }
184 function isArticle() { return $this->mIsarticle; }
185 function setPrintable() { $this->mPrintable = true; }
186 function isPrintable() { return $this->mPrintable; }
187 function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
188 function isSyndicated() { return $this->mShowFeedLinks; }
189 function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
190 function getOnloadHandler() { return $this->mOnloadHandler; }
191 function disable() { $this->mDoNothing = true; }
192
193 function setArticleRelated( $v ) {
194 $this->mIsArticleRelated = $v;
195 if ( !$v ) {
196 $this->mIsarticle = false;
197 }
198 }
199 function setArticleFlag( $v ) {
200 $this->mIsarticle = $v;
201 if ( $v ) {
202 $this->mIsArticleRelated = $v;
203 }
204 }
205
206 function isArticleRelated() { return $this->mIsArticleRelated; }
207
208 function getLanguageLinks() { return $this->mLanguageLinks; }
209 function addLanguageLinks($newLinkArray) {
210 $this->mLanguageLinks += $newLinkArray;
211 }
212 function setLanguageLinks($newLinkArray) {
213 $this->mLanguageLinks = $newLinkArray;
214 }
215
216 function getCategoryLinks() {
217 return $this->mCategoryLinks;
218 }
219
220 /**
221 * Add an array of categories, with names in the keys
222 */
223 function addCategoryLinks($categories) {
224 global $wgUser, $wgContLang;
225
226 if ( !is_array( $categories ) ) {
227 return;
228 }
229 # Add the links to the link cache in a batch
230 $arr = array( NS_CATEGORY => $categories );
231 $lb = new LinkBatch;
232 $lb->setArray( $arr );
233 $lb->execute();
234
235 $sk =& $wgUser->getSkin();
236 foreach ( $categories as $category => $arbitrary ) {
237 $title = Title::makeTitleSafe( NS_CATEGORY, $category );
238 $text = $wgContLang->convertHtml( $title->getText() );
239 $this->mCategoryLinks[] = $sk->makeLinkObj( $title, $text );
240 }
241 }
242
243 function setCategoryLinks($categories) {
244 $this->mCategoryLinks = array();
245 $this->addCategoryLinks($categories);
246 }
247
248 function suppressQuickbar() { $this->mSuppressQuickbar = true; }
249 function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
250
251 function addHTML( $text ) { $this->mBodytext .= $text; }
252 function clearHTML() { $this->mBodytext = ''; }
253 function getHTML() { return $this->mBodytext; }
254 function debug( $text ) { $this->mDebugtext .= $text; }
255
256 /* @deprecated */
257 function setParserOptions( $options ) {
258 return $this->ParserOptions( $options );
259 }
260
261 function ParserOptions( $options = null ) {
262 return wfSetVar( $this->mParserOptions, $options );
263 }
264
265 /**
266 * Set the revision ID which will be seen by the wiki text parser
267 * for things such as embedded {{REVISIONID}} variable use.
268 * @param mixed $revid an integer, or NULL
269 * @return mixed previous value
270 */
271 function setRevisionId( $revid ) {
272 $val = is_null( $revid ) ? null : intval( $revid );
273 return wfSetVar( $this->mRevisionId, $val );
274 }
275
276 /**
277 * Convert wikitext to HTML and add it to the buffer
278 * Default assumes that the current page title will
279 * be used.
280 */
281 function addWikiText( $text, $linestart = true ) {
282 global $wgTitle;
283 $this->addWikiTextTitle($text, $wgTitle, $linestart);
284 }
285
286 function addWikiTextWithTitle($text, &$title, $linestart = true) {
287 $this->addWikiTextTitle($text, $title, $linestart);
288 }
289
290 function addWikiTextTitle($text, &$title, $linestart) {
291 global $wgParser;
292 $fname = 'OutputPage:addWikiTextTitle';
293 wfProfileIn($fname);
294 wfIncrStats('pcache_not_possible');
295 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions,
296 $linestart, true, $this->mRevisionId );
297 $this->addParserOutput( $parserOutput );
298 wfProfileOut($fname);
299 }
300
301 function addParserOutputNoText( &$parserOutput ) {
302 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
303 $this->addCategoryLinks( $parserOutput->getCategories() );
304 $this->mNewSectionLink = $parserOutput->getNewSection();
305 $this->addKeywords( $parserOutput );
306 if ( $parserOutput->getCacheTime() == -1 ) {
307 $this->enableClientCache( false );
308 }
309 if ( $parserOutput->mHTMLtitle != "" ) {
310 $this->mPagetitle = $parserOutput->mHTMLtitle ;
311 }
312 if ( $parserOutput->mSubtitle != '' ) {
313 $this->mSubtitle .= $parserOutput->mSubtitle ;
314 }
315 }
316
317 function addParserOutput( &$parserOutput ) {
318 $this->addParserOutputNoText( $parserOutput );
319 $this->addHTML( $parserOutput->getText() );
320 }
321
322 /**
323 * Add wikitext to the buffer, assuming that this is the primary text for a page view
324 * Saves the text into the parser cache if possible
325 */
326 function addPrimaryWikiText( $text, $article, $cache = true ) {
327 global $wgParser, $wgUser;
328
329 $this->mParserOptions->setTidy(true);
330 $parserOutput = $wgParser->parse( $text, $article->mTitle,
331 $this->mParserOptions, true, true, $this->mRevisionId );
332 $this->mParserOptions->setTidy(false);
333 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
334 $parserCache =& ParserCache::singleton();
335 $parserCache->save( $parserOutput, $article, $wgUser );
336 }
337
338 $this->addParserOutputNoText( $parserOutput );
339 $text = $parserOutput->getText();
340 $this->mNoGallery = $parserOutput->getNoGallery();
341 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
342 $parserOutput->setText( $text );
343 $this->addHTML( $parserOutput->getText() );
344 }
345
346 /**
347 * For anything that isn't primary text or interface message
348 */
349 function addSecondaryWikiText( $text, $linestart = true ) {
350 global $wgTitle;
351 $this->mParserOptions->setTidy(true);
352 $this->addWikiTextTitle($text, $wgTitle, $linestart);
353 $this->mParserOptions->setTidy(false);
354 }
355
356
357 /**
358 * Add the output of a QuickTemplate to the output buffer
359 * @param QuickTemplate $template
360 */
361 function addTemplate( &$template ) {
362 ob_start();
363 $template->execute();
364 $this->addHTML( ob_get_contents() );
365 ob_end_clean();
366 }
367
368 /**
369 * Parse wikitext and return the HTML.
370 */
371 function parse( $text, $linestart = true, $interface = false ) {
372 global $wgParser, $wgTitle;
373 if ( $interface) { $this->mParserOptions->setInterfaceMessage(true); }
374 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions,
375 $linestart, true, $this->mRevisionId );
376 if ( $interface) { $this->mParserOptions->setInterfaceMessage(false); }
377 return $parserOutput->getText();
378 }
379
380 /**
381 * @param $article
382 * @param $user
383 *
384 * @return bool
385 */
386 function tryParserCache( &$article, $user ) {
387 $parserCache =& ParserCache::singleton();
388 $parserOutput = $parserCache->get( $article, $user );
389 if ( $parserOutput !== false ) {
390 $this->addParserOutputNoText( $parserOutput );
391 $text = $parserOutput->getText();
392 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
393 $this->addHTML( $text );
394 return true;
395 } else {
396 return false;
397 }
398 }
399
400 /**
401 * Set the maximum cache time on the Squid in seconds
402 * @param $maxage
403 */
404 function setSquidMaxage( $maxage ) {
405 $this->mSquidMaxage = $maxage;
406 }
407
408 /**
409 * Use enableClientCache(false) to force it to send nocache headers
410 * @param $state
411 */
412 function enableClientCache( $state ) {
413 return wfSetVar( $this->mEnableClientCache, $state );
414 }
415
416 function uncacheableBecauseRequestvars() {
417 global $wgRequest;
418 return $wgRequest->getText('useskin', false) === false
419 && $wgRequest->getText('uselang', false) === false;
420 }
421
422 function sendCacheControl() {
423 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
424 $fname = 'OutputPage::sendCacheControl';
425
426 if ($this->mETag)
427 header("ETag: $this->mETag");
428
429 # don't serve compressed data to clients who can't handle it
430 # maintain different caches for logged-in users and non-logged in ones
431 header( 'Vary: Accept-Encoding, Cookie' );
432 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache ) {
433 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
434 ! $this->isPrintable() && $this->mSquidMaxage != 0 )
435 {
436 if ( $wgUseESI ) {
437 # We'll purge the proxy cache explicitly, but require end user agents
438 # to revalidate against the proxy on each visit.
439 # Surrogate-Control controls our Squid, Cache-Control downstream caches
440 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
441 # start with a shorter timeout for initial testing
442 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
443 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
444 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
445 } else {
446 # We'll purge the proxy cache for anons explicitly, but require end user agents
447 # to revalidate against the proxy on each visit.
448 # IMPORTANT! The Squid needs to replace the Cache-Control header with
449 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
450 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
451 # start with a shorter timeout for initial testing
452 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
453 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
454 }
455 } else {
456 # We do want clients to cache if they can, but they *must* check for updates
457 # on revisiting the page.
458 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
459 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
460 header( "Cache-Control: private, must-revalidate, max-age=0" );
461 }
462 if($this->mLastModified) header( "Last-modified: {$this->mLastModified}" );
463 } else {
464 wfDebug( "$fname: no caching **\n", false );
465
466 # In general, the absence of a last modified header should be enough to prevent
467 # the client from using its cache. We send a few other things just to make sure.
468 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
469 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
470 header( 'Pragma: no-cache' );
471 }
472 }
473
474 /**
475 * Finally, all the text has been munged and accumulated into
476 * the object, let's actually output it:
477 */
478 function output() {
479 global $wgUser, $wgOutputEncoding;
480 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
481 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
482
483 if( $this->mDoNothing ){
484 return;
485 }
486 $fname = 'OutputPage::output';
487 wfProfileIn( $fname );
488 $sk = $wgUser->getSkin();
489
490 if ( $wgUseAjax ) {
491 $this->addScript( "<script type=\"{$wgJsMimeType}\">
492 var wgScriptPath=\"{$wgScriptPath}\";
493 var wgServer=\"{$wgServer}\";
494 </script>" );
495 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
496 }
497
498 if ( '' != $this->mRedirect ) {
499 if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
500 # Standards require redirect URLs to be absolute
501 global $wgServer;
502 $this->mRedirect = $wgServer . $this->mRedirect;
503 }
504 if( $this->mRedirectCode == '301') {
505 if( !$wgDebugRedirects ) {
506 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
507 }
508 $this->mLastModified = wfTimestamp( TS_RFC2822 );
509 }
510
511 $this->sendCacheControl();
512
513 if( $wgDebugRedirects ) {
514 $url = htmlspecialchars( $this->mRedirect );
515 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
516 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
517 print "</body>\n</html>\n";
518 } else {
519 header( 'Location: '.$this->mRedirect );
520 }
521 wfProfileOut( $fname );
522 return;
523 }
524 elseif ( $this->mStatusCode )
525 {
526 $statusMessage = array(
527 100 => 'Continue',
528 101 => 'Switching Protocols',
529 102 => 'Processing',
530 200 => 'OK',
531 201 => 'Created',
532 202 => 'Accepted',
533 203 => 'Non-Authoritative Information',
534 204 => 'No Content',
535 205 => 'Reset Content',
536 206 => 'Partial Content',
537 207 => 'Multi-Status',
538 300 => 'Multiple Choices',
539 301 => 'Moved Permanently',
540 302 => 'Found',
541 303 => 'See Other',
542 304 => 'Not Modified',
543 305 => 'Use Proxy',
544 307 => 'Temporary Redirect',
545 400 => 'Bad Request',
546 401 => 'Unauthorized',
547 402 => 'Payment Required',
548 403 => 'Forbidden',
549 404 => 'Not Found',
550 405 => 'Method Not Allowed',
551 406 => 'Not Acceptable',
552 407 => 'Proxy Authentication Required',
553 408 => 'Request Timeout',
554 409 => 'Conflict',
555 410 => 'Gone',
556 411 => 'Length Required',
557 412 => 'Precondition Failed',
558 413 => 'Request Entity Too Large',
559 414 => 'Request-URI Too Large',
560 415 => 'Unsupported Media Type',
561 416 => 'Request Range Not Satisfiable',
562 417 => 'Expectation Failed',
563 422 => 'Unprocessable Entity',
564 423 => 'Locked',
565 424 => 'Failed Dependency',
566 500 => 'Internal Server Error',
567 501 => 'Not Implemented',
568 502 => 'Bad Gateway',
569 503 => 'Service Unavailable',
570 504 => 'Gateway Timeout',
571 505 => 'HTTP Version Not Supported',
572 507 => 'Insufficient Storage'
573 );
574
575 if ( $statusMessage[$this->mStatusCode] )
576 header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] );
577 }
578
579 # Buffer output; final headers may depend on later processing
580 ob_start();
581
582 # Disable temporary placeholders, so that the skin produces HTML
583 $sk->postParseLinkColour( false );
584
585 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
586 header( 'Content-language: '.$wgContLanguageCode );
587
588 if ($this->mArticleBodyOnly) {
589 $this->out($this->mBodytext);
590 } else {
591 wfProfileIn( 'Output-skin' );
592 $sk->outputPage( $this );
593 wfProfileOut( 'Output-skin' );
594 }
595
596 $this->sendCacheControl();
597 ob_end_flush();
598 wfProfileOut( $fname );
599 }
600
601 function out( $ins ) {
602 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
603 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
604 $outs = $ins;
605 } else {
606 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
607 if ( false === $outs ) { $outs = $ins; }
608 }
609 print $outs;
610 }
611
612 function setEncodings() {
613 global $wgInputEncoding, $wgOutputEncoding;
614 global $wgUser, $wgContLang;
615
616 $wgInputEncoding = strtolower( $wgInputEncoding );
617
618 if( $wgUser->getOption( 'altencoding' ) ) {
619 $wgContLang->setAltEncoding();
620 return;
621 }
622
623 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
624 $wgOutputEncoding = strtolower( $wgOutputEncoding );
625 return;
626 }
627 $wgOutputEncoding = $wgInputEncoding;
628 }
629
630 /**
631 * Returns a HTML comment with the elapsed time since request.
632 * This method has no side effects.
633 * Use wfReportTime() instead.
634 * @return string
635 * @deprecated
636 */
637 function reportTime() {
638 $time = wfReportTime();
639 return $time;
640 }
641
642 /**
643 * Produce a "user is blocked" page
644 */
645 function blockedPage( $return = true ) {
646 global $wgUser, $wgContLang, $wgTitle;
647
648 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
649 $this->setRobotpolicy( 'noindex,nofollow' );
650 $this->setArticleRelated( false );
651
652 $id = $wgUser->blockedBy();
653 $reason = $wgUser->blockedFor();
654 $ip = wfGetIP();
655
656 if ( is_numeric( $id ) ) {
657 $name = User::whoIs( $id );
658 } else {
659 $name = $id;
660 }
661 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
662
663 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
664
665 # Don't auto-return to special pages
666 if( $return ) {
667 $return = $wgTitle->getNamespace() > -1 ? $wgTitle->getPrefixedText() : NULL;
668 $this->returnToMain( false, $return );
669 }
670 }
671
672 /**
673 * Note: these arguments are keys into wfMsg(), not text!
674 */
675 function showErrorPage( $title, $msg ) {
676 global $wgTitle;
677
678 $this->mDebugtext .= 'Original title: ' .
679 $wgTitle->getPrefixedText() . "\n";
680 $this->setPageTitle( wfMsg( $title ) );
681 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
682 $this->setRobotpolicy( 'noindex,nofollow' );
683 $this->setArticleRelated( false );
684 $this->enableClientCache( false );
685 $this->mRedirect = '';
686
687 $this->mBodytext = '';
688 $this->addWikiText( wfMsg( $msg ) );
689 $this->returnToMain( false );
690 }
691
692 /** @obsolete */
693 function errorpage( $title, $msg ) {
694 throw new ErrorPageError( $title, $msg );
695 }
696
697 /**
698 * Display an error page indicating that a given version of MediaWiki is
699 * required to use it
700 *
701 * @param mixed $version The version of MediaWiki needed to use the page
702 */
703 function versionRequired( $version ) {
704 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
705 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
706 $this->setRobotpolicy( 'noindex,nofollow' );
707 $this->setArticleRelated( false );
708 $this->mBodytext = '';
709
710 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
711 $this->returnToMain();
712 }
713
714 /**
715 * Display an error page noting that a given permission bit is required.
716 * This should generally replace the sysopRequired, developerRequired etc.
717 * @param string $permission key required
718 */
719 function permissionRequired( $permission ) {
720 global $wgUser;
721
722 $this->setPageTitle( wfMsg( 'badaccess' ) );
723 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
724 $this->setRobotpolicy( 'noindex,nofollow' );
725 $this->setArticleRelated( false );
726 $this->mBodytext = '';
727
728 $sk = $wgUser->getSkin();
729 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
730 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
731 $this->returnToMain();
732 }
733
734 /**
735 * @deprecated
736 */
737 function sysopRequired() {
738 global $wgUser;
739
740 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
741 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
742 $this->setRobotpolicy( 'noindex,nofollow' );
743 $this->setArticleRelated( false );
744 $this->mBodytext = '';
745
746 $sk = $wgUser->getSkin();
747 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
748 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
749 $this->returnToMain();
750 }
751
752 /**
753 * @deprecated
754 */
755 function developerRequired() {
756 global $wgUser;
757
758 $this->setPageTitle( wfMsg( 'developertitle' ) );
759 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
760 $this->setRobotpolicy( 'noindex,nofollow' );
761 $this->setArticleRelated( false );
762 $this->mBodytext = '';
763
764 $sk = $wgUser->getSkin();
765 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
766 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
767 $this->returnToMain();
768 }
769
770 /**
771 * Produce the stock "please login to use the wiki" page
772 */
773 function loginToUse() {
774 global $wgUser, $wgTitle, $wgContLang;
775 $skin = $wgUser->getSkin();
776
777 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
778 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
779 $this->setRobotPolicy( 'noindex,nofollow' );
780 $this->setArticleFlag( false );
781
782 $loginTitle = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
783 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
784 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
785 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
786
787 $this->returnToMain();
788 }
789
790 /** @obsolete */
791 function databaseError( $fname, $sql, $error, $errno ) {
792 throw new MWException( "OutputPage::databaseError is obsolete\n" );
793 }
794
795 function readOnlyPage( $source = null, $protected = false ) {
796 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
797
798 $this->setRobotpolicy( 'noindex,nofollow' );
799 $this->setArticleRelated( false );
800
801 if( $protected ) {
802 $skin = $wgUser->getSkin();
803 $this->setPageTitle( wfMsg( 'viewsource' ) );
804 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
805
806 # Determine if protection is due to the page being a system message
807 # and show an appropriate explanation
808 if( $wgTitle->getNamespace() == NS_MEDIAWIKI && !$wgUser->isAllowed( 'editinterface' ) ) {
809 $this->addWikiText( wfMsg( 'protectedinterface' ) );
810 } else {
811 $this->addWikiText( wfMsg( 'protectedtext' ) );
812 }
813 } else {
814 $this->setPageTitle( wfMsg( 'readonly' ) );
815 if ( $wgReadOnly ) {
816 $reason = $wgReadOnly;
817 } else {
818 $reason = file_get_contents( $wgReadOnlyFile );
819 }
820 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
821 }
822
823 if( is_string( $source ) ) {
824 if( strcmp( $source, '' ) == 0 ) {
825 global $wgTitle;
826 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI ) {
827 $source = wfMsgWeirdKey ( $wgTitle->getText() );
828 } else {
829 $source = '';
830 }
831 }
832 $rows = $wgUser->getIntOption( 'rows' );
833 $cols = $wgUser->getIntOption( 'cols' );
834
835 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
836 htmlspecialchars( $source ) . "\n</textarea>";
837 $this->addHTML( $text );
838 }
839
840 $this->returnToMain( false );
841 }
842
843 /** @obsolete */
844 function fatalError( $message ) {
845 throw new FatalError( $message );
846 }
847
848 /** @obsolete */
849 function unexpectedValueError( $name, $val ) {
850 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
851 }
852
853 /** @obsolete */
854 function fileCopyError( $old, $new ) {
855 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
856 }
857
858 /** @obsolete */
859 function fileRenameError( $old, $new ) {
860 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
861 }
862
863 /** @obsolete */
864 function fileDeleteError( $name ) {
865 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
866 }
867
868 /** @obsolete */
869 function fileNotFoundError( $name ) {
870 throw new FatalError( wfMsg( 'filenotfound', $name ) );
871 }
872
873 function showFatalError( $message ) {
874 $this->setPageTitle( wfMsg( "internalerror" ) );
875 $this->setRobotpolicy( "noindex,nofollow" );
876 $this->setArticleRelated( false );
877 $this->enableClientCache( false );
878 $this->mRedirect = '';
879 $this->mBodytext = $message;
880 }
881
882 function showUnexpectedValueError( $name, $val ) {
883 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
884 }
885
886 function showFileCopyError( $old, $new ) {
887 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
888 }
889
890 function showFileRenameError( $old, $new ) {
891 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
892 }
893
894 function showFileDeleteError( $name ) {
895 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
896 }
897
898 function showFileNotFoundError( $name ) {
899 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
900 }
901
902 /**
903 * return from error messages or notes
904 * @param $auto automatically redirect the user after 10 seconds
905 * @param $returnto page title to return to. Default is Main Page.
906 */
907 function returnToMain( $auto = true, $returnto = NULL ) {
908 global $wgUser, $wgOut, $wgRequest;
909
910 if ( $returnto == NULL ) {
911 $returnto = $wgRequest->getText( 'returnto' );
912 }
913
914 if ( '' === $returnto ) {
915 $returnto = wfMsgForContent( 'mainpage' );
916 }
917
918 if ( is_object( $returnto ) ) {
919 $titleObj = $returnto;
920 } else {
921 $titleObj = Title::newFromText( $returnto );
922 }
923 if ( !is_object( $titleObj ) ) {
924 $titleObj = Title::newMainPage();
925 }
926
927 $sk = $wgUser->getSkin();
928 $link = $sk->makeLinkObj( $titleObj, '' );
929
930 $r = wfMsg( 'returnto', $link );
931 if ( $auto ) {
932 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
933 }
934 $wgOut->addHTML( "\n<p>$r</p>\n" );
935 }
936
937 /**
938 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
939 * and uses the first 10 of them for META keywords
940 */
941 function addKeywords( &$parserOutput ) {
942 global $wgTitle;
943 $this->addKeyword( $wgTitle->getPrefixedText() );
944 $count = 1;
945 $links2d =& $parserOutput->getLinks();
946 if ( !is_array( $links2d ) ) {
947 return;
948 }
949 foreach ( $links2d as $ns => $dbkeys ) {
950 foreach( $dbkeys as $dbkey => $id ) {
951 $this->addKeyword( $dbkey );
952 if ( ++$count > 10 ) {
953 break 2;
954 }
955 }
956 }
957 }
958
959 /**
960 * @access private
961 * @return string
962 */
963 function headElement() {
964 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
965 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
966
967 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
968 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
969 } else {
970 $ret = '';
971 }
972
973 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
974
975 if ( '' == $this->getHTMLTitle() ) {
976 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
977 }
978
979 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
980 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
981 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
982 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
983
984 $ret .= $this->getHeadLinks();
985 global $wgStylePath;
986 if( $this->isPrintable() ) {
987 $media = '';
988 } else {
989 $media = "media='print'";
990 }
991 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
992 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
993
994 $sk = $wgUser->getSkin();
995 $ret .= $sk->getHeadScripts();
996 $ret .= $this->mScripts;
997 $ret .= $sk->getUserStyles();
998
999 if ($wgUseTrackbacks && $this->isArticleRelated())
1000 $ret .= $wgTitle->trackbackRDF();
1001
1002 $ret .= "</head>\n";
1003 return $ret;
1004 }
1005
1006 function getHeadLinks() {
1007 global $wgRequest;
1008 $ret = '';
1009 foreach ( $this->mMetatags as $tag ) {
1010 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1011 $a = 'http-equiv';
1012 $tag[0] = substr( $tag[0], 5 );
1013 } else {
1014 $a = 'name';
1015 }
1016 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1017 }
1018
1019 $p = $this->mRobotpolicy;
1020 if( $p !== '' && $p != 'index,follow' ) {
1021 // http://www.robotstxt.org/wc/meta-user.html
1022 // Only show if it's different from the default robots policy
1023 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1024 }
1025
1026 if ( count( $this->mKeywords ) > 0 ) {
1027 $strip = array(
1028 "/<.*?>/" => '',
1029 "/_/" => ' '
1030 );
1031 $ret .= "<meta name=\"keywords\" content=\"" .
1032 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
1033 }
1034 foreach ( $this->mLinktags as $tag ) {
1035 $ret .= '<link';
1036 foreach( $tag as $attr => $val ) {
1037 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1038 }
1039 $ret .= " />\n";
1040 }
1041 if( $this->isSyndicated() ) {
1042 # FIXME: centralize the mime-type and name information in Feed.php
1043 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1044 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1045 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1046 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1047 }
1048
1049 return $ret;
1050 }
1051
1052 /**
1053 * Turn off regular page output and return an error reponse
1054 * for when rate limiting has triggered.
1055 * @todo i18n
1056 * @access public
1057 */
1058 function rateLimited() {
1059 global $wgOut;
1060 $wgOut->disable();
1061 wfHttpError( 500, 'Internal Server Error',
1062 'Sorry, the server has encountered an internal error. ' .
1063 'Please wait a moment and hit "refresh" to submit the request again.' );
1064 }
1065
1066 /**
1067 * Show an "add new section" link?
1068 *
1069 * @return bool True if the parser output instructs us to add one
1070 */
1071 function showNewSectionLink() {
1072 return $this->mNewSectionLink;
1073 }
1074
1075 }
1076 ?>