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 $wgLang, $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) {
266 global $wgParser, $wgUseTidy;
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, $wgUseTidy;
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, $wgLang, $wgDebugComments, $wgCookieExpiration;
424 global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
425 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
427 if( $this->mDoNothing
){
430 $fname = 'OutputPage::output';
431 wfProfileIn( $fname );
432 $sk = $wgUser->getSkin();
434 if ( '' != $this->mRedirect
) {
435 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
436 # Standards require redirect URLs to be absolute
438 $this->mRedirect
= $wgServer . $this->mRedirect
;
440 if( $this->mRedirectCode
== '301') {
441 if( !$wgDebugRedirects ) {
442 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
444 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
447 $this->sendCacheControl();
449 if( $wgDebugRedirects ) {
450 $url = htmlspecialchars( $this->mRedirect
);
451 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
452 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
453 print "</body>\n</html>\n";
455 header( 'Location: '.$this->mRedirect
);
457 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
458 wfProfileOut( $fname );
461 elseif ( $this->mStatusCode
)
463 $statusMessage = array(
465 101 => 'Switching Protocols',
470 203 => 'Non-Authoritative Information',
472 205 => 'Reset Content',
473 206 => 'Partial Content',
474 207 => 'Multi-Status',
475 300 => 'Multiple Choices',
476 301 => 'Moved Permanently',
479 304 => 'Not Modified',
481 307 => 'Temporary Redirect',
482 400 => 'Bad Request',
483 401 => 'Unauthorized',
484 402 => 'Payment Required',
487 405 => 'Method Not Allowed',
488 406 => 'Not Acceptable',
489 407 => 'Proxy Authentication Required',
490 408 => 'Request Timeout',
493 411 => 'Length Required',
494 412 => 'Precondition Failed',
495 413 => 'Request Entity Too Large',
496 414 => 'Request-URI Too Large',
497 415 => 'Unsupported Media Type',
498 416 => 'Request Range Not Satisfiable',
499 417 => 'Expectation Failed',
500 422 => 'Unprocessable Entity',
502 424 => 'Failed Dependency',
503 500 => 'Internal Server Error',
504 501 => 'Not Implemented',
505 502 => 'Bad Gateway',
506 503 => 'Service Unavailable',
507 504 => 'Gateway Timeout',
508 505 => 'HTTP Version Not Supported',
509 507 => 'Insufficient Storage'
512 if ( $statusMessage[$this->mStatusCode
] )
513 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
516 # Buffer output; final headers may depend on later processing
519 $this->transformBuffer();
521 # Disable temporary placeholders, so that the skin produces HTML
522 $sk->postParseLinkColour( false );
524 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
525 header( 'Content-language: '.$wgContLanguageCode );
527 $exp = time() +
$wgCookieExpiration;
528 foreach( $this->mCookies
as $name => $val ) {
529 setcookie( $name, $val, $exp, '/' );
532 if ($this->mArticleBodyOnly
) {
533 $this->out($this->mBodytext
);
535 wfProfileIn( 'Output-skin' );
536 $sk->outputPage( $this );
537 wfProfileOut( 'Output-skin' );
540 $this->sendCacheControl();
542 wfProfileOut( $fname );
545 function out( $ins ) {
546 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
547 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
550 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
551 if ( false === $outs ) { $outs = $ins; }
556 function setEncodings() {
557 global $wgInputEncoding, $wgOutputEncoding;
558 global $wgUser, $wgContLang;
560 $wgInputEncoding = strtolower( $wgInputEncoding );
562 if( $wgUser->getOption( 'altencoding' ) ) {
563 $wgContLang->setAltEncoding();
567 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
568 $wgOutputEncoding = strtolower( $wgOutputEncoding );
571 $wgOutputEncoding = $wgInputEncoding;
575 * Returns a HTML comment with the elapsed time since request.
576 * This method has no side effects.
577 * Use wfReportTime() instead.
581 function reportTime() {
582 $time = wfReportTime();
587 * Note: these arguments are keys into wfMsg(), not text!
589 function errorpage( $title, $msg ) {
592 $this->mDebugtext
.= 'Original title: ' .
593 $wgTitle->getPrefixedText() . "\n";
594 $this->setPageTitle( wfMsg( $title ) );
595 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
596 $this->setRobotpolicy( 'noindex,nofollow' );
597 $this->setArticleRelated( false );
598 $this->enableClientCache( false );
599 $this->mRedirect
= '';
601 $this->mBodytext
= '';
602 $this->addWikiText( wfMsg( $msg ) );
603 $this->returnToMain( false );
610 * Display an error page indicating that a given version of MediaWiki is
613 * @param mixed $version The version of MediaWiki needed to use the page
615 function versionRequired( $version ) {
618 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
619 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
620 $this->setRobotpolicy( 'noindex,nofollow' );
621 $this->setArticleRelated( false );
622 $this->mBodytext
= '';
624 $sk = $wgUser->getSkin();
625 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
626 $this->returnToMain();
630 * Display an error page noting that a given permission bit is required.
631 * This should generally replace the sysopRequired, developerRequired etc.
632 * @param string $permission key required
634 function permissionRequired( $permission ) {
637 $this->setPageTitle( wfMsg( 'badaccess' ) );
638 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
639 $this->setRobotpolicy( 'noindex,nofollow' );
640 $this->setArticleRelated( false );
641 $this->mBodytext
= '';
643 $sk = $wgUser->getSkin();
644 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
645 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
646 $this->returnToMain();
652 function sysopRequired() {
655 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
656 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
657 $this->setRobotpolicy( 'noindex,nofollow' );
658 $this->setArticleRelated( false );
659 $this->mBodytext
= '';
661 $sk = $wgUser->getSkin();
662 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
663 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
664 $this->returnToMain();
670 function developerRequired() {
673 $this->setPageTitle( wfMsg( 'developertitle' ) );
674 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
675 $this->setRobotpolicy( 'noindex,nofollow' );
676 $this->setArticleRelated( false );
677 $this->mBodytext
= '';
679 $sk = $wgUser->getSkin();
680 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
681 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
682 $this->returnToMain();
685 function loginToUse() {
686 global $wgUser, $wgTitle, $wgContLang;
688 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
689 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
690 $this->setRobotpolicy( 'noindex,nofollow' );
691 $this->setArticleFlag( false );
692 $this->mBodytext
= '';
693 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
694 $sk = $wgUser->getSkin();
695 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
696 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
697 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
699 # We put a comment in the .html file so a Sysop can diagnose the page the
701 $this->addHTML( "\n<!--" .
702 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
704 $wgTitle->getDBkey() . '-->' );
705 $this->returnToMain(); # Flip back to the main page after 10 seconds.
708 function databaseError( $fname, $sql, $error, $errno ) {
709 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
711 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
712 $this->setRobotpolicy( 'noindex,nofollow' );
713 $this->setArticleRelated( false );
714 $this->enableClientCache( false );
715 $this->mRedirect
= '';
717 if( !$wgShowSQLErrors ) {
718 $sql = wfMsg( 'sqlhidden' );
721 if ( $wgCommandLineMode ) {
722 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
723 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
725 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
726 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
729 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
733 $this->mBodytext
= $msg;
738 function readOnlyPage( $source = null, $protected = false ) {
739 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
741 $this->setRobotpolicy( 'noindex,nofollow' );
742 $this->setArticleRelated( false );
745 $this->setPageTitle( wfMsg( 'viewsource' ) );
746 $this->addWikiText( wfMsg( 'protectedtext' ) );
748 $this->setPageTitle( wfMsg( 'readonly' ) );
750 $reason = $wgReadOnly;
752 $reason = file_get_contents( $wgReadOnlyFile );
754 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
757 if( is_string( $source ) ) {
758 if( strcmp( $source, '' ) == 0 ) {
759 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
761 $rows = $wgUser->getOption( 'rows' );
762 $cols = $wgUser->getOption( 'cols' );
763 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
764 htmlspecialchars( $source ) . "\n</textarea>";
765 $this->addHTML( $text );
768 $this->returnToMain( false );
771 function fatalError( $message ) {
772 $this->setPageTitle( wfMsg( "internalerror" ) );
773 $this->setRobotpolicy( "noindex,nofollow" );
774 $this->setArticleRelated( false );
775 $this->enableClientCache( false );
776 $this->mRedirect
= '';
778 $this->mBodytext
= $message;
783 function unexpectedValueError( $name, $val ) {
784 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
787 function fileCopyError( $old, $new ) {
788 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
791 function fileRenameError( $old, $new ) {
792 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
795 function fileDeleteError( $name ) {
796 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
799 function fileNotFoundError( $name ) {
800 $this->fatalError( wfMsg( 'filenotfound', $name ) );
804 * return from error messages or notes
805 * @param $auto automatically redirect the user after 10 seconds
806 * @param $returnto page title to return to. Default is Main Page.
808 function returnToMain( $auto = true, $returnto = NULL ) {
809 global $wgUser, $wgOut, $wgRequest;
811 if ( $returnto == NULL ) {
812 $returnto = $wgRequest->getText( 'returnto' );
814 $returnto = htmlspecialchars( $returnto );
816 $sk = $wgUser->getSkin();
817 if ( '' == $returnto ) {
818 $returnto = wfMsgForContent( 'mainpage' );
820 $link = $sk->makeKnownLink( $returnto, '' );
822 $r = wfMsg( 'returnto', $link );
824 $titleObj = Title
::newFromText( $returnto );
825 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
827 $wgOut->addHTML( "\n<p>$r</p>\n" );
831 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
832 * and uses the first 10 of them for META keywords
834 function addMetaTags () {
835 global $wgLinkCache , $wgOut ;
836 $categories = array_keys ( $wgLinkCache->mCategoryLinks
) ;
837 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
838 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
839 $a = array_merge ( array_slice ( $good , 0 , 1 ), $categories, array_slice ( $good , 1 , 9 ) , $bad ) ;
840 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
841 $a = implode ( ',' , $a ) ;
846 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
848 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
855 function headElement() {
856 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
857 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
859 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
860 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
865 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
867 if ( '' == $this->getHTMLTitle() ) {
868 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
871 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
872 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
873 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
874 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
876 $ret .= $this->getHeadLinks();
878 if( $this->isPrintable() ) {
881 $media = "media='print'";
883 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
884 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
886 $sk = $wgUser->getSkin();
887 $ret .= $sk->getHeadScripts();
888 $ret .= $this->mScripts
;
889 $ret .= $sk->getUserStyles();
891 if ($wgUseTrackbacks && $this->isArticleRelated())
892 $ret .= $wgTitle->trackbackRDF();
898 function getHeadLinks() {
899 global $wgRequest, $wgStylePath;
901 foreach ( $this->mMetatags
as $tag ) {
902 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
904 $tag[0] = substr( $tag[0], 5 );
908 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
910 $p = $this->mRobotpolicy
;
911 if ( '' == $p ) { $p = 'index,follow'; }
912 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
914 if ( count( $this->mKeywords
) > 0 ) {
919 $ret .= "<meta name=\"keywords\" content=\"" .
920 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
922 foreach ( $this->mLinktags
as $tag ) {
924 foreach( $tag as $attr => $val ) {
925 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
929 if( $this->isSyndicated() ) {
930 # FIXME: centralize the mime-type and name information in Feed.php
931 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
932 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
933 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
934 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
941 * Run any necessary pre-output transformations on the buffer text
943 function transformBuffer( $options = 0 ) {
948 * Turn off regular page output and return an error reponse
949 * for when rate limiting has triggered.
953 function rateLimited() {
956 wfHttpError( 500, 'Internal Server Error',
957 'Sorry, the server has encountered an internal error. ' .
958 'Please wait a moment and hit "refresh" to submit the request again.' );