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