2 if ( ! defined( 'MEDIAWIKI' ) )
11 var $mMetatags, $mKeywords;
12 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
13 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
14 var $mSubtitle, $mRedirect, $mStatusCode;
15 var $mLastModified, $mETag, $mCategoryLinks;
16 var $mScripts, $mLinkColours, $mPageLinkTitle;
19 var $mSuppressQuickbar;
22 var $mContainsOldMagic, $mContainsNewMagic;
23 var $mIsArticleRelated;
24 protected $mParserOptions; // lazy initialised, use parserOptions()
25 var $mShowFeedLinks = false;
26 var $mEnableClientCache = true;
27 var $mArticleBodyOnly = false;
29 var $mNewSectionLink = false;
30 var $mNoGallery = false;
34 * Initialise private variables
36 function __construct() {
37 global $wgAllowUserJs;
38 $this->mAllowUserJs
= $wgAllowUserJs;
39 $this->mMetatags
= $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
= null;
51 $this->mSquidMaxage
= 0;
53 $this->mHeadItems
= array();
55 $this->mRevisionId
= null;
56 $this->mNewSectionLink
= false;
57 $this->mTemplateIds
= array();
60 public function redirect( $url, $responsecode = '302' ) {
61 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
62 $this->mRedirect
= str_replace( "\n", '', $url );
63 $this->mRedirectCode
= $responsecode;
67 * Set the HTTP status code to send with the output.
69 * @param int $statusCode
72 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
74 # To add an http-equiv meta tag, precede the name with "http:"
75 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
76 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
77 function addScript( $script ) { $this->mScripts
.= "\t\t".$script; }
78 function addStyle( $style ) {
79 global $wgStylePath, $wgStyleVersion;
82 'rel' => 'stylesheet',
83 'href' => $wgStylePath . '/' . $style . '?' . $wgStyleVersion ) );
87 * Add a self-contained script tag with the given contents
88 * @param string $script JavaScript text, no <script> tags
90 function addInlineScript( $script ) {
92 $this->mScripts
.= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
95 function getScript() {
96 return $this->mScripts
. $this->getHeadItems();
99 function getHeadItems() {
101 foreach ( $this->mHeadItems
as $item ) {
107 function addHeadItem( $name, $value ) {
108 $this->mHeadItems
[$name] = $value;
111 function setETag($tag) { $this->mETag
= $tag; }
112 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
113 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
115 function addLink( $linkarr ) {
116 # $linkarr should be an associative array of attributes. We'll escape on output.
117 array_push( $this->mLinktags
, $linkarr );
120 function addMetadataLink( $linkarr ) {
121 # note: buggy CC software only reads first "meta" link
122 static $haveMeta = false;
123 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
124 $this->addLink( $linkarr );
129 * checkLastModified tells the client to use the client-cached page if
130 * possible. If sucessful, the OutputPage is disabled so that
131 * any future call to OutputPage->output() have no effect.
133 * @return bool True iff cache-ok headers was sent.
135 function checkLastModified ( $timestamp ) {
136 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
137 $fname = 'OutputPage::checkLastModified';
139 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
140 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
143 if( !$wgCachePages ) {
144 wfDebug( "$fname: CACHE DISABLED\n", false );
147 if( $wgUser->getOption( 'nocache' ) ) {
148 wfDebug( "$fname: USER DISABLED CACHE\n", false );
152 $timestamp=wfTimestamp(TS_MW
,$timestamp);
153 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
155 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
156 # IE sends sizes after the date like this:
157 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
158 # this breaks strtotime().
159 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
161 wfSuppressWarnings(); // E_STRICT system time bitching
162 $modsinceTime = strtotime( $modsince );
165 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
166 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
167 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
168 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
169 # Make sure you're in a place you can leave when you call us!
170 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
171 $this->mLastModified
= $lastmod;
172 $this->sendCacheControl();
173 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
176 // Don't output a compressed blob when using ob_gzhandler;
177 // it's technically against HTTP spec and seems to confuse
178 // Firefox when the response gets split over two packets.
179 wfClearOutputBuffers();
183 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
184 $this->mLastModified
= $lastmod;
187 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
188 $this->mLastModified
= $lastmod;
192 function getPageTitleActionText () {
201 // Display title is already customized
204 return wfMsg('history_short');
206 // FIXME: bug 2735; not correct for special pages etc
207 return wfMsg('preview');
209 return wfMsg('info_short');
215 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
216 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
217 public function setPageTitle( $name ) {
218 global $action, $wgContLang;
219 $name = $wgContLang->convert($name, true);
220 $this->mPagetitle
= $name;
221 if(!empty($action)) {
222 $taction = $this->getPageTitleActionText();
223 if( !empty( $taction ) ) {
224 $name .= ' - '.$taction;
228 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
230 public function getHTMLTitle() { return $this->mHTMLtitle
; }
231 public function getPageTitle() { return $this->mPagetitle
; }
232 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
233 public function getSubtitle() { return $this->mSubtitle
; }
234 public function isArticle() { return $this->mIsarticle
; }
235 public function setPrintable() { $this->mPrintable
= true; }
236 public function isPrintable() { return $this->mPrintable
; }
237 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
238 public function isSyndicated() { return $this->mShowFeedLinks
; }
239 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
240 public function getOnloadHandler() { return $this->mOnloadHandler
; }
241 public function disable() { $this->mDoNothing
= true; }
243 public function setArticleRelated( $v ) {
244 $this->mIsArticleRelated
= $v;
246 $this->mIsarticle
= false;
249 public function setArticleFlag( $v ) {
250 $this->mIsarticle
= $v;
252 $this->mIsArticleRelated
= $v;
256 public function isArticleRelated() { return $this->mIsArticleRelated
; }
258 public function getLanguageLinks() { return $this->mLanguageLinks
; }
259 public function addLanguageLinks($newLinkArray) {
260 $this->mLanguageLinks +
= $newLinkArray;
262 public function setLanguageLinks($newLinkArray) {
263 $this->mLanguageLinks
= $newLinkArray;
266 public function getCategoryLinks() {
267 return $this->mCategoryLinks
;
271 * Add an array of categories, with names in the keys
273 public function addCategoryLinks($categories) {
274 global $wgUser, $wgContLang;
276 if ( !is_array( $categories ) ) {
279 # Add the links to the link cache in a batch
280 $arr = array( NS_CATEGORY
=> $categories );
282 $lb->setArray( $arr );
285 $sk = $wgUser->getSkin();
286 foreach ( $categories as $category => $unused ) {
287 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
288 $text = $wgContLang->convertHtml( $title->getText() );
289 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
293 public function setCategoryLinks($categories) {
294 $this->mCategoryLinks
= array();
295 $this->addCategoryLinks($categories);
298 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
299 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
301 public function disallowUserJs() { $this->mAllowUserJs
= false; }
302 public function isUserJsAllowed() { return $this->mAllowUserJs
; }
304 public function addHTML( $text ) { $this->mBodytext
.= $text; }
305 public function clearHTML() { $this->mBodytext
= ''; }
306 public function getHTML() { return $this->mBodytext
; }
307 public function debug( $text ) { $this->mDebugtext
.= $text; }
310 public function setParserOptions( $options ) {
311 return $this->parserOptions( $options );
314 public function parserOptions( $options = null ) {
315 if ( !$this->mParserOptions
) {
316 $this->mParserOptions
= new ParserOptions
;
318 return wfSetVar( $this->mParserOptions
, $options );
322 * Set the revision ID which will be seen by the wiki text parser
323 * for things such as embedded {{REVISIONID}} variable use.
324 * @param mixed $revid an integer, or NULL
325 * @return mixed previous value
327 public function setRevisionId( $revid ) {
328 $val = is_null( $revid ) ?
null : intval( $revid );
329 return wfSetVar( $this->mRevisionId
, $val );
333 * Convert wikitext to HTML and add it to the buffer
334 * Default assumes that the current page title will
337 * @param string $text
338 * @param bool $linestart
340 public function addWikiText( $text, $linestart = true ) {
342 $this->addWikiTextTitle($text, $wgTitle, $linestart);
345 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
346 $this->addWikiTextTitle($text, $title, $linestart);
349 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
350 $this->addWikiTextTitle( $text, $title, $linestart, true );
353 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
356 $fname = 'OutputPage:addWikiTextTitle';
359 wfIncrStats('pcache_not_possible');
361 $popts = $this->parserOptions();
362 $popts->setTidy($tidy);
364 $parserOutput = $wgParser->parse( $text, $title, $popts,
365 $linestart, true, $this->mRevisionId
);
367 $this->addParserOutput( $parserOutput );
369 wfProfileOut($fname);
374 * @param ParserOutput object &$parserOutput
376 public function addParserOutputNoText( &$parserOutput ) {
377 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
378 $this->addCategoryLinks( $parserOutput->getCategories() );
379 $this->mNewSectionLink
= $parserOutput->getNewSection();
380 $this->addKeywords( $parserOutput );
381 if ( $parserOutput->getCacheTime() == -1 ) {
382 $this->enableClientCache( false );
384 if ( $parserOutput->mHTMLtitle
!= "" ) {
385 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
387 if ( $parserOutput->mSubtitle
!= '' ) {
388 $this->mSubtitle
.= $parserOutput->mSubtitle
;
390 $this->mNoGallery
= $parserOutput->getNoGallery();
391 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
393 $this->mTemplateIds +
= (array)$parserOutput->mTemplateIds
;
395 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
400 * @param ParserOutput &$parserOutput
402 function addParserOutput( &$parserOutput ) {
403 $this->addParserOutputNoText( $parserOutput );
404 $text = $parserOutput->getText();
405 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
406 $this->addHTML( $text );
410 * Add wikitext to the buffer, assuming that this is the primary text for a page view
411 * Saves the text into the parser cache if possible.
413 * @param string $text
414 * @param Article $article
416 * @deprecated Use Article::outputWikitext
418 public function addPrimaryWikiText( $text, $article, $cache = true ) {
419 global $wgParser, $wgUser;
421 $popts = $this->parserOptions();
422 $popts->setTidy(true);
423 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
424 $popts, true, true, $this->mRevisionId
);
425 $popts->setTidy(false);
426 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
427 $parserCache =& ParserCache
::singleton();
428 $parserCache->save( $parserOutput, $article, $wgUser );
431 $this->addParserOutput( $parserOutput );
435 * @deprecated use addWikiTextTidy()
437 public function addSecondaryWikiText( $text, $linestart = true ) {
439 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
443 * Add wikitext with tidy enabled
445 public function addWikiTextTidy( $text, $linestart = true ) {
447 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
452 * Add the output of a QuickTemplate to the output buffer
454 * @param QuickTemplate $template
456 public function addTemplate( &$template ) {
458 $template->execute();
459 $this->addHTML( ob_get_contents() );
464 * Parse wikitext and return the HTML.
466 * @param string $text
467 * @param bool $linestart Is this the start of a line?
468 * @param bool $interface ??
470 public function parse( $text, $linestart = true, $interface = false ) {
471 global $wgParser, $wgTitle;
472 $popts = $this->parserOptions();
473 if ( $interface) { $popts->setInterfaceMessage(true); }
474 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
475 $linestart, true, $this->mRevisionId
);
476 if ( $interface) { $popts->setInterfaceMessage(false); }
477 return $parserOutput->getText();
481 * @param Article $article
484 * @return bool True if successful, else false.
486 public function tryParserCache( &$article, $user ) {
487 $parserCache =& ParserCache
::singleton();
488 $parserOutput = $parserCache->get( $article, $user );
489 if ( $parserOutput !== false ) {
490 $this->addParserOutput( $parserOutput );
498 * @param int $maxage Maximum cache time on the Squid, in seconds.
500 public function setSquidMaxage( $maxage ) {
501 $this->mSquidMaxage
= $maxage;
505 * Use enableClientCache(false) to force it to send nocache headers
508 public function enableClientCache( $state ) {
509 return wfSetVar( $this->mEnableClientCache
, $state );
512 function uncacheableBecauseRequestvars() {
514 return $wgRequest->getText('useskin', false) === false
515 && $wgRequest->getText('uselang', false) === false;
518 public function sendCacheControl() {
519 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
520 $fname = 'OutputPage::sendCacheControl';
522 if ($wgUseETag && $this->mETag
)
523 $wgRequest->response()->header("ETag: $this->mETag");
525 # don't serve compressed data to clients who can't handle it
526 # maintain different caches for logged-in users and non-logged in ones
527 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
528 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
529 if( $wgUseSquid && session_id() == '' &&
530 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
533 # We'll purge the proxy cache explicitly, but require end user agents
534 # to revalidate against the proxy on each visit.
535 # Surrogate-Control controls our Squid, Cache-Control downstream caches
536 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
537 # start with a shorter timeout for initial testing
538 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
539 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
540 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
542 # We'll purge the proxy cache for anons explicitly, but require end user agents
543 # to revalidate against the proxy on each visit.
544 # IMPORTANT! The Squid needs to replace the Cache-Control header with
545 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
546 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
547 # start with a shorter timeout for initial testing
548 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
549 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
552 # We do want clients to cache if they can, but they *must* check for updates
553 # on revisiting the page.
554 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
555 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
556 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
558 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
560 wfDebug( "$fname: no caching **\n", false );
562 # In general, the absence of a last modified header should be enough to prevent
563 # the client from using its cache. We send a few other things just to make sure.
564 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
565 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
566 $wgRequest->response()->header( 'Pragma: no-cache' );
571 * Finally, all the text has been munged and accumulated into
572 * the object, let's actually output it:
574 public function output() {
575 global $wgUser, $wgOutputEncoding, $wgRequest;
576 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
577 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
578 global $wgServer, $wgStyleVersion;
580 if( $this->mDoNothing
){
583 $fname = 'OutputPage::output';
584 wfProfileIn( $fname );
585 $sk = $wgUser->getSkin();
588 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
590 wfRunHooks( 'AjaxAddScript', array( &$this ) );
592 if( $wgAjaxSearch ) {
593 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
594 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
597 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
598 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
602 if ( '' != $this->mRedirect
) {
603 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
604 # Standards require redirect URLs to be absolute
606 $this->mRedirect
= $wgServer . $this->mRedirect
;
608 if( $this->mRedirectCode
== '301') {
609 if( !$wgDebugRedirects ) {
610 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
612 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
615 $this->sendCacheControl();
617 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
618 if( $wgDebugRedirects ) {
619 $url = htmlspecialchars( $this->mRedirect
);
620 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
621 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
622 print "</body>\n</html>\n";
624 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
626 wfProfileOut( $fname );
629 elseif ( $this->mStatusCode
)
631 $statusMessage = array(
633 101 => 'Switching Protocols',
638 203 => 'Non-Authoritative Information',
640 205 => 'Reset Content',
641 206 => 'Partial Content',
642 207 => 'Multi-Status',
643 300 => 'Multiple Choices',
644 301 => 'Moved Permanently',
647 304 => 'Not Modified',
649 307 => 'Temporary Redirect',
650 400 => 'Bad Request',
651 401 => 'Unauthorized',
652 402 => 'Payment Required',
655 405 => 'Method Not Allowed',
656 406 => 'Not Acceptable',
657 407 => 'Proxy Authentication Required',
658 408 => 'Request Timeout',
661 411 => 'Length Required',
662 412 => 'Precondition Failed',
663 413 => 'Request Entity Too Large',
664 414 => 'Request-URI Too Large',
665 415 => 'Unsupported Media Type',
666 416 => 'Request Range Not Satisfiable',
667 417 => 'Expectation Failed',
668 422 => 'Unprocessable Entity',
670 424 => 'Failed Dependency',
671 500 => 'Internal Server Error',
672 501 => 'Not Implemented',
673 502 => 'Bad Gateway',
674 503 => 'Service Unavailable',
675 504 => 'Gateway Timeout',
676 505 => 'HTTP Version Not Supported',
677 507 => 'Insufficient Storage'
680 if ( $statusMessage[$this->mStatusCode
] )
681 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
684 # Buffer output; final headers may depend on later processing
687 # Disable temporary placeholders, so that the skin produces HTML
688 $sk->postParseLinkColour( false );
690 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
691 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
693 if ($this->mArticleBodyOnly
) {
694 $this->out($this->mBodytext
);
696 wfProfileIn( 'Output-skin' );
697 $sk->outputPage( $this );
698 wfProfileOut( 'Output-skin' );
701 $this->sendCacheControl();
703 wfProfileOut( $fname );
710 public function out( $ins ) {
711 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
712 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
715 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
716 if ( false === $outs ) { $outs = $ins; }
724 public static function setEncodings() {
725 global $wgInputEncoding, $wgOutputEncoding;
726 global $wgUser, $wgContLang;
728 $wgInputEncoding = strtolower( $wgInputEncoding );
730 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
731 $wgOutputEncoding = strtolower( $wgOutputEncoding );
734 $wgOutputEncoding = $wgInputEncoding;
738 * Deprecated, use wfReportTime() instead.
742 public function reportTime() {
743 $time = wfReportTime();
748 * Produce a "user is blocked" page.
750 * @param bool $return Whether to have a "return to $wgTitle" message or not.
753 function blockedPage( $return = true ) {
754 global $wgUser, $wgContLang, $wgTitle, $wgLang;
756 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
757 $this->setRobotpolicy( 'noindex,nofollow' );
758 $this->setArticleRelated( false );
760 $id = $wgUser->blockedBy();
761 $reason = $wgUser->blockedFor();
764 if ( is_numeric( $id ) ) {
765 $name = User
::whoIs( $id );
769 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
771 $blockid = $wgUser->mBlock
->mId
;
773 $blockExpiry = $wgUser->mBlock
->mExpiry
;
774 if ( $blockExpiry == 'infinity' ) {
775 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
776 // Search for localization in 'ipboptions'
777 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
778 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
779 if ( strpos( $option, ":" ) === false )
781 list( $show, $value ) = explode( ":", $option );
782 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
783 $blockExpiry = $show;
788 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
791 if ( $wgUser->mBlock
->mAuto
) {
792 $msg = 'autoblockedtext';
794 $msg = 'blockedtext';
797 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
798 * This could be a username, an ip range, or a single ip. */
799 $intended = $wgUser->mBlock
->mAddress
;
801 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended ) );
803 # Don't auto-return to special pages
805 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
806 $this->returnToMain( false, $return );
811 * Output a standard error page
813 * @param string $title Message key for page title
814 * @param string $msg Message key for page text
815 * @param array $params Message parameters
817 public function showErrorPage( $title, $msg, $params = array() ) {
820 $this->mDebugtext
.= 'Original title: ' .
821 $wgTitle->getPrefixedText() . "\n";
822 $this->setPageTitle( wfMsg( $title ) );
823 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
824 $this->setRobotpolicy( 'noindex,nofollow' );
825 $this->setArticleRelated( false );
826 $this->enableClientCache( false );
827 $this->mRedirect
= '';
828 $this->mBodytext
= '';
830 array_unshift( $params, $msg );
831 $message = call_user_func_array( 'wfMsg', $params );
832 $this->addWikiText( $message );
834 $this->returnToMain( false );
838 public function errorpage( $title, $msg ) {
839 throw new ErrorPageError( $title, $msg );
843 * Display an error page indicating that a given version of MediaWiki is
846 * @param mixed $version The version of MediaWiki needed to use the page
848 public function versionRequired( $version ) {
849 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
850 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
851 $this->setRobotpolicy( 'noindex,nofollow' );
852 $this->setArticleRelated( false );
853 $this->mBodytext
= '';
855 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
856 $this->returnToMain();
860 * Display an error page noting that a given permission bit is required.
862 * @param string $permission key required
864 public function permissionRequired( $permission ) {
865 global $wgGroupPermissions, $wgUser;
867 $this->setPageTitle( wfMsg( 'badaccess' ) );
868 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
869 $this->setRobotpolicy( 'noindex,nofollow' );
870 $this->setArticleRelated( false );
871 $this->mBodytext
= '';
874 foreach( $wgGroupPermissions as $key => $value ) {
875 if( isset( $value[$permission] ) && $value[$permission] == true ) {
876 $groupName = User
::getGroupName( $key );
877 $groupPage = User
::getGroupPage( $key );
879 $skin = $wgUser->getSkin();
880 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
882 $groups[] = $groupName;
886 $n = count( $groups );
887 $groups = implode( ', ', $groups );
892 $message = wfMsgHtml( "badaccess-group$n", $groups );
895 $message = wfMsgHtml( 'badaccess-groups', $groups );
897 $this->addHtml( $message );
898 $this->returnToMain( false );
902 * Use permissionRequired.
905 public function sysopRequired() {
906 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
910 * Use permissionRequired.
913 public function developerRequired() {
914 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
918 * Produce the stock "please login to use the wiki" page
920 public function loginToUse() {
921 global $wgUser, $wgTitle, $wgContLang;
923 if( $wgUser->isLoggedIn() ) {
924 $this->permissionRequired( 'read' );
928 $skin = $wgUser->getSkin();
930 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
931 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
932 $this->setRobotPolicy( 'noindex,nofollow' );
933 $this->setArticleFlag( false );
935 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
936 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
937 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
938 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
940 # Don't return to the main page if the user can't read it
941 # otherwise we'll end up in a pointless loop
942 $mainPage = Title
::newMainPage();
943 if( $mainPage->userCanRead() )
944 $this->returnToMain( true, $mainPage );
948 public function databaseError( $fname, $sql, $error, $errno ) {
949 throw new MWException( "OutputPage::databaseError is obsolete\n" );
954 * @param bool $protected Is the reason the page can't be reached because it's protected?
955 * @param mixed $source
957 public function readOnlyPage( $source = null, $protected = false ) {
958 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
959 $skin = $wgUser->getSkin();
961 $this->setRobotpolicy( 'noindex,nofollow' );
962 $this->setArticleRelated( false );
965 $this->setPageTitle( wfMsg( 'viewsource' ) );
966 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
968 list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources();
970 # Determine if protection is due to the page being a system message
971 # and show an appropriate explanation
972 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
973 $this->addWikiText( wfMsg( 'protectedinterface' ) );
974 } if ( $cascadeSources && count($cascadeSources) > 0 ) {
977 foreach ( $cascadeSources as $title ) {
978 $titles .= '* [[:' . $title->getPrefixedText() . "]]\n";
981 $notice = wfMsgExt( 'cascadeprotected', array('parsemag'), count($cascadeSources) ) . "\n$titles";
983 $this->addWikiText( $notice );
985 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
988 $this->setPageTitle( wfMsg( 'readonly' ) );
990 $reason = $wgReadOnly;
992 $reason = file_get_contents( $wgReadOnlyFile );
994 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
997 if( is_string( $source ) ) {
998 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
999 $rows = $wgUser->getIntOption( 'rows' );
1000 $cols = $wgUser->getIntOption( 'cols' );
1001 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
1002 htmlspecialchars( $source ) . "\n</textarea>";
1003 $this->addHTML( $text );
1005 $article = new Article($wgTitle);
1006 $this->addHTML( $skin->formatTemplates($article->getUsedTemplates()) );
1008 $this->returnToMain( false );
1012 public function fatalError( $message ) {
1013 throw new FatalError( $message );
1017 public function unexpectedValueError( $name, $val ) {
1018 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1022 public function fileCopyError( $old, $new ) {
1023 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1027 public function fileRenameError( $old, $new ) {
1028 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1032 public function fileDeleteError( $name ) {
1033 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1037 public function fileNotFoundError( $name ) {
1038 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1041 public function showFatalError( $message ) {
1042 $this->setPageTitle( wfMsg( "internalerror" ) );
1043 $this->setRobotpolicy( "noindex,nofollow" );
1044 $this->setArticleRelated( false );
1045 $this->enableClientCache( false );
1046 $this->mRedirect
= '';
1047 $this->mBodytext
= $message;
1050 public function showUnexpectedValueError( $name, $val ) {
1051 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1054 public function showFileCopyError( $old, $new ) {
1055 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1058 public function showFileRenameError( $old, $new ) {
1059 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1062 public function showFileDeleteError( $name ) {
1063 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1066 public function showFileNotFoundError( $name ) {
1067 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1071 * return from error messages or notes
1072 * @param $auto automatically redirect the user after 10 seconds
1073 * @param $returnto page title to return to. Default is Main Page.
1075 public function returnToMain( $auto = true, $returnto = NULL ) {
1076 global $wgUser, $wgOut, $wgRequest;
1078 if ( $returnto == NULL ) {
1079 $returnto = $wgRequest->getText( 'returnto' );
1082 if ( '' === $returnto ) {
1083 $returnto = Title
::newMainPage();
1086 if ( is_object( $returnto ) ) {
1087 $titleObj = $returnto;
1089 $titleObj = Title
::newFromText( $returnto );
1091 if ( !is_object( $titleObj ) ) {
1092 $titleObj = Title
::newMainPage();
1095 $sk = $wgUser->getSkin();
1096 $link = $sk->makeLinkObj( $titleObj, '' );
1098 $r = wfMsg( 'returnto', $link );
1100 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
1102 $wgOut->addHTML( "\n<p>$r</p>\n" );
1106 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1107 * and uses the first 10 of them for META keywords
1109 * @param ParserOutput &$parserOutput
1111 private function addKeywords( &$parserOutput ) {
1113 $this->addKeyword( $wgTitle->getPrefixedText() );
1115 $links2d =& $parserOutput->getLinks();
1116 if ( !is_array( $links2d ) ) {
1119 foreach ( $links2d as $dbkeys ) {
1120 foreach( $dbkeys as $dbkey => $unused ) {
1121 $this->addKeyword( $dbkey );
1122 if ( ++
$count > 10 ) {
1130 * @return string The doctype, opening <html>, and head element.
1132 public function headElement() {
1133 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1134 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1135 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1137 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1138 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1143 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1145 if ( '' == $this->getHTMLTitle() ) {
1146 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1149 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1150 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1151 foreach($wgXhtmlNamespaces as $tag => $ns) {
1152 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1154 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1155 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1156 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1158 $ret .= $this->getHeadLinks();
1159 global $wgStylePath;
1160 if( $this->isPrintable() ) {
1163 $media = "media='print'";
1165 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1166 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1168 $sk = $wgUser->getSkin();
1169 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1170 $ret .= $this->mScripts
;
1171 $ret .= $sk->getUserStyles();
1172 $ret .= $this->getHeadItems();
1174 if ($wgUseTrackbacks && $this->isArticleRelated())
1175 $ret .= $wgTitle->trackbackRDF();
1177 $ret .= "</head>\n";
1182 * @return string HTML tag links to be put in the header.
1184 public function getHeadLinks() {
1187 foreach ( $this->mMetatags
as $tag ) {
1188 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1190 $tag[0] = substr( $tag[0], 5 );
1194 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1197 $p = $this->mRobotpolicy
;
1198 if( $p !== '' && $p != 'index,follow' ) {
1199 // http://www.robotstxt.org/wc/meta-user.html
1200 // Only show if it's different from the default robots policy
1201 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1204 if ( count( $this->mKeywords
) > 0 ) {
1209 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1210 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1212 foreach ( $this->mLinktags
as $tag ) {
1213 $ret .= "\t\t<link";
1214 foreach( $tag as $attr => $val ) {
1215 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1219 if( $this->isSyndicated() ) {
1220 # FIXME: centralize the mime-type and name information in Feed.php
1221 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1222 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1223 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1224 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 1.0' href='$link' />\n";
1231 * Turn off regular page output and return an error reponse
1232 * for when rate limiting has triggered.
1235 public function rateLimited() {
1238 wfHttpError( 500, 'Internal Server Error',
1239 'Sorry, the server has encountered an internal error. ' .
1240 'Please wait a moment and hit "refresh" to submit the request again.' );
1244 * Show an "add new section" link?
1246 * @return bool True if the parser output instructs us to add one
1248 public function showNewSectionLink() {
1249 return $this->mNewSectionLink
;
1253 * Show a warning about slave lag
1255 * If the lag is higher than 30 seconds, then the warning is
1256 * a bit more obvious
1258 * @param int $lag Slave lag
1260 public function showLagWarning( $lag ) {
1261 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1263 if ($lag < $wgSlaveLagWarning)
1266 $message = ($lag >= $wgSlaveLagCritical) ?
'lag-warn-high' : 'lag-warn-normal';
1267 $warning = wfMsgHtml( $message, htmlspecialchars( $lag ) );
1268 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );