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;
58 $this->mRevisionId
= null;
61 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ) ; }
62 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
63 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
64 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
66 # To add an http-equiv meta tag, precede the name with "http:"
67 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
68 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
69 function addScript( $script ) { $this->mScripts
.= $script; }
70 function getScript() { return $this->mScripts
; }
72 function setETag($tag) { $this->mETag
= $tag; }
73 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
74 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
76 function addLink( $linkarr ) {
77 # $linkarr should be an associative array of attributes. We'll escape on output.
78 array_push( $this->mLinktags
, $linkarr );
81 function addMetadataLink( $linkarr ) {
82 # note: buggy CC software only reads first "meta" link
83 static $haveMeta = false;
84 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
85 $this->addLink( $linkarr );
90 * checkLastModified tells the client to use the client-cached page if
91 * possible. If sucessful, the OutputPage is disabled so that
92 * any future call to OutputPage->output() have no effect. The method
93 * returns true iff cache-ok headers was sent.
95 function checkLastModified ( $timestamp ) {
96 global $wgCachePages, $wgUser;
97 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
98 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
101 if( !$wgCachePages ) {
102 wfDebug( "CACHE DISABLED\n", false );
105 if( $wgUser->getOption( 'nocache' ) ) {
106 wfDebug( "USER DISABLED CACHE\n", false );
110 $timestamp=wfTimestamp(TS_MW
,$timestamp);
111 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
) );
113 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
114 # IE sends sizes after the date like this:
115 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
116 # this breaks strtotime().
117 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
118 $modsinceTime = strtotime( $modsince );
119 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
120 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
121 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
122 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
123 # Make sure you're in a place you can leave when you call us!
124 header( "HTTP/1.0 304 Not Modified" );
125 $this->mLastModified
= $lastmod;
126 $this->sendCacheControl();
127 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
129 @ob_end_clean
(); // Don't output compressed blob
132 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
133 $this->mLastModified
= $lastmod;
136 wfDebug( "client did not send If-Modified-Since header\n", false );
137 $this->mLastModified
= $lastmod;
141 function getPageTitleActionText () {
145 return wfMsg('edit');
147 return wfMsg('history_short');
149 return wfMsg('protect');
151 return wfMsg('unprotect');
153 return wfMsg('delete');
155 return wfMsg('watch');
157 return wfMsg('unwatch');
159 return wfMsg('preview');
161 return wfMsg('info_short');
167 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
168 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
169 function setPageTitle( $name ) {
170 global $action, $wgContLang;
171 $name = $wgContLang->convert($name, true);
172 $this->mPagetitle
= $name;
173 if(!empty($action)) {
174 $taction = $this->getPageTitleActionText();
175 if( !empty( $taction ) ) {
176 $name .= ' - '.$taction;
180 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
182 function getHTMLTitle() { return $this->mHTMLtitle
; }
183 function getPageTitle() { return $this->mPagetitle
; }
184 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
185 function getSubtitle() { return $this->mSubtitle
; }
186 function isArticle() { return $this->mIsarticle
; }
187 function setPrintable() { $this->mPrintable
= true; }
188 function isPrintable() { return $this->mPrintable
; }
189 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
190 function isSyndicated() { return $this->mShowFeedLinks
; }
191 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
192 function getOnloadHandler() { return $this->mOnloadHandler
; }
193 function disable() { $this->mDoNothing
= true; }
195 function setArticleRelated( $v ) {
196 $this->mIsArticleRelated
= $v;
198 $this->mIsarticle
= false;
201 function setArticleFlag( $v ) {
202 $this->mIsarticle
= $v;
204 $this->mIsArticleRelated
= $v;
208 function isArticleRelated() { return $this->mIsArticleRelated
; }
210 function getLanguageLinks() { return $this->mLanguageLinks
; }
211 function addLanguageLinks($newLinkArray) {
212 $this->mLanguageLinks +
= $newLinkArray;
214 function setLanguageLinks($newLinkArray) {
215 $this->mLanguageLinks
= $newLinkArray;
218 function getCategoryLinks() {
219 return $this->mCategoryLinks
;
221 function addCategoryLinks($newLinkArray) {
222 $this->mCategoryLinks +
= $newLinkArray;
224 function setCategoryLinks($newLinkArray) {
225 $this->mCategoryLinks +
= $newLinkArray;
228 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
229 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
231 function addHTML( $text ) { $this->mBodytext
.= $text; }
232 function clearHTML() { $this->mBodytext
= ''; }
233 function getHTML() { return $this->mBodytext
; }
234 function debug( $text ) { $this->mDebugtext
.= $text; }
236 function setParserOptions( $options ) {
237 return wfSetVar( $this->mParserOptions
, $options );
241 * Set the revision ID which will be seen by the wiki text parser
242 * for things such as embedded {{REVISIONID}} variable use.
243 * @param mixed $revid an integer, or NULL
244 * @return mixed previous value
246 function setRevisionId( $revid ) {
247 $val = is_null( $revid ) ?
null : intval( $revid );
248 return wfSetVar( $this->mRevisionId
, $val );
252 * Convert wikitext to HTML and add it to the buffer
253 * Default assumes that the current page title will
256 function addWikiText( $text, $linestart = true ) {
258 $this->addWikiTextTitle($text, $wgTitle, $linestart);
261 function addWikiTextWithTitle($text, &$title, $linestart = true) {
262 $this->addWikiTextTitle($text, $title, $linestart);
265 function addWikiTextTitle($text, &$title, $linestart) {
267 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
268 $linestart, true, $this->mRevisionId
);
269 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
270 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
271 if ( $parserOutput->getCacheTime() == -1 ) {
272 $this->enableClientCache( false );
274 $this->addHTML( $parserOutput->getText() );
278 * Add wikitext to the buffer, assuming that this is the primary text for a page view
279 * Saves the text into the parser cache if possible
281 function addPrimaryWikiText( $text, $cacheArticle ) {
282 global $wgParser, $wgParserCache, $wgUser;
284 $parserOutput = $wgParser->parse( $text, $cacheArticle->mTitle
,
285 $this->mParserOptions
, true, true, $this->mRevisionId
);
287 $text = $parserOutput->getText();
289 if ( $cacheArticle && $parserOutput->getCacheTime() != -1 ) {
290 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
293 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
294 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
295 if ( $parserOutput->getCacheTime() == -1 ) {
296 $this->enableClientCache( false );
298 $this->addHTML( $text );
302 * Add the output of a QuickTemplate to the output buffer
303 * @param QuickTemplate $template
305 function addTemplate( &$template ) {
307 $template->execute();
308 $this->addHtml( ob_get_contents() );
313 * Parse wikitext and return the HTML. This is for special pages that add the text later
315 function parse( $text, $linestart = true ) {
316 global $wgParser, $wgTitle;
317 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
318 $linestart, true, $this->mRevisionId
);
319 return $parserOutput->getText();
328 function tryParserCache( $article, $user ) {
329 global $wgParserCache;
330 $parserOutput = $wgParserCache->get( $article, $user );
331 if ( $parserOutput !== false ) {
332 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
333 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
334 $this->addHTML( $parserOutput->getText() );
335 $t = $parserOutput->getTitleText();
337 $this->setPageTitle( $t );
346 * Set the maximum cache time on the Squid in seconds
349 function setSquidMaxage( $maxage ) {
350 $this->mSquidMaxage
= $maxage;
354 * Use enableClientCache(false) to force it to send nocache headers
357 function enableClientCache( $state ) {
358 return wfSetVar( $this->mEnableClientCache
, $state );
361 function uncacheableBecauseRequestvars() {
363 return $wgRequest->getText('useskin', false) === false
364 && $wgRequest->getText('uselang', false) === false;
367 function sendCacheControl() {
368 global $wgUseSquid, $wgUseESI;
371 header("ETag: $this->mETag");
373 # don't serve compressed data to clients who can't handle it
374 # maintain different caches for logged-in users and non-logged in ones
375 header( 'Vary: Accept-Encoding, Cookie' );
376 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
377 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
378 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
381 # We'll purge the proxy cache explicitly, but require end user agents
382 # to revalidate against the proxy on each visit.
383 # Surrogate-Control controls our Squid, Cache-Control downstream caches
384 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
385 # start with a shorter timeout for initial testing
386 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
387 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
388 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
390 # We'll purge the proxy cache for anons explicitly, but require end user agents
391 # to revalidate against the proxy on each visit.
392 # IMPORTANT! The Squid needs to replace the Cache-Control header with
393 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
394 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
395 # start with a shorter timeout for initial testing
396 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
397 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
400 # We do want clients to cache if they can, but they *must* check for updates
401 # on revisiting the page.
402 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
403 header( "Expires: -1" );
404 header( "Cache-Control: private, must-revalidate, max-age=0" );
406 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
408 wfDebug( "** no caching **\n", false );
410 # In general, the absence of a last modified header should be enough to prevent
411 # the client from using its cache. We send a few other things just to make sure.
412 header( 'Expires: -1' );
413 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
414 header( 'Pragma: no-cache' );
419 * Finally, all the text has been munged and accumulated into
420 * the object, let's actually output it:
423 global $wgUser, $wgCookieExpiration, $wgOutputEncoding;
424 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType, $wgProfiler;
426 if( $this->mDoNothing
){
429 $fname = 'OutputPage::output';
430 wfProfileIn( $fname );
431 $sk = $wgUser->getSkin();
433 if ( '' != $this->mRedirect
) {
434 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
435 # Standards require redirect URLs to be absolute
437 $this->mRedirect
= $wgServer . $this->mRedirect
;
439 if( $this->mRedirectCode
== '301') {
440 if( !$wgDebugRedirects ) {
441 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
443 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
446 $this->sendCacheControl();
448 if( $wgDebugRedirects ) {
449 $url = htmlspecialchars( $this->mRedirect
);
450 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
451 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
452 print "</body>\n</html>\n";
454 header( 'Location: '.$this->mRedirect
);
456 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
457 wfProfileOut( $fname );
460 elseif ( $this->mStatusCode
)
462 $statusMessage = array(
464 101 => 'Switching Protocols',
469 203 => 'Non-Authoritative Information',
471 205 => 'Reset Content',
472 206 => 'Partial Content',
473 207 => 'Multi-Status',
474 300 => 'Multiple Choices',
475 301 => 'Moved Permanently',
478 304 => 'Not Modified',
480 307 => 'Temporary Redirect',
481 400 => 'Bad Request',
482 401 => 'Unauthorized',
483 402 => 'Payment Required',
486 405 => 'Method Not Allowed',
487 406 => 'Not Acceptable',
488 407 => 'Proxy Authentication Required',
489 408 => 'Request Timeout',
492 411 => 'Length Required',
493 412 => 'Precondition Failed',
494 413 => 'Request Entity Too Large',
495 414 => 'Request-URI Too Large',
496 415 => 'Unsupported Media Type',
497 416 => 'Request Range Not Satisfiable',
498 417 => 'Expectation Failed',
499 422 => 'Unprocessable Entity',
501 424 => 'Failed Dependency',
502 500 => 'Internal Server Error',
503 501 => 'Not Implemented',
504 502 => 'Bad Gateway',
505 503 => 'Service Unavailable',
506 504 => 'Gateway Timeout',
507 505 => 'HTTP Version Not Supported',
508 507 => 'Insufficient Storage'
511 if ( $statusMessage[$this->mStatusCode
] )
512 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
515 # Buffer output; final headers may depend on later processing
518 $this->transformBuffer();
520 # Disable temporary placeholders, so that the skin produces HTML
521 $sk->postParseLinkColour( false );
523 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
524 header( 'Content-language: '.$wgContLanguageCode );
526 $exp = time() +
$wgCookieExpiration;
527 foreach( $this->mCookies
as $name => $val ) {
528 setcookie( $name, $val, $exp, '/' );
531 if ($this->mArticleBodyOnly
) {
532 $this->out($this->mBodytext
);
534 wfProfileIn( 'Output-skin' );
535 $sk->outputPage( $this );
536 wfProfileOut( 'Output-skin' );
539 $this->sendCacheControl();
541 wfProfileOut( $fname );
544 function out( $ins ) {
545 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
546 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
549 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
550 if ( false === $outs ) { $outs = $ins; }
555 function setEncodings() {
556 global $wgInputEncoding, $wgOutputEncoding;
557 global $wgUser, $wgContLang;
559 $wgInputEncoding = strtolower( $wgInputEncoding );
561 if( $wgUser->getOption( 'altencoding' ) ) {
562 $wgContLang->setAltEncoding();
566 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
567 $wgOutputEncoding = strtolower( $wgOutputEncoding );
570 $wgOutputEncoding = $wgInputEncoding;
574 * Returns a HTML comment with the elapsed time since request.
575 * This method has no side effects.
576 * Use wfReportTime() instead.
580 function reportTime() {
581 $time = wfReportTime();
586 * Note: these arguments are keys into wfMsg(), not text!
588 function errorpage( $title, $msg ) {
591 $this->mDebugtext
.= 'Original title: ' .
592 $wgTitle->getPrefixedText() . "\n";
593 $this->setPageTitle( wfMsg( $title ) );
594 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
595 $this->setRobotpolicy( 'noindex,nofollow' );
596 $this->setArticleRelated( false );
597 $this->enableClientCache( false );
598 $this->mRedirect
= '';
600 $this->mBodytext
= '';
601 $this->addWikiText( wfMsg( $msg ) );
602 $this->returnToMain( false );
609 * Display an error page indicating that a given version of MediaWiki is
612 * @param mixed $version The version of MediaWiki needed to use the page
614 function versionRequired( $version ) {
617 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
618 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
619 $this->setRobotpolicy( 'noindex,nofollow' );
620 $this->setArticleRelated( false );
621 $this->mBodytext
= '';
623 $sk = $wgUser->getSkin();
624 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
625 $this->returnToMain();
629 * Display an error page noting that a given permission bit is required.
630 * This should generally replace the sysopRequired, developerRequired etc.
631 * @param string $permission key required
633 function permissionRequired( $permission ) {
636 $this->setPageTitle( wfMsg( 'badaccess' ) );
637 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
638 $this->setRobotpolicy( 'noindex,nofollow' );
639 $this->setArticleRelated( false );
640 $this->mBodytext
= '';
642 $sk = $wgUser->getSkin();
643 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
644 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
645 $this->returnToMain();
651 function sysopRequired() {
654 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
655 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
656 $this->setRobotpolicy( 'noindex,nofollow' );
657 $this->setArticleRelated( false );
658 $this->mBodytext
= '';
660 $sk = $wgUser->getSkin();
661 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
662 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
663 $this->returnToMain();
669 function developerRequired() {
672 $this->setPageTitle( wfMsg( 'developertitle' ) );
673 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
674 $this->setRobotpolicy( 'noindex,nofollow' );
675 $this->setArticleRelated( false );
676 $this->mBodytext
= '';
678 $sk = $wgUser->getSkin();
679 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
680 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
681 $this->returnToMain();
684 function loginToUse() {
685 global $wgUser, $wgTitle, $wgContLang;
687 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
688 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
689 $this->setRobotpolicy( 'noindex,nofollow' );
690 $this->setArticleFlag( false );
691 $this->mBodytext
= '';
692 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
693 $sk = $wgUser->getSkin();
694 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
695 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
696 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
698 # We put a comment in the .html file so a Sysop can diagnose the page the
700 $this->addHTML( "\n<!--" .
701 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
703 $wgTitle->getDBkey() . '-->' );
704 $this->returnToMain(); # Flip back to the main page after 10 seconds.
707 function databaseError( $fname, $sql, $error, $errno ) {
708 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
710 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
711 $this->setRobotpolicy( 'noindex,nofollow' );
712 $this->setArticleRelated( false );
713 $this->enableClientCache( false );
714 $this->mRedirect
= '';
716 if( !$wgShowSQLErrors ) {
717 $sql = wfMsg( 'sqlhidden' );
720 if ( $wgCommandLineMode ) {
721 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
722 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
724 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
725 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
728 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
732 $this->mBodytext
= $msg;
737 function readOnlyPage( $source = null, $protected = false ) {
738 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
740 $this->setRobotpolicy( 'noindex,nofollow' );
741 $this->setArticleRelated( false );
744 $this->setPageTitle( wfMsg( 'viewsource' ) );
745 $this->addWikiText( wfMsg( 'protectedtext' ) );
747 $this->setPageTitle( wfMsg( 'readonly' ) );
749 $reason = $wgReadOnly;
751 $reason = file_get_contents( $wgReadOnlyFile );
753 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
756 if( is_string( $source ) ) {
757 if( strcmp( $source, '' ) == 0 ) {
758 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
760 $rows = $wgUser->getOption( 'rows' );
761 $cols = $wgUser->getOption( 'cols' );
762 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
763 htmlspecialchars( $source ) . "\n</textarea>";
764 $this->addHTML( $text );
767 $this->returnToMain( false );
770 function fatalError( $message ) {
771 $this->setPageTitle( wfMsg( "internalerror" ) );
772 $this->setRobotpolicy( "noindex,nofollow" );
773 $this->setArticleRelated( false );
774 $this->enableClientCache( false );
775 $this->mRedirect
= '';
777 $this->mBodytext
= $message;
782 function unexpectedValueError( $name, $val ) {
783 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
786 function fileCopyError( $old, $new ) {
787 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
790 function fileRenameError( $old, $new ) {
791 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
794 function fileDeleteError( $name ) {
795 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
798 function fileNotFoundError( $name ) {
799 $this->fatalError( wfMsg( 'filenotfound', $name ) );
803 * return from error messages or notes
804 * @param $auto automatically redirect the user after 10 seconds
805 * @param $returnto page title to return to. Default is Main Page.
807 function returnToMain( $auto = true, $returnto = NULL ) {
808 global $wgUser, $wgOut, $wgRequest;
810 if ( $returnto == NULL ) {
811 $returnto = $wgRequest->getText( 'returnto' );
813 $returnto = htmlspecialchars( $returnto );
815 $sk = $wgUser->getSkin();
816 if ( '' == $returnto ) {
817 $returnto = wfMsgForContent( 'mainpage' );
819 $link = $sk->makeKnownLink( $returnto, '' );
821 $r = wfMsg( 'returnto', $link );
823 $titleObj = Title
::newFromText( $returnto );
824 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
826 $wgOut->addHTML( "\n<p>$r</p>\n" );
830 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
831 * and uses the first 10 of them for META keywords
833 function addMetaTags () {
834 global $wgLinkCache , $wgOut ;
835 $categories = array_keys ( $wgLinkCache->mCategoryLinks
) ;
836 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
837 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
838 $a = array_merge ( array_slice ( $good , 0 , 1 ), $categories, array_slice ( $good , 1 , 9 ) , $bad ) ;
839 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
840 $a = implode ( ',' , $a ) ;
845 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
847 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
854 function headElement() {
855 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
856 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
858 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
859 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
864 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
866 if ( '' == $this->getHTMLTitle() ) {
867 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
870 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
871 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
872 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
873 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
875 $ret .= $this->getHeadLinks();
877 if( $this->isPrintable() ) {
880 $media = "media='print'";
882 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
883 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
885 $sk = $wgUser->getSkin();
886 $ret .= $sk->getHeadScripts();
887 $ret .= $this->mScripts
;
888 $ret .= $sk->getUserStyles();
890 if ($wgUseTrackbacks && $this->isArticleRelated())
891 $ret .= $wgTitle->trackbackRDF();
897 function getHeadLinks() {
898 global $wgRequest, $wgStylePath;
900 foreach ( $this->mMetatags
as $tag ) {
901 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
903 $tag[0] = substr( $tag[0], 5 );
907 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
909 $p = $this->mRobotpolicy
;
910 if ( '' == $p ) { $p = 'index,follow'; }
911 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
913 if ( count( $this->mKeywords
) > 0 ) {
918 $ret .= "<meta name=\"keywords\" content=\"" .
919 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
921 foreach ( $this->mLinktags
as $tag ) {
923 foreach( $tag as $attr => $val ) {
924 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
928 if( $this->isSyndicated() ) {
929 # FIXME: centralize the mime-type and name information in Feed.php
930 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
931 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
932 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
933 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
940 * Run any necessary pre-output transformations on the buffer text
942 function transformBuffer( $options = 0 ) {
947 * Turn off regular page output and return an error reponse
948 * for when rate limiting has triggered.
952 function rateLimited() {
955 wfHttpError( 500, 'Internal Server Error',
956 'Sorry, the server has encountered an internal error. ' .
957 'Please wait a moment and hit "refresh" to submit the request again.' );