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;
34 * Initialise private variables
36 function OutputPage() {
37 $this->mHeaders
= $this->mMetatags
=
38 $this->mKeywords
= $this->mLinktags
= array();
39 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
40 $this->mRedirect
= $this->mLastModified
=
41 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
42 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
43 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
44 $this->mSuppressQuickbar
= $this->mPrintable
= false;
45 $this->mLanguageLinks
= array();
46 $this->mCategoryLinks
= array();
47 $this->mDoNothing
= false;
48 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
49 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
50 $this->mSquidMaxage
= 0;
53 $this->mRevisionId
= null;
54 $this->mNewSectionLink
= false;
57 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ); }
58 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
59 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
61 # To add an http-equiv meta tag, precede the name with "http:"
62 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
63 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
64 function addScript( $script ) { $this->mScripts
.= $script; }
65 function getScript() { return $this->mScripts
; }
67 function setETag($tag) { $this->mETag
= $tag; }
68 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
69 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
71 function addLink( $linkarr ) {
72 # $linkarr should be an associative array of attributes. We'll escape on output.
73 array_push( $this->mLinktags
, $linkarr );
76 function addMetadataLink( $linkarr ) {
77 # note: buggy CC software only reads first "meta" link
78 static $haveMeta = false;
79 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
80 $this->addLink( $linkarr );
85 * checkLastModified tells the client to use the client-cached page if
86 * possible. If sucessful, the OutputPage is disabled so that
87 * any future call to OutputPage->output() have no effect. The method
88 * returns true iff cache-ok headers was sent.
90 function checkLastModified ( $timestamp ) {
91 global $wgCachePages, $wgCacheEpoch, $wgUser;
92 $fname = 'OutputPage::checkLastModified';
94 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
95 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
98 if( !$wgCachePages ) {
99 wfDebug( "$fname: CACHE DISABLED\n", false );
102 if( $wgUser->getOption( 'nocache' ) ) {
103 wfDebug( "$fname: USER DISABLED CACHE\n", false );
107 $timestamp=wfTimestamp(TS_MW
,$timestamp);
108 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
110 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
111 # IE sends sizes after the date like this:
112 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
113 # this breaks strtotime().
114 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
115 $modsinceTime = strtotime( $modsince );
116 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
117 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
118 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
119 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
120 # Make sure you're in a place you can leave when you call us!
121 header( "HTTP/1.0 304 Not Modified" );
122 $this->mLastModified
= $lastmod;
123 $this->sendCacheControl();
124 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
126 @ob_end_clean
(); // Don't output compressed blob
129 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
130 $this->mLastModified
= $lastmod;
133 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
134 $this->mLastModified
= $lastmod;
138 function getPageTitleActionText () {
147 // Display title is already customized
150 return wfMsg('history_short');
152 // FIXME: bug 2735; not correct for special pages etc
153 return wfMsg('preview');
155 return wfMsg('info_short');
161 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
162 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
163 function setPageTitle( $name ) {
164 global $action, $wgContLang;
165 $name = $wgContLang->convert($name, true);
166 $this->mPagetitle
= $name;
167 if(!empty($action)) {
168 $taction = $this->getPageTitleActionText();
169 if( !empty( $taction ) ) {
170 $name .= ' - '.$taction;
174 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
176 function getHTMLTitle() { return $this->mHTMLtitle
; }
177 function getPageTitle() { return $this->mPagetitle
; }
178 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
179 function getSubtitle() { return $this->mSubtitle
; }
180 function isArticle() { return $this->mIsarticle
; }
181 function setPrintable() { $this->mPrintable
= true; }
182 function isPrintable() { return $this->mPrintable
; }
183 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
184 function isSyndicated() { return $this->mShowFeedLinks
; }
185 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
186 function getOnloadHandler() { return $this->mOnloadHandler
; }
187 function disable() { $this->mDoNothing
= true; }
189 function setArticleRelated( $v ) {
190 $this->mIsArticleRelated
= $v;
192 $this->mIsarticle
= false;
195 function setArticleFlag( $v ) {
196 $this->mIsarticle
= $v;
198 $this->mIsArticleRelated
= $v;
202 function isArticleRelated() { return $this->mIsArticleRelated
; }
204 function getLanguageLinks() { return $this->mLanguageLinks
; }
205 function addLanguageLinks($newLinkArray) {
206 $this->mLanguageLinks +
= $newLinkArray;
208 function setLanguageLinks($newLinkArray) {
209 $this->mLanguageLinks
= $newLinkArray;
212 function getCategoryLinks() {
213 return $this->mCategoryLinks
;
217 * Add an array of categories, with names in the keys
219 function addCategoryLinks($categories) {
220 global $wgUser, $wgContLang;
222 if ( !is_array( $categories ) ) {
225 # Add the links to the link cache in a batch
226 $arr = array( NS_CATEGORY
=> $categories );
228 $lb->setArray( $arr );
231 $sk =& $wgUser->getSkin();
232 foreach ( $categories as $category => $arbitrary ) {
233 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
234 $text = $wgContLang->convertHtml( $title->getText() );
235 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
239 function setCategoryLinks($categories) {
240 $this->mCategoryLinks
= array();
241 $this->addCategoryLinks($categories);
244 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
245 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
247 function addHTML( $text ) { $this->mBodytext
.= $text; }
248 function clearHTML() { $this->mBodytext
= ''; }
249 function getHTML() { return $this->mBodytext
; }
250 function debug( $text ) { $this->mDebugtext
.= $text; }
253 function setParserOptions( $options ) {
254 return $this->ParserOptions( $options );
257 function ParserOptions( $options = null ) {
258 return wfSetVar( $this->mParserOptions
, $options );
262 * Set the revision ID which will be seen by the wiki text parser
263 * for things such as embedded {{REVISIONID}} variable use.
264 * @param mixed $revid an integer, or NULL
265 * @return mixed previous value
267 function setRevisionId( $revid ) {
268 $val = is_null( $revid ) ?
null : intval( $revid );
269 return wfSetVar( $this->mRevisionId
, $val );
273 * Convert wikitext to HTML and add it to the buffer
274 * Default assumes that the current page title will
277 function addWikiText( $text, $linestart = true ) {
279 $this->addWikiTextTitle($text, $wgTitle, $linestart);
282 function addWikiTextWithTitle($text, &$title, $linestart = true) {
283 $this->addWikiTextTitle($text, $title, $linestart);
286 function addWikiTextTitle($text, &$title, $linestart) {
288 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
289 $linestart, true, $this->mRevisionId
);
290 $this->addParserOutput( $parserOutput );
293 function addParserOutputNoText( &$parserOutput ) {
294 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
295 $this->addCategoryLinks( $parserOutput->getCategories() );
296 $this->mNewSectionLink
= $parserOutput->getNewSection();
297 $this->addKeywords( $parserOutput );
298 if ( $parserOutput->getCacheTime() == -1 ) {
299 $this->enableClientCache( false );
301 if ( $parserOutput->mHTMLtitle
!= "" ) {
302 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
303 $this->mSubtitle
.= $parserOutput->mSubtitle
;
307 function addParserOutput( &$parserOutput ) {
308 $this->addParserOutputNoText( $parserOutput );
309 $this->addHTML( $parserOutput->getText() );
313 * Add wikitext to the buffer, assuming that this is the primary text for a page view
314 * Saves the text into the parser cache if possible
316 function addPrimaryWikiText( $text, $article, $cache = true ) {
317 global $wgParser, $wgUser;
319 $this->mParserOptions
->setTidy(true);
320 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
321 $this->mParserOptions
, true, true, $this->mRevisionId
);
322 $this->mParserOptions
->setTidy(false);
323 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
324 $parserCache =& ParserCache
::singleton();
325 $parserCache->save( $parserOutput, $article, $wgUser );
328 $this->addParserOutputNoText( $parserOutput );
329 $text = $parserOutput->getText();
330 $this->mNoGallery
= $parserOutput->getNoGallery();
331 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
332 $parserOutput->setText( $text );
333 $this->addHTML( $parserOutput->getText() );
337 * For anything that isn't primary text or interface message
339 function addSecondaryWikiText( $text, $linestart = true ) {
341 $this->mParserOptions
->setTidy(true);
342 $this->addWikiTextTitle($text, $wgTitle, $linestart);
343 $this->mParserOptions
->setTidy(false);
348 * Add the output of a QuickTemplate to the output buffer
349 * @param QuickTemplate $template
351 function addTemplate( &$template ) {
353 $template->execute();
354 $this->addHTML( ob_get_contents() );
359 * Parse wikitext and return the HTML.
361 function parse( $text, $linestart = true, $interface = false ) {
362 global $wgParser, $wgTitle;
363 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(true); }
364 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
365 $linestart, true, $this->mRevisionId
);
366 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(false); }
367 return $parserOutput->getText();
376 function tryParserCache( &$article, $user ) {
377 $parserCache =& ParserCache
::singleton();
378 $parserOutput = $parserCache->get( $article, $user );
379 if ( $parserOutput !== false ) {
380 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
381 $this->addCategoryLinks( $parserOutput->getCategories() );
382 $this->addKeywords( $parserOutput );
383 $this->mNewSectionLink
= $parserOutput->getNewSection();
384 $this->mNoGallery
= $parserOutput->getNoGallery();
385 $text = $parserOutput->getText();
386 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
387 $this->addHTML( $text );
388 $t = $parserOutput->getTitleText();
390 $this->setPageTitle( $t );
399 * Set the maximum cache time on the Squid in seconds
402 function setSquidMaxage( $maxage ) {
403 $this->mSquidMaxage
= $maxage;
407 * Use enableClientCache(false) to force it to send nocache headers
410 function enableClientCache( $state ) {
411 return wfSetVar( $this->mEnableClientCache
, $state );
414 function uncacheableBecauseRequestvars() {
416 return $wgRequest->getText('useskin', false) === false
417 && $wgRequest->getText('uselang', false) === false;
420 function sendCacheControl() {
421 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
422 $fname = 'OutputPage::sendCacheControl';
425 header("ETag: $this->mETag");
427 # don't serve compressed data to clients who can't handle it
428 # maintain different caches for logged-in users and non-logged in ones
429 header( 'Vary: Accept-Encoding, Cookie' );
430 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
431 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
432 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
435 # We'll purge the proxy cache explicitly, but require end user agents
436 # to revalidate against the proxy on each visit.
437 # Surrogate-Control controls our Squid, Cache-Control downstream caches
438 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
439 # start with a shorter timeout for initial testing
440 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
441 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
442 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
444 # We'll purge the proxy cache for anons explicitly, but require end user agents
445 # to revalidate against the proxy on each visit.
446 # IMPORTANT! The Squid needs to replace the Cache-Control header with
447 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
448 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
449 # start with a shorter timeout for initial testing
450 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
451 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
454 # We do want clients to cache if they can, but they *must* check for updates
455 # on revisiting the page.
456 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
457 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
458 header( "Cache-Control: private, must-revalidate, max-age=0" );
460 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
462 wfDebug( "$fname: no caching **\n", false );
464 # In general, the absence of a last modified header should be enough to prevent
465 # the client from using its cache. We send a few other things just to make sure.
466 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
467 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
468 header( 'Pragma: no-cache' );
473 * Finally, all the text has been munged and accumulated into
474 * the object, let's actually output it:
477 global $wgUser, $wgOutputEncoding;
478 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
479 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
481 if( $this->mDoNothing
){
484 $fname = 'OutputPage::output';
485 wfProfileIn( $fname );
486 $sk = $wgUser->getSkin();
489 $this->addScript( "<script type=\"{$wgJsMimeType}\">
490 var wgScriptPath=\"{$wgScriptPath}\";
491 var wgServer=\"{$wgServer}\";
493 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
496 if ( '' != $this->mRedirect
) {
497 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
498 # Standards require redirect URLs to be absolute
500 $this->mRedirect
= $wgServer . $this->mRedirect
;
502 if( $this->mRedirectCode
== '301') {
503 if( !$wgDebugRedirects ) {
504 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
506 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
509 $this->sendCacheControl();
511 if( $wgDebugRedirects ) {
512 $url = htmlspecialchars( $this->mRedirect
);
513 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
514 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
515 print "</body>\n</html>\n";
517 header( 'Location: '.$this->mRedirect
);
519 wfProfileOut( $fname );
522 elseif ( $this->mStatusCode
)
524 $statusMessage = array(
526 101 => 'Switching Protocols',
531 203 => 'Non-Authoritative Information',
533 205 => 'Reset Content',
534 206 => 'Partial Content',
535 207 => 'Multi-Status',
536 300 => 'Multiple Choices',
537 301 => 'Moved Permanently',
540 304 => 'Not Modified',
542 307 => 'Temporary Redirect',
543 400 => 'Bad Request',
544 401 => 'Unauthorized',
545 402 => 'Payment Required',
548 405 => 'Method Not Allowed',
549 406 => 'Not Acceptable',
550 407 => 'Proxy Authentication Required',
551 408 => 'Request Timeout',
554 411 => 'Length Required',
555 412 => 'Precondition Failed',
556 413 => 'Request Entity Too Large',
557 414 => 'Request-URI Too Large',
558 415 => 'Unsupported Media Type',
559 416 => 'Request Range Not Satisfiable',
560 417 => 'Expectation Failed',
561 422 => 'Unprocessable Entity',
563 424 => 'Failed Dependency',
564 500 => 'Internal Server Error',
565 501 => 'Not Implemented',
566 502 => 'Bad Gateway',
567 503 => 'Service Unavailable',
568 504 => 'Gateway Timeout',
569 505 => 'HTTP Version Not Supported',
570 507 => 'Insufficient Storage'
573 if ( $statusMessage[$this->mStatusCode
] )
574 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
577 # Buffer output; final headers may depend on later processing
580 # Disable temporary placeholders, so that the skin produces HTML
581 $sk->postParseLinkColour( false );
583 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
584 header( 'Content-language: '.$wgContLanguageCode );
586 if ($this->mArticleBodyOnly
) {
587 $this->out($this->mBodytext
);
589 wfProfileIn( 'Output-skin' );
590 $sk->outputPage( $this );
591 wfProfileOut( 'Output-skin' );
594 $this->sendCacheControl();
596 wfProfileOut( $fname );
599 function out( $ins ) {
600 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
601 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
604 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
605 if ( false === $outs ) { $outs = $ins; }
610 function setEncodings() {
611 global $wgInputEncoding, $wgOutputEncoding;
612 global $wgUser, $wgContLang;
614 $wgInputEncoding = strtolower( $wgInputEncoding );
616 if( $wgUser->getOption( 'altencoding' ) ) {
617 $wgContLang->setAltEncoding();
621 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
622 $wgOutputEncoding = strtolower( $wgOutputEncoding );
625 $wgOutputEncoding = $wgInputEncoding;
629 * Returns a HTML comment with the elapsed time since request.
630 * This method has no side effects.
631 * Use wfReportTime() instead.
635 function reportTime() {
636 $time = wfReportTime();
641 * Produce a "user is blocked" page
643 function blockedPage() {
644 global $wgUser, $wgContLang, $wgTitle;
646 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
647 $this->setRobotpolicy( 'noindex,nofollow' );
648 $this->setArticleRelated( false );
650 $id = $wgUser->blockedBy();
651 $reason = $wgUser->blockedFor();
654 if ( is_numeric( $id ) ) {
655 $name = User
::whoIs( $id );
659 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
661 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
663 # Don't auto-return to special pages
664 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
665 $this->returnToMain( false, $return );
669 * Note: these arguments are keys into wfMsg(), not text!
671 function showErrorPage( $title, $msg ) {
674 $this->mDebugtext
.= 'Original title: ' .
675 $wgTitle->getPrefixedText() . "\n";
676 $this->setPageTitle( wfMsg( $title ) );
677 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
678 $this->setRobotpolicy( 'noindex,nofollow' );
679 $this->setArticleRelated( false );
680 $this->enableClientCache( false );
681 $this->mRedirect
= '';
683 $this->mBodytext
= '';
684 $this->addWikiText( wfMsg( $msg ) );
685 $this->returnToMain( false );
689 function errorpage( $title, $msg ) {
690 throw new ErrorPageError( $title, $msg );
694 * Display an error page indicating that a given version of MediaWiki is
697 * @param mixed $version The version of MediaWiki needed to use the page
699 function versionRequired( $version ) {
700 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
701 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
702 $this->setRobotpolicy( 'noindex,nofollow' );
703 $this->setArticleRelated( false );
704 $this->mBodytext
= '';
706 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
707 $this->returnToMain();
711 * Display an error page noting that a given permission bit is required.
712 * This should generally replace the sysopRequired, developerRequired etc.
713 * @param string $permission key required
715 function permissionRequired( $permission ) {
718 $this->setPageTitle( wfMsg( 'badaccess' ) );
719 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
720 $this->setRobotpolicy( 'noindex,nofollow' );
721 $this->setArticleRelated( false );
722 $this->mBodytext
= '';
724 $sk = $wgUser->getSkin();
725 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
726 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
727 $this->returnToMain();
733 function sysopRequired() {
736 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
737 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
738 $this->setRobotpolicy( 'noindex,nofollow' );
739 $this->setArticleRelated( false );
740 $this->mBodytext
= '';
742 $sk = $wgUser->getSkin();
743 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
744 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
745 $this->returnToMain();
751 function developerRequired() {
754 $this->setPageTitle( wfMsg( 'developertitle' ) );
755 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
756 $this->setRobotpolicy( 'noindex,nofollow' );
757 $this->setArticleRelated( false );
758 $this->mBodytext
= '';
760 $sk = $wgUser->getSkin();
761 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
762 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
763 $this->returnToMain();
767 * Produce the stock "please login to use the wiki" page
769 function loginToUse() {
770 global $wgUser, $wgTitle, $wgContLang;
771 $skin = $wgUser->getSkin();
773 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
774 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
775 $this->setRobotPolicy( 'noindex,nofollow' );
776 $this->setArticleFlag( false );
778 $loginTitle = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
779 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
780 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
781 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
783 $this->returnToMain();
787 function databaseError( $fname, $sql, $error, $errno ) {
788 throw new MWException( "OutputPage::databaseError is obsolete\n" );
791 function readOnlyPage( $source = null, $protected = false ) {
792 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
794 $this->setRobotpolicy( 'noindex,nofollow' );
795 $this->setArticleRelated( false );
798 $skin = $wgUser->getSkin();
799 $this->setPageTitle( wfMsg( 'viewsource' ) );
800 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
802 # Determine if protection is due to the page being a system message
803 # and show an appropriate explanation
804 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
&& !$wgUser->isAllowed( 'editinterface' ) ) {
805 $this->addWikiText( wfMsg( 'protectedinterface' ) );
807 $this->addWikiText( wfMsg( 'protectedtext' ) );
810 $this->setPageTitle( wfMsg( 'readonly' ) );
812 $reason = $wgReadOnly;
814 $reason = file_get_contents( $wgReadOnlyFile );
816 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
819 if( is_string( $source ) ) {
820 if( strcmp( $source, '' ) == 0 ) {
822 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
823 $source = wfMsgWeirdKey ( $wgTitle->getText() );
825 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
828 $rows = $wgUser->getIntOption( 'rows' );
829 $cols = $wgUser->getIntOption( 'cols' );
831 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
832 htmlspecialchars( $source ) . "\n</textarea>";
833 $this->addHTML( $text );
836 $this->returnToMain( false );
840 function fatalError( $message ) {
841 throw new FatalError( $message );
845 function unexpectedValueError( $name, $val ) {
846 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
850 function fileCopyError( $old, $new ) {
851 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
855 function fileRenameError( $old, $new ) {
856 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
860 function fileDeleteError( $name ) {
861 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
865 function fileNotFoundError( $name ) {
866 throw new FatalError( wfMsg( 'filenotfound', $name ) );
869 function showFatalError( $message ) {
870 $this->setPageTitle( wfMsg( "internalerror" ) );
871 $this->setRobotpolicy( "noindex,nofollow" );
872 $this->setArticleRelated( false );
873 $this->enableClientCache( false );
874 $this->mRedirect
= '';
875 $this->mBodytext
= $message;
878 function showUnexpectedValueError( $name, $val ) {
879 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
882 function showFileCopyError( $old, $new ) {
883 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
886 function showFileRenameError( $old, $new ) {
887 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
890 function showFileDeleteError( $name ) {
891 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
894 function showFileNotFoundError( $name ) {
895 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
899 * return from error messages or notes
900 * @param $auto automatically redirect the user after 10 seconds
901 * @param $returnto page title to return to. Default is Main Page.
903 function returnToMain( $auto = true, $returnto = NULL ) {
904 global $wgUser, $wgOut, $wgRequest;
906 if ( $returnto == NULL ) {
907 $returnto = $wgRequest->getText( 'returnto' );
909 $returnto = htmlspecialchars( $returnto );
911 $sk = $wgUser->getSkin();
912 if ( '' == $returnto ) {
913 $returnto = wfMsgForContent( 'mainpage' );
915 $link = $sk->makeLinkObj( Title
::newFromText( $returnto ), '' );
917 $r = wfMsg( 'returnto', $link );
919 $titleObj = Title
::newFromText( $returnto );
920 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
922 $wgOut->addHTML( "\n<p>$r</p>\n" );
926 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
927 * and uses the first 10 of them for META keywords
929 function addKeywords( &$parserOutput ) {
931 $this->addKeyword( $wgTitle->getPrefixedText() );
933 $links2d =& $parserOutput->getLinks();
934 if ( !is_array( $links2d ) ) {
937 foreach ( $links2d as $ns => $dbkeys ) {
938 foreach( $dbkeys as $dbkey => $id ) {
939 $this->addKeyword( $dbkey );
940 if ( ++
$count > 10 ) {
951 function headElement() {
952 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
953 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
955 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
956 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
961 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
963 if ( '' == $this->getHTMLTitle() ) {
964 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
967 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
968 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
969 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
970 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
972 $ret .= $this->getHeadLinks();
974 if( $this->isPrintable() ) {
977 $media = "media='print'";
979 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
980 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
982 $sk = $wgUser->getSkin();
983 $ret .= $sk->getHeadScripts();
984 $ret .= $this->mScripts
;
985 $ret .= $sk->getUserStyles();
987 if ($wgUseTrackbacks && $this->isArticleRelated())
988 $ret .= $wgTitle->trackbackRDF();
994 function getHeadLinks() {
997 foreach ( $this->mMetatags
as $tag ) {
998 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1000 $tag[0] = substr( $tag[0], 5 );
1004 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1007 $p = $this->mRobotpolicy
;
1008 if( $p !== '' && $p != 'index,follow' ) {
1009 // http://www.robotstxt.org/wc/meta-user.html
1010 // Only show if it's different from the default robots policy
1011 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1014 if ( count( $this->mKeywords
) > 0 ) {
1019 $ret .= "<meta name=\"keywords\" content=\"" .
1020 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1022 foreach ( $this->mLinktags
as $tag ) {
1024 foreach( $tag as $attr => $val ) {
1025 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1029 if( $this->isSyndicated() ) {
1030 # FIXME: centralize the mime-type and name information in Feed.php
1031 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1032 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1033 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1034 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1041 * Turn off regular page output and return an error reponse
1042 * for when rate limiting has triggered.
1046 function rateLimited() {
1049 wfHttpError( 500, 'Internal Server Error',
1050 'Sorry, the server has encountered an internal error. ' .
1051 'Please wait a moment and hit "refresh" to submit the request again.' );
1055 * Show an "add new section" link?
1057 * @return bool True if the parser output instructs us to add one
1059 function showNewSectionLink() {
1060 return $this->mNewSectionLink
;