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 $mFeedLinksAppendQuery = false;
27 var $mEnableClientCache = true;
28 var $mArticleBodyOnly = false;
30 var $mNewSectionLink = false;
31 var $mNoGallery = false;
32 var $mPageTitleActionText = '';
36 * Initialise private variables
38 function __construct() {
39 global $wgAllowUserJs;
40 $this->mAllowUserJs
= $wgAllowUserJs;
41 $this->mMetatags
= $this->mKeywords
= $this->mLinktags
= array();
42 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
43 $this->mRedirect
= $this->mLastModified
=
44 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
45 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
46 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
47 $this->mSuppressQuickbar
= $this->mPrintable
= false;
48 $this->mLanguageLinks
= array();
49 $this->mCategoryLinks
= array();
50 $this->mDoNothing
= false;
51 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
52 $this->mParserOptions
= null;
53 $this->mSquidMaxage
= 0;
55 $this->mHeadItems
= array();
57 $this->mRevisionId
= null;
58 $this->mNewSectionLink
= false;
59 $this->mTemplateIds
= array();
62 public function redirect( $url, $responsecode = '302' ) {
63 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
64 $this->mRedirect
= str_replace( "\n", '', $url );
65 $this->mRedirectCode
= $responsecode;
68 public function getRedirect() {
69 return $this->mRedirect
;
73 * Set the HTTP status code to send with the output.
75 * @param int $statusCode
78 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
80 # To add an http-equiv meta tag, precede the name with "http:"
81 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
82 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
83 function addScript( $script ) { $this->mScripts
.= "\t\t".$script; }
84 function addStyle( $style ) {
85 global $wgStylePath, $wgStyleVersion;
88 'rel' => 'stylesheet',
89 'href' => $wgStylePath . '/' . $style . '?' . $wgStyleVersion ) );
93 * Add a self-contained script tag with the given contents
94 * @param string $script JavaScript text, no <script> tags
96 function addInlineScript( $script ) {
98 $this->mScripts
.= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
101 function getScript() {
102 return $this->mScripts
. $this->getHeadItems();
105 function getHeadItems() {
107 foreach ( $this->mHeadItems
as $item ) {
113 function addHeadItem( $name, $value ) {
114 $this->mHeadItems
[$name] = $value;
117 function hasHeadItem( $name ) {
118 return isset( $this->mHeadItems
[$name] );
121 function setETag($tag) { $this->mETag
= $tag; }
122 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
123 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
125 function addLink( $linkarr ) {
126 # $linkarr should be an associative array of attributes. We'll escape on output.
127 array_push( $this->mLinktags
, $linkarr );
130 function addMetadataLink( $linkarr ) {
131 # note: buggy CC software only reads first "meta" link
132 static $haveMeta = false;
133 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
134 $this->addLink( $linkarr );
139 * checkLastModified tells the client to use the client-cached page if
140 * possible. If sucessful, the OutputPage is disabled so that
141 * any future call to OutputPage->output() have no effect.
143 * @return bool True iff cache-ok headers was sent.
145 function checkLastModified ( $timestamp ) {
146 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
147 $fname = 'OutputPage::checkLastModified';
149 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
150 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
153 if( !$wgCachePages ) {
154 wfDebug( "$fname: CACHE DISABLED\n", false );
157 if( $wgUser->getOption( 'nocache' ) ) {
158 wfDebug( "$fname: USER DISABLED CACHE\n", false );
162 $timestamp=wfTimestamp(TS_MW
,$timestamp);
163 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
165 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
166 # IE sends sizes after the date like this:
167 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
168 # this breaks strtotime().
169 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
171 wfSuppressWarnings(); // E_STRICT system time bitching
172 $modsinceTime = strtotime( $modsince );
175 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
176 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
177 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
178 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
179 # Make sure you're in a place you can leave when you call us!
180 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
181 $this->mLastModified
= $lastmod;
182 $this->sendCacheControl();
183 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
186 // Don't output a compressed blob when using ob_gzhandler;
187 // it's technically against HTTP spec and seems to confuse
188 // Firefox when the response gets split over two packets.
189 wfClearOutputBuffers();
193 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
194 $this->mLastModified
= $lastmod;
197 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
198 $this->mLastModified
= $lastmod;
202 function setPageTitleActionText( $text ) {
203 $this->mPageTitleActionText
= $text;
206 function getPageTitleActionText () {
207 if ( isset( $this->mPageTitleActionText
) ) {
208 return $this->mPageTitleActionText
;
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 setFeedAppendQuery( $val ) { $this->mFeedLinksAppendQuery
= $val; }
237 public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery
; }
238 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
239 public function getOnloadHandler() { return $this->mOnloadHandler
; }
240 public function disable() { $this->mDoNothing
= true; }
242 public function setArticleRelated( $v ) {
243 $this->mIsArticleRelated
= $v;
245 $this->mIsarticle
= false;
248 public function setArticleFlag( $v ) {
249 $this->mIsarticle
= $v;
251 $this->mIsArticleRelated
= $v;
255 public function isArticleRelated() { return $this->mIsArticleRelated
; }
257 public function getLanguageLinks() { return $this->mLanguageLinks
; }
258 public function addLanguageLinks($newLinkArray) {
259 $this->mLanguageLinks +
= $newLinkArray;
261 public function setLanguageLinks($newLinkArray) {
262 $this->mLanguageLinks
= $newLinkArray;
265 public function getCategoryLinks() {
266 return $this->mCategoryLinks
;
270 * Add an array of categories, with names in the keys
272 public function addCategoryLinks($categories) {
273 global $wgUser, $wgContLang;
275 if ( !is_array( $categories ) ) {
278 # Add the links to the link cache in a batch
279 $arr = array( NS_CATEGORY
=> $categories );
281 $lb->setArray( $arr );
284 $sk = $wgUser->getSkin();
285 foreach ( $categories as $category => $unused ) {
286 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
287 $text = $wgContLang->convertHtml( $title->getText() );
288 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
292 public function setCategoryLinks($categories) {
293 $this->mCategoryLinks
= array();
294 $this->addCategoryLinks($categories);
297 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
298 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
300 public function disallowUserJs() { $this->mAllowUserJs
= false; }
301 public function isUserJsAllowed() { return $this->mAllowUserJs
; }
303 public function addHTML( $text ) { $this->mBodytext
.= $text; }
304 public function clearHTML() { $this->mBodytext
= ''; }
305 public function getHTML() { return $this->mBodytext
; }
306 public function debug( $text ) { $this->mDebugtext
.= $text; }
309 public function setParserOptions( $options ) {
310 return $this->parserOptions( $options );
313 public function parserOptions( $options = null ) {
314 if ( !$this->mParserOptions
) {
315 $this->mParserOptions
= new ParserOptions
;
317 return wfSetVar( $this->mParserOptions
, $options );
321 * Set the revision ID which will be seen by the wiki text parser
322 * for things such as embedded {{REVISIONID}} variable use.
323 * @param mixed $revid an integer, or NULL
324 * @return mixed previous value
326 public function setRevisionId( $revid ) {
327 $val = is_null( $revid ) ?
null : intval( $revid );
328 return wfSetVar( $this->mRevisionId
, $val );
332 * Convert wikitext to HTML and add it to the buffer
333 * Default assumes that the current page title will
336 * @param string $text
337 * @param bool $linestart
339 public function addWikiText( $text, $linestart = true ) {
341 $this->addWikiTextTitle($text, $wgTitle, $linestart);
344 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
345 $this->addWikiTextTitle($text, $title, $linestart);
348 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
349 $this->addWikiTextTitle( $text, $title, $linestart, true );
352 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
355 $fname = 'OutputPage:addWikiTextTitle';
358 wfIncrStats('pcache_not_possible');
360 $popts = $this->parserOptions();
361 $oldTidy = $popts->setTidy($tidy);
363 $parserOutput = $wgParser->parse( $text, $title, $popts,
364 $linestart, true, $this->mRevisionId
);
366 $popts->setTidy( $oldTidy );
368 $this->addParserOutput( $parserOutput );
370 wfProfileOut($fname);
375 * @param ParserOutput object &$parserOutput
377 public function addParserOutputNoText( &$parserOutput ) {
378 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
379 $this->addCategoryLinks( $parserOutput->getCategories() );
380 $this->mNewSectionLink
= $parserOutput->getNewSection();
381 $this->addKeywords( $parserOutput );
382 if ( $parserOutput->getCacheTime() == -1 ) {
383 $this->enableClientCache( false );
385 $this->mNoGallery
= $parserOutput->getNoGallery();
386 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
388 $this->mTemplateIds +
= (array)$parserOutput->mTemplateIds
;
391 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
392 $this->setPageTitle( $dt );
394 # Hooks registered in the object
395 global $wgParserOutputHooks;
396 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
397 list( $hookName, $data ) = $hookInfo;
398 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
399 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
403 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
408 * @param ParserOutput &$parserOutput
410 function addParserOutput( &$parserOutput ) {
411 $this->addParserOutputNoText( $parserOutput );
412 $text = $parserOutput->getText();
413 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
414 $this->addHTML( $text );
418 * Add wikitext to the buffer, assuming that this is the primary text for a page view
419 * Saves the text into the parser cache if possible.
421 * @param string $text
422 * @param Article $article
424 * @deprecated Use Article::outputWikitext
426 public function addPrimaryWikiText( $text, $article, $cache = true ) {
427 global $wgParser, $wgUser;
429 $popts = $this->parserOptions();
430 $popts->setTidy(true);
431 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
432 $popts, true, true, $this->mRevisionId
);
433 $popts->setTidy(false);
434 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
435 $parserCache =& ParserCache
::singleton();
436 $parserCache->save( $parserOutput, $article, $wgUser );
439 $this->addParserOutput( $parserOutput );
443 * @deprecated use addWikiTextTidy()
445 public function addSecondaryWikiText( $text, $linestart = true ) {
447 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
451 * Add wikitext with tidy enabled
453 public function addWikiTextTidy( $text, $linestart = true ) {
455 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
460 * Add the output of a QuickTemplate to the output buffer
462 * @param QuickTemplate $template
464 public function addTemplate( &$template ) {
466 $template->execute();
467 $this->addHTML( ob_get_contents() );
472 * Parse wikitext and return the HTML.
474 * @param string $text
475 * @param bool $linestart Is this the start of a line?
476 * @param bool $interface ??
478 public function parse( $text, $linestart = true, $interface = false ) {
479 global $wgParser, $wgTitle;
480 $popts = $this->parserOptions();
481 if ( $interface) { $popts->setInterfaceMessage(true); }
482 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
483 $linestart, true, $this->mRevisionId
);
484 if ( $interface) { $popts->setInterfaceMessage(false); }
485 return $parserOutput->getText();
489 * @param Article $article
492 * @return bool True if successful, else false.
494 public function tryParserCache( &$article, $user ) {
495 $parserCache =& ParserCache
::singleton();
496 $parserOutput = $parserCache->get( $article, $user );
497 if ( $parserOutput !== false ) {
498 $this->addParserOutput( $parserOutput );
506 * @param int $maxage Maximum cache time on the Squid, in seconds.
508 public function setSquidMaxage( $maxage ) {
509 $this->mSquidMaxage
= $maxage;
513 * Use enableClientCache(false) to force it to send nocache headers
516 public function enableClientCache( $state ) {
517 return wfSetVar( $this->mEnableClientCache
, $state );
520 function uncacheableBecauseRequestvars() {
522 return $wgRequest->getText('useskin', false) === false
523 && $wgRequest->getText('uselang', false) === false;
526 public function sendCacheControl() {
527 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
528 $fname = 'OutputPage::sendCacheControl';
530 if ($wgUseETag && $this->mETag
)
531 $wgRequest->response()->header("ETag: $this->mETag");
533 # don't serve compressed data to clients who can't handle it
534 # maintain different caches for logged-in users and non-logged in ones
535 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
536 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
537 if( $wgUseSquid && session_id() == '' &&
538 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
541 # We'll purge the proxy cache explicitly, but require end user agents
542 # to revalidate against the proxy on each visit.
543 # Surrogate-Control controls our Squid, Cache-Control downstream caches
544 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
545 # start with a shorter timeout for initial testing
546 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
547 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
548 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
550 # We'll purge the proxy cache for anons explicitly, but require end user agents
551 # to revalidate against the proxy on each visit.
552 # IMPORTANT! The Squid needs to replace the Cache-Control header with
553 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
554 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
555 # start with a shorter timeout for initial testing
556 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
557 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
560 # We do want clients to cache if they can, but they *must* check for updates
561 # on revisiting the page.
562 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
563 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
564 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
566 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
568 wfDebug( "$fname: no caching **\n", false );
570 # In general, the absence of a last modified header should be enough to prevent
571 # the client from using its cache. We send a few other things just to make sure.
572 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
573 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
574 $wgRequest->response()->header( 'Pragma: no-cache' );
579 * Finally, all the text has been munged and accumulated into
580 * the object, let's actually output it:
582 public function output() {
583 global $wgUser, $wgOutputEncoding, $wgRequest;
584 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
585 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
586 global $wgServer, $wgStyleVersion;
588 if( $this->mDoNothing
){
591 $fname = 'OutputPage::output';
592 wfProfileIn( $fname );
593 $sk = $wgUser->getSkin();
596 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
598 wfRunHooks( 'AjaxAddScript', array( &$this ) );
600 if( $wgAjaxSearch ) {
601 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
602 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
605 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
606 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
610 if ( '' != $this->mRedirect
) {
611 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
612 # Standards require redirect URLs to be absolute
614 $this->mRedirect
= $wgServer . $this->mRedirect
;
616 if( $this->mRedirectCode
== '301') {
617 if( !$wgDebugRedirects ) {
618 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
620 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
623 $this->sendCacheControl();
625 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
626 if( $wgDebugRedirects ) {
627 $url = htmlspecialchars( $this->mRedirect
);
628 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
629 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
630 print "</body>\n</html>\n";
632 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
634 wfProfileOut( $fname );
637 elseif ( $this->mStatusCode
)
639 $statusMessage = array(
641 101 => 'Switching Protocols',
646 203 => 'Non-Authoritative Information',
648 205 => 'Reset Content',
649 206 => 'Partial Content',
650 207 => 'Multi-Status',
651 300 => 'Multiple Choices',
652 301 => 'Moved Permanently',
655 304 => 'Not Modified',
657 307 => 'Temporary Redirect',
658 400 => 'Bad Request',
659 401 => 'Unauthorized',
660 402 => 'Payment Required',
663 405 => 'Method Not Allowed',
664 406 => 'Not Acceptable',
665 407 => 'Proxy Authentication Required',
666 408 => 'Request Timeout',
669 411 => 'Length Required',
670 412 => 'Precondition Failed',
671 413 => 'Request Entity Too Large',
672 414 => 'Request-URI Too Large',
673 415 => 'Unsupported Media Type',
674 416 => 'Request Range Not Satisfiable',
675 417 => 'Expectation Failed',
676 422 => 'Unprocessable Entity',
678 424 => 'Failed Dependency',
679 500 => 'Internal Server Error',
680 501 => 'Not Implemented',
681 502 => 'Bad Gateway',
682 503 => 'Service Unavailable',
683 504 => 'Gateway Timeout',
684 505 => 'HTTP Version Not Supported',
685 507 => 'Insufficient Storage'
688 if ( $statusMessage[$this->mStatusCode
] )
689 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
692 # Buffer output; final headers may depend on later processing
695 # Disable temporary placeholders, so that the skin produces HTML
696 $sk->postParseLinkColour( false );
698 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
699 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
701 if ($this->mArticleBodyOnly
) {
702 $this->out($this->mBodytext
);
704 wfProfileIn( 'Output-skin' );
705 $sk->outputPage( $this );
706 wfProfileOut( 'Output-skin' );
709 $this->sendCacheControl();
711 wfProfileOut( $fname );
718 public function out( $ins ) {
719 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
720 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
723 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
724 if ( false === $outs ) { $outs = $ins; }
732 public static function setEncodings() {
733 global $wgInputEncoding, $wgOutputEncoding;
734 global $wgUser, $wgContLang;
736 $wgInputEncoding = strtolower( $wgInputEncoding );
738 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
739 $wgOutputEncoding = strtolower( $wgOutputEncoding );
742 $wgOutputEncoding = $wgInputEncoding;
746 * Deprecated, use wfReportTime() instead.
750 public function reportTime() {
751 $time = wfReportTime();
756 * Produce a "user is blocked" page.
758 * @param bool $return Whether to have a "return to $wgTitle" message or not.
761 function blockedPage( $return = true ) {
762 global $wgUser, $wgContLang, $wgTitle, $wgLang;
764 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
765 $this->setRobotpolicy( 'noindex,nofollow' );
766 $this->setArticleRelated( false );
768 $name = User
::whoIs( $wgUser->blockedBy() );
769 $reason = $wgUser->blockedFor();
770 if( $reason == '' ) {
771 $reason = wfMsg( 'blockednoreason' );
773 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
776 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
778 $blockid = $wgUser->mBlock
->mId
;
780 $blockExpiry = $wgUser->mBlock
->mExpiry
;
781 if ( $blockExpiry == 'infinity' ) {
782 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
783 // Search for localization in 'ipboptions'
784 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
785 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
786 if ( strpos( $option, ":" ) === false )
788 list( $show, $value ) = explode( ":", $option );
789 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
790 $blockExpiry = $show;
795 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
798 if ( $wgUser->mBlock
->mAuto
) {
799 $msg = 'autoblockedtext';
801 $msg = 'blockedtext';
804 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
805 * This could be a username, an ip range, or a single ip. */
806 $intended = $wgUser->mBlock
->mAddress
;
808 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp ) );
810 # Don't auto-return to special pages
812 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
813 $this->returnToMain( false, $return );
818 * Output a standard error page
820 * @param string $title Message key for page title
821 * @param string $msg Message key for page text
822 * @param array $params Message parameters
824 public function showErrorPage( $title, $msg, $params = array() ) {
827 $this->mDebugtext
.= 'Original title: ' .
828 $wgTitle->getPrefixedText() . "\n";
829 $this->setPageTitle( wfMsg( $title ) );
830 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
831 $this->setRobotpolicy( 'noindex,nofollow' );
832 $this->setArticleRelated( false );
833 $this->enableClientCache( false );
834 $this->mRedirect
= '';
835 $this->mBodytext
= '';
837 array_unshift( $params, 'parse' );
838 array_unshift( $params, $msg );
839 $this->addHtml( call_user_func_array( 'wfMsgExt', $params ) );
841 $this->returnToMain( false );
845 * Output a standard permission error page
847 * @param array $errors Error message keys
849 public function showPermissionsErrorPage( $errors )
853 $this->mDebugtext
.= 'Original title: ' .
854 $wgTitle->getPrefixedText() . "\n";
855 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
856 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
857 $this->setRobotpolicy( 'noindex,nofollow' );
858 $this->setArticleRelated( false );
859 $this->enableClientCache( false );
860 $this->mRedirect
= '';
861 $this->mBodytext
= '';
862 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors ) );
866 public function errorpage( $title, $msg ) {
867 throw new ErrorPageError( $title, $msg );
871 * Display an error page indicating that a given version of MediaWiki is
874 * @param mixed $version The version of MediaWiki needed to use the page
876 public function versionRequired( $version ) {
877 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
878 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
879 $this->setRobotpolicy( 'noindex,nofollow' );
880 $this->setArticleRelated( false );
881 $this->mBodytext
= '';
883 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
884 $this->returnToMain();
888 * Display an error page noting that a given permission bit is required.
890 * @param string $permission key required
892 public function permissionRequired( $permission ) {
893 global $wgGroupPermissions, $wgUser;
895 $this->setPageTitle( wfMsg( 'badaccess' ) );
896 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
897 $this->setRobotpolicy( 'noindex,nofollow' );
898 $this->setArticleRelated( false );
899 $this->mBodytext
= '';
902 foreach( $wgGroupPermissions as $key => $value ) {
903 if( isset( $value[$permission] ) && $value[$permission] == true ) {
904 $groupName = User
::getGroupName( $key );
905 $groupPage = User
::getGroupPage( $key );
907 $skin = $wgUser->getSkin();
908 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
910 $groups[] = $groupName;
914 $n = count( $groups );
915 $groups = implode( ', ', $groups );
920 $message = wfMsgHtml( "badaccess-group$n", $groups );
923 $message = wfMsgHtml( 'badaccess-groups', $groups );
925 $this->addHtml( $message );
926 $this->returnToMain( false );
930 * Use permissionRequired.
933 public function sysopRequired() {
934 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
938 * Use permissionRequired.
941 public function developerRequired() {
942 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
946 * Produce the stock "please login to use the wiki" page
948 public function loginToUse() {
949 global $wgUser, $wgTitle, $wgContLang;
951 if( $wgUser->isLoggedIn() ) {
952 $this->permissionRequired( 'read' );
956 $skin = $wgUser->getSkin();
958 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
959 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
960 $this->setRobotPolicy( 'noindex,nofollow' );
961 $this->setArticleFlag( false );
963 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
964 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
965 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
966 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
968 # Don't return to the main page if the user can't read it
969 # otherwise we'll end up in a pointless loop
970 $mainPage = Title
::newMainPage();
971 if( $mainPage->userCanRead() )
972 $this->returnToMain( true, $mainPage );
976 public function databaseError( $fname, $sql, $error, $errno ) {
977 throw new MWException( "OutputPage::databaseError is obsolete\n" );
981 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
982 * @return string The error-messages, formatted into a list.
984 public function formatPermissionsErrorMessage( $errors ) {
987 if (sizeof( $errors ) > 1) {
989 $text .= wfMsgExt( 'permissionserrorstext', array( 'parse' ), count( $errors ) ) . "\n";
990 $text .= '<ul class="permissions-errors">' . "\n";
992 foreach( $errors as $error )
995 $text .= call_user_func_array( 'wfMsg', $error );
1000 $text .= call_user_func_array( 'wfMsg', $errors[0]);
1007 * Display a page stating that the Wiki is in read-only mode,
1008 * and optionally show the source of the page that the user
1009 * was trying to edit. Should only be called (for this
1010 * purpose) after wfReadOnly() has returned true.
1012 * For historical reasons, this function is _also_ used to
1013 * show the error message when a user tries to edit a page
1014 * they are not allowed to edit. (Unless it's because they're
1015 * blocked, then we show blockedPage() instead.) In this
1016 * case, the second parameter should be set to true and a list
1017 * of reasons supplied as the third parameter.
1019 * @todo Needs to be split into multiple functions.
1021 * @param string $source Source code to show (or null).
1022 * @param bool $protected Is this a permissions error?
1023 * @param array $reasons List of reasons for this error, as returned by Title::getUserPermissionsErrors().
1025 public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
1026 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
1028 $this->setRobotpolicy( 'noindex,nofollow' );
1029 $this->setArticleRelated( false );
1031 // If no reason is given, just supply a default "I can't let you do
1032 // that, Dave" message. Should only occur if called by legacy code.
1033 if ( $protected && empty($reasons) ) {
1034 $reasons[] = array( 'badaccess-group0' );
1037 if ( !empty($reasons) ) {
1038 // Permissions error
1039 $this->setPageTitle( wfMsg( 'viewsource' ) );
1040 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1041 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) );
1043 // Wiki is read only
1044 $this->setPageTitle( wfMsg( 'readonly' ) );
1045 if ( $wgReadOnly ) {
1046 $reason = $wgReadOnly;
1048 // Should not happen, user should have called wfReadOnly() first
1049 $reason = file_get_contents( $wgReadOnlyFile );
1051 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
1054 // Show source, if supplied
1055 if( is_string( $source ) ) {
1056 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
1057 $text = wfOpenElement( 'textarea',
1058 array( 'id' => 'wpTextbox1',
1059 'name' => 'wpTextbox1',
1060 'cols' => $wgUser->getOption( 'cols' ),
1061 'rows' => $wgUser->getOption( 'rows' ),
1062 'readonly' => 'readonly' ) );
1063 $text .= htmlspecialchars( $source );
1064 $text .= wfCloseElement( 'textarea' );
1065 $this->addHTML( $text );
1067 // Show templates used by this article
1068 $skin = $wgUser->getSkin();
1069 $article = new Article( $wgTitle );
1070 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1073 $this->returnToMain( false, $wgTitle );
1077 public function fatalError( $message ) {
1078 throw new FatalError( $message );
1082 public function unexpectedValueError( $name, $val ) {
1083 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1087 public function fileCopyError( $old, $new ) {
1088 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1092 public function fileRenameError( $old, $new ) {
1093 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1097 public function fileDeleteError( $name ) {
1098 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1102 public function fileNotFoundError( $name ) {
1103 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1106 public function showFatalError( $message ) {
1107 $this->setPageTitle( wfMsg( "internalerror" ) );
1108 $this->setRobotpolicy( "noindex,nofollow" );
1109 $this->setArticleRelated( false );
1110 $this->enableClientCache( false );
1111 $this->mRedirect
= '';
1112 $this->mBodytext
= $message;
1115 public function showUnexpectedValueError( $name, $val ) {
1116 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1119 public function showFileCopyError( $old, $new ) {
1120 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1123 public function showFileRenameError( $old, $new ) {
1124 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1127 public function showFileDeleteError( $name ) {
1128 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1131 public function showFileNotFoundError( $name ) {
1132 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1136 * Add a "return to" link pointing to a specified title
1138 * @param Title $title Title to link
1140 public function addReturnTo( $title ) {
1142 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1143 $this->addHtml( "<p>{$link}</p>\n" );
1147 * Add a "return to" link pointing to a specified title,
1148 * or the title indicated in the request, or else the main page
1150 * @param null $unused No longer used
1151 * @param Title $returnto Title to return to
1153 public function returnToMain( $unused = null, $returnto = NULL ) {
1156 if ( $returnto == NULL ) {
1157 $returnto = $wgRequest->getText( 'returnto' );
1160 if ( '' === $returnto ) {
1161 $returnto = Title
::newMainPage();
1164 if ( is_object( $returnto ) ) {
1165 $titleObj = $returnto;
1167 $titleObj = Title
::newFromText( $returnto );
1169 if ( !is_object( $titleObj ) ) {
1170 $titleObj = Title
::newMainPage();
1173 $this->addReturnTo( $titleObj );
1177 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1178 * and uses the first 10 of them for META keywords
1180 * @param ParserOutput &$parserOutput
1182 private function addKeywords( &$parserOutput ) {
1184 $this->addKeyword( $wgTitle->getPrefixedText() );
1186 $links2d =& $parserOutput->getLinks();
1187 if ( !is_array( $links2d ) ) {
1190 foreach ( $links2d as $dbkeys ) {
1191 foreach( $dbkeys as $dbkey => $unused ) {
1192 $this->addKeyword( $dbkey );
1193 if ( ++
$count > 10 ) {
1201 * @return string The doctype, opening <html>, and head element.
1203 public function headElement() {
1204 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1205 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1206 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1208 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1209 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1214 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1216 if ( '' == $this->getHTMLTitle() ) {
1217 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1220 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1221 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1222 foreach($wgXhtmlNamespaces as $tag => $ns) {
1223 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1225 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1226 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1227 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1229 $ret .= $this->getHeadLinks();
1230 global $wgStylePath;
1231 if( $this->isPrintable() ) {
1234 $media = "media='print'";
1236 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1237 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1239 $sk = $wgUser->getSkin();
1240 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1241 $ret .= $this->mScripts
;
1242 $ret .= $sk->getUserStyles();
1243 $ret .= $this->getHeadItems();
1245 if ($wgUseTrackbacks && $this->isArticleRelated())
1246 $ret .= $wgTitle->trackbackRDF();
1248 $ret .= "</head>\n";
1253 * @return string HTML tag links to be put in the header.
1255 public function getHeadLinks() {
1258 foreach ( $this->mMetatags
as $tag ) {
1259 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1261 $tag[0] = substr( $tag[0], 5 );
1265 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1268 $p = $this->mRobotpolicy
;
1269 if( $p !== '' && $p != 'index,follow' ) {
1270 // http://www.robotstxt.org/wc/meta-user.html
1271 // Only show if it's different from the default robots policy
1272 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1275 if ( count( $this->mKeywords
) > 0 ) {
1280 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1281 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1283 foreach ( $this->mLinktags
as $tag ) {
1284 $ret .= "\t\t<link";
1285 foreach( $tag as $attr => $val ) {
1286 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1291 if( $this->isSyndicated() ) {
1292 # Use the page name for the title (accessed through $wgTitle since
1293 # there's no other way). In principle, this could lead to issues
1294 # with having the same name for different feeds corresponding to
1295 # the same page, but we can't avoid that at this low a level.
1296 global $wgTitle, $wgFeedClasses;
1298 if( is_string( $this->getFeedAppendQuery() ) ) {
1299 $appendQuery = "&" . $this->getFeedAppendQuery();
1304 foreach( $wgFeedClasses as $format => $class ) {
1305 $ret .= $this->feedLink(
1307 $wgRequest->appendQuery( "feed=rss{$appendQuery}" ),
1308 wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) );
1312 # Recent changes feed should appear on every page
1313 # Put it after the per-page feed to avoid changing existing behavior.
1314 # It's still available, probably via a menu in your browser.
1316 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
1317 $ret .= $this->feedLink(
1319 $rctitle->getFullURL( 'feed=rss' ),
1320 wfMsg( 'site-rss-feed', $wgSitename ) );
1321 $ret .= $this->feedLink(
1323 $rctitle->getFullURL( 'feed=atom' ),
1324 wfMsg( 'site-atom-feed', $wgSitename ) );
1330 * Generate a <link rel/> for an RSS feed.
1332 private function feedLink( $type, $url, $text ) {
1333 return Xml
::element( 'link', array(
1334 'rel' => 'alternate',
1335 'type' => "application/$type+xml",
1337 'href' => $url ) ) . "\n";
1341 * Turn off regular page output and return an error reponse
1342 * for when rate limiting has triggered.
1344 public function rateLimited() {
1347 $this->setPageTitle(wfMsg('actionthrottled'));
1348 $this->setRobotPolicy( 'noindex,follow' );
1349 $this->setArticleRelated( false );
1350 $this->enableClientCache( false );
1351 $this->mRedirect
= '';
1353 $this->setStatusCode(503);
1354 $this->addWikiText( wfMsg('actionthrottledtext') );
1356 $this->returnToMain( false, $wgTitle );
1360 * Show an "add new section" link?
1364 public function showNewSectionLink() {
1365 return $this->mNewSectionLink
;
1369 * Show a warning about slave lag
1371 * If the lag is higher than $wgSlaveLagCritical seconds,
1372 * then the warning is a bit more obvious. If the lag is
1373 * lower than $wgSlaveLagWarning, then no warning is shown.
1375 * @param int $lag Slave lag
1377 public function showLagWarning( $lag ) {
1378 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1379 if( $lag >= $wgSlaveLagWarning ) {
1380 $message = $lag < $wgSlaveLagCritical
1383 $warning = wfMsgExt( $message, 'parse', $lag );
1384 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );