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;
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
= '';
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 # Add the links to the link cache in a batch
221 $arr = array( NS_CATEGORY
=> $categories );
223 $lb->setArray( $arr );
226 $sk =& $wgUser->getSkin();
227 foreach ( $categories as $category => $arbitrary ) {
228 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
229 $text = $wgContLang->convertHtml( $title->getText() );
230 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
234 function setCategoryLinks($categories) {
235 $this->mCategoryLinks
= array();
236 $this->addCategoryLinks($categories);
239 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
240 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
242 function addHTML( $text ) { $this->mBodytext
.= $text; }
243 function clearHTML() { $this->mBodytext
= ''; }
244 function getHTML() { return $this->mBodytext
; }
245 function debug( $text ) { $this->mDebugtext
.= $text; }
248 function setParserOptions( $options ) {
249 return $this->ParserOptions( $options );
252 function ParserOptions( $options = null ) {
253 return wfSetVar( $this->mParserOptions
, $options );
257 * Set the revision ID which will be seen by the wiki text parser
258 * for things such as embedded {{REVISIONID}} variable use.
259 * @param mixed $revid an integer, or NULL
260 * @return mixed previous value
262 function setRevisionId( $revid ) {
263 $val = is_null( $revid ) ?
null : intval( $revid );
264 return wfSetVar( $this->mRevisionId
, $val );
268 * Convert wikitext to HTML and add it to the buffer
269 * Default assumes that the current page title will
272 function addWikiText( $text, $linestart = true ) {
274 $this->addWikiTextTitle($text, $wgTitle, $linestart);
277 function addWikiTextWithTitle($text, &$title, $linestart = true) {
278 $this->addWikiTextTitle($text, $title, $linestart);
281 function addWikiTextTitle($text, &$title, $linestart) {
283 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
284 $linestart, true, $this->mRevisionId
);
285 $this->addParserOutput( $parserOutput );
288 function addParserOutputNoText( &$parserOutput ) {
289 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
290 $this->addCategoryLinks( $parserOutput->getCategories() );
291 $this->addKeywords( $parserOutput );
292 if ( $parserOutput->getCacheTime() == -1 ) {
293 $this->enableClientCache( false );
297 function addParserOutput( &$parserOutput ) {
298 $this->addParserOutputNoText( $parserOutput );
299 $this->addHTML( $parserOutput->getText() );
303 * Add wikitext to the buffer, assuming that this is the primary text for a page view
304 * Saves the text into the parser cache if possible
306 function addPrimaryWikiText( $text, $article, $cache = true ) {
307 global $wgParser, $wgUser;
309 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
310 $this->mParserOptions
, true, true, $this->mRevisionId
);
312 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
313 $parserCache =& ParserCache
::singleton();
314 $parserCache->save( $parserOutput, $article, $wgUser );
317 $this->addParserOutputNoText( $parserOutput );
318 $text = $parserOutput->getText();
319 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
320 $parserOutput->setText( $text );
321 $this->addHTML( $parserOutput->getText() );
325 * Add the output of a QuickTemplate to the output buffer
326 * @param QuickTemplate $template
328 function addTemplate( &$template ) {
330 $template->execute();
331 $this->addHTML( ob_get_contents() );
336 * Parse wikitext and return the HTML. This is for special pages that add the text later
338 function parse( $text, $linestart = true ) {
339 global $wgParser, $wgTitle;
340 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
341 $linestart, true, $this->mRevisionId
);
342 return $parserOutput->getText();
351 function tryParserCache( $article, $user ) {
352 $parserCache =& ParserCache
::singleton();
353 $parserOutput = $parserCache->get( $article, $user );
354 if ( $parserOutput !== false ) {
355 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
356 $this->addCategoryLinks( $parserOutput->getCategories() );
357 $this->addKeywords( $parserOutput );
358 $text = $parserOutput->getText();
359 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
360 $this->addHTML( $text );
361 $t = $parserOutput->getTitleText();
363 $this->setPageTitle( $t );
372 * Set the maximum cache time on the Squid in seconds
375 function setSquidMaxage( $maxage ) {
376 $this->mSquidMaxage
= $maxage;
380 * Use enableClientCache(false) to force it to send nocache headers
383 function enableClientCache( $state ) {
384 return wfSetVar( $this->mEnableClientCache
, $state );
387 function uncacheableBecauseRequestvars() {
389 return $wgRequest->getText('useskin', false) === false
390 && $wgRequest->getText('uselang', false) === false;
393 function sendCacheControl() {
394 global $wgUseSquid, $wgUseESI, $wgSquidMaxage;
397 header("ETag: $this->mETag");
399 # don't serve compressed data to clients who can't handle it
400 # maintain different caches for logged-in users and non-logged in ones
401 header( 'Vary: Accept-Encoding, Cookie' );
402 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
403 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
404 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
407 # We'll purge the proxy cache explicitly, but require end user agents
408 # to revalidate against the proxy on each visit.
409 # Surrogate-Control controls our Squid, Cache-Control downstream caches
410 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
411 # start with a shorter timeout for initial testing
412 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
413 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
414 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
416 # We'll purge the proxy cache for anons explicitly, but require end user agents
417 # to revalidate against the proxy on each visit.
418 # IMPORTANT! The Squid needs to replace the Cache-Control header with
419 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
420 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
421 # start with a shorter timeout for initial testing
422 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
423 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
426 # We do want clients to cache if they can, but they *must* check for updates
427 # on revisiting the page.
428 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
429 header( "Expires: -1" );
430 header( "Cache-Control: private, must-revalidate, max-age=0" );
432 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
434 wfDebug( "** no caching **\n", false );
436 # In general, the absence of a last modified header should be enough to prevent
437 # the client from using its cache. We send a few other things just to make sure.
438 header( 'Expires: -1' );
439 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
440 header( 'Pragma: no-cache' );
445 * Finally, all the text has been munged and accumulated into
446 * the object, let's actually output it:
449 global $wgUser, $wgOutputEncoding;
450 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType, $wgProfiler;
452 if( $this->mDoNothing
){
455 $fname = 'OutputPage::output';
456 wfProfileIn( $fname );
457 $sk = $wgUser->getSkin();
459 if ( '' != $this->mRedirect
) {
460 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
461 # Standards require redirect URLs to be absolute
463 $this->mRedirect
= $wgServer . $this->mRedirect
;
465 if( $this->mRedirectCode
== '301') {
466 if( !$wgDebugRedirects ) {
467 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
469 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
472 $this->sendCacheControl();
474 if( $wgDebugRedirects ) {
475 $url = htmlspecialchars( $this->mRedirect
);
476 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
477 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
478 print "</body>\n</html>\n";
480 header( 'Location: '.$this->mRedirect
);
482 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
483 wfProfileOut( $fname );
486 elseif ( $this->mStatusCode
)
488 $statusMessage = array(
490 101 => 'Switching Protocols',
495 203 => 'Non-Authoritative Information',
497 205 => 'Reset Content',
498 206 => 'Partial Content',
499 207 => 'Multi-Status',
500 300 => 'Multiple Choices',
501 301 => 'Moved Permanently',
504 304 => 'Not Modified',
506 307 => 'Temporary Redirect',
507 400 => 'Bad Request',
508 401 => 'Unauthorized',
509 402 => 'Payment Required',
512 405 => 'Method Not Allowed',
513 406 => 'Not Acceptable',
514 407 => 'Proxy Authentication Required',
515 408 => 'Request Timeout',
518 411 => 'Length Required',
519 412 => 'Precondition Failed',
520 413 => 'Request Entity Too Large',
521 414 => 'Request-URI Too Large',
522 415 => 'Unsupported Media Type',
523 416 => 'Request Range Not Satisfiable',
524 417 => 'Expectation Failed',
525 422 => 'Unprocessable Entity',
527 424 => 'Failed Dependency',
528 500 => 'Internal Server Error',
529 501 => 'Not Implemented',
530 502 => 'Bad Gateway',
531 503 => 'Service Unavailable',
532 504 => 'Gateway Timeout',
533 505 => 'HTTP Version Not Supported',
534 507 => 'Insufficient Storage'
537 if ( $statusMessage[$this->mStatusCode
] )
538 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
541 # Buffer output; final headers may depend on later processing
544 # Disable temporary placeholders, so that the skin produces HTML
545 $sk->postParseLinkColour( false );
547 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
548 header( 'Content-language: '.$wgContLanguageCode );
550 if ($this->mArticleBodyOnly
) {
551 $this->out($this->mBodytext
);
553 wfProfileIn( 'Output-skin' );
554 $sk->outputPage( $this );
555 wfProfileOut( 'Output-skin' );
558 $this->sendCacheControl();
560 wfProfileOut( $fname );
563 function out( $ins ) {
564 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
565 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
568 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
569 if ( false === $outs ) { $outs = $ins; }
574 function setEncodings() {
575 global $wgInputEncoding, $wgOutputEncoding;
576 global $wgUser, $wgContLang;
578 $wgInputEncoding = strtolower( $wgInputEncoding );
580 if( $wgUser->getOption( 'altencoding' ) ) {
581 $wgContLang->setAltEncoding();
585 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
586 $wgOutputEncoding = strtolower( $wgOutputEncoding );
589 $wgOutputEncoding = $wgInputEncoding;
593 * Returns a HTML comment with the elapsed time since request.
594 * This method has no side effects.
595 * Use wfReportTime() instead.
599 function reportTime() {
600 $time = wfReportTime();
605 * Produce a "user is blocked" page
607 function blockedPage() {
608 global $wgUser, $wgContLang;
610 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
611 $this->setRobotpolicy( 'noindex,nofollow' );
612 $this->setArticleRelated( false );
614 $id = $wgUser->blockedBy();
615 $reason = $wgUser->blockedFor();
618 if ( is_numeric( $id ) ) {
619 $name = User
::whoIs( $id );
623 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
625 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
626 $this->returnToMain( false );
630 * Note: these arguments are keys into wfMsg(), not text!
632 function errorpage( $title, $msg ) {
635 $this->mDebugtext
.= 'Original title: ' .
636 $wgTitle->getPrefixedText() . "\n";
637 $this->setPageTitle( wfMsg( $title ) );
638 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
639 $this->setRobotpolicy( 'noindex,nofollow' );
640 $this->setArticleRelated( false );
641 $this->enableClientCache( false );
642 $this->mRedirect
= '';
644 $this->mBodytext
= '';
645 $this->addWikiText( wfMsg( $msg ) );
646 $this->returnToMain( false );
653 * Display an error page indicating that a given version of MediaWiki is
656 * @param mixed $version The version of MediaWiki needed to use the page
658 function versionRequired( $version ) {
661 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
662 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
663 $this->setRobotpolicy( 'noindex,nofollow' );
664 $this->setArticleRelated( false );
665 $this->mBodytext
= '';
667 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
668 $this->returnToMain();
672 * Display an error page noting that a given permission bit is required.
673 * This should generally replace the sysopRequired, developerRequired etc.
674 * @param string $permission key required
676 function permissionRequired( $permission ) {
679 $this->setPageTitle( wfMsg( 'badaccess' ) );
680 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
681 $this->setRobotpolicy( 'noindex,nofollow' );
682 $this->setArticleRelated( false );
683 $this->mBodytext
= '';
685 $sk = $wgUser->getSkin();
686 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
687 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
688 $this->returnToMain();
694 function sysopRequired() {
697 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
698 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
699 $this->setRobotpolicy( 'noindex,nofollow' );
700 $this->setArticleRelated( false );
701 $this->mBodytext
= '';
703 $sk = $wgUser->getSkin();
704 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
705 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
706 $this->returnToMain();
712 function developerRequired() {
715 $this->setPageTitle( wfMsg( 'developertitle' ) );
716 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
717 $this->setRobotpolicy( 'noindex,nofollow' );
718 $this->setArticleRelated( false );
719 $this->mBodytext
= '';
721 $sk = $wgUser->getSkin();
722 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
723 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
724 $this->returnToMain();
727 function loginToUse() {
728 global $wgUser, $wgTitle, $wgContLang;
730 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
731 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
732 $this->setRobotpolicy( 'noindex,nofollow' );
733 $this->setArticleFlag( false );
734 $this->mBodytext
= '';
735 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
736 $sk = $wgUser->getSkin();
737 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
738 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
739 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
741 # We put a comment in the .html file so a Sysop can diagnose the page the
743 $this->addHTML( "\n<!--" .
744 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
746 $wgTitle->getDBkey() . '-->' );
747 $this->returnToMain(); # Flip back to the main page after 10 seconds.
750 function databaseError( $fname, $sql, $error, $errno ) {
751 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
753 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
754 $this->setRobotpolicy( 'noindex,nofollow' );
755 $this->setArticleRelated( false );
756 $this->enableClientCache( false );
757 $this->mRedirect
= '';
759 if( !$wgShowSQLErrors ) {
760 $sql = wfMsg( 'sqlhidden' );
763 if ( $wgCommandLineMode ) {
764 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
765 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
767 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
768 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
771 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
775 $this->mBodytext
= $msg;
780 function readOnlyPage( $source = null, $protected = false ) {
781 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
783 $this->setRobotpolicy( 'noindex,nofollow' );
784 $this->setArticleRelated( false );
787 $this->setPageTitle( wfMsg( 'viewsource' ) );
788 $this->addWikiText( wfMsg( 'protectedtext' ) );
790 $this->setPageTitle( wfMsg( 'readonly' ) );
792 $reason = $wgReadOnly;
794 $reason = file_get_contents( $wgReadOnlyFile );
796 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
799 if( is_string( $source ) ) {
800 if( strcmp( $source, '' ) == 0 ) {
802 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
803 $source = wfMsgWeirdKey ( $wgTitle->getText() ) ;
805 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
808 $rows = $wgUser->getOption( 'rows' );
809 $cols = $wgUser->getOption( 'cols' );
810 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
811 htmlspecialchars( $source ) . "\n</textarea>";
812 $this->addHTML( $text );
815 $this->returnToMain( false );
818 function fatalError( $message ) {
819 $this->setPageTitle( wfMsg( "internalerror" ) );
820 $this->setRobotpolicy( "noindex,nofollow" );
821 $this->setArticleRelated( false );
822 $this->enableClientCache( false );
823 $this->mRedirect
= '';
825 $this->mBodytext
= $message;
830 function unexpectedValueError( $name, $val ) {
831 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
834 function fileCopyError( $old, $new ) {
835 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
838 function fileRenameError( $old, $new ) {
839 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
842 function fileDeleteError( $name ) {
843 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
846 function fileNotFoundError( $name ) {
847 $this->fatalError( wfMsg( 'filenotfound', $name ) );
851 * return from error messages or notes
852 * @param $auto automatically redirect the user after 10 seconds
853 * @param $returnto page title to return to. Default is Main Page.
855 function returnToMain( $auto = true, $returnto = NULL ) {
856 global $wgUser, $wgOut, $wgRequest;
858 if ( $returnto == NULL ) {
859 $returnto = $wgRequest->getText( 'returnto' );
861 $returnto = htmlspecialchars( $returnto );
863 $sk = $wgUser->getSkin();
864 if ( '' == $returnto ) {
865 $returnto = wfMsgForContent( 'mainpage' );
867 $link = $sk->makeKnownLink( $returnto, '' );
869 $r = wfMsg( 'returnto', $link );
871 $titleObj = Title
::newFromText( $returnto );
872 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
874 $wgOut->addHTML( "\n<p>$r</p>\n" );
878 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
879 * and uses the first 10 of them for META keywords
881 function addKeywords( &$parserOutput ) {
883 $this->addKeyword( $wgTitle->getPrefixedText() );
885 $links2d =& $parserOutput->getLinks();
886 foreach ( $links2d as $ns => $dbkeys ) {
887 foreach( $dbkeys as $dbkey => $id ) {
888 $this->addKeyword( $dbkey );
889 if ( ++
$count > 10 ) {
900 function headElement() {
901 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
902 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
904 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
905 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
910 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
912 if ( '' == $this->getHTMLTitle() ) {
913 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
916 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
917 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
918 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
919 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
921 $ret .= $this->getHeadLinks();
923 if( $this->isPrintable() ) {
926 $media = "media='print'";
928 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
929 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
931 $sk = $wgUser->getSkin();
932 $ret .= $sk->getHeadScripts();
933 $ret .= $this->mScripts
;
934 $ret .= $sk->getUserStyles();
936 if ($wgUseTrackbacks && $this->isArticleRelated())
937 $ret .= $wgTitle->trackbackRDF();
943 function getHeadLinks() {
944 global $wgRequest, $wgStylePath;
946 foreach ( $this->mMetatags
as $tag ) {
947 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
949 $tag[0] = substr( $tag[0], 5 );
953 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
956 $p = $this->mRobotpolicy
;
957 if( $p !== '' && $p != 'index,follow' ) {
958 // http://www.robotstxt.org/wc/meta-user.html
959 // Only show if it's different from the default robots policy
960 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
963 if ( count( $this->mKeywords
) > 0 ) {
968 $ret .= "<meta name=\"keywords\" content=\"" .
969 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
971 foreach ( $this->mLinktags
as $tag ) {
973 foreach( $tag as $attr => $val ) {
974 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
978 if( $this->isSyndicated() ) {
979 # FIXME: centralize the mime-type and name information in Feed.php
980 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
981 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
982 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
983 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
990 * Turn off regular page output and return an error reponse
991 * for when rate limiting has triggered.
995 function rateLimited() {
998 wfHttpError( 500, 'Internal Server Error',
999 'Sorry, the server has encountered an internal error. ' .
1000 'Please wait a moment and hit "refresh" to submit the request again.' );