f4b83b1367b76f809c01de443c8ed3b0d9acee0a
[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. This is for special pages that add the text later
356 */
357 function parse( $text, $linestart = true ) {
358 global $wgParser, $wgTitle;
359 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions,
360 $linestart, true, $this->mRevisionId );
361 return $parserOutput->getText();
362 }
363
364 /**
365 * @param $article
366 * @param $user
367 *
368 * @return bool
369 */
370 function tryParserCache( &$article, $user ) {
371 $parserCache =& ParserCache::singleton();
372 $parserOutput = $parserCache->get( $article, $user );
373 if ( $parserOutput !== false ) {
374 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
375 $this->addCategoryLinks( $parserOutput->getCategories() );
376 $this->addKeywords( $parserOutput );
377 $text = $parserOutput->getText();
378 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
379 $this->addHTML( $text );
380 $t = $parserOutput->getTitleText();
381 if( !empty( $t ) ) {
382 $this->setPageTitle( $t );
383 }
384 return true;
385 } else {
386 return false;
387 }
388 }
389
390 /**
391 * Set the maximum cache time on the Squid in seconds
392 * @param $maxage
393 */
394 function setSquidMaxage( $maxage ) {
395 $this->mSquidMaxage = $maxage;
396 }
397
398 /**
399 * Use enableClientCache(false) to force it to send nocache headers
400 * @param $state
401 */
402 function enableClientCache( $state ) {
403 return wfSetVar( $this->mEnableClientCache, $state );
404 }
405
406 function uncacheableBecauseRequestvars() {
407 global $wgRequest;
408 return $wgRequest->getText('useskin', false) === false
409 && $wgRequest->getText('uselang', false) === false;
410 }
411
412 function sendCacheControl() {
413 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
414
415 if ($this->mETag)
416 header("ETag: $this->mETag");
417
418 # don't serve compressed data to clients who can't handle it
419 # maintain different caches for logged-in users and non-logged in ones
420 header( 'Vary: Accept-Encoding, Cookie' );
421 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache ) {
422 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
423 ! $this->isPrintable() && $this->mSquidMaxage != 0 )
424 {
425 if ( $wgUseESI ) {
426 # We'll purge the proxy cache explicitly, but require end user agents
427 # to revalidate against the proxy on each visit.
428 # Surrogate-Control controls our Squid, Cache-Control downstream caches
429 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
430 # start with a shorter timeout for initial testing
431 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
432 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
433 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
434 } else {
435 # We'll purge the proxy cache for anons explicitly, but require end user agents
436 # to revalidate against the proxy on each visit.
437 # IMPORTANT! The Squid needs to replace the Cache-Control header with
438 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
439 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
440 # start with a shorter timeout for initial testing
441 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
442 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
443 }
444 } else {
445 # We do want clients to cache if they can, but they *must* check for updates
446 # on revisiting the page.
447 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
448 header( "Expires: -1" );
449 header( "Cache-Control: private, must-revalidate, max-age=0" );
450 }
451 if($this->mLastModified) header( "Last-modified: {$this->mLastModified}" );
452 } else {
453 wfDebug( "** no caching **\n", false );
454
455 # In general, the absence of a last modified header should be enough to prevent
456 # the client from using its cache. We send a few other things just to make sure.
457 header( 'Expires: -1' );
458 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
459 header( 'Pragma: no-cache' );
460 }
461 }
462
463 /**
464 * Finally, all the text has been munged and accumulated into
465 * the object, let's actually output it:
466 */
467 function output() {
468 global $wgUser, $wgOutputEncoding;
469 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
470 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
471
472 if( $this->mDoNothing ){
473 return;
474 }
475 $fname = 'OutputPage::output';
476 wfProfileIn( $fname );
477 $sk = $wgUser->getSkin();
478
479 if ( $wgUseAjax ) {
480 $this->addScript( "<script type=\"{$wgJsMimeType}\">
481 var wgScriptPath=\"{$wgScriptPath}\";
482 var wgServer=\"{$wgServer}\";
483 </script>" );
484 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
485 }
486
487 if ( '' != $this->mRedirect ) {
488 if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
489 # Standards require redirect URLs to be absolute
490 global $wgServer;
491 $this->mRedirect = $wgServer . $this->mRedirect;
492 }
493 if( $this->mRedirectCode == '301') {
494 if( !$wgDebugRedirects ) {
495 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
496 }
497 $this->mLastModified = wfTimestamp( TS_RFC2822 );
498 }
499
500 $this->sendCacheControl();
501
502 if( $wgDebugRedirects ) {
503 $url = htmlspecialchars( $this->mRedirect );
504 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
505 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
506 print "</body>\n</html>\n";
507 } else {
508 header( 'Location: '.$this->mRedirect );
509 }
510 wfProfileOut( $fname );
511 return;
512 }
513 elseif ( $this->mStatusCode )
514 {
515 $statusMessage = array(
516 100 => 'Continue',
517 101 => 'Switching Protocols',
518 102 => 'Processing',
519 200 => 'OK',
520 201 => 'Created',
521 202 => 'Accepted',
522 203 => 'Non-Authoritative Information',
523 204 => 'No Content',
524 205 => 'Reset Content',
525 206 => 'Partial Content',
526 207 => 'Multi-Status',
527 300 => 'Multiple Choices',
528 301 => 'Moved Permanently',
529 302 => 'Found',
530 303 => 'See Other',
531 304 => 'Not Modified',
532 305 => 'Use Proxy',
533 307 => 'Temporary Redirect',
534 400 => 'Bad Request',
535 401 => 'Unauthorized',
536 402 => 'Payment Required',
537 403 => 'Forbidden',
538 404 => 'Not Found',
539 405 => 'Method Not Allowed',
540 406 => 'Not Acceptable',
541 407 => 'Proxy Authentication Required',
542 408 => 'Request Timeout',
543 409 => 'Conflict',
544 410 => 'Gone',
545 411 => 'Length Required',
546 412 => 'Precondition Failed',
547 413 => 'Request Entity Too Large',
548 414 => 'Request-URI Too Large',
549 415 => 'Unsupported Media Type',
550 416 => 'Request Range Not Satisfiable',
551 417 => 'Expectation Failed',
552 422 => 'Unprocessable Entity',
553 423 => 'Locked',
554 424 => 'Failed Dependency',
555 500 => 'Internal Server Error',
556 501 => 'Not Implemented',
557 502 => 'Bad Gateway',
558 503 => 'Service Unavailable',
559 504 => 'Gateway Timeout',
560 505 => 'HTTP Version Not Supported',
561 507 => 'Insufficient Storage'
562 );
563
564 if ( $statusMessage[$this->mStatusCode] )
565 header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] );
566 }
567
568 # Buffer output; final headers may depend on later processing
569 ob_start();
570
571 # Disable temporary placeholders, so that the skin produces HTML
572 $sk->postParseLinkColour( false );
573
574 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
575 header( 'Content-language: '.$wgContLanguageCode );
576
577 if ($this->mArticleBodyOnly) {
578 $this->out($this->mBodytext);
579 } else {
580 wfProfileIn( 'Output-skin' );
581 $sk->outputPage( $this );
582 wfProfileOut( 'Output-skin' );
583 }
584
585 $this->sendCacheControl();
586 ob_end_flush();
587 wfProfileOut( $fname );
588 }
589
590 function out( $ins ) {
591 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
592 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
593 $outs = $ins;
594 } else {
595 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
596 if ( false === $outs ) { $outs = $ins; }
597 }
598 print $outs;
599 }
600
601 function setEncodings() {
602 global $wgInputEncoding, $wgOutputEncoding;
603 global $wgUser, $wgContLang;
604
605 $wgInputEncoding = strtolower( $wgInputEncoding );
606
607 if( $wgUser->getOption( 'altencoding' ) ) {
608 $wgContLang->setAltEncoding();
609 return;
610 }
611
612 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
613 $wgOutputEncoding = strtolower( $wgOutputEncoding );
614 return;
615 }
616 $wgOutputEncoding = $wgInputEncoding;
617 }
618
619 /**
620 * Returns a HTML comment with the elapsed time since request.
621 * This method has no side effects.
622 * Use wfReportTime() instead.
623 * @return string
624 * @deprecated
625 */
626 function reportTime() {
627 $time = wfReportTime();
628 return $time;
629 }
630
631 /**
632 * Produce a "user is blocked" page
633 */
634 function blockedPage() {
635 global $wgUser, $wgContLang;
636
637 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
638 $this->setRobotpolicy( 'noindex,nofollow' );
639 $this->setArticleRelated( false );
640
641 $id = $wgUser->blockedBy();
642 $reason = $wgUser->blockedFor();
643 $ip = wfGetIP();
644
645 if ( is_numeric( $id ) ) {
646 $name = User::whoIs( $id );
647 } else {
648 $name = $id;
649 }
650 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
651
652 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
653 $this->returnToMain( false );
654 }
655
656 /**
657 * Note: these arguments are keys into wfMsg(), not text!
658 */
659 function errorpage( $title, $msg ) {
660 global $wgTitle;
661
662 $this->mDebugtext .= 'Original title: ' .
663 $wgTitle->getPrefixedText() . "\n";
664 $this->setPageTitle( wfMsg( $title ) );
665 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
666 $this->setRobotpolicy( 'noindex,nofollow' );
667 $this->setArticleRelated( false );
668 $this->enableClientCache( false );
669 $this->mRedirect = '';
670
671 $this->mBodytext = '';
672 $this->addWikiText( wfMsg( $msg ) );
673 $this->returnToMain( false );
674
675 $this->output();
676 wfErrorExit();
677 }
678
679 /**
680 * Display an error page indicating that a given version of MediaWiki is
681 * required to use it
682 *
683 * @param mixed $version The version of MediaWiki needed to use the page
684 */
685 function versionRequired( $version ) {
686 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
687 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
688 $this->setRobotpolicy( 'noindex,nofollow' );
689 $this->setArticleRelated( false );
690 $this->mBodytext = '';
691
692 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
693 $this->returnToMain();
694 }
695
696 /**
697 * Display an error page noting that a given permission bit is required.
698 * This should generally replace the sysopRequired, developerRequired etc.
699 * @param string $permission key required
700 */
701 function permissionRequired( $permission ) {
702 global $wgUser;
703
704 $this->setPageTitle( wfMsg( 'badaccess' ) );
705 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
706 $this->setRobotpolicy( 'noindex,nofollow' );
707 $this->setArticleRelated( false );
708 $this->mBodytext = '';
709
710 $sk = $wgUser->getSkin();
711 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
712 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
713 $this->returnToMain();
714 }
715
716 /**
717 * @deprecated
718 */
719 function sysopRequired() {
720 global $wgUser;
721
722 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
723 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
724 $this->setRobotpolicy( 'noindex,nofollow' );
725 $this->setArticleRelated( false );
726 $this->mBodytext = '';
727
728 $sk = $wgUser->getSkin();
729 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
730 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
731 $this->returnToMain();
732 }
733
734 /**
735 * @deprecated
736 */
737 function developerRequired() {
738 global $wgUser;
739
740 $this->setPageTitle( wfMsg( 'developertitle' ) );
741 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
742 $this->setRobotpolicy( 'noindex,nofollow' );
743 $this->setArticleRelated( false );
744 $this->mBodytext = '';
745
746 $sk = $wgUser->getSkin();
747 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
748 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
749 $this->returnToMain();
750 }
751
752 function loginToUse() {
753 global $wgUser, $wgTitle, $wgContLang;
754
755 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
756 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
757 $this->setRobotpolicy( 'noindex,nofollow' );
758 $this->setArticleFlag( false );
759 $this->mBodytext = '';
760 $loginpage = Title::makeTitle(NS_SPECIAL, 'Userlogin');
761 $sk = $wgUser->getSkin();
762 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
763 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
764 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
765
766 # We put a comment in the .html file so a Sysop can diagnose the page the
767 # user can't see.
768 $this->addHTML( "\n<!--" .
769 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
770 ':' .
771 $wgTitle->getDBkey() . '-->' );
772 $this->returnToMain(); # Flip back to the main page after 10 seconds.
773 }
774
775 function databaseError( $fname, $sql, $error, $errno ) {
776 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
777
778 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
779 $this->setRobotpolicy( 'noindex,nofollow' );
780 $this->setArticleRelated( false );
781 $this->enableClientCache( false );
782 $this->mRedirect = '';
783
784 if( !$wgShowSQLErrors ) {
785 $sql = wfMsg( 'sqlhidden' );
786 }
787
788 if ( $wgCommandLineMode ) {
789 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
790 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
791 } else {
792 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
793 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
794 }
795
796 if ( $wgCommandLineMode || !is_object( $wgUser )) {
797 print $msg."\n";
798 wfErrorExit();
799 }
800 $this->mBodytext = $msg;
801 $this->output();
802 wfErrorExit();
803 }
804
805 function readOnlyPage( $source = null, $protected = false ) {
806 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
807
808 $this->setRobotpolicy( 'noindex,nofollow' );
809 $this->setArticleRelated( false );
810
811 if( $protected ) {
812 $skin = $wgUser->getSkin();
813 $this->setPageTitle( wfMsg( 'viewsource' ) );
814 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
815 $this->addWikiText( wfMsg( 'protectedtext' ) );
816 } else {
817 $this->setPageTitle( wfMsg( 'readonly' ) );
818 if ( $wgReadOnly ) {
819 $reason = $wgReadOnly;
820 } else {
821 $reason = file_get_contents( $wgReadOnlyFile );
822 }
823 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
824 }
825
826 if( is_string( $source ) ) {
827 if( strcmp( $source, '' ) == 0 ) {
828 global $wgTitle;
829 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI ) {
830 $source = wfMsgWeirdKey ( $wgTitle->getText() );
831 } else {
832 $source = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
833 }
834 }
835 $rows = $wgUser->getOption( 'rows' );
836 $cols = $wgUser->getOption( 'cols' );
837 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
838 htmlspecialchars( $source ) . "\n</textarea>";
839 $this->addHTML( $text );
840 }
841
842 $this->returnToMain( false );
843 }
844
845 function fatalError( $message ) {
846 $this->setPageTitle( wfMsg( "internalerror" ) );
847 $this->setRobotpolicy( "noindex,nofollow" );
848 $this->setArticleRelated( false );
849 $this->enableClientCache( false );
850 $this->mRedirect = '';
851
852 $this->mBodytext = $message;
853 $this->output();
854 wfErrorExit();
855 }
856
857 function unexpectedValueError( $name, $val ) {
858 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
859 }
860
861 function fileCopyError( $old, $new ) {
862 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
863 }
864
865 function fileRenameError( $old, $new ) {
866 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
867 }
868
869 function fileDeleteError( $name ) {
870 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
871 }
872
873 function fileNotFoundError( $name ) {
874 $this->fatalError( wfMsg( 'filenotfound', $name ) );
875 }
876
877 /**
878 * return from error messages or notes
879 * @param $auto automatically redirect the user after 10 seconds
880 * @param $returnto page title to return to. Default is Main Page.
881 */
882 function returnToMain( $auto = true, $returnto = NULL ) {
883 global $wgUser, $wgOut, $wgRequest;
884
885 if ( $returnto == NULL ) {
886 $returnto = $wgRequest->getText( 'returnto' );
887 }
888 $returnto = htmlspecialchars( $returnto );
889
890 $sk = $wgUser->getSkin();
891 if ( '' == $returnto ) {
892 $returnto = wfMsgForContent( 'mainpage' );
893 }
894 $link = $sk->makeLinkObj( Title::newFromText( $returnto ), '' );
895
896 $r = wfMsg( 'returnto', $link );
897 if ( $auto ) {
898 $titleObj = Title::newFromText( $returnto );
899 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
900 }
901 $wgOut->addHTML( "\n<p>$r</p>\n" );
902 }
903
904 /**
905 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
906 * and uses the first 10 of them for META keywords
907 */
908 function addKeywords( &$parserOutput ) {
909 global $wgTitle;
910 $this->addKeyword( $wgTitle->getPrefixedText() );
911 $count = 1;
912 $links2d =& $parserOutput->getLinks();
913 if ( !is_array( $links2d ) ) {
914 return;
915 }
916 foreach ( $links2d as $ns => $dbkeys ) {
917 foreach( $dbkeys as $dbkey => $id ) {
918 $this->addKeyword( $dbkey );
919 if ( ++$count > 10 ) {
920 break 2;
921 }
922 }
923 }
924 }
925
926 /**
927 * @access private
928 * @return string
929 */
930 function headElement() {
931 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
932 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
933
934 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
935 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
936 } else {
937 $ret = '';
938 }
939
940 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
941
942 if ( '' == $this->getHTMLTitle() ) {
943 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
944 }
945
946 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
947 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
948 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
949 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
950
951 $ret .= $this->getHeadLinks();
952 global $wgStylePath;
953 if( $this->isPrintable() ) {
954 $media = '';
955 } else {
956 $media = "media='print'";
957 }
958 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
959 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
960
961 $sk = $wgUser->getSkin();
962 $ret .= $sk->getHeadScripts();
963 $ret .= $this->mScripts;
964 $ret .= $sk->getUserStyles();
965
966 if ($wgUseTrackbacks && $this->isArticleRelated())
967 $ret .= $wgTitle->trackbackRDF();
968
969 $ret .= "</head>\n";
970 return $ret;
971 }
972
973 function getHeadLinks() {
974 global $wgRequest;
975 $ret = '';
976 foreach ( $this->mMetatags as $tag ) {
977 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
978 $a = 'http-equiv';
979 $tag[0] = substr( $tag[0], 5 );
980 } else {
981 $a = 'name';
982 }
983 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
984 }
985
986 $p = $this->mRobotpolicy;
987 if( $p !== '' && $p != 'index,follow' ) {
988 // http://www.robotstxt.org/wc/meta-user.html
989 // Only show if it's different from the default robots policy
990 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
991 }
992
993 if ( count( $this->mKeywords ) > 0 ) {
994 $strip = array(
995 "/<.*?>/" => '',
996 "/_/" => ' '
997 );
998 $ret .= "<meta name=\"keywords\" content=\"" .
999 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
1000 }
1001 foreach ( $this->mLinktags as $tag ) {
1002 $ret .= '<link';
1003 foreach( $tag as $attr => $val ) {
1004 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1005 }
1006 $ret .= " />\n";
1007 }
1008 if( $this->isSyndicated() ) {
1009 # FIXME: centralize the mime-type and name information in Feed.php
1010 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1011 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1012 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1013 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1014 }
1015
1016 return $ret;
1017 }
1018
1019 /**
1020 * Turn off regular page output and return an error reponse
1021 * for when rate limiting has triggered.
1022 * @todo i18n
1023 * @access public
1024 */
1025 function rateLimited() {
1026 global $wgOut;
1027 $wgOut->disable();
1028 wfHttpError( 500, 'Internal Server Error',
1029 'Sorry, the server has encountered an internal error. ' .
1030 'Please wait a moment and hit "refresh" to submit the request again.' );
1031 }
1032
1033 }
1034 ?>