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