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