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;
31 var $mPageTitleActionText = '';
35 * Initialise private variables
37 function __construct() {
38 global $wgAllowUserJs;
39 $this->mAllowUserJs
= $wgAllowUserJs;
40 $this->mMetatags
= $this->mKeywords
= $this->mLinktags
= array();
41 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
42 $this->mRedirect
= $this->mLastModified
=
43 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
44 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
45 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
46 $this->mSuppressQuickbar
= $this->mPrintable
= false;
47 $this->mLanguageLinks
= array();
48 $this->mCategoryLinks
= array();
49 $this->mDoNothing
= false;
50 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
51 $this->mParserOptions
= null;
52 $this->mSquidMaxage
= 0;
54 $this->mHeadItems
= array();
56 $this->mRevisionId
= null;
57 $this->mNewSectionLink
= false;
58 $this->mTemplateIds
= 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 hasHeadItem( $name ) {
113 return isset( $this->mHeadItems
[$name] );
116 function setETag($tag) { $this->mETag
= $tag; }
117 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
118 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
120 function addLink( $linkarr ) {
121 # $linkarr should be an associative array of attributes. We'll escape on output.
122 array_push( $this->mLinktags
, $linkarr );
125 function addMetadataLink( $linkarr ) {
126 # note: buggy CC software only reads first "meta" link
127 static $haveMeta = false;
128 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
129 $this->addLink( $linkarr );
134 * checkLastModified tells the client to use the client-cached page if
135 * possible. If sucessful, the OutputPage is disabled so that
136 * any future call to OutputPage->output() have no effect.
138 * @return bool True iff cache-ok headers was sent.
140 function checkLastModified ( $timestamp ) {
141 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
142 $fname = 'OutputPage::checkLastModified';
144 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
145 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
148 if( !$wgCachePages ) {
149 wfDebug( "$fname: CACHE DISABLED\n", false );
152 if( $wgUser->getOption( 'nocache' ) ) {
153 wfDebug( "$fname: USER DISABLED CACHE\n", false );
157 $timestamp=wfTimestamp(TS_MW
,$timestamp);
158 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
160 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
161 # IE sends sizes after the date like this:
162 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
163 # this breaks strtotime().
164 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
166 wfSuppressWarnings(); // E_STRICT system time bitching
167 $modsinceTime = strtotime( $modsince );
170 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
171 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
172 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
173 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
174 # Make sure you're in a place you can leave when you call us!
175 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
176 $this->mLastModified
= $lastmod;
177 $this->sendCacheControl();
178 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
181 // Don't output a compressed blob when using ob_gzhandler;
182 // it's technically against HTTP spec and seems to confuse
183 // Firefox when the response gets split over two packets.
184 wfClearOutputBuffers();
188 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
189 $this->mLastModified
= $lastmod;
192 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
193 $this->mLastModified
= $lastmod;
197 function setPageTitleActionText( $text ) {
198 $this->mPageTitleActionText
= $text;
201 function getPageTitleActionText () {
202 if ( isset( $this->mPageTitleActionText
) ) {
203 return $this->mPageTitleActionText
;
207 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
208 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
209 public function setPageTitle( $name ) {
210 global $action, $wgContLang;
211 $name = $wgContLang->convert($name, true);
212 $this->mPagetitle
= $name;
213 if(!empty($action)) {
214 $taction = $this->getPageTitleActionText();
215 if( !empty( $taction ) ) {
216 $name .= ' - '.$taction;
220 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
222 public function getHTMLTitle() { return $this->mHTMLtitle
; }
223 public function getPageTitle() { return $this->mPagetitle
; }
224 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
225 public function getSubtitle() { return $this->mSubtitle
; }
226 public function isArticle() { return $this->mIsarticle
; }
227 public function setPrintable() { $this->mPrintable
= true; }
228 public function isPrintable() { return $this->mPrintable
; }
229 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
230 public function isSyndicated() { return $this->mShowFeedLinks
; }
231 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
232 public function getOnloadHandler() { return $this->mOnloadHandler
; }
233 public function disable() { $this->mDoNothing
= true; }
235 public function setArticleRelated( $v ) {
236 $this->mIsArticleRelated
= $v;
238 $this->mIsarticle
= false;
241 public function setArticleFlag( $v ) {
242 $this->mIsarticle
= $v;
244 $this->mIsArticleRelated
= $v;
248 public function isArticleRelated() { return $this->mIsArticleRelated
; }
250 public function getLanguageLinks() { return $this->mLanguageLinks
; }
251 public function addLanguageLinks($newLinkArray) {
252 $this->mLanguageLinks +
= $newLinkArray;
254 public function setLanguageLinks($newLinkArray) {
255 $this->mLanguageLinks
= $newLinkArray;
258 public function getCategoryLinks() {
259 return $this->mCategoryLinks
;
263 * Add an array of categories, with names in the keys
265 public function addCategoryLinks($categories) {
266 global $wgUser, $wgContLang;
268 if ( !is_array( $categories ) ) {
271 # Add the links to the link cache in a batch
272 $arr = array( NS_CATEGORY
=> $categories );
274 $lb->setArray( $arr );
277 $sk = $wgUser->getSkin();
278 foreach ( $categories as $category => $unused ) {
279 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
280 $text = $wgContLang->convertHtml( $title->getText() );
281 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
285 public function setCategoryLinks($categories) {
286 $this->mCategoryLinks
= array();
287 $this->addCategoryLinks($categories);
290 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
291 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
293 public function disallowUserJs() { $this->mAllowUserJs
= false; }
294 public function isUserJsAllowed() { return $this->mAllowUserJs
; }
296 public function addHTML( $text ) { $this->mBodytext
.= $text; }
297 public function clearHTML() { $this->mBodytext
= ''; }
298 public function getHTML() { return $this->mBodytext
; }
299 public function debug( $text ) { $this->mDebugtext
.= $text; }
302 public function setParserOptions( $options ) {
303 return $this->parserOptions( $options );
306 public function parserOptions( $options = null ) {
307 if ( !$this->mParserOptions
) {
308 $this->mParserOptions
= new ParserOptions
;
310 return wfSetVar( $this->mParserOptions
, $options );
314 * Set the revision ID which will be seen by the wiki text parser
315 * for things such as embedded {{REVISIONID}} variable use.
316 * @param mixed $revid an integer, or NULL
317 * @return mixed previous value
319 public function setRevisionId( $revid ) {
320 $val = is_null( $revid ) ?
null : intval( $revid );
321 return wfSetVar( $this->mRevisionId
, $val );
325 * Convert wikitext to HTML and add it to the buffer
326 * Default assumes that the current page title will
329 * @param string $text
330 * @param bool $linestart
332 public function addWikiText( $text, $linestart = true ) {
334 $this->addWikiTextTitle($text, $wgTitle, $linestart);
337 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
338 $this->addWikiTextTitle($text, $title, $linestart);
341 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
342 $this->addWikiTextTitle( $text, $title, $linestart, true );
345 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
348 $fname = 'OutputPage:addWikiTextTitle';
351 wfIncrStats('pcache_not_possible');
353 $popts = $this->parserOptions();
354 $popts->setTidy($tidy);
356 $parserOutput = $wgParser->parse( $text, $title, $popts,
357 $linestart, true, $this->mRevisionId
);
359 $this->addParserOutput( $parserOutput );
361 wfProfileOut($fname);
366 * @param ParserOutput object &$parserOutput
368 public function addParserOutputNoText( &$parserOutput ) {
369 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
370 $this->addCategoryLinks( $parserOutput->getCategories() );
371 $this->mNewSectionLink
= $parserOutput->getNewSection();
372 $this->addKeywords( $parserOutput );
373 if ( $parserOutput->getCacheTime() == -1 ) {
374 $this->enableClientCache( false );
376 $this->mNoGallery
= $parserOutput->getNoGallery();
377 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
379 $this->mTemplateIds +
= (array)$parserOutput->mTemplateIds
;
382 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
383 $this->setPageTitle( $dt );
385 # Hooks registered in the object
386 global $wgParserOutputHooks;
387 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
388 list( $hookName, $data ) = $hookInfo;
389 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
390 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
394 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
399 * @param ParserOutput &$parserOutput
401 function addParserOutput( &$parserOutput ) {
402 $this->addParserOutputNoText( $parserOutput );
403 $text = $parserOutput->getText();
404 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
405 $this->addHTML( $text );
409 * Add wikitext to the buffer, assuming that this is the primary text for a page view
410 * Saves the text into the parser cache if possible.
412 * @param string $text
413 * @param Article $article
415 * @deprecated Use Article::outputWikitext
417 public function addPrimaryWikiText( $text, $article, $cache = true ) {
418 global $wgParser, $wgUser;
420 $popts = $this->parserOptions();
421 $popts->setTidy(true);
422 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
423 $popts, true, true, $this->mRevisionId
);
424 $popts->setTidy(false);
425 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
426 $parserCache =& ParserCache
::singleton();
427 $parserCache->save( $parserOutput, $article, $wgUser );
430 $this->addParserOutput( $parserOutput );
434 * @deprecated use addWikiTextTidy()
436 public function addSecondaryWikiText( $text, $linestart = true ) {
438 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
442 * Add wikitext with tidy enabled
444 public function addWikiTextTidy( $text, $linestart = true ) {
446 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
451 * Add the output of a QuickTemplate to the output buffer
453 * @param QuickTemplate $template
455 public function addTemplate( &$template ) {
457 $template->execute();
458 $this->addHTML( ob_get_contents() );
463 * Parse wikitext and return the HTML.
465 * @param string $text
466 * @param bool $linestart Is this the start of a line?
467 * @param bool $interface ??
469 public function parse( $text, $linestart = true, $interface = false ) {
470 global $wgParser, $wgTitle;
471 $popts = $this->parserOptions();
472 if ( $interface) { $popts->setInterfaceMessage(true); }
473 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
474 $linestart, true, $this->mRevisionId
);
475 if ( $interface) { $popts->setInterfaceMessage(false); }
476 return $parserOutput->getText();
480 * @param Article $article
483 * @return bool True if successful, else false.
485 public function tryParserCache( &$article, $user ) {
486 $parserCache =& ParserCache
::singleton();
487 $parserOutput = $parserCache->get( $article, $user );
488 if ( $parserOutput !== false ) {
489 $this->addParserOutput( $parserOutput );
497 * @param int $maxage Maximum cache time on the Squid, in seconds.
499 public function setSquidMaxage( $maxage ) {
500 $this->mSquidMaxage
= $maxage;
504 * Use enableClientCache(false) to force it to send nocache headers
507 public function enableClientCache( $state ) {
508 return wfSetVar( $this->mEnableClientCache
, $state );
511 function uncacheableBecauseRequestvars() {
513 return $wgRequest->getText('useskin', false) === false
514 && $wgRequest->getText('uselang', false) === false;
517 public function sendCacheControl() {
518 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
519 $fname = 'OutputPage::sendCacheControl';
521 if ($wgUseETag && $this->mETag
)
522 $wgRequest->response()->header("ETag: $this->mETag");
524 # don't serve compressed data to clients who can't handle it
525 # maintain different caches for logged-in users and non-logged in ones
526 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
527 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
528 if( $wgUseSquid && session_id() == '' &&
529 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
532 # We'll purge the proxy cache explicitly, but require end user agents
533 # to revalidate against the proxy on each visit.
534 # Surrogate-Control controls our Squid, Cache-Control downstream caches
535 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
536 # start with a shorter timeout for initial testing
537 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
538 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
539 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
541 # We'll purge the proxy cache for anons explicitly, but require end user agents
542 # to revalidate against the proxy on each visit.
543 # IMPORTANT! The Squid needs to replace the Cache-Control header with
544 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
545 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
546 # start with a shorter timeout for initial testing
547 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
548 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
551 # We do want clients to cache if they can, but they *must* check for updates
552 # on revisiting the page.
553 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
554 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
555 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
557 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
559 wfDebug( "$fname: no caching **\n", false );
561 # In general, the absence of a last modified header should be enough to prevent
562 # the client from using its cache. We send a few other things just to make sure.
563 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
564 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
565 $wgRequest->response()->header( 'Pragma: no-cache' );
570 * Finally, all the text has been munged and accumulated into
571 * the object, let's actually output it:
573 public function output() {
574 global $wgUser, $wgOutputEncoding, $wgRequest;
575 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
576 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
577 global $wgServer, $wgStyleVersion;
579 if( $this->mDoNothing
){
582 $fname = 'OutputPage::output';
583 wfProfileIn( $fname );
584 $sk = $wgUser->getSkin();
587 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
589 wfRunHooks( 'AjaxAddScript', array( &$this ) );
591 if( $wgAjaxSearch ) {
592 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
593 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
596 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
597 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
601 if ( '' != $this->mRedirect
) {
602 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
603 # Standards require redirect URLs to be absolute
605 $this->mRedirect
= $wgServer . $this->mRedirect
;
607 if( $this->mRedirectCode
== '301') {
608 if( !$wgDebugRedirects ) {
609 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
611 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
614 $this->sendCacheControl();
616 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
617 if( $wgDebugRedirects ) {
618 $url = htmlspecialchars( $this->mRedirect
);
619 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
620 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
621 print "</body>\n</html>\n";
623 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
625 wfProfileOut( $fname );
628 elseif ( $this->mStatusCode
)
630 $statusMessage = array(
632 101 => 'Switching Protocols',
637 203 => 'Non-Authoritative Information',
639 205 => 'Reset Content',
640 206 => 'Partial Content',
641 207 => 'Multi-Status',
642 300 => 'Multiple Choices',
643 301 => 'Moved Permanently',
646 304 => 'Not Modified',
648 307 => 'Temporary Redirect',
649 400 => 'Bad Request',
650 401 => 'Unauthorized',
651 402 => 'Payment Required',
654 405 => 'Method Not Allowed',
655 406 => 'Not Acceptable',
656 407 => 'Proxy Authentication Required',
657 408 => 'Request Timeout',
660 411 => 'Length Required',
661 412 => 'Precondition Failed',
662 413 => 'Request Entity Too Large',
663 414 => 'Request-URI Too Large',
664 415 => 'Unsupported Media Type',
665 416 => 'Request Range Not Satisfiable',
666 417 => 'Expectation Failed',
667 422 => 'Unprocessable Entity',
669 424 => 'Failed Dependency',
670 500 => 'Internal Server Error',
671 501 => 'Not Implemented',
672 502 => 'Bad Gateway',
673 503 => 'Service Unavailable',
674 504 => 'Gateway Timeout',
675 505 => 'HTTP Version Not Supported',
676 507 => 'Insufficient Storage'
679 if ( $statusMessage[$this->mStatusCode
] )
680 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
683 # Buffer output; final headers may depend on later processing
686 # Disable temporary placeholders, so that the skin produces HTML
687 $sk->postParseLinkColour( false );
689 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
690 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
692 if ($this->mArticleBodyOnly
) {
693 $this->out($this->mBodytext
);
695 wfProfileIn( 'Output-skin' );
696 $sk->outputPage( $this );
697 wfProfileOut( 'Output-skin' );
700 $this->sendCacheControl();
702 wfProfileOut( $fname );
709 public function out( $ins ) {
710 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
711 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
714 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
715 if ( false === $outs ) { $outs = $ins; }
723 public static function setEncodings() {
724 global $wgInputEncoding, $wgOutputEncoding;
725 global $wgUser, $wgContLang;
727 $wgInputEncoding = strtolower( $wgInputEncoding );
729 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
730 $wgOutputEncoding = strtolower( $wgOutputEncoding );
733 $wgOutputEncoding = $wgInputEncoding;
737 * Deprecated, use wfReportTime() instead.
741 public function reportTime() {
742 $time = wfReportTime();
747 * Produce a "user is blocked" page.
749 * @param bool $return Whether to have a "return to $wgTitle" message or not.
752 function blockedPage( $return = true ) {
753 global $wgUser, $wgContLang, $wgTitle, $wgLang;
755 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
756 $this->setRobotpolicy( 'noindex,nofollow' );
757 $this->setArticleRelated( false );
759 $name = User
::whoIs( $wgUser->blockedBy() );
760 $reason = $wgUser->blockedFor();
761 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
764 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
766 $blockid = $wgUser->mBlock
->mId
;
768 $blockExpiry = $wgUser->mBlock
->mExpiry
;
769 if ( $blockExpiry == 'infinity' ) {
770 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
771 // Search for localization in 'ipboptions'
772 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
773 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
774 if ( strpos( $option, ":" ) === false )
776 list( $show, $value ) = explode( ":", $option );
777 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
778 $blockExpiry = $show;
783 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
786 if ( $wgUser->mBlock
->mAuto
) {
787 $msg = 'autoblockedtext';
789 $msg = 'blockedtext';
792 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
793 * This could be a username, an ip range, or a single ip. */
794 $intended = $wgUser->mBlock
->mAddress
;
796 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp ) );
798 # Don't auto-return to special pages
800 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
801 $this->returnToMain( false, $return );
806 * Output a standard error page
808 * @param string $title Message key for page title
809 * @param string $msg Message key for page text
810 * @param array $params Message parameters
812 public function showErrorPage( $title, $msg, $params = array() ) {
815 $this->mDebugtext
.= 'Original title: ' .
816 $wgTitle->getPrefixedText() . "\n";
817 $this->setPageTitle( wfMsg( $title ) );
818 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
819 $this->setRobotpolicy( 'noindex,nofollow' );
820 $this->setArticleRelated( false );
821 $this->enableClientCache( false );
822 $this->mRedirect
= '';
823 $this->mBodytext
= '';
825 array_unshift( $params, 'parse' );
826 array_unshift( $params, $msg );
827 $this->addHtml( call_user_func_array( 'wfMsgExt', $params ) );
829 $this->returnToMain( false );
833 * Output a standard permission error page
835 * @param array $errors Error message keys
837 public function showPermissionsErrorPage( $errors )
841 $this->mDebugtext
.= 'Original title: ' .
842 $wgTitle->getPrefixedText() . "\n";
843 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
844 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
845 $this->setRobotpolicy( 'noindex,nofollow' );
846 $this->setArticleRelated( false );
847 $this->enableClientCache( false );
848 $this->mRedirect
= '';
849 $this->mBodytext
= '';
850 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors ) );
854 public function errorpage( $title, $msg ) {
855 throw new ErrorPageError( $title, $msg );
859 * Display an error page indicating that a given version of MediaWiki is
862 * @param mixed $version The version of MediaWiki needed to use the page
864 public function versionRequired( $version ) {
865 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
866 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
867 $this->setRobotpolicy( 'noindex,nofollow' );
868 $this->setArticleRelated( false );
869 $this->mBodytext
= '';
871 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
872 $this->returnToMain();
876 * Display an error page noting that a given permission bit is required.
878 * @param string $permission key required
880 public function permissionRequired( $permission ) {
881 global $wgGroupPermissions, $wgUser;
883 $this->setPageTitle( wfMsg( 'badaccess' ) );
884 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
885 $this->setRobotpolicy( 'noindex,nofollow' );
886 $this->setArticleRelated( false );
887 $this->mBodytext
= '';
890 foreach( $wgGroupPermissions as $key => $value ) {
891 if( isset( $value[$permission] ) && $value[$permission] == true ) {
892 $groupName = User
::getGroupName( $key );
893 $groupPage = User
::getGroupPage( $key );
895 $skin = $wgUser->getSkin();
896 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
898 $groups[] = $groupName;
902 $n = count( $groups );
903 $groups = implode( ', ', $groups );
908 $message = wfMsgHtml( "badaccess-group$n", $groups );
911 $message = wfMsgHtml( 'badaccess-groups', $groups );
913 $this->addHtml( $message );
914 $this->returnToMain( false );
918 * Use permissionRequired.
921 public function sysopRequired() {
922 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
926 * Use permissionRequired.
929 public function developerRequired() {
930 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
934 * Produce the stock "please login to use the wiki" page
936 public function loginToUse() {
937 global $wgUser, $wgTitle, $wgContLang;
939 if( $wgUser->isLoggedIn() ) {
940 $this->permissionRequired( 'read' );
944 $skin = $wgUser->getSkin();
946 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
947 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
948 $this->setRobotPolicy( 'noindex,nofollow' );
949 $this->setArticleFlag( false );
951 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
952 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
953 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
954 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
956 # Don't return to the main page if the user can't read it
957 # otherwise we'll end up in a pointless loop
958 $mainPage = Title
::newMainPage();
959 if( $mainPage->userCanRead() )
960 $this->returnToMain( true, $mainPage );
964 public function databaseError( $fname, $sql, $error, $errno ) {
965 throw new MWException( "OutputPage::databaseError is obsolete\n" );
969 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
970 * @return string The error-messages, formatted into a list.
972 public function formatPermissionsErrorMessage( $errors ) {
975 if (sizeof( $errors ) > 1) {
977 $text .= wfMsgExt( 'permissionserrorstext', array( 'parse' ), count( $errors ) ) . "\n";
978 $text .= '<ul class="permissions-errors">' . "\n";
980 foreach( $errors as $error )
983 $text .= call_user_func_array( 'wfMsg', $error );
988 $text .= call_user_func_array( 'wfMsg', $errors[0]);
996 * @param bool $protected Is the reason the page can't be reached because it's protected?
997 * @param mixed $source
998 * @param bool $protected, page is protected?
999 * @param array $reason, array of arrays( msg, args )
1001 public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
1002 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
1003 $skin = $wgUser->getSkin();
1005 $this->setRobotpolicy( 'noindex,nofollow' );
1006 $this->setArticleRelated( false );
1008 if ( !empty($reasons) ) {
1009 $this->setPageTitle( wfMsg( 'viewsource' ) );
1010 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1012 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) );
1013 } else if( $protected ) {
1014 $this->setPageTitle( wfMsg( 'viewsource' ) );
1015 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1016 list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources();
1018 // Show an appropriate explanation depending upon the reason
1019 // for the protection...all of these should be moved to the
1021 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
1022 // User isn't allowed to edit the interface
1023 $this->addWikiText( wfMsg( 'protectedinterface' ) );
1024 } elseif( $cascadeSources && ( $count = count( $cascadeSources ) ) > 0 ) {
1025 // Cascading protection
1027 foreach( $cascadeSources as $title )
1028 $titles .= "* [[:" . $title->getPrefixedText() . "]]\n";
1029 $this->addWikiText( wfMsgExt( 'cascadeprotected', 'parsemag', $count ) . "\n{$titles}" );
1030 } elseif( !$wgTitle->isProtected( 'edit' ) && $wgTitle->isNamespaceProtected() ) {
1031 // Namespace protection
1032 $ns = $wgTitle->getNamespace() == NS_MAIN
1033 ?
wfMsg( 'nstab-main' )
1034 : $wgTitle->getNsText();
1035 $this->addWikiText( wfMsg( 'namespaceprotected', $ns ) );
1037 // Standard protection
1038 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
1041 $this->setPageTitle( wfMsg( 'readonly' ) );
1042 if ( $wgReadOnly ) {
1043 $reason = $wgReadOnly;
1045 $reason = file_get_contents( $wgReadOnlyFile );
1047 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
1050 if( is_string( $source ) ) {
1051 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
1052 $rows = $wgUser->getIntOption( 'rows' );
1053 $cols = $wgUser->getIntOption( 'cols' );
1054 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
1055 htmlspecialchars( $source ) . "\n</textarea>";
1056 $this->addHTML( $text );
1058 $article = new Article( $wgTitle );
1059 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1061 $this->returnToMain( false );
1065 public function fatalError( $message ) {
1066 throw new FatalError( $message );
1070 public function unexpectedValueError( $name, $val ) {
1071 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1075 public function fileCopyError( $old, $new ) {
1076 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1080 public function fileRenameError( $old, $new ) {
1081 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1085 public function fileDeleteError( $name ) {
1086 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1090 public function fileNotFoundError( $name ) {
1091 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1094 public function showFatalError( $message ) {
1095 $this->setPageTitle( wfMsg( "internalerror" ) );
1096 $this->setRobotpolicy( "noindex,nofollow" );
1097 $this->setArticleRelated( false );
1098 $this->enableClientCache( false );
1099 $this->mRedirect
= '';
1100 $this->mBodytext
= $message;
1103 public function showUnexpectedValueError( $name, $val ) {
1104 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1107 public function showFileCopyError( $old, $new ) {
1108 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1111 public function showFileRenameError( $old, $new ) {
1112 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1115 public function showFileDeleteError( $name ) {
1116 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1119 public function showFileNotFoundError( $name ) {
1120 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1124 * Add a "return to" link pointing to a specified title
1126 * @param Title $title Title to link
1128 public function addReturnTo( $title ) {
1130 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1131 $this->addHtml( "<p>{$link}</p>\n" );
1135 * Add a "return to" link pointing to a specified title,
1136 * or the title indicated in the request, or else the main page
1138 * @param null $unused No longer used
1139 * @param Title $returnto Title to return to
1141 public function returnToMain( $unused = null, $returnto = NULL ) {
1144 if ( $returnto == NULL ) {
1145 $returnto = $wgRequest->getText( 'returnto' );
1148 if ( '' === $returnto ) {
1149 $returnto = Title
::newMainPage();
1152 if ( is_object( $returnto ) ) {
1153 $titleObj = $returnto;
1155 $titleObj = Title
::newFromText( $returnto );
1157 if ( !is_object( $titleObj ) ) {
1158 $titleObj = Title
::newMainPage();
1161 $this->addReturnTo( $titleObj );
1165 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1166 * and uses the first 10 of them for META keywords
1168 * @param ParserOutput &$parserOutput
1170 private function addKeywords( &$parserOutput ) {
1172 $this->addKeyword( $wgTitle->getPrefixedText() );
1174 $links2d =& $parserOutput->getLinks();
1175 if ( !is_array( $links2d ) ) {
1178 foreach ( $links2d as $dbkeys ) {
1179 foreach( $dbkeys as $dbkey => $unused ) {
1180 $this->addKeyword( $dbkey );
1181 if ( ++
$count > 10 ) {
1189 * @return string The doctype, opening <html>, and head element.
1191 public function headElement() {
1192 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1193 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1194 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1196 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1197 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1202 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1204 if ( '' == $this->getHTMLTitle() ) {
1205 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1208 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1209 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1210 foreach($wgXhtmlNamespaces as $tag => $ns) {
1211 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1213 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1214 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1215 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1217 $ret .= $this->getHeadLinks();
1218 global $wgStylePath;
1219 if( $this->isPrintable() ) {
1222 $media = "media='print'";
1224 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1225 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1227 $sk = $wgUser->getSkin();
1228 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1229 $ret .= $this->mScripts
;
1230 $ret .= $sk->getUserStyles();
1231 $ret .= $this->getHeadItems();
1233 if ($wgUseTrackbacks && $this->isArticleRelated())
1234 $ret .= $wgTitle->trackbackRDF();
1236 $ret .= "</head>\n";
1241 * @return string HTML tag links to be put in the header.
1243 public function getHeadLinks() {
1246 foreach ( $this->mMetatags
as $tag ) {
1247 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1249 $tag[0] = substr( $tag[0], 5 );
1253 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1256 $p = $this->mRobotpolicy
;
1257 if( $p !== '' && $p != 'index,follow' ) {
1258 // http://www.robotstxt.org/wc/meta-user.html
1259 // Only show if it's different from the default robots policy
1260 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1263 if ( count( $this->mKeywords
) > 0 ) {
1268 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1269 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1271 foreach ( $this->mLinktags
as $tag ) {
1272 $ret .= "\t\t<link";
1273 foreach( $tag as $attr => $val ) {
1274 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1278 if( $this->isSyndicated() ) {
1279 # FIXME: centralize the mime-type and name information in Feed.php
1280 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1281 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1282 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1283 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 1.0' href='$link' />\n";
1290 * Turn off regular page output and return an error reponse
1291 * for when rate limiting has triggered.
1294 public function rateLimited() {
1297 wfHttpError( 500, 'Internal Server Error',
1298 'Sorry, the server has encountered an internal error. ' .
1299 'Please wait a moment and hit "refresh" to submit the request again.' );
1303 * Show an "add new section" link?
1307 public function showNewSectionLink() {
1308 return $this->mNewSectionLink
;
1312 * Show a warning about slave lag
1314 * If the lag is higher than $wgSlaveLagCritical seconds,
1315 * then the warning is a bit more obvious. If the lag is
1316 * lower than $wgSlaveLagWarning, then no warning is shown.
1318 * @param int $lag Slave lag
1320 public function showLagWarning( $lag ) {
1321 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1322 if( $lag >= $wgSlaveLagWarning ) {
1323 $message = $lag < $wgSlaveLagCritical
1326 $warning = wfMsgExt( $message, 'parse', $lag );
1327 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );