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 = '';
33 var $mParseWarnings = array();
37 * Initialise private variables
39 function __construct() {
40 global $wgAllowUserJs;
41 $this->mAllowUserJs
= $wgAllowUserJs;
42 $this->mMetatags
= $this->mKeywords
= $this->mLinktags
= array();
43 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
44 $this->mRedirect
= $this->mLastModified
=
45 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
46 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
47 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
48 $this->mSuppressQuickbar
= $this->mPrintable
= false;
49 $this->mLanguageLinks
= array();
50 $this->mCategoryLinks
= array();
51 $this->mDoNothing
= false;
52 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
53 $this->mParserOptions
= null;
54 $this->mSquidMaxage
= 0;
56 $this->mHeadItems
= array();
58 $this->mRevisionId
= null;
59 $this->mNewSectionLink
= false;
60 $this->mTemplateIds
= array();
63 public function redirect( $url, $responsecode = '302' ) {
64 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
65 $this->mRedirect
= str_replace( "\n", '', $url );
66 $this->mRedirectCode
= $responsecode;
69 public function getRedirect() {
70 return $this->mRedirect
;
74 * Set the HTTP status code to send with the output.
76 * @param int $statusCode
79 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
81 # To add an http-equiv meta tag, precede the name with "http:"
82 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
83 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
84 function addScript( $script ) { $this->mScripts
.= "\t\t".$script; }
85 function addStyle( $style ) {
86 global $wgStylePath, $wgStyleVersion;
89 'rel' => 'stylesheet',
90 'href' => $wgStylePath . '/' . $style . '?' . $wgStyleVersion ) );
94 * Add a self-contained script tag with the given contents
95 * @param string $script JavaScript text, no <script> tags
97 function addInlineScript( $script ) {
99 $this->mScripts
.= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
102 function getScript() {
103 return $this->mScripts
. $this->getHeadItems();
106 function getHeadItems() {
108 foreach ( $this->mHeadItems
as $item ) {
114 function addHeadItem( $name, $value ) {
115 $this->mHeadItems
[$name] = $value;
118 function hasHeadItem( $name ) {
119 return isset( $this->mHeadItems
[$name] );
122 function setETag($tag) { $this->mETag
= $tag; }
123 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
124 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
126 function addLink( $linkarr ) {
127 # $linkarr should be an associative array of attributes. We'll escape on output.
128 array_push( $this->mLinktags
, $linkarr );
131 function addMetadataLink( $linkarr ) {
132 # note: buggy CC software only reads first "meta" link
133 static $haveMeta = false;
134 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
135 $this->addLink( $linkarr );
140 * checkLastModified tells the client to use the client-cached page if
141 * possible. If sucessful, the OutputPage is disabled so that
142 * any future call to OutputPage->output() have no effect.
144 * @return bool True iff cache-ok headers was sent.
146 function checkLastModified ( $timestamp ) {
147 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
148 $fname = 'OutputPage::checkLastModified';
150 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
151 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
154 if( !$wgCachePages ) {
155 wfDebug( "$fname: CACHE DISABLED\n", false );
158 if( $wgUser->getOption( 'nocache' ) ) {
159 wfDebug( "$fname: USER DISABLED CACHE\n", false );
163 $timestamp=wfTimestamp(TS_MW
,$timestamp);
164 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
166 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
167 # IE sends sizes after the date like this:
168 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
169 # this breaks strtotime().
170 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
172 wfSuppressWarnings(); // E_STRICT system time bitching
173 $modsinceTime = strtotime( $modsince );
176 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
177 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
178 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
179 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
180 # Make sure you're in a place you can leave when you call us!
181 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
182 $this->mLastModified
= $lastmod;
183 $this->sendCacheControl();
184 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
187 // Don't output a compressed blob when using ob_gzhandler;
188 // it's technically against HTTP spec and seems to confuse
189 // Firefox when the response gets split over two packets.
190 wfClearOutputBuffers();
194 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
195 $this->mLastModified
= $lastmod;
198 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
199 $this->mLastModified
= $lastmod;
203 function setPageTitleActionText( $text ) {
204 $this->mPageTitleActionText
= $text;
207 function getPageTitleActionText () {
208 if ( isset( $this->mPageTitleActionText
) ) {
209 return $this->mPageTitleActionText
;
213 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
214 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
215 public function setPageTitle( $name ) {
216 global $action, $wgContLang;
217 $name = $wgContLang->convert($name, true);
218 $this->mPagetitle
= $name;
219 if(!empty($action)) {
220 $taction = $this->getPageTitleActionText();
221 if( !empty( $taction ) ) {
222 $name .= ' - '.$taction;
226 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
228 public function getHTMLTitle() { return $this->mHTMLtitle
; }
229 public function getPageTitle() { return $this->mPagetitle
; }
230 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
231 public function getSubtitle() { return $this->mSubtitle
; }
232 public function isArticle() { return $this->mIsarticle
; }
233 public function setPrintable() { $this->mPrintable
= true; }
234 public function isPrintable() { return $this->mPrintable
; }
235 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
236 public function isSyndicated() { return $this->mShowFeedLinks
; }
237 public function setFeedAppendQuery( $val ) { $this->mFeedLinksAppendQuery
= $val; }
238 public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery
; }
239 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
240 public function getOnloadHandler() { return $this->mOnloadHandler
; }
241 public function disable() { $this->mDoNothing
= true; }
243 public function setArticleRelated( $v ) {
244 $this->mIsArticleRelated
= $v;
246 $this->mIsarticle
= false;
249 public function setArticleFlag( $v ) {
250 $this->mIsarticle
= $v;
252 $this->mIsArticleRelated
= $v;
256 public function isArticleRelated() { return $this->mIsArticleRelated
; }
258 public function getLanguageLinks() { return $this->mLanguageLinks
; }
259 public function addLanguageLinks($newLinkArray) {
260 $this->mLanguageLinks +
= $newLinkArray;
262 public function setLanguageLinks($newLinkArray) {
263 $this->mLanguageLinks
= $newLinkArray;
266 public function getCategoryLinks() {
267 return $this->mCategoryLinks
;
271 * Add an array of categories, with names in the keys
273 public function addCategoryLinks($categories) {
274 global $wgUser, $wgContLang;
276 if ( !is_array( $categories ) ) {
279 # Add the links to the link cache in a batch
280 $arr = array( NS_CATEGORY
=> $categories );
282 $lb->setArray( $arr );
285 $sk = $wgUser->getSkin();
286 foreach ( $categories as $category => $unused ) {
287 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
288 $text = $wgContLang->convertHtml( $title->getText() );
289 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
293 public function setCategoryLinks($categories) {
294 $this->mCategoryLinks
= array();
295 $this->addCategoryLinks($categories);
298 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
299 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
301 public function disallowUserJs() { $this->mAllowUserJs
= false; }
302 public function isUserJsAllowed() { return $this->mAllowUserJs
; }
304 public function addHTML( $text ) { $this->mBodytext
.= $text; }
305 public function clearHTML() { $this->mBodytext
= ''; }
306 public function getHTML() { return $this->mBodytext
; }
307 public function debug( $text ) { $this->mDebugtext
.= $text; }
310 public function setParserOptions( $options ) {
311 return $this->parserOptions( $options );
314 public function parserOptions( $options = null ) {
315 if ( !$this->mParserOptions
) {
316 $this->mParserOptions
= new ParserOptions
;
318 return wfSetVar( $this->mParserOptions
, $options );
322 * Set the revision ID which will be seen by the wiki text parser
323 * for things such as embedded {{REVISIONID}} variable use.
324 * @param mixed $revid an integer, or NULL
325 * @return mixed previous value
327 public function setRevisionId( $revid ) {
328 $val = is_null( $revid ) ?
null : intval( $revid );
329 return wfSetVar( $this->mRevisionId
, $val );
333 * Convert wikitext to HTML and add it to the buffer
334 * Default assumes that the current page title will
337 * @param string $text
338 * @param bool $linestart
340 public function addWikiText( $text, $linestart = true ) {
342 $this->addWikiTextTitle($text, $wgTitle, $linestart);
345 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
346 $this->addWikiTextTitle($text, $title, $linestart);
349 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
350 $this->addWikiTextTitle( $text, $title, $linestart, true );
353 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
356 $fname = 'OutputPage:addWikiTextTitle';
359 wfIncrStats('pcache_not_possible');
361 $popts = $this->parserOptions();
362 $oldTidy = $popts->setTidy($tidy);
364 $parserOutput = $wgParser->parse( $text, $title, $popts,
365 $linestart, true, $this->mRevisionId
);
367 $popts->setTidy( $oldTidy );
369 $this->addParserOutput( $parserOutput );
371 wfProfileOut($fname);
376 * @param ParserOutput object &$parserOutput
378 public function addParserOutputNoText( &$parserOutput ) {
379 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
380 $this->addCategoryLinks( $parserOutput->getCategories() );
381 $this->mNewSectionLink
= $parserOutput->getNewSection();
382 $this->addKeywords( $parserOutput );
383 $this->mParseWarnings
= $parserOutput->getWarnings();
384 if ( $parserOutput->getCacheTime() == -1 ) {
385 $this->enableClientCache( false );
387 $this->mNoGallery
= $parserOutput->getNoGallery();
388 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
390 $this->mTemplateIds +
= (array)$parserOutput->mTemplateIds
;
393 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
394 $this->setPageTitle( $dt );
396 # Hooks registered in the object
397 global $wgParserOutputHooks;
398 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
399 list( $hookName, $data ) = $hookInfo;
400 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
401 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
405 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
410 * @param ParserOutput &$parserOutput
412 function addParserOutput( &$parserOutput ) {
413 $this->addParserOutputNoText( $parserOutput );
414 $text = $parserOutput->getText();
415 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
416 $this->addHTML( $text );
420 * Add wikitext to the buffer, assuming that this is the primary text for a page view
421 * Saves the text into the parser cache if possible.
423 * @param string $text
424 * @param Article $article
426 * @deprecated Use Article::outputWikitext
428 public function addPrimaryWikiText( $text, $article, $cache = true ) {
429 global $wgParser, $wgUser;
431 $popts = $this->parserOptions();
432 $popts->setTidy(true);
433 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
434 $popts, true, true, $this->mRevisionId
);
435 $popts->setTidy(false);
436 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
437 $parserCache =& ParserCache
::singleton();
438 $parserCache->save( $parserOutput, $article, $wgUser );
441 $this->addParserOutput( $parserOutput );
445 * @deprecated use addWikiTextTidy()
447 public function addSecondaryWikiText( $text, $linestart = true ) {
449 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
453 * Add wikitext with tidy enabled
455 public function addWikiTextTidy( $text, $linestart = true ) {
457 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
462 * Add the output of a QuickTemplate to the output buffer
464 * @param QuickTemplate $template
466 public function addTemplate( &$template ) {
468 $template->execute();
469 $this->addHTML( ob_get_contents() );
474 * Parse wikitext and return the HTML.
476 * @param string $text
477 * @param bool $linestart Is this the start of a line?
478 * @param bool $interface ??
480 public function parse( $text, $linestart = true, $interface = false ) {
481 global $wgParser, $wgTitle;
482 $popts = $this->parserOptions();
483 if ( $interface) { $popts->setInterfaceMessage(true); }
484 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
485 $linestart, true, $this->mRevisionId
);
486 if ( $interface) { $popts->setInterfaceMessage(false); }
487 return $parserOutput->getText();
491 * @param Article $article
494 * @return bool True if successful, else false.
496 public function tryParserCache( &$article, $user ) {
497 $parserCache =& ParserCache
::singleton();
498 $parserOutput = $parserCache->get( $article, $user );
499 if ( $parserOutput !== false ) {
500 $this->addParserOutput( $parserOutput );
508 * @param int $maxage Maximum cache time on the Squid, in seconds.
510 public function setSquidMaxage( $maxage ) {
511 $this->mSquidMaxage
= $maxage;
515 * Use enableClientCache(false) to force it to send nocache headers
518 public function enableClientCache( $state ) {
519 return wfSetVar( $this->mEnableClientCache
, $state );
522 function uncacheableBecauseRequestvars() {
524 return $wgRequest->getText('useskin', false) === false
525 && $wgRequest->getText('uselang', false) === false;
528 /** Get a complete X-Vary-Options header */
529 public function getXVO() {
530 global $wgCookiePrefix;
531 return 'X-Vary-Options: ' .
533 "Cookie;string-contains={$wgCookiePrefix}UserID;" .
535 'string-contains=' . session_name() . ',' .
536 # Encoding checks for gzip only
537 'Accept-Encoding;list-contains=gzip';
540 public function sendCacheControl() {
541 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
542 $fname = 'OutputPage::sendCacheControl';
544 $response = $wgRequest->response();
545 if ($wgUseETag && $this->mETag
)
546 $response->header("ETag: $this->mETag");
548 # don't serve compressed data to clients who can't handle it
549 # maintain different caches for logged-in users and non-logged in ones
550 $response->header( 'Vary: Accept-Encoding, Cookie' );
552 # Add an X-Vary-Options header for Squid with Wikimedia patches
553 $response->header( $this->getXVO() );
555 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
556 if( $wgUseSquid && session_id() == '' &&
557 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
560 # We'll purge the proxy cache explicitly, but require end user agents
561 # to revalidate against the proxy on each visit.
562 # Surrogate-Control controls our Squid, Cache-Control downstream caches
563 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
564 # start with a shorter timeout for initial testing
565 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
566 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
567 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
569 # We'll purge the proxy cache for anons explicitly, but require end user agents
570 # to revalidate against the proxy on each visit.
571 # IMPORTANT! The Squid needs to replace the Cache-Control header with
572 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
573 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
574 # start with a shorter timeout for initial testing
575 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
576 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
579 # We do want clients to cache if they can, but they *must* check for updates
580 # on revisiting the page.
581 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
582 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
583 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
585 if($this->mLastModified
) $response->header( "Last-modified: {$this->mLastModified}" );
587 wfDebug( "$fname: no caching **\n", false );
589 # In general, the absence of a last modified header should be enough to prevent
590 # the client from using its cache. We send a few other things just to make sure.
591 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
592 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
593 $response->header( 'Pragma: no-cache' );
598 * Finally, all the text has been munged and accumulated into
599 * the object, let's actually output it:
601 public function output() {
602 global $wgUser, $wgOutputEncoding, $wgRequest;
603 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
604 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
605 global $wgServer, $wgStyleVersion;
607 if( $this->mDoNothing
){
610 $fname = 'OutputPage::output';
611 wfProfileIn( $fname );
613 if ( '' != $this->mRedirect
) {
614 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
615 # Standards require redirect URLs to be absolute
617 $this->mRedirect
= $wgServer . $this->mRedirect
;
619 if( $this->mRedirectCode
== '301') {
620 if( !$wgDebugRedirects ) {
621 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
623 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
626 $this->sendCacheControl();
628 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
629 if( $wgDebugRedirects ) {
630 $url = htmlspecialchars( $this->mRedirect
);
631 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
632 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
633 print "</body>\n</html>\n";
635 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
637 wfProfileOut( $fname );
640 elseif ( $this->mStatusCode
)
642 $statusMessage = array(
644 101 => 'Switching Protocols',
649 203 => 'Non-Authoritative Information',
651 205 => 'Reset Content',
652 206 => 'Partial Content',
653 207 => 'Multi-Status',
654 300 => 'Multiple Choices',
655 301 => 'Moved Permanently',
658 304 => 'Not Modified',
660 307 => 'Temporary Redirect',
661 400 => 'Bad Request',
662 401 => 'Unauthorized',
663 402 => 'Payment Required',
666 405 => 'Method Not Allowed',
667 406 => 'Not Acceptable',
668 407 => 'Proxy Authentication Required',
669 408 => 'Request Timeout',
672 411 => 'Length Required',
673 412 => 'Precondition Failed',
674 413 => 'Request Entity Too Large',
675 414 => 'Request-URI Too Large',
676 415 => 'Unsupported Media Type',
677 416 => 'Request Range Not Satisfiable',
678 417 => 'Expectation Failed',
679 422 => 'Unprocessable Entity',
681 424 => 'Failed Dependency',
682 500 => 'Internal Server Error',
683 501 => 'Not Implemented',
684 502 => 'Bad Gateway',
685 503 => 'Service Unavailable',
686 504 => 'Gateway Timeout',
687 505 => 'HTTP Version Not Supported',
688 507 => 'Insufficient Storage'
691 if ( $statusMessage[$this->mStatusCode
] )
692 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
695 $sk = $wgUser->getSkin();
698 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
700 wfRunHooks( 'AjaxAddScript', array( &$this ) );
702 if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) {
703 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
704 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
707 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
708 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
714 # Buffer output; final headers may depend on later processing
717 # Disable temporary placeholders, so that the skin produces HTML
718 $sk->postParseLinkColour( false );
720 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
721 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
723 if ($this->mArticleBodyOnly
) {
724 $this->out($this->mBodytext
);
726 wfProfileIn( 'Output-skin' );
727 $sk->outputPage( $this );
728 wfProfileOut( 'Output-skin' );
731 $this->sendCacheControl();
733 wfProfileOut( $fname );
740 public function out( $ins ) {
741 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
742 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
745 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
746 if ( false === $outs ) { $outs = $ins; }
754 public static function setEncodings() {
755 global $wgInputEncoding, $wgOutputEncoding;
756 global $wgUser, $wgContLang;
758 $wgInputEncoding = strtolower( $wgInputEncoding );
760 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
761 $wgOutputEncoding = strtolower( $wgOutputEncoding );
764 $wgOutputEncoding = $wgInputEncoding;
768 * Deprecated, use wfReportTime() instead.
772 public function reportTime() {
773 $time = wfReportTime();
778 * Produce a "user is blocked" page.
780 * @param bool $return Whether to have a "return to $wgTitle" message or not.
783 function blockedPage( $return = true ) {
784 global $wgUser, $wgContLang, $wgTitle, $wgLang;
786 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
787 $this->setRobotpolicy( 'noindex,nofollow' );
788 $this->setArticleRelated( false );
790 $name = User
::whoIs( $wgUser->blockedBy() );
791 $reason = $wgUser->blockedFor();
792 if( $reason == '' ) {
793 $reason = wfMsg( 'blockednoreason' );
795 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
798 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
800 $blockid = $wgUser->mBlock
->mId
;
802 $blockExpiry = $wgUser->mBlock
->mExpiry
;
803 if ( $blockExpiry == 'infinity' ) {
804 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
805 // Search for localization in 'ipboptions'
806 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
807 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
808 if ( strpos( $option, ":" ) === false )
810 list( $show, $value ) = explode( ":", $option );
811 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
812 $blockExpiry = $show;
817 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
820 if ( $wgUser->mBlock
->mAuto
) {
821 $msg = 'autoblockedtext';
823 $msg = 'blockedtext';
826 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
827 * This could be a username, an ip range, or a single ip. */
828 $intended = $wgUser->mBlock
->mAddress
;
830 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp ) );
832 # Don't auto-return to special pages
834 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
835 $this->returnToMain( false, $return );
840 * Output a standard error page
842 * @param string $title Message key for page title
843 * @param string $msg Message key for page text
844 * @param array $params Message parameters
846 public function showErrorPage( $title, $msg, $params = array() ) {
848 if ( isset($wgTitle) ) {
849 $this->mDebugtext
.= 'Original title: ' . $wgTitle->getPrefixedText() . "\n";
851 $this->setPageTitle( wfMsg( $title ) );
852 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
853 $this->setRobotpolicy( 'noindex,nofollow' );
854 $this->setArticleRelated( false );
855 $this->enableClientCache( false );
856 $this->mRedirect
= '';
857 $this->mBodytext
= '';
859 array_unshift( $params, 'parse' );
860 array_unshift( $params, $msg );
861 $this->addHtml( call_user_func_array( 'wfMsgExt', $params ) );
863 $this->returnToMain( false );
867 * Output a standard permission error page
869 * @param array $errors Error message keys
871 public function showPermissionsErrorPage( $errors )
875 $this->mDebugtext
.= 'Original title: ' .
876 $wgTitle->getPrefixedText() . "\n";
877 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
878 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
879 $this->setRobotpolicy( 'noindex,nofollow' );
880 $this->setArticleRelated( false );
881 $this->enableClientCache( false );
882 $this->mRedirect
= '';
883 $this->mBodytext
= '';
884 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors ) );
888 public function errorpage( $title, $msg ) {
889 throw new ErrorPageError( $title, $msg );
893 * Display an error page indicating that a given version of MediaWiki is
896 * @param mixed $version The version of MediaWiki needed to use the page
898 public function versionRequired( $version ) {
899 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
900 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
901 $this->setRobotpolicy( 'noindex,nofollow' );
902 $this->setArticleRelated( false );
903 $this->mBodytext
= '';
905 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
906 $this->returnToMain();
910 * Display an error page noting that a given permission bit is required.
912 * @param string $permission key required
914 public function permissionRequired( $permission ) {
915 global $wgGroupPermissions, $wgUser;
917 $this->setPageTitle( wfMsg( 'badaccess' ) );
918 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
919 $this->setRobotpolicy( 'noindex,nofollow' );
920 $this->setArticleRelated( false );
921 $this->mBodytext
= '';
924 foreach( $wgGroupPermissions as $key => $value ) {
925 if( isset( $value[$permission] ) && $value[$permission] == true ) {
926 $groupName = User
::getGroupName( $key );
927 $groupPage = User
::getGroupPage( $key );
929 $skin = $wgUser->getSkin();
930 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
932 $groups[] = $groupName;
936 $n = count( $groups );
937 $groups = implode( ', ', $groups );
942 $message = wfMsgHtml( "badaccess-group$n", $groups );
945 $message = wfMsgHtml( 'badaccess-groups', $groups );
947 $this->addHtml( $message );
948 $this->returnToMain( false );
952 * Use permissionRequired.
955 public function sysopRequired() {
956 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
960 * Use permissionRequired.
963 public function developerRequired() {
964 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
968 * Produce the stock "please login to use the wiki" page
970 public function loginToUse() {
971 global $wgUser, $wgTitle, $wgContLang;
973 if( $wgUser->isLoggedIn() ) {
974 $this->permissionRequired( 'read' );
978 $skin = $wgUser->getSkin();
980 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
981 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
982 $this->setRobotPolicy( 'noindex,nofollow' );
983 $this->setArticleFlag( false );
985 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
986 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
987 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
988 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
990 # Don't return to the main page if the user can't read it
991 # otherwise we'll end up in a pointless loop
992 $mainPage = Title
::newMainPage();
993 if( $mainPage->userCanRead() )
994 $this->returnToMain( true, $mainPage );
998 public function databaseError( $fname, $sql, $error, $errno ) {
999 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1003 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
1004 * @return string The wikitext error-messages, formatted into a list.
1006 public function formatPermissionsErrorMessage( $errors ) {
1007 $text = wfMsgExt( 'permissionserrorstext', array( 'parsemag' ), count( $errors ) ) . "\n\n";
1009 if (count( $errors ) > 1) {
1010 $text .= '<ul class="permissions-errors">' . "\n";
1012 foreach( $errors as $error )
1015 $text .= call_user_func_array( 'wfMsg', $error );
1020 $text .= '<div class="permissions-errors">' . call_user_func_array( 'wfMsg', $errors[0]) . '</div>';
1027 * Display a page stating that the Wiki is in read-only mode,
1028 * and optionally show the source of the page that the user
1029 * was trying to edit. Should only be called (for this
1030 * purpose) after wfReadOnly() has returned true.
1032 * For historical reasons, this function is _also_ used to
1033 * show the error message when a user tries to edit a page
1034 * they are not allowed to edit. (Unless it's because they're
1035 * blocked, then we show blockedPage() instead.) In this
1036 * case, the second parameter should be set to true and a list
1037 * of reasons supplied as the third parameter.
1039 * @todo Needs to be split into multiple functions.
1041 * @param string $source Source code to show (or null).
1042 * @param bool $protected Is this a permissions error?
1043 * @param array $reasons List of reasons for this error, as returned by Title::getUserPermissionsErrors().
1045 public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
1046 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
1047 $skin = $wgUser->getSkin();
1049 $this->setRobotpolicy( 'noindex,nofollow' );
1050 $this->setArticleRelated( false );
1052 // If no reason is given, just supply a default "I can't let you do
1053 // that, Dave" message. Should only occur if called by legacy code.
1054 if ( $protected && empty($reasons) ) {
1055 $reasons[] = array( 'badaccess-group0' );
1058 if ( !empty($reasons) ) {
1059 // Permissions error
1061 $this->setPageTitle( wfMsg( 'viewsource' ) );
1062 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1064 $this->setPageTitle( wfMsg( 'badaccess' ) );
1066 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) );
1068 // Wiki is read only
1069 $this->setPageTitle( wfMsg( 'readonly' ) );
1070 if ( $wgReadOnly ) {
1071 $reason = $wgReadOnly;
1073 // Should not happen, user should have called wfReadOnly() first
1074 $reason = file_get_contents( $wgReadOnlyFile );
1076 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
1079 // Show source, if supplied
1080 if( is_string( $source ) ) {
1081 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
1082 $text = wfOpenElement( 'textarea',
1083 array( 'id' => 'wpTextbox1',
1084 'name' => 'wpTextbox1',
1085 'cols' => $wgUser->getOption( 'cols' ),
1086 'rows' => $wgUser->getOption( 'rows' ),
1087 'readonly' => 'readonly' ) );
1088 $text .= htmlspecialchars( $source );
1089 $text .= wfCloseElement( 'textarea' );
1090 $this->addHTML( $text );
1092 // Show templates used by this article
1093 $skin = $wgUser->getSkin();
1094 $article = new Article( $wgTitle );
1095 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1098 # If the title doesn't exist, it's fairly pointless to print a return
1099 # link to it. After all, you just tried editing it and couldn't, so
1100 # what's there to do there?
1101 if( $wgTitle->exists() ) {
1102 $this->returnToMain( false, $wgTitle );
1107 public function fatalError( $message ) {
1108 throw new FatalError( $message );
1112 public function unexpectedValueError( $name, $val ) {
1113 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1117 public function fileCopyError( $old, $new ) {
1118 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1122 public function fileRenameError( $old, $new ) {
1123 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1127 public function fileDeleteError( $name ) {
1128 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1132 public function fileNotFoundError( $name ) {
1133 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1136 public function showFatalError( $message ) {
1137 $this->setPageTitle( wfMsg( "internalerror" ) );
1138 $this->setRobotpolicy( "noindex,nofollow" );
1139 $this->setArticleRelated( false );
1140 $this->enableClientCache( false );
1141 $this->mRedirect
= '';
1142 $this->mBodytext
= $message;
1145 public function showUnexpectedValueError( $name, $val ) {
1146 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1149 public function showFileCopyError( $old, $new ) {
1150 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1153 public function showFileRenameError( $old, $new ) {
1154 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1157 public function showFileDeleteError( $name ) {
1158 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1161 public function showFileNotFoundError( $name ) {
1162 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1166 * Add a "return to" link pointing to a specified title
1168 * @param Title $title Title to link
1170 public function addReturnTo( $title ) {
1172 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1173 $this->addHtml( "<p>{$link}</p>\n" );
1177 * Add a "return to" link pointing to a specified title,
1178 * or the title indicated in the request, or else the main page
1180 * @param null $unused No longer used
1181 * @param Title $returnto Title to return to
1183 public function returnToMain( $unused = null, $returnto = NULL ) {
1186 if ( $returnto == NULL ) {
1187 $returnto = $wgRequest->getText( 'returnto' );
1190 if ( '' === $returnto ) {
1191 $returnto = Title
::newMainPage();
1194 if ( is_object( $returnto ) ) {
1195 $titleObj = $returnto;
1197 $titleObj = Title
::newFromText( $returnto );
1199 if ( !is_object( $titleObj ) ) {
1200 $titleObj = Title
::newMainPage();
1203 $this->addReturnTo( $titleObj );
1207 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1208 * and uses the first 10 of them for META keywords
1210 * @param ParserOutput &$parserOutput
1212 private function addKeywords( &$parserOutput ) {
1214 $this->addKeyword( $wgTitle->getPrefixedText() );
1216 $links2d =& $parserOutput->getLinks();
1217 if ( !is_array( $links2d ) ) {
1220 foreach ( $links2d as $dbkeys ) {
1221 foreach( $dbkeys as $dbkey => $unused ) {
1222 $this->addKeyword( $dbkey );
1223 if ( ++
$count > 10 ) {
1231 * @return string The doctype, opening <html>, and head element.
1233 public function headElement() {
1234 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1235 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1236 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1238 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1239 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1244 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1246 if ( '' == $this->getHTMLTitle() ) {
1247 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1250 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1251 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1252 foreach($wgXhtmlNamespaces as $tag => $ns) {
1253 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1255 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1256 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1257 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1259 $ret .= $this->getHeadLinks();
1260 global $wgStylePath;
1261 if( $this->isPrintable() ) {
1264 $media = "media='print'";
1266 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1267 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1269 $sk = $wgUser->getSkin();
1270 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1271 $ret .= $this->mScripts
;
1272 $ret .= $sk->getUserStyles();
1273 $ret .= $this->getHeadItems();
1275 if ($wgUseTrackbacks && $this->isArticleRelated())
1276 $ret .= $wgTitle->trackbackRDF();
1278 $ret .= "</head>\n";
1283 * @return string HTML tag links to be put in the header.
1285 public function getHeadLinks() {
1288 foreach ( $this->mMetatags
as $tag ) {
1289 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1291 $tag[0] = substr( $tag[0], 5 );
1295 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1298 $p = $this->mRobotpolicy
;
1299 if( $p !== '' && $p != 'index,follow' ) {
1300 // http://www.robotstxt.org/wc/meta-user.html
1301 // Only show if it's different from the default robots policy
1302 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1305 if ( count( $this->mKeywords
) > 0 ) {
1310 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1311 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1313 foreach ( $this->mLinktags
as $tag ) {
1314 $ret .= "\t\t<link";
1315 foreach( $tag as $attr => $val ) {
1316 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1321 foreach( $this->getSyndicationLinks() as $format => $link ) {
1322 # Use the page name for the title (accessed through $wgTitle since
1323 # there's no other way). In principle, this could lead to issues
1324 # with having the same name for different feeds corresponding to
1325 # the same page, but we can't avoid that at this low a level.
1328 $ret .= $this->feedLink(
1331 wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) ); # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
1334 # Recent changes feed should appear on every page
1335 # Put it after the per-page feed to avoid changing existing behavior.
1336 # It's still available, probably via a menu in your browser.
1338 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
1339 $ret .= $this->feedLink(
1341 $rctitle->getFullURL( 'feed=rss' ),
1342 wfMsg( 'site-rss-feed', $wgSitename ) );
1343 $ret .= $this->feedLink(
1345 $rctitle->getFullURL( 'feed=atom' ),
1346 wfMsg( 'site-atom-feed', $wgSitename ) );
1352 * Return URLs for each supported syndication format for this page.
1353 * @return array associating format keys with URLs
1355 public function getSyndicationLinks() {
1356 global $wgTitle, $wgFeedClasses;
1359 if( $this->isSyndicated() ) {
1360 if( is_string( $this->getFeedAppendQuery() ) ) {
1361 $appendQuery = "&" . $this->getFeedAppendQuery();
1366 foreach( $wgFeedClasses as $format => $class ) {
1367 $links[$format] = $wgTitle->getLocalUrl( "feed=$format{$appendQuery}" );
1374 * Generate a <link rel/> for an RSS feed.
1376 private function feedLink( $type, $url, $text ) {
1377 return Xml
::element( 'link', array(
1378 'rel' => 'alternate',
1379 'type' => "application/$type+xml",
1381 'href' => $url ) ) . "\n";
1385 * Turn off regular page output and return an error reponse
1386 * for when rate limiting has triggered.
1388 public function rateLimited() {
1389 global $wgOut, $wgTitle;
1391 $this->setPageTitle(wfMsg('actionthrottled'));
1392 $this->setRobotPolicy( 'noindex,follow' );
1393 $this->setArticleRelated( false );
1394 $this->enableClientCache( false );
1395 $this->mRedirect
= '';
1397 $this->setStatusCode(503);
1398 $this->addWikiText( wfMsg('actionthrottledtext') );
1400 $this->returnToMain( false, $wgTitle );
1404 * Show an "add new section" link?
1408 public function showNewSectionLink() {
1409 return $this->mNewSectionLink
;
1413 * Show a warning about slave lag
1415 * If the lag is higher than $wgSlaveLagCritical seconds,
1416 * then the warning is a bit more obvious. If the lag is
1417 * lower than $wgSlaveLagWarning, then no warning is shown.
1419 * @param int $lag Slave lag
1421 public function showLagWarning( $lag ) {
1422 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1423 if( $lag >= $wgSlaveLagWarning ) {
1424 $message = $lag < $wgSlaveLagCritical
1427 $warning = wfMsgExt( $message, 'parse', $lag );
1428 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );