fix typo in var name
[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 $wgLang, $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, $wgUseTidy;
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, $wgUseTidy;
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, $wgLang, $wgDebugComments, $wgCookieExpiration;
424 global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
425 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
426
427 if( $this->mDoNothing ){
428 return;
429 }
430 $fname = 'OutputPage::output';
431 wfProfileIn( $fname );
432 $sk = $wgUser->getSkin();
433
434 if ( '' != $this->mRedirect ) {
435 if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
436 # Standards require redirect URLs to be absolute
437 global $wgServer;
438 $this->mRedirect = $wgServer . $this->mRedirect;
439 }
440 if( $this->mRedirectCode == '301') {
441 if( !$wgDebugRedirects ) {
442 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
443 }
444 $this->mLastModified = wfTimestamp( TS_RFC2822 );
445 }
446
447 $this->sendCacheControl();
448
449 if( $wgDebugRedirects ) {
450 $url = htmlspecialchars( $this->mRedirect );
451 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
452 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
453 print "</body>\n</html>\n";
454 } else {
455 header( 'Location: '.$this->mRedirect );
456 }
457 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
458 wfProfileOut( $fname );
459 return;
460 }
461 elseif ( $this->mStatusCode )
462 {
463 $statusMessage = array(
464 100 => 'Continue',
465 101 => 'Switching Protocols',
466 102 => 'Processing',
467 200 => 'OK',
468 201 => 'Created',
469 202 => 'Accepted',
470 203 => 'Non-Authoritative Information',
471 204 => 'No Content',
472 205 => 'Reset Content',
473 206 => 'Partial Content',
474 207 => 'Multi-Status',
475 300 => 'Multiple Choices',
476 301 => 'Moved Permanently',
477 302 => 'Found',
478 303 => 'See Other',
479 304 => 'Not Modified',
480 305 => 'Use Proxy',
481 307 => 'Temporary Redirect',
482 400 => 'Bad Request',
483 401 => 'Unauthorized',
484 402 => 'Payment Required',
485 403 => 'Forbidden',
486 404 => 'Not Found',
487 405 => 'Method Not Allowed',
488 406 => 'Not Acceptable',
489 407 => 'Proxy Authentication Required',
490 408 => 'Request Timeout',
491 409 => 'Conflict',
492 410 => 'Gone',
493 411 => 'Length Required',
494 412 => 'Precondition Failed',
495 413 => 'Request Entity Too Large',
496 414 => 'Request-URI Too Large',
497 415 => 'Unsupported Media Type',
498 416 => 'Request Range Not Satisfiable',
499 417 => 'Expectation Failed',
500 422 => 'Unprocessable Entity',
501 423 => 'Locked',
502 424 => 'Failed Dependency',
503 500 => 'Internal Server Error',
504 501 => 'Not Implemented',
505 502 => 'Bad Gateway',
506 503 => 'Service Unavailable',
507 504 => 'Gateway Timeout',
508 505 => 'HTTP Version Not Supported',
509 507 => 'Insufficient Storage'
510 );
511
512 if ( $statusMessage[$this->mStatusCode] )
513 header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] );
514 }
515
516 # Buffer output; final headers may depend on later processing
517 ob_start();
518
519 $this->transformBuffer();
520
521 # Disable temporary placeholders, so that the skin produces HTML
522 $sk->postParseLinkColour( false );
523
524 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
525 header( 'Content-language: '.$wgContLanguageCode );
526
527 $exp = time() + $wgCookieExpiration;
528 foreach( $this->mCookies as $name => $val ) {
529 setcookie( $name, $val, $exp, '/' );
530 }
531
532 if ($this->mArticleBodyOnly) {
533 $this->out($this->mBodytext);
534 } else {
535 wfProfileIn( 'Output-skin' );
536 $sk->outputPage( $this );
537 wfProfileOut( 'Output-skin' );
538 }
539
540 $this->sendCacheControl();
541 ob_end_flush();
542 wfProfileOut( $fname );
543 }
544
545 function out( $ins ) {
546 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
547 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
548 $outs = $ins;
549 } else {
550 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
551 if ( false === $outs ) { $outs = $ins; }
552 }
553 print $outs;
554 }
555
556 function setEncodings() {
557 global $wgInputEncoding, $wgOutputEncoding;
558 global $wgUser, $wgContLang;
559
560 $wgInputEncoding = strtolower( $wgInputEncoding );
561
562 if( $wgUser->getOption( 'altencoding' ) ) {
563 $wgContLang->setAltEncoding();
564 return;
565 }
566
567 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
568 $wgOutputEncoding = strtolower( $wgOutputEncoding );
569 return;
570 }
571 $wgOutputEncoding = $wgInputEncoding;
572 }
573
574 /**
575 * Returns a HTML comment with the elapsed time since request.
576 * This method has no side effects.
577 * Use wfReportTime() instead.
578 * @return string
579 * @deprecated
580 */
581 function reportTime() {
582 $time = wfReportTime();
583 return $time;
584 }
585
586 /**
587 * Note: these arguments are keys into wfMsg(), not text!
588 */
589 function errorpage( $title, $msg ) {
590 global $wgTitle;
591
592 $this->mDebugtext .= 'Original title: ' .
593 $wgTitle->getPrefixedText() . "\n";
594 $this->setPageTitle( wfMsg( $title ) );
595 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
596 $this->setRobotpolicy( 'noindex,nofollow' );
597 $this->setArticleRelated( false );
598 $this->enableClientCache( false );
599 $this->mRedirect = '';
600
601 $this->mBodytext = '';
602 $this->addWikiText( wfMsg( $msg ) );
603 $this->returnToMain( false );
604
605 $this->output();
606 wfErrorExit();
607 }
608
609 /**
610 * Display an error page indicating that a given version of MediaWiki is
611 * required to use it
612 *
613 * @param mixed $version The version of MediaWiki needed to use the page
614 */
615 function versionRequired( $version ) {
616 global $wgUser;
617
618 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
619 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
620 $this->setRobotpolicy( 'noindex,nofollow' );
621 $this->setArticleRelated( false );
622 $this->mBodytext = '';
623
624 $sk = $wgUser->getSkin();
625 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
626 $this->returnToMain();
627 }
628
629 /**
630 * Display an error page noting that a given permission bit is required.
631 * This should generally replace the sysopRequired, developerRequired etc.
632 * @param string $permission key required
633 */
634 function permissionRequired( $permission ) {
635 global $wgUser;
636
637 $this->setPageTitle( wfMsg( 'badaccess' ) );
638 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
639 $this->setRobotpolicy( 'noindex,nofollow' );
640 $this->setArticleRelated( false );
641 $this->mBodytext = '';
642
643 $sk = $wgUser->getSkin();
644 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
645 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
646 $this->returnToMain();
647 }
648
649 /**
650 * @deprecated
651 */
652 function sysopRequired() {
653 global $wgUser;
654
655 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
656 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
657 $this->setRobotpolicy( 'noindex,nofollow' );
658 $this->setArticleRelated( false );
659 $this->mBodytext = '';
660
661 $sk = $wgUser->getSkin();
662 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
663 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
664 $this->returnToMain();
665 }
666
667 /**
668 * @deprecated
669 */
670 function developerRequired() {
671 global $wgUser;
672
673 $this->setPageTitle( wfMsg( 'developertitle' ) );
674 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
675 $this->setRobotpolicy( 'noindex,nofollow' );
676 $this->setArticleRelated( false );
677 $this->mBodytext = '';
678
679 $sk = $wgUser->getSkin();
680 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
681 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
682 $this->returnToMain();
683 }
684
685 function loginToUse() {
686 global $wgUser, $wgTitle, $wgContLang;
687
688 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
689 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
690 $this->setRobotpolicy( 'noindex,nofollow' );
691 $this->setArticleFlag( false );
692 $this->mBodytext = '';
693 $loginpage = Title::makeTitle(NS_SPECIAL, 'Userlogin');
694 $sk = $wgUser->getSkin();
695 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
696 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
697 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
698
699 # We put a comment in the .html file so a Sysop can diagnose the page the
700 # user can't see.
701 $this->addHTML( "\n<!--" .
702 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
703 ':' .
704 $wgTitle->getDBkey() . '-->' );
705 $this->returnToMain(); # Flip back to the main page after 10 seconds.
706 }
707
708 function databaseError( $fname, $sql, $error, $errno ) {
709 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
710
711 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
712 $this->setRobotpolicy( 'noindex,nofollow' );
713 $this->setArticleRelated( false );
714 $this->enableClientCache( false );
715 $this->mRedirect = '';
716
717 if( !$wgShowSQLErrors ) {
718 $sql = wfMsg( 'sqlhidden' );
719 }
720
721 if ( $wgCommandLineMode ) {
722 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
723 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
724 } else {
725 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
726 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
727 }
728
729 if ( $wgCommandLineMode || !is_object( $wgUser )) {
730 print $msg."\n";
731 wfErrorExit();
732 }
733 $this->mBodytext = $msg;
734 $this->output();
735 wfErrorExit();
736 }
737
738 function readOnlyPage( $source = null, $protected = false ) {
739 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
740
741 $this->setRobotpolicy( 'noindex,nofollow' );
742 $this->setArticleRelated( false );
743
744 if( $protected ) {
745 $this->setPageTitle( wfMsg( 'viewsource' ) );
746 $this->addWikiText( wfMsg( 'protectedtext' ) );
747 } else {
748 $this->setPageTitle( wfMsg( 'readonly' ) );
749 if ( $wgReadOnly ) {
750 $reason = $wgReadOnly;
751 } else {
752 $reason = file_get_contents( $wgReadOnlyFile );
753 }
754 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
755 }
756
757 if( is_string( $source ) ) {
758 if( strcmp( $source, '' ) == 0 ) {
759 $source = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
760 }
761 $rows = $wgUser->getOption( 'rows' );
762 $cols = $wgUser->getOption( 'cols' );
763 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
764 htmlspecialchars( $source ) . "\n</textarea>";
765 $this->addHTML( $text );
766 }
767
768 $this->returnToMain( false );
769 }
770
771 function fatalError( $message ) {
772 $this->setPageTitle( wfMsg( "internalerror" ) );
773 $this->setRobotpolicy( "noindex,nofollow" );
774 $this->setArticleRelated( false );
775 $this->enableClientCache( false );
776 $this->mRedirect = '';
777
778 $this->mBodytext = $message;
779 $this->output();
780 wfErrorExit();
781 }
782
783 function unexpectedValueError( $name, $val ) {
784 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
785 }
786
787 function fileCopyError( $old, $new ) {
788 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
789 }
790
791 function fileRenameError( $old, $new ) {
792 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
793 }
794
795 function fileDeleteError( $name ) {
796 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
797 }
798
799 function fileNotFoundError( $name ) {
800 $this->fatalError( wfMsg( 'filenotfound', $name ) );
801 }
802
803 /**
804 * return from error messages or notes
805 * @param $auto automatically redirect the user after 10 seconds
806 * @param $returnto page title to return to. Default is Main Page.
807 */
808 function returnToMain( $auto = true, $returnto = NULL ) {
809 global $wgUser, $wgOut, $wgRequest;
810
811 if ( $returnto == NULL ) {
812 $returnto = $wgRequest->getText( 'returnto' );
813 }
814 $returnto = htmlspecialchars( $returnto );
815
816 $sk = $wgUser->getSkin();
817 if ( '' == $returnto ) {
818 $returnto = wfMsgForContent( 'mainpage' );
819 }
820 $link = $sk->makeKnownLink( $returnto, '' );
821
822 $r = wfMsg( 'returnto', $link );
823 if ( $auto ) {
824 $titleObj = Title::newFromText( $returnto );
825 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
826 }
827 $wgOut->addHTML( "\n<p>$r</p>\n" );
828 }
829
830 /**
831 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
832 * and uses the first 10 of them for META keywords
833 */
834 function addMetaTags () {
835 global $wgLinkCache , $wgOut ;
836 $categories = array_keys ( $wgLinkCache->mCategoryLinks ) ;
837 $good = array_keys ( $wgLinkCache->mGoodLinks ) ;
838 $bad = array_keys ( $wgLinkCache->mBadLinks ) ;
839 $a = array_merge ( array_slice ( $good , 0 , 1 ), $categories, array_slice ( $good , 1 , 9 ) , $bad ) ;
840 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
841 $a = implode ( ',' , $a ) ;
842 $strip = array(
843 "/<.*?>/" => '',
844 "/_/" => ' '
845 );
846 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
847
848 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
849 }
850
851 /**
852 * @private
853 * @return string
854 */
855 function headElement() {
856 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
857 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
858
859 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
860 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
861 } else {
862 $ret = '';
863 }
864
865 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
866
867 if ( '' == $this->getHTMLTitle() ) {
868 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
869 }
870
871 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
872 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
873 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
874 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
875
876 $ret .= $this->getHeadLinks();
877 global $wgStylePath;
878 if( $this->isPrintable() ) {
879 $media = '';
880 } else {
881 $media = "media='print'";
882 }
883 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
884 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
885
886 $sk = $wgUser->getSkin();
887 $ret .= $sk->getHeadScripts();
888 $ret .= $this->mScripts;
889 $ret .= $sk->getUserStyles();
890
891 if ($wgUseTrackbacks && $this->isArticleRelated())
892 $ret .= $wgTitle->trackbackRDF();
893
894 $ret .= "</head>\n";
895 return $ret;
896 }
897
898 function getHeadLinks() {
899 global $wgRequest, $wgStylePath;
900 $ret = '';
901 foreach ( $this->mMetatags as $tag ) {
902 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
903 $a = 'http-equiv';
904 $tag[0] = substr( $tag[0], 5 );
905 } else {
906 $a = 'name';
907 }
908 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
909 }
910 $p = $this->mRobotpolicy;
911 if ( '' == $p ) { $p = 'index,follow'; }
912 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
913
914 if ( count( $this->mKeywords ) > 0 ) {
915 $strip = array(
916 "/<.*?>/" => '',
917 "/_/" => ' '
918 );
919 $ret .= "<meta name=\"keywords\" content=\"" .
920 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
921 }
922 foreach ( $this->mLinktags as $tag ) {
923 $ret .= '<link';
924 foreach( $tag as $attr => $val ) {
925 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
926 }
927 $ret .= " />\n";
928 }
929 if( $this->isSyndicated() ) {
930 # FIXME: centralize the mime-type and name information in Feed.php
931 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
932 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
933 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
934 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
935 }
936
937 return $ret;
938 }
939
940 /**
941 * Run any necessary pre-output transformations on the buffer text
942 */
943 function transformBuffer( $options = 0 ) {
944 }
945
946
947 /**
948 * Turn off regular page output and return an error reponse
949 * for when rate limiting has triggered.
950 * @todo i18n
951 * @access public
952 */
953 function rateLimited() {
954 global $wgOut;
955 $wgOut->disable();
956 wfHttpError( 500, 'Internal Server Error',
957 'Sorry, the server has encountered an internal error. ' .
958 'Please wait a moment and hit "refresh" to submit the request again.' );
959 }
960
961 }
962
963 } // MediaWiki
964
965 ?>