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;
38 * Initialise private variables
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;
59 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ) ; }
60 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
61 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
63 # To add an http-equiv meta tag, precede the name with "http:"
64 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
65 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
66 function addScript( $script ) { $this->mScripts
.= $script; }
67 function getScript() { return $this->mScripts
; }
69 function setETag($tag) { $this->mETag
= $tag; }
71 function addLink( $linkarr ) {
72 # $linkarr should be an associative array of attributes. We'll escape on output.
73 array_push( $this->mLinktags
, $linkarr );
76 function addMetadataLink( $linkarr ) {
77 # note: buggy CC software only reads first "meta" link
78 static $haveMeta = false;
79 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
80 $this->addLink( $linkarr );
85 * checkLastModified tells the client to use the client-cached page if
86 * possible. If sucessful, the OutputPage is disabled so that
87 * any future call to OutputPage->output() have no effect. The method
88 * returns true iff cache-ok headers was sent.
90 function checkLastModified ( $timestamp ) {
91 global $wgLang, $wgCachePages, $wgUser;
92 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
93 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
96 if( !$wgCachePages ) {
97 wfDebug( "CACHE DISABLED\n", false );
100 if( $wgUser->getOption( 'nocache' ) ) {
101 wfDebug( "USER DISABLED CACHE\n", false );
105 $timestamp=wfTimestamp(TS_MW
,$timestamp);
106 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
) );
108 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
109 # IE sends sizes after the date like this:
110 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
111 # this breaks strtotime().
112 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
113 $ismodsince = wfTimestamp( TS_MW
, strtotime( $modsince ) );
114 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
115 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
116 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
117 # Make sure you're in a place you can leave when you call us!
118 header( "HTTP/1.0 304 Not Modified" );
119 $this->mLastModified
= $lastmod;
120 $this->sendCacheControl();
121 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
125 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
126 $this->mLastModified
= $lastmod;
129 wfDebug( "client did not send If-Modified-Since header\n", false );
130 $this->mLastModified
= $lastmod;
134 function getPageTitleActionText () {
138 return wfMsg('edit');
140 return wfMsg('history_short');
142 return wfMsg('protect');
144 return wfMsg('unprotect');
146 return wfMsg('delete');
148 return wfMsg('watch');
150 return wfMsg('unwatch');
152 return wfMsg('preview');
154 return wfMsg('info_short');
160 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
161 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
162 function setPageTitle( $name ) {
163 global $action, $wgContLang;
164 $name = $wgContLang->convert($name, true);
165 $this->mPagetitle
= $name;
166 if(!empty($action)) {
167 $taction = $this->getPageTitleActionText();
168 if( !empty( $taction ) ) {
169 $name .= ' - '.$taction;
172 $this->setHTMLTitle( $name . ' - ' . wfMsg( 'wikititlesuffix' ) );
174 function getHTMLTitle() { return $this->mHTMLtitle
; }
175 function getPageTitle() { return $this->mPagetitle
; }
176 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
177 function getSubtitle() { return $this->mSubtitle
; }
178 function isArticle() { return $this->mIsarticle
; }
179 function setPrintable() { $this->mPrintable
= true; }
180 function isPrintable() { return $this->mPrintable
; }
181 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
182 function isSyndicated() { return $this->mShowFeedLinks
; }
183 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
184 function getOnloadHandler() { return $this->mOnloadHandler
; }
185 function disable() { $this->mDoNothing
= true; }
187 function setArticleRelated( $v ) {
188 $this->mIsArticleRelated
= $v;
190 $this->mIsarticle
= false;
193 function setArticleFlag( $v ) {
194 $this->mIsarticle
= $v;
196 $this->mIsArticleRelated
= $v;
200 function isArticleRelated() { return $this->mIsArticleRelated
; }
202 function getLanguageLinks() { return $this->mLanguageLinks
; }
203 function addLanguageLinks($newLinkArray) {
204 $this->mLanguageLinks +
= $newLinkArray;
206 function setLanguageLinks($newLinkArray) {
207 $this->mLanguageLinks
= $newLinkArray;
210 function getCategoryLinks() {
211 return $this->mCategoryLinks
;
213 function addCategoryLinks($newLinkArray) {
214 $this->mCategoryLinks +
= $newLinkArray;
216 function setCategoryLinks($newLinkArray) {
217 $this->mCategoryLinks +
= $newLinkArray;
220 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
221 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
223 function addHTML( $text ) { $this->mBodytext
.= $text; }
224 function clearHTML() { $this->mBodytext
= ''; }
225 function getHTML() { return $this->mBodytext
; }
226 function debug( $text ) { $this->mDebugtext
.= $text; }
228 function setParserOptions( $options ) {
229 return wfSetVar( $this->mParserOptions
, $options );
233 * Convert wikitext to HTML and add it to the buffer
234 * Default assumes that the current page title will
237 function addWikiText( $text, $linestart = true ) {
239 $this->addWikiTextTitle($text, $wgTitle, $linestart);
242 function addWikiTextWithTitle($text, &$title, $linestart = true) {
243 $this->addWikiTextTitle($text, $title, $linestart);
246 function addWikiTextTitle($text, &$title, $linestart) {
247 global $wgParser, $wgUseTidy;
248 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
, $linestart );
249 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
250 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
251 if ( $parserOutput->getCacheTime() == -1 ) {
252 $this->enableClientCache( false );
254 $this->addHTML( $parserOutput->getText() );
258 * Add wikitext to the buffer, assuming that this is the primary text for a page view
259 * Saves the text into the parser cache if possible
261 function addPrimaryWikiText( $text, $cacheArticle ) {
262 global $wgParser, $wgParserCache, $wgUser, $wgTitle, $wgUseTidy;
264 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, true );
266 $text = $parserOutput->getText();
268 if ( $cacheArticle && $parserOutput->getCacheTime() != -1 ) {
269 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
272 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
273 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
274 if ( $parserOutput->getCacheTime() == -1 ) {
275 $this->enableClientCache( false );
277 $this->addHTML( $text );
281 * Add the output of a QuickTemplate to the output buffer
282 * @param QuickTemplate $template
284 function addTemplate( &$template ) {
286 $template->execute();
287 $this->addHtml( ob_get_contents() );
292 * Parse wikitext and return the HTML. This is for special pages that add the text later
294 function parse( $text, $linestart = true ) {
295 global $wgParser, $wgTitle;
296 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
297 return $parserOutput->getText();
306 function tryParserCache( $article, $user ) {
307 global $wgParserCache;
308 $parserOutput = $wgParserCache->get( $article, $user );
309 if ( $parserOutput !== false ) {
310 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
311 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
312 $this->addHTML( $parserOutput->getText() );
313 $t = $parserOutput->getTitleText();
315 $this->setPageTitle( $t );
324 * Set the maximum cache time on the Squid in seconds
327 function setSquidMaxage( $maxage ) {
328 $this->mSquidMaxage
= $maxage;
332 * Use enableClientCache(false) to force it to send nocache headers
335 function enableClientCache( $state ) {
336 return wfSetVar( $this->mEnableClientCache
, $state );
339 function sendCacheControl() {
340 global $wgUseSquid, $wgUseESI;
343 header("ETag: $this->mETag");
345 # don't serve compressed data to clients who can't handle it
346 # maintain different caches for logged-in users and non-logged in ones
347 header( 'Vary: Accept-Encoding, Cookie' );
348 if( $this->mEnableClientCache
) {
349 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
350 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
353 # We'll purge the proxy cache explicitly, but require end user agents
354 # to revalidate against the proxy on each visit.
355 # Surrogate-Control controls our Squid, Cache-Control downstream caches
356 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
357 # start with a shorter timeout for initial testing
358 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
359 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
360 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
362 # We'll purge the proxy cache for anons explicitly, but require end user agents
363 # to revalidate against the proxy on each visit.
364 # IMPORTANT! The Squid needs to replace the Cache-Control header with
365 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
366 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
367 # start with a shorter timeout for initial testing
368 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
369 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
372 # We do want clients to cache if they can, but they *must* check for updates
373 # on revisiting the page.
374 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
375 header( "Expires: -1" );
376 header( "Cache-Control: private, must-revalidate, max-age=0" );
378 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
380 wfDebug( "** no caching **\n", false );
382 # In general, the absence of a last modified header should be enough to prevent
383 # the client from using its cache. We send a few other things just to make sure.
384 header( 'Expires: -1' );
385 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
386 header( 'Pragma: no-cache' );
391 * Finally, all the text has been munged and accumulated into
392 * the object, let's actually output it:
395 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
396 global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
397 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
399 if( $this->mDoNothing
){
402 $fname = 'OutputPage::output';
403 wfProfileIn( $fname );
404 $sk = $wgUser->getSkin();
406 if ( '' != $this->mRedirect
) {
407 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
408 # Standards require redirect URLs to be absolute
410 $this->mRedirect
= $wgServer . $this->mRedirect
;
412 if( $this->mRedirectCode
== '301') {
413 if( !$wgDebugRedirects ) {
414 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
416 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
419 $this->sendCacheControl();
421 if( $wgDebugRedirects ) {
422 $url = htmlspecialchars( $this->mRedirect
);
423 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
424 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
425 print "</body>\n</html>\n";
427 header( 'Location: '.$this->mRedirect
);
429 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
434 # Buffer output; final headers may depend on later processing
437 $this->transformBuffer();
439 # Disable temporary placeholders, so that the skin produces HTML
440 $sk->postParseLinkColour( false );
442 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
443 header( 'Content-language: '.$wgContLanguageCode );
445 $exp = time() +
$wgCookieExpiration;
446 foreach( $this->mCookies
as $name => $val ) {
447 setcookie( $name, $val, $exp, '/' );
450 wfProfileIn( 'Output-skin' );
451 $sk->outputPage( $this );
452 wfProfileOut( 'Output-skin' );
454 $this->sendCacheControl();
458 function out( $ins ) {
459 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
460 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
463 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
464 if ( false === $outs ) { $outs = $ins; }
469 function setEncodings() {
470 global $wgInputEncoding, $wgOutputEncoding;
471 global $wgUser, $wgContLang;
473 $wgInputEncoding = strtolower( $wgInputEncoding );
475 if( $wgUser->getOption( 'altencoding' ) ) {
476 $wgContLang->setAltEncoding();
480 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
481 $wgOutputEncoding = strtolower( $wgOutputEncoding );
484 $wgOutputEncoding = $wgInputEncoding;
488 * Returns a HTML comment with the elapsed time since request.
489 * This method has no side effects.
492 function reportTime() {
493 global $wgRequestTime;
496 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
497 $start = (float)$sec +
(float)$usec;
498 $elapsed = $now - $start;
500 # Use real server name if available, so we know which machine
501 # in a server farm generated the current page.
502 if ( function_exists( 'posix_uname' ) ) {
503 $uname = @posix_uname
();
507 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
508 $hostname = $uname['nodename'];
510 # This may be a virtual server.
511 $hostname = $_SERVER['SERVER_NAME'];
513 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
514 $hostname, $elapsed );
519 * Note: these arguments are keys into wfMsg(), not text!
521 function errorpage( $title, $msg ) {
524 $this->mDebugtext
.= 'Original title: ' .
525 $wgTitle->getPrefixedText() . "\n";
526 $this->setPageTitle( wfMsg( $title ) );
527 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
528 $this->setRobotpolicy( 'noindex,nofollow' );
529 $this->setArticleRelated( false );
530 $this->enableClientCache( false );
531 $this->mRedirect
= '';
533 $this->mBodytext
= '';
534 $this->addWikiText( wfMsg( $msg ) );
535 $this->returnToMain( false );
542 * Display an error page indicating that a given version of MediaWiki is
545 * @param mixed $version The version of MediaWiki needed to use the page
547 function versionRequired( $version ) {
550 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
551 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
552 $this->setRobotpolicy( 'noindex,nofollow' );
553 $this->setArticleRelated( false );
554 $this->mBodytext
= '';
556 $sk = $wgUser->getSkin();
557 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
558 $this->returnToMain();
562 * Display an error page noting that a given permission bit is required.
563 * This should generally replace the sysopRequired, developerRequired etc.
564 * @param string $permission key required
566 function permissionRequired( $permission ) {
569 $this->setPageTitle( wfMsg( 'badaccess' ) );
570 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
571 $this->setRobotpolicy( 'noindex,nofollow' );
572 $this->setArticleRelated( false );
573 $this->mBodytext
= '';
575 $sk = $wgUser->getSkin();
576 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
577 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
578 $this->returnToMain();
584 function sysopRequired() {
587 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
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( 'sysoptext', $ap ) );
596 $this->returnToMain();
602 function developerRequired() {
605 $this->setPageTitle( wfMsg( 'developertitle' ) );
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( 'developertext', $ap ) );
614 $this->returnToMain();
617 function loginToUse() {
618 global $wgUser, $wgTitle, $wgContLang;
620 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
621 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
622 $this->setRobotpolicy( 'noindex,nofollow' );
623 $this->setArticleFlag( false );
624 $this->mBodytext
= '';
625 $this->addWikiText( wfMsg( 'loginreqtext' ) );
627 # We put a comment in the .html file so a Sysop can diagnose the page the
629 $this->addHTML( "\n<!--" .
630 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
632 $wgTitle->getDBkey() . '-->' );
633 $this->returnToMain(); # Flip back to the main page after 10 seconds.
636 function databaseError( $fname, $sql, $error, $errno ) {
637 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
639 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
640 $this->setRobotpolicy( 'noindex,nofollow' );
641 $this->setArticleRelated( false );
642 $this->enableClientCache( false );
643 $this->mRedirect
= '';
645 if( !$wgShowSQLErrors ) {
646 $sql = wfMsg( 'sqlhidden' );
649 if ( $wgCommandLineMode ) {
650 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
651 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
653 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
654 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
657 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
661 $this->mBodytext
= $msg;
666 function readOnlyPage( $source = null, $protected = false ) {
667 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
669 $this->setRobotpolicy( 'noindex,nofollow' );
670 $this->setArticleRelated( false );
673 $this->setPageTitle( wfMsg( 'viewsource' ) );
674 $this->addWikiText( wfMsg( 'protectedtext' ) );
676 $this->setPageTitle( wfMsg( 'readonly' ) );
678 $reason = $wgReadOnly;
680 $reason = file_get_contents( $wgReadOnlyFile );
682 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
685 if( is_string( $source ) ) {
686 if( strcmp( $source, '' ) == 0 ) {
687 $source = wfMsg( 'noarticletext' );
689 $rows = $wgUser->getOption( 'rows' );
690 $cols = $wgUser->getOption( 'cols' );
691 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
692 htmlspecialchars( $source ) . "\n</textarea>";
693 $this->addHTML( $text );
696 $this->returnToMain( false );
699 function fatalError( $message ) {
700 $this->setPageTitle( wfMsg( "internalerror" ) );
701 $this->setRobotpolicy( "noindex,nofollow" );
702 $this->setArticleRelated( false );
703 $this->enableClientCache( false );
704 $this->mRedirect
= '';
706 $this->mBodytext
= $message;
711 function unexpectedValueError( $name, $val ) {
712 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
715 function fileCopyError( $old, $new ) {
716 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
719 function fileRenameError( $old, $new ) {
720 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
723 function fileDeleteError( $name ) {
724 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
727 function fileNotFoundError( $name ) {
728 $this->fatalError( wfMsg( 'filenotfound', $name ) );
732 * return from error messages or notes
733 * @param $auto automatically redirect the user after 10 seconds
734 * @param $returnto page title to return to. Default is Main Page.
736 function returnToMain( $auto = true, $returnto = NULL ) {
737 global $wgUser, $wgOut, $wgRequest;
739 if ( $returnto == NULL ) {
740 $returnto = $wgRequest->getText( 'returnto' );
742 $returnto = htmlspecialchars( $returnto );
744 $sk = $wgUser->getSkin();
745 if ( '' == $returnto ) {
746 $returnto = wfMsgForContent( 'mainpage' );
748 $link = $sk->makeKnownLink( $returnto, '' );
750 $r = wfMsg( 'returnto', $link );
752 $titleObj = Title
::newFromText( $returnto );
753 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
755 $wgOut->addHTML( "\n<p>$r</p>\n" );
759 * This function takes the existing and broken links for the page
760 * and uses the first 10 of them for META keywords
762 function addMetaTags () {
763 global $wgLinkCache , $wgOut ;
764 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
765 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
766 $a = array_merge ( $good , $bad ) ;
767 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
768 $a = implode ( ',' , $a ) ;
773 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
775 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
782 function headElement() {
783 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
784 global $wgUser, $wgContLang, $wgRequest;
786 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
787 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
792 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
794 if ( "" == $this->mHTMLtitle
) {
795 $this->mHTMLtitle
= wfMsg( "pagetitle", $this->mPagetitle
);
798 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
799 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
800 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle
) . "</title>\n";
801 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
803 $ret .= $this->getHeadLinks();
805 if( $this->isPrintable() ) {
808 $media = "media='print'";
810 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
811 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
813 $sk = $wgUser->getSkin();
814 $ret .= $sk->getHeadScripts();
815 $ret .= $this->mScripts
;
816 $ret .= $sk->getUserStyles();
822 function getHeadLinks() {
823 global $wgRequest, $wgStylePath;
825 foreach ( $this->mMetatags
as $tag ) {
826 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
828 $tag[0] = substr( $tag[0], 5 );
832 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
834 $p = $this->mRobotpolicy
;
835 if ( '' == $p ) { $p = 'index,follow'; }
836 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
838 if ( count( $this->mKeywords
) > 0 ) {
843 $ret .= "<meta name=\"keywords\" content=\"" .
844 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
846 foreach ( $this->mLinktags
as $tag ) {
848 foreach( $tag as $attr => $val ) {
849 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
853 if( $this->isSyndicated() ) {
854 # FIXME: centralize the mime-type and name information in Feed.php
855 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
856 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
857 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
858 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
865 * Run any necessary pre-output transformations on the buffer text
867 function transformBuffer( $options = 0 ) {
872 * Turn off regular page output and return an error reponse
873 * for when rate limiting has triggered.
877 function rateLimited() {
880 wfHttpError( 500, 'Internal Server Error',
881 'Sorry, the server has encountered an internal error. ' .
882 'Please wait a moment and hit "refresh" to submit the request again.' );