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