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 );
300 function addParserOutput( &$parserOutput ) {
301 $this->addParserOutputNoText( $parserOutput );
302 $this->addHTML( $parserOutput->getText() );
306 * Add wikitext to the buffer, assuming that this is the primary text for a page view
307 * Saves the text into the parser cache if possible
309 function addPrimaryWikiText( $text, $article, $cache = true ) {
310 global $wgParser, $wgUser;
312 $this->mParserOptions
->setTidy(true);
313 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
314 $this->mParserOptions
, true, true, $this->mRevisionId
);
315 $this->mParserOptions
->setTidy(false);
316 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
317 $parserCache =& ParserCache
::singleton();
318 $parserCache->save( $parserOutput, $article, $wgUser );
321 $this->addParserOutputNoText( $parserOutput );
322 $text = $parserOutput->getText();
323 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
324 $parserOutput->setText( $text );
325 $this->addHTML( $parserOutput->getText() );
329 * For anything that isn't primary text or interface message
331 function addSecondaryWikiText( $text, $linestart = true ) {
333 $this->mParserOptions
->setTidy(true);
334 $this->addWikiTextTitle($text, $wgTitle, $linestart);
335 $this->mParserOptions
->setTidy(false);
340 * Add the output of a QuickTemplate to the output buffer
341 * @param QuickTemplate $template
343 function addTemplate( &$template ) {
345 $template->execute();
346 $this->addHTML( ob_get_contents() );
351 * Parse wikitext and return the HTML. This is for special pages that add the text later
353 function parse( $text, $linestart = true ) {
354 global $wgParser, $wgTitle;
355 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
356 $linestart, true, $this->mRevisionId
);
357 return $parserOutput->getText();
366 function tryParserCache( &$article, $user ) {
367 $parserCache =& ParserCache
::singleton();
368 $parserOutput = $parserCache->get( $article, $user );
369 if ( $parserOutput !== false ) {
370 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
371 $this->addCategoryLinks( $parserOutput->getCategories() );
372 $this->addKeywords( $parserOutput );
373 $text = $parserOutput->getText();
374 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
375 $this->addHTML( $text );
376 $t = $parserOutput->getTitleText();
378 $this->setPageTitle( $t );
387 * Set the maximum cache time on the Squid in seconds
390 function setSquidMaxage( $maxage ) {
391 $this->mSquidMaxage
= $maxage;
395 * Use enableClientCache(false) to force it to send nocache headers
398 function enableClientCache( $state ) {
399 return wfSetVar( $this->mEnableClientCache
, $state );
402 function uncacheableBecauseRequestvars() {
404 return $wgRequest->getText('useskin', false) === false
405 && $wgRequest->getText('uselang', false) === false;
408 function sendCacheControl() {
409 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
412 header("ETag: $this->mETag");
414 # don't serve compressed data to clients who can't handle it
415 # maintain different caches for logged-in users and non-logged in ones
416 header( 'Vary: Accept-Encoding, Cookie' );
417 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
418 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
419 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
422 # We'll purge the proxy cache explicitly, but require end user agents
423 # to revalidate against the proxy on each visit.
424 # Surrogate-Control controls our Squid, Cache-Control downstream caches
425 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
426 # start with a shorter timeout for initial testing
427 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
428 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
429 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
431 # We'll purge the proxy cache for anons explicitly, but require end user agents
432 # to revalidate against the proxy on each visit.
433 # IMPORTANT! The Squid needs to replace the Cache-Control header with
434 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
435 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
436 # start with a shorter timeout for initial testing
437 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
438 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
441 # We do want clients to cache if they can, but they *must* check for updates
442 # on revisiting the page.
443 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
444 header( "Expires: -1" );
445 header( "Cache-Control: private, must-revalidate, max-age=0" );
447 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
449 wfDebug( "** no caching **\n", false );
451 # In general, the absence of a last modified header should be enough to prevent
452 # the client from using its cache. We send a few other things just to make sure.
453 header( 'Expires: -1' );
454 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
455 header( 'Pragma: no-cache' );
460 * Finally, all the text has been munged and accumulated into
461 * the object, let's actually output it:
464 global $wgUser, $wgOutputEncoding;
465 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
466 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgScriptPath, $wgServer;
468 if( $this->mDoNothing
){
471 $fname = 'OutputPage::output';
472 wfProfileIn( $fname );
473 $sk = $wgUser->getSkin();
476 $this->addScript( "<script type=\"{$wgJsMimeType}\">
477 var wgScriptPath=\"{$wgScriptPath}\";
478 var wgServer=\"{$wgServer}\";
480 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
483 if ( '' != $this->mRedirect
) {
484 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
485 # Standards require redirect URLs to be absolute
487 $this->mRedirect
= $wgServer . $this->mRedirect
;
489 if( $this->mRedirectCode
== '301') {
490 if( !$wgDebugRedirects ) {
491 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
493 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
496 $this->sendCacheControl();
498 if( $wgDebugRedirects ) {
499 $url = htmlspecialchars( $this->mRedirect
);
500 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
501 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
502 print "</body>\n</html>\n";
504 header( 'Location: '.$this->mRedirect
);
506 wfProfileOut( $fname );
509 elseif ( $this->mStatusCode
)
511 $statusMessage = array(
513 101 => 'Switching Protocols',
518 203 => 'Non-Authoritative Information',
520 205 => 'Reset Content',
521 206 => 'Partial Content',
522 207 => 'Multi-Status',
523 300 => 'Multiple Choices',
524 301 => 'Moved Permanently',
527 304 => 'Not Modified',
529 307 => 'Temporary Redirect',
530 400 => 'Bad Request',
531 401 => 'Unauthorized',
532 402 => 'Payment Required',
535 405 => 'Method Not Allowed',
536 406 => 'Not Acceptable',
537 407 => 'Proxy Authentication Required',
538 408 => 'Request Timeout',
541 411 => 'Length Required',
542 412 => 'Precondition Failed',
543 413 => 'Request Entity Too Large',
544 414 => 'Request-URI Too Large',
545 415 => 'Unsupported Media Type',
546 416 => 'Request Range Not Satisfiable',
547 417 => 'Expectation Failed',
548 422 => 'Unprocessable Entity',
550 424 => 'Failed Dependency',
551 500 => 'Internal Server Error',
552 501 => 'Not Implemented',
553 502 => 'Bad Gateway',
554 503 => 'Service Unavailable',
555 504 => 'Gateway Timeout',
556 505 => 'HTTP Version Not Supported',
557 507 => 'Insufficient Storage'
560 if ( $statusMessage[$this->mStatusCode
] )
561 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
564 # Buffer output; final headers may depend on later processing
567 # Disable temporary placeholders, so that the skin produces HTML
568 $sk->postParseLinkColour( false );
570 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
571 header( 'Content-language: '.$wgContLanguageCode );
573 if ($this->mArticleBodyOnly
) {
574 $this->out($this->mBodytext
);
576 wfProfileIn( 'Output-skin' );
577 $sk->outputPage( $this );
578 wfProfileOut( 'Output-skin' );
581 $this->sendCacheControl();
583 wfProfileOut( $fname );
586 function out( $ins ) {
587 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
588 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
591 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
592 if ( false === $outs ) { $outs = $ins; }
597 function setEncodings() {
598 global $wgInputEncoding, $wgOutputEncoding;
599 global $wgUser, $wgContLang;
601 $wgInputEncoding = strtolower( $wgInputEncoding );
603 if( $wgUser->getOption( 'altencoding' ) ) {
604 $wgContLang->setAltEncoding();
608 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
609 $wgOutputEncoding = strtolower( $wgOutputEncoding );
612 $wgOutputEncoding = $wgInputEncoding;
616 * Returns a HTML comment with the elapsed time since request.
617 * This method has no side effects.
618 * Use wfReportTime() instead.
622 function reportTime() {
623 $time = wfReportTime();
628 * Produce a "user is blocked" page
630 function blockedPage() {
631 global $wgUser, $wgContLang;
633 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
634 $this->setRobotpolicy( 'noindex,nofollow' );
635 $this->setArticleRelated( false );
637 $id = $wgUser->blockedBy();
638 $reason = $wgUser->blockedFor();
641 if ( is_numeric( $id ) ) {
642 $name = User
::whoIs( $id );
646 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
648 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
649 $this->returnToMain( false );
653 * Note: these arguments are keys into wfMsg(), not text!
655 function errorpage( $title, $msg ) {
658 $this->mDebugtext
.= 'Original title: ' .
659 $wgTitle->getPrefixedText() . "\n";
660 $this->setPageTitle( wfMsg( $title ) );
661 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
662 $this->setRobotpolicy( 'noindex,nofollow' );
663 $this->setArticleRelated( false );
664 $this->enableClientCache( false );
665 $this->mRedirect
= '';
667 $this->mBodytext
= '';
668 $this->addWikiText( wfMsg( $msg ) );
669 $this->returnToMain( false );
676 * Display an error page indicating that a given version of MediaWiki is
679 * @param mixed $version The version of MediaWiki needed to use the page
681 function versionRequired( $version ) {
682 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
683 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
684 $this->setRobotpolicy( 'noindex,nofollow' );
685 $this->setArticleRelated( false );
686 $this->mBodytext
= '';
688 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
689 $this->returnToMain();
693 * Display an error page noting that a given permission bit is required.
694 * This should generally replace the sysopRequired, developerRequired etc.
695 * @param string $permission key required
697 function permissionRequired( $permission ) {
700 $this->setPageTitle( wfMsg( 'badaccess' ) );
701 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
702 $this->setRobotpolicy( 'noindex,nofollow' );
703 $this->setArticleRelated( false );
704 $this->mBodytext
= '';
706 $sk = $wgUser->getSkin();
707 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
708 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
709 $this->returnToMain();
715 function sysopRequired() {
718 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
719 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
720 $this->setRobotpolicy( 'noindex,nofollow' );
721 $this->setArticleRelated( false );
722 $this->mBodytext
= '';
724 $sk = $wgUser->getSkin();
725 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
726 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
727 $this->returnToMain();
733 function developerRequired() {
736 $this->setPageTitle( wfMsg( 'developertitle' ) );
737 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
738 $this->setRobotpolicy( 'noindex,nofollow' );
739 $this->setArticleRelated( false );
740 $this->mBodytext
= '';
742 $sk = $wgUser->getSkin();
743 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
744 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
745 $this->returnToMain();
748 function loginToUse() {
749 global $wgUser, $wgTitle, $wgContLang;
751 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
752 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
753 $this->setRobotpolicy( 'noindex,nofollow' );
754 $this->setArticleFlag( false );
755 $this->mBodytext
= '';
756 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
757 $sk = $wgUser->getSkin();
758 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
759 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
760 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
762 # We put a comment in the .html file so a Sysop can diagnose the page the
764 $this->addHTML( "\n<!--" .
765 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
767 $wgTitle->getDBkey() . '-->' );
768 $this->returnToMain(); # Flip back to the main page after 10 seconds.
771 function databaseError( $fname, $sql, $error, $errno ) {
772 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
774 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
775 $this->setRobotpolicy( 'noindex,nofollow' );
776 $this->setArticleRelated( false );
777 $this->enableClientCache( false );
778 $this->mRedirect
= '';
780 if( !$wgShowSQLErrors ) {
781 $sql = wfMsg( 'sqlhidden' );
784 if ( $wgCommandLineMode ) {
785 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
786 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
788 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
789 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
792 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
796 $this->mBodytext
= $msg;
801 function readOnlyPage( $source = null, $protected = false ) {
802 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
804 $this->setRobotpolicy( 'noindex,nofollow' );
805 $this->setArticleRelated( false );
808 $skin = $wgUser->getSkin();
809 $this->setPageTitle( wfMsg( 'viewsource' ) );
810 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
811 $this->addWikiText( wfMsg( 'protectedtext' ) );
813 $this->setPageTitle( wfMsg( 'readonly' ) );
815 $reason = $wgReadOnly;
817 $reason = file_get_contents( $wgReadOnlyFile );
819 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
822 if( is_string( $source ) ) {
823 if( strcmp( $source, '' ) == 0 ) {
825 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
826 $source = wfMsgWeirdKey ( $wgTitle->getText() );
828 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
831 $rows = $wgUser->getOption( 'rows' );
832 $cols = $wgUser->getOption( 'cols' );
833 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
834 htmlspecialchars( $source ) . "\n</textarea>";
835 $this->addHTML( $text );
838 $this->returnToMain( false );
841 function fatalError( $message ) {
842 $this->setPageTitle( wfMsg( "internalerror" ) );
843 $this->setRobotpolicy( "noindex,nofollow" );
844 $this->setArticleRelated( false );
845 $this->enableClientCache( false );
846 $this->mRedirect
= '';
848 $this->mBodytext
= $message;
853 function unexpectedValueError( $name, $val ) {
854 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
857 function fileCopyError( $old, $new ) {
858 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
861 function fileRenameError( $old, $new ) {
862 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
865 function fileDeleteError( $name ) {
866 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
869 function fileNotFoundError( $name ) {
870 $this->fatalError( wfMsg( 'filenotfound', $name ) );
874 * return from error messages or notes
875 * @param $auto automatically redirect the user after 10 seconds
876 * @param $returnto page title to return to. Default is Main Page.
878 function returnToMain( $auto = true, $returnto = NULL ) {
879 global $wgUser, $wgOut, $wgRequest;
881 if ( $returnto == NULL ) {
882 $returnto = $wgRequest->getText( 'returnto' );
884 $returnto = htmlspecialchars( $returnto );
886 $sk = $wgUser->getSkin();
887 if ( '' == $returnto ) {
888 $returnto = wfMsgForContent( 'mainpage' );
890 $link = $sk->makeLinkObj( Title
::newFromText( $returnto ), '' );
892 $r = wfMsg( 'returnto', $link );
894 $titleObj = Title
::newFromText( $returnto );
895 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
897 $wgOut->addHTML( "\n<p>$r</p>\n" );
901 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
902 * and uses the first 10 of them for META keywords
904 function addKeywords( &$parserOutput ) {
906 $this->addKeyword( $wgTitle->getPrefixedText() );
908 $links2d =& $parserOutput->getLinks();
909 if ( !is_array( $links2d ) ) {
912 foreach ( $links2d as $ns => $dbkeys ) {
913 foreach( $dbkeys as $dbkey => $id ) {
914 $this->addKeyword( $dbkey );
915 if ( ++
$count > 10 ) {
926 function headElement() {
927 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
928 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
930 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
931 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
936 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
938 if ( '' == $this->getHTMLTitle() ) {
939 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
942 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
943 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
944 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
945 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
947 $ret .= $this->getHeadLinks();
949 if( $this->isPrintable() ) {
952 $media = "media='print'";
954 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
955 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
957 $sk = $wgUser->getSkin();
958 $ret .= $sk->getHeadScripts();
959 $ret .= $this->mScripts
;
960 $ret .= $sk->getUserStyles();
962 if ($wgUseTrackbacks && $this->isArticleRelated())
963 $ret .= $wgTitle->trackbackRDF();
969 function getHeadLinks() {
972 foreach ( $this->mMetatags
as $tag ) {
973 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
975 $tag[0] = substr( $tag[0], 5 );
979 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
982 $p = $this->mRobotpolicy
;
983 if( $p !== '' && $p != 'index,follow' ) {
984 // http://www.robotstxt.org/wc/meta-user.html
985 // Only show if it's different from the default robots policy
986 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
989 if ( count( $this->mKeywords
) > 0 ) {
994 $ret .= "<meta name=\"keywords\" content=\"" .
995 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
997 foreach ( $this->mLinktags
as $tag ) {
999 foreach( $tag as $attr => $val ) {
1000 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1004 if( $this->isSyndicated() ) {
1005 # FIXME: centralize the mime-type and name information in Feed.php
1006 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1007 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1008 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1009 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
1016 * Turn off regular page output and return an error reponse
1017 * for when rate limiting has triggered.
1021 function rateLimited() {
1024 wfHttpError( 500, 'Internal Server Error',
1025 'Sorry, the server has encountered an internal error. ' .
1026 'Please wait a moment and hit "refresh" to submit the request again.' );