2 if ( ! defined( 'MEDIAWIKI' ) )
9 require_once 'Math.php';
16 var $mHeaders, $mMetatags, $mKeywords;
17 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
18 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
19 var $mSubtitle, $mRedirect, $mStatusCode;
20 var $mLastModified, $mETag, $mCategoryLinks;
21 var $mScripts, $mLinkColours, $mPageLinkTitle;
23 var $mSuppressQuickbar;
26 var $mContainsOldMagic, $mContainsNewMagic;
27 var $mIsArticleRelated;
29 var $mShowFeedLinks = false;
30 var $mEnableClientCache = true;
31 var $mArticleBodyOnly = false;
33 var $mNewSectionLink = false;
37 * Initialise private variables
39 function OutputPage() {
40 $this->mHeaders
= $this->mMetatags
=
41 $this->mKeywords
= $this->mLinktags
= array();
42 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
43 $this->mRedirect
= $this->mLastModified
=
44 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
45 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
46 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
47 $this->mSuppressQuickbar
= $this->mPrintable
= false;
48 $this->mLanguageLinks
= array();
49 $this->mCategoryLinks
= array();
50 $this->mDoNothing
= false;
51 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
52 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
53 $this->mSquidMaxage
= 0;
56 $this->mRevisionId
= null;
57 $this->mNewSectionLink
= false;
60 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ); }
61 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
62 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
64 # To add an http-equiv meta tag, precede the name with "http:"
65 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
66 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
67 function addScript( $script ) { $this->mScripts
.= $script; }
68 function getScript() { return $this->mScripts
; }
70 function setETag($tag) { $this->mETag
= $tag; }
71 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
72 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
74 function addLink( $linkarr ) {
75 # $linkarr should be an associative array of attributes. We'll escape on output.
76 array_push( $this->mLinktags
, $linkarr );
79 function addMetadataLink( $linkarr ) {
80 # note: buggy CC software only reads first "meta" link
81 static $haveMeta = false;
82 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
83 $this->addLink( $linkarr );
88 * checkLastModified tells the client to use the client-cached page if
89 * possible. If sucessful, the OutputPage is disabled so that
90 * any future call to OutputPage->output() have no effect. The method
91 * returns true iff cache-ok headers was sent.
93 function checkLastModified ( $timestamp ) {
94 global $wgCachePages, $wgCacheEpoch, $wgUser;
95 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
96 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
99 if( !$wgCachePages ) {
100 wfDebug( "CACHE DISABLED\n", false );
103 if( $wgUser->getOption( 'nocache' ) ) {
104 wfDebug( "USER DISABLED CACHE\n", false );
108 $timestamp=wfTimestamp(TS_MW
,$timestamp);
109 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
111 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
112 # IE sends sizes after the date like this:
113 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
114 # this breaks strtotime().
115 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
116 $modsinceTime = strtotime( $modsince );
117 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
118 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
119 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
120 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
121 # Make sure you're in a place you can leave when you call us!
122 header( "HTTP/1.0 304 Not Modified" );
123 $this->mLastModified
= $lastmod;
124 $this->sendCacheControl();
125 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
127 @ob_end_clean
(); // Don't output compressed blob
130 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
131 $this->mLastModified
= $lastmod;
134 wfDebug( "client did not send If-Modified-Since header\n", false );
135 $this->mLastModified
= $lastmod;
139 function getPageTitleActionText () {
148 // Display title is already customized
151 return wfMsg('history_short');
153 // FIXME: bug 2735; not correct for special pages etc
154 return wfMsg('preview');
156 return wfMsg('info_short');
162 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
163 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
164 function setPageTitle( $name ) {
165 global $action, $wgContLang;
166 $name = $wgContLang->convert($name, true);
167 $this->mPagetitle
= $name;
168 if(!empty($action)) {
169 $taction = $this->getPageTitleActionText();
170 if( !empty( $taction ) ) {
171 $name .= ' - '.$taction;
175 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
177 function getHTMLTitle() { return $this->mHTMLtitle
; }
178 function getPageTitle() { return $this->mPagetitle
; }
179 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
180 function getSubtitle() { return $this->mSubtitle
; }
181 function isArticle() { return $this->mIsarticle
; }
182 function setPrintable() { $this->mPrintable
= true; }
183 function isPrintable() { return $this->mPrintable
; }
184 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
185 function isSyndicated() { return $this->mShowFeedLinks
; }
186 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
187 function getOnloadHandler() { return $this->mOnloadHandler
; }
188 function disable() { $this->mDoNothing
= true; }
190 function setArticleRelated( $v ) {
191 $this->mIsArticleRelated
= $v;
193 $this->mIsarticle
= false;
196 function setArticleFlag( $v ) {
197 $this->mIsarticle
= $v;
199 $this->mIsArticleRelated
= $v;
203 function isArticleRelated() { return $this->mIsArticleRelated
; }
205 function getLanguageLinks() { return $this->mLanguageLinks
; }
206 function addLanguageLinks($newLinkArray) {
207 $this->mLanguageLinks +
= $newLinkArray;
209 function setLanguageLinks($newLinkArray) {
210 $this->mLanguageLinks
= $newLinkArray;
213 function getCategoryLinks() {
214 return $this->mCategoryLinks
;
218 * Add an array of categories, with names in the keys
220 function addCategoryLinks($categories) {
221 global $wgUser, $wgContLang;
223 if ( !is_array( $categories ) ) {
226 # Add the links to the link cache in a batch
227 $arr = array( NS_CATEGORY
=> $categories );
229 $lb->setArray( $arr );
232 $sk =& $wgUser->getSkin();
233 foreach ( $categories as $category => $arbitrary ) {
234 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
235 $text = $wgContLang->convertHtml( $title->getText() );
236 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
240 function setCategoryLinks($categories) {
241 $this->mCategoryLinks
= array();
242 $this->addCategoryLinks($categories);
245 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
246 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
248 function addHTML( $text ) { $this->mBodytext
.= $text; }
249 function clearHTML() { $this->mBodytext
= ''; }
250 function getHTML() { return $this->mBodytext
; }
251 function debug( $text ) { $this->mDebugtext
.= $text; }
254 function setParserOptions( $options ) {
255 return $this->ParserOptions( $options );
258 function ParserOptions( $options = null ) {
259 return wfSetVar( $this->mParserOptions
, $options );
263 * Set the revision ID which will be seen by the wiki text parser
264 * for things such as embedded {{REVISIONID}} variable use.
265 * @param mixed $revid an integer, or NULL
266 * @return mixed previous value
268 function setRevisionId( $revid ) {
269 $val = is_null( $revid ) ?
null : intval( $revid );
270 return wfSetVar( $this->mRevisionId
, $val );
274 * Convert wikitext to HTML and add it to the buffer
275 * Default assumes that the current page title will
278 function addWikiText( $text, $linestart = true ) {
280 $this->addWikiTextTitle($text, $wgTitle, $linestart);
283 function addWikiTextWithTitle($text, &$title, $linestart = true) {
284 $this->addWikiTextTitle($text, $title, $linestart);
287 function addWikiTextTitle($text, &$title, $linestart) {
289 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
290 $linestart, true, $this->mRevisionId
);
291 $this->addParserOutput( $parserOutput );
294 function addParserOutputNoText( &$parserOutput ) {
295 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
296 $this->addCategoryLinks( $parserOutput->getCategories() );
297 $this->mNewSectionLink
= $parserOutput->getNewSection();
298 $this->addKeywords( $parserOutput );
299 if ( $parserOutput->getCacheTime() == -1 ) {
300 $this->enableClientCache( false );
302 if ( $parserOutput->mHTMLtitle
!= "" ) {
303 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
304 $this->mSubtitle
.= $parserOutput->mSubtitle
;
308 function addParserOutput( &$parserOutput ) {
309 $this->addParserOutputNoText( $parserOutput );
310 $this->addHTML( $parserOutput->getText() );
314 * Add wikitext to the buffer, assuming that this is the primary text for a page view
315 * Saves the text into the parser cache if possible
317 function addPrimaryWikiText( $text, $article, $cache = true ) {
318 global $wgParser, $wgUser;
320 $this->mParserOptions
->setTidy(true);
321 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
322 $this->mParserOptions
, true, true, $this->mRevisionId
);
323 $this->mParserOptions
->setTidy(false);
324 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
325 $parserCache =& ParserCache
::singleton();
326 $parserCache->save( $parserOutput, $article, $wgUser );
329 $this->addParserOutputNoText( $parserOutput );
330 $text = $parserOutput->getText();
331 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
332 $parserOutput->setText( $text );
333 $this->addHTML( $parserOutput->getText() );
337 * For anything that isn't primary text or interface message
339 function addSecondaryWikiText( $text, $linestart = true ) {
341 $this->mParserOptions
->setTidy(true);
342 $this->addWikiTextTitle($text, $wgTitle, $linestart);
343 $this->mParserOptions
->setTidy(false);
348 * Add the output of a QuickTemplate to the output buffer
349 * @param QuickTemplate $template
351 function addTemplate( &$template ) {
353 $template->execute();
354 $this->addHTML( ob_get_contents() );
359 * Parse wikitext and return the HTML.
361 function parse( $text, $linestart = true, $interface = false ) {
362 global $wgParser, $wgTitle;
363 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(true); }
364 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
365 $linestart, true, $this->mRevisionId
);
366 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(false); }
367 return $parserOutput->getText();
376 function tryParserCache( &$article, $user ) {
377 $parserCache =& ParserCache
::singleton();
378 $parserOutput = $parserCache->get( $article, $user );
379 if ( $parserOutput !== false ) {
380 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
381 $this->addCategoryLinks( $parserOutput->getCategories() );
382 $this->addKeywords( $parserOutput );
383 $this->mNewSectionLink
= $parserOutput->getNewSection();
384 $text = $parserOutput->getText();
385 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
386 $this->addHTML( $text );
387 $t = $parserOutput->getTitleText();
389 $this->setPageTitle( $t );
398 * Set the maximum cache time on the Squid in seconds
401 function setSquidMaxage( $maxage ) {
402 $this->mSquidMaxage
= $maxage;
406 * Use enableClientCache(false) to force it to send nocache headers
409 function enableClientCache( $state ) {
410 return wfSetVar( $this->mEnableClientCache
, $state );
413 function uncacheableBecauseRequestvars() {
415 return $wgRequest->getText('useskin', false) === false
416 && $wgRequest->getText('uselang', false) === false;
419 function sendCacheControl() {
420 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
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( "** 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( "** 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( "** 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( "** 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 errorpage( $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 );
690 * Display an error page indicating that a given version of MediaWiki is
693 * @param mixed $version The version of MediaWiki needed to use the page
695 function versionRequired( $version ) {
696 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
697 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
698 $this->setRobotpolicy( 'noindex,nofollow' );
699 $this->setArticleRelated( false );
700 $this->mBodytext
= '';
702 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
703 $this->returnToMain();
707 * Display an error page noting that a given permission bit is required.
708 * This should generally replace the sysopRequired, developerRequired etc.
709 * @param string $permission key required
711 function permissionRequired( $permission ) {
714 $this->setPageTitle( wfMsg( 'badaccess' ) );
715 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
716 $this->setRobotpolicy( 'noindex,nofollow' );
717 $this->setArticleRelated( false );
718 $this->mBodytext
= '';
720 $sk = $wgUser->getSkin();
721 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
722 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
723 $this->returnToMain();
729 function sysopRequired() {
732 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
733 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
734 $this->setRobotpolicy( 'noindex,nofollow' );
735 $this->setArticleRelated( false );
736 $this->mBodytext
= '';
738 $sk = $wgUser->getSkin();
739 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
740 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
741 $this->returnToMain();
747 function developerRequired() {
750 $this->setPageTitle( wfMsg( 'developertitle' ) );
751 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
752 $this->setRobotpolicy( 'noindex,nofollow' );
753 $this->setArticleRelated( false );
754 $this->mBodytext
= '';
756 $sk = $wgUser->getSkin();
757 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
758 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
759 $this->returnToMain();
763 * Produce the stock "please login to use the wiki" page
765 function loginToUse() {
766 global $wgUser, $wgTitle, $wgContLang;
767 $skin = $wgUser->getSkin();
769 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
770 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
771 $this->setRobotPolicy( 'noindex,nofollow' );
772 $this->setArticleFlag( false );
774 $loginTitle = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
775 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
776 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
777 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
779 $this->returnToMain();
782 function databaseError( $fname, $sql, $error, $errno ) {
783 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
785 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
786 $this->setRobotpolicy( 'noindex,nofollow' );
787 $this->setArticleRelated( false );
788 $this->enableClientCache( false );
789 $this->mRedirect
= '';
791 if( !$wgShowSQLErrors ) {
792 $sql = wfMsg( 'sqlhidden' );
795 if ( $wgCommandLineMode ) {
796 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
797 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
799 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
800 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
803 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
807 $this->mBodytext
= $msg;
812 function readOnlyPage( $source = null, $protected = false ) {
813 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
815 $this->setRobotpolicy( 'noindex,nofollow' );
816 $this->setArticleRelated( false );
819 $skin = $wgUser->getSkin();
820 $this->setPageTitle( wfMsg( 'viewsource' ) );
821 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
823 # Determine if protection is due to the page being a system message
824 # and show an appropriate explanation
825 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
&& !$wgUser->isAllowed( 'editinterface' ) ) {
826 $this->addWikiText( wfMsg( 'protectedinterface' ) );
828 $this->addWikiText( wfMsg( 'protectedtext' ) );
831 $this->setPageTitle( wfMsg( 'readonly' ) );
833 $reason = $wgReadOnly;
835 $reason = file_get_contents( $wgReadOnlyFile );
837 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
840 if( is_string( $source ) ) {
841 if( strcmp( $source, '' ) == 0 ) {
843 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
844 $source = wfMsgWeirdKey ( $wgTitle->getText() );
846 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
849 $rows = $wgUser->getOption( 'rows' );
850 $cols = $wgUser->getOption( 'cols' );
852 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
853 htmlspecialchars( $source ) . "\n</textarea>";
854 $this->addHTML( $text );
857 $this->returnToMain( false );
860 function fatalError( $message ) {
861 $this->setPageTitle( wfMsg( "internalerror" ) );
862 $this->setRobotpolicy( "noindex,nofollow" );
863 $this->setArticleRelated( false );
864 $this->enableClientCache( false );
865 $this->mRedirect
= '';
867 $this->mBodytext
= $message;
872 function unexpectedValueError( $name, $val ) {
873 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
876 function fileCopyError( $old, $new ) {
877 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
880 function fileRenameError( $old, $new ) {
881 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
884 function fileDeleteError( $name ) {
885 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
888 function fileNotFoundError( $name ) {
889 $this->fatalError( wfMsg( 'filenotfound', $name ) );
893 * return from error messages or notes
894 * @param $auto automatically redirect the user after 10 seconds
895 * @param $returnto page title to return to. Default is Main Page.
897 function returnToMain( $auto = true, $returnto = NULL ) {
898 global $wgUser, $wgOut, $wgRequest;
900 if ( $returnto == NULL ) {
901 $returnto = $wgRequest->getText( 'returnto' );
903 $returnto = htmlspecialchars( $returnto );
905 $sk = $wgUser->getSkin();
906 if ( '' == $returnto ) {
907 $returnto = wfMsgForContent( 'mainpage' );
909 $link = $sk->makeLinkObj( Title
::newFromText( $returnto ), '' );
911 $r = wfMsg( 'returnto', $link );
913 $titleObj = Title
::newFromText( $returnto );
914 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
916 $wgOut->addHTML( "\n<p>$r</p>\n" );
920 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
921 * and uses the first 10 of them for META keywords
923 function addKeywords( &$parserOutput ) {
925 $this->addKeyword( $wgTitle->getPrefixedText() );
927 $links2d =& $parserOutput->getLinks();
928 if ( !is_array( $links2d ) ) {
931 foreach ( $links2d as $ns => $dbkeys ) {
932 foreach( $dbkeys as $dbkey => $id ) {
933 $this->addKeyword( $dbkey );
934 if ( ++
$count > 10 ) {
945 function headElement() {
946 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
947 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
949 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
950 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
955 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
957 if ( '' == $this->getHTMLTitle() ) {
958 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
961 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
962 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
963 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
964 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
966 $ret .= $this->getHeadLinks();
968 if( $this->isPrintable() ) {
971 $media = "media='print'";
973 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
974 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
976 $sk = $wgUser->getSkin();
977 $ret .= $sk->getHeadScripts();
978 $ret .= $this->mScripts
;
979 $ret .= $sk->getUserStyles();
981 if ($wgUseTrackbacks && $this->isArticleRelated())
982 $ret .= $wgTitle->trackbackRDF();
988 function getHeadLinks() {
991 foreach ( $this->mMetatags
as $tag ) {
992 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
994 $tag[0] = substr( $tag[0], 5 );
998 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1001 $p = $this->mRobotpolicy
;
1002 if( $p !== '' && $p != 'index,follow' ) {
1003 // http://www.robotstxt.org/wc/meta-user.html
1004 // Only show if it's different from the default robots policy
1005 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1008 if ( count( $this->mKeywords
) > 0 ) {
1013 $ret .= "<meta name=\"keywords\" content=\"" .
1014 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1016 foreach ( $this->mLinktags
as $tag ) {
1018 foreach( $tag as $attr => $val ) {
1019 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1023 if( $this->isSyndicated() ) {
1024 # FIXME: centralize the mime-type and name information in Feed.php
1025 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1026 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1027 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1028 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1035 * Turn off regular page output and return an error reponse
1036 * for when rate limiting has triggered.
1040 function rateLimited() {
1043 wfHttpError( 500, 'Internal Server Error',
1044 'Sorry, the server has encountered an internal error. ' .
1045 'Please wait a moment and hit "refresh" to submit the request again.' );
1049 * Show an "add new section" link?
1051 * @return bool True if the parser output instructs us to add one
1053 function showNewSectionLink() {
1054 return $this->mNewSectionLink
;