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