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;
35 * Initialise private variables
37 function OutputPage() {
38 $this->mHeaders
= $this->mMetatags
=
39 $this->mKeywords
= $this->mLinktags
= array();
40 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
41 $this->mRedirect
= $this->mLastModified
=
42 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
43 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
44 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
45 $this->mSuppressQuickbar
= $this->mPrintable
= false;
46 $this->mLanguageLinks
= array();
47 $this->mCategoryLinks
= array();
48 $this->mDoNothing
= false;
49 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
50 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
51 $this->mSquidMaxage
= 0;
54 $this->mRevisionId
= null;
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 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
93 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
96 if( !$wgCachePages ) {
97 wfDebug( "CACHE DISABLED\n", false );
100 if( $wgUser->getOption( 'nocache' ) ) {
101 wfDebug( "USER DISABLED CACHE\n", false );
105 $timestamp=wfTimestamp(TS_MW
,$timestamp);
106 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
108 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
109 # IE sends sizes after the date like this:
110 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
111 # this breaks strtotime().
112 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
113 $modsinceTime = strtotime( $modsince );
114 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
115 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
116 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
117 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
118 # Make sure you're in a place you can leave when you call us!
119 header( "HTTP/1.0 304 Not Modified" );
120 $this->mLastModified
= $lastmod;
121 $this->sendCacheControl();
122 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
124 @ob_end_clean
(); // Don't output compressed blob
127 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
128 $this->mLastModified
= $lastmod;
131 wfDebug( "client did not send If-Modified-Since header\n", false );
132 $this->mLastModified
= $lastmod;
136 function getPageTitleActionText () {
145 // Display title is already customized
148 return wfMsg('history_short');
150 // FIXME: bug 2735; not correct for special pages etc
151 return wfMsg('preview');
153 return wfMsg('info_short');
159 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
160 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
161 function setPageTitle( $name ) {
162 global $action, $wgContLang;
163 $name = $wgContLang->convert($name, true);
164 $this->mPagetitle
= $name;
165 if(!empty($action)) {
166 $taction = $this->getPageTitleActionText();
167 if( !empty( $taction ) ) {
168 $name .= ' - '.$taction;
172 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
174 function getHTMLTitle() { return $this->mHTMLtitle
; }
175 function getPageTitle() { return $this->mPagetitle
; }
176 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
177 function getSubtitle() { return $this->mSubtitle
; }
178 function isArticle() { return $this->mIsarticle
; }
179 function setPrintable() { $this->mPrintable
= true; }
180 function isPrintable() { return $this->mPrintable
; }
181 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
182 function isSyndicated() { return $this->mShowFeedLinks
; }
183 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
184 function getOnloadHandler() { return $this->mOnloadHandler
; }
185 function disable() { $this->mDoNothing
= true; }
187 function setArticleRelated( $v ) {
188 $this->mIsArticleRelated
= $v;
190 $this->mIsarticle
= false;
193 function setArticleFlag( $v ) {
194 $this->mIsarticle
= $v;
196 $this->mIsArticleRelated
= $v;
200 function isArticleRelated() { return $this->mIsArticleRelated
; }
202 function getLanguageLinks() { return $this->mLanguageLinks
; }
203 function addLanguageLinks($newLinkArray) {
204 $this->mLanguageLinks +
= $newLinkArray;
206 function setLanguageLinks($newLinkArray) {
207 $this->mLanguageLinks
= $newLinkArray;
210 function getCategoryLinks() {
211 return $this->mCategoryLinks
;
215 * Add an array of categories, with names in the keys
217 function addCategoryLinks($categories) {
218 global $wgUser, $wgContLang;
220 if ( !is_array( $categories ) ) {
223 # Add the links to the link cache in a batch
224 $arr = array( NS_CATEGORY
=> $categories );
226 $lb->setArray( $arr );
229 $sk =& $wgUser->getSkin();
230 foreach ( $categories as $category => $arbitrary ) {
231 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
232 $text = $wgContLang->convertHtml( $title->getText() );
233 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
237 function setCategoryLinks($categories) {
238 $this->mCategoryLinks
= array();
239 $this->addCategoryLinks($categories);
242 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
243 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
245 function addHTML( $text ) { $this->mBodytext
.= $text; }
246 function clearHTML() { $this->mBodytext
= ''; }
247 function getHTML() { return $this->mBodytext
; }
248 function debug( $text ) { $this->mDebugtext
.= $text; }
251 function setParserOptions( $options ) {
252 return $this->ParserOptions( $options );
255 function ParserOptions( $options = null ) {
256 return wfSetVar( $this->mParserOptions
, $options );
260 * Set the revision ID which will be seen by the wiki text parser
261 * for things such as embedded {{REVISIONID}} variable use.
262 * @param mixed $revid an integer, or NULL
263 * @return mixed previous value
265 function setRevisionId( $revid ) {
266 $val = is_null( $revid ) ?
null : intval( $revid );
267 return wfSetVar( $this->mRevisionId
, $val );
271 * Convert wikitext to HTML and add it to the buffer
272 * Default assumes that the current page title will
275 function addWikiText( $text, $linestart = true ) {
277 $this->addWikiTextTitle($text, $wgTitle, $linestart);
280 function addWikiTextWithTitle($text, &$title, $linestart = true) {
281 $this->addWikiTextTitle($text, $title, $linestart);
284 function addWikiTextTitle($text, &$title, $linestart) {
286 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
287 $linestart, true, $this->mRevisionId
);
288 $this->addParserOutput( $parserOutput );
291 function addParserOutputNoText( &$parserOutput ) {
292 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
293 $this->addCategoryLinks( $parserOutput->getCategories() );
294 $this->addKeywords( $parserOutput );
295 if ( $parserOutput->getCacheTime() == -1 ) {
296 $this->enableClientCache( false );
298 if ( $parserOutput->mHTMLtitle
!= "" ) {
299 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
300 $this->mSubtitle
.= $parserOutput->mSubtitle
;
304 function addParserOutput( &$parserOutput ) {
305 $this->addParserOutputNoText( $parserOutput );
306 $this->addHTML( $parserOutput->getText() );
310 * Add wikitext to the buffer, assuming that this is the primary text for a page view
311 * Saves the text into the parser cache if possible
313 function addPrimaryWikiText( $text, $article, $cache = true ) {
314 global $wgParser, $wgUser;
316 $this->mParserOptions
->setTidy(true);
317 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
318 $this->mParserOptions
, true, true, $this->mRevisionId
);
319 $this->mParserOptions
->setTidy(false);
320 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
321 $parserCache =& ParserCache
::singleton();
322 $parserCache->save( $parserOutput, $article, $wgUser );
325 $this->addParserOutputNoText( $parserOutput );
326 $text = $parserOutput->getText();
327 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
328 $parserOutput->setText( $text );
329 $this->addHTML( $parserOutput->getText() );
333 * For anything that isn't primary text or interface message
335 function addSecondaryWikiText( $text, $linestart = true ) {
337 $this->mParserOptions
->setTidy(true);
338 $this->addWikiTextTitle($text, $wgTitle, $linestart);
339 $this->mParserOptions
->setTidy(false);
344 * Add the output of a QuickTemplate to the output buffer
345 * @param QuickTemplate $template
347 function addTemplate( &$template ) {
349 $template->execute();
350 $this->addHTML( ob_get_contents() );
355 * Parse wikitext and return the HTML.
357 function parse( $text, $linestart = true, $interface = false ) {
358 global $wgParser, $wgTitle;
359 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(true); }
360 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
361 $linestart, true, $this->mRevisionId
);
362 if ( $interface) { $this->mParserOptions
->setInterfaceMessage(false); }
363 return $parserOutput->getText();
372 function tryParserCache( &$article, $user ) {
373 $parserCache =& ParserCache
::singleton();
374 $parserOutput = $parserCache->get( $article, $user );
375 if ( $parserOutput !== false ) {
376 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
377 $this->addCategoryLinks( $parserOutput->getCategories() );
378 $this->addKeywords( $parserOutput );
379 $text = $parserOutput->getText();
380 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
381 $this->addHTML( $text );
382 $t = $parserOutput->getTitleText();
384 $this->setPageTitle( $t );
393 * Set the maximum cache time on the Squid in seconds
396 function setSquidMaxage( $maxage ) {
397 $this->mSquidMaxage
= $maxage;
401 * Use enableClientCache(false) to force it to send nocache headers
404 function enableClientCache( $state ) {
405 return wfSetVar( $this->mEnableClientCache
, $state );
408 function uncacheableBecauseRequestvars() {
410 return $wgRequest->getText('useskin', false) === false
411 && $wgRequest->getText('uselang', false) === false;
414 function sendCacheControl() {
415 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
418 header("ETag: $this->mETag");
420 # don't serve compressed data to clients who can't handle it
421 # maintain different caches for logged-in users and non-logged in ones
422 header( 'Vary: Accept-Encoding, Cookie' );
423 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
424 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
425 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
428 # We'll purge the proxy cache explicitly, but require end user agents
429 # to revalidate against the proxy on each visit.
430 # Surrogate-Control controls our Squid, Cache-Control downstream caches
431 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
432 # start with a shorter timeout for initial testing
433 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
434 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
435 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
437 # We'll purge the proxy cache for anons explicitly, but require end user agents
438 # to revalidate against the proxy on each visit.
439 # IMPORTANT! The Squid needs to replace the Cache-Control header with
440 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
441 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
442 # start with a shorter timeout for initial testing
443 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
444 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
447 # We do want clients to cache if they can, but they *must* check for updates
448 # on revisiting the page.
449 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
450 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
451 header( "Cache-Control: private, must-revalidate, max-age=0" );
453 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
455 wfDebug( "** no caching **\n", false );
457 # In general, the absence of a last modified header should be enough to prevent
458 # the client from using its cache. We send a few other things just to make sure.
459 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
460 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
461 header( 'Pragma: no-cache' );
466 * Finally, all the text has been munged and accumulated into
467 * the object, let's actually output it:
470 global $wgUser, $wgOutputEncoding;
471 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
472 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
474 if( $this->mDoNothing
){
477 $fname = 'OutputPage::output';
478 wfProfileIn( $fname );
479 $sk = $wgUser->getSkin();
482 $this->addScript( "<script type=\"{$wgJsMimeType}\">
483 var wgScriptPath=\"{$wgScriptPath}\";
484 var wgServer=\"{$wgServer}\";
486 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
489 if ( '' != $this->mRedirect
) {
490 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
491 # Standards require redirect URLs to be absolute
493 $this->mRedirect
= $wgServer . $this->mRedirect
;
495 if( $this->mRedirectCode
== '301') {
496 if( !$wgDebugRedirects ) {
497 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
499 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
502 $this->sendCacheControl();
504 if( $wgDebugRedirects ) {
505 $url = htmlspecialchars( $this->mRedirect
);
506 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
507 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
508 print "</body>\n</html>\n";
510 header( 'Location: '.$this->mRedirect
);
512 wfProfileOut( $fname );
515 elseif ( $this->mStatusCode
)
517 $statusMessage = array(
519 101 => 'Switching Protocols',
524 203 => 'Non-Authoritative Information',
526 205 => 'Reset Content',
527 206 => 'Partial Content',
528 207 => 'Multi-Status',
529 300 => 'Multiple Choices',
530 301 => 'Moved Permanently',
533 304 => 'Not Modified',
535 307 => 'Temporary Redirect',
536 400 => 'Bad Request',
537 401 => 'Unauthorized',
538 402 => 'Payment Required',
541 405 => 'Method Not Allowed',
542 406 => 'Not Acceptable',
543 407 => 'Proxy Authentication Required',
544 408 => 'Request Timeout',
547 411 => 'Length Required',
548 412 => 'Precondition Failed',
549 413 => 'Request Entity Too Large',
550 414 => 'Request-URI Too Large',
551 415 => 'Unsupported Media Type',
552 416 => 'Request Range Not Satisfiable',
553 417 => 'Expectation Failed',
554 422 => 'Unprocessable Entity',
556 424 => 'Failed Dependency',
557 500 => 'Internal Server Error',
558 501 => 'Not Implemented',
559 502 => 'Bad Gateway',
560 503 => 'Service Unavailable',
561 504 => 'Gateway Timeout',
562 505 => 'HTTP Version Not Supported',
563 507 => 'Insufficient Storage'
566 if ( $statusMessage[$this->mStatusCode
] )
567 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
570 # Buffer output; final headers may depend on later processing
573 # Disable temporary placeholders, so that the skin produces HTML
574 $sk->postParseLinkColour( false );
576 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
577 header( 'Content-language: '.$wgContLanguageCode );
579 if ($this->mArticleBodyOnly
) {
580 $this->out($this->mBodytext
);
582 wfProfileIn( 'Output-skin' );
583 $sk->outputPage( $this );
584 wfProfileOut( 'Output-skin' );
587 $this->sendCacheControl();
589 wfProfileOut( $fname );
592 function out( $ins ) {
593 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
594 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
597 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
598 if ( false === $outs ) { $outs = $ins; }
603 function setEncodings() {
604 global $wgInputEncoding, $wgOutputEncoding;
605 global $wgUser, $wgContLang;
607 $wgInputEncoding = strtolower( $wgInputEncoding );
609 if( $wgUser->getOption( 'altencoding' ) ) {
610 $wgContLang->setAltEncoding();
614 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
615 $wgOutputEncoding = strtolower( $wgOutputEncoding );
618 $wgOutputEncoding = $wgInputEncoding;
622 * Returns a HTML comment with the elapsed time since request.
623 * This method has no side effects.
624 * Use wfReportTime() instead.
628 function reportTime() {
629 $time = wfReportTime();
634 * Produce a "user is blocked" page
636 function blockedPage() {
637 global $wgUser, $wgContLang, $wgTitle;
639 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
640 $this->setRobotpolicy( 'noindex,nofollow' );
641 $this->setArticleRelated( false );
643 $id = $wgUser->blockedBy();
644 $reason = $wgUser->blockedFor();
647 if ( is_numeric( $id ) ) {
648 $name = User
::whoIs( $id );
652 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
654 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
656 # Don't auto-return to special pages
657 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
658 $this->returnToMain( false, $return );
662 * Note: these arguments are keys into wfMsg(), not text!
664 function errorpage( $title, $msg ) {
667 $this->mDebugtext
.= 'Original title: ' .
668 $wgTitle->getPrefixedText() . "\n";
669 $this->setPageTitle( wfMsg( $title ) );
670 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
671 $this->setRobotpolicy( 'noindex,nofollow' );
672 $this->setArticleRelated( false );
673 $this->enableClientCache( false );
674 $this->mRedirect
= '';
676 $this->mBodytext
= '';
677 $this->addWikiText( wfMsg( $msg ) );
678 $this->returnToMain( false );
685 * Display an error page indicating that a given version of MediaWiki is
688 * @param mixed $version The version of MediaWiki needed to use the page
690 function versionRequired( $version ) {
691 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
692 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
693 $this->setRobotpolicy( 'noindex,nofollow' );
694 $this->setArticleRelated( false );
695 $this->mBodytext
= '';
697 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
698 $this->returnToMain();
702 * Display an error page noting that a given permission bit is required.
703 * This should generally replace the sysopRequired, developerRequired etc.
704 * @param string $permission key required
706 function permissionRequired( $permission ) {
709 $this->setPageTitle( wfMsg( 'badaccess' ) );
710 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
711 $this->setRobotpolicy( 'noindex,nofollow' );
712 $this->setArticleRelated( false );
713 $this->mBodytext
= '';
715 $sk = $wgUser->getSkin();
716 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
717 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
718 $this->returnToMain();
724 function sysopRequired() {
727 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
728 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
729 $this->setRobotpolicy( 'noindex,nofollow' );
730 $this->setArticleRelated( false );
731 $this->mBodytext
= '';
733 $sk = $wgUser->getSkin();
734 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
735 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
736 $this->returnToMain();
742 function developerRequired() {
745 $this->setPageTitle( wfMsg( 'developertitle' ) );
746 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
747 $this->setRobotpolicy( 'noindex,nofollow' );
748 $this->setArticleRelated( false );
749 $this->mBodytext
= '';
751 $sk = $wgUser->getSkin();
752 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
753 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
754 $this->returnToMain();
757 function loginToUse() {
758 global $wgUser, $wgTitle, $wgContLang;
760 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
761 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
762 $this->setRobotpolicy( 'noindex,nofollow' );
763 $this->setArticleFlag( false );
764 $this->mBodytext
= '';
765 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
766 $sk = $wgUser->getSkin();
767 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
768 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
769 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
771 # We put a comment in the .html file so a Sysop can diagnose the page the
773 $this->addHTML( "\n<!--" .
774 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
776 $wgTitle->getDBkey() . '-->' );
777 $this->returnToMain(); # Flip back to the main page after 10 seconds.
780 function databaseError( $fname, $sql, $error, $errno ) {
781 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
783 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
784 $this->setRobotpolicy( 'noindex,nofollow' );
785 $this->setArticleRelated( false );
786 $this->enableClientCache( false );
787 $this->mRedirect
= '';
789 if( !$wgShowSQLErrors ) {
790 $sql = wfMsg( 'sqlhidden' );
793 if ( $wgCommandLineMode ) {
794 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
795 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
797 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
798 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
801 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
805 $this->mBodytext
= $msg;
810 function readOnlyPage( $source = null, $protected = false ) {
811 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
813 $this->setRobotpolicy( 'noindex,nofollow' );
814 $this->setArticleRelated( false );
817 $skin = $wgUser->getSkin();
818 $this->setPageTitle( wfMsg( 'viewsource' ) );
819 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
821 # Determine if protection is due to the page being a system message
822 # and show an appropriate explanation
823 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
&& !$wgUser->isAllowed( 'editinterface' ) ) {
824 $this->addWikiText( wfMsg( 'protectedinterface' ) );
826 $this->addWikiText( wfMsg( 'protectedtext' ) );
829 $this->setPageTitle( wfMsg( 'readonly' ) );
831 $reason = $wgReadOnly;
833 $reason = file_get_contents( $wgReadOnlyFile );
835 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
838 if( is_string( $source ) ) {
839 if( strcmp( $source, '' ) == 0 ) {
841 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
842 $source = wfMsgWeirdKey ( $wgTitle->getText() );
844 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
847 $rows = $wgUser->getOption( 'rows' );
848 $cols = $wgUser->getOption( 'cols' );
850 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
851 htmlspecialchars( $source ) . "\n</textarea>";
852 $this->addHTML( $text );
855 $this->returnToMain( false );
858 function fatalError( $message ) {
859 $this->setPageTitle( wfMsg( "internalerror" ) );
860 $this->setRobotpolicy( "noindex,nofollow" );
861 $this->setArticleRelated( false );
862 $this->enableClientCache( false );
863 $this->mRedirect
= '';
865 $this->mBodytext
= $message;
870 function unexpectedValueError( $name, $val ) {
871 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
874 function fileCopyError( $old, $new ) {
875 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
878 function fileRenameError( $old, $new ) {
879 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
882 function fileDeleteError( $name ) {
883 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
886 function fileNotFoundError( $name ) {
887 $this->fatalError( wfMsg( 'filenotfound', $name ) );
891 * return from error messages or notes
892 * @param $auto automatically redirect the user after 10 seconds
893 * @param $returnto page title to return to. Default is Main Page.
895 function returnToMain( $auto = true, $returnto = NULL ) {
896 global $wgUser, $wgOut, $wgRequest;
898 if ( $returnto == NULL ) {
899 $returnto = $wgRequest->getText( 'returnto' );
901 $returnto = htmlspecialchars( $returnto );
903 $sk = $wgUser->getSkin();
904 if ( '' == $returnto ) {
905 $returnto = wfMsgForContent( 'mainpage' );
907 $link = $sk->makeLinkObj( Title
::newFromText( $returnto ), '' );
909 $r = wfMsg( 'returnto', $link );
911 $titleObj = Title
::newFromText( $returnto );
912 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
914 $wgOut->addHTML( "\n<p>$r</p>\n" );
918 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
919 * and uses the first 10 of them for META keywords
921 function addKeywords( &$parserOutput ) {
923 $this->addKeyword( $wgTitle->getPrefixedText() );
925 $links2d =& $parserOutput->getLinks();
926 if ( !is_array( $links2d ) ) {
929 foreach ( $links2d as $ns => $dbkeys ) {
930 foreach( $dbkeys as $dbkey => $id ) {
931 $this->addKeyword( $dbkey );
932 if ( ++
$count > 10 ) {
943 function headElement() {
944 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
945 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
947 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
948 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
953 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
955 if ( '' == $this->getHTMLTitle() ) {
956 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
959 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
960 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
961 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
962 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
964 $ret .= $this->getHeadLinks();
966 if( $this->isPrintable() ) {
969 $media = "media='print'";
971 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
972 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
974 $sk = $wgUser->getSkin();
975 $ret .= $sk->getHeadScripts();
976 $ret .= $this->mScripts
;
977 $ret .= $sk->getUserStyles();
979 if ($wgUseTrackbacks && $this->isArticleRelated())
980 $ret .= $wgTitle->trackbackRDF();
986 function getHeadLinks() {
989 foreach ( $this->mMetatags
as $tag ) {
990 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
992 $tag[0] = substr( $tag[0], 5 );
996 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
999 $p = $this->mRobotpolicy
;
1000 if( $p !== '' && $p != 'index,follow' ) {
1001 // http://www.robotstxt.org/wc/meta-user.html
1002 // Only show if it's different from the default robots policy
1003 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1006 if ( count( $this->mKeywords
) > 0 ) {
1011 $ret .= "<meta name=\"keywords\" content=\"" .
1012 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1014 foreach ( $this->mLinktags
as $tag ) {
1016 foreach( $tag as $attr => $val ) {
1017 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1021 if( $this->isSyndicated() ) {
1022 # FIXME: centralize the mime-type and name information in Feed.php
1023 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1024 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1025 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1026 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1033 * Turn off regular page output and return an error reponse
1034 * for when rate limiting has triggered.
1038 function rateLimited() {
1041 wfHttpError( 500, 'Internal Server Error',
1042 'Sorry, the server has encountered an internal error. ' .
1043 'Please wait a moment and hit "refresh" to submit the request again.' );