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 ) {
97 function setETag($tag) { $this->mETag
= $tag; }
98 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
99 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
101 function addLink( $linkarr ) {
102 # $linkarr should be an associative array of attributes. We'll escape on output.
103 array_push( $this->mLinktags
, $linkarr );
106 function addMetadataLink( $linkarr ) {
107 # note: buggy CC software only reads first "meta" link
108 static $haveMeta = false;
109 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
110 $this->addLink( $linkarr );
115 * checkLastModified tells the client to use the client-cached page if
116 * possible. If sucessful, the OutputPage is disabled so that
117 * any future call to OutputPage->output() have no effect.
119 * @return bool True iff cache-ok headers was sent.
121 function checkLastModified ( $timestamp ) {
122 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
123 $fname = 'OutputPage::checkLastModified';
125 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
126 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
129 if( !$wgCachePages ) {
130 wfDebug( "$fname: CACHE DISABLED\n", false );
133 if( $wgUser->getOption( 'nocache' ) ) {
134 wfDebug( "$fname: USER DISABLED CACHE\n", false );
138 $timestamp=wfTimestamp(TS_MW
,$timestamp);
139 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
141 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
142 # IE sends sizes after the date like this:
143 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
144 # this breaks strtotime().
145 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
146 $modsinceTime = strtotime( $modsince );
147 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
148 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
149 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
150 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
151 # Make sure you're in a place you can leave when you call us!
152 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
153 $this->mLastModified
= $lastmod;
154 $this->sendCacheControl();
155 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
158 // Don't output a compressed blob when using ob_gzhandler;
159 // it's technically against HTTP spec and seems to confuse
160 // Firefox when the response gets split over two packets.
161 wfClearOutputBuffers();
165 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
166 $this->mLastModified
= $lastmod;
169 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
170 $this->mLastModified
= $lastmod;
174 function getPageTitleActionText () {
183 // Display title is already customized
186 return wfMsg('history_short');
188 // FIXME: bug 2735; not correct for special pages etc
189 return wfMsg('preview');
191 return wfMsg('info_short');
197 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
198 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
199 public function setPageTitle( $name ) {
200 global $action, $wgContLang;
201 $name = $wgContLang->convert($name, true);
202 $this->mPagetitle
= $name;
203 if(!empty($action)) {
204 $taction = $this->getPageTitleActionText();
205 if( !empty( $taction ) ) {
206 $name .= ' - '.$taction;
210 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
212 public function getHTMLTitle() { return $this->mHTMLtitle
; }
213 public function getPageTitle() { return $this->mPagetitle
; }
214 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
215 public function getSubtitle() { return $this->mSubtitle
; }
216 public function isArticle() { return $this->mIsarticle
; }
217 public function setPrintable() { $this->mPrintable
= true; }
218 public function isPrintable() { return $this->mPrintable
; }
219 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
220 public function isSyndicated() { return $this->mShowFeedLinks
; }
221 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
222 public function getOnloadHandler() { return $this->mOnloadHandler
; }
223 public function disable() { $this->mDoNothing
= true; }
225 public function setArticleRelated( $v ) {
226 $this->mIsArticleRelated
= $v;
228 $this->mIsarticle
= false;
231 public function setArticleFlag( $v ) {
232 $this->mIsarticle
= $v;
234 $this->mIsArticleRelated
= $v;
238 public function isArticleRelated() { return $this->mIsArticleRelated
; }
240 public function getLanguageLinks() { return $this->mLanguageLinks
; }
241 public function addLanguageLinks($newLinkArray) {
242 $this->mLanguageLinks +
= $newLinkArray;
244 public function setLanguageLinks($newLinkArray) {
245 $this->mLanguageLinks
= $newLinkArray;
248 public function getCategoryLinks() {
249 return $this->mCategoryLinks
;
253 * Add an array of categories, with names in the keys
255 public function addCategoryLinks($categories) {
256 global $wgUser, $wgContLang;
258 if ( !is_array( $categories ) ) {
261 # Add the links to the link cache in a batch
262 $arr = array( NS_CATEGORY
=> $categories );
264 $lb->setArray( $arr );
267 $sk = $wgUser->getSkin();
268 foreach ( $categories as $category => $unused ) {
269 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
270 $text = $wgContLang->convertHtml( $title->getText() );
271 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
275 public function setCategoryLinks($categories) {
276 $this->mCategoryLinks
= array();
277 $this->addCategoryLinks($categories);
280 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
281 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
283 public function addHTML( $text ) { $this->mBodytext
.= $text; }
284 public function clearHTML() { $this->mBodytext
= ''; }
285 public function getHTML() { return $this->mBodytext
; }
286 public function debug( $text ) { $this->mDebugtext
.= $text; }
289 public function setParserOptions( $options ) {
290 return $this->parserOptions( $options );
293 public function parserOptions( $options = null ) {
294 if ( !$this->mParserOptions
) {
295 $this->mParserOptions
= new ParserOptions
;
297 return wfSetVar( $this->mParserOptions
, $options );
301 * Set the revision ID which will be seen by the wiki text parser
302 * for things such as embedded {{REVISIONID}} variable use.
303 * @param mixed $revid an integer, or NULL
304 * @return mixed previous value
306 public function setRevisionId( $revid ) {
307 $val = is_null( $revid ) ?
null : intval( $revid );
308 return wfSetVar( $this->mRevisionId
, $val );
312 * Convert wikitext to HTML and add it to the buffer
313 * Default assumes that the current page title will
316 * @param string $text
317 * @param bool $linestart
319 public function addWikiText( $text, $linestart = true ) {
321 $this->addWikiTextTitle($text, $wgTitle, $linestart);
324 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
325 $this->addWikiTextTitle($text, $title, $linestart);
328 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
329 $this->addWikiTextTitle( $text, $title, $linestart, true );
332 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
335 $fname = 'OutputPage:addWikiTextTitle';
338 wfIncrStats('pcache_not_possible');
340 $popts = $this->parserOptions();
341 $popts->setTidy($tidy);
343 $parserOutput = $wgParser->parse( $text, $title, $popts,
344 $linestart, true, $this->mRevisionId
);
346 $this->addParserOutput( $parserOutput );
348 wfProfileOut($fname);
353 * @param ParserOutput object &$parserOutput
355 public function addParserOutputNoText( &$parserOutput ) {
356 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
357 $this->addCategoryLinks( $parserOutput->getCategories() );
358 $this->mNewSectionLink
= $parserOutput->getNewSection();
359 $this->addKeywords( $parserOutput );
360 if ( $parserOutput->getCacheTime() == -1 ) {
361 $this->enableClientCache( false );
363 if ( $parserOutput->mHTMLtitle
!= "" ) {
364 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
366 if ( $parserOutput->mSubtitle
!= '' ) {
367 $this->mSubtitle
.= $parserOutput->mSubtitle
;
369 $this->mNoGallery
= $parserOutput->getNoGallery();
370 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
371 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
376 * @param ParserOutput &$parserOutput
378 function addParserOutput( &$parserOutput ) {
379 $this->addParserOutputNoText( $parserOutput );
380 $text = $parserOutput->getText();
381 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
382 $this->addHTML( $text );
386 * Add wikitext to the buffer, assuming that this is the primary text for a page view
387 * Saves the text into the parser cache if possible.
389 * @param string $text
390 * @param Article $article
392 * @deprecated Use Article::outputWikitext
394 public function addPrimaryWikiText( $text, $article, $cache = true ) {
395 global $wgParser, $wgUser;
397 $popts = $this->parserOptions();
398 $popts->setTidy(true);
399 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
400 $popts, true, true, $this->mRevisionId
);
401 $popts->setTidy(false);
402 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
403 $parserCache =& ParserCache
::singleton();
404 $parserCache->save( $parserOutput, $article, $wgUser );
407 $this->addParserOutput( $parserOutput );
411 * @deprecated use addWikiTextTidy()
413 public function addSecondaryWikiText( $text, $linestart = true ) {
415 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
419 * Add wikitext with tidy enabled
421 public function addWikiTextTidy( $text, $linestart = true ) {
423 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
428 * Add the output of a QuickTemplate to the output buffer
430 * @param QuickTemplate $template
432 public function addTemplate( &$template ) {
434 $template->execute();
435 $this->addHTML( ob_get_contents() );
440 * Parse wikitext and return the HTML.
442 * @param string $text
443 * @param bool $linestart Is this the start of a line?
444 * @param bool $interface ??
446 public function parse( $text, $linestart = true, $interface = false ) {
447 global $wgParser, $wgTitle;
448 $popts = $this->parserOptions();
449 if ( $interface) { $popts->setInterfaceMessage(true); }
450 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
451 $linestart, true, $this->mRevisionId
);
452 if ( $interface) { $popts->setInterfaceMessage(false); }
453 return $parserOutput->getText();
457 * @param Article $article
460 * @return bool True if successful, else false.
462 public function tryParserCache( &$article, $user ) {
463 $parserCache =& ParserCache
::singleton();
464 $parserOutput = $parserCache->get( $article, $user );
465 if ( $parserOutput !== false ) {
466 $this->addParserOutput( $parserOutput );
474 * @param int $maxage Maximum cache time on the Squid, in seconds.
476 public function setSquidMaxage( $maxage ) {
477 $this->mSquidMaxage
= $maxage;
481 * Use enableClientCache(false) to force it to send nocache headers
484 public function enableClientCache( $state ) {
485 return wfSetVar( $this->mEnableClientCache
, $state );
488 function uncacheableBecauseRequestvars() {
490 return $wgRequest->getText('useskin', false) === false
491 && $wgRequest->getText('uselang', false) === false;
494 public function sendCacheControl() {
495 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
496 $fname = 'OutputPage::sendCacheControl';
498 if ($wgUseETag && $this->mETag
)
499 $wgRequest->response()->header("ETag: $this->mETag");
501 # don't serve compressed data to clients who can't handle it
502 # maintain different caches for logged-in users and non-logged in ones
503 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
504 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
505 if( $wgUseSquid && session_id() == '' &&
506 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
509 # We'll purge the proxy cache explicitly, but require end user agents
510 # to revalidate against the proxy on each visit.
511 # Surrogate-Control controls our Squid, Cache-Control downstream caches
512 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
513 # start with a shorter timeout for initial testing
514 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
515 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
516 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
518 # We'll purge the proxy cache for anons explicitly, but require end user agents
519 # to revalidate against the proxy on each visit.
520 # IMPORTANT! The Squid needs to replace the Cache-Control header with
521 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
522 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
523 # start with a shorter timeout for initial testing
524 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
525 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
528 # We do want clients to cache if they can, but they *must* check for updates
529 # on revisiting the page.
530 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
531 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
532 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
534 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
536 wfDebug( "$fname: no caching **\n", false );
538 # In general, the absence of a last modified header should be enough to prevent
539 # the client from using its cache. We send a few other things just to make sure.
540 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
541 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
542 $wgRequest->response()->header( 'Pragma: no-cache' );
547 * Finally, all the text has been munged and accumulated into
548 * the object, let's actually output it:
550 public function output() {
551 global $wgUser, $wgOutputEncoding, $wgRequest;
552 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
553 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
554 global $wgServer, $wgStyleVersion;
556 if( $this->mDoNothing
){
559 $fname = 'OutputPage::output';
560 wfProfileIn( $fname );
561 $sk = $wgUser->getSkin();
564 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
566 wfRunHooks( 'AjaxAddScript', array( &$this ) );
568 if( $wgAjaxSearch ) {
569 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
570 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
573 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
574 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
578 if ( '' != $this->mRedirect
) {
579 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
580 # Standards require redirect URLs to be absolute
582 $this->mRedirect
= $wgServer . $this->mRedirect
;
584 if( $this->mRedirectCode
== '301') {
585 if( !$wgDebugRedirects ) {
586 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
588 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
591 $this->sendCacheControl();
593 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
594 if( $wgDebugRedirects ) {
595 $url = htmlspecialchars( $this->mRedirect
);
596 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
597 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
598 print "</body>\n</html>\n";
600 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
602 wfProfileOut( $fname );
605 elseif ( $this->mStatusCode
)
607 $statusMessage = array(
609 101 => 'Switching Protocols',
614 203 => 'Non-Authoritative Information',
616 205 => 'Reset Content',
617 206 => 'Partial Content',
618 207 => 'Multi-Status',
619 300 => 'Multiple Choices',
620 301 => 'Moved Permanently',
623 304 => 'Not Modified',
625 307 => 'Temporary Redirect',
626 400 => 'Bad Request',
627 401 => 'Unauthorized',
628 402 => 'Payment Required',
631 405 => 'Method Not Allowed',
632 406 => 'Not Acceptable',
633 407 => 'Proxy Authentication Required',
634 408 => 'Request Timeout',
637 411 => 'Length Required',
638 412 => 'Precondition Failed',
639 413 => 'Request Entity Too Large',
640 414 => 'Request-URI Too Large',
641 415 => 'Unsupported Media Type',
642 416 => 'Request Range Not Satisfiable',
643 417 => 'Expectation Failed',
644 422 => 'Unprocessable Entity',
646 424 => 'Failed Dependency',
647 500 => 'Internal Server Error',
648 501 => 'Not Implemented',
649 502 => 'Bad Gateway',
650 503 => 'Service Unavailable',
651 504 => 'Gateway Timeout',
652 505 => 'HTTP Version Not Supported',
653 507 => 'Insufficient Storage'
656 if ( $statusMessage[$this->mStatusCode
] )
657 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
660 # Buffer output; final headers may depend on later processing
663 # Disable temporary placeholders, so that the skin produces HTML
664 $sk->postParseLinkColour( false );
666 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
667 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
669 if ($this->mArticleBodyOnly
) {
670 $this->out($this->mBodytext
);
672 wfProfileIn( 'Output-skin' );
673 $sk->outputPage( $this );
674 wfProfileOut( 'Output-skin' );
677 $this->sendCacheControl();
679 wfProfileOut( $fname );
686 public function out( $ins ) {
687 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
688 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
691 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
692 if ( false === $outs ) { $outs = $ins; }
700 public static function setEncodings() {
701 global $wgInputEncoding, $wgOutputEncoding;
702 global $wgUser, $wgContLang;
704 $wgInputEncoding = strtolower( $wgInputEncoding );
706 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
707 $wgOutputEncoding = strtolower( $wgOutputEncoding );
710 $wgOutputEncoding = $wgInputEncoding;
714 * Deprecated, use wfReportTime() instead.
718 public function reportTime() {
719 $time = wfReportTime();
724 * Produce a "user is blocked" page.
726 * @param bool $return Whether to have a "return to $wgTitle" message or not.
729 function blockedPage( $return = true ) {
730 global $wgUser, $wgContLang, $wgTitle;
732 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
733 $this->setRobotpolicy( 'noindex,nofollow' );
734 $this->setArticleRelated( false );
736 $id = $wgUser->blockedBy();
737 $reason = $wgUser->blockedFor();
740 if ( is_numeric( $id ) ) {
741 $name = User
::whoIs( $id );
745 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
747 $blockid = $wgUser->mBlock
->mId
;
749 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name, $blockid ) );
751 # Don't auto-return to special pages
753 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
754 $this->returnToMain( false, $return );
759 * Outputs a pretty page to explain why the request exploded.
761 * @param string $title Message key for page title.
762 * @param string $msg Message key for page text.
765 public function showErrorPage( $title, $msg ) {
768 $this->mDebugtext
.= 'Original title: ' .
769 $wgTitle->getPrefixedText() . "\n";
770 $this->setPageTitle( wfMsg( $title ) );
771 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
772 $this->setRobotpolicy( 'noindex,nofollow' );
773 $this->setArticleRelated( false );
774 $this->enableClientCache( false );
775 $this->mRedirect
= '';
777 $this->mBodytext
= '';
778 $this->addWikiText( wfMsg( $msg ) );
779 $this->returnToMain( false );
783 public function errorpage( $title, $msg ) {
784 throw new ErrorPageError( $title, $msg );
788 * Display an error page indicating that a given version of MediaWiki is
791 * @param mixed $version The version of MediaWiki needed to use the page
793 public function versionRequired( $version ) {
794 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
795 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
796 $this->setRobotpolicy( 'noindex,nofollow' );
797 $this->setArticleRelated( false );
798 $this->mBodytext
= '';
800 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
801 $this->returnToMain();
805 * Display an error page noting that a given permission bit is required.
807 * @param string $permission key required
809 public function permissionRequired( $permission ) {
810 global $wgGroupPermissions, $wgUser;
812 $this->setPageTitle( wfMsg( 'badaccess' ) );
813 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
814 $this->setRobotpolicy( 'noindex,nofollow' );
815 $this->setArticleRelated( false );
816 $this->mBodytext
= '';
819 foreach( $wgGroupPermissions as $key => $value ) {
820 if( isset( $value[$permission] ) && $value[$permission] == true ) {
821 $groupName = User
::getGroupName( $key );
822 $groupPage = User
::getGroupPage( $key );
824 $skin = $wgUser->getSkin();
825 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
827 $groups[] = $groupName;
831 $n = count( $groups );
832 $groups = implode( ', ', $groups );
837 $message = wfMsgHtml( "badaccess-group$n", $groups );
840 $message = wfMsgHtml( 'badaccess-groups', $groups );
842 $this->addHtml( $message );
843 $this->returnToMain( false );
847 * Use permissionRequired.
850 public function sysopRequired() {
851 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
855 * Use permissionRequired.
858 public function developerRequired() {
859 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
863 * Produce the stock "please login to use the wiki" page
865 public function loginToUse() {
866 global $wgUser, $wgTitle, $wgContLang;
868 if( $wgUser->isLoggedIn() ) {
869 $this->permissionRequired( 'read' );
873 $skin = $wgUser->getSkin();
875 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
876 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
877 $this->setRobotPolicy( 'noindex,nofollow' );
878 $this->setArticleFlag( false );
880 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
881 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
882 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
883 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
885 # Don't return to the main page if the user can't read it
886 # otherwise we'll end up in a pointless loop
887 $mainPage = Title
::newMainPage();
888 if( $mainPage->userCanRead() )
889 $this->returnToMain( true, $mainPage );
893 public function databaseError( $fname, $sql, $error, $errno ) {
894 throw new MWException( "OutputPage::databaseError is obsolete\n" );
899 * @param bool $protected Is the reason the page can't be reached because it's protected?
900 * @param mixed $source
902 public function readOnlyPage( $source = null, $protected = false ) {
903 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
904 $skin = $wgUser->getSkin();
906 $this->setRobotpolicy( 'noindex,nofollow' );
907 $this->setArticleRelated( false );
910 $this->setPageTitle( wfMsg( 'viewsource' ) );
911 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
913 list( $cascadeSources, $restrictions ) = $wgTitle->getCascadeProtectionSources();
915 # Determine if protection is due to the page being a system message
916 # and show an appropriate explanation
917 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
918 $this->addWikiText( wfMsg( 'protectedinterface' ) );
919 } if ( $cascadeSources && count($cascadeSources) > 0 ) {
922 foreach ( $cascadeSources as $title ) {
923 $titles .= '* [[:' . $title->getPrefixedText() . "]]\n";
926 $notice = wfMsg( 'cascadeprotected' ) . "\n$titles";
928 $this->addWikiText( $notice );
930 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
933 $this->setPageTitle( wfMsg( 'readonly' ) );
935 $reason = $wgReadOnly;
937 $reason = file_get_contents( $wgReadOnlyFile );
939 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
942 if( is_string( $source ) ) {
943 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
944 $rows = $wgUser->getIntOption( 'rows' );
945 $cols = $wgUser->getIntOption( 'cols' );
946 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
947 htmlspecialchars( $source ) . "\n</textarea>";
948 $this->addHTML( $text );
950 $article = new Article($wgTitle);
951 $this->addHTML( $skin->formatTemplates($article->getUsedTemplates()) );
953 $this->returnToMain( false );
957 public function fatalError( $message ) {
958 throw new FatalError( $message );
962 public function unexpectedValueError( $name, $val ) {
963 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
967 public function fileCopyError( $old, $new ) {
968 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
972 public function fileRenameError( $old, $new ) {
973 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
977 public function fileDeleteError( $name ) {
978 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
982 public function fileNotFoundError( $name ) {
983 throw new FatalError( wfMsg( 'filenotfound', $name ) );
986 public function showFatalError( $message ) {
987 $this->setPageTitle( wfMsg( "internalerror" ) );
988 $this->setRobotpolicy( "noindex,nofollow" );
989 $this->setArticleRelated( false );
990 $this->enableClientCache( false );
991 $this->mRedirect
= '';
992 $this->mBodytext
= $message;
995 public function showUnexpectedValueError( $name, $val ) {
996 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
999 public function showFileCopyError( $old, $new ) {
1000 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1003 public function showFileRenameError( $old, $new ) {
1004 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1007 public function showFileDeleteError( $name ) {
1008 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1011 public function showFileNotFoundError( $name ) {
1012 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1016 * return from error messages or notes
1017 * @param $auto automatically redirect the user after 10 seconds
1018 * @param $returnto page title to return to. Default is Main Page.
1020 public function returnToMain( $auto = true, $returnto = NULL ) {
1021 global $wgUser, $wgOut, $wgRequest;
1023 if ( $returnto == NULL ) {
1024 $returnto = $wgRequest->getText( 'returnto' );
1027 if ( '' === $returnto ) {
1028 $returnto = Title
::newMainPage();
1031 if ( is_object( $returnto ) ) {
1032 $titleObj = $returnto;
1034 $titleObj = Title
::newFromText( $returnto );
1036 if ( !is_object( $titleObj ) ) {
1037 $titleObj = Title
::newMainPage();
1040 $sk = $wgUser->getSkin();
1041 $link = $sk->makeLinkObj( $titleObj, '' );
1043 $r = wfMsg( 'returnto', $link );
1045 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
1047 $wgOut->addHTML( "\n<p>$r</p>\n" );
1051 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1052 * and uses the first 10 of them for META keywords
1054 * @param ParserOutput &$parserOutput
1056 private function addKeywords( &$parserOutput ) {
1058 $this->addKeyword( $wgTitle->getPrefixedText() );
1060 $links2d =& $parserOutput->getLinks();
1061 if ( !is_array( $links2d ) ) {
1064 foreach ( $links2d as $dbkeys ) {
1065 foreach( $dbkeys as $dbkey => $unused ) {
1066 $this->addKeyword( $dbkey );
1067 if ( ++
$count > 10 ) {
1075 * @return string The doctype, opening <html>, and head element.
1077 public function headElement() {
1078 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1079 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1080 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1082 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1083 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1088 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1090 if ( '' == $this->getHTMLTitle() ) {
1091 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1094 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1095 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1096 foreach($wgXhtmlNamespaces as $tag => $ns) {
1097 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1099 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1100 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1101 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1103 $ret .= $this->getHeadLinks();
1104 global $wgStylePath;
1105 if( $this->isPrintable() ) {
1108 $media = "media='print'";
1110 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1111 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1113 $sk = $wgUser->getSkin();
1114 $ret .= $sk->getHeadScripts();
1115 $ret .= $this->mScripts
;
1116 $ret .= $sk->getUserStyles();
1117 $ret .= $this->getHeadItems();
1119 if ($wgUseTrackbacks && $this->isArticleRelated())
1120 $ret .= $wgTitle->trackbackRDF();
1122 $ret .= "</head>\n";
1127 * @return string HTML tag links to be put in the header.
1129 public function getHeadLinks() {
1132 foreach ( $this->mMetatags
as $tag ) {
1133 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1135 $tag[0] = substr( $tag[0], 5 );
1139 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1142 $p = $this->mRobotpolicy
;
1143 if( $p !== '' && $p != 'index,follow' ) {
1144 // http://www.robotstxt.org/wc/meta-user.html
1145 // Only show if it's different from the default robots policy
1146 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1149 if ( count( $this->mKeywords
) > 0 ) {
1154 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1155 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1157 foreach ( $this->mLinktags
as $tag ) {
1158 $ret .= "\t\t<link";
1159 foreach( $tag as $attr => $val ) {
1160 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1164 if( $this->isSyndicated() ) {
1165 # FIXME: centralize the mime-type and name information in Feed.php
1166 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1167 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1168 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1169 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 1.0' href='$link' />\n";
1176 * Turn off regular page output and return an error reponse
1177 * for when rate limiting has triggered.
1180 public function rateLimited() {
1183 wfHttpError( 500, 'Internal Server Error',
1184 'Sorry, the server has encountered an internal error. ' .
1185 'Please wait a moment and hit "refresh" to submit the request again.' );
1189 * Show an "add new section" link?
1191 * @return bool True if the parser output instructs us to add one
1193 public function showNewSectionLink() {
1194 return $this->mNewSectionLink
;