2 if ( ! defined( 'MEDIAWIKI' ) )
13 var $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->mMetatags
= $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;
50 $this->mParserOptions
= ParserOptions
::newFromUser( $nullvalue );
51 $this->mSquidMaxage
= 0;
54 $this->mRevisionId
= null;
55 $this->mNewSectionLink
= false;
58 function redirect( $url, $responsecode = '302' ) {
59 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
60 $this->mRedirect
= str_replace( "\n", '', $url );
61 $this->mRedirectCode
= $responsecode;
64 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
66 # To add an http-equiv meta tag, precede the name with "http:"
67 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
68 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
69 function addScript( $script ) { $this->mScripts
.= $script; }
70 function getScript() { return $this->mScripts
; }
72 function setETag($tag) { $this->mETag
= $tag; }
73 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
74 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
76 function addLink( $linkarr ) {
77 # $linkarr should be an associative array of attributes. We'll escape on output.
78 array_push( $this->mLinktags
, $linkarr );
81 function addMetadataLink( $linkarr ) {
82 # note: buggy CC software only reads first "meta" link
83 static $haveMeta = false;
84 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
85 $this->addLink( $linkarr );
90 * checkLastModified tells the client to use the client-cached page if
91 * possible. If sucessful, the OutputPage is disabled so that
92 * any future call to OutputPage->output() have no effect. The method
93 * returns true iff cache-ok headers was sent.
95 function checkLastModified ( $timestamp ) {
96 global $wgCachePages, $wgCacheEpoch, $wgUser;
97 $fname = 'OutputPage::checkLastModified';
99 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
100 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
103 if( !$wgCachePages ) {
104 wfDebug( "$fname: CACHE DISABLED\n", false );
107 if( $wgUser->getOption( 'nocache' ) ) {
108 wfDebug( "$fname: USER DISABLED CACHE\n", false );
112 $timestamp=wfTimestamp(TS_MW
,$timestamp);
113 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
115 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
116 # IE sends sizes after the date like this:
117 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
118 # this breaks strtotime().
119 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
120 $modsinceTime = strtotime( $modsince );
121 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
122 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
123 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
124 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
125 # Make sure you're in a place you can leave when you call us!
126 header( "HTTP/1.0 304 Not Modified" );
127 $this->mLastModified
= $lastmod;
128 $this->sendCacheControl();
129 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
131 @ob_end_clean
(); // Don't output compressed blob
134 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
135 $this->mLastModified
= $lastmod;
138 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
139 $this->mLastModified
= $lastmod;
143 function getPageTitleActionText () {
152 // Display title is already customized
155 return wfMsg('history_short');
157 // FIXME: bug 2735; not correct for special pages etc
158 return wfMsg('preview');
160 return wfMsg('info_short');
166 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
167 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
168 function setPageTitle( $name ) {
169 global $action, $wgContLang;
170 $name = $wgContLang->convert($name, true);
171 $this->mPagetitle
= $name;
172 if(!empty($action)) {
173 $taction = $this->getPageTitleActionText();
174 if( !empty( $taction ) ) {
175 $name .= ' - '.$taction;
179 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
181 function getHTMLTitle() { return $this->mHTMLtitle
; }
182 function getPageTitle() { return $this->mPagetitle
; }
183 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
184 function getSubtitle() { return $this->mSubtitle
; }
185 function isArticle() { return $this->mIsarticle
; }
186 function setPrintable() { $this->mPrintable
= true; }
187 function isPrintable() { return $this->mPrintable
; }
188 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
189 function isSyndicated() { return $this->mShowFeedLinks
; }
190 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
191 function getOnloadHandler() { return $this->mOnloadHandler
; }
192 function disable() { $this->mDoNothing
= true; }
194 function setArticleRelated( $v ) {
195 $this->mIsArticleRelated
= $v;
197 $this->mIsarticle
= false;
200 function setArticleFlag( $v ) {
201 $this->mIsarticle
= $v;
203 $this->mIsArticleRelated
= $v;
207 function isArticleRelated() { return $this->mIsArticleRelated
; }
209 function getLanguageLinks() { return $this->mLanguageLinks
; }
210 function addLanguageLinks($newLinkArray) {
211 $this->mLanguageLinks +
= $newLinkArray;
213 function setLanguageLinks($newLinkArray) {
214 $this->mLanguageLinks
= $newLinkArray;
217 function getCategoryLinks() {
218 return $this->mCategoryLinks
;
222 * Add an array of categories, with names in the keys
224 function addCategoryLinks($categories) {
225 global $wgUser, $wgContLang;
227 if ( !is_array( $categories ) ) {
230 # Add the links to the link cache in a batch
231 $arr = array( NS_CATEGORY
=> $categories );
233 $lb->setArray( $arr );
236 $sk =& $wgUser->getSkin();
237 foreach ( $categories as $category => $arbitrary ) {
238 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
239 $text = $wgContLang->convertHtml( $title->getText() );
240 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
244 function setCategoryLinks($categories) {
245 $this->mCategoryLinks
= array();
246 $this->addCategoryLinks($categories);
249 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
250 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
252 function addHTML( $text ) { $this->mBodytext
.= $text; }
253 function clearHTML() { $this->mBodytext
= ''; }
254 function getHTML() { return $this->mBodytext
; }
255 function debug( $text ) { $this->mDebugtext
.= $text; }
258 function setParserOptions( $options ) {
259 return $this->ParserOptions( $options );
262 function ParserOptions( $options = null ) {
263 return wfSetVar( $this->mParserOptions
, $options );
267 * Set the revision ID which will be seen by the wiki text parser
268 * for things such as embedded {{REVISIONID}} variable use.
269 * @param mixed $revid an integer, or NULL
270 * @return mixed previous value
272 function setRevisionId( $revid ) {
273 $val = is_null( $revid ) ?
null : intval( $revid );
274 return wfSetVar( $this->mRevisionId
, $val );
278 * Convert wikitext to HTML and add it to the buffer
279 * Default assumes that the current page title will
282 function addWikiText( $text, $linestart = true ) {
284 $this->addWikiTextTitle($text, $wgTitle, $linestart);
287 function addWikiTextWithTitle($text, &$title, $linestart = true) {
288 $this->addWikiTextTitle($text, $title, $linestart);
291 function addWikiTextTitle($text, &$title, $linestart) {
293 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
294 $linestart, true, $this->mRevisionId
);
295 $this->addParserOutput( $parserOutput );
298 function addParserOutputNoText( &$parserOutput ) {
299 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
300 $this->addCategoryLinks( $parserOutput->getCategories() );
301 $this->mNewSectionLink
= $parserOutput->getNewSection();
302 $this->addKeywords( $parserOutput );
303 if ( $parserOutput->getCacheTime() == -1 ) {
304 $this->enableClientCache( false );
306 if ( $parserOutput->mHTMLtitle
!= "" ) {
307 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
308 $this->mSubtitle
.= $parserOutput->mSubtitle
;
312 function addParserOutput( &$parserOutput ) {
313 $this->addParserOutputNoText( $parserOutput );
314 $this->addHTML( $parserOutput->getText() );
318 * Add wikitext to the buffer, assuming that this is the primary text for a page view
319 * Saves the text into the parser cache if possible
321 function addPrimaryWikiText( $text, $article, $cache = true ) {
322 global $wgParser, $wgUser;
324 $this->mParserOptions
->setTidy(true);
325 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
326 $this->mParserOptions
, true, true, $this->mRevisionId
);
327 $this->mParserOptions
->setTidy(false);
328 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
329 $parserCache =& ParserCache
::singleton();
330 $parserCache->save( $parserOutput, $article, $wgUser );
333 $this->addParserOutputNoText( $parserOutput );
334 $text = $parserOutput->getText();
335 $this->mNoGallery
= $parserOutput->getNoGallery();
336 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
337 $parserOutput->setText( $text );
338 $this->addHTML( $parserOutput->getText() );
342 * For anything that isn't primary text or interface message
344 function addSecondaryWikiText( $text, $linestart = true ) {
346 $this->mParserOptions
->setTidy(true);
347 $this->addWikiTextTitle($text, $wgTitle, $linestart);
348 $this->mParserOptions
->setTidy(false);
353 * Add the output of a QuickTemplate to the output buffer
354 * @param QuickTemplate $template
356 function addTemplate( &$template ) {
358 $template->execute();
359 $this->addHTML( ob_get_contents() );
364 * Parse wikitext and return the HTML.
366 function parse( $text, $linestart = true, $interface = false ) {
367 global $wgParser, $wgTitle;
368 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(true); }
369 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
370 $linestart, true, $this->mRevisionId
);
371 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(false); }
372 return $parserOutput->getText();
381 function tryParserCache( &$article, $user ) {
382 $parserCache =& ParserCache
::singleton();
383 $parserOutput = $parserCache->get( $article, $user );
384 if ( $parserOutput !== false ) {
385 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
386 $this->addCategoryLinks( $parserOutput->getCategories() );
387 $this->addKeywords( $parserOutput );
388 $this->mNewSectionLink
= $parserOutput->getNewSection();
389 $this->mNoGallery
= $parserOutput->getNoGallery();
390 $text = $parserOutput->getText();
391 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
392 $this->addHTML( $text );
393 $t = $parserOutput->getTitleText();
395 $this->setPageTitle( $t );
404 * Set the maximum cache time on the Squid in seconds
407 function setSquidMaxage( $maxage ) {
408 $this->mSquidMaxage
= $maxage;
412 * Use enableClientCache(false) to force it to send nocache headers
415 function enableClientCache( $state ) {
416 return wfSetVar( $this->mEnableClientCache
, $state );
419 function uncacheableBecauseRequestvars() {
421 return $wgRequest->getText('useskin', false) === false
422 && $wgRequest->getText('uselang', false) === false;
425 function sendCacheControl() {
426 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
427 $fname = 'OutputPage::sendCacheControl';
430 header("ETag: $this->mETag");
432 # don't serve compressed data to clients who can't handle it
433 # maintain different caches for logged-in users and non-logged in ones
434 header( 'Vary: Accept-Encoding, Cookie' );
435 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
436 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
437 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
440 # We'll purge the proxy cache explicitly, but require end user agents
441 # to revalidate against the proxy on each visit.
442 # Surrogate-Control controls our Squid, Cache-Control downstream caches
443 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
444 # start with a shorter timeout for initial testing
445 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
446 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
447 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
449 # We'll purge the proxy cache for anons explicitly, but require end user agents
450 # to revalidate against the proxy on each visit.
451 # IMPORTANT! The Squid needs to replace the Cache-Control header with
452 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
453 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
454 # start with a shorter timeout for initial testing
455 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
456 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
459 # We do want clients to cache if they can, but they *must* check for updates
460 # on revisiting the page.
461 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
462 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
463 header( "Cache-Control: private, must-revalidate, max-age=0" );
465 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
467 wfDebug( "$fname: no caching **\n", false );
469 # In general, the absence of a last modified header should be enough to prevent
470 # the client from using its cache. We send a few other things just to make sure.
471 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
472 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
473 header( 'Pragma: no-cache' );
478 * Finally, all the text has been munged and accumulated into
479 * the object, let's actually output it:
482 global $wgUser, $wgOutputEncoding;
483 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
484 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
486 if( $this->mDoNothing
){
489 $fname = 'OutputPage::output';
490 wfProfileIn( $fname );
491 $sk = $wgUser->getSkin();
494 $this->addScript( "<script type=\"{$wgJsMimeType}\">
495 var wgScriptPath=\"{$wgScriptPath}\";
496 var wgServer=\"{$wgServer}\";
498 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
501 if ( '' != $this->mRedirect
) {
502 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
503 # Standards require redirect URLs to be absolute
505 $this->mRedirect
= $wgServer . $this->mRedirect
;
507 if( $this->mRedirectCode
== '301') {
508 if( !$wgDebugRedirects ) {
509 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
511 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
514 $this->sendCacheControl();
516 if( $wgDebugRedirects ) {
517 $url = htmlspecialchars( $this->mRedirect
);
518 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
519 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
520 print "</body>\n</html>\n";
522 header( 'Location: '.$this->mRedirect
);
524 wfProfileOut( $fname );
527 elseif ( $this->mStatusCode
)
529 $statusMessage = array(
531 101 => 'Switching Protocols',
536 203 => 'Non-Authoritative Information',
538 205 => 'Reset Content',
539 206 => 'Partial Content',
540 207 => 'Multi-Status',
541 300 => 'Multiple Choices',
542 301 => 'Moved Permanently',
545 304 => 'Not Modified',
547 307 => 'Temporary Redirect',
548 400 => 'Bad Request',
549 401 => 'Unauthorized',
550 402 => 'Payment Required',
553 405 => 'Method Not Allowed',
554 406 => 'Not Acceptable',
555 407 => 'Proxy Authentication Required',
556 408 => 'Request Timeout',
559 411 => 'Length Required',
560 412 => 'Precondition Failed',
561 413 => 'Request Entity Too Large',
562 414 => 'Request-URI Too Large',
563 415 => 'Unsupported Media Type',
564 416 => 'Request Range Not Satisfiable',
565 417 => 'Expectation Failed',
566 422 => 'Unprocessable Entity',
568 424 => 'Failed Dependency',
569 500 => 'Internal Server Error',
570 501 => 'Not Implemented',
571 502 => 'Bad Gateway',
572 503 => 'Service Unavailable',
573 504 => 'Gateway Timeout',
574 505 => 'HTTP Version Not Supported',
575 507 => 'Insufficient Storage'
578 if ( $statusMessage[$this->mStatusCode
] )
579 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
582 # Buffer output; final headers may depend on later processing
585 # Disable temporary placeholders, so that the skin produces HTML
586 $sk->postParseLinkColour( false );
588 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
589 header( 'Content-language: '.$wgContLanguageCode );
591 if ($this->mArticleBodyOnly
) {
592 $this->out($this->mBodytext
);
594 wfProfileIn( 'Output-skin' );
595 $sk->outputPage( $this );
596 wfProfileOut( 'Output-skin' );
599 $this->sendCacheControl();
601 wfProfileOut( $fname );
604 function out( $ins ) {
605 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
606 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
609 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
610 if ( false === $outs ) { $outs = $ins; }
615 function setEncodings() {
616 global $wgInputEncoding, $wgOutputEncoding;
617 global $wgUser, $wgContLang;
619 $wgInputEncoding = strtolower( $wgInputEncoding );
621 if( $wgUser->getOption( 'altencoding' ) ) {
622 $wgContLang->setAltEncoding();
626 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
627 $wgOutputEncoding = strtolower( $wgOutputEncoding );
630 $wgOutputEncoding = $wgInputEncoding;
634 * Returns a HTML comment with the elapsed time since request.
635 * This method has no side effects.
636 * Use wfReportTime() instead.
640 function reportTime() {
641 $time = wfReportTime();
646 * Produce a "user is blocked" page
648 function blockedPage( $return = true ) {
649 global $wgUser, $wgContLang, $wgTitle;
651 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
652 $this->setRobotpolicy( 'noindex,nofollow' );
653 $this->setArticleRelated( false );
655 $id = $wgUser->blockedBy();
656 $reason = $wgUser->blockedFor();
659 if ( is_numeric( $id ) ) {
660 $name = User
::whoIs( $id );
664 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
666 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
668 # Don't auto-return to special pages
670 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
671 $this->returnToMain( false, $return );
676 * Note: these arguments are keys into wfMsg(), not text!
678 function showErrorPage( $title, $msg ) {
681 $this->mDebugtext
.= 'Original title: ' .
682 $wgTitle->getPrefixedText() . "\n";
683 $this->setPageTitle( wfMsg( $title ) );
684 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
685 $this->setRobotpolicy( 'noindex,nofollow' );
686 $this->setArticleRelated( false );
687 $this->enableClientCache( false );
688 $this->mRedirect
= '';
690 $this->mBodytext
= '';
691 $this->addWikiText( wfMsg( $msg ) );
692 $this->returnToMain( false );
696 function errorpage( $title, $msg ) {
697 throw new ErrorPageError( $title, $msg );
701 * Display an error page indicating that a given version of MediaWiki is
704 * @param mixed $version The version of MediaWiki needed to use the page
706 function versionRequired( $version ) {
707 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
708 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
709 $this->setRobotpolicy( 'noindex,nofollow' );
710 $this->setArticleRelated( false );
711 $this->mBodytext
= '';
713 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
714 $this->returnToMain();
718 * Display an error page noting that a given permission bit is required.
719 * This should generally replace the sysopRequired, developerRequired etc.
720 * @param string $permission key required
722 function permissionRequired( $permission ) {
725 $this->setPageTitle( wfMsg( 'badaccess' ) );
726 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
727 $this->setRobotpolicy( 'noindex,nofollow' );
728 $this->setArticleRelated( false );
729 $this->mBodytext
= '';
731 $sk = $wgUser->getSkin();
732 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
733 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
734 $this->returnToMain();
740 function sysopRequired() {
743 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
744 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
745 $this->setRobotpolicy( 'noindex,nofollow' );
746 $this->setArticleRelated( false );
747 $this->mBodytext
= '';
749 $sk = $wgUser->getSkin();
750 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
751 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
752 $this->returnToMain();
758 function developerRequired() {
761 $this->setPageTitle( wfMsg( 'developertitle' ) );
762 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
763 $this->setRobotpolicy( 'noindex,nofollow' );
764 $this->setArticleRelated( false );
765 $this->mBodytext
= '';
767 $sk = $wgUser->getSkin();
768 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
769 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
770 $this->returnToMain();
774 * Produce the stock "please login to use the wiki" page
776 function loginToUse() {
777 global $wgUser, $wgTitle, $wgContLang;
778 $skin = $wgUser->getSkin();
780 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
781 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
782 $this->setRobotPolicy( 'noindex,nofollow' );
783 $this->setArticleFlag( false );
785 $loginTitle = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
786 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
787 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
788 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
790 $this->returnToMain();
794 function databaseError( $fname, $sql, $error, $errno ) {
795 throw new MWException( "OutputPage::databaseError is obsolete\n" );
798 function readOnlyPage( $source = null, $protected = false ) {
799 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
801 $this->setRobotpolicy( 'noindex,nofollow' );
802 $this->setArticleRelated( false );
805 $skin = $wgUser->getSkin();
806 $this->setPageTitle( wfMsg( 'viewsource' ) );
807 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
809 # Determine if protection is due to the page being a system message
810 # and show an appropriate explanation
811 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
&& !$wgUser->isAllowed( 'editinterface' ) ) {
812 $this->addWikiText( wfMsg( 'protectedinterface' ) );
814 $this->addWikiText( wfMsg( 'protectedtext' ) );
817 $this->setPageTitle( wfMsg( 'readonly' ) );
819 $reason = $wgReadOnly;
821 $reason = file_get_contents( $wgReadOnlyFile );
823 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
826 if( is_string( $source ) ) {
827 if( strcmp( $source, '' ) == 0 ) {
829 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
830 $source = wfMsgWeirdKey ( $wgTitle->getText() );
835 $rows = $wgUser->getIntOption( 'rows' );
836 $cols = $wgUser->getIntOption( 'cols' );
838 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
839 htmlspecialchars( $source ) . "\n</textarea>";
840 $this->addHTML( $text );
843 $this->returnToMain( false );
847 function fatalError( $message ) {
848 throw new FatalError( $message );
852 function unexpectedValueError( $name, $val ) {
853 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
857 function fileCopyError( $old, $new ) {
858 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
862 function fileRenameError( $old, $new ) {
863 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
867 function fileDeleteError( $name ) {
868 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
872 function fileNotFoundError( $name ) {
873 throw new FatalError( wfMsg( 'filenotfound', $name ) );
876 function showFatalError( $message ) {
877 $this->setPageTitle( wfMsg( "internalerror" ) );
878 $this->setRobotpolicy( "noindex,nofollow" );
879 $this->setArticleRelated( false );
880 $this->enableClientCache( false );
881 $this->mRedirect
= '';
882 $this->mBodytext
= $message;
885 function showUnexpectedValueError( $name, $val ) {
886 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
889 function showFileCopyError( $old, $new ) {
890 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
893 function showFileRenameError( $old, $new ) {
894 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
897 function showFileDeleteError( $name ) {
898 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
901 function showFileNotFoundError( $name ) {
902 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
906 * return from error messages or notes
907 * @param $auto automatically redirect the user after 10 seconds
908 * @param $returnto page title to return to. Default is Main Page.
910 function returnToMain( $auto = true, $returnto = NULL ) {
911 global $wgUser, $wgOut, $wgRequest;
913 if ( $returnto == NULL ) {
914 $returnto = $wgRequest->getText( 'returnto' );
917 if ( '' === $returnto ) {
918 $returnto = wfMsgForContent( 'mainpage' );
921 if ( is_object( $returnto ) ) {
922 $titleObj = $returnto;
924 $titleObj = Title
::newFromText( $returnto );
926 if ( !is_object( $titleObj ) ) {
927 $titleObj = Title
::newMainPage();
930 $sk = $wgUser->getSkin();
931 $link = $sk->makeLinkObj( $titleObj, '' );
933 $r = wfMsg( 'returnto', $link );
935 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
937 $wgOut->addHTML( "\n<p>$r</p>\n" );
941 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
942 * and uses the first 10 of them for META keywords
944 function addKeywords( &$parserOutput ) {
946 $this->addKeyword( $wgTitle->getPrefixedText() );
948 $links2d =& $parserOutput->getLinks();
949 if ( !is_array( $links2d ) ) {
952 foreach ( $links2d as $ns => $dbkeys ) {
953 foreach( $dbkeys as $dbkey => $id ) {
954 $this->addKeyword( $dbkey );
955 if ( ++
$count > 10 ) {
966 function headElement() {
967 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
968 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
970 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
971 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
976 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
978 if ( '' == $this->getHTMLTitle() ) {
979 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
982 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
983 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
984 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
985 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
987 $ret .= $this->getHeadLinks();
989 if( $this->isPrintable() ) {
992 $media = "media='print'";
994 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
995 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
997 $sk = $wgUser->getSkin();
998 $ret .= $sk->getHeadScripts();
999 $ret .= $this->mScripts
;
1000 $ret .= $sk->getUserStyles();
1002 if ($wgUseTrackbacks && $this->isArticleRelated())
1003 $ret .= $wgTitle->trackbackRDF();
1005 $ret .= "</head>\n";
1009 function getHeadLinks() {
1012 foreach ( $this->mMetatags
as $tag ) {
1013 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1015 $tag[0] = substr( $tag[0], 5 );
1019 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1022 $p = $this->mRobotpolicy
;
1023 if( $p !== '' && $p != 'index,follow' ) {
1024 // http://www.robotstxt.org/wc/meta-user.html
1025 // Only show if it's different from the default robots policy
1026 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1029 if ( count( $this->mKeywords
) > 0 ) {
1034 $ret .= "<meta name=\"keywords\" content=\"" .
1035 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1037 foreach ( $this->mLinktags
as $tag ) {
1039 foreach( $tag as $attr => $val ) {
1040 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1044 if( $this->isSyndicated() ) {
1045 # FIXME: centralize the mime-type and name information in Feed.php
1046 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1047 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1048 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1049 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1056 * Turn off regular page output and return an error reponse
1057 * for when rate limiting has triggered.
1061 function rateLimited() {
1064 wfHttpError( 500, 'Internal Server Error',
1065 'Sorry, the server has encountered an internal error. ' .
1066 'Please wait a moment and hit "refresh" to submit the request again.' );
1070 * Show an "add new section" link?
1072 * @return bool True if the parser output instructs us to add one
1074 function showNewSectionLink() {
1075 return $this->mNewSectionLink
;