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