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, $mStatusCode;
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; }
63 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
65 # To add an http-equiv meta tag, precede the name with "http:"
66 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
67 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
68 function addScript( $script ) { $this->mScripts
.= $script; }
69 function getScript() { return $this->mScripts
; }
71 function setETag($tag) { $this->mETag
= $tag; }
72 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
73 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
75 function addLink( $linkarr ) {
76 # $linkarr should be an associative array of attributes. We'll escape on output.
77 array_push( $this->mLinktags
, $linkarr );
80 function addMetadataLink( $linkarr ) {
81 # note: buggy CC software only reads first "meta" link
82 static $haveMeta = false;
83 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
84 $this->addLink( $linkarr );
89 * checkLastModified tells the client to use the client-cached page if
90 * possible. If sucessful, the OutputPage is disabled so that
91 * any future call to OutputPage->output() have no effect. The method
92 * returns true iff cache-ok headers was sent.
94 function checkLastModified ( $timestamp ) {
95 global $wgLang, $wgCachePages, $wgUser;
96 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
97 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
100 if( !$wgCachePages ) {
101 wfDebug( "CACHE DISABLED\n", false );
104 if( $wgUser->getOption( 'nocache' ) ) {
105 wfDebug( "USER DISABLED CACHE\n", false );
109 $timestamp=wfTimestamp(TS_MW
,$timestamp);
110 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
) );
112 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
113 # IE sends sizes after the date like this:
114 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
115 # this breaks strtotime().
116 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
117 $modsinceTime = strtotime( $modsince );
118 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
119 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
120 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
121 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
122 # Make sure you're in a place you can leave when you call us!
123 header( "HTTP/1.0 304 Not Modified" );
124 $this->mLastModified
= $lastmod;
125 $this->sendCacheControl();
126 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
128 @ob_end_clean
(); // Don't output compressed blob
131 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
132 $this->mLastModified
= $lastmod;
135 wfDebug( "client did not send If-Modified-Since header\n", false );
136 $this->mLastModified
= $lastmod;
140 function getPageTitleActionText () {
144 return wfMsg('edit');
146 return wfMsg('history_short');
148 return wfMsg('protect');
150 return wfMsg('unprotect');
152 return wfMsg('delete');
154 return wfMsg('watch');
156 return wfMsg('unwatch');
158 return wfMsg('preview');
160 return wfMsg('info_short');
166 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
167 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
168 function setPageTitle( $name ) {
169 global $action, $wgContLang;
170 $name = $wgContLang->convert($name, true);
171 $this->mPagetitle
= $name;
172 if(!empty($action)) {
173 $taction = $this->getPageTitleActionText();
174 if( !empty( $taction ) ) {
175 $name .= ' - '.$taction;
179 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
181 function getHTMLTitle() { return $this->mHTMLtitle
; }
182 function getPageTitle() { return $this->mPagetitle
; }
183 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
184 function getSubtitle() { return $this->mSubtitle
; }
185 function isArticle() { return $this->mIsarticle
; }
186 function setPrintable() { $this->mPrintable
= true; }
187 function isPrintable() { return $this->mPrintable
; }
188 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
189 function isSyndicated() { return $this->mShowFeedLinks
; }
190 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
191 function getOnloadHandler() { return $this->mOnloadHandler
; }
192 function disable() { $this->mDoNothing
= true; }
194 function setArticleRelated( $v ) {
195 $this->mIsArticleRelated
= $v;
197 $this->mIsarticle
= false;
200 function setArticleFlag( $v ) {
201 $this->mIsarticle
= $v;
203 $this->mIsArticleRelated
= $v;
207 function isArticleRelated() { return $this->mIsArticleRelated
; }
209 function getLanguageLinks() { return $this->mLanguageLinks
; }
210 function addLanguageLinks($newLinkArray) {
211 $this->mLanguageLinks +
= $newLinkArray;
213 function setLanguageLinks($newLinkArray) {
214 $this->mLanguageLinks
= $newLinkArray;
217 function getCategoryLinks() {
218 return $this->mCategoryLinks
;
220 function addCategoryLinks($newLinkArray) {
221 $this->mCategoryLinks +
= $newLinkArray;
223 function setCategoryLinks($newLinkArray) {
224 $this->mCategoryLinks +
= $newLinkArray;
227 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
228 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
230 function addHTML( $text ) { $this->mBodytext
.= $text; }
231 function clearHTML() { $this->mBodytext
= ''; }
232 function getHTML() { return $this->mBodytext
; }
233 function debug( $text ) { $this->mDebugtext
.= $text; }
235 function setParserOptions( $options ) {
236 return wfSetVar( $this->mParserOptions
, $options );
240 * Convert wikitext to HTML and add it to the buffer
241 * Default assumes that the current page title will
244 function addWikiText( $text, $linestart = true ) {
246 $this->addWikiTextTitle($text, $wgTitle, $linestart);
249 function addWikiTextWithTitle($text, &$title, $linestart = true) {
250 $this->addWikiTextTitle($text, $title, $linestart);
253 function addWikiTextTitle($text, &$title, $linestart) {
254 global $wgParser, $wgUseTidy;
255 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
, $linestart );
256 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
257 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
258 if ( $parserOutput->getCacheTime() == -1 ) {
259 $this->enableClientCache( false );
261 $this->addHTML( $parserOutput->getText() );
265 * Add wikitext to the buffer, assuming that this is the primary text for a page view
266 * Saves the text into the parser cache if possible
268 function addPrimaryWikiText( $text, $cacheArticle ) {
269 global $wgParser, $wgParserCache, $wgUser, $wgTitle, $wgUseTidy;
271 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, true );
273 $text = $parserOutput->getText();
275 if ( $cacheArticle && $parserOutput->getCacheTime() != -1 ) {
276 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
279 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
280 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
281 if ( $parserOutput->getCacheTime() == -1 ) {
282 $this->enableClientCache( false );
284 $this->addHTML( $text );
288 * Add the output of a QuickTemplate to the output buffer
289 * @param QuickTemplate $template
291 function addTemplate( &$template ) {
293 $template->execute();
294 $this->addHtml( ob_get_contents() );
299 * Parse wikitext and return the HTML. This is for special pages that add the text later
301 function parse( $text, $linestart = true ) {
302 global $wgParser, $wgTitle;
303 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
, $linestart );
304 return $parserOutput->getText();
313 function tryParserCache( $article, $user ) {
314 global $wgParserCache;
315 $parserOutput = $wgParserCache->get( $article, $user );
316 if ( $parserOutput !== false ) {
317 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
318 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
319 $this->addHTML( $parserOutput->getText() );
320 $t = $parserOutput->getTitleText();
322 $this->setPageTitle( $t );
331 * Set the maximum cache time on the Squid in seconds
334 function setSquidMaxage( $maxage ) {
335 $this->mSquidMaxage
= $maxage;
339 * Use enableClientCache(false) to force it to send nocache headers
342 function enableClientCache( $state ) {
343 return wfSetVar( $this->mEnableClientCache
, $state );
346 function uncacheableBecauseRequestvars() {
348 return $wgRequest->getText('useskin', false) === false
349 && $wgRequest->getText('uselang', false) === false;
352 function sendCacheControl() {
353 global $wgUseSquid, $wgUseESI;
356 header("ETag: $this->mETag");
358 # don't serve compressed data to clients who can't handle it
359 # maintain different caches for logged-in users and non-logged in ones
360 header( 'Vary: Accept-Encoding, Cookie' );
361 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
362 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
363 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
366 # We'll purge the proxy cache explicitly, but require end user agents
367 # to revalidate against the proxy on each visit.
368 # Surrogate-Control controls our Squid, Cache-Control downstream caches
369 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
370 # start with a shorter timeout for initial testing
371 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
372 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
373 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
375 # We'll purge the proxy cache for anons explicitly, but require end user agents
376 # to revalidate against the proxy on each visit.
377 # IMPORTANT! The Squid needs to replace the Cache-Control header with
378 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
379 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
380 # start with a shorter timeout for initial testing
381 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
382 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
385 # We do want clients to cache if they can, but they *must* check for updates
386 # on revisiting the page.
387 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
388 header( "Expires: -1" );
389 header( "Cache-Control: private, must-revalidate, max-age=0" );
391 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
393 wfDebug( "** no caching **\n", false );
395 # In general, the absence of a last modified header should be enough to prevent
396 # the client from using its cache. We send a few other things just to make sure.
397 header( 'Expires: -1' );
398 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
399 header( 'Pragma: no-cache' );
404 * Finally, all the text has been munged and accumulated into
405 * the object, let's actually output it:
408 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
409 global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
410 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
412 if( $this->mDoNothing
){
415 $fname = 'OutputPage::output';
416 wfProfileIn( $fname );
417 $sk = $wgUser->getSkin();
419 if ( '' != $this->mRedirect
) {
420 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
421 # Standards require redirect URLs to be absolute
423 $this->mRedirect
= $wgServer . $this->mRedirect
;
425 if( $this->mRedirectCode
== '301') {
426 if( !$wgDebugRedirects ) {
427 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
429 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
432 $this->sendCacheControl();
434 if( $wgDebugRedirects ) {
435 $url = htmlspecialchars( $this->mRedirect
);
436 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
437 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
438 print "</body>\n</html>\n";
440 header( 'Location: '.$this->mRedirect
);
442 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
443 wfProfileOut( $fname );
446 elseif ( $this->mStatusCode
)
448 $statusMessage = array(
450 101 => 'Switching Protocols',
455 203 => 'Non-Authoritative Information',
457 205 => 'Reset Content',
458 206 => 'Partial Content',
459 207 => 'Multi-Status',
460 300 => 'Multiple Choices',
461 301 => 'Moved Permanently',
464 304 => 'Not Modified',
466 307 => 'Temporary Redirect',
467 400 => 'Bad Request',
468 401 => 'Unauthorized',
469 402 => 'Payment Required',
472 405 => 'Method Not Allowed',
473 406 => 'Not Acceptable',
474 407 => 'Proxy Authentication Required',
475 408 => 'Request Timeout',
478 411 => 'Length Required',
479 412 => 'Precondition Failed',
480 413 => 'Request Entity Too Large',
481 414 => 'Request-URI Too Large',
482 415 => 'Unsupported Media Type',
483 416 => 'Request Range Not Satisfiable',
484 417 => 'Expectation Failed',
485 422 => 'Unprocessable Entity',
487 424 => 'Failed Dependency',
488 500 => 'Internal Server Error',
489 501 => 'Not Implemented',
490 502 => 'Bad Gateway',
491 503 => 'Service Unavailable',
492 504 => 'Gateway Timeout',
493 505 => 'HTTP Version Not Supported',
494 507 => 'Insufficient Storage'
497 if ( $statusMessage[$this->mStatusCode
] )
498 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
501 # Buffer output; final headers may depend on later processing
504 $this->transformBuffer();
506 # Disable temporary placeholders, so that the skin produces HTML
507 $sk->postParseLinkColour( false );
509 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
510 header( 'Content-language: '.$wgContLanguageCode );
512 $exp = time() +
$wgCookieExpiration;
513 foreach( $this->mCookies
as $name => $val ) {
514 setcookie( $name, $val, $exp, '/' );
517 if ($this->mArticleBodyOnly
) {
518 $this->out($this->mBodytext
);
520 wfProfileIn( 'Output-skin' );
521 $sk->outputPage( $this );
522 wfProfileOut( 'Output-skin' );
525 $this->sendCacheControl();
527 wfProfileOut( $fname );
530 function out( $ins ) {
531 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
532 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
535 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
536 if ( false === $outs ) { $outs = $ins; }
541 function setEncodings() {
542 global $wgInputEncoding, $wgOutputEncoding;
543 global $wgUser, $wgContLang;
545 $wgInputEncoding = strtolower( $wgInputEncoding );
547 if( $wgUser->getOption( 'altencoding' ) ) {
548 $wgContLang->setAltEncoding();
552 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
553 $wgOutputEncoding = strtolower( $wgOutputEncoding );
556 $wgOutputEncoding = $wgInputEncoding;
560 * Returns a HTML comment with the elapsed time since request.
561 * This method has no side effects.
562 * Use wfReportTime() instead.
566 function reportTime() {
567 $time = wfReportTime();
572 * Note: these arguments are keys into wfMsg(), not text!
574 function errorpage( $title, $msg ) {
577 $this->mDebugtext
.= 'Original title: ' .
578 $wgTitle->getPrefixedText() . "\n";
579 $this->setPageTitle( wfMsg( $title ) );
580 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
581 $this->setRobotpolicy( 'noindex,nofollow' );
582 $this->setArticleRelated( false );
583 $this->enableClientCache( false );
584 $this->mRedirect
= '';
586 $this->mBodytext
= '';
587 $this->addWikiText( wfMsg( $msg ) );
588 $this->returnToMain( false );
595 * Display an error page indicating that a given version of MediaWiki is
598 * @param mixed $version The version of MediaWiki needed to use the page
600 function versionRequired( $version ) {
603 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
604 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
605 $this->setRobotpolicy( 'noindex,nofollow' );
606 $this->setArticleRelated( false );
607 $this->mBodytext
= '';
609 $sk = $wgUser->getSkin();
610 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
611 $this->returnToMain();
615 * Display an error page noting that a given permission bit is required.
616 * This should generally replace the sysopRequired, developerRequired etc.
617 * @param string $permission key required
619 function permissionRequired( $permission ) {
622 $this->setPageTitle( wfMsg( 'badaccess' ) );
623 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
624 $this->setRobotpolicy( 'noindex,nofollow' );
625 $this->setArticleRelated( false );
626 $this->mBodytext
= '';
628 $sk = $wgUser->getSkin();
629 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
630 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
631 $this->returnToMain();
637 function sysopRequired() {
640 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
641 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
642 $this->setRobotpolicy( 'noindex,nofollow' );
643 $this->setArticleRelated( false );
644 $this->mBodytext
= '';
646 $sk = $wgUser->getSkin();
647 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
648 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
649 $this->returnToMain();
655 function developerRequired() {
658 $this->setPageTitle( wfMsg( 'developertitle' ) );
659 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
660 $this->setRobotpolicy( 'noindex,nofollow' );
661 $this->setArticleRelated( false );
662 $this->mBodytext
= '';
664 $sk = $wgUser->getSkin();
665 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
666 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
667 $this->returnToMain();
670 function loginToUse() {
671 global $wgUser, $wgTitle, $wgContLang;
673 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
674 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
675 $this->setRobotpolicy( 'noindex,nofollow' );
676 $this->setArticleFlag( false );
677 $this->mBodytext
= '';
678 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
679 $sk = $wgUser->getSkin();
680 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
681 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
682 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
684 # We put a comment in the .html file so a Sysop can diagnose the page the
686 $this->addHTML( "\n<!--" .
687 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
689 $wgTitle->getDBkey() . '-->' );
690 $this->returnToMain(); # Flip back to the main page after 10 seconds.
693 function databaseError( $fname, $sql, $error, $errno ) {
694 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
696 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
697 $this->setRobotpolicy( 'noindex,nofollow' );
698 $this->setArticleRelated( false );
699 $this->enableClientCache( false );
700 $this->mRedirect
= '';
702 if( !$wgShowSQLErrors ) {
703 $sql = wfMsg( 'sqlhidden' );
706 if ( $wgCommandLineMode ) {
707 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
708 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
710 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
711 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
714 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
718 $this->mBodytext
= $msg;
723 function readOnlyPage( $source = null, $protected = false ) {
724 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
726 $this->setRobotpolicy( 'noindex,nofollow' );
727 $this->setArticleRelated( false );
730 $this->setPageTitle( wfMsg( 'viewsource' ) );
731 $this->addWikiText( wfMsg( 'protectedtext' ) );
733 $this->setPageTitle( wfMsg( 'readonly' ) );
735 $reason = $wgReadOnly;
737 $reason = file_get_contents( $wgReadOnlyFile );
739 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
742 if( is_string( $source ) ) {
743 if( strcmp( $source, '' ) == 0 ) {
744 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
746 $rows = $wgUser->getOption( 'rows' );
747 $cols = $wgUser->getOption( 'cols' );
748 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
749 htmlspecialchars( $source ) . "\n</textarea>";
750 $this->addHTML( $text );
753 $this->returnToMain( false );
756 function fatalError( $message ) {
757 $this->setPageTitle( wfMsg( "internalerror" ) );
758 $this->setRobotpolicy( "noindex,nofollow" );
759 $this->setArticleRelated( false );
760 $this->enableClientCache( false );
761 $this->mRedirect
= '';
763 $this->mBodytext
= $message;
768 function unexpectedValueError( $name, $val ) {
769 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
772 function fileCopyError( $old, $new ) {
773 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
776 function fileRenameError( $old, $new ) {
777 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
780 function fileDeleteError( $name ) {
781 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
784 function fileNotFoundError( $name ) {
785 $this->fatalError( wfMsg( 'filenotfound', $name ) );
789 * return from error messages or notes
790 * @param $auto automatically redirect the user after 10 seconds
791 * @param $returnto page title to return to. Default is Main Page.
793 function returnToMain( $auto = true, $returnto = NULL ) {
794 global $wgUser, $wgOut, $wgRequest;
796 if ( $returnto == NULL ) {
797 $returnto = $wgRequest->getText( 'returnto' );
799 $returnto = htmlspecialchars( $returnto );
801 $sk = $wgUser->getSkin();
802 if ( '' == $returnto ) {
803 $returnto = wfMsgForContent( 'mainpage' );
805 $link = $sk->makeKnownLink( $returnto, '' );
807 $r = wfMsg( 'returnto', $link );
809 $titleObj = Title
::newFromText( $returnto );
810 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
812 $wgOut->addHTML( "\n<p>$r</p>\n" );
816 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
817 * and uses the first 10 of them for META keywords
819 function addMetaTags () {
820 global $wgLinkCache , $wgOut ;
821 $categories = array_keys ( $wgLinkCache->mCategoryLinks
) ;
822 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
823 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
824 $a = array_merge ( array_slice ( $good , 0 , 1 ), $categories, array_slice ( $good , 1 , 9 ) , $bad ) ;
825 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
826 $a = implode ( ',' , $a ) ;
831 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
833 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
840 function headElement() {
841 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
842 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
844 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
845 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
850 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
852 if ( '' == $this->getHTMLTitle() ) {
853 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
856 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
857 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
858 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
859 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
861 $ret .= $this->getHeadLinks();
863 if( $this->isPrintable() ) {
866 $media = "media='print'";
868 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
869 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
871 $sk = $wgUser->getSkin();
872 $ret .= $sk->getHeadScripts();
873 $ret .= $this->mScripts
;
874 $ret .= $sk->getUserStyles();
876 if ($wgUseTrackbacks && $this->isArticleRelated())
877 $ret .= $wgTitle->trackbackRDF();
883 function getHeadLinks() {
884 global $wgRequest, $wgStylePath;
886 foreach ( $this->mMetatags
as $tag ) {
887 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
889 $tag[0] = substr( $tag[0], 5 );
893 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
895 $p = $this->mRobotpolicy
;
896 if ( '' == $p ) { $p = 'index,follow'; }
897 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
899 if ( count( $this->mKeywords
) > 0 ) {
904 $ret .= "<meta name=\"keywords\" content=\"" .
905 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
907 foreach ( $this->mLinktags
as $tag ) {
909 foreach( $tag as $attr => $val ) {
910 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
914 if( $this->isSyndicated() ) {
915 # FIXME: centralize the mime-type and name information in Feed.php
916 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
917 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
918 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
919 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
926 * Run any necessary pre-output transformations on the buffer text
928 function transformBuffer( $options = 0 ) {
933 * Turn off regular page output and return an error reponse
934 * for when rate limiting has triggered.
938 function rateLimited() {
941 wfHttpError( 500, 'Internal Server Error',
942 'Sorry, the server has encountered an internal error. ' .
943 'Please wait a moment and hit "refresh" to submit the request again.' );