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;
51 $this->mRevisionId
= null;
52 $this->mNewSectionLink
= false;
55 public function redirect( $url, $responsecode = '302' ) {
56 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
57 $this->mRedirect
= str_replace( "\n", '', $url );
58 $this->mRedirectCode
= $responsecode;
62 * Set the HTTP status code to send with the output.
64 * @param int $statusCode
67 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
69 # To add an http-equiv meta tag, precede the name with "http:"
70 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
71 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
72 function addScript( $script ) { $this->mScripts
.= $script; }
75 * Add a self-contained script tag with the given contents
76 * @param string $script JavaScript text, no <script> tags
78 function addInlineScript( $script ) {
80 $this->mScripts
.= "<script type=\"$wgJsMimeType\"><!--\n$script\n--></script>";
83 function getScript() { return $this->mScripts
; }
85 function setETag($tag) { $this->mETag
= $tag; }
86 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
87 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
89 function addLink( $linkarr ) {
90 # $linkarr should be an associative array of attributes. We'll escape on output.
91 array_push( $this->mLinktags
, $linkarr );
94 function addMetadataLink( $linkarr ) {
95 # note: buggy CC software only reads first "meta" link
96 static $haveMeta = false;
97 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
98 $this->addLink( $linkarr );
103 * checkLastModified tells the client to use the client-cached page if
104 * possible. If sucessful, the OutputPage is disabled so that
105 * any future call to OutputPage->output() have no effect.
107 * @return bool True iff cache-ok headers was sent.
109 function checkLastModified ( $timestamp ) {
110 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
111 $fname = 'OutputPage::checkLastModified';
113 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
114 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
117 if( !$wgCachePages ) {
118 wfDebug( "$fname: CACHE DISABLED\n", false );
121 if( $wgUser->getOption( 'nocache' ) ) {
122 wfDebug( "$fname: USER DISABLED CACHE\n", false );
126 $timestamp=wfTimestamp(TS_MW
,$timestamp);
127 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
129 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
130 # IE sends sizes after the date like this:
131 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
132 # this breaks strtotime().
133 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
134 $modsinceTime = strtotime( $modsince );
135 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
136 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
137 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
138 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
139 # Make sure you're in a place you can leave when you call us!
140 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
141 $this->mLastModified
= $lastmod;
142 $this->sendCacheControl();
143 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
146 // Don't output a compressed blob when using ob_gzhandler;
147 // it's technically against HTTP spec and seems to confuse
148 // Firefox when the response gets split over two packets.
149 wfClearOutputBuffers();
153 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
154 $this->mLastModified
= $lastmod;
157 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
158 $this->mLastModified
= $lastmod;
162 function getPageTitleActionText () {
171 // Display title is already customized
174 return wfMsg('history_short');
176 // FIXME: bug 2735; not correct for special pages etc
177 return wfMsg('preview');
179 return wfMsg('info_short');
185 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
186 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
187 public function setPageTitle( $name ) {
188 global $action, $wgContLang;
189 $name = $wgContLang->convert($name, true);
190 $this->mPagetitle
= $name;
191 if(!empty($action)) {
192 $taction = $this->getPageTitleActionText();
193 if( !empty( $taction ) ) {
194 $name .= ' - '.$taction;
198 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
200 public function getHTMLTitle() { return $this->mHTMLtitle
; }
201 public function getPageTitle() { return $this->mPagetitle
; }
202 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
203 public function getSubtitle() { return $this->mSubtitle
; }
204 public function isArticle() { return $this->mIsarticle
; }
205 public function setPrintable() { $this->mPrintable
= true; }
206 public function isPrintable() { return $this->mPrintable
; }
207 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
208 public function isSyndicated() { return $this->mShowFeedLinks
; }
209 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
210 public function getOnloadHandler() { return $this->mOnloadHandler
; }
211 public function disable() { $this->mDoNothing
= true; }
213 public function setArticleRelated( $v ) {
214 $this->mIsArticleRelated
= $v;
216 $this->mIsarticle
= false;
219 public function setArticleFlag( $v ) {
220 $this->mIsarticle
= $v;
222 $this->mIsArticleRelated
= $v;
226 public function isArticleRelated() { return $this->mIsArticleRelated
; }
228 public function getLanguageLinks() { return $this->mLanguageLinks
; }
229 public function addLanguageLinks($newLinkArray) {
230 $this->mLanguageLinks +
= $newLinkArray;
232 public function setLanguageLinks($newLinkArray) {
233 $this->mLanguageLinks
= $newLinkArray;
236 public function getCategoryLinks() {
237 return $this->mCategoryLinks
;
241 * Add an array of categories, with names in the keys
243 public function addCategoryLinks($categories) {
244 global $wgUser, $wgContLang;
246 if ( !is_array( $categories ) ) {
249 # Add the links to the link cache in a batch
250 $arr = array( NS_CATEGORY
=> $categories );
252 $lb->setArray( $arr );
255 $sk =& $wgUser->getSkin();
256 foreach ( $categories as $category => $unused ) {
257 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
258 $text = $wgContLang->convertHtml( $title->getText() );
259 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
263 public function setCategoryLinks($categories) {
264 $this->mCategoryLinks
= array();
265 $this->addCategoryLinks($categories);
268 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
269 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
271 public function addHTML( $text ) { $this->mBodytext
.= $text; }
272 public function clearHTML() { $this->mBodytext
= ''; }
273 public function getHTML() { return $this->mBodytext
; }
274 public function debug( $text ) { $this->mDebugtext
.= $text; }
277 public function setParserOptions( $options ) {
278 return $this->parserOptions( $options );
281 public function parserOptions( $options = null ) {
282 if ( !$this->mParserOptions
) {
283 $this->mParserOptions
= new ParserOptions
;
285 return wfSetVar( $this->mParserOptions
, $options );
289 * Set the revision ID which will be seen by the wiki text parser
290 * for things such as embedded {{REVISIONID}} variable use.
291 * @param mixed $revid an integer, or NULL
292 * @return mixed previous value
294 public function setRevisionId( $revid ) {
295 $val = is_null( $revid ) ?
null : intval( $revid );
296 return wfSetVar( $this->mRevisionId
, $val );
300 * Convert wikitext to HTML and add it to the buffer
301 * Default assumes that the current page title will
304 * @param string $text
305 * @param bool $linestart
307 public function addWikiText( $text, $linestart = true ) {
309 $this->addWikiTextTitle($text, $wgTitle, $linestart);
312 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
313 $this->addWikiTextTitle($text, $title, $linestart);
316 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
317 $this->addWikiTextTitle( $text, $title, $linestart, true );
320 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
323 $fname = 'OutputPage:addWikiTextTitle';
326 wfIncrStats('pcache_not_possible');
328 $popts = $this->parserOptions();
329 $popts->setTidy($tidy);
331 $parserOutput = $wgParser->parse( $text, $title, $popts,
332 $linestart, true, $this->mRevisionId
);
334 $this->addParserOutput( $parserOutput );
336 wfProfileOut($fname);
341 * @param ParserOutput object &$parserOutput
343 public function addParserOutputNoText( &$parserOutput ) {
344 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
345 $this->addCategoryLinks( $parserOutput->getCategories() );
346 $this->mNewSectionLink
= $parserOutput->getNewSection();
347 $this->addKeywords( $parserOutput );
348 if ( $parserOutput->getCacheTime() == -1 ) {
349 $this->enableClientCache( false );
351 if ( $parserOutput->mHTMLtitle
!= "" ) {
352 $this->mPagetitle
= $parserOutput->mHTMLtitle
;
354 if ( $parserOutput->mSubtitle
!= '' ) {
355 $this->mSubtitle
.= $parserOutput->mSubtitle
;
357 $this->mNoGallery
= $parserOutput->getNoGallery();
358 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
363 * @param ParserOutput &$parserOutput
365 function addParserOutput( &$parserOutput ) {
366 $this->addParserOutputNoText( $parserOutput );
367 $text = $parserOutput->getText();
368 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
369 $this->addHTML( $text );
373 * Add wikitext to the buffer, assuming that this is the primary text for a page view
374 * Saves the text into the parser cache if possible.
376 * @param string $text
377 * @param Article $article
379 * @deprecated Use Article::outputWikitext
381 public function addPrimaryWikiText( $text, $article, $cache = true ) {
382 global $wgParser, $wgUser;
384 $popts = $this->parserOptions();
385 $popts->setTidy(true);
386 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
387 $popts, true, true, $this->mRevisionId
);
388 $popts->setTidy(false);
389 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
390 $parserCache =& ParserCache
::singleton();
391 $parserCache->save( $parserOutput, $article, $wgUser );
394 $this->addParserOutput( $parserOutput );
398 * @deprecated use addWikiTextTidy()
400 public function addSecondaryWikiText( $text, $linestart = true ) {
402 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
406 * Add wikitext with tidy enabled
408 public function addWikiTextTidy( $text, $linestart = true ) {
410 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
415 * Add the output of a QuickTemplate to the output buffer
417 * @param QuickTemplate $template
419 public function addTemplate( &$template ) {
421 $template->execute();
422 $this->addHTML( ob_get_contents() );
427 * Parse wikitext and return the HTML.
429 * @param string $text
430 * @param bool $linestart Is this the start of a line?
431 * @param bool $interface ??
433 public function parse( $text, $linestart = true, $interface = false ) {
434 global $wgParser, $wgTitle;
435 $popts = $this->parserOptions();
436 if ( $interface) { $popts->setInterfaceMessage(true); }
437 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
438 $linestart, true, $this->mRevisionId
);
439 if ( $interface) { $popts->setInterfaceMessage(false); }
440 return $parserOutput->getText();
444 * @param Article $article
447 * @return bool True if successful, else false.
449 public function tryParserCache( &$article, $user ) {
450 $parserCache =& ParserCache
::singleton();
451 $parserOutput = $parserCache->get( $article, $user );
452 if ( $parserOutput !== false ) {
453 $this->addParserOutput( $parserOutput );
461 * @param int $maxage Maximum cache time on the Squid, in seconds.
463 public function setSquidMaxage( $maxage ) {
464 $this->mSquidMaxage
= $maxage;
468 * Use enableClientCache(false) to force it to send nocache headers
471 public function enableClientCache( $state ) {
472 return wfSetVar( $this->mEnableClientCache
, $state );
475 function uncacheableBecauseRequestvars() {
477 return $wgRequest->getText('useskin', false) === false
478 && $wgRequest->getText('uselang', false) === false;
481 public function sendCacheControl() {
482 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
483 $fname = 'OutputPage::sendCacheControl';
485 if ($wgUseETag && $this->mETag
)
486 $wgRequest->response()->header("ETag: $this->mETag");
488 # don't serve compressed data to clients who can't handle it
489 # maintain different caches for logged-in users and non-logged in ones
490 $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
491 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
492 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
493 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
496 # We'll purge the proxy cache explicitly, but require end user agents
497 # to revalidate against the proxy on each visit.
498 # Surrogate-Control controls our Squid, Cache-Control downstream caches
499 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
500 # start with a shorter timeout for initial testing
501 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
502 $wgRequest->response()->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
503 $wgRequest->response()->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
505 # We'll purge the proxy cache for anons explicitly, but require end user agents
506 # to revalidate against the proxy on each visit.
507 # IMPORTANT! The Squid needs to replace the Cache-Control header with
508 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
509 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
510 # start with a shorter timeout for initial testing
511 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
512 $wgRequest->response()->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
515 # We do want clients to cache if they can, but they *must* check for updates
516 # on revisiting the page.
517 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
518 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
519 $wgRequest->response()->header( "Cache-Control: private, must-revalidate, max-age=0" );
521 if($this->mLastModified
) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
523 wfDebug( "$fname: no caching **\n", false );
525 # In general, the absence of a last modified header should be enough to prevent
526 # the client from using its cache. We send a few other things just to make sure.
527 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
528 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
529 $wgRequest->response()->header( 'Pragma: no-cache' );
534 * Finally, all the text has been munged and accumulated into
535 * the object, let's actually output it:
537 public function output() {
538 global $wgUser, $wgOutputEncoding, $wgRequest;
539 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
540 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
541 global $wgServer, $wgStyleVersion;
543 if( $this->mDoNothing
){
546 $fname = 'OutputPage::output';
547 wfProfileIn( $fname );
548 $sk = $wgUser->getSkin();
551 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
552 if( $wgAjaxSearch ) {
553 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js\"></script>\n" );
554 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
557 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
558 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js\"></script>\n" );
562 if ( '' != $this->mRedirect
) {
563 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
564 # Standards require redirect URLs to be absolute
566 $this->mRedirect
= $wgServer . $this->mRedirect
;
568 if( $this->mRedirectCode
== '301') {
569 if( !$wgDebugRedirects ) {
570 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
572 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
575 $this->sendCacheControl();
577 if( $wgDebugRedirects ) {
578 $url = htmlspecialchars( $this->mRedirect
);
579 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
580 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
581 print "</body>\n</html>\n";
583 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
585 wfProfileOut( $fname );
588 elseif ( $this->mStatusCode
)
590 $statusMessage = array(
592 101 => 'Switching Protocols',
597 203 => 'Non-Authoritative Information',
599 205 => 'Reset Content',
600 206 => 'Partial Content',
601 207 => 'Multi-Status',
602 300 => 'Multiple Choices',
603 301 => 'Moved Permanently',
606 304 => 'Not Modified',
608 307 => 'Temporary Redirect',
609 400 => 'Bad Request',
610 401 => 'Unauthorized',
611 402 => 'Payment Required',
614 405 => 'Method Not Allowed',
615 406 => 'Not Acceptable',
616 407 => 'Proxy Authentication Required',
617 408 => 'Request Timeout',
620 411 => 'Length Required',
621 412 => 'Precondition Failed',
622 413 => 'Request Entity Too Large',
623 414 => 'Request-URI Too Large',
624 415 => 'Unsupported Media Type',
625 416 => 'Request Range Not Satisfiable',
626 417 => 'Expectation Failed',
627 422 => 'Unprocessable Entity',
629 424 => 'Failed Dependency',
630 500 => 'Internal Server Error',
631 501 => 'Not Implemented',
632 502 => 'Bad Gateway',
633 503 => 'Service Unavailable',
634 504 => 'Gateway Timeout',
635 505 => 'HTTP Version Not Supported',
636 507 => 'Insufficient Storage'
639 if ( $statusMessage[$this->mStatusCode
] )
640 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
643 # Buffer output; final headers may depend on later processing
646 # Disable temporary placeholders, so that the skin produces HTML
647 $sk->postParseLinkColour( false );
649 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
650 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
652 if ($this->mArticleBodyOnly
) {
653 $this->out($this->mBodytext
);
655 wfProfileIn( 'Output-skin' );
656 $sk->outputPage( $this );
657 wfProfileOut( 'Output-skin' );
660 $this->sendCacheControl();
662 wfProfileOut( $fname );
669 public function out( $ins ) {
670 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
671 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
674 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
675 if ( false === $outs ) { $outs = $ins; }
683 public static function setEncodings() {
684 global $wgInputEncoding, $wgOutputEncoding;
685 global $wgUser, $wgContLang;
687 $wgInputEncoding = strtolower( $wgInputEncoding );
689 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
690 $wgOutputEncoding = strtolower( $wgOutputEncoding );
693 $wgOutputEncoding = $wgInputEncoding;
697 * Deprecated, use wfReportTime() instead.
701 public function reportTime() {
702 $time = wfReportTime();
707 * Produce a "user is blocked" page.
709 * @param bool $return Whether to have a "return to $wgTitle" message or not.
712 function blockedPage( $return = true ) {
713 global $wgUser, $wgContLang, $wgTitle;
715 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
716 $this->setRobotpolicy( 'noindex,nofollow' );
717 $this->setArticleRelated( false );
719 $id = $wgUser->blockedBy();
720 $reason = $wgUser->blockedFor();
723 if ( is_numeric( $id ) ) {
724 $name = User
::whoIs( $id );
728 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
730 $blockid = $wgUser->mBlock
->mId
;
732 $this->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name, $blockid ) );
734 # Don't auto-return to special pages
736 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
737 $this->returnToMain( false, $return );
742 * Outputs a pretty page to explain why the request exploded.
744 * @param string $title Message key for page title.
745 * @param string $msg Message key for page text.
748 public function showErrorPage( $title, $msg ) {
751 $this->mDebugtext
.= 'Original title: ' .
752 $wgTitle->getPrefixedText() . "\n";
753 $this->setPageTitle( wfMsg( $title ) );
754 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
755 $this->setRobotpolicy( 'noindex,nofollow' );
756 $this->setArticleRelated( false );
757 $this->enableClientCache( false );
758 $this->mRedirect
= '';
760 $this->mBodytext
= '';
761 $this->addWikiText( wfMsg( $msg ) );
762 $this->returnToMain( false );
766 public function errorpage( $title, $msg ) {
767 throw new ErrorPageError( $title, $msg );
771 * Display an error page indicating that a given version of MediaWiki is
774 * @param mixed $version The version of MediaWiki needed to use the page
776 public function versionRequired( $version ) {
777 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
778 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
779 $this->setRobotpolicy( 'noindex,nofollow' );
780 $this->setArticleRelated( false );
781 $this->mBodytext
= '';
783 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
784 $this->returnToMain();
788 * Display an error page noting that a given permission bit is required.
790 * @param string $permission key required
792 public function permissionRequired( $permission ) {
793 global $wgGroupPermissions, $wgUser;
795 $this->setPageTitle( wfMsg( 'badaccess' ) );
796 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
797 $this->setRobotpolicy( 'noindex,nofollow' );
798 $this->setArticleRelated( false );
799 $this->mBodytext
= '';
802 foreach( $wgGroupPermissions as $key => $value ) {
803 if( isset( $value[$permission] ) && $value[$permission] == true ) {
804 $groupName = User
::getGroupName( $key );
805 $groupPage = User
::getGroupPage( $key );
807 $skin =& $wgUser->getSkin();
808 $groups[] = '"'.$skin->makeLinkObj( $groupPage, $groupName ).'"';
810 $groups[] = '"'.$groupName.'"';
814 $n = count( $groups );
815 $groups = implode( ', ', $groups );
820 $message = wfMsgHtml( "badaccess-group$n", $groups );
823 $message = wfMsgHtml( 'badaccess-groups', $groups );
825 $this->addHtml( $message );
826 $this->returnToMain( false );
830 * Use permissionRequired.
833 public function sysopRequired() {
834 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
838 * Use permissionRequired.
841 public function developerRequired() {
842 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
846 * Produce the stock "please login to use the wiki" page
848 public function loginToUse() {
849 global $wgUser, $wgTitle, $wgContLang;
851 if( $wgUser->isLoggedIn() ) {
852 $this->permissionRequired( 'read' );
856 $skin = $wgUser->getSkin();
858 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
859 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
860 $this->setRobotPolicy( 'noindex,nofollow' );
861 $this->setArticleFlag( false );
863 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
864 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
865 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
866 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
868 # Don't return to the main page if the user can't read it
869 # otherwise we'll end up in a pointless loop
870 $mainPage = Title
::newMainPage();
871 if( $mainPage->userCanRead() )
872 $this->returnToMain( true, $mainPage );
876 public function databaseError( $fname, $sql, $error, $errno ) {
877 throw new MWException( "OutputPage::databaseError is obsolete\n" );
882 * @param bool $protected Is the reason the page can't be reached because it's protected?
883 * @param mixed $source
885 public function readOnlyPage( $source = null, $protected = false ) {
886 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
887 $skin = $wgUser->getSkin();
889 $this->setRobotpolicy( 'noindex,nofollow' );
890 $this->setArticleRelated( false );
893 $this->setPageTitle( wfMsg( 'viewsource' ) );
894 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
896 $cascadeSources = $wgTitle->getCascadeProtectionSources();
898 # Determine if protection is due to the page being a system message
899 # and show an appropriate explanation
900 if( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
901 $this->addWikiText( wfMsg( 'protectedinterface' ) );
902 } if ( $cascadeSources && count($cascadeSources) > 0 ) {
905 foreach ( $cascadeSources as $title ) {
906 $titles .= '* [[:' . $title->getPrefixedText() . "]]\n";
909 $notice = wfMsg( 'cascadeprotected' ) . "\n$titles";
911 $this->addWikiText( $notice );
913 $this->addWikiText( wfMsg( 'protectedpagetext' ) );
916 $this->setPageTitle( wfMsg( 'readonly' ) );
918 $reason = $wgReadOnly;
920 $reason = file_get_contents( $wgReadOnlyFile );
922 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
925 if( is_string( $source ) ) {
926 $this->addWikiText( wfMsg( 'viewsourcetext' ) );
927 $rows = $wgUser->getIntOption( 'rows' );
928 $cols = $wgUser->getIntOption( 'cols' );
929 $text = "\n<textarea name='wpTextbox1' id='wpTextbox1' cols='$cols' rows='$rows' readonly='readonly'>" .
930 htmlspecialchars( $source ) . "\n</textarea>";
931 $this->addHTML( $text );
933 $article = new Article($wgTitle);
934 $this->addHTML( $skin->formatTemplates($article->getUsedTemplates()) );
936 $this->returnToMain( false );
940 public function fatalError( $message ) {
941 throw new FatalError( $message );
945 public function unexpectedValueError( $name, $val ) {
946 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
950 public function fileCopyError( $old, $new ) {
951 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
955 public function fileRenameError( $old, $new ) {
956 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
960 public function fileDeleteError( $name ) {
961 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
965 public function fileNotFoundError( $name ) {
966 throw new FatalError( wfMsg( 'filenotfound', $name ) );
969 public function showFatalError( $message ) {
970 $this->setPageTitle( wfMsg( "internalerror" ) );
971 $this->setRobotpolicy( "noindex,nofollow" );
972 $this->setArticleRelated( false );
973 $this->enableClientCache( false );
974 $this->mRedirect
= '';
975 $this->mBodytext
= $message;
978 public function showUnexpectedValueError( $name, $val ) {
979 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
982 public function showFileCopyError( $old, $new ) {
983 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
986 public function showFileRenameError( $old, $new ) {
987 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
990 public function showFileDeleteError( $name ) {
991 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
994 public function showFileNotFoundError( $name ) {
995 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
999 * return from error messages or notes
1000 * @param $auto automatically redirect the user after 10 seconds
1001 * @param $returnto page title to return to. Default is Main Page.
1003 public function returnToMain( $auto = true, $returnto = NULL ) {
1004 global $wgUser, $wgOut, $wgRequest;
1006 if ( $returnto == NULL ) {
1007 $returnto = $wgRequest->getText( 'returnto' );
1010 if ( '' === $returnto ) {
1011 $returnto = Title
::newMainPage();
1014 if ( is_object( $returnto ) ) {
1015 $titleObj = $returnto;
1017 $titleObj = Title
::newFromText( $returnto );
1019 if ( !is_object( $titleObj ) ) {
1020 $titleObj = Title
::newMainPage();
1023 $sk = $wgUser->getSkin();
1024 $link = $sk->makeLinkObj( $titleObj, '' );
1026 $r = wfMsg( 'returnto', $link );
1028 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
1030 $wgOut->addHTML( "\n<p>$r</p>\n" );
1034 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1035 * and uses the first 10 of them for META keywords
1037 * @param ParserOutput &$parserOutput
1039 private function addKeywords( &$parserOutput ) {
1041 $this->addKeyword( $wgTitle->getPrefixedText() );
1043 $links2d =& $parserOutput->getLinks();
1044 if ( !is_array( $links2d ) ) {
1047 foreach ( $links2d as $dbkeys ) {
1048 foreach( $dbkeys as $dbkey => $unused ) {
1049 $this->addKeyword( $dbkey );
1050 if ( ++
$count > 10 ) {
1058 * @return string The doctype, opening <html>, and head element.
1060 public function headElement() {
1061 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1062 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1063 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1065 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1066 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1071 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1073 if ( '' == $this->getHTMLTitle() ) {
1074 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1077 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1078 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1079 foreach($wgXhtmlNamespaces as $tag => $ns) {
1080 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1082 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1083 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1084 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1086 $ret .= $this->getHeadLinks();
1087 global $wgStylePath;
1088 if( $this->isPrintable() ) {
1091 $media = "media='print'";
1093 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1094 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1096 $sk = $wgUser->getSkin();
1097 $ret .= $sk->getHeadScripts();
1098 $ret .= $this->mScripts
;
1099 $ret .= $sk->getUserStyles();
1101 if ($wgUseTrackbacks && $this->isArticleRelated())
1102 $ret .= $wgTitle->trackbackRDF();
1104 $ret .= "</head>\n";
1109 * @return string HTML tag links to be put in the header.
1111 public function getHeadLinks() {
1114 foreach ( $this->mMetatags
as $tag ) {
1115 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1117 $tag[0] = substr( $tag[0], 5 );
1121 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1124 $p = $this->mRobotpolicy
;
1125 if( $p !== '' && $p != 'index,follow' ) {
1126 // http://www.robotstxt.org/wc/meta-user.html
1127 // Only show if it's different from the default robots policy
1128 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1131 if ( count( $this->mKeywords
) > 0 ) {
1136 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1137 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1139 foreach ( $this->mLinktags
as $tag ) {
1140 $ret .= "\t\t<link";
1141 foreach( $tag as $attr => $val ) {
1142 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1146 if( $this->isSyndicated() ) {
1147 # FIXME: centralize the mime-type and name information in Feed.php
1148 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
1149 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
1150 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
1151 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 1.0' href='$link' />\n";
1158 * Turn off regular page output and return an error reponse
1159 * for when rate limiting has triggered.
1162 public function rateLimited() {
1165 wfHttpError( 500, 'Internal Server Error',
1166 'Sorry, the server has encountered an internal error. ' .
1167 'Please wait a moment and hit "refresh" to submit the request again.' );
1171 * Show an "add new section" link?
1173 * @return bool True if the parser output instructs us to add one
1175 public function showNewSectionLink() {
1176 return $this->mNewSectionLink
;