* (bug 1949) Profiling typo in rare error case
[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 */
231 function addWikiText( $text, $linestart = true ) {
232 global $wgParser, $wgTitle, $wgUseTidy;
233
234 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
235 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
236 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
237 $this->addHTML( $parserOutput->getText() );
238 }
239
240 /**
241 * Add wikitext to the buffer, assuming that this is the primary text for a page view
242 * Saves the text into the parser cache if possible
243 */
244 function addPrimaryWikiText( $text, $cacheArticle ) {
245 global $wgParser, $wgParserCache, $wgUser, $wgTitle, $wgUseTidy;
246
247 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, true );
248
249 $text = $parserOutput->getText();
250
251 if ( $cacheArticle ) {
252 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
253 }
254
255 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
256 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
257 $this->addHTML( $text );
258 }
259
260 /**
261 * Add the output of a QuickTemplate to the output buffer
262 * @param QuickTemplate $template
263 */
264 function addTemplate( &$template ) {
265 ob_start();
266 $template->execute();
267 $this->addHtml( ob_get_contents() );
268 ob_end_clean();
269 }
270
271 /**
272 * Parse wikitext and return the HTML. This is for special pages that add the text later
273 */
274 function parse( $text, $linestart = true ) {
275 global $wgParser, $wgTitle;
276 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
277 return $parserOutput->getText();
278 }
279
280 /**
281 * @param $article
282 * @param $user
283 *
284 * @return bool
285 */
286 function tryParserCache( $article, $user ) {
287 global $wgParserCache;
288 $parserOutput = $wgParserCache->get( $article, $user );
289 if ( $parserOutput !== false ) {
290 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
291 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
292 $this->addHTML( $parserOutput->getText() );
293 $t = $parserOutput->getTitleText();
294 if( !empty( $t ) ) {
295 $this->setPageTitle( $t );
296 }
297 return true;
298 } else {
299 return false;
300 }
301 }
302
303 /**
304 * Set the maximum cache time on the Squid in seconds
305 * @param $maxage
306 */
307 function setSquidMaxage( $maxage ) {
308 $this->mSquidMaxage = $maxage;
309 }
310
311 /**
312 * Use enableClientCache(false) to force it to send nocache headers
313 * @param $state
314 */
315 function enableClientCache( $state ) {
316 return wfSetVar( $this->mEnableClientCache, $state );
317 }
318
319 function sendCacheControl() {
320 global $wgUseSquid, $wgUseESI;
321 # don't serve compressed data to clients who can't handle it
322 # maintain different caches for logged-in users and non-logged in ones
323 header( 'Vary: Accept-Encoding, Cookie' );
324 if( $this->mEnableClientCache ) {
325 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
326 ! $this->isPrintable() && $this->mSquidMaxage != 0 )
327 {
328 if ( $wgUseESI ) {
329 # We'll purge the proxy cache explicitly, but require end user agents
330 # to revalidate against the proxy on each visit.
331 # Surrogate-Control controls our Squid, Cache-Control downstream caches
332 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
333 # start with a shorter timeout for initial testing
334 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
335 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
336 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
337 } else {
338 # We'll purge the proxy cache for anons explicitly, but require end user agents
339 # to revalidate against the proxy on each visit.
340 # IMPORTANT! The Squid needs to replace the Cache-Control header with
341 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
342 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
343 # start with a shorter timeout for initial testing
344 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
345 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
346 }
347 } else {
348 # We do want clients to cache if they can, but they *must* check for updates
349 # on revisiting the page.
350 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
351 header( "Expires: -1" );
352 header( "Cache-Control: private, must-revalidate, max-age=0" );
353 }
354 if($this->mLastModified) header( "Last-modified: {$this->mLastModified}" );
355 } else {
356 wfDebug( "** no caching **\n", false );
357
358 # In general, the absence of a last modified header should be enough to prevent
359 # the client from using its cache. We send a few other things just to make sure.
360 header( 'Expires: -1' );
361 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
362 header( 'Pragma: no-cache' );
363 }
364 }
365
366 /**
367 * Finally, all the text has been munged and accumulated into
368 * the object, let's actually output it:
369 */
370 function output() {
371 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
372 global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
373 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
374
375 if( $this->mDoNothing ){
376 return;
377 }
378 $fname = 'OutputPage::output';
379 wfProfileIn( $fname );
380 $sk = $wgUser->getSkin();
381
382 if ( '' != $this->mRedirect ) {
383 if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
384 # Standards require redirect URLs to be absolute
385 global $wgServer;
386 $this->mRedirect = $wgServer . $this->mRedirect;
387 }
388 if( $this->mRedirectCode == '301') {
389 if( !$wgDebugRedirects ) {
390 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
391 }
392 $this->mLastModified = wfTimestamp( TS_RFC2822 );
393 }
394
395 $this->sendCacheControl();
396
397 if( $wgDebugRedirects ) {
398 $url = htmlspecialchars( $this->mRedirect );
399 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
400 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
401 print "</body>\n</html>\n";
402 } else {
403 header( 'Location: '.$this->mRedirect );
404 }
405 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
406 return;
407 }
408
409
410 # Buffer output; final headers may depend on later processing
411 ob_start();
412
413 $this->transformBuffer();
414
415 # Disable temporary placeholders, so that the skin produces HTML
416 $sk->postParseLinkColour( false );
417
418 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
419 header( 'Content-language: '.$wgContLanguageCode );
420
421 $exp = time() + $wgCookieExpiration;
422 foreach( $this->mCookies as $name => $val ) {
423 setcookie( $name, $val, $exp, '/' );
424 }
425
426 wfProfileIn( 'Output-skin' );
427 $sk->outputPage( $this );
428 wfProfileOut( 'Output-skin' );
429
430 $this->sendCacheControl();
431 ob_end_flush();
432 }
433
434 function out( $ins ) {
435 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
436 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
437 $outs = $ins;
438 } else {
439 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
440 if ( false === $outs ) { $outs = $ins; }
441 }
442 print $outs;
443 }
444
445 function setEncodings() {
446 global $wgInputEncoding, $wgOutputEncoding;
447 global $wgUser, $wgContLang;
448
449 $wgInputEncoding = strtolower( $wgInputEncoding );
450
451 if( $wgUser->getOption( 'altencoding' ) ) {
452 $wgContLang->setAltEncoding();
453 return;
454 }
455
456 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
457 $wgOutputEncoding = strtolower( $wgOutputEncoding );
458 return;
459 }
460
461 /*
462 # This code is unused anyway!
463 # Commenting out. --bv 2003-11-15
464
465 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
466 $best = 0.0;
467 $bestset = "*";
468
469 foreach ( $a as $s ) {
470 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
471 $set = $m[1];
472 $q = (float)($m[2]);
473 } else {
474 $set = $s;
475 $q = 1.0;
476 }
477 if ( $q > $best ) {
478 $bestset = $set;
479 $best = $q;
480 }
481 }
482 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
483 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
484 $wgOutputEncoding = strtolower( $bestset );
485
486 # Disable for now
487 #
488 */
489 $wgOutputEncoding = $wgInputEncoding;
490 }
491
492 /**
493 * Returns a HTML comment with the elapsed time since request.
494 * This method has no side effects.
495 * @return string
496 */
497 function reportTime() {
498 global $wgRequestTime;
499
500 $now = wfTime();
501 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
502 $start = (float)$sec + (float)$usec;
503 $elapsed = $now - $start;
504
505 # Use real server name if available, so we know which machine
506 # in a server farm generated the current page.
507 if ( function_exists( 'posix_uname' ) ) {
508 $uname = @posix_uname();
509 } else {
510 $uname = false;
511 }
512 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
513 $hostname = $uname['nodename'];
514 } else {
515 # This may be a virtual server.
516 $hostname = $_SERVER['SERVER_NAME'];
517 }
518 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
519 $hostname, $elapsed );
520 return $com;
521 }
522
523 /**
524 * Note: these arguments are keys into wfMsg(), not text!
525 */
526 function errorpage( $title, $msg ) {
527 global $wgTitle;
528
529 $this->mDebugtext .= 'Original title: ' .
530 $wgTitle->getPrefixedText() . "\n";
531 $this->setPageTitle( wfMsg( $title ) );
532 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
533 $this->setRobotpolicy( 'noindex,nofollow' );
534 $this->setArticleRelated( false );
535 $this->enableClientCache( false );
536 $this->mRedirect = '';
537
538 $this->mBodytext = '';
539 $this->addWikiText( wfMsg( $msg ) );
540 $this->returnToMain( false );
541
542 $this->output();
543 wfErrorExit();
544 }
545
546 function sysopRequired() {
547 global $wgUser;
548
549 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
550 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
551 $this->setRobotpolicy( 'noindex,nofollow' );
552 $this->setArticleRelated( false );
553 $this->mBodytext = '';
554
555 $sk = $wgUser->getSkin();
556 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
557 $this->addHTML( wfMsg( 'sysoptext', $ap ) );
558 $this->returnToMain();
559 }
560
561 function developerRequired() {
562 global $wgUser;
563
564 $this->setPageTitle( wfMsg( 'developertitle' ) );
565 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
566 $this->setRobotpolicy( 'noindex,nofollow' );
567 $this->setArticleRelated( false );
568 $this->mBodytext = '';
569
570 $sk = $wgUser->getSkin();
571 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
572 $this->addHTML( wfMsg( 'developertext', $ap ) );
573 $this->returnToMain();
574 }
575
576 function loginToUse() {
577 global $wgUser, $wgTitle, $wgContLang;
578
579 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
580 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
581 $this->setRobotpolicy( 'noindex,nofollow' );
582 $this->setArticleFlag( false );
583 $this->mBodytext = '';
584 $this->addWikiText( wfMsg( 'loginreqtext' ) );
585
586 # We put a comment in the .html file so a Sysop can diagnose the page the
587 # user can't see.
588 $this->addHTML( "\n<!--" .
589 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
590 ':' .
591 $wgTitle->getDBkey() . '-->' );
592 $this->returnToMain(); # Flip back to the main page after 10 seconds.
593 }
594
595 function databaseError( $fname, $sql, $error, $errno ) {
596 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
597
598 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
599 $this->setRobotpolicy( 'noindex,nofollow' );
600 $this->setArticleRelated( false );
601 $this->enableClientCache( false );
602 $this->mRedirect = '';
603
604 if( !$wgShowSQLErrors ) {
605 $sql = wfMsg( 'sqlhidden' );
606 }
607
608 if ( $wgCommandLineMode ) {
609 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
610 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
611 } else {
612 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
613 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
614 }
615
616 if ( $wgCommandLineMode || !is_object( $wgUser )) {
617 print $msg."\n";
618 wfErrorExit();
619 }
620 $this->mBodytext = $msg;
621 $this->output();
622 wfErrorExit();
623 }
624
625 function readOnlyPage( $source = null, $protected = false ) {
626 global $wgUser, $wgReadOnlyFile;
627
628 $this->setRobotpolicy( 'noindex,nofollow' );
629 $this->setArticleRelated( false );
630
631 if( $protected ) {
632 $this->setPageTitle( wfMsg( 'viewsource' ) );
633 $this->addWikiText( wfMsg( 'protectedtext' ) );
634 } else {
635 $this->setPageTitle( wfMsg( 'readonly' ) );
636 $reason = file_get_contents( $wgReadOnlyFile );
637 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
638 }
639
640 if( is_string( $source ) ) {
641 if( strcmp( $source, '' ) == 0 ) {
642 $source = wfMsg( 'noarticletext' );
643 }
644 $rows = $wgUser->getOption( 'rows' );
645 $cols = $wgUser->getOption( 'cols' );
646 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
647 htmlspecialchars( $source ) . "\n</textarea>";
648 $this->addHTML( $text );
649 }
650
651 $this->returnToMain( false );
652 }
653
654 function fatalError( $message ) {
655 $this->setPageTitle( wfMsg( "internalerror" ) );
656 $this->setRobotpolicy( "noindex,nofollow" );
657 $this->setArticleRelated( false );
658 $this->enableClientCache( false );
659 $this->mRedirect = '';
660
661 $this->mBodytext = $message;
662 $this->output();
663 wfErrorExit();
664 }
665
666 function unexpectedValueError( $name, $val ) {
667 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
668 }
669
670 function fileCopyError( $old, $new ) {
671 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
672 }
673
674 function fileRenameError( $old, $new ) {
675 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
676 }
677
678 function fileDeleteError( $name ) {
679 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
680 }
681
682 function fileNotFoundError( $name ) {
683 $this->fatalError( wfMsg( 'filenotfound', $name ) );
684 }
685
686 /**
687 * return from error messages or notes
688 * @param $auto automatically redirect the user after 10 seconds
689 * @param $returnto page title to return to. Default is Main Page.
690 */
691 function returnToMain( $auto = true, $returnto = NULL ) {
692 global $wgUser, $wgOut, $wgRequest;
693
694 if ( $returnto == NULL ) {
695 $returnto = $wgRequest->getText( 'returnto' );
696 }
697 $returnto = htmlspecialchars( $returnto );
698
699 $sk = $wgUser->getSkin();
700 if ( '' == $returnto ) {
701 $returnto = wfMsgForContent( 'mainpage' );
702 }
703 $link = $sk->makeKnownLink( $returnto, '' );
704
705 $r = wfMsg( 'returnto', $link );
706 if ( $auto ) {
707 $titleObj = Title::newFromText( $returnto );
708 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
709 }
710 $wgOut->addHTML( "\n<p>$r</p>\n" );
711 }
712
713 /**
714 * This function takes the existing and broken links for the page
715 * and uses the first 10 of them for META keywords
716 */
717 function addMetaTags () {
718 global $wgLinkCache , $wgOut ;
719 $good = array_keys ( $wgLinkCache->mGoodLinks ) ;
720 $bad = array_keys ( $wgLinkCache->mBadLinks ) ;
721 $a = array_merge ( $good , $bad ) ;
722 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
723 $a = implode ( ',' , $a ) ;
724 $strip = array(
725 "/<.*?" . ">/" => '',
726 "/[_]/" => ' '
727 );
728 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
729
730 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
731 }
732
733 /**
734 * @private
735 * @return string
736 */
737 function headElement() {
738 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
739 global $wgUser, $wgContLang, $wgRequest;
740
741 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
742 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
743 } else {
744 $ret = '';
745 }
746
747 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
748
749 if ( "" == $this->mHTMLtitle ) {
750 $this->mHTMLtitle = wfMsg( "pagetitle", $this->mPagetitle );
751 }
752
753 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
754 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
755 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle ) . "</title>\n";
756 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
757
758 $ret .= $this->getHeadLinks();
759 global $wgStylePath;
760 if( $this->isPrintable() ) {
761 $media = '';
762 } else {
763 $media = "media='print'";
764 }
765 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
766 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
767
768 $sk = $wgUser->getSkin();
769 $ret .= $sk->getHeadScripts();
770 $ret .= $this->mScripts;
771 $ret .= $sk->getUserStyles();
772
773 $ret .= "</head>\n";
774 return $ret;
775 }
776
777 function getHeadLinks() {
778 global $wgRequest, $wgStylePath;
779 $ret = '';
780 foreach ( $this->mMetatags as $tag ) {
781 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
782 $a = 'http-equiv';
783 $tag[0] = substr( $tag[0], 5 );
784 } else {
785 $a = 'name';
786 }
787 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
788 }
789 $p = $this->mRobotpolicy;
790 if ( '' == $p ) { $p = 'index,follow'; }
791 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
792
793 if ( count( $this->mKeywords ) > 0 ) {
794 $strip = array(
795 "/<.*?" . ">/" => '',
796 "/[_]/" => ' '
797 );
798 $ret .= "<meta name=\"keywords\" content=\"" .
799 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
800 }
801 foreach ( $this->mLinktags as $tag ) {
802 $ret .= '<link';
803 foreach( $tag as $attr => $val ) {
804 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
805 }
806 $ret .= " />\n";
807 }
808 if( $this->isSyndicated() ) {
809 # FIXME: centralize the mime-type and name information in Feed.php
810 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
811 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
812 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
813 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
814 }
815
816 return $ret;
817 }
818
819 /**
820 * Run any necessary pre-output transformations on the buffer text
821 */
822 function transformBuffer( $options = 0 ) {
823 }
824
825 }
826
827 } // MediaWiki
828
829 ?>