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;
67 public function getRedirect() {
68 return $this->mRedirect
;
72 * Set the HTTP status code to send with the output.
74 * @param int $statusCode
77 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
79 # To add an http-equiv meta tag, precede the name with "http:"
80 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
81 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
82 function addScript( $script ) { $this->mScripts
.= "\t\t".$script; }
83 function addStyle( $style ) {
84 global $wgStylePath, $wgStyleVersion;
87 'rel' => 'stylesheet',
88 'href' => $wgStylePath . '/' . $style . '?' . $wgStyleVersion ) );
92 * Add a self-contained script tag with the given contents
93 * @param string $script JavaScript text, no <script> tags
95 function addInlineScript( $script ) {
97 $this->mScripts
.= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
100 function getScript() {
101 return $this->mScripts
. $this->getHeadItems();
104 function getHeadItems() {
106 foreach ( $this->mHeadItems
as $item ) {
112 function addHeadItem( $name, $value ) {
113 $this->mHeadItems
[$name] = $value;
116 function hasHeadItem( $name ) {
117 return isset( $this->mHeadItems
[$name] );
120 function setETag($tag) { $this->mETag
= $tag; }
121 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
122 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
124 function addLink( $linkarr ) {
125 # $linkarr should be an associative array of attributes. We'll escape on output.
126 array_push( $this->mLinktags
, $linkarr );
129 function addMetadataLink( $linkarr ) {
130 # note: buggy CC software only reads first "meta" link
131 static $haveMeta = false;
132 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
133 $this->addLink( $linkarr );
138 * checkLastModified tells the client to use the client-cached page if
139 * possible. If sucessful, the OutputPage is disabled so that
140 * any future call to OutputPage->output() have no effect.
142 * @return bool True iff cache-ok headers was sent.
144 function checkLastModified ( $timestamp ) {
145 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
146 $fname = 'OutputPage::checkLastModified';
148 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
149 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
152 if( !$wgCachePages ) {
153 wfDebug( "$fname: CACHE DISABLED\n", false );
156 if( $wgUser->getOption( 'nocache' ) ) {
157 wfDebug( "$fname: USER DISABLED CACHE\n", false );
161 $timestamp=wfTimestamp(TS_MW
,$timestamp);
162 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
164 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
165 # IE sends sizes after the date like this:
166 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
167 # this breaks strtotime().
168 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
170 wfSuppressWarnings(); // E_STRICT system time bitching
171 $modsinceTime = strtotime( $modsince );
174 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
175 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
176 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
177 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
178 # Make sure you're in a place you can leave when you call us!
179 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
180 $this->mLastModified
= $lastmod;
181 $this->sendCacheControl();
182 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
185 // Don't output a compressed blob when using ob_gzhandler;
186 // it's technically against HTTP spec and seems to confuse
187 // Firefox when the response gets split over two packets.
188 wfClearOutputBuffers();
192 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
193 $this->mLastModified
= $lastmod;
196 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
197 $this->mLastModified
= $lastmod;
201 function setPageTitleActionText( $text ) {
202 $this->mPageTitleActionText
= $text;
205 function getPageTitleActionText () {
206 if ( isset( $this->mPageTitleActionText
) ) {
207 return $this->mPageTitleActionText
;
211 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
212 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
213 public function setPageTitle( $name ) {
214 global $action, $wgContLang;
215 $name = $wgContLang->convert($name, true);
216 $this->mPagetitle
= $name;
217 if(!empty($action)) {
218 $taction = $this->getPageTitleActionText();
219 if( !empty( $taction ) ) {
220 $name .= ' - '.$taction;
224 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
226 public function getHTMLTitle() { return $this->mHTMLtitle
; }
227 public function getPageTitle() { return $this->mPagetitle
; }
228 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
229 public function getSubtitle() { return $this->mSubtitle
; }
230 public function isArticle() { return $this->mIsarticle
; }
231 public function setPrintable() { $this->mPrintable
= true; }
232 public function isPrintable() { return $this->mPrintable
; }
233 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
234 public function isSyndicated() { return $this->mShowFeedLinks
; }
235 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
236 public function getOnloadHandler() { return $this->mOnloadHandler
; }
237 public function disable() { $this->mDoNothing
= true; }
239 public function setArticleRelated( $v ) {
240 $this->mIsArticleRelated
= $v;
242 $this->mIsarticle
= false;
245 public function setArticleFlag( $v ) {
246 $this->mIsarticle
= $v;
248 $this->mIsArticleRelated
= $v;
252 public function isArticleRelated() { return $this->mIsArticleRelated
; }
254 public function getLanguageLinks() { return $this->mLanguageLinks
; }
255 public function addLanguageLinks($newLinkArray) {
256 $this->mLanguageLinks +
= $newLinkArray;
258 public function setLanguageLinks($newLinkArray) {
259 $this->mLanguageLinks
= $newLinkArray;
262 public function getCategoryLinks() {
263 return $this->mCategoryLinks
;
267 * Add an array of categories, with names in the keys
269 public function addCategoryLinks($categories) {
270 global $wgUser, $wgContLang;
272 if ( !is_array( $categories ) ) {
275 # Add the links to the link cache in a batch
276 $arr = array( NS_CATEGORY
=> $categories );
278 $lb->setArray( $arr );
281 $sk = $wgUser->getSkin();
282 foreach ( $categories as $category => $unused ) {
283 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
284 $text = $wgContLang->convertHtml( $title->getText() );
285 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
289 public function setCategoryLinks($categories) {
290 $this->mCategoryLinks
= array();
291 $this->addCategoryLinks($categories);
294 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
295 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
297 public function disallowUserJs() { $this->mAllowUserJs
= false; }
298 public function isUserJsAllowed() { return $this->mAllowUserJs
; }
300 public function addHTML( $text ) { $this->mBodytext
.= $text; }
301 public function clearHTML() { $this->mBodytext
= ''; }
302 public function getHTML() { return $this->mBodytext
; }
303 public function debug( $text ) { $this->mDebugtext
.= $text; }
306 public function setParserOptions( $options ) {
307 return $this->parserOptions( $options );
310 public function parserOptions( $options = null ) {
311 if ( !$this->mParserOptions
) {
312 $this->mParserOptions
= new ParserOptions
;
314 return wfSetVar( $this->mParserOptions
, $options );
318 * Set the revision ID which will be seen by the wiki text parser
319 * for things such as embedded {{REVISIONID}} variable use.
320 * @param mixed $revid an integer, or NULL
321 * @return mixed previous value
323 public function setRevisionId( $revid ) {
324 $val = is_null( $revid ) ?
null : intval( $revid );
325 return wfSetVar( $this->mRevisionId
, $val );
329 * Convert wikitext to HTML and add it to the buffer
330 * Default assumes that the current page title will
333 * @param string $text
334 * @param bool $linestart
336 public function addWikiText( $text, $linestart = true ) {
338 $this->addWikiTextTitle($text, $wgTitle, $linestart);
341 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
342 $this->addWikiTextTitle($text, $title, $linestart);
345 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
346 $this->addWikiTextTitle( $text, $title, $linestart, true );
349 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
352 $fname = 'OutputPage:addWikiTextTitle';
355 wfIncrStats('pcache_not_possible');
357 $popts = $this->parserOptions();
358 $oldTidy = $popts->setTidy($tidy);
360 $parserOutput = $wgParser->parse( $text, $title, $popts,
361 $linestart, true, $this->mRevisionId
);
363 $popts->setTidy( $oldTidy );
365 $this->addParserOutput( $parserOutput );
367 wfProfileOut($fname);
372 * @param ParserOutput object &$parserOutput
374 public function addParserOutputNoText( &$parserOutput ) {
375 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
376 $this->addCategoryLinks( $parserOutput->getCategories() );
377 $this->mNewSectionLink
= $parserOutput->getNewSection();
378 $this->addKeywords( $parserOutput );
379 if ( $parserOutput->getCacheTime() == -1 ) {
380 $this->enableClientCache( false );
382 $this->mNoGallery
= $parserOutput->getNoGallery();
383 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
385 $this->mTemplateIds +
= (array)$parserOutput->mTemplateIds
;
388 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
389 $this->setPageTitle( $dt );
391 # Hooks registered in the object
392 global $wgParserOutputHooks;
393 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
394 list( $hookName, $data ) = $hookInfo;
395 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
396 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
400 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
405 * @param ParserOutput &$parserOutput
407 function addParserOutput( &$parserOutput ) {
408 $this->addParserOutputNoText( $parserOutput );
409 $text = $parserOutput->getText();
410 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
411 $this->addHTML( $text );
415 * Add wikitext to the buffer, assuming that this is the primary text for a page view
416 * Saves the text into the parser cache if possible.
418 * @param string $text
419 * @param Article $article
421 * @deprecated Use Article::outputWikitext
423 public function addPrimaryWikiText( $text, $article, $cache = true ) {
424 global $wgParser, $wgUser;
426 $popts = $this->parserOptions();
427 $popts->setTidy(true);
428 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
429 $popts, true, true, $this->mRevisionId
);
430 $popts->setTidy(false);
431 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
432 $parserCache =& ParserCache
::singleton();
433 $parserCache->save( $parserOutput, $article, $wgUser );
436 $this->addParserOutput( $parserOutput );
440 * @deprecated use addWikiTextTidy()
442 public function addSecondaryWikiText( $text, $linestart = true ) {
444 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
448 * Add wikitext with tidy enabled
450 public function addWikiTextTidy( $text, $linestart = true ) {
452 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
457 * Add the output of a QuickTemplate to the output buffer
459 * @param QuickTemplate $template
461 public function addTemplate( &$template ) {
463 $template->execute();
464 $this->addHTML( ob_get_contents() );
469 * Parse wikitext and return the HTML.
471 * @param string $text
472 * @param bool $linestart Is this the start of a line?
473 * @param bool $interface ??
475 public function parse( $text, $linestart = true, $interface = false ) {
476 global $wgParser, $wgTitle;
477 $popts = $this->parserOptions();
478 if ( $interface) { $popts->setInterfaceMessage(true); }
479 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
480 $linestart, true, $this->mRevisionId
);
481 if ( $interface) { $popts->setInterfaceMessage(false); }
482 return $parserOutput->getText();
486 * @param Article $article
489 * @return bool True if successful, else false.
491 public function tryParserCache( &$article, $user ) {
492 $parserCache =& ParserCache
::singleton();
493 $parserOutput = $parserCache->get( $article, $user );
494 if ( $parserOutput !== false ) {
495 $this->addParserOutput( $parserOutput );
503 * @param int $maxage Maximum cache time on the Squid, in seconds.
505 public function setSquidMaxage( $maxage ) {
506 $this->mSquidMaxage
= $maxage;
510 * Use enableClientCache(false) to force it to send nocache headers
513 public function enableClientCache( $state ) {
514 return wfSetVar( $this->mEnableClientCache
, $state );
517 function uncacheableBecauseRequestvars() {
519 return $wgRequest->getText('useskin', false) === false
520 && $wgRequest->getText('uselang', false) === false;
523 public function sendCacheControl() {
524 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
525 $fname = 'OutputPage::sendCacheControl';
527 if ($wgUseETag && $this->mETag
)
528 $wgRequest->response()->header("ETag: $this->mETag");
530 # don't serve compressed data to clients who can't handle it
531 # maintain different caches for logged-in users and non-logged in ones
532 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
533 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
534 if( $wgUseSquid && session_id() == '' &&
535 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
538 # We'll purge the proxy cache explicitly, but require end user agents
539 # to revalidate against the proxy on each visit.
540 # Surrogate-Control controls our Squid, Cache-Control downstream caches
541 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
542 # start with a shorter timeout for initial testing
543 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
544 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
545 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
547 # We'll purge the proxy cache for anons explicitly, but require end user agents
548 # to revalidate against the proxy on each visit.
549 # IMPORTANT! The Squid needs to replace the Cache-Control header with
550 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
551 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
552 # start with a shorter timeout for initial testing
553 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
554 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
557 # We do want clients to cache if they can, but they *must* check for updates
558 # on revisiting the page.
559 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
560 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
561 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
563 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
565 wfDebug( "$fname: no caching **\n", false );
567 # In general, the absence of a last modified header should be enough to prevent
568 # the client from using its cache. We send a few other things just to make sure.
569 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
570 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
571 $wgRequest->response()->header( 'Pragma: no-cache' );
576 * Finally, all the text has been munged and accumulated into
577 * the object, let's actually output it:
579 public function output() {
580 global $wgUser, $wgOutputEncoding, $wgRequest;
581 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
582 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
583 global $wgServer, $wgStyleVersion;
585 if( $this->mDoNothing
){
588 $fname = 'OutputPage::output';
589 wfProfileIn( $fname );
590 $sk = $wgUser->getSkin();
593 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
595 wfRunHooks( 'AjaxAddScript', array( &$this ) );
597 if( $wgAjaxSearch ) {
598 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
599 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
602 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
603 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
607 if ( '' != $this->mRedirect
) {
608 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
609 # Standards require redirect URLs to be absolute
611 $this->mRedirect
= $wgServer . $this->mRedirect
;
613 if( $this->mRedirectCode
== '301') {
614 if( !$wgDebugRedirects ) {
615 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
617 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
620 $this->sendCacheControl();
622 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
623 if( $wgDebugRedirects ) {
624 $url = htmlspecialchars( $this->mRedirect
);
625 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
626 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
627 print "</body>\n</html>\n";
629 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
631 wfProfileOut( $fname );
634 elseif ( $this->mStatusCode
)
636 $statusMessage = array(
638 101 => 'Switching Protocols',
643 203 => 'Non-Authoritative Information',
645 205 => 'Reset Content',
646 206 => 'Partial Content',
647 207 => 'Multi-Status',
648 300 => 'Multiple Choices',
649 301 => 'Moved Permanently',
652 304 => 'Not Modified',
654 307 => 'Temporary Redirect',
655 400 => 'Bad Request',
656 401 => 'Unauthorized',
657 402 => 'Payment Required',
660 405 => 'Method Not Allowed',
661 406 => 'Not Acceptable',
662 407 => 'Proxy Authentication Required',
663 408 => 'Request Timeout',
666 411 => 'Length Required',
667 412 => 'Precondition Failed',
668 413 => 'Request Entity Too Large',
669 414 => 'Request-URI Too Large',
670 415 => 'Unsupported Media Type',
671 416 => 'Request Range Not Satisfiable',
672 417 => 'Expectation Failed',
673 422 => 'Unprocessable Entity',
675 424 => 'Failed Dependency',
676 500 => 'Internal Server Error',
677 501 => 'Not Implemented',
678 502 => 'Bad Gateway',
679 503 => 'Service Unavailable',
680 504 => 'Gateway Timeout',
681 505 => 'HTTP Version Not Supported',
682 507 => 'Insufficient Storage'
685 if ( $statusMessage[$this->mStatusCode
] )
686 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
689 # Buffer output; final headers may depend on later processing
692 # Disable temporary placeholders, so that the skin produces HTML
693 $sk->postParseLinkColour( false );
695 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
696 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
698 if ($this->mArticleBodyOnly
) {
699 $this->out($this->mBodytext
);
701 wfProfileIn( 'Output-skin' );
702 $sk->outputPage( $this );
703 wfProfileOut( 'Output-skin' );
706 $this->sendCacheControl();
708 wfProfileOut( $fname );
715 public function out( $ins ) {
716 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
717 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
720 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
721 if ( false === $outs ) { $outs = $ins; }
729 public static function setEncodings() {
730 global $wgInputEncoding, $wgOutputEncoding;
731 global $wgUser, $wgContLang;
733 $wgInputEncoding = strtolower( $wgInputEncoding );
735 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
736 $wgOutputEncoding = strtolower( $wgOutputEncoding );
739 $wgOutputEncoding = $wgInputEncoding;
743 * Deprecated, use wfReportTime() instead.
747 public function reportTime() {
748 $time = wfReportTime();
753 * Produce a "user is blocked" page.
755 * @param bool $return Whether to have a "return to $wgTitle" message or not.
758 function blockedPage( $return = true ) {
759 global $wgUser, $wgContLang, $wgTitle, $wgLang;
761 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
762 $this->setRobotpolicy( 'noindex,nofollow' );
763 $this->setArticleRelated( false );
765 $name = User
::whoIs( $wgUser->blockedBy() );
766 $reason = $wgUser->blockedFor();
767 if( $reason == '' ) {
768 $reason = wfMsg( 'blockednoreason' );
770 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
773 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
775 $blockid = $wgUser->mBlock
->mId
;
777 $blockExpiry = $wgUser->mBlock
->mExpiry
;
778 if ( $blockExpiry == 'infinity' ) {
779 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
780 // Search for localization in 'ipboptions'
781 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
782 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
783 if ( strpos( $option, ":" ) === false )
785 list( $show, $value ) = explode( ":", $option );
786 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
787 $blockExpiry = $show;
792 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
795 if ( $wgUser->mBlock
->mAuto
) {
796 $msg = 'autoblockedtext';
798 $msg = 'blockedtext';
801 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
802 * This could be a username, an ip range, or a single ip. */
803 $intended = $wgUser->mBlock
->mAddress
;
805 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp ) );
807 # Don't auto-return to special pages
809 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
810 $this->returnToMain( false, $return );
815 * Output a standard error page
817 * @param string $title Message key for page title
818 * @param string $msg Message key for page text
819 * @param array $params Message parameters
821 public function showErrorPage( $title, $msg, $params = array() ) {
824 $this->mDebugtext
.= 'Original title: ' .
825 $wgTitle->getPrefixedText() . "\n";
826 $this->setPageTitle( wfMsg( $title ) );
827 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
828 $this->setRobotpolicy( 'noindex,nofollow' );
829 $this->setArticleRelated( false );
830 $this->enableClientCache( false );
831 $this->mRedirect
= '';
832 $this->mBodytext
= '';
834 array_unshift( $params, 'parse' );
835 array_unshift( $params, $msg );
836 $this->addHtml( call_user_func_array( 'wfMsgExt', $params ) );
838 $this->returnToMain( false );
842 * Output a standard permission error page
844 * @param array $errors Error message keys
846 public function showPermissionsErrorPage( $errors )
850 $this->mDebugtext
.= 'Original title: ' .
851 $wgTitle->getPrefixedText() . "\n";
852 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
853 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
854 $this->setRobotpolicy( 'noindex,nofollow' );
855 $this->setArticleRelated( false );
856 $this->enableClientCache( false );
857 $this->mRedirect
= '';
858 $this->mBodytext
= '';
859 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors ) );
863 public function errorpage( $title, $msg ) {
864 throw new ErrorPageError( $title, $msg );
868 * Display an error page indicating that a given version of MediaWiki is
871 * @param mixed $version The version of MediaWiki needed to use the page
873 public function versionRequired( $version ) {
874 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
875 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
876 $this->setRobotpolicy( 'noindex,nofollow' );
877 $this->setArticleRelated( false );
878 $this->mBodytext
= '';
880 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
881 $this->returnToMain();
885 * Display an error page noting that a given permission bit is required.
887 * @param string $permission key required
889 public function permissionRequired( $permission ) {
890 global $wgGroupPermissions, $wgUser;
892 $this->setPageTitle( wfMsg( 'badaccess' ) );
893 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
894 $this->setRobotpolicy( 'noindex,nofollow' );
895 $this->setArticleRelated( false );
896 $this->mBodytext
= '';
899 foreach( $wgGroupPermissions as $key => $value ) {
900 if( isset( $value[$permission] ) && $value[$permission] == true ) {
901 $groupName = User
::getGroupName( $key );
902 $groupPage = User
::getGroupPage( $key );
904 $skin = $wgUser->getSkin();
905 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
907 $groups[] = $groupName;
911 $n = count( $groups );
912 $groups = implode( ', ', $groups );
917 $message = wfMsgHtml( "badaccess-group$n", $groups );
920 $message = wfMsgHtml( 'badaccess-groups', $groups );
922 $this->addHtml( $message );
923 $this->returnToMain( false );
927 * Use permissionRequired.
930 public function sysopRequired() {
931 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
935 * Use permissionRequired.
938 public function developerRequired() {
939 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
943 * Produce the stock "please login to use the wiki" page
945 public function loginToUse() {
946 global $wgUser, $wgTitle, $wgContLang;
948 if( $wgUser->isLoggedIn() ) {
949 $this->permissionRequired( 'read' );
953 $skin = $wgUser->getSkin();
955 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
956 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
957 $this->setRobotPolicy( 'noindex,nofollow' );
958 $this->setArticleFlag( false );
960 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
961 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
962 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
963 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
965 # Don't return to the main page if the user can't read it
966 # otherwise we'll end up in a pointless loop
967 $mainPage = Title
::newMainPage();
968 if( $mainPage->userCanRead() )
969 $this->returnToMain( true, $mainPage );
973 public function databaseError( $fname, $sql, $error, $errno ) {
974 throw new MWException( "OutputPage::databaseError is obsolete\n" );
978 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
979 * @return string The error-messages, formatted into a list.
981 public function formatPermissionsErrorMessage( $errors ) {
984 if (sizeof( $errors ) > 1) {
986 $text .= wfMsgExt( 'permissionserrorstext', array( 'parse' ), count( $errors ) ) . "\n";
987 $text .= '<ul class="permissions-errors">' . "\n";
989 foreach( $errors as $error )
992 $text .= call_user_func_array( 'wfMsg', $error );
997 $text .= call_user_func_array( 'wfMsg', $errors[0]);
1005 * @param bool $protected Is the reason the page can't be reached because it's protected?
1006 * @param mixed $source
1007 * @param bool $protected, page is protected?
1008 * @param array $reason, array of arrays( msg, args )
1010 public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
1011 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
1012 $skin = $wgUser->getSkin();
1014 $this->setRobotpolicy( 'noindex,nofollow' );
1015 $this->setArticleRelated( false );
1017 if ( !empty($reasons) ) {
1018 $this->setPageTitle( wfMsg( 'viewsource' ) );
1019 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1021 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) );
1022 } else if( $protected ) {
1023 $this->setPageTitle( wfMsg( 'viewsource' ) );
1024 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1025 list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources();
1027 // Show an appropriate explanation depending upon the reason
1028 // for the protection...all of these should be moved to the
1030 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
1031 // User isn't allowed to edit the interface
1032 $this->addWikiText( wfMsg( 'protectedinterface' ) );
1033 } elseif( $cascadeSources && ( $count = count( $cascadeSources ) ) > 0 ) {
1034 // Cascading protection
1036 foreach( $cascadeSources as $title )
1037 $titles .= "* [[:" . $title->getPrefixedText() . "]]\n";
1038 $this->addWikiText( wfMsgExt( 'cascadeprotected', 'parsemag', $count, "\n{$titles}" ) );
1039 } elseif( !$wgTitle->isProtected( 'edit' ) && $wgTitle->isNamespaceProtected() ) {
1040 // Namespace protection
1041 $ns = $wgTitle->getNamespace() == NS_MAIN
1042 ?
wfMsg( 'nstab-main' )
1043 : $wgTitle->getNsText();
1044 $this->addWikiText( wfMsg( 'namespaceprotected', $ns ) );
1046 // Standard protection
1047 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
1050 $this->setPageTitle( wfMsg( 'readonly' ) );
1051 if ( $wgReadOnly ) {
1052 $reason = $wgReadOnly;
1054 $reason = file_get_contents( $wgReadOnlyFile );
1056 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
1059 if( is_string( $source ) ) {
1060 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
1061 $rows = $wgUser->getIntOption( 'rows' );
1062 $cols = $wgUser->getIntOption( 'cols' );
1063 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
1064 htmlspecialchars( $source ) . "\n</textarea>";
1065 $this->addHTML( $text );
1067 $article = new Article( $wgTitle );
1068 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1070 $this->returnToMain( false, $wgTitle );
1074 public function fatalError( $message ) {
1075 throw new FatalError( $message );
1079 public function unexpectedValueError( $name, $val ) {
1080 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1084 public function fileCopyError( $old, $new ) {
1085 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1089 public function fileRenameError( $old, $new ) {
1090 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1094 public function fileDeleteError( $name ) {
1095 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1099 public function fileNotFoundError( $name ) {
1100 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1103 public function showFatalError( $message ) {
1104 $this->setPageTitle( wfMsg( "internalerror" ) );
1105 $this->setRobotpolicy( "noindex,nofollow" );
1106 $this->setArticleRelated( false );
1107 $this->enableClientCache( false );
1108 $this->mRedirect
= '';
1109 $this->mBodytext
= $message;
1112 public function showUnexpectedValueError( $name, $val ) {
1113 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1116 public function showFileCopyError( $old, $new ) {
1117 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1120 public function showFileRenameError( $old, $new ) {
1121 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1124 public function showFileDeleteError( $name ) {
1125 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1128 public function showFileNotFoundError( $name ) {
1129 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1133 * Add a "return to" link pointing to a specified title
1135 * @param Title $title Title to link
1137 public function addReturnTo( $title ) {
1139 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1140 $this->addHtml( "<p>{$link}</p>\n" );
1144 * Add a "return to" link pointing to a specified title,
1145 * or the title indicated in the request, or else the main page
1147 * @param null $unused No longer used
1148 * @param Title $returnto Title to return to
1150 public function returnToMain( $unused = null, $returnto = NULL ) {
1153 if ( $returnto == NULL ) {
1154 $returnto = $wgRequest->getText( 'returnto' );
1157 if ( '' === $returnto ) {
1158 $returnto = Title
::newMainPage();
1161 if ( is_object( $returnto ) ) {
1162 $titleObj = $returnto;
1164 $titleObj = Title
::newFromText( $returnto );
1166 if ( !is_object( $titleObj ) ) {
1167 $titleObj = Title
::newMainPage();
1170 $this->addReturnTo( $titleObj );
1174 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1175 * and uses the first 10 of them for META keywords
1177 * @param ParserOutput &$parserOutput
1179 private function addKeywords( &$parserOutput ) {
1181 $this->addKeyword( $wgTitle->getPrefixedText() );
1183 $links2d =& $parserOutput->getLinks();
1184 if ( !is_array( $links2d ) ) {
1187 foreach ( $links2d as $dbkeys ) {
1188 foreach( $dbkeys as $dbkey => $unused ) {
1189 $this->addKeyword( $dbkey );
1190 if ( ++
$count > 10 ) {
1198 * @return string The doctype, opening <html>, and head element.
1200 public function headElement() {
1201 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1202 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1203 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1205 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1206 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1211 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1213 if ( '' == $this->getHTMLTitle() ) {
1214 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1217 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1218 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1219 foreach($wgXhtmlNamespaces as $tag => $ns) {
1220 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1222 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1223 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1224 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1226 $ret .= $this->getHeadLinks();
1227 global $wgStylePath;
1228 if( $this->isPrintable() ) {
1231 $media = "media='print'";
1233 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1234 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1236 $sk = $wgUser->getSkin();
1237 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1238 $ret .= $this->mScripts
;
1239 $ret .= $sk->getUserStyles();
1240 $ret .= $this->getHeadItems();
1242 if ($wgUseTrackbacks && $this->isArticleRelated())
1243 $ret .= $wgTitle->trackbackRDF();
1245 $ret .= "</head>\n";
1250 * @return string HTML tag links to be put in the header.
1252 public function getHeadLinks() {
1255 foreach ( $this->mMetatags
as $tag ) {
1256 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1258 $tag[0] = substr( $tag[0], 5 );
1262 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1265 $p = $this->mRobotpolicy
;
1266 if( $p !== '' && $p != 'index,follow' ) {
1267 // http://www.robotstxt.org/wc/meta-user.html
1268 // Only show if it's different from the default robots policy
1269 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1272 if ( count( $this->mKeywords
) > 0 ) {
1277 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1278 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1280 foreach ( $this->mLinktags
as $tag ) {
1281 $ret .= "\t\t<link";
1282 foreach( $tag as $attr => $val ) {
1283 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1288 if( $this->isSyndicated() ) {
1289 # FIXME: centralize the mime-type and name information in Feed.php
1290 # Use the page name for the title (accessed through $wgTitle since
1291 # there's no other way). In principle, this could lead to issues
1292 # with having the same name for different feeds corresponding to
1293 # the same page, but we can't avoid that at this low a level.
1295 $ret .= $this->feedLink(
1297 $wgRequest->appendQuery( 'feed=rss' ),
1298 wfMsg( 'page-rss-feed', $wgTitle->getPrefixedText() ) );
1299 $ret .= $this->feedLink(
1301 $wgRequest->appendQuery( 'feed=atom' ),
1302 wfMsg( 'page-atom-feed', $wgTitle->getPrefixedText() ) );
1305 # Recent changes feed should appear on every page
1306 # Put it after the per-page feed to avoid changing existing behavior.
1307 # It's still available, probably via a menu in your browser.
1309 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
1310 $ret .= $this->feedLink(
1312 $rctitle->getFullURL( 'feed=rss' ),
1313 wfMsg( 'site-rss-feed', $wgSitename ) );
1314 $ret .= $this->feedLink(
1316 $rctitle->getFullURL( 'feed=atom' ),
1317 wfMsg( 'site-atom-feed', $wgSitename ) );
1323 * Generate a <link rel/> for an RSS feed.
1325 private function feedLink( $type, $url, $text ) {
1326 return Xml
::element( 'link', array(
1327 'rel' => 'alternate',
1328 'type' => "application/$type+xml",
1330 'href' => $url ) ) . "\n";
1334 * Turn off regular page output and return an error reponse
1335 * for when rate limiting has triggered.
1338 public function rateLimited() {
1341 wfHttpError( 500, 'Internal Server Error',
1342 'Sorry, the server has encountered an internal error. ' .
1343 'Please wait a moment and hit "refresh" to submit the request again.' );
1347 * Show an "add new section" link?
1351 public function showNewSectionLink() {
1352 return $this->mNewSectionLink
;
1356 * Show a warning about slave lag
1358 * If the lag is higher than $wgSlaveLagCritical seconds,
1359 * then the warning is a bit more obvious. If the lag is
1360 * lower than $wgSlaveLagWarning, then no warning is shown.
1362 * @param int $lag Slave lag
1364 public function showLagWarning( $lag ) {
1365 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1366 if( $lag >= $wgSlaveLagWarning ) {
1367 $message = $lag < $wgSlaveLagCritical
1370 $warning = wfMsgExt( $message, 'parse', $lag );
1371 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );