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;
25 protected $mParserOptions; // lazy initialised, use parserOptions()
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;
49 $this->mParserOptions
= null;
50 $this->mSquidMaxage
= 0;
53 $this->mRevisionId
= null;
54 $this->mNewSectionLink
= false;
57 function redirect( $url, $responsecode = '302' ) {
58 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
59 $this->mRedirect
= str_replace( "\n", '', $url );
60 $this->mRedirectCode
= $responsecode;
63 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
65 # To add an http-equiv meta tag, precede the name with "http:"
66 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
67 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
68 function addScript( $script ) { $this->mScripts
.= $script; }
69 function getScript() { return $this->mScripts
; }
71 function setETag($tag) { $this->mETag
= $tag; }
72 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
73 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
75 function addLink( $linkarr ) {
76 # $linkarr should be an associative array of attributes. We'll escape on output.
77 array_push( $this->mLinktags
, $linkarr );
80 function addMetadataLink( $linkarr ) {
81 # note: buggy CC software only reads first "meta" link
82 static $haveMeta = false;
83 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
84 $this->addLink( $linkarr );
89 * checkLastModified tells the client to use the client-cached page if
90 * possible. If sucessful, the OutputPage is disabled so that
91 * any future call to OutputPage->output() have no effect. The method
92 * returns true iff cache-ok headers was sent.
94 function checkLastModified ( $timestamp ) {
95 global $wgCachePages, $wgCacheEpoch, $wgUser;
96 $fname = 'OutputPage::checkLastModified';
98 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
99 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
102 if( !$wgCachePages ) {
103 wfDebug( "$fname: CACHE DISABLED\n", false );
106 if( $wgUser->getOption( 'nocache' ) ) {
107 wfDebug( "$fname: USER DISABLED CACHE\n", false );
111 $timestamp=wfTimestamp(TS_MW
,$timestamp);
112 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
114 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
115 # IE sends sizes after the date like this:
116 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
117 # this breaks strtotime().
118 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
119 $modsinceTime = strtotime( $modsince );
120 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
121 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
122 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
123 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
124 # Make sure you're in a place you can leave when you call us!
125 header( "HTTP/1.0 304 Not Modified" );
126 $this->mLastModified
= $lastmod;
127 $this->sendCacheControl();
128 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
130 @ob_end_clean
(); // Don't output compressed blob
133 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
134 $this->mLastModified
= $lastmod;
137 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
138 $this->mLastModified
= $lastmod;
142 function getPageTitleActionText () {
151 // Display title is already customized
154 return wfMsg('history_short');
156 // FIXME: bug 2735; not correct for special pages etc
157 return wfMsg('preview');
159 return wfMsg('info_short');
165 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
166 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
167 function setPageTitle( $name ) {
168 global $action, $wgContLang;
169 $name = $wgContLang->convert($name, true);
170 $this->mPagetitle
= $name;
171 if(!empty($action)) {
172 $taction = $this->getPageTitleActionText();
173 if( !empty( $taction ) ) {
174 $name .= ' - '.$taction;
178 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
180 function getHTMLTitle() { return $this->mHTMLtitle
; }
181 function getPageTitle() { return $this->mPagetitle
; }
182 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
183 function getSubtitle() { return $this->mSubtitle
; }
184 function isArticle() { return $this->mIsarticle
; }
185 function setPrintable() { $this->mPrintable
= true; }
186 function isPrintable() { return $this->mPrintable
; }
187 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
188 function isSyndicated() { return $this->mShowFeedLinks
; }
189 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
190 function getOnloadHandler() { return $this->mOnloadHandler
; }
191 function disable() { $this->mDoNothing
= true; }
193 function setArticleRelated( $v ) {
194 $this->mIsArticleRelated
= $v;
196 $this->mIsarticle
= false;
199 function setArticleFlag( $v ) {
200 $this->mIsarticle
= $v;
202 $this->mIsArticleRelated
= $v;
206 function isArticleRelated() { return $this->mIsArticleRelated
; }
208 function getLanguageLinks() { return $this->mLanguageLinks
; }
209 function addLanguageLinks($newLinkArray) {
210 $this->mLanguageLinks +
= $newLinkArray;
212 function setLanguageLinks($newLinkArray) {
213 $this->mLanguageLinks
= $newLinkArray;
216 function getCategoryLinks() {
217 return $this->mCategoryLinks
;
221 * Add an array of categories, with names in the keys
223 function addCategoryLinks($categories) {
224 global $wgUser, $wgContLang;
226 if ( !is_array( $categories ) ) {
229 # Add the links to the link cache in a batch
230 $arr = array( NS_CATEGORY
=> $categories );
232 $lb->setArray( $arr );
235 $sk =& $wgUser->getSkin();
236 foreach ( $categories as $category => $arbitrary ) {
237 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
238 $text = $wgContLang->convertHtml( $title->getText() );
239 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
243 function setCategoryLinks($categories) {
244 $this->mCategoryLinks
= array();
245 $this->addCategoryLinks($categories);
248 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
249 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
251 function addHTML( $text ) { $this->mBodytext
.= $text; }
252 function clearHTML() { $this->mBodytext
= ''; }
253 function getHTML() { return $this->mBodytext
; }
254 function debug( $text ) { $this->mDebugtext
.= $text; }
257 function setParserOptions( $options ) {
258 return $this->parserOptions( $options );
261 function parserOptions( $options = null ) {
262 if ( !$this->mParserOptions
) {
263 $this->mParserOptions
= new ParserOptions
;
265 return wfSetVar( $this->mParserOptions
, $options );
269 * Set the revision ID which will be seen by the wiki text parser
270 * for things such as embedded {{REVISIONID}} variable use.
271 * @param mixed $revid an integer, or NULL
272 * @return mixed previous value
274 function setRevisionId( $revid ) {
275 $val = is_null( $revid ) ?
null : intval( $revid );
276 return wfSetVar( $this->mRevisionId
, $val );
280 * Convert wikitext to HTML and add it to the buffer
281 * Default assumes that the current page title will
284 function addWikiText( $text, $linestart = true ) {
286 $this->addWikiTextTitle($text, $wgTitle, $linestart);
289 function addWikiTextWithTitle($text, &$title, $linestart = true) {
290 $this->addWikiTextTitle($text, $title, $linestart);
293 function addWikiTextTitle($text, &$title, $linestart) {
295 $fname = 'OutputPage:addWikiTextTitle';
297 wfIncrStats('pcache_not_possible');
298 $parserOutput = $wgParser->parse( $text, $title, $this->parserOptions(),
299 $linestart, true, $this->mRevisionId
);
300 $this->addParserOutput( $parserOutput );
301 wfProfileOut($fname);
304 function addParserOutputNoText( &$parserOutput ) {
305 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
306 $this->addCategoryLinks( $parserOutput->getCategories() );
307 $this->mNewSectionLink
= $parserOutput->getNewSection();
308 $this->addKeywords( $parserOutput );
309 if ( $parserOutput->getCacheTime() == -1 ) {
310 $this->enableClientCache( false );
312 if ( $parserOutput->mHTMLtitle
!= "" ) {
313 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
315 if ( $parserOutput->mSubtitle
!= '' ) {
316 $this->mSubtitle
.= $parserOutput->mSubtitle
;
320 function addParserOutput( &$parserOutput ) {
321 $this->addParserOutputNoText( $parserOutput );
322 $this->addHTML( $parserOutput->getText() );
326 * Add wikitext to the buffer, assuming that this is the primary text for a page view
327 * Saves the text into the parser cache if possible
329 function addPrimaryWikiText( $text, $article, $cache = true ) {
330 global $wgParser, $wgUser;
332 $popts = $this->parserOptions();
333 $popts->setTidy(true);
334 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
335 $popts, true, true, $this->mRevisionId
);
336 $popts->setTidy(false);
337 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
338 $parserCache =& ParserCache
::singleton();
339 $parserCache->save( $parserOutput, $article, $wgUser );
342 $this->addParserOutputNoText( $parserOutput );
343 $text = $parserOutput->getText();
344 $this->mNoGallery
= $parserOutput->getNoGallery();
345 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
346 $parserOutput->setText( $text );
347 $this->addHTML( $parserOutput->getText() );
351 * For anything that isn't primary text or interface message
353 function addSecondaryWikiText( $text, $linestart = true ) {
355 $popts = $this->parserOptions();
356 $popts->setTidy(true);
357 $this->addWikiTextTitle($text, $wgTitle, $linestart);
358 $popts->setTidy(false);
363 * Add the output of a QuickTemplate to the output buffer
364 * @param QuickTemplate $template
366 function addTemplate( &$template ) {
368 $template->execute();
369 $this->addHTML( ob_get_contents() );
374 * Parse wikitext and return the HTML.
376 function parse( $text, $linestart = true, $interface = false ) {
377 global $wgParser, $wgTitle;
378 $popts = $this->parserOptions();
379 if ( $interface) { $popts->setInterfaceMessage(true); }
380 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
381 $linestart, true, $this->mRevisionId
);
382 if ( $interface) { $popts->setInterfaceMessage(false); }
383 return $parserOutput->getText();
392 function tryParserCache( &$article, $user ) {
393 $parserCache =& ParserCache
::singleton();
394 $parserOutput = $parserCache->get( $article, $user );
395 if ( $parserOutput !== false ) {
396 $this->addParserOutputNoText( $parserOutput );
397 $text = $parserOutput->getText();
398 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
399 $this->addHTML( $text );
407 * Set the maximum cache time on the Squid in seconds
410 function setSquidMaxage( $maxage ) {
411 $this->mSquidMaxage
= $maxage;
415 * Use enableClientCache(false) to force it to send nocache headers
418 function enableClientCache( $state ) {
419 return wfSetVar( $this->mEnableClientCache
, $state );
422 function uncacheableBecauseRequestvars() {
424 return $wgRequest->getText('useskin', false) === false
425 && $wgRequest->getText('uselang', false) === false;
428 function sendCacheControl() {
429 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
430 $fname = 'OutputPage::sendCacheControl';
433 header("ETag: $this->mETag");
435 # don't serve compressed data to clients who can't handle it
436 # maintain different caches for logged-in users and non-logged in ones
437 header( 'Vary: Accept-Encoding, Cookie' );
438 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
439 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
440 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
443 # We'll purge the proxy cache explicitly, but require end user agents
444 # to revalidate against the proxy on each visit.
445 # Surrogate-Control controls our Squid, Cache-Control downstream caches
446 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
447 # start with a shorter timeout for initial testing
448 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
449 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
450 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
452 # We'll purge the proxy cache for anons explicitly, but require end user agents
453 # to revalidate against the proxy on each visit.
454 # IMPORTANT! The Squid needs to replace the Cache-Control header with
455 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
456 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
457 # start with a shorter timeout for initial testing
458 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
459 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
462 # We do want clients to cache if they can, but they *must* check for updates
463 # on revisiting the page.
464 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
465 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
466 header( "Cache-Control: private, must-revalidate, max-age=0" );
468 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
470 wfDebug( "$fname: no caching **\n", false );
472 # In general, the absence of a last modified header should be enough to prevent
473 # the client from using its cache. We send a few other things just to make sure.
474 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
475 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
476 header( 'Pragma: no-cache' );
481 * Finally, all the text has been munged and accumulated into
482 * the object, let's actually output it:
485 global $wgUser, $wgOutputEncoding;
486 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
487 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgScriptPath, $wgServer;
489 if( $this->mDoNothing
){
492 $fname = 'OutputPage::output';
493 wfProfileIn( $fname );
494 $sk = $wgUser->getSkin();
497 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
500 if ( $wgUseAjax && $wgAjaxSearch ) {
501 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js\"></script>\n" );
502 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
505 if ( '' != $this->mRedirect
) {
506 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
507 # Standards require redirect URLs to be absolute
509 $this->mRedirect
= $wgServer . $this->mRedirect
;
511 if( $this->mRedirectCode
== '301') {
512 if( !$wgDebugRedirects ) {
513 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
515 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
518 $this->sendCacheControl();
520 if( $wgDebugRedirects ) {
521 $url = htmlspecialchars( $this->mRedirect
);
522 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
523 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
524 print "</body>\n</html>\n";
526 header( 'Location: '.$this->mRedirect
);
528 wfProfileOut( $fname );
531 elseif ( $this->mStatusCode
)
533 $statusMessage = array(
535 101 => 'Switching Protocols',
540 203 => 'Non-Authoritative Information',
542 205 => 'Reset Content',
543 206 => 'Partial Content',
544 207 => 'Multi-Status',
545 300 => 'Multiple Choices',
546 301 => 'Moved Permanently',
549 304 => 'Not Modified',
551 307 => 'Temporary Redirect',
552 400 => 'Bad Request',
553 401 => 'Unauthorized',
554 402 => 'Payment Required',
557 405 => 'Method Not Allowed',
558 406 => 'Not Acceptable',
559 407 => 'Proxy Authentication Required',
560 408 => 'Request Timeout',
563 411 => 'Length Required',
564 412 => 'Precondition Failed',
565 413 => 'Request Entity Too Large',
566 414 => 'Request-URI Too Large',
567 415 => 'Unsupported Media Type',
568 416 => 'Request Range Not Satisfiable',
569 417 => 'Expectation Failed',
570 422 => 'Unprocessable Entity',
572 424 => 'Failed Dependency',
573 500 => 'Internal Server Error',
574 501 => 'Not Implemented',
575 502 => 'Bad Gateway',
576 503 => 'Service Unavailable',
577 504 => 'Gateway Timeout',
578 505 => 'HTTP Version Not Supported',
579 507 => 'Insufficient Storage'
582 if ( $statusMessage[$this->mStatusCode
] )
583 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
586 # Buffer output; final headers may depend on later processing
589 # Disable temporary placeholders, so that the skin produces HTML
590 $sk->postParseLinkColour( false );
592 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
593 header( 'Content-language: '.$wgContLanguageCode );
595 if ($this->mArticleBodyOnly
) {
596 $this->out($this->mBodytext
);
598 wfProfileIn( 'Output-skin' );
599 $sk->outputPage( $this );
600 wfProfileOut( 'Output-skin' );
603 $this->sendCacheControl();
605 wfProfileOut( $fname );
608 function out( $ins ) {
609 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
610 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
613 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
614 if ( false === $outs ) { $outs = $ins; }
619 function setEncodings() {
620 global $wgInputEncoding, $wgOutputEncoding;
621 global $wgUser, $wgContLang;
623 $wgInputEncoding = strtolower( $wgInputEncoding );
625 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
626 $wgOutputEncoding = strtolower( $wgOutputEncoding );
629 $wgOutputEncoding = $wgInputEncoding;
633 * Returns a HTML comment with the elapsed time since request.
634 * This method has no side effects.
635 * Use wfReportTime() instead.
639 function reportTime() {
640 $time = wfReportTime();
645 * Produce a "user is blocked" page
647 function blockedPage( $return = true ) {
648 global $wgUser, $wgContLang, $wgTitle;
650 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
651 $this->setRobotpolicy( 'noindex,nofollow' );
652 $this->setArticleRelated( false );
654 $id = $wgUser->blockedBy();
655 $reason = $wgUser->blockedFor();
658 if ( is_numeric( $id ) ) {
659 $name = User
::whoIs( $id );
663 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
665 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
667 # Don't auto-return to special pages
669 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
670 $this->returnToMain( false, $return );
675 * Note: these arguments are keys into wfMsg(), not text!
677 function showErrorPage( $title, $msg ) {
680 $this->mDebugtext
.= 'Original title: ' .
681 $wgTitle->getPrefixedText() . "\n";
682 $this->setPageTitle( wfMsg( $title ) );
683 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
684 $this->setRobotpolicy( 'noindex,nofollow' );
685 $this->setArticleRelated( false );
686 $this->enableClientCache( false );
687 $this->mRedirect
= '';
689 $this->mBodytext
= '';
690 $this->addWikiText( wfMsg( $msg ) );
691 $this->returnToMain( false );
695 function errorpage( $title, $msg ) {
696 throw new ErrorPageError( $title, $msg );
700 * Display an error page indicating that a given version of MediaWiki is
703 * @param mixed $version The version of MediaWiki needed to use the page
705 function versionRequired( $version ) {
706 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
707 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
708 $this->setRobotpolicy( 'noindex,nofollow' );
709 $this->setArticleRelated( false );
710 $this->mBodytext
= '';
712 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
713 $this->returnToMain();
717 * Display an error page noting that a given permission bit is required.
718 * @param string $permission key required
720 function permissionRequired( $permission ) {
721 global $wgGroupPermissions, $wgUser;
723 $this->setPageTitle( wfMsg( 'badaccess' ) );
724 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
725 $this->setRobotpolicy( 'noindex,nofollow' );
726 $this->setArticleRelated( false );
727 $this->mBodytext
= '';
730 foreach ( $wgGroupPermissions as $key => $value ) {
731 if ( isset( $value[$permission] ) && $value[$permission] == true ) {
736 if ( $group == '' ) {
737 $message = wfMsg( 'badaccess-nogroup' );
739 $groupName = User
::getGroupName( $group );
740 $groupPage = User
::getGroupPage( $group );
742 $sk = $wgUser->getSkin();
743 $groupLink = $sk->makeLinkObj( $groupPage, $groupName );
745 $groupLink = $groupName;
747 $message = wfMsg( 'badaccess-group', $groupLink );
749 $this->addHTML( $message );
750 $this->returnToMain( false );
756 function sysopRequired() {
757 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
763 function developerRequired() {
764 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
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 $loginTitle = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
780 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
781 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
782 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
784 $this->returnToMain();
788 function databaseError( $fname, $sql, $error, $errno ) {
789 throw new MWException( "OutputPage::databaseError is obsolete\n" );
792 function readOnlyPage( $source = null, $protected = false ) {
793 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
795 $this->setRobotpolicy( 'noindex,nofollow' );
796 $this->setArticleRelated( false );
799 $skin = $wgUser->getSkin();
800 $this->setPageTitle( wfMsg( 'viewsource' ) );
801 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
803 # Determine if protection is due to the page being a system message
804 # and show an appropriate explanation
805 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
&& !$wgUser->isAllowed( 'editinterface' ) ) {
806 $this->addWikiText( wfMsg( 'protectedinterface' ) );
808 $this->addWikiText( wfMsg( 'protectedtext' ) );
811 $this->setPageTitle( wfMsg( 'readonly' ) );
813 $reason = $wgReadOnly;
815 $reason = file_get_contents( $wgReadOnlyFile );
817 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
820 if( is_string( $source ) ) {
821 if( strcmp( $source, '' ) == 0 ) {
823 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
824 $source = wfMsgWeirdKey ( $wgTitle->getText() );
829 $rows = $wgUser->getIntOption( 'rows' );
830 $cols = $wgUser->getIntOption( 'cols' );
832 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
833 htmlspecialchars( $source ) . "\n</textarea>";
834 $this->addHTML( $text );
837 $this->returnToMain( false );
841 function fatalError( $message ) {
842 throw new FatalError( $message );
846 function unexpectedValueError( $name, $val ) {
847 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
851 function fileCopyError( $old, $new ) {
852 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
856 function fileRenameError( $old, $new ) {
857 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
861 function fileDeleteError( $name ) {
862 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
866 function fileNotFoundError( $name ) {
867 throw new FatalError( wfMsg( 'filenotfound', $name ) );
870 function showFatalError( $message ) {
871 $this->setPageTitle( wfMsg( "internalerror" ) );
872 $this->setRobotpolicy( "noindex,nofollow" );
873 $this->setArticleRelated( false );
874 $this->enableClientCache( false );
875 $this->mRedirect
= '';
876 $this->mBodytext
= $message;
879 function showUnexpectedValueError( $name, $val ) {
880 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
883 function showFileCopyError( $old, $new ) {
884 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
887 function showFileRenameError( $old, $new ) {
888 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
891 function showFileDeleteError( $name ) {
892 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
895 function showFileNotFoundError( $name ) {
896 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
900 * return from error messages or notes
901 * @param $auto automatically redirect the user after 10 seconds
902 * @param $returnto page title to return to. Default is Main Page.
904 function returnToMain( $auto = true, $returnto = NULL ) {
905 global $wgUser, $wgOut, $wgRequest;
907 if ( $returnto == NULL ) {
908 $returnto = $wgRequest->getText( 'returnto' );
911 if ( '' === $returnto ) {
912 $returnto = wfMsgForContent( 'mainpage' );
915 if ( is_object( $returnto ) ) {
916 $titleObj = $returnto;
918 $titleObj = Title
::newFromText( $returnto );
920 if ( !is_object( $titleObj ) ) {
921 $titleObj = Title
::newMainPage();
924 $sk = $wgUser->getSkin();
925 $link = $sk->makeLinkObj( $titleObj, '' );
927 $r = wfMsg( 'returnto', $link );
929 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
931 $wgOut->addHTML( "\n<p>$r</p>\n" );
935 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
936 * and uses the first 10 of them for META keywords
938 function addKeywords( &$parserOutput ) {
940 $this->addKeyword( $wgTitle->getPrefixedText() );
942 $links2d =& $parserOutput->getLinks();
943 if ( !is_array( $links2d ) ) {
946 foreach ( $links2d as $ns => $dbkeys ) {
947 foreach( $dbkeys as $dbkey => $id ) {
948 $this->addKeyword( $dbkey );
949 if ( ++
$count > 10 ) {
960 function headElement() {
961 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
962 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
964 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
965 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
970 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
972 if ( '' == $this->getHTMLTitle() ) {
973 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
976 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
977 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
978 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
979 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
981 $ret .= $this->getHeadLinks();
983 if( $this->isPrintable() ) {
986 $media = "media='print'";
988 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
989 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
991 $sk = $wgUser->getSkin();
992 $ret .= $sk->getHeadScripts();
993 $ret .= $this->mScripts
;
994 $ret .= $sk->getUserStyles();
996 if ($wgUseTrackbacks && $this->isArticleRelated())
997 $ret .= $wgTitle->trackbackRDF();
1003 function getHeadLinks() {
1006 foreach ( $this->mMetatags
as $tag ) {
1007 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1009 $tag[0] = substr( $tag[0], 5 );
1013 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1016 $p = $this->mRobotpolicy
;
1017 if( $p !== '' && $p != 'index,follow' ) {
1018 // http://www.robotstxt.org/wc/meta-user.html
1019 // Only show if it's different from the default robots policy
1020 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1023 if ( count( $this->mKeywords
) > 0 ) {
1028 $ret .= "<meta name=\"keywords\" content=\"" .
1029 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1031 foreach ( $this->mLinktags
as $tag ) {
1033 foreach( $tag as $attr => $val ) {
1034 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1038 if( $this->isSyndicated() ) {
1039 # FIXME: centralize the mime-type and name information in Feed.php
1040 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1041 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1042 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1043 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1050 * Turn off regular page output and return an error reponse
1051 * for when rate limiting has triggered.
1055 function rateLimited() {
1058 wfHttpError( 500, 'Internal Server Error',
1059 'Sorry, the server has encountered an internal error. ' .
1060 'Please wait a moment and hit "refresh" to submit the request again.' );
1064 * Show an "add new section" link?
1066 * @return bool True if the parser output instructs us to add one
1068 function showNewSectionLink() {
1069 return $this->mNewSectionLink
;