2 if ( ! defined( 'MEDIAWIKI' ) )
9 require_once 'Math.php';
16 private $mHeaders, $mMetatags, $mKeywords;
17 private $mLinktags, $mPagetitle;
18 private $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
19 private $mSubtitle, $mRedirect, $mStatusCode;
20 private $mLastModified, $mETag ;
21 private $mScripts, $mLinkColours;
22 private $mSuppressQuickbar;
23 private $mOnloadHandler;
25 private $mContainsOldMagic, $mContainsNewMagic;
26 private $mIsArticleRelated;
27 private $mParserOptions;
28 private $mShowFeedLinks = false;
29 private $mEnableClientCache = true;
30 private $mArticleBodyOnly = false;
31 private $mNewSectionLink = false;
33 /** @todo FIXME shouldn't those be private ? */
43 * Initialise private variables
45 function OutputPage() {
46 $this->mHeaders
= $this->mMetatags
=
47 $this->mKeywords
= $this->mLinktags
= array();
48 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
49 $this->mRedirect
= $this->mLastModified
=
50 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
51 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
52 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
53 $this->mSuppressQuickbar
= $this->mPrintable
= false;
54 $this->mLanguageLinks
= array();
55 $this->mCategoryLinks
= array();
56 $this->mDoNothing
= false;
57 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
58 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
59 $this->mSquidMaxage
= 0;
62 $this->mRevisionId
= null;
63 $this->mNewSectionLink
= false;
66 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ); }
67 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
68 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
70 # To add an http-equiv meta tag, precede the name with "http:"
71 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
72 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
73 function addScript( $script ) { $this->mScripts
.= $script; }
74 function getScript() { return $this->mScripts
; }
76 function setETag($tag) { $this->mETag
= $tag; }
77 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
78 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
80 function addLink( $linkarr ) {
81 # $linkarr should be an associative array of attributes. We'll escape on output.
82 array_push( $this->mLinktags
, $linkarr );
85 function addMetadataLink( $linkarr ) {
86 # note: buggy CC software only reads first "meta" link
87 static $haveMeta = false;
88 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
89 $this->addLink( $linkarr );
94 * checkLastModified tells the client to use the client-cached page if
95 * possible. If sucessful, the OutputPage is disabled so that
96 * any future call to OutputPage->output() have no effect. The method
97 * returns true iff cache-ok headers was sent.
99 function checkLastModified ( $timestamp ) {
100 global $wgCachePages, $wgCacheEpoch, $wgUser;
101 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
102 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
105 if( !$wgCachePages ) {
106 wfDebug( "CACHE DISABLED\n", false );
109 if( $wgUser->getOption( 'nocache' ) ) {
110 wfDebug( "USER DISABLED CACHE\n", false );
114 $timestamp=wfTimestamp(TS_MW
,$timestamp);
115 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
117 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
118 # IE sends sizes after the date like this:
119 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
120 # this breaks strtotime().
121 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
122 $modsinceTime = strtotime( $modsince );
123 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
124 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
125 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
126 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
127 # Make sure you're in a place you can leave when you call us!
128 header( "HTTP/1.0 304 Not Modified" );
129 $this->mLastModified
= $lastmod;
130 $this->sendCacheControl();
131 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
133 @ob_end_clean
(); // Don't output compressed blob
136 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
137 $this->mLastModified
= $lastmod;
140 wfDebug( "client did not send If-Modified-Since header\n", false );
141 $this->mLastModified
= $lastmod;
145 function getPageTitleActionText () {
154 // Display title is already customized
157 return wfMsg('history_short');
159 // FIXME: bug 2735; not correct for special pages etc
160 return wfMsg('preview');
162 return wfMsg('info_short');
168 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
169 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
170 function setPageTitle( $name ) {
171 global $action, $wgContLang;
172 $name = $wgContLang->convert($name, true);
173 $this->mPagetitle
= $name;
174 if(!empty($action)) {
175 $taction = $this->getPageTitleActionText();
176 if( !empty( $taction ) ) {
177 $name .= ' - '.$taction;
181 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
183 function getHTMLTitle() { return $this->mHTMLtitle
; }
184 function getPageTitle() { return $this->mPagetitle
; }
185 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
186 function getSubtitle() { return $this->mSubtitle
; }
187 function isArticle() { return $this->mIsarticle
; }
188 function setPrintable() { $this->mPrintable
= true; }
189 function isPrintable() { return $this->mPrintable
; }
190 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
191 function isSyndicated() { return $this->mShowFeedLinks
; }
192 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
193 function getOnloadHandler() { return $this->mOnloadHandler
; }
194 function disable() { $this->mDoNothing
= true; }
196 function setArticleRelated( $v ) {
197 $this->mIsArticleRelated
= $v;
199 $this->mIsarticle
= false;
202 function setArticleFlag( $v ) {
203 $this->mIsarticle
= $v;
205 $this->mIsArticleRelated
= $v;
209 function isArticleRelated() { return $this->mIsArticleRelated
; }
211 function getLanguageLinks() { return $this->mLanguageLinks
; }
212 function addLanguageLinks($newLinkArray) {
213 $this->mLanguageLinks +
= $newLinkArray;
215 function setLanguageLinks($newLinkArray) {
216 $this->mLanguageLinks
= $newLinkArray;
219 function getCategoryLinks() {
220 return $this->mCategoryLinks
;
224 * Add an array of categories, with names in the keys
226 function addCategoryLinks($categories) {
227 global $wgUser, $wgContLang;
229 if ( !is_array( $categories ) ) {
232 # Add the links to the link cache in a batch
233 $arr = array( NS_CATEGORY
=> $categories );
235 $lb->setArray( $arr );
238 $sk =& $wgUser->getSkin();
239 foreach ( $categories as $category => $arbitrary ) {
240 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
241 $text = $wgContLang->convertHtml( $title->getText() );
242 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
246 function setCategoryLinks($categories) {
247 $this->mCategoryLinks
= array();
248 $this->addCategoryLinks($categories);
251 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
252 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
254 function addHTML( $text ) { $this->mBodytext
.= $text; }
255 function clearHTML() { $this->mBodytext
= ''; }
256 function getHTML() { return $this->mBodytext
; }
257 function debug( $text ) { $this->mDebugtext
.= $text; }
260 function setParserOptions( $options ) {
261 return $this->ParserOptions( $options );
264 function ParserOptions( $options = null ) {
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 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
296 $linestart, true, $this->mRevisionId
);
297 $this->addParserOutput( $parserOutput );
300 function addParserOutputNoText( &$parserOutput ) {
301 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
302 $this->addCategoryLinks( $parserOutput->getCategories() );
303 $this->mNewSectionLink
= $parserOutput->getNewSection();
304 $this->addKeywords( $parserOutput );
305 if ( $parserOutput->getCacheTime() == -1 ) {
306 $this->enableClientCache( false );
308 if ( $parserOutput->mHTMLtitle
!= "" ) {
309 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
310 $this->mSubtitle
.= $parserOutput->mSubtitle
;
314 function addParserOutput( &$parserOutput ) {
315 $this->addParserOutputNoText( $parserOutput );
316 $this->addHTML( $parserOutput->getText() );
320 * Add wikitext to the buffer, assuming that this is the primary text for a page view
321 * Saves the text into the parser cache if possible
323 function addPrimaryWikiText( $text, $article, $cache = true ) {
324 global $wgParser, $wgUser;
326 $this->mParserOptions
->setTidy(true);
327 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
328 $this->mParserOptions
, true, true, $this->mRevisionId
);
329 $this->mParserOptions
->setTidy(false);
330 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
331 $parserCache =& ParserCache
::singleton();
332 $parserCache->save( $parserOutput, $article, $wgUser );
335 $this->addParserOutputNoText( $parserOutput );
336 $text = $parserOutput->getText();
337 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
338 $parserOutput->setText( $text );
339 $this->addHTML( $parserOutput->getText() );
343 * For anything that isn't primary text or interface message
345 function addSecondaryWikiText( $text, $linestart = true ) {
347 $this->mParserOptions
->setTidy(true);
348 $this->addWikiTextTitle($text, $wgTitle, $linestart);
349 $this->mParserOptions
->setTidy(false);
354 * Add the output of a QuickTemplate to the output buffer
355 * @param QuickTemplate $template
357 function addTemplate( &$template ) {
359 $template->execute();
360 $this->addHTML( ob_get_contents() );
365 * Parse wikitext and return the HTML.
367 function parse( $text, $linestart = true, $interface = false ) {
368 global $wgParser, $wgTitle;
369 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(true); }
370 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
371 $linestart, true, $this->mRevisionId
);
372 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(false); }
373 return $parserOutput->getText();
382 function tryParserCache( &$article, $user ) {
383 $parserCache =& ParserCache
::singleton();
384 $parserOutput = $parserCache->get( $article, $user );
385 if ( $parserOutput !== false ) {
386 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
387 $this->addCategoryLinks( $parserOutput->getCategories() );
388 $this->addKeywords( $parserOutput );
389 $this->mNewSectionLink
= $parserOutput->getNewSection();
390 $text = $parserOutput->getText();
391 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
392 $this->addHTML( $text );
393 $t = $parserOutput->getTitleText();
395 $this->setPageTitle( $t );
404 * Set the maximum cache time on the Squid in seconds
407 function setSquidMaxage( $maxage ) {
408 $this->mSquidMaxage
= $maxage;
412 * Use enableClientCache(false) to force it to send nocache headers
415 function enableClientCache( $state ) {
416 return wfSetVar( $this->mEnableClientCache
, $state );
419 function uncacheableBecauseRequestvars() {
421 return $wgRequest->getText('useskin', false) === false
422 && $wgRequest->getText('uselang', false) === false;
425 function sendCacheControl() {
426 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
429 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 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( "** 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 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
446 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( "** 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 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( "** private caching; {$this->mLastModified} **\n", false );
461 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
462 header( "Cache-Control: private, must-revalidate, max-age=0" );
464 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
466 wfDebug( "** 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 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
471 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
472 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;
482 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
483 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
485 if( $this->mDoNothing
){
488 $fname = 'OutputPage::output';
489 wfProfileIn( $fname );
490 $sk = $wgUser->getSkin();
493 $this->addScript( "<script type=\"{$wgJsMimeType}\">
494 var wgScriptPath=\"{$wgScriptPath}\";
495 var wgServer=\"{$wgServer}\";
497 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
500 if ( '' != $this->mRedirect
) {
501 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
502 # Standards require redirect URLs to be absolute
504 $this->mRedirect
= $wgServer . $this->mRedirect
;
506 if( $this->mRedirectCode
== '301') {
507 if( !$wgDebugRedirects ) {
508 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
510 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
513 $this->sendCacheControl();
515 if( $wgDebugRedirects ) {
516 $url = htmlspecialchars( $this->mRedirect
);
517 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
518 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
519 print "</body>\n</html>\n";
521 header( 'Location: '.$this->mRedirect
);
523 wfProfileOut( $fname );
526 elseif ( $this->mStatusCode
)
528 $statusMessage = array(
530 101 => 'Switching Protocols',
535 203 => 'Non-Authoritative Information',
537 205 => 'Reset Content',
538 206 => 'Partial Content',
539 207 => 'Multi-Status',
540 300 => 'Multiple Choices',
541 301 => 'Moved Permanently',
544 304 => 'Not Modified',
546 307 => 'Temporary Redirect',
547 400 => 'Bad Request',
548 401 => 'Unauthorized',
549 402 => 'Payment Required',
552 405 => 'Method Not Allowed',
553 406 => 'Not Acceptable',
554 407 => 'Proxy Authentication Required',
555 408 => 'Request Timeout',
558 411 => 'Length Required',
559 412 => 'Precondition Failed',
560 413 => 'Request Entity Too Large',
561 414 => 'Request-URI Too Large',
562 415 => 'Unsupported Media Type',
563 416 => 'Request Range Not Satisfiable',
564 417 => 'Expectation Failed',
565 422 => 'Unprocessable Entity',
567 424 => 'Failed Dependency',
568 500 => 'Internal Server Error',
569 501 => 'Not Implemented',
570 502 => 'Bad Gateway',
571 503 => 'Service Unavailable',
572 504 => 'Gateway Timeout',
573 505 => 'HTTP Version Not Supported',
574 507 => 'Insufficient Storage'
577 if ( $statusMessage[$this->mStatusCode
] )
578 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
581 # Buffer output; final headers may depend on later processing
584 # Disable temporary placeholders, so that the skin produces HTML
585 $sk->postParseLinkColour( false );
587 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
588 header( 'Content-language: '.$wgContLanguageCode );
590 if ($this->mArticleBodyOnly
) {
591 $this->out($this->mBodytext
);
593 wfProfileIn( 'Output-skin' );
594 $sk->outputPage( $this );
595 wfProfileOut( 'Output-skin' );
598 $this->sendCacheControl();
600 wfProfileOut( $fname );
603 function out( $ins ) {
604 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
605 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
608 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
609 if ( false === $outs ) { $outs = $ins; }
614 static function setEncodings() {
615 global $wgInputEncoding, $wgOutputEncoding;
616 global $wgUser, $wgContLang;
618 $wgInputEncoding = strtolower( $wgInputEncoding );
620 if( $wgUser->getOption( 'altencoding' ) ) {
621 $wgContLang->setAltEncoding();
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() {
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
668 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
669 $this->returnToMain( false, $return );
673 * Note: these arguments are keys into wfMsg(), not text!
675 function errorpage( $title, $msg ) {
678 $this->mDebugtext
.= 'Original title: ' .
679 $wgTitle->getPrefixedText() . "\n";
680 $this->setPageTitle( wfMsg( $title ) );
681 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
682 $this->setRobotpolicy( 'noindex,nofollow' );
683 $this->setArticleRelated( false );
684 $this->enableClientCache( false );
685 $this->mRedirect
= '';
687 $this->mBodytext
= '';
688 $this->addWikiText( wfMsg( $msg ) );
689 $this->returnToMain( false );
696 * Display an error page indicating that a given version of MediaWiki is
699 * @param mixed $version The version of MediaWiki needed to use the page
701 function versionRequired( $version ) {
702 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
703 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
704 $this->setRobotpolicy( 'noindex,nofollow' );
705 $this->setArticleRelated( false );
706 $this->mBodytext
= '';
708 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
709 $this->returnToMain();
713 * Display an error page noting that a given permission bit is required.
714 * This should generally replace the sysopRequired, developerRequired etc.
715 * @param string $permission key required
717 function permissionRequired( $permission ) {
720 $this->setPageTitle( wfMsg( 'badaccess' ) );
721 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
722 $this->setRobotpolicy( 'noindex,nofollow' );
723 $this->setArticleRelated( false );
724 $this->mBodytext
= '';
726 $sk = $wgUser->getSkin();
727 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
728 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
729 $this->returnToMain();
735 function sysopRequired() {
738 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
739 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
740 $this->setRobotpolicy( 'noindex,nofollow' );
741 $this->setArticleRelated( false );
742 $this->mBodytext
= '';
744 $sk = $wgUser->getSkin();
745 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
746 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
747 $this->returnToMain();
753 function developerRequired() {
756 $this->setPageTitle( wfMsg( 'developertitle' ) );
757 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
758 $this->setRobotpolicy( 'noindex,nofollow' );
759 $this->setArticleRelated( false );
760 $this->mBodytext
= '';
762 $sk = $wgUser->getSkin();
763 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
764 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
765 $this->returnToMain();
769 * Produce the stock "please login to use the wiki" page
771 function loginToUse() {
772 global $wgUser, $wgTitle, $wgContLang;
773 $skin = $wgUser->getSkin();
775 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
776 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
777 $this->setRobotPolicy( 'noindex,nofollow' );
778 $this->setArticleFlag( false );
780 $loginTitle = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
781 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
782 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
783 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
785 $this->returnToMain();
788 function databaseError( $fname, $sql, $error, $errno ) {
789 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
791 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
792 $this->setRobotpolicy( 'noindex,nofollow' );
793 $this->setArticleRelated( false );
794 $this->enableClientCache( false );
795 $this->mRedirect
= '';
797 if( !$wgShowSQLErrors ) {
798 $sql = wfMsg( 'sqlhidden' );
801 if ( $wgCommandLineMode ) {
802 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
803 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
805 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
806 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
809 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
813 $this->mBodytext
= $msg;
818 function readOnlyPage( $source = null, $protected = false ) {
819 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
821 $this->setRobotpolicy( 'noindex,nofollow' );
822 $this->setArticleRelated( false );
825 $skin = $wgUser->getSkin();
826 $this->setPageTitle( wfMsg( 'viewsource' ) );
827 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
829 # Determine if protection is due to the page being a system message
830 # and show an appropriate explanation
831 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
&& !$wgUser->isAllowed( 'editinterface' ) ) {
832 $this->addWikiText( wfMsg( 'protectedinterface' ) );
834 $this->addWikiText( wfMsg( 'protectedtext' ) );
837 $this->setPageTitle( wfMsg( 'readonly' ) );
839 $reason = $wgReadOnly;
841 $reason = file_get_contents( $wgReadOnlyFile );
843 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
846 if( is_string( $source ) ) {
847 if( strcmp( $source, '' ) == 0 ) {
849 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
850 $source = wfMsgWeirdKey ( $wgTitle->getText() );
852 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
855 $rows = $wgUser->getOption( 'rows' );
856 $cols = $wgUser->getOption( 'cols' );
858 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
859 htmlspecialchars( $source ) . "\n</textarea>";
860 $this->addHTML( $text );
863 $this->returnToMain( false );
866 function fatalError( $message ) {
867 $this->setPageTitle( wfMsg( "internalerror" ) );
868 $this->setRobotpolicy( "noindex,nofollow" );
869 $this->setArticleRelated( false );
870 $this->enableClientCache( false );
871 $this->mRedirect
= '';
873 $this->mBodytext
= $message;
878 function unexpectedValueError( $name, $val ) {
879 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
882 function fileCopyError( $old, $new ) {
883 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
886 function fileRenameError( $old, $new ) {
887 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
890 function fileDeleteError( $name ) {
891 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
894 function fileNotFoundError( $name ) {
895 $this->fatalError( wfMsg( 'filenotfound', $name ) );
899 * return from error messages or notes
900 * @param $auto automatically redirect the user after 10 seconds
901 * @param $returnto page title to return to. Default is Main Page.
903 function returnToMain( $auto = true, $returnto = NULL ) {
904 global $wgUser, $wgOut, $wgRequest;
906 if ( $returnto == NULL ) {
907 $returnto = $wgRequest->getText( 'returnto' );
909 $returnto = htmlspecialchars( $returnto );
911 $sk = $wgUser->getSkin();
912 if ( '' == $returnto ) {
913 $returnto = wfMsgForContent( 'mainpage' );
915 $link = $sk->makeLinkObj( Title
::newFromText( $returnto ), '' );
917 $r = wfMsg( 'returnto', $link );
919 $titleObj = Title
::newFromText( $returnto );
920 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
922 $wgOut->addHTML( "\n<p>$r</p>\n" );
926 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
927 * and uses the first 10 of them for META keywords
929 function addKeywords( &$parserOutput ) {
931 $this->addKeyword( $wgTitle->getPrefixedText() );
933 $links2d =& $parserOutput->getLinks();
934 if ( !is_array( $links2d ) ) {
937 foreach ( $links2d as $ns => $dbkeys ) {
938 foreach( $dbkeys as $dbkey => $id ) {
939 $this->addKeyword( $dbkey );
940 if ( ++
$count > 10 ) {
951 function headElement() {
952 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
953 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
955 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
956 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
961 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
963 if ( '' == $this->getHTMLTitle() ) {
964 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
967 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
968 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
969 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
970 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
972 $ret .= $this->getHeadLinks();
974 if( $this->isPrintable() ) {
977 $media = "media='print'";
979 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
980 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
982 $sk = $wgUser->getSkin();
983 $ret .= $sk->getHeadScripts();
984 $ret .= $this->mScripts
;
985 $ret .= $sk->getUserStyles();
987 if ($wgUseTrackbacks && $this->isArticleRelated())
988 $ret .= $wgTitle->trackbackRDF();
994 function getHeadLinks() {
997 foreach ( $this->mMetatags
as $tag ) {
998 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1000 $tag[0] = substr( $tag[0], 5 );
1004 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1007 $p = $this->mRobotpolicy
;
1008 if( $p !== '' && $p != 'index,follow' ) {
1009 // http://www.robotstxt.org/wc/meta-user.html
1010 // Only show if it's different from the default robots policy
1011 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1014 if ( count( $this->mKeywords
) > 0 ) {
1019 $ret .= "<meta name=\"keywords\" content=\"" .
1020 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1022 foreach ( $this->mLinktags
as $tag ) {
1024 foreach( $tag as $attr => $val ) {
1025 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1029 if( $this->isSyndicated() ) {
1030 # FIXME: centralize the mime-type and name information in Feed.php
1031 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1032 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1033 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1034 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1041 * Turn off regular page output and return an error reponse
1042 * for when rate limiting has triggered.
1046 function rateLimited() {
1049 wfHttpError( 500, 'Internal Server Error',
1050 'Sorry, the server has encountered an internal error. ' .
1051 'Please wait a moment and hit "refresh" to submit the request again.' );
1055 * Show an "add new section" link?
1057 * @return bool True if the parser output instructs us to add one
1059 function showNewSectionLink() {
1060 return $this->mNewSectionLink
;