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