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