Revert to r14165 . Did too many changes, didnt even run parserTests (i am bad)
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( -1 );
4 /**
5 * @package MediaWiki
6 */
7
8 if ( $wgUseTeX )
9 require_once 'Math.php';
10
11 /**
12 * @todo document
13 * @package MediaWiki
14 */
15 class OutputPage {
16 var $mHeaders, $mMetatags, $mKeywords;
17 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
18 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
19 var $mSubtitle, $mRedirect, $mStatusCode;
20 var $mLastModified, $mETag, $mCategoryLinks;
21 var $mScripts, $mLinkColours, $mPageLinkTitle;
22
23 var $mSuppressQuickbar;
24 var $mOnloadHandler;
25 var $mDoNothing;
26 var $mContainsOldMagic, $mContainsNewMagic;
27 var $mIsArticleRelated;
28 var $mParserOptions;
29 var $mShowFeedLinks = false;
30 var $mEnableClientCache = true;
31 var $mArticleBodyOnly = false;
32
33 var $mNewSectionLink = false;
34
35 /**
36 * Constructor
37 * Initialise private variables
38 */
39 function OutputPage() {
40 $this->mHeaders = $this->mMetatags =
41 $this->mKeywords = $this->mLinktags = array();
42 $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
43 $this->mRedirect = $this->mLastModified =
44 $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
45 $this->mOnloadHandler = $this->mPageLinkTitle = '';
46 $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
47 $this->mSuppressQuickbar = $this->mPrintable = false;
48 $this->mLanguageLinks = array();
49 $this->mCategoryLinks = array();
50 $this->mDoNothing = false;
51 $this->mContainsOldMagic = $this->mContainsNewMagic = 0;
52 $this->mParserOptions = ParserOptions::newFromUser( $temp = NULL );
53 $this->mSquidMaxage = 0;
54 $this->mScripts = '';
55 $this->mETag = false;
56 $this->mRevisionId = null;
57 $this->mNewSectionLink = false;
58 }
59
60 function addHeader( $name, $val ) { array_push( $this->mHeaders, $name.': '.$val ); }
61 function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $url; $this->mRedirectCode = $responsecode; }
62 function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; }
63
64 # To add an http-equiv meta tag, precede the name with "http:"
65 function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
66 function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
67 function addScript( $script ) { $this->mScripts .= $script; }
68 function getScript() { return $this->mScripts; }
69
70 function setETag($tag) { $this->mETag = $tag; }
71 function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; }
72 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly; }
73
74 function addLink( $linkarr ) {
75 # $linkarr should be an associative array of attributes. We'll escape on output.
76 array_push( $this->mLinktags, $linkarr );
77 }
78
79 function addMetadataLink( $linkarr ) {
80 # note: buggy CC software only reads first "meta" link
81 static $haveMeta = false;
82 $linkarr['rel'] = ($haveMeta) ? 'alternate meta' : 'meta';
83 $this->addLink( $linkarr );
84 $haveMeta = true;
85 }
86
87 /**
88 * checkLastModified tells the client to use the client-cached page if
89 * possible. If sucessful, the OutputPage is disabled so that
90 * any future call to OutputPage->output() have no effect. The method
91 * returns true iff cache-ok headers was sent.
92 */
93 function checkLastModified ( $timestamp ) {
94 global $wgCachePages, $wgCacheEpoch, $wgUser;
95 if ( !$timestamp || $timestamp == '19700101000000' ) {
96 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
97 return;
98 }
99 if( !$wgCachePages ) {
100 wfDebug( "CACHE DISABLED\n", false );
101 return;
102 }
103 if( $wgUser->getOption( 'nocache' ) ) {
104 wfDebug( "USER DISABLED CACHE\n", false );
105 return;
106 }
107
108 $timestamp=wfTimestamp(TS_MW,$timestamp);
109 $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched, $wgCacheEpoch ) );
110
111 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
112 # IE sends sizes after the date like this:
113 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
114 # this breaks strtotime().
115 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
116 $modsinceTime = strtotime( $modsince );
117 $ismodsince = wfTimestamp( TS_MW, $modsinceTime ? $modsinceTime : 1 );
118 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
119 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
120 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
121 # Make sure you're in a place you can leave when you call us!
122 header( "HTTP/1.0 304 Not Modified" );
123 $this->mLastModified = $lastmod;
124 $this->sendCacheControl();
125 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
126 $this->disable();
127 @ob_end_clean(); // Don't output compressed blob
128 return true;
129 } else {
130 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
131 $this->mLastModified = $lastmod;
132 }
133 } else {
134 wfDebug( "client did not send If-Modified-Since header\n", false );
135 $this->mLastModified = $lastmod;
136 }
137 }
138
139 function getPageTitleActionText () {
140 global $action;
141 switch($action) {
142 case 'edit':
143 case 'delete':
144 case 'protect':
145 case 'unprotect':
146 case 'watch':
147 case 'unwatch':
148 // Display title is already customized
149 return '';
150 case 'history':
151 return wfMsg('history_short');
152 case 'submit':
153 // FIXME: bug 2735; not correct for special pages etc
154 return wfMsg('preview');
155 case 'info':
156 return wfMsg('info_short');
157 default:
158 return '';
159 }
160 }
161
162 function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
163 function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
164 function setPageTitle( $name ) {
165 global $action, $wgContLang;
166 $name = $wgContLang->convert($name, true);
167 $this->mPagetitle = $name;
168 if(!empty($action)) {
169 $taction = $this->getPageTitleActionText();
170 if( !empty( $taction ) ) {
171 $name .= ' - '.$taction;
172 }
173 }
174
175 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
176 }
177 function getHTMLTitle() { return $this->mHTMLtitle; }
178 function getPageTitle() { return $this->mPagetitle; }
179 function setSubtitle( $str ) { $this->mSubtitle = /*$this->parse(*/$str/*)*/; } // @bug 2514
180 function getSubtitle() { return $this->mSubtitle; }
181 function isArticle() { return $this->mIsarticle; }
182 function setPrintable() { $this->mPrintable = true; }
183 function isPrintable() { return $this->mPrintable; }
184 function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
185 function isSyndicated() { return $this->mShowFeedLinks; }
186 function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
187 function getOnloadHandler() { return $this->mOnloadHandler; }
188 function disable() { $this->mDoNothing = true; }
189
190 function setArticleRelated( $v ) {
191 $this->mIsArticleRelated = $v;
192 if ( !$v ) {
193 $this->mIsarticle = false;
194 }
195 }
196 function setArticleFlag( $v ) {
197 $this->mIsarticle = $v;
198 if ( $v ) {
199 $this->mIsArticleRelated = $v;
200 }
201 }
202
203 function isArticleRelated() { return $this->mIsArticleRelated; }
204
205 function getLanguageLinks() { return $this->mLanguageLinks; }
206 function addLanguageLinks($newLinkArray) {
207 $this->mLanguageLinks += $newLinkArray;
208 }
209 function setLanguageLinks($newLinkArray) {
210 $this->mLanguageLinks = $newLinkArray;
211 }
212
213 function getCategoryLinks() {
214 return $this->mCategoryLinks;
215 }
216
217 /**
218 * Add an array of categories, with names in the keys
219 */
220 function addCategoryLinks($categories) {
221 global $wgUser, $wgContLang;
222
223 if ( !is_array( $categories ) ) {
224 return;
225 }
226 # Add the links to the link cache in a batch
227 $arr = array( NS_CATEGORY => $categories );
228 $lb = new LinkBatch;
229 $lb->setArray( $arr );
230 $lb->execute();
231
232 $sk =& $wgUser->getSkin();
233 foreach ( $categories as $category => $arbitrary ) {
234 $title = Title::makeTitleSafe( NS_CATEGORY, $category );
235 $text = $wgContLang->convertHtml( $title->getText() );
236 $this->mCategoryLinks[] = $sk->makeLinkObj( $title, $text );
237 }
238 }
239
240 function setCategoryLinks($categories) {
241 $this->mCategoryLinks = array();
242 $this->addCategoryLinks($categories);
243 }
244
245 function suppressQuickbar() { $this->mSuppressQuickbar = true; }
246 function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
247
248 function addHTML( $text ) { $this->mBodytext .= $text; }
249 function clearHTML() { $this->mBodytext = ''; }
250 function getHTML() { return $this->mBodytext; }
251 function debug( $text ) { $this->mDebugtext .= $text; }
252
253 /* @deprecated */
254 function setParserOptions( $options ) {
255 return $this->ParserOptions( $options );
256 }
257
258 function ParserOptions( $options = null ) {
259 return wfSetVar( $this->mParserOptions, $options );
260 }
261
262 /**
263 * Set the revision ID which will be seen by the wiki text parser
264 * for things such as embedded {{REVISIONID}} variable use.
265 * @param mixed $revid an integer, or NULL
266 * @return mixed previous value
267 */
268 function setRevisionId( $revid ) {
269 $val = is_null( $revid ) ? null : intval( $revid );
270 return wfSetVar( $this->mRevisionId, $val );
271 }
272
273 /**
274 * Convert wikitext to HTML and add it to the buffer
275 * Default assumes that the current page title will
276 * be used.
277 */
278 function addWikiText( $text, $linestart = true ) {
279 global $wgTitle;
280 $this->addWikiTextTitle($text, $wgTitle, $linestart);
281 }
282
283 function addWikiTextWithTitle($text, &$title, $linestart = true) {
284 $this->addWikiTextTitle($text, $title, $linestart);
285 }
286
287 function addWikiTextTitle($text, &$title, $linestart) {
288 global $wgParser;
289 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions,
290 $linestart, true, $this->mRevisionId );
291 $this->addParserOutput( $parserOutput );
292 }
293
294 function addParserOutputNoText( &$parserOutput ) {
295 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
296 $this->addCategoryLinks( $parserOutput->getCategories() );
297 $this->mNewSectionLink = $parserOutput->getNewSection();
298 $this->addKeywords( $parserOutput );
299 if ( $parserOutput->getCacheTime() == -1 ) {
300 $this->enableClientCache( false );
301 }
302 if ( $parserOutput->mHTMLtitle != "" ) {
303 $this->mPagetitle = $parserOutput->mHTMLtitle ;
304 $this->mSubtitle .= $parserOutput->mSubtitle ;
305 }
306 }
307
308 function addParserOutput( &$parserOutput ) {
309 $this->addParserOutputNoText( $parserOutput );
310 $this->addHTML( $parserOutput->getText() );
311 }
312
313 /**
314 * Add wikitext to the buffer, assuming that this is the primary text for a page view
315 * Saves the text into the parser cache if possible
316 */
317 function addPrimaryWikiText( $text, $article, $cache = true ) {
318 global $wgParser, $wgUser;
319
320 $this->mParserOptions->setTidy(true);
321 $parserOutput = $wgParser->parse( $text, $article->mTitle,
322 $this->mParserOptions, true, true, $this->mRevisionId );
323 $this->mParserOptions->setTidy(false);
324 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
325 $parserCache =& ParserCache::singleton();
326 $parserCache->save( $parserOutput, $article, $wgUser );
327 }
328
329 $this->addParserOutputNoText( $parserOutput );
330 $text = $parserOutput->getText();
331 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
332 $parserOutput->setText( $text );
333 $this->addHTML( $parserOutput->getText() );
334 }
335
336 /**
337 * For anything that isn't primary text or interface message
338 */
339 function addSecondaryWikiText( $text, $linestart = true ) {
340 global $wgTitle;
341 $this->mParserOptions->setTidy(true);
342 $this->addWikiTextTitle($text, $wgTitle, $linestart);
343 $this->mParserOptions->setTidy(false);
344 }
345
346
347 /**
348 * Add the output of a QuickTemplate to the output buffer
349 * @param QuickTemplate $template
350 */
351 function addTemplate( &$template ) {
352 ob_start();
353 $template->execute();
354 $this->addHTML( ob_get_contents() );
355 ob_end_clean();
356 }
357
358 /**
359 * Parse wikitext and return the HTML.
360 */
361 function parse( $text, $linestart = true, $interface = false ) {
362 global $wgParser, $wgTitle;
363 if ( $interface) { $this->mParserOptions->setInterfaceMessage(true); }
364 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions,
365 $linestart, true, $this->mRevisionId );
366 if ( $interface) { $this->mParserOptions->setInterfaceMessage(false); }
367 return $parserOutput->getText();
368 }
369
370 /**
371 * @param $article
372 * @param $user
373 *
374 * @return bool
375 */
376 function tryParserCache( &$article, $user ) {
377 $parserCache =& ParserCache::singleton();
378 $parserOutput = $parserCache->get( $article, $user );
379 if ( $parserOutput !== false ) {
380 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
381 $this->addCategoryLinks( $parserOutput->getCategories() );
382 $this->addKeywords( $parserOutput );
383 $this->mNewSectionLink = $parserOutput->getNewSection();
384 $text = $parserOutput->getText();
385 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
386 $this->addHTML( $text );
387 $t = $parserOutput->getTitleText();
388 if( !empty( $t ) ) {
389 $this->setPageTitle( $t );
390 }
391 return true;
392 } else {
393 return false;
394 }
395 }
396
397 /**
398 * Set the maximum cache time on the Squid in seconds
399 * @param $maxage
400 */
401 function setSquidMaxage( $maxage ) {
402 $this->mSquidMaxage = $maxage;
403 }
404
405 /**
406 * Use enableClientCache(false) to force it to send nocache headers
407 * @param $state
408 */
409 function enableClientCache( $state ) {
410 return wfSetVar( $this->mEnableClientCache, $state );
411 }
412
413 function uncacheableBecauseRequestvars() {
414 global $wgRequest;
415 return $wgRequest->getText('useskin', false) === false
416 && $wgRequest->getText('uselang', false) === false;
417 }
418
419 function sendCacheControl() {
420 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
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( "** 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( "** 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( "** 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( "** 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 errorpage( $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 $this->output();
686 wfErrorExit();
687 }
688
689 /**
690 * Display an error page indicating that a given version of MediaWiki is
691 * required to use it
692 *
693 * @param mixed $version The version of MediaWiki needed to use the page
694 */
695 function versionRequired( $version ) {
696 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
697 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
698 $this->setRobotpolicy( 'noindex,nofollow' );
699 $this->setArticleRelated( false );
700 $this->mBodytext = '';
701
702 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
703 $this->returnToMain();
704 }
705
706 /**
707 * Display an error page noting that a given permission bit is required.
708 * This should generally replace the sysopRequired, developerRequired etc.
709 * @param string $permission key required
710 */
711 function permissionRequired( $permission ) {
712 global $wgUser;
713
714 $this->setPageTitle( wfMsg( 'badaccess' ) );
715 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
716 $this->setRobotpolicy( 'noindex,nofollow' );
717 $this->setArticleRelated( false );
718 $this->mBodytext = '';
719
720 $sk = $wgUser->getSkin();
721 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
722 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
723 $this->returnToMain();
724 }
725
726 /**
727 * @deprecated
728 */
729 function sysopRequired() {
730 global $wgUser;
731
732 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
733 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
734 $this->setRobotpolicy( 'noindex,nofollow' );
735 $this->setArticleRelated( false );
736 $this->mBodytext = '';
737
738 $sk = $wgUser->getSkin();
739 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
740 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
741 $this->returnToMain();
742 }
743
744 /**
745 * @deprecated
746 */
747 function developerRequired() {
748 global $wgUser;
749
750 $this->setPageTitle( wfMsg( 'developertitle' ) );
751 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
752 $this->setRobotpolicy( 'noindex,nofollow' );
753 $this->setArticleRelated( false );
754 $this->mBodytext = '';
755
756 $sk = $wgUser->getSkin();
757 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
758 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
759 $this->returnToMain();
760 }
761
762 /**
763 * Produce the stock "please login to use the wiki" page
764 */
765 function loginToUse() {
766 global $wgUser, $wgTitle, $wgContLang;
767 $skin = $wgUser->getSkin();
768
769 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
770 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
771 $this->setRobotPolicy( 'noindex,nofollow' );
772 $this->setArticleFlag( false );
773
774 $loginTitle = Title::makeTitle( NS_SPECIAL, 'Userlogin' );
775 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
776 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
777 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
778
779 $this->returnToMain();
780 }
781
782 function databaseError( $fname, $sql, $error, $errno ) {
783 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
784
785 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
786 $this->setRobotpolicy( 'noindex,nofollow' );
787 $this->setArticleRelated( false );
788 $this->enableClientCache( false );
789 $this->mRedirect = '';
790
791 if( !$wgShowSQLErrors ) {
792 $sql = wfMsg( 'sqlhidden' );
793 }
794
795 if ( $wgCommandLineMode ) {
796 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
797 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
798 } else {
799 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
800 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
801 }
802
803 if ( $wgCommandLineMode || !is_object( $wgUser )) {
804 print $msg."\n";
805 wfErrorExit();
806 }
807 $this->mBodytext = $msg;
808 $this->output();
809 wfErrorExit();
810 }
811
812 function readOnlyPage( $source = null, $protected = false ) {
813 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
814
815 $this->setRobotpolicy( 'noindex,nofollow' );
816 $this->setArticleRelated( false );
817
818 if( $protected ) {
819 $skin = $wgUser->getSkin();
820 $this->setPageTitle( wfMsg( 'viewsource' ) );
821 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
822
823 # Determine if protection is due to the page being a system message
824 # and show an appropriate explanation
825 if( $wgTitle->getNamespace() == NS_MEDIAWIKI && !$wgUser->isAllowed( 'editinterface' ) ) {
826 $this->addWikiText( wfMsg( 'protectedinterface' ) );
827 } else {
828 $this->addWikiText( wfMsg( 'protectedtext' ) );
829 }
830 } else {
831 $this->setPageTitle( wfMsg( 'readonly' ) );
832 if ( $wgReadOnly ) {
833 $reason = $wgReadOnly;
834 } else {
835 $reason = file_get_contents( $wgReadOnlyFile );
836 }
837 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
838 }
839
840 if( is_string( $source ) ) {
841 if( strcmp( $source, '' ) == 0 ) {
842 global $wgTitle;
843 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI ) {
844 $source = wfMsgWeirdKey ( $wgTitle->getText() );
845 } else {
846 $source = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
847 }
848 }
849 $rows = $wgUser->getOption( 'rows' );
850 $cols = $wgUser->getOption( 'cols' );
851
852 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
853 htmlspecialchars( $source ) . "\n</textarea>";
854 $this->addHTML( $text );
855 }
856
857 $this->returnToMain( false );
858 }
859
860 function fatalError( $message ) {
861 $this->setPageTitle( wfMsg( "internalerror" ) );
862 $this->setRobotpolicy( "noindex,nofollow" );
863 $this->setArticleRelated( false );
864 $this->enableClientCache( false );
865 $this->mRedirect = '';
866
867 $this->mBodytext = $message;
868 $this->output();
869 wfErrorExit();
870 }
871
872 function unexpectedValueError( $name, $val ) {
873 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
874 }
875
876 function fileCopyError( $old, $new ) {
877 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
878 }
879
880 function fileRenameError( $old, $new ) {
881 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
882 }
883
884 function fileDeleteError( $name ) {
885 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
886 }
887
888 function fileNotFoundError( $name ) {
889 $this->fatalError( wfMsg( 'filenotfound', $name ) );
890 }
891
892 /**
893 * return from error messages or notes
894 * @param $auto automatically redirect the user after 10 seconds
895 * @param $returnto page title to return to. Default is Main Page.
896 */
897 function returnToMain( $auto = true, $returnto = NULL ) {
898 global $wgUser, $wgOut, $wgRequest;
899
900 if ( $returnto == NULL ) {
901 $returnto = $wgRequest->getText( 'returnto' );
902 }
903 $returnto = htmlspecialchars( $returnto );
904
905 $sk = $wgUser->getSkin();
906 if ( '' == $returnto ) {
907 $returnto = wfMsgForContent( 'mainpage' );
908 }
909 $link = $sk->makeLinkObj( Title::newFromText( $returnto ), '' );
910
911 $r = wfMsg( 'returnto', $link );
912 if ( $auto ) {
913 $titleObj = Title::newFromText( $returnto );
914 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
915 }
916 $wgOut->addHTML( "\n<p>$r</p>\n" );
917 }
918
919 /**
920 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
921 * and uses the first 10 of them for META keywords
922 */
923 function addKeywords( &$parserOutput ) {
924 global $wgTitle;
925 $this->addKeyword( $wgTitle->getPrefixedText() );
926 $count = 1;
927 $links2d =& $parserOutput->getLinks();
928 if ( !is_array( $links2d ) ) {
929 return;
930 }
931 foreach ( $links2d as $ns => $dbkeys ) {
932 foreach( $dbkeys as $dbkey => $id ) {
933 $this->addKeyword( $dbkey );
934 if ( ++$count > 10 ) {
935 break 2;
936 }
937 }
938 }
939 }
940
941 /**
942 * @access private
943 * @return string
944 */
945 function headElement() {
946 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
947 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
948
949 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
950 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
951 } else {
952 $ret = '';
953 }
954
955 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
956
957 if ( '' == $this->getHTMLTitle() ) {
958 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
959 }
960
961 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
962 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
963 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
964 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
965
966 $ret .= $this->getHeadLinks();
967 global $wgStylePath;
968 if( $this->isPrintable() ) {
969 $media = '';
970 } else {
971 $media = "media='print'";
972 }
973 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
974 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
975
976 $sk = $wgUser->getSkin();
977 $ret .= $sk->getHeadScripts();
978 $ret .= $this->mScripts;
979 $ret .= $sk->getUserStyles();
980
981 if ($wgUseTrackbacks && $this->isArticleRelated())
982 $ret .= $wgTitle->trackbackRDF();
983
984 $ret .= "</head>\n";
985 return $ret;
986 }
987
988 function getHeadLinks() {
989 global $wgRequest;
990 $ret = '';
991 foreach ( $this->mMetatags as $tag ) {
992 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
993 $a = 'http-equiv';
994 $tag[0] = substr( $tag[0], 5 );
995 } else {
996 $a = 'name';
997 }
998 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
999 }
1000
1001 $p = $this->mRobotpolicy;
1002 if( $p !== '' && $p != 'index,follow' ) {
1003 // http://www.robotstxt.org/wc/meta-user.html
1004 // Only show if it's different from the default robots policy
1005 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1006 }
1007
1008 if ( count( $this->mKeywords ) > 0 ) {
1009 $strip = array(
1010 "/<.*?>/" => '',
1011 "/_/" => ' '
1012 );
1013 $ret .= "<meta name=\"keywords\" content=\"" .
1014 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
1015 }
1016 foreach ( $this->mLinktags as $tag ) {
1017 $ret .= '<link';
1018 foreach( $tag as $attr => $val ) {
1019 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1020 }
1021 $ret .= " />\n";
1022 }
1023 if( $this->isSyndicated() ) {
1024 # FIXME: centralize the mime-type and name information in Feed.php
1025 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1026 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1027 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1028 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1029 }
1030
1031 return $ret;
1032 }
1033
1034 /**
1035 * Turn off regular page output and return an error reponse
1036 * for when rate limiting has triggered.
1037 * @todo i18n
1038 * @access public
1039 */
1040 function rateLimited() {
1041 global $wgOut;
1042 $wgOut->disable();
1043 wfHttpError( 500, 'Internal Server Error',
1044 'Sorry, the server has encountered an internal error. ' .
1045 'Please wait a moment and hit "refresh" to submit the request again.' );
1046 }
1047
1048 /**
1049 * Show an "add new section" link?
1050 *
1051 * @return bool True if the parser output instructs us to add one
1052 */
1053 function showNewSectionLink() {
1054 return $this->mNewSectionLink;
1055 }
1056
1057 }
1058 ?>