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;
66 public function getRedirect() {
67 return $this->mRedirect
;
71 * Set the HTTP status code to send with the output.
73 * @param int $statusCode
76 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
78 # To add an http-equiv meta tag, precede the name with "http:"
79 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
80 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
81 function addScript( $script ) { $this->mScripts
.= "\t\t".$script; }
82 function addStyle( $style ) {
83 global $wgStylePath, $wgStyleVersion;
86 'rel' => 'stylesheet',
87 'href' => $wgStylePath . '/' . $style . '?' . $wgStyleVersion ) );
91 * Add a self-contained script tag with the given contents
92 * @param string $script JavaScript text, no <script> tags
94 function addInlineScript( $script ) {
96 $this->mScripts
.= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
99 function getScript() {
100 return $this->mScripts
. $this->getHeadItems();
103 function getHeadItems() {
105 foreach ( $this->mHeadItems
as $item ) {
111 function addHeadItem( $name, $value ) {
112 $this->mHeadItems
[$name] = $value;
115 function hasHeadItem( $name ) {
116 return isset( $this->mHeadItems
[$name] );
119 function setETag($tag) { $this->mETag
= $tag; }
120 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
121 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
123 function addLink( $linkarr ) {
124 # $linkarr should be an associative array of attributes. We'll escape on output.
125 array_push( $this->mLinktags
, $linkarr );
128 function addMetadataLink( $linkarr ) {
129 # note: buggy CC software only reads first "meta" link
130 static $haveMeta = false;
131 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
132 $this->addLink( $linkarr );
137 * checkLastModified tells the client to use the client-cached page if
138 * possible. If sucessful, the OutputPage is disabled so that
139 * any future call to OutputPage->output() have no effect.
141 * @return bool True iff cache-ok headers was sent.
143 function checkLastModified ( $timestamp ) {
144 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
145 $fname = 'OutputPage::checkLastModified';
147 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
148 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
151 if( !$wgCachePages ) {
152 wfDebug( "$fname: CACHE DISABLED\n", false );
155 if( $wgUser->getOption( 'nocache' ) ) {
156 wfDebug( "$fname: USER DISABLED CACHE\n", false );
160 $timestamp=wfTimestamp(TS_MW
,$timestamp);
161 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
163 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
164 # IE sends sizes after the date like this:
165 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
166 # this breaks strtotime().
167 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
169 wfSuppressWarnings(); // E_STRICT system time bitching
170 $modsinceTime = strtotime( $modsince );
173 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
174 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
175 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
176 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
177 # Make sure you're in a place you can leave when you call us!
178 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
179 $this->mLastModified
= $lastmod;
180 $this->sendCacheControl();
181 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
184 // Don't output a compressed blob when using ob_gzhandler;
185 // it's technically against HTTP spec and seems to confuse
186 // Firefox when the response gets split over two packets.
187 wfClearOutputBuffers();
191 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
192 $this->mLastModified
= $lastmod;
195 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
196 $this->mLastModified
= $lastmod;
200 function setPageTitleActionText( $text ) {
201 $this->mPageTitleActionText
= $text;
204 function getPageTitleActionText () {
205 if ( isset( $this->mPageTitleActionText
) ) {
206 return $this->mPageTitleActionText
;
210 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
211 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
212 public function setPageTitle( $name ) {
213 global $action, $wgContLang;
214 $name = $wgContLang->convert($name, true);
215 $this->mPagetitle
= $name;
216 if(!empty($action)) {
217 $taction = $this->getPageTitleActionText();
218 if( !empty( $taction ) ) {
219 $name .= ' - '.$taction;
223 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
225 public function getHTMLTitle() { return $this->mHTMLtitle
; }
226 public function getPageTitle() { return $this->mPagetitle
; }
227 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
228 public function getSubtitle() { return $this->mSubtitle
; }
229 public function isArticle() { return $this->mIsarticle
; }
230 public function setPrintable() { $this->mPrintable
= true; }
231 public function isPrintable() { return $this->mPrintable
; }
232 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
233 public function isSyndicated() { return $this->mShowFeedLinks
; }
234 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
235 public function getOnloadHandler() { return $this->mOnloadHandler
; }
236 public function disable() { $this->mDoNothing
= true; }
238 public function setArticleRelated( $v ) {
239 $this->mIsArticleRelated
= $v;
241 $this->mIsarticle
= false;
244 public function setArticleFlag( $v ) {
245 $this->mIsarticle
= $v;
247 $this->mIsArticleRelated
= $v;
251 public function isArticleRelated() { return $this->mIsArticleRelated
; }
253 public function getLanguageLinks() { return $this->mLanguageLinks
; }
254 public function addLanguageLinks($newLinkArray) {
255 $this->mLanguageLinks +
= $newLinkArray;
257 public function setLanguageLinks($newLinkArray) {
258 $this->mLanguageLinks
= $newLinkArray;
261 public function getCategoryLinks() {
262 return $this->mCategoryLinks
;
266 * Add an array of categories, with names in the keys
268 public function addCategoryLinks($categories) {
269 global $wgUser, $wgContLang;
271 if ( !is_array( $categories ) ) {
274 # Add the links to the link cache in a batch
275 $arr = array( NS_CATEGORY
=> $categories );
277 $lb->setArray( $arr );
280 $sk = $wgUser->getSkin();
281 foreach ( $categories as $category => $unused ) {
282 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
283 $text = $wgContLang->convertHtml( $title->getText() );
284 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
288 public function setCategoryLinks($categories) {
289 $this->mCategoryLinks
= array();
290 $this->addCategoryLinks($categories);
293 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
294 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
296 public function disallowUserJs() { $this->mAllowUserJs
= false; }
297 public function isUserJsAllowed() { return $this->mAllowUserJs
; }
299 public function addHTML( $text ) { $this->mBodytext
.= $text; }
300 public function clearHTML() { $this->mBodytext
= ''; }
301 public function getHTML() { return $this->mBodytext
; }
302 public function debug( $text ) { $this->mDebugtext
.= $text; }
305 public function setParserOptions( $options ) {
306 return $this->parserOptions( $options );
309 public function parserOptions( $options = null ) {
310 if ( !$this->mParserOptions
) {
311 $this->mParserOptions
= new ParserOptions
;
313 return wfSetVar( $this->mParserOptions
, $options );
317 * Set the revision ID which will be seen by the wiki text parser
318 * for things such as embedded {{REVISIONID}} variable use.
319 * @param mixed $revid an integer, or NULL
320 * @return mixed previous value
322 public function setRevisionId( $revid ) {
323 $val = is_null( $revid ) ?
null : intval( $revid );
324 return wfSetVar( $this->mRevisionId
, $val );
328 * Convert wikitext to HTML and add it to the buffer
329 * Default assumes that the current page title will
332 * @param string $text
333 * @param bool $linestart
335 public function addWikiText( $text, $linestart = true ) {
337 $this->addWikiTextTitle($text, $wgTitle, $linestart);
340 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
341 $this->addWikiTextTitle($text, $title, $linestart);
344 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
345 $this->addWikiTextTitle( $text, $title, $linestart, true );
348 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
351 $fname = 'OutputPage:addWikiTextTitle';
354 wfIncrStats('pcache_not_possible');
356 $popts = $this->parserOptions();
357 $oldTidy = $popts->setTidy($tidy);
359 $parserOutput = $wgParser->parse( $text, $title, $popts,
360 $linestart, true, $this->mRevisionId
);
362 $popts->setTidy( $oldTidy );
364 $this->addParserOutput( $parserOutput );
366 wfProfileOut($fname);
371 * @param ParserOutput object &$parserOutput
373 public function addParserOutputNoText( &$parserOutput ) {
374 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
375 $this->addCategoryLinks( $parserOutput->getCategories() );
376 $this->mNewSectionLink
= $parserOutput->getNewSection();
377 $this->addKeywords( $parserOutput );
378 if ( $parserOutput->getCacheTime() == -1 ) {
379 $this->enableClientCache( false );
381 $this->mNoGallery
= $parserOutput->getNoGallery();
382 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
384 $this->mTemplateIds +
= (array)$parserOutput->mTemplateIds
;
387 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
388 $this->setPageTitle( $dt );
390 # Hooks registered in the object
391 global $wgParserOutputHooks;
392 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
393 list( $hookName, $data ) = $hookInfo;
394 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
395 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
399 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
404 * @param ParserOutput &$parserOutput
406 function addParserOutput( &$parserOutput ) {
407 $this->addParserOutputNoText( $parserOutput );
408 $text = $parserOutput->getText();
409 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
410 $this->addHTML( $text );
414 * Add wikitext to the buffer, assuming that this is the primary text for a page view
415 * Saves the text into the parser cache if possible.
417 * @param string $text
418 * @param Article $article
420 * @deprecated Use Article::outputWikitext
422 public function addPrimaryWikiText( $text, $article, $cache = true ) {
423 global $wgParser, $wgUser;
425 $popts = $this->parserOptions();
426 $popts->setTidy(true);
427 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
428 $popts, true, true, $this->mRevisionId
);
429 $popts->setTidy(false);
430 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
431 $parserCache =& ParserCache
::singleton();
432 $parserCache->save( $parserOutput, $article, $wgUser );
435 $this->addParserOutput( $parserOutput );
439 * @deprecated use addWikiTextTidy()
441 public function addSecondaryWikiText( $text, $linestart = true ) {
443 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
447 * Add wikitext with tidy enabled
449 public function addWikiTextTidy( $text, $linestart = true ) {
451 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
456 * Add the output of a QuickTemplate to the output buffer
458 * @param QuickTemplate $template
460 public function addTemplate( &$template ) {
462 $template->execute();
463 $this->addHTML( ob_get_contents() );
468 * Parse wikitext and return the HTML.
470 * @param string $text
471 * @param bool $linestart Is this the start of a line?
472 * @param bool $interface ??
474 public function parse( $text, $linestart = true, $interface = false ) {
475 global $wgParser, $wgTitle;
476 $popts = $this->parserOptions();
477 if ( $interface) { $popts->setInterfaceMessage(true); }
478 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
479 $linestart, true, $this->mRevisionId
);
480 if ( $interface) { $popts->setInterfaceMessage(false); }
481 return $parserOutput->getText();
485 * @param Article $article
488 * @return bool True if successful, else false.
490 public function tryParserCache( &$article, $user ) {
491 $parserCache =& ParserCache
::singleton();
492 $parserOutput = $parserCache->get( $article, $user );
493 if ( $parserOutput !== false ) {
494 $this->addParserOutput( $parserOutput );
502 * @param int $maxage Maximum cache time on the Squid, in seconds.
504 public function setSquidMaxage( $maxage ) {
505 $this->mSquidMaxage
= $maxage;
509 * Use enableClientCache(false) to force it to send nocache headers
512 public function enableClientCache( $state ) {
513 return wfSetVar( $this->mEnableClientCache
, $state );
516 function uncacheableBecauseRequestvars() {
518 return $wgRequest->getText('useskin', false) === false
519 && $wgRequest->getText('uselang', false) === false;
522 public function sendCacheControl() {
523 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
524 $fname = 'OutputPage::sendCacheControl';
526 if ($wgUseETag && $this->mETag
)
527 $wgRequest->response()->header("ETag: $this->mETag");
529 # don't serve compressed data to clients who can't handle it
530 # maintain different caches for logged-in users and non-logged in ones
531 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
532 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
533 if( $wgUseSquid && session_id() == '' &&
534 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
537 # We'll purge the proxy cache explicitly, but require end user agents
538 # to revalidate against the proxy on each visit.
539 # Surrogate-Control controls our Squid, Cache-Control downstream caches
540 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
541 # start with a shorter timeout for initial testing
542 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
543 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
544 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
546 # We'll purge the proxy cache for anons explicitly, but require end user agents
547 # to revalidate against the proxy on each visit.
548 # IMPORTANT! The Squid needs to replace the Cache-Control header with
549 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
550 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
551 # start with a shorter timeout for initial testing
552 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
553 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
556 # We do want clients to cache if they can, but they *must* check for updates
557 # on revisiting the page.
558 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
559 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
560 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
562 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
564 wfDebug( "$fname: no caching **\n", false );
566 # In general, the absence of a last modified header should be enough to prevent
567 # the client from using its cache. We send a few other things just to make sure.
568 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
569 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
570 $wgRequest->response()->header( 'Pragma: no-cache' );
575 * Finally, all the text has been munged and accumulated into
576 * the object, let's actually output it:
578 public function output() {
579 global $wgUser, $wgOutputEncoding, $wgRequest;
580 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
581 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
582 global $wgServer, $wgStyleVersion;
584 if( $this->mDoNothing
){
587 $fname = 'OutputPage::output';
588 wfProfileIn( $fname );
589 $sk = $wgUser->getSkin();
592 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
594 wfRunHooks( 'AjaxAddScript', array( &$this ) );
596 if( $wgAjaxSearch ) {
597 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
598 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
601 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
602 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
606 if ( '' != $this->mRedirect
) {
607 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
608 # Standards require redirect URLs to be absolute
610 $this->mRedirect
= $wgServer . $this->mRedirect
;
612 if( $this->mRedirectCode
== '301') {
613 if( !$wgDebugRedirects ) {
614 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
616 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
619 $this->sendCacheControl();
621 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
622 if( $wgDebugRedirects ) {
623 $url = htmlspecialchars( $this->mRedirect
);
624 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
625 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
626 print "</body>\n</html>\n";
628 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
630 wfProfileOut( $fname );
633 elseif ( $this->mStatusCode
)
635 $statusMessage = array(
637 101 => 'Switching Protocols',
642 203 => 'Non-Authoritative Information',
644 205 => 'Reset Content',
645 206 => 'Partial Content',
646 207 => 'Multi-Status',
647 300 => 'Multiple Choices',
648 301 => 'Moved Permanently',
651 304 => 'Not Modified',
653 307 => 'Temporary Redirect',
654 400 => 'Bad Request',
655 401 => 'Unauthorized',
656 402 => 'Payment Required',
659 405 => 'Method Not Allowed',
660 406 => 'Not Acceptable',
661 407 => 'Proxy Authentication Required',
662 408 => 'Request Timeout',
665 411 => 'Length Required',
666 412 => 'Precondition Failed',
667 413 => 'Request Entity Too Large',
668 414 => 'Request-URI Too Large',
669 415 => 'Unsupported Media Type',
670 416 => 'Request Range Not Satisfiable',
671 417 => 'Expectation Failed',
672 422 => 'Unprocessable Entity',
674 424 => 'Failed Dependency',
675 500 => 'Internal Server Error',
676 501 => 'Not Implemented',
677 502 => 'Bad Gateway',
678 503 => 'Service Unavailable',
679 504 => 'Gateway Timeout',
680 505 => 'HTTP Version Not Supported',
681 507 => 'Insufficient Storage'
684 if ( $statusMessage[$this->mStatusCode
] )
685 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
688 # Buffer output; final headers may depend on later processing
691 # Disable temporary placeholders, so that the skin produces HTML
692 $sk->postParseLinkColour( false );
694 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
695 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
697 if ($this->mArticleBodyOnly
) {
698 $this->out($this->mBodytext
);
700 wfProfileIn( 'Output-skin' );
701 $sk->outputPage( $this );
702 wfProfileOut( 'Output-skin' );
705 $this->sendCacheControl();
707 wfProfileOut( $fname );
714 public function out( $ins ) {
715 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
716 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
719 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
720 if ( false === $outs ) { $outs = $ins; }
728 public static function setEncodings() {
729 global $wgInputEncoding, $wgOutputEncoding;
730 global $wgUser, $wgContLang;
732 $wgInputEncoding = strtolower( $wgInputEncoding );
734 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
735 $wgOutputEncoding = strtolower( $wgOutputEncoding );
738 $wgOutputEncoding = $wgInputEncoding;
742 * Deprecated, use wfReportTime() instead.
746 public function reportTime() {
747 $time = wfReportTime();
752 * Produce a "user is blocked" page.
754 * @param bool $return Whether to have a "return to $wgTitle" message or not.
757 function blockedPage( $return = true ) {
758 global $wgUser, $wgContLang, $wgTitle, $wgLang;
760 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
761 $this->setRobotpolicy( 'noindex,nofollow' );
762 $this->setArticleRelated( false );
764 $name = User
::whoIs( $wgUser->blockedBy() );
765 $reason = $wgUser->blockedFor();
766 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
769 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
771 $blockid = $wgUser->mBlock
->mId
;
773 $blockExpiry = $wgUser->mBlock
->mExpiry
;
774 if ( $blockExpiry == 'infinity' ) {
775 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
776 // Search for localization in 'ipboptions'
777 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
778 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
779 if ( strpos( $option, ":" ) === false )
781 list( $show, $value ) = explode( ":", $option );
782 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
783 $blockExpiry = $show;
788 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
791 if ( $wgUser->mBlock
->mAuto
) {
792 $msg = 'autoblockedtext';
794 $msg = 'blockedtext';
797 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
798 * This could be a username, an ip range, or a single ip. */
799 $intended = $wgUser->mBlock
->mAddress
;
801 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp ) );
803 # Don't auto-return to special pages
805 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
806 $this->returnToMain( false, $return );
811 * Output a standard error page
813 * @param string $title Message key for page title
814 * @param string $msg Message key for page text
815 * @param array $params Message parameters
817 public function showErrorPage( $title, $msg, $params = array() ) {
820 $this->mDebugtext
.= 'Original title: ' .
821 $wgTitle->getPrefixedText() . "\n";
822 $this->setPageTitle( wfMsg( $title ) );
823 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
824 $this->setRobotpolicy( 'noindex,nofollow' );
825 $this->setArticleRelated( false );
826 $this->enableClientCache( false );
827 $this->mRedirect
= '';
828 $this->mBodytext
= '';
830 array_unshift( $params, 'parse' );
831 array_unshift( $params, $msg );
832 $this->addHtml( call_user_func_array( 'wfMsgExt', $params ) );
834 $this->returnToMain( false );
838 * Output a standard permission error page
840 * @param array $errors Error message keys
842 public function showPermissionsErrorPage( $errors )
846 $this->mDebugtext
.= 'Original title: ' .
847 $wgTitle->getPrefixedText() . "\n";
848 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
849 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
850 $this->setRobotpolicy( 'noindex,nofollow' );
851 $this->setArticleRelated( false );
852 $this->enableClientCache( false );
853 $this->mRedirect
= '';
854 $this->mBodytext
= '';
855 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors ) );
859 public function errorpage( $title, $msg ) {
860 throw new ErrorPageError( $title, $msg );
864 * Display an error page indicating that a given version of MediaWiki is
867 * @param mixed $version The version of MediaWiki needed to use the page
869 public function versionRequired( $version ) {
870 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
871 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
872 $this->setRobotpolicy( 'noindex,nofollow' );
873 $this->setArticleRelated( false );
874 $this->mBodytext
= '';
876 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
877 $this->returnToMain();
881 * Display an error page noting that a given permission bit is required.
883 * @param string $permission key required
885 public function permissionRequired( $permission ) {
886 global $wgGroupPermissions, $wgUser;
888 $this->setPageTitle( wfMsg( 'badaccess' ) );
889 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
890 $this->setRobotpolicy( 'noindex,nofollow' );
891 $this->setArticleRelated( false );
892 $this->mBodytext
= '';
895 foreach( $wgGroupPermissions as $key => $value ) {
896 if( isset( $value[$permission] ) && $value[$permission] == true ) {
897 $groupName = User
::getGroupName( $key );
898 $groupPage = User
::getGroupPage( $key );
900 $skin = $wgUser->getSkin();
901 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
903 $groups[] = $groupName;
907 $n = count( $groups );
908 $groups = implode( ', ', $groups );
913 $message = wfMsgHtml( "badaccess-group$n", $groups );
916 $message = wfMsgHtml( 'badaccess-groups', $groups );
918 $this->addHtml( $message );
919 $this->returnToMain( false );
923 * Use permissionRequired.
926 public function sysopRequired() {
927 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
931 * Use permissionRequired.
934 public function developerRequired() {
935 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
939 * Produce the stock "please login to use the wiki" page
941 public function loginToUse() {
942 global $wgUser, $wgTitle, $wgContLang;
944 if( $wgUser->isLoggedIn() ) {
945 $this->permissionRequired( 'read' );
949 $skin = $wgUser->getSkin();
951 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
952 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
953 $this->setRobotPolicy( 'noindex,nofollow' );
954 $this->setArticleFlag( false );
956 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
957 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
958 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
959 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
961 # Don't return to the main page if the user can't read it
962 # otherwise we'll end up in a pointless loop
963 $mainPage = Title
::newMainPage();
964 if( $mainPage->userCanRead() )
965 $this->returnToMain( true, $mainPage );
969 public function databaseError( $fname, $sql, $error, $errno ) {
970 throw new MWException( "OutputPage::databaseError is obsolete\n" );
974 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
975 * @return string The error-messages, formatted into a list.
977 public function formatPermissionsErrorMessage( $errors ) {
980 if (sizeof( $errors ) > 1) {
982 $text .= wfMsgExt( 'permissionserrorstext', array( 'parse' ), count( $errors ) ) . "\n";
983 $text .= '<ul class="permissions-errors">' . "\n";
985 foreach( $errors as $error )
988 $text .= call_user_func_array( 'wfMsg', $error );
993 $text .= call_user_func_array( 'wfMsg', $errors[0]);
1001 * @param bool $protected Is the reason the page can't be reached because it's protected?
1002 * @param mixed $source
1003 * @param bool $protected, page is protected?
1004 * @param array $reason, array of arrays( msg, args )
1006 public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
1007 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
1008 $skin = $wgUser->getSkin();
1010 $this->setRobotpolicy( 'noindex,nofollow' );
1011 $this->setArticleRelated( false );
1013 if ( !empty($reasons) ) {
1014 $this->setPageTitle( wfMsg( 'viewsource' ) );
1015 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1017 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) );
1018 } else if( $protected ) {
1019 $this->setPageTitle( wfMsg( 'viewsource' ) );
1020 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1021 list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources();
1023 // Show an appropriate explanation depending upon the reason
1024 // for the protection...all of these should be moved to the
1026 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
1027 // User isn't allowed to edit the interface
1028 $this->addWikiText( wfMsg( 'protectedinterface' ) );
1029 } elseif( $cascadeSources && ( $count = count( $cascadeSources ) ) > 0 ) {
1030 // Cascading protection
1032 foreach( $cascadeSources as $title )
1033 $titles .= "* [[:" . $title->getPrefixedText() . "]]\n";
1034 $this->addWikiText( wfMsgExt( 'cascadeprotected', 'parsemag', $count, "\n{$titles}" ) );
1035 } elseif( !$wgTitle->isProtected( 'edit' ) && $wgTitle->isNamespaceProtected() ) {
1036 // Namespace protection
1037 $ns = $wgTitle->getNamespace() == NS_MAIN
1038 ?
wfMsg( 'nstab-main' )
1039 : $wgTitle->getNsText();
1040 $this->addWikiText( wfMsg( 'namespaceprotected', $ns ) );
1042 // Standard protection
1043 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
1046 $this->setPageTitle( wfMsg( 'readonly' ) );
1047 if ( $wgReadOnly ) {
1048 $reason = $wgReadOnly;
1050 $reason = file_get_contents( $wgReadOnlyFile );
1052 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
1055 if( is_string( $source ) ) {
1056 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
1057 $rows = $wgUser->getIntOption( 'rows' );
1058 $cols = $wgUser->getIntOption( 'cols' );
1059 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
1060 htmlspecialchars( $source ) . "\n</textarea>";
1061 $this->addHTML( $text );
1063 $article = new Article( $wgTitle );
1064 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1066 $this->returnToMain( false, $wgTitle );
1070 public function fatalError( $message ) {
1071 throw new FatalError( $message );
1075 public function unexpectedValueError( $name, $val ) {
1076 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1080 public function fileCopyError( $old, $new ) {
1081 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1085 public function fileRenameError( $old, $new ) {
1086 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1090 public function fileDeleteError( $name ) {
1091 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1095 public function fileNotFoundError( $name ) {
1096 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1099 public function showFatalError( $message ) {
1100 $this->setPageTitle( wfMsg( "internalerror" ) );
1101 $this->setRobotpolicy( "noindex,nofollow" );
1102 $this->setArticleRelated( false );
1103 $this->enableClientCache( false );
1104 $this->mRedirect
= '';
1105 $this->mBodytext
= $message;
1108 public function showUnexpectedValueError( $name, $val ) {
1109 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1112 public function showFileCopyError( $old, $new ) {
1113 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1116 public function showFileRenameError( $old, $new ) {
1117 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1120 public function showFileDeleteError( $name ) {
1121 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1124 public function showFileNotFoundError( $name ) {
1125 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1129 * Add a "return to" link pointing to a specified title
1131 * @param Title $title Title to link
1133 public function addReturnTo( $title ) {
1135 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1136 $this->addHtml( "<p>{$link}</p>\n" );
1140 * Add a "return to" link pointing to a specified title,
1141 * or the title indicated in the request, or else the main page
1143 * @param null $unused No longer used
1144 * @param Title $returnto Title to return to
1146 public function returnToMain( $unused = null, $returnto = NULL ) {
1149 if ( $returnto == NULL ) {
1150 $returnto = $wgRequest->getText( 'returnto' );
1153 if ( '' === $returnto ) {
1154 $returnto = Title
::newMainPage();
1157 if ( is_object( $returnto ) ) {
1158 $titleObj = $returnto;
1160 $titleObj = Title
::newFromText( $returnto );
1162 if ( !is_object( $titleObj ) ) {
1163 $titleObj = Title
::newMainPage();
1166 $this->addReturnTo( $titleObj );
1170 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1171 * and uses the first 10 of them for META keywords
1173 * @param ParserOutput &$parserOutput
1175 private function addKeywords( &$parserOutput ) {
1177 $this->addKeyword( $wgTitle->getPrefixedText() );
1179 $links2d =& $parserOutput->getLinks();
1180 if ( !is_array( $links2d ) ) {
1183 foreach ( $links2d as $dbkeys ) {
1184 foreach( $dbkeys as $dbkey => $unused ) {
1185 $this->addKeyword( $dbkey );
1186 if ( ++
$count > 10 ) {
1194 * @return string The doctype, opening <html>, and head element.
1196 public function headElement() {
1197 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1198 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1199 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1201 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1202 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1207 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1209 if ( '' == $this->getHTMLTitle() ) {
1210 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1213 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1214 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1215 foreach($wgXhtmlNamespaces as $tag => $ns) {
1216 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1218 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1219 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1220 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1222 $ret .= $this->getHeadLinks();
1223 global $wgStylePath;
1224 if( $this->isPrintable() ) {
1227 $media = "media='print'";
1229 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1230 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1232 $sk = $wgUser->getSkin();
1233 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1234 $ret .= $this->mScripts
;
1235 $ret .= $sk->getUserStyles();
1236 $ret .= $this->getHeadItems();
1238 if ($wgUseTrackbacks && $this->isArticleRelated())
1239 $ret .= $wgTitle->trackbackRDF();
1241 $ret .= "</head>\n";
1246 * @return string HTML tag links to be put in the header.
1248 public function getHeadLinks() {
1251 foreach ( $this->mMetatags
as $tag ) {
1252 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1254 $tag[0] = substr( $tag[0], 5 );
1258 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1261 $p = $this->mRobotpolicy
;
1262 if( $p !== '' && $p != 'index,follow' ) {
1263 // http://www.robotstxt.org/wc/meta-user.html
1264 // Only show if it's different from the default robots policy
1265 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1268 if ( count( $this->mKeywords
) > 0 ) {
1273 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1274 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1276 foreach ( $this->mLinktags
as $tag ) {
1277 $ret .= "\t\t<link";
1278 foreach( $tag as $attr => $val ) {
1279 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1284 if( $this->isSyndicated() ) {
1285 # FIXME: centralize the mime-type and name information in Feed.php
1286 # Use the page name for the title (accessed through $wgTitle since
1287 # there's no other way). In principle, this could lead to issues
1288 # with having the same name for different feeds corresponding to
1289 # the same page, but we can't avoid that at this low a level.
1291 $ret .= $this->feedLink(
1293 $wgRequest->appendQuery( 'feed=rss' ),
1294 wfMsg( 'page-rss-feed', $wgTitle->getPrefixedText() ) );
1295 $ret .= $this->feedLink(
1297 $wgRequest->appendQuery( 'feed=atom' ),
1298 wfMsg( 'page-atom-feed', $wgTitle->getPrefixedText() ) );
1301 # Recent changes feed should appear on every page
1302 # Put it after the per-page feed to avoid changing existing behavior.
1303 # It's still available, probably via a menu in your browser.
1305 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
1306 $ret .= $this->feedLink(
1308 $rctitle->getFullURL( 'feed=rss' ),
1309 wfMsg( 'site-rss-feed', $wgSitename ) );
1310 $ret .= $this->feedLink(
1312 $rctitle->getFullURL( 'feed=atom' ),
1313 wfMsg( 'site-atom-feed', $wgSitename ) );
1319 * Generate a <link rel/> for an RSS feed.
1321 private function feedLink( $type, $url, $text ) {
1322 return Xml
::element( 'link', array(
1323 'rel' => 'alternate',
1324 'type' => "application/$type+xml",
1326 'href' => $url ) ) . "\n";
1330 * Turn off regular page output and return an error reponse
1331 * for when rate limiting has triggered.
1334 public function rateLimited() {
1337 wfHttpError( 500, 'Internal Server Error',
1338 'Sorry, the server has encountered an internal error. ' .
1339 'Please wait a moment and hit "refresh" to submit the request again.' );
1343 * Show an "add new section" link?
1347 public function showNewSectionLink() {
1348 return $this->mNewSectionLink
;
1352 * Show a warning about slave lag
1354 * If the lag is higher than $wgSlaveLagCritical seconds,
1355 * then the warning is a bit more obvious. If the lag is
1356 * lower than $wgSlaveLagWarning, then no warning is shown.
1358 * @param int $lag Slave lag
1360 public function showLagWarning( $lag ) {
1361 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1362 if( $lag >= $wgSlaveLagWarning ) {
1363 $message = $lag < $wgSlaveLagCritical
1366 $warning = wfMsgExt( $message, 'parse', $lag );
1367 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );