useless call
[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 $this->transformBuffer();
519
520 # Disable temporary placeholders, so that the skin produces HTML
521 $sk->postParseLinkColour( false );
522
523 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
524 header( 'Content-language: '.$wgContLanguageCode );
525
526 $exp = time() + $wgCookieExpiration;
527 foreach( $this->mCookies as $name => $val ) {
528 setcookie( $name, $val, $exp, '/' );
529 }
530
531 if ($this->mArticleBodyOnly) {
532 $this->out($this->mBodytext);
533 } else {
534 wfProfileIn( 'Output-skin' );
535 $sk->outputPage( $this );
536 wfProfileOut( 'Output-skin' );
537 }
538
539 $this->sendCacheControl();
540 ob_end_flush();
541 wfProfileOut( $fname );
542 }
543
544 function out( $ins ) {
545 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
546 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
547 $outs = $ins;
548 } else {
549 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
550 if ( false === $outs ) { $outs = $ins; }
551 }
552 print $outs;
553 }
554
555 function setEncodings() {
556 global $wgInputEncoding, $wgOutputEncoding;
557 global $wgUser, $wgContLang;
558
559 $wgInputEncoding = strtolower( $wgInputEncoding );
560
561 if( $wgUser->getOption( 'altencoding' ) ) {
562 $wgContLang->setAltEncoding();
563 return;
564 }
565
566 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
567 $wgOutputEncoding = strtolower( $wgOutputEncoding );
568 return;
569 }
570 $wgOutputEncoding = $wgInputEncoding;
571 }
572
573 /**
574 * Returns a HTML comment with the elapsed time since request.
575 * This method has no side effects.
576 * Use wfReportTime() instead.
577 * @return string
578 * @deprecated
579 */
580 function reportTime() {
581 $time = wfReportTime();
582 return $time;
583 }
584
585 /**
586 * Note: these arguments are keys into wfMsg(), not text!
587 */
588 function errorpage( $title, $msg ) {
589 global $wgTitle;
590
591 $this->mDebugtext .= 'Original title: ' .
592 $wgTitle->getPrefixedText() . "\n";
593 $this->setPageTitle( wfMsg( $title ) );
594 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
595 $this->setRobotpolicy( 'noindex,nofollow' );
596 $this->setArticleRelated( false );
597 $this->enableClientCache( false );
598 $this->mRedirect = '';
599
600 $this->mBodytext = '';
601 $this->addWikiText( wfMsg( $msg ) );
602 $this->returnToMain( false );
603
604 $this->output();
605 wfErrorExit();
606 }
607
608 /**
609 * Display an error page indicating that a given version of MediaWiki is
610 * required to use it
611 *
612 * @param mixed $version The version of MediaWiki needed to use the page
613 */
614 function versionRequired( $version ) {
615 global $wgUser;
616
617 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
618 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
619 $this->setRobotpolicy( 'noindex,nofollow' );
620 $this->setArticleRelated( false );
621 $this->mBodytext = '';
622
623 $sk = $wgUser->getSkin();
624 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
625 $this->returnToMain();
626 }
627
628 /**
629 * Display an error page noting that a given permission bit is required.
630 * This should generally replace the sysopRequired, developerRequired etc.
631 * @param string $permission key required
632 */
633 function permissionRequired( $permission ) {
634 global $wgUser;
635
636 $this->setPageTitle( wfMsg( 'badaccess' ) );
637 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
638 $this->setRobotpolicy( 'noindex,nofollow' );
639 $this->setArticleRelated( false );
640 $this->mBodytext = '';
641
642 $sk = $wgUser->getSkin();
643 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
644 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
645 $this->returnToMain();
646 }
647
648 /**
649 * @deprecated
650 */
651 function sysopRequired() {
652 global $wgUser;
653
654 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
655 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
656 $this->setRobotpolicy( 'noindex,nofollow' );
657 $this->setArticleRelated( false );
658 $this->mBodytext = '';
659
660 $sk = $wgUser->getSkin();
661 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
662 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
663 $this->returnToMain();
664 }
665
666 /**
667 * @deprecated
668 */
669 function developerRequired() {
670 global $wgUser;
671
672 $this->setPageTitle( wfMsg( 'developertitle' ) );
673 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
674 $this->setRobotpolicy( 'noindex,nofollow' );
675 $this->setArticleRelated( false );
676 $this->mBodytext = '';
677
678 $sk = $wgUser->getSkin();
679 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
680 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
681 $this->returnToMain();
682 }
683
684 function loginToUse() {
685 global $wgUser, $wgTitle, $wgContLang;
686
687 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
688 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
689 $this->setRobotpolicy( 'noindex,nofollow' );
690 $this->setArticleFlag( false );
691 $this->mBodytext = '';
692 $loginpage = Title::makeTitle(NS_SPECIAL, 'Userlogin');
693 $sk = $wgUser->getSkin();
694 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
695 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
696 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
697
698 # We put a comment in the .html file so a Sysop can diagnose the page the
699 # user can't see.
700 $this->addHTML( "\n<!--" .
701 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
702 ':' .
703 $wgTitle->getDBkey() . '-->' );
704 $this->returnToMain(); # Flip back to the main page after 10 seconds.
705 }
706
707 function databaseError( $fname, $sql, $error, $errno ) {
708 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
709
710 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
711 $this->setRobotpolicy( 'noindex,nofollow' );
712 $this->setArticleRelated( false );
713 $this->enableClientCache( false );
714 $this->mRedirect = '';
715
716 if( !$wgShowSQLErrors ) {
717 $sql = wfMsg( 'sqlhidden' );
718 }
719
720 if ( $wgCommandLineMode ) {
721 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
722 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
723 } else {
724 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
725 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
726 }
727
728 if ( $wgCommandLineMode || !is_object( $wgUser )) {
729 print $msg."\n";
730 wfErrorExit();
731 }
732 $this->mBodytext = $msg;
733 $this->output();
734 wfErrorExit();
735 }
736
737 function readOnlyPage( $source = null, $protected = false ) {
738 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
739
740 $this->setRobotpolicy( 'noindex,nofollow' );
741 $this->setArticleRelated( false );
742
743 if( $protected ) {
744 $this->setPageTitle( wfMsg( 'viewsource' ) );
745 $this->addWikiText( wfMsg( 'protectedtext' ) );
746 } else {
747 $this->setPageTitle( wfMsg( 'readonly' ) );
748 if ( $wgReadOnly ) {
749 $reason = $wgReadOnly;
750 } else {
751 $reason = file_get_contents( $wgReadOnlyFile );
752 }
753 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
754 }
755
756 if( is_string( $source ) ) {
757 if( strcmp( $source, '' ) == 0 ) {
758 $source = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
759 }
760 $rows = $wgUser->getOption( 'rows' );
761 $cols = $wgUser->getOption( 'cols' );
762 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
763 htmlspecialchars( $source ) . "\n</textarea>";
764 $this->addHTML( $text );
765 }
766
767 $this->returnToMain( false );
768 }
769
770 function fatalError( $message ) {
771 $this->setPageTitle( wfMsg( "internalerror" ) );
772 $this->setRobotpolicy( "noindex,nofollow" );
773 $this->setArticleRelated( false );
774 $this->enableClientCache( false );
775 $this->mRedirect = '';
776
777 $this->mBodytext = $message;
778 $this->output();
779 wfErrorExit();
780 }
781
782 function unexpectedValueError( $name, $val ) {
783 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
784 }
785
786 function fileCopyError( $old, $new ) {
787 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
788 }
789
790 function fileRenameError( $old, $new ) {
791 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
792 }
793
794 function fileDeleteError( $name ) {
795 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
796 }
797
798 function fileNotFoundError( $name ) {
799 $this->fatalError( wfMsg( 'filenotfound', $name ) );
800 }
801
802 /**
803 * return from error messages or notes
804 * @param $auto automatically redirect the user after 10 seconds
805 * @param $returnto page title to return to. Default is Main Page.
806 */
807 function returnToMain( $auto = true, $returnto = NULL ) {
808 global $wgUser, $wgOut, $wgRequest;
809
810 if ( $returnto == NULL ) {
811 $returnto = $wgRequest->getText( 'returnto' );
812 }
813 $returnto = htmlspecialchars( $returnto );
814
815 $sk = $wgUser->getSkin();
816 if ( '' == $returnto ) {
817 $returnto = wfMsgForContent( 'mainpage' );
818 }
819 $link = $sk->makeKnownLink( $returnto, '' );
820
821 $r = wfMsg( 'returnto', $link );
822 if ( $auto ) {
823 $titleObj = Title::newFromText( $returnto );
824 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
825 }
826 $wgOut->addHTML( "\n<p>$r</p>\n" );
827 }
828
829 /**
830 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
831 * and uses the first 10 of them for META keywords
832 */
833 function addMetaTags () {
834 global $wgLinkCache , $wgOut ;
835 $categories = array_keys ( $wgLinkCache->mCategoryLinks ) ;
836 $good = array_keys ( $wgLinkCache->mGoodLinks ) ;
837 $bad = array_keys ( $wgLinkCache->mBadLinks ) ;
838 $a = array_merge ( array_slice ( $good , 0 , 1 ), $categories, array_slice ( $good , 1 , 9 ) , $bad ) ;
839 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
840 $a = implode ( ',' , $a ) ;
841 $strip = array(
842 "/<.*?>/" => '',
843 "/_/" => ' '
844 );
845 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
846
847 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
848 }
849
850 /**
851 * @private
852 * @return string
853 */
854 function headElement() {
855 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
856 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
857
858 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
859 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
860 } else {
861 $ret = '';
862 }
863
864 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
865
866 if ( '' == $this->getHTMLTitle() ) {
867 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
868 }
869
870 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
871 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
872 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
873 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
874
875 $ret .= $this->getHeadLinks();
876 global $wgStylePath;
877 if( $this->isPrintable() ) {
878 $media = '';
879 } else {
880 $media = "media='print'";
881 }
882 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
883 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
884
885 $sk = $wgUser->getSkin();
886 $ret .= $sk->getHeadScripts();
887 $ret .= $this->mScripts;
888 $ret .= $sk->getUserStyles();
889
890 if ($wgUseTrackbacks && $this->isArticleRelated())
891 $ret .= $wgTitle->trackbackRDF();
892
893 $ret .= "</head>\n";
894 return $ret;
895 }
896
897 function getHeadLinks() {
898 global $wgRequest, $wgStylePath;
899 $ret = '';
900 foreach ( $this->mMetatags as $tag ) {
901 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
902 $a = 'http-equiv';
903 $tag[0] = substr( $tag[0], 5 );
904 } else {
905 $a = 'name';
906 }
907 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
908 }
909 $p = $this->mRobotpolicy;
910 if ( '' == $p ) { $p = 'index,follow'; }
911 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
912
913 if ( count( $this->mKeywords ) > 0 ) {
914 $strip = array(
915 "/<.*?>/" => '',
916 "/_/" => ' '
917 );
918 $ret .= "<meta name=\"keywords\" content=\"" .
919 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
920 }
921 foreach ( $this->mLinktags as $tag ) {
922 $ret .= '<link';
923 foreach( $tag as $attr => $val ) {
924 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
925 }
926 $ret .= " />\n";
927 }
928 if( $this->isSyndicated() ) {
929 # FIXME: centralize the mime-type and name information in Feed.php
930 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
931 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
932 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
933 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
934 }
935
936 return $ret;
937 }
938
939 /**
940 * Run any necessary pre-output transformations on the buffer text
941 */
942 function transformBuffer( $options = 0 ) {
943 }
944
945
946 /**
947 * Turn off regular page output and return an error reponse
948 * for when rate limiting has triggered.
949 * @todo i18n
950 * @access public
951 */
952 function rateLimited() {
953 global $wgOut;
954 $wgOut->disable();
955 wfHttpError( 500, 'Internal Server Error',
956 'Sorry, the server has encountered an internal error. ' .
957 'Please wait a moment and hit "refresh" to submit the request again.' );
958 }
959
960 }
961
962 } // MediaWiki
963
964 ?>