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. This is for special pages that add the text later
357 function parse( $text, $linestart = true ) {
358 global $wgParser, $wgTitle;
359 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
360 $linestart, true, $this->mRevisionId
);
361 return $parserOutput->getText();
370 function tryParserCache( &$article, $user ) {
371 $parserCache =& ParserCache
::singleton();
372 $parserOutput = $parserCache->get( $article, $user );
373 if ( $parserOutput !== false ) {
374 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
375 $this->addCategoryLinks( $parserOutput->getCategories() );
376 $this->addKeywords( $parserOutput );
377 $text = $parserOutput->getText();
378 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
379 $this->addHTML( $text );
380 $t = $parserOutput->getTitleText();
382 $this->setPageTitle( $t );
391 * Set the maximum cache time on the Squid in seconds
394 function setSquidMaxage( $maxage ) {
395 $this->mSquidMaxage
= $maxage;
399 * Use enableClientCache(false) to force it to send nocache headers
402 function enableClientCache( $state ) {
403 return wfSetVar( $this->mEnableClientCache
, $state );
406 function uncacheableBecauseRequestvars() {
408 return $wgRequest->getText('useskin', false) === false
409 && $wgRequest->getText('uselang', false) === false;
412 function sendCacheControl() {
413 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
416 header("ETag: $this->mETag");
418 # don't serve compressed data to clients who can't handle it
419 # maintain different caches for logged-in users and non-logged in ones
420 header( 'Vary: Accept-Encoding, Cookie' );
421 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
422 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
423 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
426 # We'll purge the proxy cache explicitly, but require end user agents
427 # to revalidate against the proxy on each visit.
428 # Surrogate-Control controls our Squid, Cache-Control downstream caches
429 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
430 # start with a shorter timeout for initial testing
431 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
432 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
433 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
435 # We'll purge the proxy cache for anons explicitly, but require end user agents
436 # to revalidate against the proxy on each visit.
437 # IMPORTANT! The Squid needs to replace the Cache-Control header with
438 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
439 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
440 # start with a shorter timeout for initial testing
441 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
442 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
445 # We do want clients to cache if they can, but they *must* check for updates
446 # on revisiting the page.
447 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
448 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
449 header( "Cache-Control: private, must-revalidate, max-age=0" );
451 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
453 wfDebug( "** no caching **\n", false );
455 # In general, the absence of a last modified header should be enough to prevent
456 # the client from using its cache. We send a few other things just to make sure.
457 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
458 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
459 header( 'Pragma: no-cache' );
464 * Finally, all the text has been munged and accumulated into
465 * the object, let's actually output it:
468 global $wgUser, $wgOutputEncoding;
469 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
470 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
472 if( $this->mDoNothing
){
475 $fname = 'OutputPage::output';
476 wfProfileIn( $fname );
477 $sk = $wgUser->getSkin();
480 $this->addScript( "<script type=\"{$wgJsMimeType}\">
481 var wgScriptPath=\"{$wgScriptPath}\";
482 var wgServer=\"{$wgServer}\";
484 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
487 if ( '' != $this->mRedirect
) {
488 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
489 # Standards require redirect URLs to be absolute
491 $this->mRedirect
= $wgServer . $this->mRedirect
;
493 if( $this->mRedirectCode
== '301') {
494 if( !$wgDebugRedirects ) {
495 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
497 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
500 $this->sendCacheControl();
502 if( $wgDebugRedirects ) {
503 $url = htmlspecialchars( $this->mRedirect
);
504 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
505 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
506 print "</body>\n</html>\n";
508 header( 'Location: '.$this->mRedirect
);
510 wfProfileOut( $fname );
513 elseif ( $this->mStatusCode
)
515 $statusMessage = array(
517 101 => 'Switching Protocols',
522 203 => 'Non-Authoritative Information',
524 205 => 'Reset Content',
525 206 => 'Partial Content',
526 207 => 'Multi-Status',
527 300 => 'Multiple Choices',
528 301 => 'Moved Permanently',
531 304 => 'Not Modified',
533 307 => 'Temporary Redirect',
534 400 => 'Bad Request',
535 401 => 'Unauthorized',
536 402 => 'Payment Required',
539 405 => 'Method Not Allowed',
540 406 => 'Not Acceptable',
541 407 => 'Proxy Authentication Required',
542 408 => 'Request Timeout',
545 411 => 'Length Required',
546 412 => 'Precondition Failed',
547 413 => 'Request Entity Too Large',
548 414 => 'Request-URI Too Large',
549 415 => 'Unsupported Media Type',
550 416 => 'Request Range Not Satisfiable',
551 417 => 'Expectation Failed',
552 422 => 'Unprocessable Entity',
554 424 => 'Failed Dependency',
555 500 => 'Internal Server Error',
556 501 => 'Not Implemented',
557 502 => 'Bad Gateway',
558 503 => 'Service Unavailable',
559 504 => 'Gateway Timeout',
560 505 => 'HTTP Version Not Supported',
561 507 => 'Insufficient Storage'
564 if ( $statusMessage[$this->mStatusCode
] )
565 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
568 # Buffer output; final headers may depend on later processing
571 # Disable temporary placeholders, so that the skin produces HTML
572 $sk->postParseLinkColour( false );
574 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
575 header( 'Content-language: '.$wgContLanguageCode );
577 if ($this->mArticleBodyOnly
) {
578 $this->out($this->mBodytext
);
580 wfProfileIn( 'Output-skin' );
581 $sk->outputPage( $this );
582 wfProfileOut( 'Output-skin' );
585 $this->sendCacheControl();
587 wfProfileOut( $fname );
590 function out( $ins ) {
591 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
592 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
595 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
596 if ( false === $outs ) { $outs = $ins; }
601 function setEncodings() {
602 global $wgInputEncoding, $wgOutputEncoding;
603 global $wgUser, $wgContLang;
605 $wgInputEncoding = strtolower( $wgInputEncoding );
607 if( $wgUser->getOption( 'altencoding' ) ) {
608 $wgContLang->setAltEncoding();
612 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
613 $wgOutputEncoding = strtolower( $wgOutputEncoding );
616 $wgOutputEncoding = $wgInputEncoding;
620 * Returns a HTML comment with the elapsed time since request.
621 * This method has no side effects.
622 * Use wfReportTime() instead.
626 function reportTime() {
627 $time = wfReportTime();
632 * Produce a "user is blocked" page
634 function blockedPage() {
635 global $wgUser, $wgContLang;
637 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
638 $this->setRobotpolicy( 'noindex,nofollow' );
639 $this->setArticleRelated( false );
641 $id = $wgUser->blockedBy();
642 $reason = $wgUser->blockedFor();
645 if ( is_numeric( $id ) ) {
646 $name = User
::whoIs( $id );
650 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
652 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
653 $this->returnToMain( false );
657 * Note: these arguments are keys into wfMsg(), not text!
659 function errorpage( $title, $msg ) {
662 $this->mDebugtext
.= 'Original title: ' .
663 $wgTitle->getPrefixedText() . "\n";
664 $this->setPageTitle( wfMsg( $title ) );
665 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
666 $this->setRobotpolicy( 'noindex,nofollow' );
667 $this->setArticleRelated( false );
668 $this->enableClientCache( false );
669 $this->mRedirect
= '';
671 $this->mBodytext
= '';
672 $this->addWikiText( wfMsg( $msg ) );
673 $this->returnToMain( false );
680 * Display an error page indicating that a given version of MediaWiki is
683 * @param mixed $version The version of MediaWiki needed to use the page
685 function versionRequired( $version ) {
686 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
687 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
688 $this->setRobotpolicy( 'noindex,nofollow' );
689 $this->setArticleRelated( false );
690 $this->mBodytext
= '';
692 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
693 $this->returnToMain();
697 * Display an error page noting that a given permission bit is required.
698 * This should generally replace the sysopRequired, developerRequired etc.
699 * @param string $permission key required
701 function permissionRequired( $permission ) {
704 $this->setPageTitle( wfMsg( 'badaccess' ) );
705 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
706 $this->setRobotpolicy( 'noindex,nofollow' );
707 $this->setArticleRelated( false );
708 $this->mBodytext
= '';
710 $sk = $wgUser->getSkin();
711 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
712 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
713 $this->returnToMain();
719 function sysopRequired() {
722 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
723 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
724 $this->setRobotpolicy( 'noindex,nofollow' );
725 $this->setArticleRelated( false );
726 $this->mBodytext
= '';
728 $sk = $wgUser->getSkin();
729 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
730 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
731 $this->returnToMain();
737 function developerRequired() {
740 $this->setPageTitle( wfMsg( 'developertitle' ) );
741 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
742 $this->setRobotpolicy( 'noindex,nofollow' );
743 $this->setArticleRelated( false );
744 $this->mBodytext
= '';
746 $sk = $wgUser->getSkin();
747 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
748 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
749 $this->returnToMain();
752 function loginToUse() {
753 global $wgUser, $wgTitle, $wgContLang;
755 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
756 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
757 $this->setRobotpolicy( 'noindex,nofollow' );
758 $this->setArticleFlag( false );
759 $this->mBodytext
= '';
760 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
761 $sk = $wgUser->getSkin();
762 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
763 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
764 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
766 # We put a comment in the .html file so a Sysop can diagnose the page the
768 $this->addHTML( "\n<!--" .
769 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
771 $wgTitle->getDBkey() . '-->' );
772 $this->returnToMain(); # Flip back to the main page after 10 seconds.
775 function databaseError( $fname, $sql, $error, $errno ) {
776 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
778 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
779 $this->setRobotpolicy( 'noindex,nofollow' );
780 $this->setArticleRelated( false );
781 $this->enableClientCache( false );
782 $this->mRedirect
= '';
784 if( !$wgShowSQLErrors ) {
785 $sql = wfMsg( 'sqlhidden' );
788 if ( $wgCommandLineMode ) {
789 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
790 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
792 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
793 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
796 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
800 $this->mBodytext
= $msg;
805 function readOnlyPage( $source = null, $protected = false ) {
806 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
808 $this->setRobotpolicy( 'noindex,nofollow' );
809 $this->setArticleRelated( false );
812 $skin = $wgUser->getSkin();
813 $this->setPageTitle( wfMsg( 'viewsource' ) );
814 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
816 # Determine if protection is due to the page being a system message
817 # and show an appropriate explanation
818 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
&& !$wgUser->isAllowed( 'editinterface' ) ) {
819 $this->addWikiText( wfMsg( 'protectedinterface' ) );
821 $this->addWikiText( wfMsg( 'protectedtext' ) );
824 $this->setPageTitle( wfMsg( 'readonly' ) );
826 $reason = $wgReadOnly;
828 $reason = file_get_contents( $wgReadOnlyFile );
830 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
833 if( is_string( $source ) ) {
834 if( strcmp( $source, '' ) == 0 ) {
836 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
837 $source = wfMsgWeirdKey ( $wgTitle->getText() );
839 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
842 $rows = $wgUser->getOption( 'rows' );
843 $cols = $wgUser->getOption( 'cols' );
845 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
846 htmlspecialchars( $source ) . "\n</textarea>";
847 $this->addHTML( $text );
850 $this->returnToMain( false );
853 function fatalError( $message ) {
854 $this->setPageTitle( wfMsg( "internalerror" ) );
855 $this->setRobotpolicy( "noindex,nofollow" );
856 $this->setArticleRelated( false );
857 $this->enableClientCache( false );
858 $this->mRedirect
= '';
860 $this->mBodytext
= $message;
865 function unexpectedValueError( $name, $val ) {
866 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
869 function fileCopyError( $old, $new ) {
870 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
873 function fileRenameError( $old, $new ) {
874 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
877 function fileDeleteError( $name ) {
878 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
881 function fileNotFoundError( $name ) {
882 $this->fatalError( wfMsg( 'filenotfound', $name ) );
886 * return from error messages or notes
887 * @param $auto automatically redirect the user after 10 seconds
888 * @param $returnto page title to return to. Default is Main Page.
890 function returnToMain( $auto = true, $returnto = NULL ) {
891 global $wgUser, $wgOut, $wgRequest;
893 if ( $returnto == NULL ) {
894 $returnto = $wgRequest->getText( 'returnto' );
896 $returnto = htmlspecialchars( $returnto );
898 $sk = $wgUser->getSkin();
899 if ( '' == $returnto ) {
900 $returnto = wfMsgForContent( 'mainpage' );
902 $link = $sk->makeLinkObj( Title
::newFromText( $returnto ), '' );
904 $r = wfMsg( 'returnto', $link );
906 $titleObj = Title
::newFromText( $returnto );
907 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
909 $wgOut->addHTML( "\n<p>$r</p>\n" );
913 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
914 * and uses the first 10 of them for META keywords
916 function addKeywords( &$parserOutput ) {
918 $this->addKeyword( $wgTitle->getPrefixedText() );
920 $links2d =& $parserOutput->getLinks();
921 if ( !is_array( $links2d ) ) {
924 foreach ( $links2d as $ns => $dbkeys ) {
925 foreach( $dbkeys as $dbkey => $id ) {
926 $this->addKeyword( $dbkey );
927 if ( ++
$count > 10 ) {
938 function headElement() {
939 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
940 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
942 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
943 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
948 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
950 if ( '' == $this->getHTMLTitle() ) {
951 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
954 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
955 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
956 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
957 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
959 $ret .= $this->getHeadLinks();
961 if( $this->isPrintable() ) {
964 $media = "media='print'";
966 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
967 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
969 $sk = $wgUser->getSkin();
970 $ret .= $sk->getHeadScripts();
971 $ret .= $this->mScripts
;
972 $ret .= $sk->getUserStyles();
974 if ($wgUseTrackbacks && $this->isArticleRelated())
975 $ret .= $wgTitle->trackbackRDF();
981 function getHeadLinks() {
984 foreach ( $this->mMetatags
as $tag ) {
985 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
987 $tag[0] = substr( $tag[0], 5 );
991 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
994 $p = $this->mRobotpolicy
;
995 if( $p !== '' && $p != 'index,follow' ) {
996 // http://www.robotstxt.org/wc/meta-user.html
997 // Only show if it's different from the default robots policy
998 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1001 if ( count( $this->mKeywords
) > 0 ) {
1006 $ret .= "<meta name=\"keywords\" content=\"" .
1007 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1009 foreach ( $this->mLinktags
as $tag ) {
1011 foreach( $tag as $attr => $val ) {
1012 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1016 if( $this->isSyndicated() ) {
1017 # FIXME: centralize the mime-type and name information in Feed.php
1018 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1019 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1020 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1021 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1028 * Turn off regular page output and return an error reponse
1029 * for when rate limiting has triggered.
1033 function rateLimited() {
1036 wfHttpError( 500, 'Internal Server Error',
1037 'Sorry, the server has encountered an internal error. ' .
1038 'Please wait a moment and hit "refresh" to submit the request again.' );