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