2 if ( ! defined( 'MEDIAWIKI' ) )
11 var $mMetatags, $mKeywords;
12 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
13 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
14 var $mSubtitle, $mRedirect, $mStatusCode;
15 var $mLastModified, $mETag, $mCategoryLinks;
16 var $mScripts, $mLinkColours, $mPageLinkTitle;
19 var $mSuppressQuickbar;
22 var $mContainsOldMagic, $mContainsNewMagic;
23 var $mIsArticleRelated;
24 protected $mParserOptions; // lazy initialised, use parserOptions()
25 var $mShowFeedLinks = false;
26 var $mEnableClientCache = true;
27 var $mArticleBodyOnly = false;
29 var $mNewSectionLink = false;
30 var $mNoGallery = false;
34 * Initialise private variables
36 function __construct() {
37 global $wgAllowUserJs;
38 $this->mAllowUserJs
= $wgAllowUserJs;
39 $this->mMetatags
= $this->mKeywords
= $this->mLinktags
= array();
40 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
41 $this->mRedirect
= $this->mLastModified
=
42 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
43 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
44 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
45 $this->mSuppressQuickbar
= $this->mPrintable
= false;
46 $this->mLanguageLinks
= array();
47 $this->mCategoryLinks
= array();
48 $this->mDoNothing
= false;
49 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
50 $this->mParserOptions
= null;
51 $this->mSquidMaxage
= 0;
53 $this->mHeadItems
= array();
55 $this->mRevisionId
= null;
56 $this->mNewSectionLink
= false;
57 $this->mTemplateIds
= array();
60 public function redirect( $url, $responsecode = '302' ) {
61 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
62 $this->mRedirect
= str_replace( "\n", '', $url );
63 $this->mRedirectCode
= $responsecode;
67 * Set the HTTP status code to send with the output.
69 * @param int $statusCode
72 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
74 # To add an http-equiv meta tag, precede the name with "http:"
75 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
76 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
77 function addScript( $script ) { $this->mScripts
.= "\t\t".$script; }
78 function addStyle( $style ) {
79 global $wgStylePath, $wgStyleVersion;
82 'rel' => 'stylesheet',
83 'href' => $wgStylePath . '/' . $style . '?' . $wgStyleVersion ) );
87 * Add a self-contained script tag with the given contents
88 * @param string $script JavaScript text, no <script> tags
90 function addInlineScript( $script ) {
92 $this->mScripts
.= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
95 function getScript() {
96 return $this->mScripts
. $this->getHeadItems();
99 function getHeadItems() {
101 foreach ( $this->mHeadItems
as $item ) {
107 function addHeadItem( $name, $value ) {
108 $this->mHeadItems
[$name] = $value;
111 function setETag($tag) { $this->mETag
= $tag; }
112 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
113 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
115 function addLink( $linkarr ) {
116 # $linkarr should be an associative array of attributes. We'll escape on output.
117 array_push( $this->mLinktags
, $linkarr );
120 function addMetadataLink( $linkarr ) {
121 # note: buggy CC software only reads first "meta" link
122 static $haveMeta = false;
123 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
124 $this->addLink( $linkarr );
129 * checkLastModified tells the client to use the client-cached page if
130 * possible. If sucessful, the OutputPage is disabled so that
131 * any future call to OutputPage->output() have no effect.
133 * @return bool True iff cache-ok headers was sent.
135 function checkLastModified ( $timestamp ) {
136 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
137 $fname = 'OutputPage::checkLastModified';
139 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
140 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
143 if( !$wgCachePages ) {
144 wfDebug( "$fname: CACHE DISABLED\n", false );
147 if( $wgUser->getOption( 'nocache' ) ) {
148 wfDebug( "$fname: USER DISABLED CACHE\n", false );
152 $timestamp=wfTimestamp(TS_MW
,$timestamp);
153 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
155 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
156 # IE sends sizes after the date like this:
157 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
158 # this breaks strtotime().
159 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
160 $modsinceTime = strtotime( $modsince );
161 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
162 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
163 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
164 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
165 # Make sure you're in a place you can leave when you call us!
166 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
167 $this->mLastModified
= $lastmod;
168 $this->sendCacheControl();
169 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
172 // Don't output a compressed blob when using ob_gzhandler;
173 // it's technically against HTTP spec and seems to confuse
174 // Firefox when the response gets split over two packets.
175 wfClearOutputBuffers();
179 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
180 $this->mLastModified
= $lastmod;
183 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
184 $this->mLastModified
= $lastmod;
188 function getPageTitleActionText () {
197 // Display title is already customized
200 return wfMsg('history_short');
202 // FIXME: bug 2735; not correct for special pages etc
203 return wfMsg('preview');
205 return wfMsg('info_short');
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 $popts->setTidy($tidy);
360 $parserOutput = $wgParser->parse( $text, $title, $popts,
361 $linestart, true, $this->mRevisionId
);
363 $this->addParserOutput( $parserOutput );
365 wfProfileOut($fname);
370 * @param ParserOutput object &$parserOutput
372 public function addParserOutputNoText( &$parserOutput ) {
373 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
374 $this->addCategoryLinks( $parserOutput->getCategories() );
375 $this->mNewSectionLink
= $parserOutput->getNewSection();
376 $this->addKeywords( $parserOutput );
377 if ( $parserOutput->getCacheTime() == -1 ) {
378 $this->enableClientCache( false );
380 if ( $parserOutput->mHTMLtitle
!= "" ) {
381 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
383 if ( $parserOutput->mSubtitle
!= '' ) {
384 $this->mSubtitle
.= $parserOutput->mSubtitle
;
386 $this->mNoGallery
= $parserOutput->getNoGallery();
387 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
389 $this->mTemplateIds +
= (array)$parserOutput->mTemplateIds
;
391 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
396 * @param ParserOutput &$parserOutput
398 function addParserOutput( &$parserOutput ) {
399 $this->addParserOutputNoText( $parserOutput );
400 $text = $parserOutput->getText();
401 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
402 $this->addHTML( $text );
406 * Add wikitext to the buffer, assuming that this is the primary text for a page view
407 * Saves the text into the parser cache if possible.
409 * @param string $text
410 * @param Article $article
412 * @deprecated Use Article::outputWikitext
414 public function addPrimaryWikiText( $text, $article, $cache = true ) {
415 global $wgParser, $wgUser;
417 $popts = $this->parserOptions();
418 $popts->setTidy(true);
419 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
420 $popts, true, true, $this->mRevisionId
);
421 $popts->setTidy(false);
422 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
423 $parserCache =& ParserCache
::singleton();
424 $parserCache->save( $parserOutput, $article, $wgUser );
427 $this->addParserOutput( $parserOutput );
431 * @deprecated use addWikiTextTidy()
433 public function addSecondaryWikiText( $text, $linestart = true ) {
435 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
439 * Add wikitext with tidy enabled
441 public function addWikiTextTidy( $text, $linestart = true ) {
443 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
448 * Add the output of a QuickTemplate to the output buffer
450 * @param QuickTemplate $template
452 public function addTemplate( &$template ) {
454 $template->execute();
455 $this->addHTML( ob_get_contents() );
460 * Parse wikitext and return the HTML.
462 * @param string $text
463 * @param bool $linestart Is this the start of a line?
464 * @param bool $interface ??
466 public function parse( $text, $linestart = true, $interface = false ) {
467 global $wgParser, $wgTitle;
468 $popts = $this->parserOptions();
469 if ( $interface) { $popts->setInterfaceMessage(true); }
470 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
471 $linestart, true, $this->mRevisionId
);
472 if ( $interface) { $popts->setInterfaceMessage(false); }
473 return $parserOutput->getText();
477 * @param Article $article
480 * @return bool True if successful, else false.
482 public function tryParserCache( &$article, $user ) {
483 $parserCache =& ParserCache
::singleton();
484 $parserOutput = $parserCache->get( $article, $user );
485 if ( $parserOutput !== false ) {
486 $this->addParserOutput( $parserOutput );
494 * @param int $maxage Maximum cache time on the Squid, in seconds.
496 public function setSquidMaxage( $maxage ) {
497 $this->mSquidMaxage
= $maxage;
501 * Use enableClientCache(false) to force it to send nocache headers
504 public function enableClientCache( $state ) {
505 return wfSetVar( $this->mEnableClientCache
, $state );
508 function uncacheableBecauseRequestvars() {
510 return $wgRequest->getText('useskin', false) === false
511 && $wgRequest->getText('uselang', false) === false;
514 public function sendCacheControl() {
515 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
516 $fname = 'OutputPage::sendCacheControl';
518 if ($wgUseETag && $this->mETag
)
519 $wgRequest->response()->header("ETag: $this->mETag");
521 # don't serve compressed data to clients who can't handle it
522 # maintain different caches for logged-in users and non-logged in ones
523 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
524 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
525 if( $wgUseSquid && session_id() == '' &&
526 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
529 # We'll purge the proxy cache explicitly, but require end user agents
530 # to revalidate against the proxy on each visit.
531 # Surrogate-Control controls our Squid, Cache-Control downstream caches
532 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
533 # start with a shorter timeout for initial testing
534 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
535 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
536 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
538 # We'll purge the proxy cache for anons explicitly, but require end user agents
539 # to revalidate against the proxy on each visit.
540 # IMPORTANT! The Squid needs to replace the Cache-Control header with
541 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
542 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
543 # start with a shorter timeout for initial testing
544 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
545 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
548 # We do want clients to cache if they can, but they *must* check for updates
549 # on revisiting the page.
550 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
551 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
552 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
554 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
556 wfDebug( "$fname: no caching **\n", false );
558 # In general, the absence of a last modified header should be enough to prevent
559 # the client from using its cache. We send a few other things just to make sure.
560 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
561 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
562 $wgRequest->response()->header( 'Pragma: no-cache' );
567 * Finally, all the text has been munged and accumulated into
568 * the object, let's actually output it:
570 public function output() {
571 global $wgUser, $wgOutputEncoding, $wgRequest;
572 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
573 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
574 global $wgServer, $wgStyleVersion;
576 if( $this->mDoNothing
){
579 $fname = 'OutputPage::output';
580 wfProfileIn( $fname );
581 $sk = $wgUser->getSkin();
584 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
586 wfRunHooks( 'AjaxAddScript', array( &$this ) );
588 if( $wgAjaxSearch ) {
589 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
590 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
593 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
594 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
598 if ( '' != $this->mRedirect
) {
599 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
600 # Standards require redirect URLs to be absolute
602 $this->mRedirect
= $wgServer . $this->mRedirect
;
604 if( $this->mRedirectCode
== '301') {
605 if( !$wgDebugRedirects ) {
606 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
608 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
611 $this->sendCacheControl();
613 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
614 if( $wgDebugRedirects ) {
615 $url = htmlspecialchars( $this->mRedirect
);
616 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
617 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
618 print "</body>\n</html>\n";
620 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
622 wfProfileOut( $fname );
625 elseif ( $this->mStatusCode
)
627 $statusMessage = array(
629 101 => 'Switching Protocols',
634 203 => 'Non-Authoritative Information',
636 205 => 'Reset Content',
637 206 => 'Partial Content',
638 207 => 'Multi-Status',
639 300 => 'Multiple Choices',
640 301 => 'Moved Permanently',
643 304 => 'Not Modified',
645 307 => 'Temporary Redirect',
646 400 => 'Bad Request',
647 401 => 'Unauthorized',
648 402 => 'Payment Required',
651 405 => 'Method Not Allowed',
652 406 => 'Not Acceptable',
653 407 => 'Proxy Authentication Required',
654 408 => 'Request Timeout',
657 411 => 'Length Required',
658 412 => 'Precondition Failed',
659 413 => 'Request Entity Too Large',
660 414 => 'Request-URI Too Large',
661 415 => 'Unsupported Media Type',
662 416 => 'Request Range Not Satisfiable',
663 417 => 'Expectation Failed',
664 422 => 'Unprocessable Entity',
666 424 => 'Failed Dependency',
667 500 => 'Internal Server Error',
668 501 => 'Not Implemented',
669 502 => 'Bad Gateway',
670 503 => 'Service Unavailable',
671 504 => 'Gateway Timeout',
672 505 => 'HTTP Version Not Supported',
673 507 => 'Insufficient Storage'
676 if ( $statusMessage[$this->mStatusCode
] )
677 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
680 # Buffer output; final headers may depend on later processing
683 # Disable temporary placeholders, so that the skin produces HTML
684 $sk->postParseLinkColour( false );
686 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
687 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
689 if ($this->mArticleBodyOnly
) {
690 $this->out($this->mBodytext
);
692 wfProfileIn( 'Output-skin' );
693 $sk->outputPage( $this );
694 wfProfileOut( 'Output-skin' );
697 $this->sendCacheControl();
699 wfProfileOut( $fname );
706 public function out( $ins ) {
707 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
708 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
711 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
712 if ( false === $outs ) { $outs = $ins; }
720 public static function setEncodings() {
721 global $wgInputEncoding, $wgOutputEncoding;
722 global $wgUser, $wgContLang;
724 $wgInputEncoding = strtolower( $wgInputEncoding );
726 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
727 $wgOutputEncoding = strtolower( $wgOutputEncoding );
730 $wgOutputEncoding = $wgInputEncoding;
734 * Deprecated, use wfReportTime() instead.
738 public function reportTime() {
739 $time = wfReportTime();
744 * Produce a "user is blocked" page.
746 * @param bool $return Whether to have a "return to $wgTitle" message or not.
749 function blockedPage( $return = true ) {
750 global $wgUser, $wgContLang, $wgTitle, $wgLang;
752 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
753 $this->setRobotpolicy( 'noindex,nofollow' );
754 $this->setArticleRelated( false );
756 $id = $wgUser->blockedBy();
757 $reason = $wgUser->blockedFor();
760 if ( is_numeric( $id ) ) {
761 $name = User
::whoIs( $id );
765 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
767 $blockid = $wgUser->mBlock
->mId
;
769 $blockExpiry = $wgUser->mBlock
->mExpiry
;
770 if ( $blockExpiry == 'infinity' ) {
771 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
772 // Search for localization in 'ipboptions'
773 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
774 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
775 if ( strpos( $option, ":" ) === false )
777 list( $show, $value ) = explode( ":", $option );
778 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
779 $blockExpiry = $show;
784 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
787 if ( $wgUser->mBlock
->mAuto
) {
788 $msg = 'autoblockedtext';
790 $msg = 'blockedtext';
793 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
794 * This could be a username, an ip range, or a single ip. */
795 $intended = $wgUser->mBlock
->mAddress
;
797 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended ) );
799 # Don't auto-return to special pages
801 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
802 $this->returnToMain( false, $return );
807 * Output a standard error page
809 * @param string $title Message key for page title
810 * @param string $msg Message key for page text
811 * @param array $params Message parameters
813 public function showErrorPage( $title, $msg, $params = array() ) {
816 $this->mDebugtext
.= 'Original title: ' .
817 $wgTitle->getPrefixedText() . "\n";
818 $this->setPageTitle( wfMsg( $title ) );
819 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
820 $this->setRobotpolicy( 'noindex,nofollow' );
821 $this->setArticleRelated( false );
822 $this->enableClientCache( false );
823 $this->mRedirect
= '';
824 $this->mBodytext
= '';
826 array_unshift( $params, $msg );
827 $message = call_user_func_array( 'wfMsg', $params );
828 $this->addWikiText( $message );
830 $this->returnToMain( false );
834 public function errorpage( $title, $msg ) {
835 throw new ErrorPageError( $title, $msg );
839 * Display an error page indicating that a given version of MediaWiki is
842 * @param mixed $version The version of MediaWiki needed to use the page
844 public function versionRequired( $version ) {
845 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
846 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
847 $this->setRobotpolicy( 'noindex,nofollow' );
848 $this->setArticleRelated( false );
849 $this->mBodytext
= '';
851 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
852 $this->returnToMain();
856 * Display an error page noting that a given permission bit is required.
858 * @param string $permission key required
860 public function permissionRequired( $permission ) {
861 global $wgGroupPermissions, $wgUser;
863 $this->setPageTitle( wfMsg( 'badaccess' ) );
864 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
865 $this->setRobotpolicy( 'noindex,nofollow' );
866 $this->setArticleRelated( false );
867 $this->mBodytext
= '';
870 foreach( $wgGroupPermissions as $key => $value ) {
871 if( isset( $value[$permission] ) && $value[$permission] == true ) {
872 $groupName = User
::getGroupName( $key );
873 $groupPage = User
::getGroupPage( $key );
875 $skin = $wgUser->getSkin();
876 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
878 $groups[] = $groupName;
882 $n = count( $groups );
883 $groups = implode( ', ', $groups );
888 $message = wfMsgHtml( "badaccess-group$n", $groups );
891 $message = wfMsgHtml( 'badaccess-groups', $groups );
893 $this->addHtml( $message );
894 $this->returnToMain( false );
898 * Use permissionRequired.
901 public function sysopRequired() {
902 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
906 * Use permissionRequired.
909 public function developerRequired() {
910 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
914 * Produce the stock "please login to use the wiki" page
916 public function loginToUse() {
917 global $wgUser, $wgTitle, $wgContLang;
919 if( $wgUser->isLoggedIn() ) {
920 $this->permissionRequired( 'read' );
924 $skin = $wgUser->getSkin();
926 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
927 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
928 $this->setRobotPolicy( 'noindex,nofollow' );
929 $this->setArticleFlag( false );
931 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
932 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
933 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
934 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
936 # Don't return to the main page if the user can't read it
937 # otherwise we'll end up in a pointless loop
938 $mainPage = Title
::newMainPage();
939 if( $mainPage->userCanRead() )
940 $this->returnToMain( true, $mainPage );
944 public function databaseError( $fname, $sql, $error, $errno ) {
945 throw new MWException( "OutputPage::databaseError is obsolete\n" );
950 * @param bool $protected Is the reason the page can't be reached because it's protected?
951 * @param mixed $source
953 public function readOnlyPage( $source = null, $protected = false ) {
954 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
955 $skin = $wgUser->getSkin();
957 $this->setRobotpolicy( 'noindex,nofollow' );
958 $this->setArticleRelated( false );
961 $this->setPageTitle( wfMsg( 'viewsource' ) );
962 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
964 list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources();
966 # Determine if protection is due to the page being a system message
967 # and show an appropriate explanation
968 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
969 $this->addWikiText( wfMsg( 'protectedinterface' ) );
970 } if ( $cascadeSources && count($cascadeSources) > 0 ) {
973 foreach ( $cascadeSources as $title ) {
974 $titles .= '* [[:' . $title->getPrefixedText() . "]]\n";
977 $notice = wfMsgExt( 'cascadeprotected', array('parsemag'), count($cascadeSources) ) . "\n$titles";
979 $this->addWikiText( $notice );
981 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
984 $this->setPageTitle( wfMsg( 'readonly' ) );
986 $reason = $wgReadOnly;
988 $reason = file_get_contents( $wgReadOnlyFile );
990 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
993 if( is_string( $source ) ) {
994 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
995 $rows = $wgUser->getIntOption( 'rows' );
996 $cols = $wgUser->getIntOption( 'cols' );
997 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
998 htmlspecialchars( $source ) . "\n</textarea>";
999 $this->addHTML( $text );
1001 $article = new Article($wgTitle);
1002 $this->addHTML( $skin->formatTemplates($article->getUsedTemplates()) );
1004 $this->returnToMain( false );
1008 public function fatalError( $message ) {
1009 throw new FatalError( $message );
1013 public function unexpectedValueError( $name, $val ) {
1014 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1018 public function fileCopyError( $old, $new ) {
1019 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1023 public function fileRenameError( $old, $new ) {
1024 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1028 public function fileDeleteError( $name ) {
1029 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1033 public function fileNotFoundError( $name ) {
1034 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1037 public function showFatalError( $message ) {
1038 $this->setPageTitle( wfMsg( "internalerror" ) );
1039 $this->setRobotpolicy( "noindex,nofollow" );
1040 $this->setArticleRelated( false );
1041 $this->enableClientCache( false );
1042 $this->mRedirect
= '';
1043 $this->mBodytext
= $message;
1046 public function showUnexpectedValueError( $name, $val ) {
1047 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1050 public function showFileCopyError( $old, $new ) {
1051 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1054 public function showFileRenameError( $old, $new ) {
1055 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1058 public function showFileDeleteError( $name ) {
1059 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1062 public function showFileNotFoundError( $name ) {
1063 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1067 * return from error messages or notes
1068 * @param $auto automatically redirect the user after 10 seconds
1069 * @param $returnto page title to return to. Default is Main Page.
1071 public function returnToMain( $auto = true, $returnto = NULL ) {
1072 global $wgUser, $wgOut, $wgRequest;
1074 if ( $returnto == NULL ) {
1075 $returnto = $wgRequest->getText( 'returnto' );
1078 if ( '' === $returnto ) {
1079 $returnto = Title
::newMainPage();
1082 if ( is_object( $returnto ) ) {
1083 $titleObj = $returnto;
1085 $titleObj = Title
::newFromText( $returnto );
1087 if ( !is_object( $titleObj ) ) {
1088 $titleObj = Title
::newMainPage();
1091 $sk = $wgUser->getSkin();
1092 $link = $sk->makeLinkObj( $titleObj, '' );
1094 $r = wfMsg( 'returnto', $link );
1096 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
1098 $wgOut->addHTML( "\n<p>$r</p>\n" );
1102 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1103 * and uses the first 10 of them for META keywords
1105 * @param ParserOutput &$parserOutput
1107 private function addKeywords( &$parserOutput ) {
1109 $this->addKeyword( $wgTitle->getPrefixedText() );
1111 $links2d =& $parserOutput->getLinks();
1112 if ( !is_array( $links2d ) ) {
1115 foreach ( $links2d as $dbkeys ) {
1116 foreach( $dbkeys as $dbkey => $unused ) {
1117 $this->addKeyword( $dbkey );
1118 if ( ++
$count > 10 ) {
1126 * @return string The doctype, opening <html>, and head element.
1128 public function headElement() {
1129 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1130 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1131 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1133 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1134 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1139 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1141 if ( '' == $this->getHTMLTitle() ) {
1142 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1145 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1146 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1147 foreach($wgXhtmlNamespaces as $tag => $ns) {
1148 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1150 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1151 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1152 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1154 $ret .= $this->getHeadLinks();
1155 global $wgStylePath;
1156 if( $this->isPrintable() ) {
1159 $media = "media='print'";
1161 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1162 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1164 $sk = $wgUser->getSkin();
1165 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1166 $ret .= $this->mScripts
;
1167 $ret .= $sk->getUserStyles();
1168 $ret .= $this->getHeadItems();
1170 if ($wgUseTrackbacks && $this->isArticleRelated())
1171 $ret .= $wgTitle->trackbackRDF();
1173 $ret .= "</head>\n";
1178 * @return string HTML tag links to be put in the header.
1180 public function getHeadLinks() {
1183 foreach ( $this->mMetatags
as $tag ) {
1184 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1186 $tag[0] = substr( $tag[0], 5 );
1190 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1193 $p = $this->mRobotpolicy
;
1194 if( $p !== '' && $p != 'index,follow' ) {
1195 // http://www.robotstxt.org/wc/meta-user.html
1196 // Only show if it's different from the default robots policy
1197 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1200 if ( count( $this->mKeywords
) > 0 ) {
1205 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1206 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1208 foreach ( $this->mLinktags
as $tag ) {
1209 $ret .= "\t\t<link";
1210 foreach( $tag as $attr => $val ) {
1211 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1215 if( $this->isSyndicated() ) {
1216 # FIXME: centralize the mime-type and name information in Feed.php
1217 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1218 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1219 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1220 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 1.0' href='$link' />\n";
1227 * Turn off regular page output and return an error reponse
1228 * for when rate limiting has triggered.
1231 public function rateLimited() {
1234 wfHttpError( 500, 'Internal Server Error',
1235 'Sorry, the server has encountered an internal error. ' .
1236 'Please wait a moment and hit "refresh" to submit the request again.' );
1240 * Show an "add new section" link?
1242 * @return bool True if the parser output instructs us to add one
1244 public function showNewSectionLink() {
1245 return $this->mNewSectionLink
;
1249 * Show a warning about slave lag
1251 * If the lag is higher than 30 seconds, then the warning is
1252 * a bit more obvious
1254 * @param int $lag Slave lag
1256 public function showLagWarning( $lag ) {
1257 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1259 if ($lag < $wgSlaveLagWarning)
1262 $message = ($lag >= $wgSlaveLagCritical) ?
'lag-warn-high' : 'lag-warn-normal';
1263 $warning = wfMsgHtml( $message, htmlspecialchars( $lag ) );
1264 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );