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, $wgRequest;
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 $wgRequest->response()->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
;
318 $this->mNoGallery
= $parserOutput->getNoGallery();
319 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
322 function addParserOutput( &$parserOutput ) {
323 $this->addParserOutputNoText( $parserOutput );
324 $text = $parserOutput->getText();
325 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
326 $this->addHTML( $text );
330 * Add wikitext to the buffer, assuming that this is the primary text for a page view
331 * Saves the text into the parser cache if possible
333 function addPrimaryWikiText( $text, $article, $cache = true ) {
334 global $wgParser, $wgUser;
336 $popts = $this->parserOptions();
337 $popts->setTidy(true);
338 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
339 $popts, true, true, $this->mRevisionId
);
340 $popts->setTidy(false);
341 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
342 $parserCache =& ParserCache
::singleton();
343 $parserCache->save( $parserOutput, $article, $wgUser );
346 $this->addParserOutput( $parserOutput );
350 * For anything that isn't primary text or interface message
352 function addSecondaryWikiText( $text, $linestart = true ) {
354 $popts = $this->parserOptions();
355 $popts->setTidy(true);
356 $this->addWikiTextTitle($text, $wgTitle, $linestart);
357 $popts->setTidy(false);
362 * Add the output of a QuickTemplate to the output buffer
363 * @param QuickTemplate $template
365 function addTemplate( &$template ) {
367 $template->execute();
368 $this->addHTML( ob_get_contents() );
373 * Parse wikitext and return the HTML.
375 function parse( $text, $linestart = true, $interface = false ) {
376 global $wgParser, $wgTitle;
377 $popts = $this->parserOptions();
378 if ( $interface) { $popts->setInterfaceMessage(true); }
379 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
380 $linestart, true, $this->mRevisionId
);
381 if ( $interface) { $popts->setInterfaceMessage(false); }
382 return $parserOutput->getText();
391 function tryParserCache( &$article, $user ) {
392 $parserCache =& ParserCache
::singleton();
393 $parserOutput = $parserCache->get( $article, $user );
394 if ( $parserOutput !== false ) {
395 $this->addParserOutput( $parserOutput );
403 * Set the maximum cache time on the Squid in seconds
406 function setSquidMaxage( $maxage ) {
407 $this->mSquidMaxage
= $maxage;
411 * Use enableClientCache(false) to force it to send nocache headers
414 function enableClientCache( $state ) {
415 return wfSetVar( $this->mEnableClientCache
, $state );
418 function uncacheableBecauseRequestvars() {
420 return $wgRequest->getText('useskin', false) === false
421 && $wgRequest->getText('uselang', false) === false;
424 function sendCacheControl() {
425 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
426 $fname = 'OutputPage::sendCacheControl';
428 if ($wgUseETag && $this->mETag
)
429 $wgRequest->response()->header("ETag: $this->mETag");
431 # don't serve compressed data to clients who can't handle it
432 # maintain different caches for logged-in users and non-logged in ones
433 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
434 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
435 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
436 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
439 # We'll purge the proxy cache explicitly, but require end user agents
440 # to revalidate against the proxy on each visit.
441 # Surrogate-Control controls our Squid, Cache-Control downstream caches
442 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
443 # start with a shorter timeout for initial testing
444 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
445 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
446 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
448 # We'll purge the proxy cache for anons explicitly, but require end user agents
449 # to revalidate against the proxy on each visit.
450 # IMPORTANT! The Squid needs to replace the Cache-Control header with
451 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
452 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
453 # start with a shorter timeout for initial testing
454 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
455 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
458 # We do want clients to cache if they can, but they *must* check for updates
459 # on revisiting the page.
460 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
461 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
462 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
464 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
466 wfDebug( "$fname: no caching **\n", false );
468 # In general, the absence of a last modified header should be enough to prevent
469 # the client from using its cache. We send a few other things just to make sure.
470 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
471 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
472 $wgRequest->response()->header( 'Pragma: no-cache' );
477 * Finally, all the text has been munged and accumulated into
478 * the object, let's actually output it:
481 global $wgUser, $wgOutputEncoding, $wgRequest;
482 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
483 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgScriptPath, $wgServer;
484 global $wgStyleVersion;
486 if( $this->mDoNothing
){
489 $fname = 'OutputPage::output';
490 wfProfileIn( $fname );
491 $sk = $wgUser->getSkin();
494 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
497 if ( $wgUseAjax && $wgAjaxSearch ) {
498 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
499 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
502 if ( '' != $this->mRedirect
) {
503 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
504 # Standards require redirect URLs to be absolute
506 $this->mRedirect
= $wgServer . $this->mRedirect
;
508 if( $this->mRedirectCode
== '301') {
509 if( !$wgDebugRedirects ) {
510 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
512 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
515 $this->sendCacheControl();
517 if( $wgDebugRedirects ) {
518 $url = htmlspecialchars( $this->mRedirect
);
519 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
520 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
521 print "</body>\n</html>\n";
523 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
525 wfProfileOut( $fname );
528 elseif ( $this->mStatusCode
)
530 $statusMessage = array(
532 101 => 'Switching Protocols',
537 203 => 'Non-Authoritative Information',
539 205 => 'Reset Content',
540 206 => 'Partial Content',
541 207 => 'Multi-Status',
542 300 => 'Multiple Choices',
543 301 => 'Moved Permanently',
546 304 => 'Not Modified',
548 307 => 'Temporary Redirect',
549 400 => 'Bad Request',
550 401 => 'Unauthorized',
551 402 => 'Payment Required',
554 405 => 'Method Not Allowed',
555 406 => 'Not Acceptable',
556 407 => 'Proxy Authentication Required',
557 408 => 'Request Timeout',
560 411 => 'Length Required',
561 412 => 'Precondition Failed',
562 413 => 'Request Entity Too Large',
563 414 => 'Request-URI Too Large',
564 415 => 'Unsupported Media Type',
565 416 => 'Request Range Not Satisfiable',
566 417 => 'Expectation Failed',
567 422 => 'Unprocessable Entity',
569 424 => 'Failed Dependency',
570 500 => 'Internal Server Error',
571 501 => 'Not Implemented',
572 502 => 'Bad Gateway',
573 503 => 'Service Unavailable',
574 504 => 'Gateway Timeout',
575 505 => 'HTTP Version Not Supported',
576 507 => 'Insufficient Storage'
579 if ( $statusMessage[$this->mStatusCode
] )
580 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
583 # Buffer output; final headers may depend on later processing
586 # Disable temporary placeholders, so that the skin produces HTML
587 $sk->postParseLinkColour( false );
589 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
590 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
592 if ($this->mArticleBodyOnly
) {
593 $this->out($this->mBodytext
);
595 wfProfileIn( 'Output-skin' );
596 $sk->outputPage( $this );
597 wfProfileOut( 'Output-skin' );
600 $this->sendCacheControl();
602 wfProfileOut( $fname );
605 function out( $ins ) {
606 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
607 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
610 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
611 if ( false === $outs ) { $outs = $ins; }
616 function setEncodings() {
617 global $wgInputEncoding, $wgOutputEncoding;
618 global $wgUser, $wgContLang;
620 $wgInputEncoding = strtolower( $wgInputEncoding );
622 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
623 $wgOutputEncoding = strtolower( $wgOutputEncoding );
626 $wgOutputEncoding = $wgInputEncoding;
630 * Returns a HTML comment with the elapsed time since request.
631 * This method has no side effects.
632 * Use wfReportTime() instead.
636 function reportTime() {
637 $time = wfReportTime();
642 * Produce a "user is blocked" page
644 function blockedPage( $return = true ) {
645 global $wgUser, $wgContLang, $wgTitle;
647 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
648 $this->setRobotpolicy( 'noindex,nofollow' );
649 $this->setArticleRelated( false );
651 $id = $wgUser->blockedBy();
652 $reason = $wgUser->blockedFor();
655 if ( is_numeric( $id ) ) {
656 $name = User
::whoIs( $id );
660 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
662 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
664 # Don't auto-return to special pages
666 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
667 $this->returnToMain( false, $return );
672 * Note: these arguments are keys into wfMsg(), not text!
674 function showErrorPage( $title, $msg ) {
677 $this->mDebugtext
.= 'Original title: ' .
678 $wgTitle->getPrefixedText() . "\n";
679 $this->setPageTitle( wfMsg( $title ) );
680 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
681 $this->setRobotpolicy( 'noindex,nofollow' );
682 $this->setArticleRelated( false );
683 $this->enableClientCache( false );
684 $this->mRedirect
= '';
686 $this->mBodytext
= '';
687 $this->addWikiText( wfMsg( $msg ) );
688 $this->returnToMain( false );
692 function errorpage( $title, $msg ) {
693 throw new ErrorPageError( $title, $msg );
697 * Display an error page indicating that a given version of MediaWiki is
700 * @param mixed $version The version of MediaWiki needed to use the page
702 function versionRequired( $version ) {
703 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
704 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
705 $this->setRobotpolicy( 'noindex,nofollow' );
706 $this->setArticleRelated( false );
707 $this->mBodytext
= '';
709 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
710 $this->returnToMain();
714 * Display an error page noting that a given permission bit is required.
715 * @param string $permission key required
717 function permissionRequired( $permission ) {
718 global $wgGroupPermissions, $wgUser;
720 $this->setPageTitle( wfMsg( 'badaccess' ) );
721 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
722 $this->setRobotpolicy( 'noindex,nofollow' );
723 $this->setArticleRelated( false );
724 $this->mBodytext
= '';
727 foreach( $wgGroupPermissions as $key => $value ) {
728 if( isset( $value[$permission] ) && $value[$permission] == true ) {
729 $groupName = User
::getGroupName( $key );
730 $groupPage = User
::getGroupPage( $key );
732 $skin =& $wgUser->getSkin();
733 $groups[] = '"'.$skin->makeLinkObj( $groupPage, $groupName ).'"';
735 $groups[] = '"'.$groupName.'"';
739 $n = count( $groups );
740 $groups = implode( ', ', $groups );
745 $message = wfMsgHtml( "badaccess-group$n", $groups );
748 $message = wfMsgHtml( 'badaccess-groups', $groups );
750 $this->addHtml( $message );
751 $this->returnToMain( false );
757 function sysopRequired() {
758 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
764 function developerRequired() {
765 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
769 * Produce the stock "please login to use the wiki" page
771 function loginToUse() {
772 global $wgUser, $wgTitle, $wgContLang;
774 if( $wgUser->isLoggedIn() ) {
775 $this->permissionRequired( 'read' );
779 $skin = $wgUser->getSkin();
781 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
782 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
783 $this->setRobotPolicy( 'noindex,nofollow' );
784 $this->setArticleFlag( false );
786 $loginTitle = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
787 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
788 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
789 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
791 # Don't return to the main page if the user can't read it
792 # otherwise we'll end up in a pointless loop
793 $mainPage = Title
::newFromText( wfMsgForContent( 'mainpage' ) );
794 if( $mainPage->userCanRead() )
795 $this->returnToMain( true, $mainPage );
799 function databaseError( $fname, $sql, $error, $errno ) {
800 throw new MWException( "OutputPage::databaseError is obsolete\n" );
803 function readOnlyPage( $source = null, $protected = false ) {
804 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
806 $this->setRobotpolicy( 'noindex,nofollow' );
807 $this->setArticleRelated( false );
810 $skin = $wgUser->getSkin();
811 $this->setPageTitle( wfMsg( 'viewsource' ) );
812 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
814 # Determine if protection is due to the page being a system message
815 # and show an appropriate explanation
816 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
&& !$wgUser->isAllowed( 'editinterface' ) ) {
817 $this->addWikiText( wfMsg( 'protectedinterface' ) );
819 $this->addWikiText( wfMsg( 'protectedtext' ) );
822 $this->setPageTitle( wfMsg( 'readonly' ) );
824 $reason = $wgReadOnly;
826 $reason = file_get_contents( $wgReadOnlyFile );
828 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
831 if( is_string( $source ) ) {
832 if( strcmp( $source, '' ) == 0 ) {
834 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
835 $source = wfMsgWeirdKey ( $wgTitle->getText() );
840 $rows = $wgUser->getIntOption( 'rows' );
841 $cols = $wgUser->getIntOption( 'cols' );
843 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
844 htmlspecialchars( $source ) . "\n</textarea>";
845 $this->addHTML( $text );
848 $this->returnToMain( false );
852 function fatalError( $message ) {
853 throw new FatalError( $message );
857 function unexpectedValueError( $name, $val ) {
858 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
862 function fileCopyError( $old, $new ) {
863 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
867 function fileRenameError( $old, $new ) {
868 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
872 function fileDeleteError( $name ) {
873 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
877 function fileNotFoundError( $name ) {
878 throw new FatalError( wfMsg( 'filenotfound', $name ) );
881 function showFatalError( $message ) {
882 $this->setPageTitle( wfMsg( "internalerror" ) );
883 $this->setRobotpolicy( "noindex,nofollow" );
884 $this->setArticleRelated( false );
885 $this->enableClientCache( false );
886 $this->mRedirect
= '';
887 $this->mBodytext
= $message;
890 function showUnexpectedValueError( $name, $val ) {
891 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
894 function showFileCopyError( $old, $new ) {
895 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
898 function showFileRenameError( $old, $new ) {
899 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
902 function showFileDeleteError( $name ) {
903 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
906 function showFileNotFoundError( $name ) {
907 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
911 * return from error messages or notes
912 * @param $auto automatically redirect the user after 10 seconds
913 * @param $returnto page title to return to. Default is Main Page.
915 function returnToMain( $auto = true, $returnto = NULL ) {
916 global $wgUser, $wgOut, $wgRequest;
918 if ( $returnto == NULL ) {
919 $returnto = $wgRequest->getText( 'returnto' );
922 if ( '' === $returnto ) {
923 $returnto = wfMsgForContent( 'mainpage' );
926 if ( is_object( $returnto ) ) {
927 $titleObj = $returnto;
929 $titleObj = Title
::newFromText( $returnto );
931 if ( !is_object( $titleObj ) ) {
932 $titleObj = Title
::newMainPage();
935 $sk = $wgUser->getSkin();
936 $link = $sk->makeLinkObj( $titleObj, '' );
938 $r = wfMsg( 'returnto', $link );
940 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
942 $wgOut->addHTML( "\n<p>$r</p>\n" );
946 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
947 * and uses the first 10 of them for META keywords
949 function addKeywords( &$parserOutput ) {
951 $this->addKeyword( $wgTitle->getPrefixedText() );
953 $links2d =& $parserOutput->getLinks();
954 if ( !is_array( $links2d ) ) {
957 foreach ( $links2d as $ns => $dbkeys ) {
958 foreach( $dbkeys as $dbkey => $id ) {
959 $this->addKeyword( $dbkey );
960 if ( ++
$count > 10 ) {
971 function headElement() {
972 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
973 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
975 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
976 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
981 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
983 if ( '' == $this->getHTMLTitle() ) {
984 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
987 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
988 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
989 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
990 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
992 $ret .= $this->getHeadLinks();
994 if( $this->isPrintable() ) {
997 $media = "media='print'";
999 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1000 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1002 $sk = $wgUser->getSkin();
1003 $ret .= $sk->getHeadScripts();
1004 $ret .= $this->mScripts
;
1005 $ret .= $sk->getUserStyles();
1007 if ($wgUseTrackbacks && $this->isArticleRelated())
1008 $ret .= $wgTitle->trackbackRDF();
1010 $ret .= "</head>\n";
1014 function getHeadLinks() {
1017 foreach ( $this->mMetatags
as $tag ) {
1018 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1020 $tag[0] = substr( $tag[0], 5 );
1024 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1027 $p = $this->mRobotpolicy
;
1028 if( $p !== '' && $p != 'index,follow' ) {
1029 // http://www.robotstxt.org/wc/meta-user.html
1030 // Only show if it's different from the default robots policy
1031 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1034 if ( count( $this->mKeywords
) > 0 ) {
1039 $ret .= "<meta name=\"keywords\" content=\"" .
1040 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1042 foreach ( $this->mLinktags
as $tag ) {
1044 foreach( $tag as $attr => $val ) {
1045 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1049 if( $this->isSyndicated() ) {
1050 # FIXME: centralize the mime-type and name information in Feed.php
1051 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1052 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1053 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1054 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 1.0' href='$link' />\n";
1061 * Turn off regular page output and return an error reponse
1062 * for when rate limiting has triggered.
1066 function rateLimited() {
1069 wfHttpError( 500, 'Internal Server Error',
1070 'Sorry, the server has encountered an internal error. ' .
1071 'Please wait a moment and hit "refresh" to submit the request again.' );
1075 * Show an "add new section" link?
1077 * @return bool True if the parser output instructs us to add one
1079 function showNewSectionLink() {
1080 return $this->mNewSectionLink
;