7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
9 if( defined( 'MEDIAWIKI' ) ) {
13 if($wgUseTeX) require_once( 'Math.php' );
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, $mETag, $mCategoryLinks;
25 var $mScripts, $mLinkColours;
27 var $mSuppressQuickbar;
30 var $mContainsOldMagic, $mContainsNewMagic;
31 var $mIsArticleRelated;
33 var $mShowFeedLinks = false;
34 var $mEnableClientCache = true;
35 var $mArticleBodyOnly = false;
39 * Initialise private variables
41 function OutputPage() {
42 $this->mHeaders
= $this->mCookies
= $this->mMetatags
=
43 $this->mKeywords
= $this->mLinktags
= array();
44 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
45 $this->mRedirect
= $this->mLastModified
=
46 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
47 $this->mOnloadHandler
= '';
48 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
49 $this->mSuppressQuickbar
= $this->mPrintable
= false;
50 $this->mLanguageLinks
= array();
51 $this->mCategoryLinks
= array() ;
52 $this->mDoNothing
= false;
53 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
54 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
55 $this->mSquidMaxage
= 0;
60 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ) ; }
61 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
62 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
64 # To add an http-equiv meta tag, precede the name with "http:"
65 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
66 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
67 function addScript( $script ) { $this->mScripts
.= $script; }
68 function getScript() { return $this->mScripts
; }
70 function setETag($tag) { $this->mETag
= $tag; }
71 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
72 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
74 function addLink( $linkarr ) {
75 # $linkarr should be an associative array of attributes. We'll escape on output.
76 array_push( $this->mLinktags
, $linkarr );
79 function addMetadataLink( $linkarr ) {
80 # note: buggy CC software only reads first "meta" link
81 static $haveMeta = false;
82 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
83 $this->addLink( $linkarr );
88 * checkLastModified tells the client to use the client-cached page if
89 * possible. If sucessful, the OutputPage is disabled so that
90 * any future call to OutputPage->output() have no effect. The method
91 * returns true iff cache-ok headers was sent.
93 function checkLastModified ( $timestamp ) {
94 global $wgLang, $wgCachePages, $wgUser;
95 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
96 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
99 if( !$wgCachePages ) {
100 wfDebug( "CACHE DISABLED\n", false );
103 if( $wgUser->getOption( 'nocache' ) ) {
104 wfDebug( "USER DISABLED CACHE\n", false );
108 $timestamp=wfTimestamp(TS_MW
,$timestamp);
109 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
) );
111 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
112 # IE sends sizes after the date like this:
113 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
114 # this breaks strtotime().
115 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
116 $modsinceTime = strtotime( $modsince );
117 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
118 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
119 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
120 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
121 # Make sure you're in a place you can leave when you call us!
122 header( "HTTP/1.0 304 Not Modified" );
123 $this->mLastModified
= $lastmod;
124 $this->sendCacheControl();
125 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
127 @ob_end_clean
(); // Don't output compressed blob
130 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
131 $this->mLastModified
= $lastmod;
134 wfDebug( "client did not send If-Modified-Since header\n", false );
135 $this->mLastModified
= $lastmod;
139 function getPageTitleActionText () {
143 return wfMsg('edit');
145 return wfMsg('history_short');
147 return wfMsg('protect');
149 return wfMsg('unprotect');
151 return wfMsg('delete');
153 return wfMsg('watch');
155 return wfMsg('unwatch');
157 return wfMsg('preview');
159 return wfMsg('info_short');
165 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
166 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
167 function setPageTitle( $name ) {
168 global $action, $wgContLang;
169 $name = $wgContLang->convert($name, true);
170 $this->mPagetitle
= $name;
171 if(!empty($action)) {
172 $taction = $this->getPageTitleActionText();
173 if( !empty( $taction ) ) {
174 $name .= ' - '.$taction;
178 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
180 function getHTMLTitle() { return $this->mHTMLtitle
; }
181 function getPageTitle() { return $this->mPagetitle
; }
182 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
183 function getSubtitle() { return $this->mSubtitle
; }
184 function isArticle() { return $this->mIsarticle
; }
185 function setPrintable() { $this->mPrintable
= true; }
186 function isPrintable() { return $this->mPrintable
; }
187 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
188 function isSyndicated() { return $this->mShowFeedLinks
; }
189 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
190 function getOnloadHandler() { return $this->mOnloadHandler
; }
191 function disable() { $this->mDoNothing
= true; }
193 function setArticleRelated( $v ) {
194 $this->mIsArticleRelated
= $v;
196 $this->mIsarticle
= false;
199 function setArticleFlag( $v ) {
200 $this->mIsarticle
= $v;
202 $this->mIsArticleRelated
= $v;
206 function isArticleRelated() { return $this->mIsArticleRelated
; }
208 function getLanguageLinks() { return $this->mLanguageLinks
; }
209 function addLanguageLinks($newLinkArray) {
210 $this->mLanguageLinks +
= $newLinkArray;
212 function setLanguageLinks($newLinkArray) {
213 $this->mLanguageLinks
= $newLinkArray;
216 function getCategoryLinks() {
217 return $this->mCategoryLinks
;
219 function addCategoryLinks($newLinkArray) {
220 $this->mCategoryLinks +
= $newLinkArray;
222 function setCategoryLinks($newLinkArray) {
223 $this->mCategoryLinks +
= $newLinkArray;
226 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
227 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
229 function addHTML( $text ) { $this->mBodytext
.= $text; }
230 function clearHTML() { $this->mBodytext
= ''; }
231 function getHTML() { return $this->mBodytext
; }
232 function debug( $text ) { $this->mDebugtext
.= $text; }
234 function setParserOptions( $options ) {
235 return wfSetVar( $this->mParserOptions
, $options );
239 * Convert wikitext to HTML and add it to the buffer
240 * Default assumes that the current page title will
243 function addWikiText( $text, $linestart = true ) {
245 $this->addWikiTextTitle($text, $wgTitle, $linestart);
248 function addWikiTextWithTitle($text, &$title, $linestart = true) {
249 $this->addWikiTextTitle($text, $title, $linestart);
252 function addWikiTextTitle($text, &$title, $linestart) {
253 global $wgParser, $wgUseTidy;
254 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
, $linestart );
255 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
256 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
257 if ( $parserOutput->getCacheTime() == -1 ) {
258 $this->enableClientCache( false );
260 $this->addHTML( $parserOutput->getText() );
264 * Add wikitext to the buffer, assuming that this is the primary text for a page view
265 * Saves the text into the parser cache if possible
267 function addPrimaryWikiText( $text, $cacheArticle ) {
268 global $wgParser, $wgParserCache, $wgUser, $wgTitle, $wgUseTidy;
270 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, true );
272 $text = $parserOutput->getText();
274 if ( $cacheArticle && $parserOutput->getCacheTime() != -1 ) {
275 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
278 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
279 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
280 if ( $parserOutput->getCacheTime() == -1 ) {
281 $this->enableClientCache( false );
283 $this->addHTML( $text );
287 * Add the output of a QuickTemplate to the output buffer
288 * @param QuickTemplate $template
290 function addTemplate( &$template ) {
292 $template->execute();
293 $this->addHtml( ob_get_contents() );
298 * Parse wikitext and return the HTML. This is for special pages that add the text later
300 function parse( $text, $linestart = true ) {
301 global $wgParser, $wgTitle;
302 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
303 return $parserOutput->getText();
312 function tryParserCache( $article, $user ) {
313 global $wgParserCache;
314 $parserOutput = $wgParserCache->get( $article, $user );
315 if ( $parserOutput !== false ) {
316 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
317 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
318 $this->addHTML( $parserOutput->getText() );
319 $t = $parserOutput->getTitleText();
321 $this->setPageTitle( $t );
330 * Set the maximum cache time on the Squid in seconds
333 function setSquidMaxage( $maxage ) {
334 $this->mSquidMaxage
= $maxage;
338 * Use enableClientCache(false) to force it to send nocache headers
341 function enableClientCache( $state ) {
342 return wfSetVar( $this->mEnableClientCache
, $state );
345 function uncacheableBecauseRequestvars() {
347 return $wgRequest->getText('useskin', false) === false
348 && $wgRequest->getText('uselang', false) === false;
351 function sendCacheControl() {
352 global $wgUseSquid, $wgUseESI;
355 header("ETag: $this->mETag");
357 # don't serve compressed data to clients who can't handle it
358 # maintain different caches for logged-in users and non-logged in ones
359 header( 'Vary: Accept-Encoding, Cookie' );
360 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
361 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
362 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
365 # We'll purge the proxy cache explicitly, but require end user agents
366 # to revalidate against the proxy on each visit.
367 # Surrogate-Control controls our Squid, Cache-Control downstream caches
368 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
369 # start with a shorter timeout for initial testing
370 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
371 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
372 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
374 # We'll purge the proxy cache for anons explicitly, but require end user agents
375 # to revalidate against the proxy on each visit.
376 # IMPORTANT! The Squid needs to replace the Cache-Control header with
377 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
378 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
379 # start with a shorter timeout for initial testing
380 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
381 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
384 # We do want clients to cache if they can, but they *must* check for updates
385 # on revisiting the page.
386 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
387 header( "Expires: -1" );
388 header( "Cache-Control: private, must-revalidate, max-age=0" );
390 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
392 wfDebug( "** no caching **\n", false );
394 # In general, the absence of a last modified header should be enough to prevent
395 # the client from using its cache. We send a few other things just to make sure.
396 header( 'Expires: -1' );
397 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
398 header( 'Pragma: no-cache' );
403 * Finally, all the text has been munged and accumulated into
404 * the object, let's actually output it:
407 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
408 global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
409 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
411 if( $this->mDoNothing
){
414 $fname = 'OutputPage::output';
415 wfProfileIn( $fname );
416 $sk = $wgUser->getSkin();
418 if ( '' != $this->mRedirect
) {
419 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
420 # Standards require redirect URLs to be absolute
422 $this->mRedirect
= $wgServer . $this->mRedirect
;
424 if( $this->mRedirectCode
== '301') {
425 if( !$wgDebugRedirects ) {
426 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
428 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
431 $this->sendCacheControl();
433 if( $wgDebugRedirects ) {
434 $url = htmlspecialchars( $this->mRedirect
);
435 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
436 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
437 print "</body>\n</html>\n";
439 header( 'Location: '.$this->mRedirect
);
441 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
442 wfProfileOut( $fname );
447 # Buffer output; final headers may depend on later processing
450 $this->transformBuffer();
452 # Disable temporary placeholders, so that the skin produces HTML
453 $sk->postParseLinkColour( false );
455 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
456 header( 'Content-language: '.$wgContLanguageCode );
458 $exp = time() +
$wgCookieExpiration;
459 foreach( $this->mCookies
as $name => $val ) {
460 setcookie( $name, $val, $exp, '/' );
463 if ($this->mArticleBodyOnly
) {
464 $this->out($this->mBodytext
);
466 wfProfileIn( 'Output-skin' );
467 $sk->outputPage( $this );
468 wfProfileOut( 'Output-skin' );
471 $this->sendCacheControl();
473 wfProfileOut( $fname );
476 function out( $ins ) {
477 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
478 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
481 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
482 if ( false === $outs ) { $outs = $ins; }
487 function setEncodings() {
488 global $wgInputEncoding, $wgOutputEncoding;
489 global $wgUser, $wgContLang;
491 $wgInputEncoding = strtolower( $wgInputEncoding );
493 if( $wgUser->getOption( 'altencoding' ) ) {
494 $wgContLang->setAltEncoding();
498 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
499 $wgOutputEncoding = strtolower( $wgOutputEncoding );
502 $wgOutputEncoding = $wgInputEncoding;
506 * Returns a HTML comment with the elapsed time since request.
507 * This method has no side effects.
510 function reportTime() {
511 global $wgRequestTime;
514 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
515 $start = (float)$sec +
(float)$usec;
516 $elapsed = $now - $start;
518 # Use real server name if available, so we know which machine
519 # in a server farm generated the current page.
520 if ( function_exists( 'posix_uname' ) ) {
521 $uname = @posix_uname
();
525 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
526 $hostname = $uname['nodename'];
528 # This may be a virtual server.
529 $hostname = $_SERVER['SERVER_NAME'];
531 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
532 $hostname, $elapsed );
537 * Note: these arguments are keys into wfMsg(), not text!
539 function errorpage( $title, $msg ) {
542 $this->mDebugtext
.= 'Original title: ' .
543 $wgTitle->getPrefixedText() . "\n";
544 $this->setPageTitle( wfMsg( $title ) );
545 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
546 $this->setRobotpolicy( 'noindex,nofollow' );
547 $this->setArticleRelated( false );
548 $this->enableClientCache( false );
549 $this->mRedirect
= '';
551 $this->mBodytext
= '';
552 $this->addWikiText( wfMsg( $msg ) );
553 $this->returnToMain( false );
560 * Display an error page indicating that a given version of MediaWiki is
563 * @param mixed $version The version of MediaWiki needed to use the page
565 function versionRequired( $version ) {
568 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
569 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
570 $this->setRobotpolicy( 'noindex,nofollow' );
571 $this->setArticleRelated( false );
572 $this->mBodytext
= '';
574 $sk = $wgUser->getSkin();
575 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
576 $this->returnToMain();
580 * Display an error page noting that a given permission bit is required.
581 * This should generally replace the sysopRequired, developerRequired etc.
582 * @param string $permission key required
584 function permissionRequired( $permission ) {
587 $this->setPageTitle( wfMsg( 'badaccess' ) );
588 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
589 $this->setRobotpolicy( 'noindex,nofollow' );
590 $this->setArticleRelated( false );
591 $this->mBodytext
= '';
593 $sk = $wgUser->getSkin();
594 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
595 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
596 $this->returnToMain();
602 function sysopRequired() {
605 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
606 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
607 $this->setRobotpolicy( 'noindex,nofollow' );
608 $this->setArticleRelated( false );
609 $this->mBodytext
= '';
611 $sk = $wgUser->getSkin();
612 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
613 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
614 $this->returnToMain();
620 function developerRequired() {
623 $this->setPageTitle( wfMsg( 'developertitle' ) );
624 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
625 $this->setRobotpolicy( 'noindex,nofollow' );
626 $this->setArticleRelated( false );
627 $this->mBodytext
= '';
629 $sk = $wgUser->getSkin();
630 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
631 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
632 $this->returnToMain();
635 function loginToUse() {
636 global $wgUser, $wgTitle, $wgContLang;
638 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
639 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
640 $this->setRobotpolicy( 'noindex,nofollow' );
641 $this->setArticleFlag( false );
642 $this->mBodytext
= '';
643 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
644 $sk = $wgUser->getSkin();
645 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
646 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
647 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
649 # We put a comment in the .html file so a Sysop can diagnose the page the
651 $this->addHTML( "\n<!--" .
652 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
654 $wgTitle->getDBkey() . '-->' );
655 $this->returnToMain(); # Flip back to the main page after 10 seconds.
658 function databaseError( $fname, $sql, $error, $errno ) {
659 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
661 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
662 $this->setRobotpolicy( 'noindex,nofollow' );
663 $this->setArticleRelated( false );
664 $this->enableClientCache( false );
665 $this->mRedirect
= '';
667 if( !$wgShowSQLErrors ) {
668 $sql = wfMsg( 'sqlhidden' );
671 if ( $wgCommandLineMode ) {
672 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
673 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
675 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
676 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
679 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
683 $this->mBodytext
= $msg;
688 function readOnlyPage( $source = null, $protected = false ) {
689 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
691 $this->setRobotpolicy( 'noindex,nofollow' );
692 $this->setArticleRelated( false );
695 $this->setPageTitle( wfMsg( 'viewsource' ) );
696 $this->addWikiText( wfMsg( 'protectedtext' ) );
698 $this->setPageTitle( wfMsg( 'readonly' ) );
700 $reason = $wgReadOnly;
702 $reason = file_get_contents( $wgReadOnlyFile );
704 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
707 if( is_string( $source ) ) {
708 if( strcmp( $source, '' ) == 0 ) {
709 $source = wfMsg( 'noarticletext' );
711 $rows = $wgUser->getOption( 'rows' );
712 $cols = $wgUser->getOption( 'cols' );
713 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
714 htmlspecialchars( $source ) . "\n</textarea>";
715 $this->addHTML( $text );
718 $this->returnToMain( false );
721 function fatalError( $message ) {
722 $this->setPageTitle( wfMsg( "internalerror" ) );
723 $this->setRobotpolicy( "noindex,nofollow" );
724 $this->setArticleRelated( false );
725 $this->enableClientCache( false );
726 $this->mRedirect
= '';
728 $this->mBodytext
= $message;
733 function unexpectedValueError( $name, $val ) {
734 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
737 function fileCopyError( $old, $new ) {
738 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
741 function fileRenameError( $old, $new ) {
742 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
745 function fileDeleteError( $name ) {
746 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
749 function fileNotFoundError( $name ) {
750 $this->fatalError( wfMsg( 'filenotfound', $name ) );
754 * return from error messages or notes
755 * @param $auto automatically redirect the user after 10 seconds
756 * @param $returnto page title to return to. Default is Main Page.
758 function returnToMain( $auto = true, $returnto = NULL ) {
759 global $wgUser, $wgOut, $wgRequest;
761 if ( $returnto == NULL ) {
762 $returnto = $wgRequest->getText( 'returnto' );
764 $returnto = htmlspecialchars( $returnto );
766 $sk = $wgUser->getSkin();
767 if ( '' == $returnto ) {
768 $returnto = wfMsgForContent( 'mainpage' );
770 $link = $sk->makeKnownLink( $returnto, '' );
772 $r = wfMsg( 'returnto', $link );
774 $titleObj = Title
::newFromText( $returnto );
775 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
777 $wgOut->addHTML( "\n<p>$r</p>\n" );
781 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
782 * and uses the first 10 of them for META keywords
784 function addMetaTags () {
785 global $wgLinkCache , $wgOut ;
786 $categories = array_keys ( $wgLinkCache->mCategoryLinks
) ;
787 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
788 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
789 $a = array_merge ( array_slice ( $good , 0 , 1 ), $categories, array_slice ( $good , 1 , 9 ) , $bad ) ;
790 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
791 $a = implode ( ',' , $a ) ;
796 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
798 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
805 function headElement() {
806 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
807 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
809 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
810 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
815 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
817 if ( '' == $this->getHTMLTitle() ) {
818 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
821 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
822 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
823 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
824 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
826 $ret .= $this->getHeadLinks();
828 if( $this->isPrintable() ) {
831 $media = "media='print'";
833 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
834 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
836 $sk = $wgUser->getSkin();
837 $ret .= $sk->getHeadScripts();
838 $ret .= $this->mScripts
;
839 $ret .= $sk->getUserStyles();
841 if ($wgUseTrackbacks && $this->isArticleRelated())
842 $ret .= $wgTitle->trackbackRDF();
848 function getHeadLinks() {
849 global $wgRequest, $wgStylePath;
851 foreach ( $this->mMetatags
as $tag ) {
852 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
854 $tag[0] = substr( $tag[0], 5 );
858 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
860 $p = $this->mRobotpolicy
;
861 if ( '' == $p ) { $p = 'index,follow'; }
862 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
864 if ( count( $this->mKeywords
) > 0 ) {
869 $ret .= "<meta name=\"keywords\" content=\"" .
870 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
872 foreach ( $this->mLinktags
as $tag ) {
874 foreach( $tag as $attr => $val ) {
875 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
879 if( $this->isSyndicated() ) {
880 # FIXME: centralize the mime-type and name information in Feed.php
881 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
882 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
883 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
884 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
891 * Run any necessary pre-output transformations on the buffer text
893 function transformBuffer( $options = 0 ) {
898 * Turn off regular page output and return an error reponse
899 * for when rate limiting has triggered.
903 function rateLimited() {
906 wfHttpError( 500, 'Internal Server Error',
907 'Sorry, the server has encountered an internal error. ' .
908 'Please wait a moment and hit "refresh" to submit the request again.' );