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;
18 var $mSuppressQuickbar;
21 var $mContainsOldMagic, $mContainsNewMagic;
22 var $mIsArticleRelated;
23 protected $mParserOptions; // lazy initialised, use parserOptions()
24 var $mShowFeedLinks = false;
25 var $mEnableClientCache = true;
26 var $mArticleBodyOnly = false;
28 var $mNewSectionLink = false;
29 var $mNoGallery = false;
33 * Initialise private variables
35 function __construct() {
36 $this->mMetatags
= $this->mKeywords
= $this->mLinktags
= array();
37 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
38 $this->mRedirect
= $this->mLastModified
=
39 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
40 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
41 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
42 $this->mSuppressQuickbar
= $this->mPrintable
= false;
43 $this->mLanguageLinks
= array();
44 $this->mCategoryLinks
= array();
45 $this->mDoNothing
= false;
46 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
47 $this->mParserOptions
= null;
48 $this->mSquidMaxage
= 0;
50 $this->mHeadItems
= array();
52 $this->mRevisionId
= null;
53 $this->mNewSectionLink
= false;
56 public function redirect( $url, $responsecode = '302' ) {
57 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
58 $this->mRedirect
= str_replace( "\n", '', $url );
59 $this->mRedirectCode
= $responsecode;
63 * Set the HTTP status code to send with the output.
65 * @param int $statusCode
68 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
70 # To add an http-equiv meta tag, precede the name with "http:"
71 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
72 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
73 function addScript( $script ) { $this->mScripts
.= "\t\t".$script; }
76 * Add a self-contained script tag with the given contents
77 * @param string $script JavaScript text, no <script> tags
79 function addInlineScript( $script ) {
81 $this->mScripts
.= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
84 function getScript() {
85 return $this->mScripts
. $this->getHeadItems();
88 function getHeadItems() {
90 foreach ( $this->mHeadItems
as $item ) {
96 function addHeadItem( $name, $value ) {
97 $this->mHeadItems
[$name] = $value;
100 function setETag($tag) { $this->mETag
= $tag; }
101 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
102 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
104 function addLink( $linkarr ) {
105 # $linkarr should be an associative array of attributes. We'll escape on output.
106 array_push( $this->mLinktags
, $linkarr );
109 function addMetadataLink( $linkarr ) {
110 # note: buggy CC software only reads first "meta" link
111 static $haveMeta = false;
112 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
113 $this->addLink( $linkarr );
118 * checkLastModified tells the client to use the client-cached page if
119 * possible. If sucessful, the OutputPage is disabled so that
120 * any future call to OutputPage->output() have no effect.
122 * @return bool True iff cache-ok headers was sent.
124 function checkLastModified ( $timestamp ) {
125 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
126 $fname = 'OutputPage::checkLastModified';
128 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
129 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
132 if( !$wgCachePages ) {
133 wfDebug( "$fname: CACHE DISABLED\n", false );
136 if( $wgUser->getOption( 'nocache' ) ) {
137 wfDebug( "$fname: USER DISABLED CACHE\n", false );
141 $timestamp=wfTimestamp(TS_MW
,$timestamp);
142 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
144 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
145 # IE sends sizes after the date like this:
146 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
147 # this breaks strtotime().
148 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
149 $modsinceTime = strtotime( $modsince );
150 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
151 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
152 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
153 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
154 # Make sure you're in a place you can leave when you call us!
155 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
156 $this->mLastModified
= $lastmod;
157 $this->sendCacheControl();
158 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
161 // Don't output a compressed blob when using ob_gzhandler;
162 // it's technically against HTTP spec and seems to confuse
163 // Firefox when the response gets split over two packets.
164 wfClearOutputBuffers();
168 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
169 $this->mLastModified
= $lastmod;
172 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
173 $this->mLastModified
= $lastmod;
177 function getPageTitleActionText () {
186 // Display title is already customized
189 return wfMsg('history_short');
191 // FIXME: bug 2735; not correct for special pages etc
192 return wfMsg('preview');
194 return wfMsg('info_short');
200 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
201 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
202 public function setPageTitle( $name ) {
203 global $action, $wgContLang;
204 $name = $wgContLang->convert($name, true);
205 $this->mPagetitle
= $name;
206 if(!empty($action)) {
207 $taction = $this->getPageTitleActionText();
208 if( !empty( $taction ) ) {
209 $name .= ' - '.$taction;
213 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
215 public function getHTMLTitle() { return $this->mHTMLtitle
; }
216 public function getPageTitle() { return $this->mPagetitle
; }
217 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
218 public function getSubtitle() { return $this->mSubtitle
; }
219 public function isArticle() { return $this->mIsarticle
; }
220 public function setPrintable() { $this->mPrintable
= true; }
221 public function isPrintable() { return $this->mPrintable
; }
222 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
223 public function isSyndicated() { return $this->mShowFeedLinks
; }
224 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
225 public function getOnloadHandler() { return $this->mOnloadHandler
; }
226 public function disable() { $this->mDoNothing
= true; }
228 public function setArticleRelated( $v ) {
229 $this->mIsArticleRelated
= $v;
231 $this->mIsarticle
= false;
234 public function setArticleFlag( $v ) {
235 $this->mIsarticle
= $v;
237 $this->mIsArticleRelated
= $v;
241 public function isArticleRelated() { return $this->mIsArticleRelated
; }
243 public function getLanguageLinks() { return $this->mLanguageLinks
; }
244 public function addLanguageLinks($newLinkArray) {
245 $this->mLanguageLinks +
= $newLinkArray;
247 public function setLanguageLinks($newLinkArray) {
248 $this->mLanguageLinks
= $newLinkArray;
251 public function getCategoryLinks() {
252 return $this->mCategoryLinks
;
256 * Add an array of categories, with names in the keys
258 public function addCategoryLinks($categories) {
259 global $wgUser, $wgContLang;
261 if ( !is_array( $categories ) ) {
264 # Add the links to the link cache in a batch
265 $arr = array( NS_CATEGORY
=> $categories );
267 $lb->setArray( $arr );
270 $sk = $wgUser->getSkin();
271 foreach ( $categories as $category => $unused ) {
272 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
273 $text = $wgContLang->convertHtml( $title->getText() );
274 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
278 public function setCategoryLinks($categories) {
279 $this->mCategoryLinks
= array();
280 $this->addCategoryLinks($categories);
283 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
284 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
286 public function addHTML( $text ) { $this->mBodytext
.= $text; }
287 public function clearHTML() { $this->mBodytext
= ''; }
288 public function getHTML() { return $this->mBodytext
; }
289 public function debug( $text ) { $this->mDebugtext
.= $text; }
292 public function setParserOptions( $options ) {
293 return $this->parserOptions( $options );
296 public function parserOptions( $options = null ) {
297 if ( !$this->mParserOptions
) {
298 $this->mParserOptions
= new ParserOptions
;
300 return wfSetVar( $this->mParserOptions
, $options );
304 * Set the revision ID which will be seen by the wiki text parser
305 * for things such as embedded {{REVISIONID}} variable use.
306 * @param mixed $revid an integer, or NULL
307 * @return mixed previous value
309 public function setRevisionId( $revid ) {
310 $val = is_null( $revid ) ?
null : intval( $revid );
311 return wfSetVar( $this->mRevisionId
, $val );
315 * Convert wikitext to HTML and add it to the buffer
316 * Default assumes that the current page title will
319 * @param string $text
320 * @param bool $linestart
322 public function addWikiText( $text, $linestart = true ) {
324 $this->addWikiTextTitle($text, $wgTitle, $linestart);
327 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
328 $this->addWikiTextTitle($text, $title, $linestart);
331 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
332 $this->addWikiTextTitle( $text, $title, $linestart, true );
335 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
338 $fname = 'OutputPage:addWikiTextTitle';
341 wfIncrStats('pcache_not_possible');
343 $popts = $this->parserOptions();
344 $popts->setTidy($tidy);
346 $parserOutput = $wgParser->parse( $text, $title, $popts,
347 $linestart, true, $this->mRevisionId
);
349 $this->addParserOutput( $parserOutput );
351 wfProfileOut($fname);
356 * @param ParserOutput object &$parserOutput
358 public function addParserOutputNoText( &$parserOutput ) {
359 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
360 $this->addCategoryLinks( $parserOutput->getCategories() );
361 $this->mNewSectionLink
= $parserOutput->getNewSection();
362 $this->addKeywords( $parserOutput );
363 if ( $parserOutput->getCacheTime() == -1 ) {
364 $this->enableClientCache( false );
366 if ( $parserOutput->mHTMLtitle
!= "" ) {
367 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
369 if ( $parserOutput->mSubtitle
!= '' ) {
370 $this->mSubtitle
.= $parserOutput->mSubtitle
;
372 $this->mNoGallery
= $parserOutput->getNoGallery();
373 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
374 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
379 * @param ParserOutput &$parserOutput
381 function addParserOutput( &$parserOutput ) {
382 $this->addParserOutputNoText( $parserOutput );
383 $text = $parserOutput->getText();
384 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
385 $this->addHTML( $text );
389 * Add wikitext to the buffer, assuming that this is the primary text for a page view
390 * Saves the text into the parser cache if possible.
392 * @param string $text
393 * @param Article $article
395 * @deprecated Use Article::outputWikitext
397 public function addPrimaryWikiText( $text, $article, $cache = true ) {
398 global $wgParser, $wgUser;
400 $popts = $this->parserOptions();
401 $popts->setTidy(true);
402 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
403 $popts, true, true, $this->mRevisionId
);
404 $popts->setTidy(false);
405 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
406 $parserCache =& ParserCache
::singleton();
407 $parserCache->save( $parserOutput, $article, $wgUser );
410 $this->addParserOutput( $parserOutput );
414 * @deprecated use addWikiTextTidy()
416 public function addSecondaryWikiText( $text, $linestart = true ) {
418 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
422 * Add wikitext with tidy enabled
424 public function addWikiTextTidy( $text, $linestart = true ) {
426 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
431 * Add the output of a QuickTemplate to the output buffer
433 * @param QuickTemplate $template
435 public function addTemplate( &$template ) {
437 $template->execute();
438 $this->addHTML( ob_get_contents() );
443 * Parse wikitext and return the HTML.
445 * @param string $text
446 * @param bool $linestart Is this the start of a line?
447 * @param bool $interface ??
449 public function parse( $text, $linestart = true, $interface = false ) {
450 global $wgParser, $wgTitle;
451 $popts = $this->parserOptions();
452 if ( $interface) { $popts->setInterfaceMessage(true); }
453 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
454 $linestart, true, $this->mRevisionId
);
455 if ( $interface) { $popts->setInterfaceMessage(false); }
456 return $parserOutput->getText();
460 * @param Article $article
463 * @return bool True if successful, else false.
465 public function tryParserCache( &$article, $user ) {
466 $parserCache =& ParserCache
::singleton();
467 $parserOutput = $parserCache->get( $article, $user );
468 if ( $parserOutput !== false ) {
469 $this->addParserOutput( $parserOutput );
477 * @param int $maxage Maximum cache time on the Squid, in seconds.
479 public function setSquidMaxage( $maxage ) {
480 $this->mSquidMaxage
= $maxage;
484 * Use enableClientCache(false) to force it to send nocache headers
487 public function enableClientCache( $state ) {
488 return wfSetVar( $this->mEnableClientCache
, $state );
491 function uncacheableBecauseRequestvars() {
493 return $wgRequest->getText('useskin', false) === false
494 && $wgRequest->getText('uselang', false) === false;
497 public function sendCacheControl() {
498 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
499 $fname = 'OutputPage::sendCacheControl';
501 if ($wgUseETag && $this->mETag
)
502 $wgRequest->response()->header("ETag: $this->mETag");
504 # don't serve compressed data to clients who can't handle it
505 # maintain different caches for logged-in users and non-logged in ones
506 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
507 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
508 if( $wgUseSquid && session_id() == '' &&
509 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
512 # We'll purge the proxy cache explicitly, but require end user agents
513 # to revalidate against the proxy on each visit.
514 # Surrogate-Control controls our Squid, Cache-Control downstream caches
515 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
516 # start with a shorter timeout for initial testing
517 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
518 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
519 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
521 # We'll purge the proxy cache for anons explicitly, but require end user agents
522 # to revalidate against the proxy on each visit.
523 # IMPORTANT! The Squid needs to replace the Cache-Control header with
524 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
525 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
526 # start with a shorter timeout for initial testing
527 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
528 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
531 # We do want clients to cache if they can, but they *must* check for updates
532 # on revisiting the page.
533 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
534 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
535 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
537 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
539 wfDebug( "$fname: no caching **\n", false );
541 # In general, the absence of a last modified header should be enough to prevent
542 # the client from using its cache. We send a few other things just to make sure.
543 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
544 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
545 $wgRequest->response()->header( 'Pragma: no-cache' );
550 * Finally, all the text has been munged and accumulated into
551 * the object, let's actually output it:
553 public function output() {
554 global $wgUser, $wgOutputEncoding, $wgRequest;
555 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
556 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
557 global $wgServer, $wgStyleVersion;
559 if( $this->mDoNothing
){
562 $fname = 'OutputPage::output';
563 wfProfileIn( $fname );
564 $sk = $wgUser->getSkin();
567 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
569 wfRunHooks( 'AjaxAddScript', array( &$this ) );
571 if( $wgAjaxSearch ) {
572 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
573 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
576 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
577 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
581 if ( '' != $this->mRedirect
) {
582 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
583 # Standards require redirect URLs to be absolute
585 $this->mRedirect
= $wgServer . $this->mRedirect
;
587 if( $this->mRedirectCode
== '301') {
588 if( !$wgDebugRedirects ) {
589 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
591 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
594 $this->sendCacheControl();
596 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
597 if( $wgDebugRedirects ) {
598 $url = htmlspecialchars( $this->mRedirect
);
599 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
600 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
601 print "</body>\n</html>\n";
603 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
605 wfProfileOut( $fname );
608 elseif ( $this->mStatusCode
)
610 $statusMessage = array(
612 101 => 'Switching Protocols',
617 203 => 'Non-Authoritative Information',
619 205 => 'Reset Content',
620 206 => 'Partial Content',
621 207 => 'Multi-Status',
622 300 => 'Multiple Choices',
623 301 => 'Moved Permanently',
626 304 => 'Not Modified',
628 307 => 'Temporary Redirect',
629 400 => 'Bad Request',
630 401 => 'Unauthorized',
631 402 => 'Payment Required',
634 405 => 'Method Not Allowed',
635 406 => 'Not Acceptable',
636 407 => 'Proxy Authentication Required',
637 408 => 'Request Timeout',
640 411 => 'Length Required',
641 412 => 'Precondition Failed',
642 413 => 'Request Entity Too Large',
643 414 => 'Request-URI Too Large',
644 415 => 'Unsupported Media Type',
645 416 => 'Request Range Not Satisfiable',
646 417 => 'Expectation Failed',
647 422 => 'Unprocessable Entity',
649 424 => 'Failed Dependency',
650 500 => 'Internal Server Error',
651 501 => 'Not Implemented',
652 502 => 'Bad Gateway',
653 503 => 'Service Unavailable',
654 504 => 'Gateway Timeout',
655 505 => 'HTTP Version Not Supported',
656 507 => 'Insufficient Storage'
659 if ( $statusMessage[$this->mStatusCode
] )
660 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
663 # Buffer output; final headers may depend on later processing
666 # Disable temporary placeholders, so that the skin produces HTML
667 $sk->postParseLinkColour( false );
669 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
670 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
672 if ($this->mArticleBodyOnly
) {
673 $this->out($this->mBodytext
);
675 wfProfileIn( 'Output-skin' );
676 $sk->outputPage( $this );
677 wfProfileOut( 'Output-skin' );
680 $this->sendCacheControl();
682 wfProfileOut( $fname );
689 public function out( $ins ) {
690 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
691 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
694 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
695 if ( false === $outs ) { $outs = $ins; }
703 public static function setEncodings() {
704 global $wgInputEncoding, $wgOutputEncoding;
705 global $wgUser, $wgContLang;
707 $wgInputEncoding = strtolower( $wgInputEncoding );
709 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
710 $wgOutputEncoding = strtolower( $wgOutputEncoding );
713 $wgOutputEncoding = $wgInputEncoding;
717 * Deprecated, use wfReportTime() instead.
721 public function reportTime() {
722 $time = wfReportTime();
727 * Produce a "user is blocked" page.
729 * @param bool $return Whether to have a "return to $wgTitle" message or not.
732 function blockedPage( $return = true ) {
733 global $wgUser, $wgContLang, $wgTitle, $wgLang;
735 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
736 $this->setRobotpolicy( 'noindex,nofollow' );
737 $this->setArticleRelated( false );
739 $id = $wgUser->blockedBy();
740 $reason = $wgUser->blockedFor();
743 if ( is_numeric( $id ) ) {
744 $name = User
::whoIs( $id );
748 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
750 $blockid = $wgUser->mBlock
->mId
;
752 $blockExpiry = $wgUser->mBlock
->mExpiry
;
753 if ( $blockExpiry == 'infinity' ) {
754 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
755 // Search for localization in 'ipboptions'
756 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
757 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
758 if ( strpos( $option, ":" ) === false )
760 list( $show, $value ) = explode( ":", $option );
761 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
762 $blockExpiry = $show;
767 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
770 if ( $wgUser->mBlock
->mAuto
) {
771 $msg = 'autoblockedtext';
773 $msg = 'blockedtext';
776 $this->addWikiText( wfMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry ) );
778 # Don't auto-return to special pages
780 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
781 $this->returnToMain( false, $return );
786 * Outputs a pretty page to explain why the request exploded.
788 * @param string $title Message key for page title.
789 * @param string $msg Message key for page text.
792 public function showErrorPage( $title, $msg ) {
795 $this->mDebugtext
.= 'Original title: ' .
796 $wgTitle->getPrefixedText() . "\n";
797 $this->setPageTitle( wfMsg( $title ) );
798 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
799 $this->setRobotpolicy( 'noindex,nofollow' );
800 $this->setArticleRelated( false );
801 $this->enableClientCache( false );
802 $this->mRedirect
= '';
804 $this->mBodytext
= '';
805 $this->addWikiText( wfMsg( $msg ) );
806 $this->returnToMain( false );
810 public function errorpage( $title, $msg ) {
811 throw new ErrorPageError( $title, $msg );
815 * Display an error page indicating that a given version of MediaWiki is
818 * @param mixed $version The version of MediaWiki needed to use the page
820 public function versionRequired( $version ) {
821 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
822 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
823 $this->setRobotpolicy( 'noindex,nofollow' );
824 $this->setArticleRelated( false );
825 $this->mBodytext
= '';
827 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
828 $this->returnToMain();
832 * Display an error page noting that a given permission bit is required.
834 * @param string $permission key required
836 public function permissionRequired( $permission ) {
837 global $wgGroupPermissions, $wgUser;
839 $this->setPageTitle( wfMsg( 'badaccess' ) );
840 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
841 $this->setRobotpolicy( 'noindex,nofollow' );
842 $this->setArticleRelated( false );
843 $this->mBodytext
= '';
846 foreach( $wgGroupPermissions as $key => $value ) {
847 if( isset( $value[$permission] ) && $value[$permission] == true ) {
848 $groupName = User
::getGroupName( $key );
849 $groupPage = User
::getGroupPage( $key );
851 $skin = $wgUser->getSkin();
852 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
854 $groups[] = $groupName;
858 $n = count( $groups );
859 $groups = implode( ', ', $groups );
864 $message = wfMsgHtml( "badaccess-group$n", $groups );
867 $message = wfMsgHtml( 'badaccess-groups', $groups );
869 $this->addHtml( $message );
870 $this->returnToMain( false );
874 * Use permissionRequired.
877 public function sysopRequired() {
878 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
882 * Use permissionRequired.
885 public function developerRequired() {
886 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
890 * Produce the stock "please login to use the wiki" page
892 public function loginToUse() {
893 global $wgUser, $wgTitle, $wgContLang;
895 if( $wgUser->isLoggedIn() ) {
896 $this->permissionRequired( 'read' );
900 $skin = $wgUser->getSkin();
902 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
903 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
904 $this->setRobotPolicy( 'noindex,nofollow' );
905 $this->setArticleFlag( false );
907 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
908 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
909 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
910 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
912 # Don't return to the main page if the user can't read it
913 # otherwise we'll end up in a pointless loop
914 $mainPage = Title
::newMainPage();
915 if( $mainPage->userCanRead() )
916 $this->returnToMain( true, $mainPage );
920 public function databaseError( $fname, $sql, $error, $errno ) {
921 throw new MWException( "OutputPage::databaseError is obsolete\n" );
926 * @param bool $protected Is the reason the page can't be reached because it's protected?
927 * @param mixed $source
929 public function readOnlyPage( $source = null, $protected = false ) {
930 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
931 $skin = $wgUser->getSkin();
933 $this->setRobotpolicy( 'noindex,nofollow' );
934 $this->setArticleRelated( false );
937 $this->setPageTitle( wfMsg( 'viewsource' ) );
938 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
940 list( $cascadeSources, $restrictions ) = $wgTitle->getCascadeProtectionSources();
942 # Determine if protection is due to the page being a system message
943 # and show an appropriate explanation
944 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
945 $this->addWikiText( wfMsg( 'protectedinterface' ) );
946 } if ( $cascadeSources && count($cascadeSources) > 0 ) {
949 foreach ( $cascadeSources as $title ) {
950 $titles .= '* [[:' . $title->getPrefixedText() . "]]\n";
953 $notice = wfMsgExt( 'cascadeprotected', array('parsemag'), count($cascadeSources) ) . "\n$titles";
955 $this->addWikiText( $notice );
957 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
960 $this->setPageTitle( wfMsg( 'readonly' ) );
962 $reason = $wgReadOnly;
964 $reason = file_get_contents( $wgReadOnlyFile );
966 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
969 if( is_string( $source ) ) {
970 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
971 $rows = $wgUser->getIntOption( 'rows' );
972 $cols = $wgUser->getIntOption( 'cols' );
973 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
974 htmlspecialchars( $source ) . "\n</textarea>";
975 $this->addHTML( $text );
977 $article = new Article($wgTitle);
978 $this->addHTML( $skin->formatTemplates($article->getUsedTemplates()) );
980 $this->returnToMain( false );
984 public function fatalError( $message ) {
985 throw new FatalError( $message );
989 public function unexpectedValueError( $name, $val ) {
990 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
994 public function fileCopyError( $old, $new ) {
995 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
999 public function fileRenameError( $old, $new ) {
1000 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1004 public function fileDeleteError( $name ) {
1005 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1009 public function fileNotFoundError( $name ) {
1010 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1013 public function showFatalError( $message ) {
1014 $this->setPageTitle( wfMsg( "internalerror" ) );
1015 $this->setRobotpolicy( "noindex,nofollow" );
1016 $this->setArticleRelated( false );
1017 $this->enableClientCache( false );
1018 $this->mRedirect
= '';
1019 $this->mBodytext
= $message;
1022 public function showUnexpectedValueError( $name, $val ) {
1023 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1026 public function showFileCopyError( $old, $new ) {
1027 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1030 public function showFileRenameError( $old, $new ) {
1031 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1034 public function showFileDeleteError( $name ) {
1035 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1038 public function showFileNotFoundError( $name ) {
1039 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1043 * return from error messages or notes
1044 * @param $auto automatically redirect the user after 10 seconds
1045 * @param $returnto page title to return to. Default is Main Page.
1047 public function returnToMain( $auto = true, $returnto = NULL ) {
1048 global $wgUser, $wgOut, $wgRequest;
1050 if ( $returnto == NULL ) {
1051 $returnto = $wgRequest->getText( 'returnto' );
1054 if ( '' === $returnto ) {
1055 $returnto = Title
::newMainPage();
1058 if ( is_object( $returnto ) ) {
1059 $titleObj = $returnto;
1061 $titleObj = Title
::newFromText( $returnto );
1063 if ( !is_object( $titleObj ) ) {
1064 $titleObj = Title
::newMainPage();
1067 $sk = $wgUser->getSkin();
1068 $link = $sk->makeLinkObj( $titleObj, '' );
1070 $r = wfMsg( 'returnto', $link );
1072 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
1074 $wgOut->addHTML( "\n<p>$r</p>\n" );
1078 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1079 * and uses the first 10 of them for META keywords
1081 * @param ParserOutput &$parserOutput
1083 private function addKeywords( &$parserOutput ) {
1085 $this->addKeyword( $wgTitle->getPrefixedText() );
1087 $links2d =& $parserOutput->getLinks();
1088 if ( !is_array( $links2d ) ) {
1091 foreach ( $links2d as $dbkeys ) {
1092 foreach( $dbkeys as $dbkey => $unused ) {
1093 $this->addKeyword( $dbkey );
1094 if ( ++
$count > 10 ) {
1102 * @return string The doctype, opening <html>, and head element.
1104 public function headElement() {
1105 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1106 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1107 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1109 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1110 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1115 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1117 if ( '' == $this->getHTMLTitle() ) {
1118 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1121 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1122 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1123 foreach($wgXhtmlNamespaces as $tag => $ns) {
1124 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1126 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1127 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1128 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1130 $ret .= $this->getHeadLinks();
1131 global $wgStylePath;
1132 if( $this->isPrintable() ) {
1135 $media = "media='print'";
1137 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1138 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1140 $sk = $wgUser->getSkin();
1141 $ret .= $sk->getHeadScripts();
1142 $ret .= $this->mScripts
;
1143 $ret .= $sk->getUserStyles();
1144 $ret .= $this->getHeadItems();
1146 if ($wgUseTrackbacks && $this->isArticleRelated())
1147 $ret .= $wgTitle->trackbackRDF();
1149 $ret .= "</head>\n";
1154 * @return string HTML tag links to be put in the header.
1156 public function getHeadLinks() {
1159 foreach ( $this->mMetatags
as $tag ) {
1160 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1162 $tag[0] = substr( $tag[0], 5 );
1166 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1169 $p = $this->mRobotpolicy
;
1170 if( $p !== '' && $p != 'index,follow' ) {
1171 // http://www.robotstxt.org/wc/meta-user.html
1172 // Only show if it's different from the default robots policy
1173 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1176 if ( count( $this->mKeywords
) > 0 ) {
1181 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1182 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1184 foreach ( $this->mLinktags
as $tag ) {
1185 $ret .= "\t\t<link";
1186 foreach( $tag as $attr => $val ) {
1187 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1191 if( $this->isSyndicated() ) {
1192 # FIXME: centralize the mime-type and name information in Feed.php
1193 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1194 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1195 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1196 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 1.0' href='$link' />\n";
1203 * Turn off regular page output and return an error reponse
1204 * for when rate limiting has triggered.
1207 public function rateLimited() {
1210 wfHttpError( 500, 'Internal Server Error',
1211 'Sorry, the server has encountered an internal error. ' .
1212 'Please wait a moment and hit "refresh" to submit the request again.' );
1216 * Show an "add new section" link?
1218 * @return bool True if the parser output instructs us to add one
1220 public function showNewSectionLink() {
1221 return $this->mNewSectionLink
;