2 if ( ! defined( 'MEDIAWIKI' ) )
13 var $mHeaders, $mMetatags, $mKeywords;
14 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
15 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
16 var $mSubtitle, $mRedirect, $mStatusCode;
17 var $mLastModified, $mETag, $mCategoryLinks;
18 var $mScripts, $mLinkColours, $mPageLinkTitle;
20 var $mSuppressQuickbar;
23 var $mContainsOldMagic, $mContainsNewMagic;
24 var $mIsArticleRelated;
26 var $mShowFeedLinks = false;
27 var $mEnableClientCache = true;
28 var $mArticleBodyOnly = false;
30 var $mNewSectionLink = false;
31 var $mNoGallery = false;
35 * Initialise private variables
37 function OutputPage() {
38 $this->mHeaders
= $this->mMetatags
=
39 $this->mKeywords
= $this->mLinktags
= array();
40 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
41 $this->mRedirect
= $this->mLastModified
=
42 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
43 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
44 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
45 $this->mSuppressQuickbar
= $this->mPrintable
= false;
46 $this->mLanguageLinks
= array();
47 $this->mCategoryLinks
= array();
48 $this->mDoNothing
= false;
49 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
50 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
51 $this->mSquidMaxage
= 0;
54 $this->mRevisionId
= null;
55 $this->mNewSectionLink
= false;
58 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ); }
59 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
60 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
62 # To add an http-equiv meta tag, precede the name with "http:"
63 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
64 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
65 function addScript( $script ) { $this->mScripts
.= $script; }
66 function getScript() { return $this->mScripts
; }
68 function setETag($tag) { $this->mETag
= $tag; }
69 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
70 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
72 function addLink( $linkarr ) {
73 # $linkarr should be an associative array of attributes. We'll escape on output.
74 array_push( $this->mLinktags
, $linkarr );
77 function addMetadataLink( $linkarr ) {
78 # note: buggy CC software only reads first "meta" link
79 static $haveMeta = false;
80 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
81 $this->addLink( $linkarr );
86 * checkLastModified tells the client to use the client-cached page if
87 * possible. If sucessful, the OutputPage is disabled so that
88 * any future call to OutputPage->output() have no effect. The method
89 * returns true iff cache-ok headers was sent.
91 function checkLastModified ( $timestamp ) {
92 global $wgCachePages, $wgCacheEpoch, $wgUser;
93 $fname = 'OutputPage::checkLastModified';
95 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
96 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
99 if( !$wgCachePages ) {
100 wfDebug( "$fname: CACHE DISABLED\n", false );
103 if( $wgUser->getOption( 'nocache' ) ) {
104 wfDebug( "$fname: USER DISABLED CACHE\n", false );
108 $timestamp=wfTimestamp(TS_MW
,$timestamp);
109 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
111 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
112 # IE sends sizes after the date like this:
113 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
114 # this breaks strtotime().
115 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
116 $modsinceTime = strtotime( $modsince );
117 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
118 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
119 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
120 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
121 # Make sure you're in a place you can leave when you call us!
122 header( "HTTP/1.0 304 Not Modified" );
123 $this->mLastModified
= $lastmod;
124 $this->sendCacheControl();
125 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
127 @ob_end_clean
(); // Don't output compressed blob
130 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
131 $this->mLastModified
= $lastmod;
134 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
135 $this->mLastModified
= $lastmod;
139 function getPageTitleActionText () {
148 // Display title is already customized
151 return wfMsg('history_short');
153 // FIXME: bug 2735; not correct for special pages etc
154 return wfMsg('preview');
156 return wfMsg('info_short');
162 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
163 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
164 function setPageTitle( $name ) {
165 global $action, $wgContLang;
166 $name = $wgContLang->convert($name, true);
167 $this->mPagetitle
= $name;
168 if(!empty($action)) {
169 $taction = $this->getPageTitleActionText();
170 if( !empty( $taction ) ) {
171 $name .= ' - '.$taction;
175 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
177 function getHTMLTitle() { return $this->mHTMLtitle
; }
178 function getPageTitle() { return $this->mPagetitle
; }
179 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
180 function getSubtitle() { return $this->mSubtitle
; }
181 function isArticle() { return $this->mIsarticle
; }
182 function setPrintable() { $this->mPrintable
= true; }
183 function isPrintable() { return $this->mPrintable
; }
184 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
185 function isSyndicated() { return $this->mShowFeedLinks
; }
186 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
187 function getOnloadHandler() { return $this->mOnloadHandler
; }
188 function disable() { $this->mDoNothing
= true; }
190 function setArticleRelated( $v ) {
191 $this->mIsArticleRelated
= $v;
193 $this->mIsarticle
= false;
196 function setArticleFlag( $v ) {
197 $this->mIsarticle
= $v;
199 $this->mIsArticleRelated
= $v;
203 function isArticleRelated() { return $this->mIsArticleRelated
; }
205 function getLanguageLinks() { return $this->mLanguageLinks
; }
206 function addLanguageLinks($newLinkArray) {
207 $this->mLanguageLinks +
= $newLinkArray;
209 function setLanguageLinks($newLinkArray) {
210 $this->mLanguageLinks
= $newLinkArray;
213 function getCategoryLinks() {
214 return $this->mCategoryLinks
;
218 * Add an array of categories, with names in the keys
220 function addCategoryLinks($categories) {
221 global $wgUser, $wgContLang;
223 if ( !is_array( $categories ) ) {
226 # Add the links to the link cache in a batch
227 $arr = array( NS_CATEGORY
=> $categories );
229 $lb->setArray( $arr );
232 $sk =& $wgUser->getSkin();
233 foreach ( $categories as $category => $arbitrary ) {
234 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
235 $text = $wgContLang->convertHtml( $title->getText() );
236 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
240 function setCategoryLinks($categories) {
241 $this->mCategoryLinks
= array();
242 $this->addCategoryLinks($categories);
245 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
246 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
248 function addHTML( $text ) { $this->mBodytext
.= $text; }
249 function clearHTML() { $this->mBodytext
= ''; }
250 function getHTML() { return $this->mBodytext
; }
251 function debug( $text ) { $this->mDebugtext
.= $text; }
254 function setParserOptions( $options ) {
255 return $this->ParserOptions( $options );
258 function ParserOptions( $options = null ) {
259 return wfSetVar( $this->mParserOptions
, $options );
263 * Set the revision ID which will be seen by the wiki text parser
264 * for things such as embedded {{REVISIONID}} variable use.
265 * @param mixed $revid an integer, or NULL
266 * @return mixed previous value
268 function setRevisionId( $revid ) {
269 $val = is_null( $revid ) ?
null : intval( $revid );
270 return wfSetVar( $this->mRevisionId
, $val );
274 * Convert wikitext to HTML and add it to the buffer
275 * Default assumes that the current page title will
278 function addWikiText( $text, $linestart = true ) {
280 $this->addWikiTextTitle($text, $wgTitle, $linestart);
283 function addWikiTextWithTitle($text, &$title, $linestart = true) {
284 $this->addWikiTextTitle($text, $title, $linestart);
287 function addWikiTextTitle($text, &$title, $linestart) {
289 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
290 $linestart, true, $this->mRevisionId
);
291 $this->addParserOutput( $parserOutput );
294 function addParserOutputNoText( &$parserOutput ) {
295 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
296 $this->addCategoryLinks( $parserOutput->getCategories() );
297 $this->mNewSectionLink
= $parserOutput->getNewSection();
298 $this->addKeywords( $parserOutput );
299 if ( $parserOutput->getCacheTime() == -1 ) {
300 $this->enableClientCache( false );
302 if ( $parserOutput->mHTMLtitle
!= "" ) {
303 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
304 $this->mSubtitle
.= $parserOutput->mSubtitle
;
308 function addParserOutput( &$parserOutput ) {
309 $this->addParserOutputNoText( $parserOutput );
310 $this->addHTML( $parserOutput->getText() );
314 * Add wikitext to the buffer, assuming that this is the primary text for a page view
315 * Saves the text into the parser cache if possible
317 function addPrimaryWikiText( $text, $article, $cache = true ) {
318 global $wgParser, $wgUser;
320 $this->mParserOptions
->setTidy(true);
321 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
322 $this->mParserOptions
, true, true, $this->mRevisionId
);
323 $this->mParserOptions
->setTidy(false);
324 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
325 $parserCache =& ParserCache
::singleton();
326 $parserCache->save( $parserOutput, $article, $wgUser );
329 $this->addParserOutputNoText( $parserOutput );
330 $text = $parserOutput->getText();
331 $this->mNoGallery
= $parserOutput->getNoGallery();
332 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
333 $parserOutput->setText( $text );
334 $this->addHTML( $parserOutput->getText() );
338 * For anything that isn't primary text or interface message
340 function addSecondaryWikiText( $text, $linestart = true ) {
342 $this->mParserOptions
->setTidy(true);
343 $this->addWikiTextTitle($text, $wgTitle, $linestart);
344 $this->mParserOptions
->setTidy(false);
349 * Add the output of a QuickTemplate to the output buffer
350 * @param QuickTemplate $template
352 function addTemplate( &$template ) {
354 $template->execute();
355 $this->addHTML( ob_get_contents() );
360 * Parse wikitext and return the HTML.
362 function parse( $text, $linestart = true, $interface = false ) {
363 global $wgParser, $wgTitle;
364 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(true); }
365 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
366 $linestart, true, $this->mRevisionId
);
367 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(false); }
368 return $parserOutput->getText();
377 function tryParserCache( &$article, $user ) {
378 $parserCache =& ParserCache
::singleton();
379 $parserOutput = $parserCache->get( $article, $user );
380 if ( $parserOutput !== false ) {
381 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
382 $this->addCategoryLinks( $parserOutput->getCategories() );
383 $this->addKeywords( $parserOutput );
384 $this->mNewSectionLink
= $parserOutput->getNewSection();
385 $this->mNoGallery
= $parserOutput->getNoGallery();
386 $text = $parserOutput->getText();
387 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
388 $this->addHTML( $text );
389 $t = $parserOutput->getTitleText();
391 $this->setPageTitle( $t );
400 * Set the maximum cache time on the Squid in seconds
403 function setSquidMaxage( $maxage ) {
404 $this->mSquidMaxage
= $maxage;
408 * Use enableClientCache(false) to force it to send nocache headers
411 function enableClientCache( $state ) {
412 return wfSetVar( $this->mEnableClientCache
, $state );
415 function uncacheableBecauseRequestvars() {
417 return $wgRequest->getText('useskin', false) === false
418 && $wgRequest->getText('uselang', false) === false;
421 function sendCacheControl() {
422 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
423 $fname = 'OutputPage::sendCacheControl';
426 header("ETag: $this->mETag");
428 # don't serve compressed data to clients who can't handle it
429 # maintain different caches for logged-in users and non-logged in ones
430 header( 'Vary: Accept-Encoding, Cookie' );
431 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
432 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
433 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
436 # We'll purge the proxy cache explicitly, but require end user agents
437 # to revalidate against the proxy on each visit.
438 # Surrogate-Control controls our Squid, Cache-Control downstream caches
439 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
440 # start with a shorter timeout for initial testing
441 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
442 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
443 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
445 # We'll purge the proxy cache for anons explicitly, but require end user agents
446 # to revalidate against the proxy on each visit.
447 # IMPORTANT! The Squid needs to replace the Cache-Control header with
448 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
449 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
450 # start with a shorter timeout for initial testing
451 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
452 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
455 # We do want clients to cache if they can, but they *must* check for updates
456 # on revisiting the page.
457 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
458 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
459 header( "Cache-Control: private, must-revalidate, max-age=0" );
461 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
463 wfDebug( "$fname: no caching **\n", false );
465 # In general, the absence of a last modified header should be enough to prevent
466 # the client from using its cache. We send a few other things just to make sure.
467 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
468 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
469 header( 'Pragma: no-cache' );
474 * Finally, all the text has been munged and accumulated into
475 * the object, let's actually output it:
478 global $wgUser, $wgOutputEncoding;
479 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
480 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
482 if( $this->mDoNothing
){
485 $fname = 'OutputPage::output';
486 wfProfileIn( $fname );
487 $sk = $wgUser->getSkin();
490 $this->addScript( "<script type=\"{$wgJsMimeType}\">
491 var wgScriptPath=\"{$wgScriptPath}\";
492 var wgServer=\"{$wgServer}\";
494 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
497 if ( '' != $this->mRedirect
) {
498 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
499 # Standards require redirect URLs to be absolute
501 $this->mRedirect
= $wgServer . $this->mRedirect
;
503 if( $this->mRedirectCode
== '301') {
504 if( !$wgDebugRedirects ) {
505 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
507 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
510 $this->sendCacheControl();
512 if( $wgDebugRedirects ) {
513 $url = htmlspecialchars( $this->mRedirect
);
514 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
515 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
516 print "</body>\n</html>\n";
518 header( 'Location: '.$this->mRedirect
);
520 wfProfileOut( $fname );
523 elseif ( $this->mStatusCode
)
525 $statusMessage = array(
527 101 => 'Switching Protocols',
532 203 => 'Non-Authoritative Information',
534 205 => 'Reset Content',
535 206 => 'Partial Content',
536 207 => 'Multi-Status',
537 300 => 'Multiple Choices',
538 301 => 'Moved Permanently',
541 304 => 'Not Modified',
543 307 => 'Temporary Redirect',
544 400 => 'Bad Request',
545 401 => 'Unauthorized',
546 402 => 'Payment Required',
549 405 => 'Method Not Allowed',
550 406 => 'Not Acceptable',
551 407 => 'Proxy Authentication Required',
552 408 => 'Request Timeout',
555 411 => 'Length Required',
556 412 => 'Precondition Failed',
557 413 => 'Request Entity Too Large',
558 414 => 'Request-URI Too Large',
559 415 => 'Unsupported Media Type',
560 416 => 'Request Range Not Satisfiable',
561 417 => 'Expectation Failed',
562 422 => 'Unprocessable Entity',
564 424 => 'Failed Dependency',
565 500 => 'Internal Server Error',
566 501 => 'Not Implemented',
567 502 => 'Bad Gateway',
568 503 => 'Service Unavailable',
569 504 => 'Gateway Timeout',
570 505 => 'HTTP Version Not Supported',
571 507 => 'Insufficient Storage'
574 if ( $statusMessage[$this->mStatusCode
] )
575 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
578 # Buffer output; final headers may depend on later processing
581 # Disable temporary placeholders, so that the skin produces HTML
582 $sk->postParseLinkColour( false );
584 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
585 header( 'Content-language: '.$wgContLanguageCode );
587 if ($this->mArticleBodyOnly
) {
588 $this->out($this->mBodytext
);
590 wfProfileIn( 'Output-skin' );
591 $sk->outputPage( $this );
592 wfProfileOut( 'Output-skin' );
595 $this->sendCacheControl();
597 wfProfileOut( $fname );
600 function out( $ins ) {
601 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
602 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
605 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
606 if ( false === $outs ) { $outs = $ins; }
611 function setEncodings() {
612 global $wgInputEncoding, $wgOutputEncoding;
613 global $wgUser, $wgContLang;
615 $wgInputEncoding = strtolower( $wgInputEncoding );
617 if( $wgUser->getOption( 'altencoding' ) ) {
618 $wgContLang->setAltEncoding();
622 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
623 $wgOutputEncoding = strtolower( $wgOutputEncoding );
626 $wgOutputEncoding = $wgInputEncoding;
630 * Returns a HTML comment with the elapsed time since request.
631 * This method has no side effects.
632 * Use wfReportTime() instead.
636 function reportTime() {
637 $time = wfReportTime();
642 * Produce a "user is blocked" page
644 function blockedPage() {
645 global $wgUser, $wgContLang, $wgTitle;
647 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
648 $this->setRobotpolicy( 'noindex,nofollow' );
649 $this->setArticleRelated( false );
651 $id = $wgUser->blockedBy();
652 $reason = $wgUser->blockedFor();
655 if ( is_numeric( $id ) ) {
656 $name = User
::whoIs( $id );
660 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
662 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
664 # Don't auto-return to special pages
665 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
666 $this->returnToMain( false, $return );
670 * Note: these arguments are keys into wfMsg(), not text!
672 function showErrorPage( $title, $msg ) {
675 $this->mDebugtext
.= 'Original title: ' .
676 $wgTitle->getPrefixedText() . "\n";
677 $this->setPageTitle( wfMsg( $title ) );
678 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
679 $this->setRobotpolicy( 'noindex,nofollow' );
680 $this->setArticleRelated( false );
681 $this->enableClientCache( false );
682 $this->mRedirect
= '';
684 $this->mBodytext
= '';
685 $this->addWikiText( wfMsg( $msg ) );
686 $this->returnToMain( false );
690 function errorpage( $title, $msg ) {
691 throw new ErrorPageError( $title, $msg );
695 * Display an error page indicating that a given version of MediaWiki is
698 * @param mixed $version The version of MediaWiki needed to use the page
700 function versionRequired( $version ) {
701 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
702 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
703 $this->setRobotpolicy( 'noindex,nofollow' );
704 $this->setArticleRelated( false );
705 $this->mBodytext
= '';
707 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
708 $this->returnToMain();
712 * Display an error page noting that a given permission bit is required.
713 * This should generally replace the sysopRequired, developerRequired etc.
714 * @param string $permission key required
716 function permissionRequired( $permission ) {
719 $this->setPageTitle( wfMsg( 'badaccess' ) );
720 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
721 $this->setRobotpolicy( 'noindex,nofollow' );
722 $this->setArticleRelated( false );
723 $this->mBodytext
= '';
725 $sk = $wgUser->getSkin();
726 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
727 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
728 $this->returnToMain();
734 function sysopRequired() {
737 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
738 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
739 $this->setRobotpolicy( 'noindex,nofollow' );
740 $this->setArticleRelated( false );
741 $this->mBodytext
= '';
743 $sk = $wgUser->getSkin();
744 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
745 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
746 $this->returnToMain();
752 function developerRequired() {
755 $this->setPageTitle( wfMsg( 'developertitle' ) );
756 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
757 $this->setRobotpolicy( 'noindex,nofollow' );
758 $this->setArticleRelated( false );
759 $this->mBodytext
= '';
761 $sk = $wgUser->getSkin();
762 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
763 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
764 $this->returnToMain();
768 * Produce the stock "please login to use the wiki" page
770 function loginToUse() {
771 global $wgUser, $wgTitle, $wgContLang;
772 $skin = $wgUser->getSkin();
774 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
775 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
776 $this->setRobotPolicy( 'noindex,nofollow' );
777 $this->setArticleFlag( false );
779 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $skin->loginLink() ) );
780 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
782 $this->returnToMain( false );
786 function databaseError( $fname, $sql, $error, $errno ) {
787 throw new MWException( "OutputPage::databaseError is obsolete\n" );
790 function readOnlyPage( $source = null, $protected = false ) {
791 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
793 $this->setRobotpolicy( 'noindex,nofollow' );
794 $this->setArticleRelated( false );
797 $skin = $wgUser->getSkin();
798 $this->setPageTitle( wfMsg( 'viewsource' ) );
799 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
801 # Determine if protection is due to the page being a system message
802 # and show an appropriate explanation
803 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
&& !$wgUser->isAllowed( 'editinterface' ) ) {
804 $this->addWikiText( wfMsg( 'protectedinterface' ) );
806 $this->addWikiText( wfMsg( 'protectedtext' ) );
809 $this->setPageTitle( wfMsg( 'readonly' ) );
811 $reason = $wgReadOnly;
813 $reason = file_get_contents( $wgReadOnlyFile );
815 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
818 if( is_string( $source ) ) {
819 if( strcmp( $source, '' ) == 0 ) {
821 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
822 $source = wfMsgWeirdKey ( $wgTitle->getText() );
824 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
827 $rows = $wgUser->getIntOption( 'rows' );
828 $cols = $wgUser->getIntOption( 'cols' );
830 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
831 htmlspecialchars( $source ) . "\n</textarea>";
832 $this->addHTML( $text );
835 $this->returnToMain( false );
839 function fatalError( $message ) {
840 throw new FatalError( $message );
844 function unexpectedValueError( $name, $val ) {
845 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
849 function fileCopyError( $old, $new ) {
850 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
854 function fileRenameError( $old, $new ) {
855 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
859 function fileDeleteError( $name ) {
860 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
864 function fileNotFoundError( $name ) {
865 throw new FatalError( wfMsg( 'filenotfound', $name ) );
868 function showFatalError( $message ) {
869 $this->setPageTitle( wfMsg( "internalerror" ) );
870 $this->setRobotpolicy( "noindex,nofollow" );
871 $this->setArticleRelated( false );
872 $this->enableClientCache( false );
873 $this->mRedirect
= '';
874 $this->mBodytext
= $message;
877 function showUnexpectedValueError( $name, $val ) {
878 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
881 function showFileCopyError( $old, $new ) {
882 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
885 function showFileRenameError( $old, $new ) {
886 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
889 function showFileDeleteError( $name ) {
890 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
893 function showFileNotFoundError( $name ) {
894 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
898 * return from error messages or notes
899 * @param $auto automatically redirect the user after 10 seconds
900 * @param $returnto page title to return to. Default is Main Page.
902 function returnToMain( $auto = true, $returnto = NULL ) {
903 global $wgUser, $wgOut, $wgRequest;
905 if ( $returnto == NULL ) {
906 $returnto = $wgRequest->getText( 'returnto' );
908 $returnto = htmlspecialchars( $returnto );
910 $sk = $wgUser->getSkin();
911 if ( '' == $returnto ) {
912 $returnto = wfMsgForContent( 'mainpage' );
914 $link = $sk->makeLinkObj( Title
::newFromText( $returnto ), '' );
916 $r = wfMsg( 'returnto', $link );
918 $titleObj = Title
::newFromText( $returnto );
919 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
921 $wgOut->addHTML( "\n<p>$r</p>\n" );
925 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
926 * and uses the first 10 of them for META keywords
928 function addKeywords( &$parserOutput ) {
930 $this->addKeyword( $wgTitle->getPrefixedText() );
932 $links2d =& $parserOutput->getLinks();
933 if ( !is_array( $links2d ) ) {
936 foreach ( $links2d as $ns => $dbkeys ) {
937 foreach( $dbkeys as $dbkey => $id ) {
938 $this->addKeyword( $dbkey );
939 if ( ++
$count > 10 ) {
950 function headElement() {
951 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
952 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
954 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
955 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
960 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
962 if ( '' == $this->getHTMLTitle() ) {
963 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
966 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
967 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
968 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
969 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
971 $ret .= $this->getHeadLinks();
973 if( $this->isPrintable() ) {
976 $media = "media='print'";
978 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
979 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
981 $sk = $wgUser->getSkin();
982 $ret .= $sk->getHeadScripts();
983 $ret .= $this->mScripts
;
984 $ret .= $sk->getUserStyles();
986 if ($wgUseTrackbacks && $this->isArticleRelated())
987 $ret .= $wgTitle->trackbackRDF();
993 function getHeadLinks() {
996 foreach ( $this->mMetatags
as $tag ) {
997 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
999 $tag[0] = substr( $tag[0], 5 );
1003 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1006 $p = $this->mRobotpolicy
;
1007 if( $p !== '' && $p != 'index,follow' ) {
1008 // http://www.robotstxt.org/wc/meta-user.html
1009 // Only show if it's different from the default robots policy
1010 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1013 if ( count( $this->mKeywords
) > 0 ) {
1018 $ret .= "<meta name=\"keywords\" content=\"" .
1019 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1021 foreach ( $this->mLinktags
as $tag ) {
1023 foreach( $tag as $attr => $val ) {
1024 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1028 if( $this->isSyndicated() ) {
1029 # FIXME: centralize the mime-type and name information in Feed.php
1030 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1031 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1032 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1033 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1040 * Turn off regular page output and return an error reponse
1041 * for when rate limiting has triggered.
1045 function rateLimited() {
1048 wfHttpError( 500, 'Internal Server Error',
1049 'Sorry, the server has encountered an internal error. ' .
1050 'Please wait a moment and hit "refresh" to submit the request again.' );
1054 * Show an "add new section" link?
1056 * @return bool True if the parser output instructs us to add one
1058 function showNewSectionLink() {
1059 return $this->mNewSectionLink
;