2 if ( ! defined( 'MEDIAWIKI' ) )
13 var $mHeaders, $mMetatags, $mKeywords;
14 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
15 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
16 var $mSubtitle, $mRedirect, $mStatusCode;
17 var $mLastModified, $mETag, $mCategoryLinks;
18 var $mScripts, $mLinkColours, $mPageLinkTitle;
20 var $mSuppressQuickbar;
23 var $mContainsOldMagic, $mContainsNewMagic;
24 var $mIsArticleRelated;
26 var $mShowFeedLinks = false;
27 var $mEnableClientCache = true;
28 var $mArticleBodyOnly = false;
30 var $mNewSectionLink = false;
34 * Initialise private variables
36 function OutputPage() {
37 $this->mHeaders
= $this->mMetatags
=
38 $this->mKeywords
= $this->mLinktags
= array();
39 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
40 $this->mRedirect
= $this->mLastModified
=
41 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
42 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
43 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
44 $this->mSuppressQuickbar
= $this->mPrintable
= false;
45 $this->mLanguageLinks
= array();
46 $this->mCategoryLinks
= array();
47 $this->mDoNothing
= false;
48 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
49 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
50 $this->mSquidMaxage
= 0;
53 $this->mRevisionId
= null;
54 $this->mNewSectionLink
= false;
57 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ); }
58 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
59 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
61 # To add an http-equiv meta tag, precede the name with "http:"
62 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
63 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
64 function addScript( $script ) { $this->mScripts
.= $script; }
65 function getScript() { return $this->mScripts
; }
67 function setETag($tag) { $this->mETag
= $tag; }
68 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
69 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
71 function addLink( $linkarr ) {
72 # $linkarr should be an associative array of attributes. We'll escape on output.
73 array_push( $this->mLinktags
, $linkarr );
76 function addMetadataLink( $linkarr ) {
77 # note: buggy CC software only reads first "meta" link
78 static $haveMeta = false;
79 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
80 $this->addLink( $linkarr );
85 * checkLastModified tells the client to use the client-cached page if
86 * possible. If sucessful, the OutputPage is disabled so that
87 * any future call to OutputPage->output() have no effect. The method
88 * returns true iff cache-ok headers was sent.
90 function checkLastModified ( $timestamp ) {
91 global $wgCachePages, $wgCacheEpoch, $wgUser;
92 $fname = 'OutputPage::checkLastModified';
94 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
95 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
98 if( !$wgCachePages ) {
99 wfDebug( "$fname: CACHE DISABLED\n", false );
102 if( $wgUser->getOption( 'nocache' ) ) {
103 wfDebug( "$fname: USER DISABLED CACHE\n", false );
107 $timestamp=wfTimestamp(TS_MW
,$timestamp);
108 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
110 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
111 # IE sends sizes after the date like this:
112 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
113 # this breaks strtotime().
114 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
115 $modsinceTime = strtotime( $modsince );
116 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
117 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
118 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
119 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
120 # Make sure you're in a place you can leave when you call us!
121 header( "HTTP/1.0 304 Not Modified" );
122 $this->mLastModified
= $lastmod;
123 $this->sendCacheControl();
124 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
126 @ob_end_clean
(); // Don't output compressed blob
129 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
130 $this->mLastModified
= $lastmod;
133 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
134 $this->mLastModified
= $lastmod;
138 function getPageTitleActionText () {
147 // Display title is already customized
150 return wfMsg('history_short');
152 // FIXME: bug 2735; not correct for special pages etc
153 return wfMsg('preview');
155 return wfMsg('info_short');
161 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
162 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
163 function setPageTitle( $name ) {
164 global $action, $wgContLang;
165 $name = $wgContLang->convert($name, true);
166 $this->mPagetitle
= $name;
167 if(!empty($action)) {
168 $taction = $this->getPageTitleActionText();
169 if( !empty( $taction ) ) {
170 $name .= ' - '.$taction;
174 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
176 function getHTMLTitle() { return $this->mHTMLtitle
; }
177 function getPageTitle() { return $this->mPagetitle
; }
178 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
179 function getSubtitle() { return $this->mSubtitle
; }
180 function isArticle() { return $this->mIsarticle
; }
181 function setPrintable() { $this->mPrintable
= true; }
182 function isPrintable() { return $this->mPrintable
; }
183 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
184 function isSyndicated() { return $this->mShowFeedLinks
; }
185 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
186 function getOnloadHandler() { return $this->mOnloadHandler
; }
187 function disable() { $this->mDoNothing
= true; }
189 function setArticleRelated( $v ) {
190 $this->mIsArticleRelated
= $v;
192 $this->mIsarticle
= false;
195 function setArticleFlag( $v ) {
196 $this->mIsarticle
= $v;
198 $this->mIsArticleRelated
= $v;
202 function isArticleRelated() { return $this->mIsArticleRelated
; }
204 function getLanguageLinks() { return $this->mLanguageLinks
; }
205 function addLanguageLinks($newLinkArray) {
206 $this->mLanguageLinks +
= $newLinkArray;
208 function setLanguageLinks($newLinkArray) {
209 $this->mLanguageLinks
= $newLinkArray;
212 function getCategoryLinks() {
213 return $this->mCategoryLinks
;
217 * Add an array of categories, with names in the keys
219 function addCategoryLinks($categories) {
220 global $wgUser, $wgContLang;
222 if ( !is_array( $categories ) ) {
225 # Add the links to the link cache in a batch
226 $arr = array( NS_CATEGORY
=> $categories );
228 $lb->setArray( $arr );
231 $sk =& $wgUser->getSkin();
232 foreach ( $categories as $category => $arbitrary ) {
233 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
234 $text = $wgContLang->convertHtml( $title->getText() );
235 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
239 function setCategoryLinks($categories) {
240 $this->mCategoryLinks
= array();
241 $this->addCategoryLinks($categories);
244 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
245 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
247 function addHTML( $text ) { $this->mBodytext
.= $text; }
248 function clearHTML() { $this->mBodytext
= ''; }
249 function getHTML() { return $this->mBodytext
; }
250 function debug( $text ) { $this->mDebugtext
.= $text; }
253 function setParserOptions( $options ) {
254 return $this->ParserOptions( $options );
257 function ParserOptions( $options = null ) {
258 return wfSetVar( $this->mParserOptions
, $options );
262 * Set the revision ID which will be seen by the wiki text parser
263 * for things such as embedded {{REVISIONID}} variable use.
264 * @param mixed $revid an integer, or NULL
265 * @return mixed previous value
267 function setRevisionId( $revid ) {
268 $val = is_null( $revid ) ?
null : intval( $revid );
269 return wfSetVar( $this->mRevisionId
, $val );
273 * Convert wikitext to HTML and add it to the buffer
274 * Default assumes that the current page title will
277 function addWikiText( $text, $linestart = true ) {
279 $this->addWikiTextTitle($text, $wgTitle, $linestart);
282 function addWikiTextWithTitle($text, &$title, $linestart = true) {
283 $this->addWikiTextTitle($text, $title, $linestart);
286 function addWikiTextTitle($text, &$title, $linestart) {
288 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
289 $linestart, true, $this->mRevisionId
);
290 $this->addParserOutput( $parserOutput );
293 function addParserOutputNoText( &$parserOutput ) {
294 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
295 $this->addCategoryLinks( $parserOutput->getCategories() );
296 $this->mNewSectionLink
= $parserOutput->getNewSection();
297 $this->addKeywords( $parserOutput );
298 if ( $parserOutput->getCacheTime() == -1 ) {
299 $this->enableClientCache( false );
301 if ( $parserOutput->mHTMLtitle
!= "" ) {
302 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
303 $this->mSubtitle
.= $parserOutput->mSubtitle
;
307 function addParserOutput( &$parserOutput ) {
308 $this->addParserOutputNoText( $parserOutput );
309 $this->addHTML( $parserOutput->getText() );
313 * Add wikitext to the buffer, assuming that this is the primary text for a page view
314 * Saves the text into the parser cache if possible
316 function addPrimaryWikiText( $text, $article, $cache = true ) {
317 global $wgParser, $wgUser;
319 $this->mParserOptions
->setTidy(true);
320 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
321 $this->mParserOptions
, true, true, $this->mRevisionId
);
322 $this->mParserOptions
->setTidy(false);
323 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
324 $parserCache =& ParserCache
::singleton();
325 $parserCache->save( $parserOutput, $article, $wgUser );
328 $this->addParserOutputNoText( $parserOutput );
329 $text = $parserOutput->getText();
330 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
331 $parserOutput->setText( $text );
332 $this->addHTML( $parserOutput->getText() );
336 * For anything that isn't primary text or interface message
338 function addSecondaryWikiText( $text, $linestart = true ) {
340 $this->mParserOptions
->setTidy(true);
341 $this->addWikiTextTitle($text, $wgTitle, $linestart);
342 $this->mParserOptions
->setTidy(false);
347 * Add the output of a QuickTemplate to the output buffer
348 * @param QuickTemplate $template
350 function addTemplate( &$template ) {
352 $template->execute();
353 $this->addHTML( ob_get_contents() );
358 * Parse wikitext and return the HTML.
360 function parse( $text, $linestart = true, $interface = false ) {
361 global $wgParser, $wgTitle;
362 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(true); }
363 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
364 $linestart, true, $this->mRevisionId
);
365 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(false); }
366 return $parserOutput->getText();
375 function tryParserCache( &$article, $user ) {
376 $parserCache =& ParserCache
::singleton();
377 $parserOutput = $parserCache->get( $article, $user );
378 if ( $parserOutput !== false ) {
379 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
380 $this->addCategoryLinks( $parserOutput->getCategories() );
381 $this->addKeywords( $parserOutput );
382 $this->mNewSectionLink
= $parserOutput->getNewSection();
383 $text = $parserOutput->getText();
384 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
385 $this->addHTML( $text );
386 $t = $parserOutput->getTitleText();
388 $this->setPageTitle( $t );
397 * Set the maximum cache time on the Squid in seconds
400 function setSquidMaxage( $maxage ) {
401 $this->mSquidMaxage
= $maxage;
405 * Use enableClientCache(false) to force it to send nocache headers
408 function enableClientCache( $state ) {
409 return wfSetVar( $this->mEnableClientCache
, $state );
412 function uncacheableBecauseRequestvars() {
414 return $wgRequest->getText('useskin', false) === false
415 && $wgRequest->getText('uselang', false) === false;
418 function sendCacheControl() {
419 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
420 $fname = 'OutputPage::sendCacheControl';
423 header("ETag: $this->mETag");
425 # don't serve compressed data to clients who can't handle it
426 # maintain different caches for logged-in users and non-logged in ones
427 header( 'Vary: Accept-Encoding, Cookie' );
428 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
429 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
430 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
433 # We'll purge the proxy cache explicitly, but require end user agents
434 # to revalidate against the proxy on each visit.
435 # Surrogate-Control controls our Squid, Cache-Control downstream caches
436 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
437 # start with a shorter timeout for initial testing
438 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
439 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
440 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
442 # We'll purge the proxy cache for anons explicitly, but require end user agents
443 # to revalidate against the proxy on each visit.
444 # IMPORTANT! The Squid needs to replace the Cache-Control header with
445 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
446 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
447 # start with a shorter timeout for initial testing
448 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
449 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
452 # We do want clients to cache if they can, but they *must* check for updates
453 # on revisiting the page.
454 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
455 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
456 header( "Cache-Control: private, must-revalidate, max-age=0" );
458 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
460 wfDebug( "$fname: no caching **\n", false );
462 # In general, the absence of a last modified header should be enough to prevent
463 # the client from using its cache. We send a few other things just to make sure.
464 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
465 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
466 header( 'Pragma: no-cache' );
471 * Finally, all the text has been munged and accumulated into
472 * the object, let's actually output it:
475 global $wgUser, $wgOutputEncoding;
476 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
477 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
479 if( $this->mDoNothing
){
482 $fname = 'OutputPage::output';
483 wfProfileIn( $fname );
484 $sk = $wgUser->getSkin();
487 $this->addScript( "<script type=\"{$wgJsMimeType}\">
488 var wgScriptPath=\"{$wgScriptPath}\";
489 var wgServer=\"{$wgServer}\";
491 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
494 if ( '' != $this->mRedirect
) {
495 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
496 # Standards require redirect URLs to be absolute
498 $this->mRedirect
= $wgServer . $this->mRedirect
;
500 if( $this->mRedirectCode
== '301') {
501 if( !$wgDebugRedirects ) {
502 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
504 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
507 $this->sendCacheControl();
509 if( $wgDebugRedirects ) {
510 $url = htmlspecialchars( $this->mRedirect
);
511 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
512 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
513 print "</body>\n</html>\n";
515 header( 'Location: '.$this->mRedirect
);
517 wfProfileOut( $fname );
520 elseif ( $this->mStatusCode
)
522 $statusMessage = array(
524 101 => 'Switching Protocols',
529 203 => 'Non-Authoritative Information',
531 205 => 'Reset Content',
532 206 => 'Partial Content',
533 207 => 'Multi-Status',
534 300 => 'Multiple Choices',
535 301 => 'Moved Permanently',
538 304 => 'Not Modified',
540 307 => 'Temporary Redirect',
541 400 => 'Bad Request',
542 401 => 'Unauthorized',
543 402 => 'Payment Required',
546 405 => 'Method Not Allowed',
547 406 => 'Not Acceptable',
548 407 => 'Proxy Authentication Required',
549 408 => 'Request Timeout',
552 411 => 'Length Required',
553 412 => 'Precondition Failed',
554 413 => 'Request Entity Too Large',
555 414 => 'Request-URI Too Large',
556 415 => 'Unsupported Media Type',
557 416 => 'Request Range Not Satisfiable',
558 417 => 'Expectation Failed',
559 422 => 'Unprocessable Entity',
561 424 => 'Failed Dependency',
562 500 => 'Internal Server Error',
563 501 => 'Not Implemented',
564 502 => 'Bad Gateway',
565 503 => 'Service Unavailable',
566 504 => 'Gateway Timeout',
567 505 => 'HTTP Version Not Supported',
568 507 => 'Insufficient Storage'
571 if ( $statusMessage[$this->mStatusCode
] )
572 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
575 # Buffer output; final headers may depend on later processing
578 # Disable temporary placeholders, so that the skin produces HTML
579 $sk->postParseLinkColour( false );
581 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
582 header( 'Content-language: '.$wgContLanguageCode );
584 if ($this->mArticleBodyOnly
) {
585 $this->out($this->mBodytext
);
587 wfProfileIn( 'Output-skin' );
588 $sk->outputPage( $this );
589 wfProfileOut( 'Output-skin' );
592 $this->sendCacheControl();
594 wfProfileOut( $fname );
597 function out( $ins ) {
598 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
599 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
602 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
603 if ( false === $outs ) { $outs = $ins; }
608 function setEncodings() {
609 global $wgInputEncoding, $wgOutputEncoding;
610 global $wgUser, $wgContLang;
612 $wgInputEncoding = strtolower( $wgInputEncoding );
614 if( $wgUser->getOption( 'altencoding' ) ) {
615 $wgContLang->setAltEncoding();
619 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
620 $wgOutputEncoding = strtolower( $wgOutputEncoding );
623 $wgOutputEncoding = $wgInputEncoding;
627 * Returns a HTML comment with the elapsed time since request.
628 * This method has no side effects.
629 * Use wfReportTime() instead.
633 function reportTime() {
634 $time = wfReportTime();
639 * Produce a "user is blocked" page
641 function blockedPage() {
642 global $wgUser, $wgContLang, $wgTitle;
644 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
645 $this->setRobotpolicy( 'noindex,nofollow' );
646 $this->setArticleRelated( false );
648 $id = $wgUser->blockedBy();
649 $reason = $wgUser->blockedFor();
652 if ( is_numeric( $id ) ) {
653 $name = User
::whoIs( $id );
657 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
659 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
661 # Don't auto-return to special pages
662 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
663 $this->returnToMain( false, $return );
667 * Note: these arguments are keys into wfMsg(), not text!
669 function showErrorPage( $title, $msg ) {
672 $this->mDebugtext
.= 'Original title: ' .
673 $wgTitle->getPrefixedText() . "\n";
674 $this->setPageTitle( wfMsg( $title ) );
675 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
676 $this->setRobotpolicy( 'noindex,nofollow' );
677 $this->setArticleRelated( false );
678 $this->enableClientCache( false );
679 $this->mRedirect
= '';
681 $this->mBodytext
= '';
682 $this->addWikiText( wfMsg( $msg ) );
683 $this->returnToMain( false );
687 function errorpage( $title, $msg ) {
688 throw new ErrorPageError( $title, $msg );
692 * Display an error page indicating that a given version of MediaWiki is
695 * @param mixed $version The version of MediaWiki needed to use the page
697 function versionRequired( $version ) {
698 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
699 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
700 $this->setRobotpolicy( 'noindex,nofollow' );
701 $this->setArticleRelated( false );
702 $this->mBodytext
= '';
704 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
705 $this->returnToMain();
709 * Display an error page noting that a given permission bit is required.
710 * This should generally replace the sysopRequired, developerRequired etc.
711 * @param string $permission key required
713 function permissionRequired( $permission ) {
716 $this->setPageTitle( wfMsg( 'badaccess' ) );
717 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
718 $this->setRobotpolicy( 'noindex,nofollow' );
719 $this->setArticleRelated( false );
720 $this->mBodytext
= '';
722 $sk = $wgUser->getSkin();
723 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
724 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
725 $this->returnToMain();
731 function sysopRequired() {
734 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
735 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
736 $this->setRobotpolicy( 'noindex,nofollow' );
737 $this->setArticleRelated( false );
738 $this->mBodytext
= '';
740 $sk = $wgUser->getSkin();
741 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
742 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
743 $this->returnToMain();
749 function developerRequired() {
752 $this->setPageTitle( wfMsg( 'developertitle' ) );
753 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
754 $this->setRobotpolicy( 'noindex,nofollow' );
755 $this->setArticleRelated( false );
756 $this->mBodytext
= '';
758 $sk = $wgUser->getSkin();
759 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
760 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
761 $this->returnToMain();
765 * Produce the stock "please login to use the wiki" page
767 function loginToUse() {
768 global $wgUser, $wgTitle, $wgContLang;
769 $skin = $wgUser->getSkin();
771 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
772 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
773 $this->setRobotPolicy( 'noindex,nofollow' );
774 $this->setArticleFlag( false );
776 $loginTitle = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
777 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
778 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
779 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
781 $this->returnToMain();
785 function databaseError( $fname, $sql, $error, $errno ) {
786 throw new MWException( "OutputPage::databaseError is obsolete\n" );
789 function readOnlyPage( $source = null, $protected = false ) {
790 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
792 $this->setRobotpolicy( 'noindex,nofollow' );
793 $this->setArticleRelated( false );
796 $skin = $wgUser->getSkin();
797 $this->setPageTitle( wfMsg( 'viewsource' ) );
798 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
800 # Determine if protection is due to the page being a system message
801 # and show an appropriate explanation
802 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
&& !$wgUser->isAllowed( 'editinterface' ) ) {
803 $this->addWikiText( wfMsg( 'protectedinterface' ) );
805 $this->addWikiText( wfMsg( 'protectedtext' ) );
808 $this->setPageTitle( wfMsg( 'readonly' ) );
810 $reason = $wgReadOnly;
812 $reason = file_get_contents( $wgReadOnlyFile );
814 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
817 if( is_string( $source ) ) {
818 if( strcmp( $source, '' ) == 0 ) {
820 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
821 $source = wfMsgWeirdKey ( $wgTitle->getText() );
823 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
826 $rows = $wgUser->getIntOption( 'rows' );
827 $cols = $wgUser->getIntOption( 'cols' );
829 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
830 htmlspecialchars( $source ) . "\n</textarea>";
831 $this->addHTML( $text );
834 $this->returnToMain( false );
838 function fatalError( $message ) {
839 throw new FatalError( $message );
843 function unexpectedValueError( $name, $val ) {
844 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
848 function fileCopyError( $old, $new ) {
849 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
853 function fileRenameError( $old, $new ) {
854 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
858 function fileDeleteError( $name ) {
859 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
863 function fileNotFoundError( $name ) {
864 throw new FatalError( wfMsg( 'filenotfound', $name ) );
867 function showFatalError( $message ) {
868 $this->setPageTitle( wfMsg( "internalerror" ) );
869 $this->setRobotpolicy( "noindex,nofollow" );
870 $this->setArticleRelated( false );
871 $this->enableClientCache( false );
872 $this->mRedirect
= '';
873 $this->mBodytext
= $message;
876 function showUnexpectedValueError( $name, $val ) {
877 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
880 function showFileCopyError( $old, $new ) {
881 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
884 function showFileRenameError( $old, $new ) {
885 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
888 function showFileDeleteError( $name ) {
889 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
892 function showFileNotFoundError( $name ) {
893 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
897 * return from error messages or notes
898 * @param $auto automatically redirect the user after 10 seconds
899 * @param $returnto page title to return to. Default is Main Page.
901 function returnToMain( $auto = true, $returnto = NULL ) {
902 global $wgUser, $wgOut, $wgRequest;
904 if ( $returnto == NULL ) {
905 $returnto = $wgRequest->getText( 'returnto' );
907 $returnto = htmlspecialchars( $returnto );
909 $sk = $wgUser->getSkin();
910 if ( '' == $returnto ) {
911 $returnto = wfMsgForContent( 'mainpage' );
913 $link = $sk->makeLinkObj( Title
::newFromText( $returnto ), '' );
915 $r = wfMsg( 'returnto', $link );
917 $titleObj = Title
::newFromText( $returnto );
918 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
920 $wgOut->addHTML( "\n<p>$r</p>\n" );
924 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
925 * and uses the first 10 of them for META keywords
927 function addKeywords( &$parserOutput ) {
929 $this->addKeyword( $wgTitle->getPrefixedText() );
931 $links2d =& $parserOutput->getLinks();
932 if ( !is_array( $links2d ) ) {
935 foreach ( $links2d as $ns => $dbkeys ) {
936 foreach( $dbkeys as $dbkey => $id ) {
937 $this->addKeyword( $dbkey );
938 if ( ++
$count > 10 ) {
949 function headElement() {
950 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
951 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
953 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
954 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
959 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
961 if ( '' == $this->getHTMLTitle() ) {
962 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
965 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
966 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
967 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
968 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
970 $ret .= $this->getHeadLinks();
972 if( $this->isPrintable() ) {
975 $media = "media='print'";
977 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
978 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
980 $sk = $wgUser->getSkin();
981 $ret .= $sk->getHeadScripts();
982 $ret .= $this->mScripts
;
983 $ret .= $sk->getUserStyles();
985 if ($wgUseTrackbacks && $this->isArticleRelated())
986 $ret .= $wgTitle->trackbackRDF();
992 function getHeadLinks() {
995 foreach ( $this->mMetatags
as $tag ) {
996 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
998 $tag[0] = substr( $tag[0], 5 );
1002 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1005 $p = $this->mRobotpolicy
;
1006 if( $p !== '' && $p != 'index,follow' ) {
1007 // http://www.robotstxt.org/wc/meta-user.html
1008 // Only show if it's different from the default robots policy
1009 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1012 if ( count( $this->mKeywords
) > 0 ) {
1017 $ret .= "<meta name=\"keywords\" content=\"" .
1018 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1020 foreach ( $this->mLinktags
as $tag ) {
1022 foreach( $tag as $attr => $val ) {
1023 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1027 if( $this->isSyndicated() ) {
1028 # FIXME: centralize the mime-type and name information in Feed.php
1029 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1030 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1031 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1032 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1039 * Turn off regular page output and return an error reponse
1040 * for when rate limiting has triggered.
1044 function rateLimited() {
1047 wfHttpError( 500, 'Internal Server Error',
1048 'Sorry, the server has encountered an internal error. ' .
1049 'Please wait a moment and hit "refresh" to submit the request again.' );
1053 * Show an "add new section" link?
1055 * @return bool True if the parser output instructs us to add one
1057 function showNewSectionLink() {
1058 return $this->mNewSectionLink
;