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, $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->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 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 $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 () {
149 // Display title is already customized
152 return wfMsg('history_short');
154 // FIXME: bug 2735; not correct for special pages etc
155 return wfMsg('preview');
157 return wfMsg('info_short');
163 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
164 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
165 function setPageTitle( $name ) {
166 global $action, $wgContLang;
167 $name = $wgContLang->convert($name, true);
168 $this->mPagetitle
= $name;
169 if(!empty($action)) {
170 $taction = $this->getPageTitleActionText();
171 if( !empty( $taction ) ) {
172 $name .= ' - '.$taction;
176 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
178 function getHTMLTitle() { return $this->mHTMLtitle
; }
179 function getPageTitle() { return $this->mPagetitle
; }
180 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
181 function getSubtitle() { return $this->mSubtitle
; }
182 function isArticle() { return $this->mIsarticle
; }
183 function setPrintable() { $this->mPrintable
= true; }
184 function isPrintable() { return $this->mPrintable
; }
185 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
186 function isSyndicated() { return $this->mShowFeedLinks
; }
187 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
188 function getOnloadHandler() { return $this->mOnloadHandler
; }
189 function disable() { $this->mDoNothing
= true; }
191 function setArticleRelated( $v ) {
192 $this->mIsArticleRelated
= $v;
194 $this->mIsarticle
= false;
197 function setArticleFlag( $v ) {
198 $this->mIsarticle
= $v;
200 $this->mIsArticleRelated
= $v;
204 function isArticleRelated() { return $this->mIsArticleRelated
; }
206 function getLanguageLinks() { return $this->mLanguageLinks
; }
207 function addLanguageLinks($newLinkArray) {
208 $this->mLanguageLinks +
= $newLinkArray;
210 function setLanguageLinks($newLinkArray) {
211 $this->mLanguageLinks
= $newLinkArray;
214 function getCategoryLinks() {
215 return $this->mCategoryLinks
;
217 function addCategoryLinks($newLinkArray) {
218 $this->mCategoryLinks +
= $newLinkArray;
220 function setCategoryLinks($newLinkArray) {
221 $this->mCategoryLinks +
= $newLinkArray;
224 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
225 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
227 function addHTML( $text ) { $this->mBodytext
.= $text; }
228 function clearHTML() { $this->mBodytext
= ''; }
229 function getHTML() { return $this->mBodytext
; }
230 function debug( $text ) { $this->mDebugtext
.= $text; }
233 function setParserOptions( $options ) {
234 return $this->ParserOptions( $options );
237 function ParserOptions( $options = null ) {
238 return wfSetVar( $this->mParserOptions
, $options );
242 * Set the revision ID which will be seen by the wiki text parser
243 * for things such as embedded {{REVISIONID}} variable use.
244 * @param mixed $revid an integer, or NULL
245 * @return mixed previous value
247 function setRevisionId( $revid ) {
248 $val = is_null( $revid ) ?
null : intval( $revid );
249 return wfSetVar( $this->mRevisionId
, $val );
253 * Convert wikitext to HTML and add it to the buffer
254 * Default assumes that the current page title will
257 function addWikiText( $text, $linestart = true ) {
259 $this->addWikiTextTitle($text, $wgTitle, $linestart);
262 function addWikiTextWithTitle($text, &$title, $linestart = true) {
263 $this->addWikiTextTitle($text, $title, $linestart);
266 function addWikiTextTitle($text, &$title, $linestart) {
268 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
269 $linestart, true, $this->mRevisionId
);
270 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
271 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
272 if ( $parserOutput->getCacheTime() == -1 ) {
273 $this->enableClientCache( false );
275 $this->addHTML( $parserOutput->getText() );
279 * Add wikitext to the buffer, assuming that this is the primary text for a page view
280 * Saves the text into the parser cache if possible
282 function addPrimaryWikiText( $text, $cacheArticle ) {
283 global $wgParser, $wgParserCache, $wgUser;
285 $parserOutput = $wgParser->parse( $text, $cacheArticle->mTitle
,
286 $this->mParserOptions
, true, true, $this->mRevisionId
);
288 $text = $parserOutput->getText();
290 if ( $cacheArticle && $parserOutput->getCacheTime() != -1 ) {
291 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
294 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
295 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
296 if ( $parserOutput->getCacheTime() == -1 ) {
297 $this->enableClientCache( false );
299 $this->addHTML( $text );
303 * Add the output of a QuickTemplate to the output buffer
304 * @param QuickTemplate $template
306 function addTemplate( &$template ) {
308 $template->execute();
309 $this->addHtml( ob_get_contents() );
314 * Parse wikitext and return the HTML. This is for special pages that add the text later
316 function parse( $text, $linestart = true ) {
317 global $wgParser, $wgTitle;
318 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
319 $linestart, true, $this->mRevisionId
);
320 return $parserOutput->getText();
329 function tryParserCache( $article, $user ) {
330 global $wgParserCache;
331 $parserOutput = $wgParserCache->get( $article, $user );
332 if ( $parserOutput !== false ) {
333 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
334 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
335 $this->addHTML( $parserOutput->getText() );
336 $t = $parserOutput->getTitleText();
338 $this->setPageTitle( $t );
347 * Set the maximum cache time on the Squid in seconds
350 function setSquidMaxage( $maxage ) {
351 $this->mSquidMaxage
= $maxage;
355 * Use enableClientCache(false) to force it to send nocache headers
358 function enableClientCache( $state ) {
359 return wfSetVar( $this->mEnableClientCache
, $state );
362 function uncacheableBecauseRequestvars() {
364 return $wgRequest->getText('useskin', false) === false
365 && $wgRequest->getText('uselang', false) === false;
368 function sendCacheControl() {
369 global $wgUseSquid, $wgUseESI;
372 header("ETag: $this->mETag");
374 # don't serve compressed data to clients who can't handle it
375 # maintain different caches for logged-in users and non-logged in ones
376 header( 'Vary: Accept-Encoding, Cookie' );
377 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
378 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
379 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
382 # We'll purge the proxy cache explicitly, but require end user agents
383 # to revalidate against the proxy on each visit.
384 # Surrogate-Control controls our Squid, Cache-Control downstream caches
385 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
386 # start with a shorter timeout for initial testing
387 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
388 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
389 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
391 # We'll purge the proxy cache for anons explicitly, but require end user agents
392 # to revalidate against the proxy on each visit.
393 # IMPORTANT! The Squid needs to replace the Cache-Control header with
394 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
395 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
396 # start with a shorter timeout for initial testing
397 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
398 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
401 # We do want clients to cache if they can, but they *must* check for updates
402 # on revisiting the page.
403 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
404 header( "Expires: -1" );
405 header( "Cache-Control: private, must-revalidate, max-age=0" );
407 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
409 wfDebug( "** no caching **\n", false );
411 # In general, the absence of a last modified header should be enough to prevent
412 # the client from using its cache. We send a few other things just to make sure.
413 header( 'Expires: -1' );
414 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
415 header( 'Pragma: no-cache' );
420 * Finally, all the text has been munged and accumulated into
421 * the object, let's actually output it:
424 global $wgUser, $wgOutputEncoding;
425 global $wgContLanguageCode, $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 # Disable temporary placeholders, so that the skin produces HTML
520 $sk->postParseLinkColour( false );
522 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
523 header( 'Content-language: '.$wgContLanguageCode );
525 if ($this->mArticleBodyOnly
) {
526 $this->out($this->mBodytext
);
528 wfProfileIn( 'Output-skin' );
529 $sk->outputPage( $this );
530 wfProfileOut( 'Output-skin' );
533 $this->sendCacheControl();
535 wfProfileOut( $fname );
538 function out( $ins ) {
539 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
540 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
543 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
544 if ( false === $outs ) { $outs = $ins; }
549 function setEncodings() {
550 global $wgInputEncoding, $wgOutputEncoding;
551 global $wgUser, $wgContLang;
553 $wgInputEncoding = strtolower( $wgInputEncoding );
555 if( $wgUser->getOption( 'altencoding' ) ) {
556 $wgContLang->setAltEncoding();
560 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
561 $wgOutputEncoding = strtolower( $wgOutputEncoding );
564 $wgOutputEncoding = $wgInputEncoding;
568 * Returns a HTML comment with the elapsed time since request.
569 * This method has no side effects.
570 * Use wfReportTime() instead.
574 function reportTime() {
575 $time = wfReportTime();
580 * Note: these arguments are keys into wfMsg(), not text!
582 function errorpage( $title, $msg ) {
585 $this->mDebugtext
.= 'Original title: ' .
586 $wgTitle->getPrefixedText() . "\n";
587 $this->setPageTitle( wfMsg( $title ) );
588 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
589 $this->setRobotpolicy( 'noindex,nofollow' );
590 $this->setArticleRelated( false );
591 $this->enableClientCache( false );
592 $this->mRedirect
= '';
594 $this->mBodytext
= '';
595 $this->addWikiText( wfMsg( $msg ) );
596 $this->returnToMain( false );
603 * Display an error page indicating that a given version of MediaWiki is
606 * @param mixed $version The version of MediaWiki needed to use the page
608 function versionRequired( $version ) {
611 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
612 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
613 $this->setRobotpolicy( 'noindex,nofollow' );
614 $this->setArticleRelated( false );
615 $this->mBodytext
= '';
617 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
618 $this->returnToMain();
622 * Display an error page noting that a given permission bit is required.
623 * This should generally replace the sysopRequired, developerRequired etc.
624 * @param string $permission key required
626 function permissionRequired( $permission ) {
629 $this->setPageTitle( wfMsg( 'badaccess' ) );
630 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
631 $this->setRobotpolicy( 'noindex,nofollow' );
632 $this->setArticleRelated( false );
633 $this->mBodytext
= '';
635 $sk = $wgUser->getSkin();
636 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
637 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
638 $this->returnToMain();
644 function sysopRequired() {
647 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
648 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
649 $this->setRobotpolicy( 'noindex,nofollow' );
650 $this->setArticleRelated( false );
651 $this->mBodytext
= '';
653 $sk = $wgUser->getSkin();
654 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
655 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
656 $this->returnToMain();
662 function developerRequired() {
665 $this->setPageTitle( wfMsg( 'developertitle' ) );
666 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
667 $this->setRobotpolicy( 'noindex,nofollow' );
668 $this->setArticleRelated( false );
669 $this->mBodytext
= '';
671 $sk = $wgUser->getSkin();
672 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
673 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
674 $this->returnToMain();
677 function loginToUse() {
678 global $wgUser, $wgTitle, $wgContLang;
680 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
681 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
682 $this->setRobotpolicy( 'noindex,nofollow' );
683 $this->setArticleFlag( false );
684 $this->mBodytext
= '';
685 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
686 $sk = $wgUser->getSkin();
687 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
688 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
689 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
691 # We put a comment in the .html file so a Sysop can diagnose the page the
693 $this->addHTML( "\n<!--" .
694 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
696 $wgTitle->getDBkey() . '-->' );
697 $this->returnToMain(); # Flip back to the main page after 10 seconds.
700 function databaseError( $fname, $sql, $error, $errno ) {
701 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
703 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
704 $this->setRobotpolicy( 'noindex,nofollow' );
705 $this->setArticleRelated( false );
706 $this->enableClientCache( false );
707 $this->mRedirect
= '';
709 if( !$wgShowSQLErrors ) {
710 $sql = wfMsg( 'sqlhidden' );
713 if ( $wgCommandLineMode ) {
714 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
715 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
717 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
718 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
721 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
725 $this->mBodytext
= $msg;
730 function readOnlyPage( $source = null, $protected = false ) {
731 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
733 $this->setRobotpolicy( 'noindex,nofollow' );
734 $this->setArticleRelated( false );
737 $this->setPageTitle( wfMsg( 'viewsource' ) );
738 $this->addWikiText( wfMsg( 'protectedtext' ) );
740 $this->setPageTitle( wfMsg( 'readonly' ) );
742 $reason = $wgReadOnly;
744 $reason = file_get_contents( $wgReadOnlyFile );
746 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
749 if( is_string( $source ) ) {
750 if( strcmp( $source, '' ) == 0 ) {
751 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
753 $rows = $wgUser->getOption( 'rows' );
754 $cols = $wgUser->getOption( 'cols' );
755 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
756 htmlspecialchars( $source ) . "\n</textarea>";
757 $this->addHTML( $text );
760 $this->returnToMain( false );
763 function fatalError( $message ) {
764 $this->setPageTitle( wfMsg( "internalerror" ) );
765 $this->setRobotpolicy( "noindex,nofollow" );
766 $this->setArticleRelated( false );
767 $this->enableClientCache( false );
768 $this->mRedirect
= '';
770 $this->mBodytext
= $message;
775 function unexpectedValueError( $name, $val ) {
776 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
779 function fileCopyError( $old, $new ) {
780 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
783 function fileRenameError( $old, $new ) {
784 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
787 function fileDeleteError( $name ) {
788 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
791 function fileNotFoundError( $name ) {
792 $this->fatalError( wfMsg( 'filenotfound', $name ) );
796 * return from error messages or notes
797 * @param $auto automatically redirect the user after 10 seconds
798 * @param $returnto page title to return to. Default is Main Page.
800 function returnToMain( $auto = true, $returnto = NULL ) {
801 global $wgUser, $wgOut, $wgRequest;
803 if ( $returnto == NULL ) {
804 $returnto = $wgRequest->getText( 'returnto' );
806 $returnto = htmlspecialchars( $returnto );
808 $sk = $wgUser->getSkin();
809 if ( '' == $returnto ) {
810 $returnto = wfMsgForContent( 'mainpage' );
812 $link = $sk->makeKnownLink( $returnto, '' );
814 $r = wfMsg( 'returnto', $link );
816 $titleObj = Title
::newFromText( $returnto );
817 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
819 $wgOut->addHTML( "\n<p>$r</p>\n" );
823 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
824 * and uses the first 10 of them for META keywords
826 function addMetaTags () {
827 global $wgLinkCache , $wgOut ;
828 $categories = array_keys ( $wgLinkCache->mCategoryLinks
) ;
829 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
830 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
831 $a = array_merge ( array_slice ( $good , 0 , 1 ), $categories, array_slice ( $good , 1 , 9 ) , $bad ) ;
832 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
833 $a = implode ( ',' , $a ) ;
838 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
840 $wgOut->addMeta( 'keywords' , $a ) ;
847 function headElement() {
848 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
849 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
851 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
852 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
857 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
859 if ( '' == $this->getHTMLTitle() ) {
860 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
863 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
864 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
865 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
866 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
868 $ret .= $this->getHeadLinks();
870 if( $this->isPrintable() ) {
873 $media = "media='print'";
875 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
876 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
878 $sk = $wgUser->getSkin();
879 $ret .= $sk->getHeadScripts();
880 $ret .= $this->mScripts
;
881 $ret .= $sk->getUserStyles();
883 if ($wgUseTrackbacks && $this->isArticleRelated())
884 $ret .= $wgTitle->trackbackRDF();
890 function getHeadLinks() {
891 global $wgRequest, $wgStylePath;
893 foreach ( $this->mMetatags
as $tag ) {
894 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
896 $tag[0] = substr( $tag[0], 5 );
900 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
903 $p = $this->mRobotpolicy
;
904 if( $p !== '' && $p != 'index,follow' ) {
905 // http://www.robotstxt.org/wc/meta-user.html
906 // Only show if it's different from the default robots policy
907 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
910 if ( count( $this->mKeywords
) > 0 ) {
915 $ret .= "<meta name=\"keywords\" content=\"" .
916 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
918 foreach ( $this->mLinktags
as $tag ) {
920 foreach( $tag as $attr => $val ) {
921 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
925 if( $this->isSyndicated() ) {
926 # FIXME: centralize the mime-type and name information in Feed.php
927 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
928 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
929 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
930 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
937 * Turn off regular page output and return an error reponse
938 * for when rate limiting has triggered.
942 function rateLimited() {
945 wfHttpError( 500, 'Internal Server Error',
946 'Sorry, the server has encountered an internal error. ' .
947 'Please wait a moment and hit "refresh" to submit the request again.' );