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();
58 $this->mImageTimestamps
= array();
61 public function redirect( $url, $responsecode = '302' ) {
62 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
63 $this->mRedirect
= str_replace( "\n", '', $url );
64 $this->mRedirectCode
= $responsecode;
68 * Set the HTTP status code to send with the output.
70 * @param int $statusCode
73 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
75 # To add an http-equiv meta tag, precede the name with "http:"
76 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
77 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
78 function addScript( $script ) { $this->mScripts
.= "\t\t".$script; }
79 function addStyle( $style ) {
80 global $wgStylePath, $wgStyleVersion;
83 'rel' => 'stylesheet',
84 'href' => $wgStylePath . '/' . $style . '?' . $wgStyleVersion ) );
88 * Add a self-contained script tag with the given contents
89 * @param string $script JavaScript text, no <script> tags
91 function addInlineScript( $script ) {
93 $this->mScripts
.= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
96 function getScript() {
97 return $this->mScripts
. $this->getHeadItems();
100 function getHeadItems() {
102 foreach ( $this->mHeadItems
as $item ) {
108 function addHeadItem( $name, $value ) {
109 $this->mHeadItems
[$name] = $value;
112 function setETag($tag) { $this->mETag
= $tag; }
113 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
114 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
116 function addLink( $linkarr ) {
117 # $linkarr should be an associative array of attributes. We'll escape on output.
118 array_push( $this->mLinktags
, $linkarr );
121 function addMetadataLink( $linkarr ) {
122 # note: buggy CC software only reads first "meta" link
123 static $haveMeta = false;
124 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
125 $this->addLink( $linkarr );
130 * checkLastModified tells the client to use the client-cached page if
131 * possible. If sucessful, the OutputPage is disabled so that
132 * any future call to OutputPage->output() have no effect.
134 * @return bool True iff cache-ok headers was sent.
136 function checkLastModified ( $timestamp ) {
137 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
138 $fname = 'OutputPage::checkLastModified';
140 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
141 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
144 if( !$wgCachePages ) {
145 wfDebug( "$fname: CACHE DISABLED\n", false );
148 if( $wgUser->getOption( 'nocache' ) ) {
149 wfDebug( "$fname: USER DISABLED CACHE\n", false );
153 $timestamp=wfTimestamp(TS_MW
,$timestamp);
154 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
156 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
157 # IE sends sizes after the date like this:
158 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
159 # this breaks strtotime().
160 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
161 $modsinceTime = strtotime( $modsince );
162 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
163 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
164 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
165 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
166 # Make sure you're in a place you can leave when you call us!
167 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
168 $this->mLastModified
= $lastmod;
169 $this->sendCacheControl();
170 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
173 // Don't output a compressed blob when using ob_gzhandler;
174 // it's technically against HTTP spec and seems to confuse
175 // Firefox when the response gets split over two packets.
176 wfClearOutputBuffers();
180 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
181 $this->mLastModified
= $lastmod;
184 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
185 $this->mLastModified
= $lastmod;
189 function getPageTitleActionText () {
198 // Display title is already customized
201 return wfMsg('history_short');
203 // FIXME: bug 2735; not correct for special pages etc
204 return wfMsg('preview');
206 return wfMsg('info_short');
212 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
213 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
214 public function setPageTitle( $name ) {
215 global $action, $wgContLang;
216 $name = $wgContLang->convert($name, true);
217 $this->mPagetitle
= $name;
218 if(!empty($action)) {
219 $taction = $this->getPageTitleActionText();
220 if( !empty( $taction ) ) {
221 $name .= ' - '.$taction;
225 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
227 public function getHTMLTitle() { return $this->mHTMLtitle
; }
228 public function getPageTitle() { return $this->mPagetitle
; }
229 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
230 public function getSubtitle() { return $this->mSubtitle
; }
231 public function isArticle() { return $this->mIsarticle
; }
232 public function setPrintable() { $this->mPrintable
= true; }
233 public function isPrintable() { return $this->mPrintable
; }
234 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
235 public function isSyndicated() { return $this->mShowFeedLinks
; }
236 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
237 public function getOnloadHandler() { return $this->mOnloadHandler
; }
238 public function disable() { $this->mDoNothing
= true; }
240 public function setArticleRelated( $v ) {
241 $this->mIsArticleRelated
= $v;
243 $this->mIsarticle
= false;
246 public function setArticleFlag( $v ) {
247 $this->mIsarticle
= $v;
249 $this->mIsArticleRelated
= $v;
253 public function isArticleRelated() { return $this->mIsArticleRelated
; }
255 public function getLanguageLinks() { return $this->mLanguageLinks
; }
256 public function addLanguageLinks($newLinkArray) {
257 $this->mLanguageLinks +
= $newLinkArray;
259 public function setLanguageLinks($newLinkArray) {
260 $this->mLanguageLinks
= $newLinkArray;
263 public function getCategoryLinks() {
264 return $this->mCategoryLinks
;
268 * Add an array of categories, with names in the keys
270 public function addCategoryLinks($categories) {
271 global $wgUser, $wgContLang;
273 if ( !is_array( $categories ) ) {
276 # Add the links to the link cache in a batch
277 $arr = array( NS_CATEGORY
=> $categories );
279 $lb->setArray( $arr );
282 $sk = $wgUser->getSkin();
283 foreach ( $categories as $category => $unused ) {
284 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
285 $text = $wgContLang->convertHtml( $title->getText() );
286 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
290 public function setCategoryLinks($categories) {
291 $this->mCategoryLinks
= array();
292 $this->addCategoryLinks($categories);
295 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
296 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
298 public function disallowUserJs() { $this->mAllowUserJs
= false; }
299 public function isUserJsAllowed() { return $this->mAllowUserJs
; }
301 public function addHTML( $text ) { $this->mBodytext
.= $text; }
302 public function clearHTML() { $this->mBodytext
= ''; }
303 public function getHTML() { return $this->mBodytext
; }
304 public function debug( $text ) { $this->mDebugtext
.= $text; }
307 public function setParserOptions( $options ) {
308 return $this->parserOptions( $options );
311 public function parserOptions( $options = null ) {
312 if ( !$this->mParserOptions
) {
313 $this->mParserOptions
= new ParserOptions
;
315 return wfSetVar( $this->mParserOptions
, $options );
319 * Set the revision ID which will be seen by the wiki text parser
320 * for things such as embedded {{REVISIONID}} variable use.
321 * @param mixed $revid an integer, or NULL
322 * @return mixed previous value
324 public function setRevisionId( $revid ) {
325 $val = is_null( $revid ) ?
null : intval( $revid );
326 return wfSetVar( $this->mRevisionId
, $val );
330 * Convert wikitext to HTML and add it to the buffer
331 * Default assumes that the current page title will
334 * @param string $text
335 * @param bool $linestart
337 public function addWikiText( $text, $linestart = true ) {
339 $this->addWikiTextTitle($text, $wgTitle, $linestart);
342 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
343 $this->addWikiTextTitle($text, $title, $linestart);
346 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
347 $this->addWikiTextTitle( $text, $title, $linestart, true );
350 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
353 $fname = 'OutputPage:addWikiTextTitle';
356 wfIncrStats('pcache_not_possible');
358 $popts = $this->parserOptions();
359 $popts->setTidy($tidy);
361 $parserOutput = $wgParser->parse( $text, $title, $popts,
362 $linestart, true, $this->mRevisionId
);
364 $this->addParserOutput( $parserOutput );
366 wfProfileOut($fname);
371 * @param ParserOutput object &$parserOutput
373 public function addParserOutputNoText( &$parserOutput ) {
374 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
375 $this->addCategoryLinks( $parserOutput->getCategories() );
376 $this->mNewSectionLink
= $parserOutput->getNewSection();
377 $this->addKeywords( $parserOutput );
378 if ( $parserOutput->getCacheTime() == -1 ) {
379 $this->enableClientCache( false );
381 if ( $parserOutput->mHTMLtitle
!= "" ) {
382 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
384 if ( $parserOutput->mSubtitle
!= '' ) {
385 $this->mSubtitle
.= $parserOutput->mSubtitle
;
387 $this->mNoGallery
= $parserOutput->getNoGallery();
388 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
390 $this->mTemplateIds +
= (array)$parserOutput->mTemplateIds
;
391 $this->mImageTimestamps +
= (array)$parserOutput->mImageTimestamps
;
393 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
398 * @param ParserOutput &$parserOutput
400 function addParserOutput( &$parserOutput ) {
401 $this->addParserOutputNoText( $parserOutput );
402 $text = $parserOutput->getText();
403 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
404 $this->addHTML( $text );
408 * Add wikitext to the buffer, assuming that this is the primary text for a page view
409 * Saves the text into the parser cache if possible.
411 * @param string $text
412 * @param Article $article
414 * @deprecated Use Article::outputWikitext
416 public function addPrimaryWikiText( $text, $article, $cache = true ) {
417 global $wgParser, $wgUser;
419 $popts = $this->parserOptions();
420 $popts->setTidy(true);
421 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
422 $popts, true, true, $this->mRevisionId
);
423 $popts->setTidy(false);
424 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
425 $parserCache =& ParserCache
::singleton();
426 $parserCache->save( $parserOutput, $article, $wgUser );
429 $this->addParserOutput( $parserOutput );
433 * @deprecated use addWikiTextTidy()
435 public function addSecondaryWikiText( $text, $linestart = true ) {
437 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
441 * Add wikitext with tidy enabled
443 public function addWikiTextTidy( $text, $linestart = true ) {
445 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
450 * Add the output of a QuickTemplate to the output buffer
452 * @param QuickTemplate $template
454 public function addTemplate( &$template ) {
456 $template->execute();
457 $this->addHTML( ob_get_contents() );
462 * Parse wikitext and return the HTML.
464 * @param string $text
465 * @param bool $linestart Is this the start of a line?
466 * @param bool $interface ??
468 public function parse( $text, $linestart = true, $interface = false ) {
469 global $wgParser, $wgTitle;
470 $popts = $this->parserOptions();
471 if ( $interface) { $popts->setInterfaceMessage(true); }
472 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
473 $linestart, true, $this->mRevisionId
);
474 if ( $interface) { $popts->setInterfaceMessage(false); }
475 return $parserOutput->getText();
479 * @param Article $article
482 * @return bool True if successful, else false.
484 public function tryParserCache( &$article, $user ) {
485 $parserCache =& ParserCache
::singleton();
486 $parserOutput = $parserCache->get( $article, $user );
487 if ( $parserOutput !== false ) {
488 $this->addParserOutput( $parserOutput );
496 * @param int $maxage Maximum cache time on the Squid, in seconds.
498 public function setSquidMaxage( $maxage ) {
499 $this->mSquidMaxage
= $maxage;
503 * Use enableClientCache(false) to force it to send nocache headers
506 public function enableClientCache( $state ) {
507 return wfSetVar( $this->mEnableClientCache
, $state );
510 function uncacheableBecauseRequestvars() {
512 return $wgRequest->getText('useskin', false) === false
513 && $wgRequest->getText('uselang', false) === false;
516 public function sendCacheControl() {
517 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
518 $fname = 'OutputPage::sendCacheControl';
520 if ($wgUseETag && $this->mETag
)
521 $wgRequest->response()->header("ETag: $this->mETag");
523 # don't serve compressed data to clients who can't handle it
524 # maintain different caches for logged-in users and non-logged in ones
525 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
526 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
527 if( $wgUseSquid && session_id() == '' &&
528 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
531 # We'll purge the proxy cache explicitly, but require end user agents
532 # to revalidate against the proxy on each visit.
533 # Surrogate-Control controls our Squid, Cache-Control downstream caches
534 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
535 # start with a shorter timeout for initial testing
536 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
537 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
538 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
540 # We'll purge the proxy cache for anons explicitly, but require end user agents
541 # to revalidate against the proxy on each visit.
542 # IMPORTANT! The Squid needs to replace the Cache-Control header with
543 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
544 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
545 # start with a shorter timeout for initial testing
546 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
547 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
550 # We do want clients to cache if they can, but they *must* check for updates
551 # on revisiting the page.
552 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
553 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
554 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
556 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
558 wfDebug( "$fname: no caching **\n", false );
560 # In general, the absence of a last modified header should be enough to prevent
561 # the client from using its cache. We send a few other things just to make sure.
562 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
563 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
564 $wgRequest->response()->header( 'Pragma: no-cache' );
569 * Finally, all the text has been munged and accumulated into
570 * the object, let's actually output it:
572 public function output() {
573 global $wgUser, $wgOutputEncoding, $wgRequest;
574 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
575 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
576 global $wgServer, $wgStyleVersion;
578 if( $this->mDoNothing
){
581 $fname = 'OutputPage::output';
582 wfProfileIn( $fname );
583 $sk = $wgUser->getSkin();
586 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
588 wfRunHooks( 'AjaxAddScript', array( &$this ) );
590 if( $wgAjaxSearch ) {
591 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
592 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
595 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
596 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
600 if ( '' != $this->mRedirect
) {
601 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
602 # Standards require redirect URLs to be absolute
604 $this->mRedirect
= $wgServer . $this->mRedirect
;
606 if( $this->mRedirectCode
== '301') {
607 if( !$wgDebugRedirects ) {
608 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
610 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
613 $this->sendCacheControl();
615 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
616 if( $wgDebugRedirects ) {
617 $url = htmlspecialchars( $this->mRedirect
);
618 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
619 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
620 print "</body>\n</html>\n";
622 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
624 wfProfileOut( $fname );
627 elseif ( $this->mStatusCode
)
629 $statusMessage = array(
631 101 => 'Switching Protocols',
636 203 => 'Non-Authoritative Information',
638 205 => 'Reset Content',
639 206 => 'Partial Content',
640 207 => 'Multi-Status',
641 300 => 'Multiple Choices',
642 301 => 'Moved Permanently',
645 304 => 'Not Modified',
647 307 => 'Temporary Redirect',
648 400 => 'Bad Request',
649 401 => 'Unauthorized',
650 402 => 'Payment Required',
653 405 => 'Method Not Allowed',
654 406 => 'Not Acceptable',
655 407 => 'Proxy Authentication Required',
656 408 => 'Request Timeout',
659 411 => 'Length Required',
660 412 => 'Precondition Failed',
661 413 => 'Request Entity Too Large',
662 414 => 'Request-URI Too Large',
663 415 => 'Unsupported Media Type',
664 416 => 'Request Range Not Satisfiable',
665 417 => 'Expectation Failed',
666 422 => 'Unprocessable Entity',
668 424 => 'Failed Dependency',
669 500 => 'Internal Server Error',
670 501 => 'Not Implemented',
671 502 => 'Bad Gateway',
672 503 => 'Service Unavailable',
673 504 => 'Gateway Timeout',
674 505 => 'HTTP Version Not Supported',
675 507 => 'Insufficient Storage'
678 if ( $statusMessage[$this->mStatusCode
] )
679 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
682 # Buffer output; final headers may depend on later processing
685 # Disable temporary placeholders, so that the skin produces HTML
686 $sk->postParseLinkColour( false );
688 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
689 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
691 if ($this->mArticleBodyOnly
) {
692 $this->out($this->mBodytext
);
694 wfProfileIn( 'Output-skin' );
695 $sk->outputPage( $this );
696 wfProfileOut( 'Output-skin' );
699 $this->sendCacheControl();
701 wfProfileOut( $fname );
708 public function out( $ins ) {
709 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
710 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
713 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
714 if ( false === $outs ) { $outs = $ins; }
722 public static function setEncodings() {
723 global $wgInputEncoding, $wgOutputEncoding;
724 global $wgUser, $wgContLang;
726 $wgInputEncoding = strtolower( $wgInputEncoding );
728 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
729 $wgOutputEncoding = strtolower( $wgOutputEncoding );
732 $wgOutputEncoding = $wgInputEncoding;
736 * Deprecated, use wfReportTime() instead.
740 public function reportTime() {
741 $time = wfReportTime();
746 * Produce a "user is blocked" page.
748 * @param bool $return Whether to have a "return to $wgTitle" message or not.
751 function blockedPage( $return = true ) {
752 global $wgUser, $wgContLang, $wgTitle, $wgLang;
754 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
755 $this->setRobotpolicy( 'noindex,nofollow' );
756 $this->setArticleRelated( false );
758 $id = $wgUser->blockedBy();
759 $reason = $wgUser->blockedFor();
762 if ( is_numeric( $id ) ) {
763 $name = User
::whoIs( $id );
767 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
769 $blockid = $wgUser->mBlock
->mId
;
771 $blockExpiry = $wgUser->mBlock
->mExpiry
;
772 if ( $blockExpiry == 'infinity' ) {
773 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
774 // Search for localization in 'ipboptions'
775 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
776 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
777 if ( strpos( $option, ":" ) === false )
779 list( $show, $value ) = explode( ":", $option );
780 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
781 $blockExpiry = $show;
786 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
789 if ( $wgUser->mBlock
->mAuto
) {
790 $msg = 'autoblockedtext';
792 $msg = 'blockedtext';
795 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry ) );
797 # Don't auto-return to special pages
799 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
800 $this->returnToMain( false, $return );
805 * Output a standard error page
807 * @param string $title Message key for page title
808 * @param string $msg Message key for page text
809 * @param array $params Message parameters
811 public function showErrorPage( $title, $msg, $params = array() ) {
814 $this->mDebugtext
.= 'Original title: ' .
815 $wgTitle->getPrefixedText() . "\n";
816 $this->setPageTitle( wfMsg( $title ) );
817 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
818 $this->setRobotpolicy( 'noindex,nofollow' );
819 $this->setArticleRelated( false );
820 $this->enableClientCache( false );
821 $this->mRedirect
= '';
822 $this->mBodytext
= '';
824 array_unshift( $params, $msg );
825 $message = call_user_func_array( 'wfMsg', $params );
826 $this->addWikiText( $message );
828 $this->returnToMain( false );
832 public function errorpage( $title, $msg ) {
833 throw new ErrorPageError( $title, $msg );
837 * Display an error page indicating that a given version of MediaWiki is
840 * @param mixed $version The version of MediaWiki needed to use the page
842 public function versionRequired( $version ) {
843 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
844 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
845 $this->setRobotpolicy( 'noindex,nofollow' );
846 $this->setArticleRelated( false );
847 $this->mBodytext
= '';
849 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
850 $this->returnToMain();
854 * Display an error page noting that a given permission bit is required.
856 * @param string $permission key required
858 public function permissionRequired( $permission ) {
859 global $wgGroupPermissions, $wgUser;
861 $this->setPageTitle( wfMsg( 'badaccess' ) );
862 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
863 $this->setRobotpolicy( 'noindex,nofollow' );
864 $this->setArticleRelated( false );
865 $this->mBodytext
= '';
868 foreach( $wgGroupPermissions as $key => $value ) {
869 if( isset( $value[$permission] ) && $value[$permission] == true ) {
870 $groupName = User
::getGroupName( $key );
871 $groupPage = User
::getGroupPage( $key );
873 $skin = $wgUser->getSkin();
874 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
876 $groups[] = $groupName;
880 $n = count( $groups );
881 $groups = implode( ', ', $groups );
886 $message = wfMsgHtml( "badaccess-group$n", $groups );
889 $message = wfMsgHtml( 'badaccess-groups', $groups );
891 $this->addHtml( $message );
892 $this->returnToMain( false );
896 * Use permissionRequired.
899 public function sysopRequired() {
900 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
904 * Use permissionRequired.
907 public function developerRequired() {
908 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
912 * Produce the stock "please login to use the wiki" page
914 public function loginToUse() {
915 global $wgUser, $wgTitle, $wgContLang;
917 if( $wgUser->isLoggedIn() ) {
918 $this->permissionRequired( 'read' );
922 $skin = $wgUser->getSkin();
924 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
925 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
926 $this->setRobotPolicy( 'noindex,nofollow' );
927 $this->setArticleFlag( false );
929 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
930 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
931 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
932 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
934 # Don't return to the main page if the user can't read it
935 # otherwise we'll end up in a pointless loop
936 $mainPage = Title
::newMainPage();
937 if( $mainPage->userCanRead() )
938 $this->returnToMain( true, $mainPage );
942 public function databaseError( $fname, $sql, $error, $errno ) {
943 throw new MWException( "OutputPage::databaseError is obsolete\n" );
948 * @param bool $protected Is the reason the page can't be reached because it's protected?
949 * @param mixed $source
951 public function readOnlyPage( $source = null, $protected = false ) {
952 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
953 $skin = $wgUser->getSkin();
955 $this->setRobotpolicy( 'noindex,nofollow' );
956 $this->setArticleRelated( false );
959 $this->setPageTitle( wfMsg( 'viewsource' ) );
960 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
962 list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources();
964 # Determine if protection is due to the page being a system message
965 # and show an appropriate explanation
966 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
967 $this->addWikiText( wfMsg( 'protectedinterface' ) );
968 } if ( $cascadeSources && count($cascadeSources) > 0 ) {
971 foreach ( $cascadeSources as $title ) {
972 $titles .= '* [[:' . $title->getPrefixedText() . "]]\n";
975 $notice = wfMsgExt( 'cascadeprotected', array('parsemag'), count($cascadeSources) ) . "\n$titles";
977 $this->addWikiText( $notice );
979 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
982 $this->setPageTitle( wfMsg( 'readonly' ) );
984 $reason = $wgReadOnly;
986 $reason = file_get_contents( $wgReadOnlyFile );
988 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
991 if( is_string( $source ) ) {
992 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
993 $rows = $wgUser->getIntOption( 'rows' );
994 $cols = $wgUser->getIntOption( 'cols' );
995 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
996 htmlspecialchars( $source ) . "\n</textarea>";
997 $this->addHTML( $text );
999 $article = new Article($wgTitle);
1000 $this->addHTML( $skin->formatTemplates($article->getUsedTemplates()) );
1002 $this->returnToMain( false );
1006 public function fatalError( $message ) {
1007 throw new FatalError( $message );
1011 public function unexpectedValueError( $name, $val ) {
1012 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1016 public function fileCopyError( $old, $new ) {
1017 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1021 public function fileRenameError( $old, $new ) {
1022 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1026 public function fileDeleteError( $name ) {
1027 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1031 public function fileNotFoundError( $name ) {
1032 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1035 public function showFatalError( $message ) {
1036 $this->setPageTitle( wfMsg( "internalerror" ) );
1037 $this->setRobotpolicy( "noindex,nofollow" );
1038 $this->setArticleRelated( false );
1039 $this->enableClientCache( false );
1040 $this->mRedirect
= '';
1041 $this->mBodytext
= $message;
1044 public function showUnexpectedValueError( $name, $val ) {
1045 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1048 public function showFileCopyError( $old, $new ) {
1049 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1052 public function showFileRenameError( $old, $new ) {
1053 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1056 public function showFileDeleteError( $name ) {
1057 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1060 public function showFileNotFoundError( $name ) {
1061 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1065 * return from error messages or notes
1066 * @param $auto automatically redirect the user after 10 seconds
1067 * @param $returnto page title to return to. Default is Main Page.
1069 public function returnToMain( $auto = true, $returnto = NULL ) {
1070 global $wgUser, $wgOut, $wgRequest;
1072 if ( $returnto == NULL ) {
1073 $returnto = $wgRequest->getText( 'returnto' );
1076 if ( '' === $returnto ) {
1077 $returnto = Title
::newMainPage();
1080 if ( is_object( $returnto ) ) {
1081 $titleObj = $returnto;
1083 $titleObj = Title
::newFromText( $returnto );
1085 if ( !is_object( $titleObj ) ) {
1086 $titleObj = Title
::newMainPage();
1089 $sk = $wgUser->getSkin();
1090 $link = $sk->makeLinkObj( $titleObj, '' );
1092 $r = wfMsg( 'returnto', $link );
1094 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
1096 $wgOut->addHTML( "\n<p>$r</p>\n" );
1100 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1101 * and uses the first 10 of them for META keywords
1103 * @param ParserOutput &$parserOutput
1105 private function addKeywords( &$parserOutput ) {
1107 $this->addKeyword( $wgTitle->getPrefixedText() );
1109 $links2d =& $parserOutput->getLinks();
1110 if ( !is_array( $links2d ) ) {
1113 foreach ( $links2d as $dbkeys ) {
1114 foreach( $dbkeys as $dbkey => $unused ) {
1115 $this->addKeyword( $dbkey );
1116 if ( ++
$count > 10 ) {
1124 * @return string The doctype, opening <html>, and head element.
1126 public function headElement() {
1127 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1128 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1129 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1131 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1132 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1137 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1139 if ( '' == $this->getHTMLTitle() ) {
1140 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1143 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1144 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1145 foreach($wgXhtmlNamespaces as $tag => $ns) {
1146 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1148 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1149 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1150 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1152 $ret .= $this->getHeadLinks();
1153 global $wgStylePath;
1154 if( $this->isPrintable() ) {
1157 $media = "media='print'";
1159 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1160 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1162 $sk = $wgUser->getSkin();
1163 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1164 $ret .= $this->mScripts
;
1165 $ret .= $sk->getUserStyles();
1166 $ret .= $this->getHeadItems();
1168 if ($wgUseTrackbacks && $this->isArticleRelated())
1169 $ret .= $wgTitle->trackbackRDF();
1171 $ret .= "</head>\n";
1176 * @return string HTML tag links to be put in the header.
1178 public function getHeadLinks() {
1181 foreach ( $this->mMetatags
as $tag ) {
1182 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1184 $tag[0] = substr( $tag[0], 5 );
1188 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1191 $p = $this->mRobotpolicy
;
1192 if( $p !== '' && $p != 'index,follow' ) {
1193 // http://www.robotstxt.org/wc/meta-user.html
1194 // Only show if it's different from the default robots policy
1195 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1198 if ( count( $this->mKeywords
) > 0 ) {
1203 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1204 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1206 foreach ( $this->mLinktags
as $tag ) {
1207 $ret .= "\t\t<link";
1208 foreach( $tag as $attr => $val ) {
1209 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1213 if( $this->isSyndicated() ) {
1214 # FIXME: centralize the mime-type and name information in Feed.php
1215 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1216 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1217 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1218 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 1.0' href='$link' />\n";
1225 * Turn off regular page output and return an error reponse
1226 * for when rate limiting has triggered.
1229 public function rateLimited() {
1232 wfHttpError( 500, 'Internal Server Error',
1233 'Sorry, the server has encountered an internal error. ' .
1234 'Please wait a moment and hit "refresh" to submit the request again.' );
1238 * Show an "add new section" link?
1240 * @return bool True if the parser output instructs us to add one
1242 public function showNewSectionLink() {
1243 return $this->mNewSectionLink
;
1247 * Show a warning about slave lag
1249 * If the lag is higher than 30 seconds, then the warning is
1250 * a bit more obvious
1252 * @param int $lag Slave lag
1254 public function showLagWarning( $lag ) {
1255 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1257 if ($lag < $wgSlaveLagWarning)
1260 $message = ($lag >= $wgSlaveLagCritical) ?
'lag-warn-high' : 'lag-warn-normal';
1261 $warning = wfMsgHtml( $message, htmlspecialchars( $lag ) );
1262 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );