2 if ( ! defined( 'MEDIAWIKI' ) )
11 var $mMetatags, $mKeywords;
12 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
13 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
14 var $mSubtitle, $mRedirect, $mStatusCode;
15 var $mLastModified, $mETag, $mCategoryLinks;
16 var $mScripts, $mLinkColours, $mPageLinkTitle;
19 var $mSuppressQuickbar;
22 var $mContainsOldMagic, $mContainsNewMagic;
23 var $mIsArticleRelated;
24 protected $mParserOptions; // lazy initialised, use parserOptions()
25 var $mShowFeedLinks = false;
26 var $mFeedLinksAppendQuery = false;
27 var $mEnableClientCache = true;
28 var $mArticleBodyOnly = false;
30 var $mNewSectionLink = false;
31 var $mNoGallery = false;
32 var $mPageTitleActionText = '';
33 var $mParseWarnings = array();
37 * Initialise private variables
39 function __construct() {
40 global $wgAllowUserJs;
41 $this->mAllowUserJs
= $wgAllowUserJs;
42 $this->mMetatags
= $this->mKeywords
= $this->mLinktags
= array();
43 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
44 $this->mRedirect
= $this->mLastModified
=
45 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
46 $this->mOnloadHandler
= $this->mPageLinkTitle
= '';
47 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
48 $this->mSuppressQuickbar
= $this->mPrintable
= false;
49 $this->mLanguageLinks
= array();
50 $this->mCategoryLinks
= array();
51 $this->mDoNothing
= false;
52 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
53 $this->mParserOptions
= null;
54 $this->mSquidMaxage
= 0;
56 $this->mHeadItems
= array();
58 $this->mRevisionId
= null;
59 $this->mNewSectionLink
= false;
60 $this->mTemplateIds
= array();
63 public function redirect( $url, $responsecode = '302' ) {
64 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
65 $this->mRedirect
= str_replace( "\n", '', $url );
66 $this->mRedirectCode
= $responsecode;
69 public function getRedirect() {
70 return $this->mRedirect
;
74 * Set the HTTP status code to send with the output.
76 * @param int $statusCode
79 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
81 # To add an http-equiv meta tag, precede the name with "http:"
82 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
83 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
84 function addScript( $script ) { $this->mScripts
.= "\t\t".$script; }
85 function addStyle( $style ) {
86 global $wgStylePath, $wgStyleVersion;
89 'rel' => 'stylesheet',
90 'href' => $wgStylePath . '/' . $style . '?' . $wgStyleVersion ) );
94 * Add a self-contained script tag with the given contents
95 * @param string $script JavaScript text, no <script> tags
97 function addInlineScript( $script ) {
99 $this->mScripts
.= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
102 function getScript() {
103 return $this->mScripts
. $this->getHeadItems();
106 function getHeadItems() {
108 foreach ( $this->mHeadItems
as $item ) {
114 function addHeadItem( $name, $value ) {
115 $this->mHeadItems
[$name] = $value;
118 function hasHeadItem( $name ) {
119 return isset( $this->mHeadItems
[$name] );
122 function setETag($tag) { $this->mETag
= $tag; }
123 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
124 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
126 function addLink( $linkarr ) {
127 # $linkarr should be an associative array of attributes. We'll escape on output.
128 array_push( $this->mLinktags
, $linkarr );
131 function addMetadataLink( $linkarr ) {
132 # note: buggy CC software only reads first "meta" link
133 static $haveMeta = false;
134 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
135 $this->addLink( $linkarr );
140 * checkLastModified tells the client to use the client-cached page if
141 * possible. If sucessful, the OutputPage is disabled so that
142 * any future call to OutputPage->output() have no effect.
144 * @return bool True iff cache-ok headers was sent.
146 function checkLastModified ( $timestamp ) {
147 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
148 $fname = 'OutputPage::checkLastModified';
150 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
151 wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" );
154 if( !$wgCachePages ) {
155 wfDebug( "$fname: CACHE DISABLED\n", false );
158 if( $wgUser->getOption( 'nocache' ) ) {
159 wfDebug( "$fname: USER DISABLED CACHE\n", false );
163 $timestamp=wfTimestamp(TS_MW
,$timestamp);
164 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
166 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
167 # IE sends sizes after the date like this:
168 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
169 # this breaks strtotime().
170 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
172 wfSuppressWarnings(); // E_STRICT system time bitching
173 $modsinceTime = strtotime( $modsince );
176 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
177 wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false );
178 wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false );
179 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
180 # Make sure you're in a place you can leave when you call us!
181 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
182 $this->mLastModified
= $lastmod;
183 $this->sendCacheControl();
184 wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
187 // Don't output a compressed blob when using ob_gzhandler;
188 // it's technically against HTTP spec and seems to confuse
189 // Firefox when the response gets split over two packets.
190 wfClearOutputBuffers();
194 wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
195 $this->mLastModified
= $lastmod;
198 wfDebug( "$fname: client did not send If-Modified-Since header\n", false );
199 $this->mLastModified
= $lastmod;
203 function setPageTitleActionText( $text ) {
204 $this->mPageTitleActionText
= $text;
207 function getPageTitleActionText () {
208 if ( isset( $this->mPageTitleActionText
) ) {
209 return $this->mPageTitleActionText
;
213 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
214 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
215 public function setPageTitle( $name ) {
216 global $action, $wgContLang;
217 $name = $wgContLang->convert($name, true);
218 $this->mPagetitle
= $name;
219 if(!empty($action)) {
220 $taction = $this->getPageTitleActionText();
221 if( !empty( $taction ) ) {
222 $name .= ' - '.$taction;
226 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
228 public function getHTMLTitle() { return $this->mHTMLtitle
; }
229 public function getPageTitle() { return $this->mPagetitle
; }
230 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
231 public function getSubtitle() { return $this->mSubtitle
; }
232 public function isArticle() { return $this->mIsarticle
; }
233 public function setPrintable() { $this->mPrintable
= true; }
234 public function isPrintable() { return $this->mPrintable
; }
235 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
236 public function isSyndicated() { return $this->mShowFeedLinks
; }
237 public function setFeedAppendQuery( $val ) { $this->mFeedLinksAppendQuery
= $val; }
238 public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery
; }
239 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
240 public function getOnloadHandler() { return $this->mOnloadHandler
; }
241 public function disable() { $this->mDoNothing
= true; }
243 public function setArticleRelated( $v ) {
244 $this->mIsArticleRelated
= $v;
246 $this->mIsarticle
= false;
249 public function setArticleFlag( $v ) {
250 $this->mIsarticle
= $v;
252 $this->mIsArticleRelated
= $v;
256 public function isArticleRelated() { return $this->mIsArticleRelated
; }
258 public function getLanguageLinks() { return $this->mLanguageLinks
; }
259 public function addLanguageLinks($newLinkArray) {
260 $this->mLanguageLinks +
= $newLinkArray;
262 public function setLanguageLinks($newLinkArray) {
263 $this->mLanguageLinks
= $newLinkArray;
266 public function getCategoryLinks() {
267 return $this->mCategoryLinks
;
271 * Add an array of categories, with names in the keys
273 public function addCategoryLinks( $categories ) {
274 global $wgUser, $wgContLang;
276 if ( !is_array( $categories ) ||
count( $categories ) == 0 ) {
280 # Add the links to a LinkBatch
281 $arr = array( NS_CATEGORY
=> $categories );
283 $lb->setArray( $arr );
285 # Fetch existence plus the hiddencat property
286 $dbr = wfGetDB( DB_SLAVE
);
287 $pageTable = $dbr->tableName( 'page' );
288 $where = $lb->constructSet( 'page', $dbr );
289 $propsTable = $dbr->tableName( 'page_props' );
290 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, pp_value
291 FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
292 $res = $dbr->query( $sql, __METHOD__
);
294 # Add the results to the link cache
295 $lb->addResultToCache( LinkCache
::singleton(), $res );
297 # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
298 $categories = array_combine( array_keys( $categories ),
299 array_fill( 0, count( $categories ), 'normal' ) );
301 # Mark hidden categories
302 foreach ( $res as $row ) {
303 if ( isset( $row->pp_value
) ) {
304 $categories[$row->page_title
] = 'hidden';
308 # Add the remaining categories to the skin
309 $sk = $wgUser->getSkin();
310 foreach ( $categories as $category => $type ) {
311 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
312 $text = $wgContLang->convertHtml( $title->getText() );
313 $this->mCategoryLinks
[$type][] = $sk->makeLinkObj( $title, $text );
317 public function setCategoryLinks($categories) {
318 $this->mCategoryLinks
= array();
319 $this->addCategoryLinks($categories);
322 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
323 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
325 public function disallowUserJs() { $this->mAllowUserJs
= false; }
326 public function isUserJsAllowed() { return $this->mAllowUserJs
; }
328 public function addHTML( $text ) { $this->mBodytext
.= $text; }
329 public function clearHTML() { $this->mBodytext
= ''; }
330 public function getHTML() { return $this->mBodytext
; }
331 public function debug( $text ) { $this->mDebugtext
.= $text; }
334 public function setParserOptions( $options ) {
335 return $this->parserOptions( $options );
338 public function parserOptions( $options = null ) {
339 if ( !$this->mParserOptions
) {
340 $this->mParserOptions
= new ParserOptions
;
342 return wfSetVar( $this->mParserOptions
, $options );
346 * Set the revision ID which will be seen by the wiki text parser
347 * for things such as embedded {{REVISIONID}} variable use.
348 * @param mixed $revid an integer, or NULL
349 * @return mixed previous value
351 public function setRevisionId( $revid ) {
352 $val = is_null( $revid ) ?
null : intval( $revid );
353 return wfSetVar( $this->mRevisionId
, $val );
357 * Convert wikitext to HTML and add it to the buffer
358 * Default assumes that the current page title will
361 * @param string $text
362 * @param bool $linestart
364 public function addWikiText( $text, $linestart = true ) {
366 $this->addWikiTextTitle($text, $wgTitle, $linestart);
369 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
370 $this->addWikiTextTitle($text, $title, $linestart);
373 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
374 $this->addWikiTextTitle( $text, $title, $linestart, true );
377 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
380 $fname = 'OutputPage:addWikiTextTitle';
383 wfIncrStats('pcache_not_possible');
385 $popts = $this->parserOptions();
386 $oldTidy = $popts->setTidy($tidy);
388 $parserOutput = $wgParser->parse( $text, $title, $popts,
389 $linestart, true, $this->mRevisionId
);
391 $popts->setTidy( $oldTidy );
393 $this->addParserOutput( $parserOutput );
395 wfProfileOut($fname);
400 * @param ParserOutput object &$parserOutput
402 public function addParserOutputNoText( &$parserOutput ) {
403 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
404 $this->addCategoryLinks( $parserOutput->getCategories() );
405 $this->mNewSectionLink
= $parserOutput->getNewSection();
406 $this->addKeywords( $parserOutput );
407 $this->mParseWarnings
= $parserOutput->getWarnings();
408 if ( $parserOutput->getCacheTime() == -1 ) {
409 $this->enableClientCache( false );
411 $this->mNoGallery
= $parserOutput->getNoGallery();
412 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
414 $this->mTemplateIds +
= (array)$parserOutput->mTemplateIds
;
417 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
418 $this->setPageTitle( $dt );
420 // Hooks registered in the object
421 global $wgParserOutputHooks;
422 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
423 list( $hookName, $data ) = $hookInfo;
424 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
425 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
429 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
434 * @param ParserOutput &$parserOutput
436 function addParserOutput( &$parserOutput ) {
437 $this->addParserOutputNoText( $parserOutput );
438 $text = $parserOutput->getText();
439 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
440 $this->addHTML( $text );
444 * Add wikitext to the buffer, assuming that this is the primary text for a page view
445 * Saves the text into the parser cache if possible.
447 * @param string $text
448 * @param Article $article
450 * @deprecated Use Article::outputWikitext
452 public function addPrimaryWikiText( $text, $article, $cache = true ) {
453 global $wgParser, $wgUser;
455 $popts = $this->parserOptions();
456 $popts->setTidy(true);
457 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
458 $popts, true, true, $this->mRevisionId
);
459 $popts->setTidy(false);
460 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
461 $parserCache = ParserCache
::singleton();
462 $parserCache->save( $parserOutput, $article, $wgUser );
465 $this->addParserOutput( $parserOutput );
469 * @deprecated use addWikiTextTidy()
471 public function addSecondaryWikiText( $text, $linestart = true ) {
473 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
477 * Add wikitext with tidy enabled
479 public function addWikiTextTidy( $text, $linestart = true ) {
481 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
486 * Add the output of a QuickTemplate to the output buffer
488 * @param QuickTemplate $template
490 public function addTemplate( &$template ) {
492 $template->execute();
493 $this->addHTML( ob_get_contents() );
498 * Parse wikitext and return the HTML.
500 * @param string $text
501 * @param bool $linestart Is this the start of a line?
502 * @param bool $interface ??
504 public function parse( $text, $linestart = true, $interface = false ) {
505 global $wgParser, $wgTitle;
506 $popts = $this->parserOptions();
507 if ( $interface) { $popts->setInterfaceMessage(true); }
508 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
509 $linestart, true, $this->mRevisionId
);
510 if ( $interface) { $popts->setInterfaceMessage(false); }
511 return $parserOutput->getText();
515 * @param Article $article
518 * @return bool True if successful, else false.
520 public function tryParserCache( &$article, $user ) {
521 $parserCache = ParserCache
::singleton();
522 $parserOutput = $parserCache->get( $article, $user );
523 if ( $parserOutput !== false ) {
524 $this->addParserOutput( $parserOutput );
532 * @param int $maxage Maximum cache time on the Squid, in seconds.
534 public function setSquidMaxage( $maxage ) {
535 $this->mSquidMaxage
= $maxage;
539 * Use enableClientCache(false) to force it to send nocache headers
542 public function enableClientCache( $state ) {
543 return wfSetVar( $this->mEnableClientCache
, $state );
546 function getCacheVaryCookies() {
547 global $wgCookiePrefix, $wgCacheVaryCookies;
549 if ( $cookies === null ) {
550 $cookies = array_merge(
552 "{$wgCookiePrefix}Token",
553 "{$wgCookiePrefix}LoggedOut",
558 wfRunHooks('GetCacheVaryCookies', array( $this, &$cookies ) );
563 function uncacheableBecauseRequestVars() {
565 return $wgRequest->getText('useskin', false) === false
566 && $wgRequest->getText('uselang', false) === false;
570 * Check if the request has a cache-varying cookie header
571 * If it does, it's very important that we don't allow public caching
573 function haveCacheVaryCookies() {
574 global $wgRequest, $wgCookiePrefix;
575 $cookieHeader = $wgRequest->getHeader( 'cookie' );
576 if ( $cookieHeader === false ) {
579 $cvCookies = $this->getCacheVaryCookies();
580 foreach ( $cvCookies as $cookieName ) {
581 # Check for a simple string match, like the way squid does it
582 if ( strpos( $cookieHeader, $cookieName ) ) {
583 wfDebug( __METHOD__
.": found $cookieName\n" );
587 wfDebug( __METHOD__
.": no cache-varying cookies found\n" );
591 /** Get a complete X-Vary-Options header */
592 public function getXVO() {
593 global $wgCookiePrefix;
594 $cvCookies = $this->getCacheVaryCookies();
595 $xvo = 'X-Vary-Options: Accept-Encoding;list-contains=gzip,Cookie;';
597 foreach ( $cvCookies as $cookieName ) {
603 $xvo .= 'string-contains=' . $cookieName;
608 public function sendCacheControl() {
609 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
610 $fname = 'OutputPage::sendCacheControl';
612 $response = $wgRequest->response();
613 if ($wgUseETag && $this->mETag
)
614 $response->header("ETag: $this->mETag");
616 # don't serve compressed data to clients who can't handle it
617 # maintain different caches for logged-in users and non-logged in ones
618 $response->header( 'Vary: Accept-Encoding, Cookie' );
620 # Add an X-Vary-Options header for Squid with Wikimedia patches
621 $response->header( $this->getXVO() );
623 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache
) {
624 if( $wgUseSquid && session_id() == '' &&
625 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 && !$this->haveCacheVaryCookies() )
628 # We'll purge the proxy cache explicitly, but require end user agents
629 # to revalidate against the proxy on each visit.
630 # Surrogate-Control controls our Squid, Cache-Control downstream caches
631 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
632 # start with a shorter timeout for initial testing
633 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
634 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
635 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
637 # We'll purge the proxy cache for anons explicitly, but require end user agents
638 # to revalidate against the proxy on each visit.
639 # IMPORTANT! The Squid needs to replace the Cache-Control header with
640 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
641 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
642 # start with a shorter timeout for initial testing
643 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
644 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
647 # We do want clients to cache if they can, but they *must* check for updates
648 # on revisiting the page.
649 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
650 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
651 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
653 if($this->mLastModified
) $response->header( "Last-modified: {$this->mLastModified}" );
655 wfDebug( "$fname: no caching **\n", false );
657 # In general, the absence of a last modified header should be enough to prevent
658 # the client from using its cache. We send a few other things just to make sure.
659 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
660 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
661 $response->header( 'Pragma: no-cache' );
666 * Finally, all the text has been munged and accumulated into
667 * the object, let's actually output it:
669 public function output() {
670 global $wgUser, $wgOutputEncoding, $wgRequest;
671 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
672 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
673 global $wgServer, $wgStyleVersion, $wgEnableMWSuggest;
675 if( $this->mDoNothing
){
678 $fname = 'OutputPage::output';
679 wfProfileIn( $fname );
681 if ( '' != $this->mRedirect
) {
682 # Standards require redirect URLs to be absolute
683 $this->mRedirect
= wfExpandUrl( $this->mRedirect
);
684 if( $this->mRedirectCode
== '301') {
685 if( !$wgDebugRedirects ) {
686 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
688 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
691 $this->sendCacheControl();
693 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
694 if( $wgDebugRedirects ) {
695 $url = htmlspecialchars( $this->mRedirect
);
696 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
697 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
698 print "</body>\n</html>\n";
700 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
702 wfProfileOut( $fname );
705 elseif ( $this->mStatusCode
)
707 $statusMessage = array(
709 101 => 'Switching Protocols',
714 203 => 'Non-Authoritative Information',
716 205 => 'Reset Content',
717 206 => 'Partial Content',
718 207 => 'Multi-Status',
719 300 => 'Multiple Choices',
720 301 => 'Moved Permanently',
723 304 => 'Not Modified',
725 307 => 'Temporary Redirect',
726 400 => 'Bad Request',
727 401 => 'Unauthorized',
728 402 => 'Payment Required',
731 405 => 'Method Not Allowed',
732 406 => 'Not Acceptable',
733 407 => 'Proxy Authentication Required',
734 408 => 'Request Timeout',
737 411 => 'Length Required',
738 412 => 'Precondition Failed',
739 413 => 'Request Entity Too Large',
740 414 => 'Request-URI Too Large',
741 415 => 'Unsupported Media Type',
742 416 => 'Request Range Not Satisfiable',
743 417 => 'Expectation Failed',
744 422 => 'Unprocessable Entity',
746 424 => 'Failed Dependency',
747 500 => 'Internal Server Error',
748 501 => 'Not Implemented',
749 502 => 'Bad Gateway',
750 503 => 'Service Unavailable',
751 504 => 'Gateway Timeout',
752 505 => 'HTTP Version Not Supported',
753 507 => 'Insufficient Storage'
756 if ( $statusMessage[$this->mStatusCode
] )
757 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
760 $sk = $wgUser->getSkin();
763 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
765 wfRunHooks( 'AjaxAddScript', array( &$this ) );
767 if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) {
768 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
769 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
772 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
773 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
776 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
777 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/mwsuggest.js?$wgStyleVersion\"></script>\n" );
782 # Buffer output; final headers may depend on later processing
785 # Disable temporary placeholders, so that the skin produces HTML
786 $sk->postParseLinkColour( false );
788 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
789 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
791 if ($this->mArticleBodyOnly
) {
792 $this->out($this->mBodytext
);
794 // Hook that allows last minute changes to the output page, e.g.
795 // adding of CSS or Javascript by extensions.
796 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
798 wfProfileIn( 'Output-skin' );
799 $sk->outputPage( $this );
800 wfProfileOut( 'Output-skin' );
803 $this->sendCacheControl();
805 wfProfileOut( $fname );
812 public function out( $ins ) {
813 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
814 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
817 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
818 if ( false === $outs ) { $outs = $ins; }
826 public static function setEncodings() {
827 global $wgInputEncoding, $wgOutputEncoding;
828 global $wgUser, $wgContLang;
830 $wgInputEncoding = strtolower( $wgInputEncoding );
832 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
833 $wgOutputEncoding = strtolower( $wgOutputEncoding );
836 $wgOutputEncoding = $wgInputEncoding;
840 * Deprecated, use wfReportTime() instead.
844 public function reportTime() {
845 $time = wfReportTime();
850 * Produce a "user is blocked" page.
852 * @param bool $return Whether to have a "return to $wgTitle" message or not.
855 function blockedPage( $return = true ) {
856 global $wgUser, $wgContLang, $wgTitle, $wgLang;
858 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
859 $this->setRobotpolicy( 'noindex,nofollow' );
860 $this->setArticleRelated( false );
862 $name = User
::whoIs( $wgUser->blockedBy() );
863 $reason = $wgUser->blockedFor();
864 if( $reason == '' ) {
865 $reason = wfMsg( 'blockednoreason' );
867 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
870 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
872 $blockid = $wgUser->mBlock
->mId
;
874 $blockExpiry = $wgUser->mBlock
->mExpiry
;
875 if ( $blockExpiry == 'infinity' ) {
876 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
877 // Search for localization in 'ipboptions'
878 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
879 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
880 if ( strpos( $option, ":" ) === false )
882 list( $show, $value ) = explode( ":", $option );
883 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
884 $blockExpiry = $show;
889 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
892 if ( $wgUser->mBlock
->mAuto
) {
893 $msg = 'autoblockedtext';
895 $msg = 'blockedtext';
898 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
899 * This could be a username, an ip range, or a single ip. */
900 $intended = $wgUser->mBlock
->mAddress
;
902 $this->addWikiMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
904 # Don't auto-return to special pages
906 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
907 $this->returnToMain( false, $return );
912 * Output a standard error page
914 * @param string $title Message key for page title
915 * @param string $msg Message key for page text
916 * @param array $params Message parameters
918 public function showErrorPage( $title, $msg, $params = array() ) {
920 if ( isset($wgTitle) ) {
921 $this->mDebugtext
.= 'Original title: ' . $wgTitle->getPrefixedText() . "\n";
923 $this->setPageTitle( wfMsg( $title ) );
924 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
925 $this->setRobotpolicy( 'noindex,nofollow' );
926 $this->setArticleRelated( false );
927 $this->enableClientCache( false );
928 $this->mRedirect
= '';
929 $this->mBodytext
= '';
931 array_unshift( $params, 'parse' );
932 array_unshift( $params, $msg );
933 $this->addHtml( call_user_func_array( 'wfMsgExt', $params ) );
935 $this->returnToMain( false );
939 * Output a standard permission error page
941 * @param array $errors Error message keys
943 public function showPermissionsErrorPage( $errors )
947 $this->mDebugtext
.= 'Original title: ' .
948 $wgTitle->getPrefixedText() . "\n";
949 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
950 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
951 $this->setRobotpolicy( 'noindex,nofollow' );
952 $this->setArticleRelated( false );
953 $this->enableClientCache( false );
954 $this->mRedirect
= '';
955 $this->mBodytext
= '';
956 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors ) );
960 public function errorpage( $title, $msg ) {
961 throw new ErrorPageError( $title, $msg );
965 * Display an error page indicating that a given version of MediaWiki is
968 * @param mixed $version The version of MediaWiki needed to use the page
970 public function versionRequired( $version ) {
971 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
972 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
973 $this->setRobotpolicy( 'noindex,nofollow' );
974 $this->setArticleRelated( false );
975 $this->mBodytext
= '';
977 $this->addWikiMsg( 'versionrequiredtext', $version );
978 $this->returnToMain();
982 * Display an error page noting that a given permission bit is required.
984 * @param string $permission key required
986 public function permissionRequired( $permission ) {
987 global $wgGroupPermissions, $wgUser;
989 $this->setPageTitle( wfMsg( 'badaccess' ) );
990 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
991 $this->setRobotpolicy( 'noindex,nofollow' );
992 $this->setArticleRelated( false );
993 $this->mBodytext
= '';
996 foreach( $wgGroupPermissions as $key => $value ) {
997 if( isset( $value[$permission] ) && $value[$permission] == true ) {
998 $groupName = User
::getGroupName( $key );
999 $groupPage = User
::getGroupPage( $key );
1001 $skin = $wgUser->getSkin();
1002 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
1004 $groups[] = $groupName;
1008 $n = count( $groups );
1009 $groups = implode( ', ', $groups );
1014 $message = wfMsgHtml( "badaccess-group$n", $groups );
1017 $message = wfMsgHtml( 'badaccess-groups', $groups );
1019 $this->addHtml( $message );
1020 $this->returnToMain( false );
1024 * Use permissionRequired.
1027 public function sysopRequired() {
1028 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
1032 * Use permissionRequired.
1035 public function developerRequired() {
1036 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
1040 * Produce the stock "please login to use the wiki" page
1042 public function loginToUse() {
1043 global $wgUser, $wgTitle, $wgContLang;
1045 if( $wgUser->isLoggedIn() ) {
1046 $this->permissionRequired( 'read' );
1050 $skin = $wgUser->getSkin();
1052 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1053 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1054 $this->setRobotPolicy( 'noindex,nofollow' );
1055 $this->setArticleFlag( false );
1057 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1058 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1059 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1060 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
1062 # Don't return to the main page if the user can't read it
1063 # otherwise we'll end up in a pointless loop
1064 $mainPage = Title
::newMainPage();
1065 if( $mainPage->userCanRead() )
1066 $this->returnToMain( true, $mainPage );
1070 public function databaseError( $fname, $sql, $error, $errno ) {
1071 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1075 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
1076 * @return string The wikitext error-messages, formatted into a list.
1078 public function formatPermissionsErrorMessage( $errors ) {
1079 $text = wfMsgNoTrans( 'permissionserrorstext', count( $errors ) ) . "\n\n";
1081 if (count( $errors ) > 1) {
1082 $text .= '<ul class="permissions-errors">' . "\n";
1084 foreach( $errors as $error )
1087 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1092 $text .= '<div class="permissions-errors">' . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . '</div>';
1099 * Display a page stating that the Wiki is in read-only mode,
1100 * and optionally show the source of the page that the user
1101 * was trying to edit. Should only be called (for this
1102 * purpose) after wfReadOnly() has returned true.
1104 * For historical reasons, this function is _also_ used to
1105 * show the error message when a user tries to edit a page
1106 * they are not allowed to edit. (Unless it's because they're
1107 * blocked, then we show blockedPage() instead.) In this
1108 * case, the second parameter should be set to true and a list
1109 * of reasons supplied as the third parameter.
1111 * @todo Needs to be split into multiple functions.
1113 * @param string $source Source code to show (or null).
1114 * @param bool $protected Is this a permissions error?
1115 * @param array $reasons List of reasons for this error, as returned by Title::getUserPermissionsErrors().
1117 public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
1118 global $wgUser, $wgTitle;
1119 $skin = $wgUser->getSkin();
1121 $this->setRobotpolicy( 'noindex,nofollow' );
1122 $this->setArticleRelated( false );
1124 // If no reason is given, just supply a default "I can't let you do
1125 // that, Dave" message. Should only occur if called by legacy code.
1126 if ( $protected && empty($reasons) ) {
1127 $reasons[] = array( 'badaccess-group0' );
1130 if ( !empty($reasons) ) {
1131 // Permissions error
1133 $this->setPageTitle( wfMsg( 'viewsource' ) );
1134 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1136 $this->setPageTitle( wfMsg( 'badaccess' ) );
1138 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) );
1140 // Wiki is read only
1141 $this->setPageTitle( wfMsg( 'readonly' ) );
1142 $reason = wfReadOnlyReason();
1143 $this->addWikiMsg( 'readonlytext', $reason );
1146 // Show source, if supplied
1147 if( is_string( $source ) ) {
1148 $this->addWikiMsg( 'viewsourcetext' );
1149 $text = wfOpenElement( 'textarea',
1150 array( 'id' => 'wpTextbox1',
1151 'name' => 'wpTextbox1',
1152 'cols' => $wgUser->getOption( 'cols' ),
1153 'rows' => $wgUser->getOption( 'rows' ),
1154 'readonly' => 'readonly' ) );
1155 $text .= htmlspecialchars( $source );
1156 $text .= wfCloseElement( 'textarea' );
1157 $this->addHTML( $text );
1159 // Show templates used by this article
1160 $skin = $wgUser->getSkin();
1161 $article = new Article( $wgTitle );
1162 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1165 # If the title doesn't exist, it's fairly pointless to print a return
1166 # link to it. After all, you just tried editing it and couldn't, so
1167 # what's there to do there?
1168 if( $wgTitle->exists() ) {
1169 $this->returnToMain( false, $wgTitle );
1174 public function fatalError( $message ) {
1175 throw new FatalError( $message );
1179 public function unexpectedValueError( $name, $val ) {
1180 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1184 public function fileCopyError( $old, $new ) {
1185 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1189 public function fileRenameError( $old, $new ) {
1190 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1194 public function fileDeleteError( $name ) {
1195 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1199 public function fileNotFoundError( $name ) {
1200 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1203 public function showFatalError( $message ) {
1204 $this->setPageTitle( wfMsg( "internalerror" ) );
1205 $this->setRobotpolicy( "noindex,nofollow" );
1206 $this->setArticleRelated( false );
1207 $this->enableClientCache( false );
1208 $this->mRedirect
= '';
1209 $this->mBodytext
= $message;
1212 public function showUnexpectedValueError( $name, $val ) {
1213 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1216 public function showFileCopyError( $old, $new ) {
1217 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1220 public function showFileRenameError( $old, $new ) {
1221 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1224 public function showFileDeleteError( $name ) {
1225 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1228 public function showFileNotFoundError( $name ) {
1229 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1233 * Add a "return to" link pointing to a specified title
1235 * @param Title $title Title to link
1237 public function addReturnTo( $title ) {
1239 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1240 $this->addHtml( "<p>{$link}</p>\n" );
1244 * Add a "return to" link pointing to a specified title,
1245 * or the title indicated in the request, or else the main page
1247 * @param null $unused No longer used
1248 * @param Title $returnto Title to return to
1250 public function returnToMain( $unused = null, $returnto = NULL ) {
1253 if ( $returnto == NULL ) {
1254 $returnto = $wgRequest->getText( 'returnto' );
1257 if ( '' === $returnto ) {
1258 $returnto = Title
::newMainPage();
1261 if ( is_object( $returnto ) ) {
1262 $titleObj = $returnto;
1264 $titleObj = Title
::newFromText( $returnto );
1266 if ( !is_object( $titleObj ) ) {
1267 $titleObj = Title
::newMainPage();
1270 $this->addReturnTo( $titleObj );
1274 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1275 * and uses the first 10 of them for META keywords
1277 * @param ParserOutput &$parserOutput
1279 private function addKeywords( &$parserOutput ) {
1281 $this->addKeyword( $wgTitle->getPrefixedText() );
1283 $links2d =& $parserOutput->getLinks();
1284 if ( !is_array( $links2d ) ) {
1287 foreach ( $links2d as $dbkeys ) {
1288 foreach( $dbkeys as $dbkey => $unused ) {
1289 $this->addKeyword( $dbkey );
1290 if ( ++
$count > 10 ) {
1298 * @return string The doctype, opening <html>, and head element.
1300 public function headElement() {
1301 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1302 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1303 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1305 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1306 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1311 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1313 if ( '' == $this->getHTMLTitle() ) {
1314 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1317 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1318 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1319 foreach($wgXhtmlNamespaces as $tag => $ns) {
1320 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1322 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1323 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1324 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1326 $ret .= $this->getHeadLinks();
1327 global $wgStylePath;
1328 if( $this->isPrintable() ) {
1331 $media = "media='print'";
1333 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1334 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1336 $sk = $wgUser->getSkin();
1337 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1338 $ret .= $this->mScripts
;
1339 $ret .= $sk->getUserStyles();
1340 $ret .= $this->getHeadItems();
1342 if ($wgUseTrackbacks && $this->isArticleRelated())
1343 $ret .= $wgTitle->trackbackRDF();
1345 $ret .= "</head>\n";
1350 * @return string HTML tag links to be put in the header.
1352 public function getHeadLinks() {
1353 global $wgRequest, $wgFeed;
1355 foreach ( $this->mMetatags
as $tag ) {
1356 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1358 $tag[0] = substr( $tag[0], 5 );
1362 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1365 $p = $this->mRobotpolicy
;
1366 if( $p !== '' && $p != 'index,follow' ) {
1367 // http://www.robotstxt.org/wc/meta-user.html
1368 // Only show if it's different from the default robots policy
1369 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1372 if ( count( $this->mKeywords
) > 0 ) {
1377 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1378 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1380 foreach ( $this->mLinktags
as $tag ) {
1381 $ret .= "\t\t<link";
1382 foreach( $tag as $attr => $val ) {
1383 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1389 foreach( $this->getSyndicationLinks() as $format => $link ) {
1390 # Use the page name for the title (accessed through $wgTitle since
1391 # there's no other way). In principle, this could lead to issues
1392 # with having the same name for different feeds corresponding to
1393 # the same page, but we can't avoid that at this low a level.
1396 $ret .= $this->feedLink(
1399 wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) ); # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
1402 # Recent changes feed should appear on every page
1403 # Put it after the per-page feed to avoid changing existing behavior.
1404 # It's still available, probably via a menu in your browser.
1406 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
1407 $ret .= $this->feedLink(
1409 $rctitle->getFullURL( 'feed=rss' ),
1410 wfMsg( 'site-rss-feed', $wgSitename ) );
1411 $ret .= $this->feedLink(
1413 $rctitle->getFullURL( 'feed=atom' ),
1414 wfMsg( 'site-atom-feed', $wgSitename ) );
1421 * Return URLs for each supported syndication format for this page.
1422 * @return array associating format keys with URLs
1424 public function getSyndicationLinks() {
1425 global $wgTitle, $wgFeedClasses;
1428 if( $this->isSyndicated() ) {
1429 if( is_string( $this->getFeedAppendQuery() ) ) {
1430 $appendQuery = "&" . $this->getFeedAppendQuery();
1435 foreach( $wgFeedClasses as $format => $class ) {
1436 $links[$format] = $wgTitle->getLocalUrl( "feed=$format{$appendQuery}" );
1443 * Generate a <link rel/> for an RSS feed.
1445 private function feedLink( $type, $url, $text ) {
1446 return Xml
::element( 'link', array(
1447 'rel' => 'alternate',
1448 'type' => "application/$type+xml",
1450 'href' => $url ) ) . "\n";
1454 * Turn off regular page output and return an error reponse
1455 * for when rate limiting has triggered.
1457 public function rateLimited() {
1458 global $wgOut, $wgTitle;
1460 $this->setPageTitle(wfMsg('actionthrottled'));
1461 $this->setRobotPolicy( 'noindex,follow' );
1462 $this->setArticleRelated( false );
1463 $this->enableClientCache( false );
1464 $this->mRedirect
= '';
1466 $this->setStatusCode(503);
1467 $this->addWikiMsg( 'actionthrottledtext' );
1469 $this->returnToMain( false, $wgTitle );
1473 * Show an "add new section" link?
1477 public function showNewSectionLink() {
1478 return $this->mNewSectionLink
;
1482 * Show a warning about slave lag
1484 * If the lag is higher than $wgSlaveLagCritical seconds,
1485 * then the warning is a bit more obvious. If the lag is
1486 * lower than $wgSlaveLagWarning, then no warning is shown.
1488 * @param int $lag Slave lag
1490 public function showLagWarning( $lag ) {
1491 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1492 if( $lag >= $wgSlaveLagWarning ) {
1493 $message = $lag < $wgSlaveLagCritical
1496 $warning = wfMsgExt( $message, 'parse', $lag );
1497 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );
1502 * Add a wikitext-formatted message to the output.
1503 * This is equivalent to:
1505 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
1507 public function addWikiMsg( /*...*/ ) {
1508 $args = func_get_args();
1509 $name = array_shift( $args );
1510 $this->addWikiMsgArray( $name, $args );
1514 * Add a wikitext-formatted message to the output.
1515 * Like addWikiMsg() except the parameters are taken as an array
1516 * instead of a variable argument list.
1518 * $options is passed through to wfMsgExt(), see that function for details.
1520 public function addWikiMsgArray( $name, $args, $options = array() ) {
1521 $options[] = 'parse';
1522 $text = wfMsgExt( $name, $options, $args );
1523 $this->addHTML( $text );
1527 * This function takes a number of message/argument specifications, wraps them in
1528 * some overall structure, and then parses the result and adds it to the output.
1530 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
1531 * on. The subsequent arguments may either be strings, in which case they are the
1532 * message names, or an arrays, in which case the first element is the message name,
1533 * and subsequent elements are the parameters to that message.
1535 * The special named parameter 'options' in a message specification array is passed
1536 * through to the $options parameter of wfMsgExt().
1540 * $wgOut->wrapWikiMsg( '<div class="error">$1</div>', 'some-error' );
1544 * $wgOut->addWikiText( '<div class="error">' . wfMsgNoTrans( 'some-error' ) . '</div>' );
1546 public function wrapWikiMsg( $wrap /*, ...*/ ) {
1547 $msgSpecs = func_get_args();
1548 array_shift( $msgSpecs );
1549 $msgSpecs = array_values( $msgSpecs );
1551 foreach ( $msgSpecs as $n => $spec ) {
1553 if ( is_array( $spec ) ) {
1555 $name = array_shift( $args );
1556 if ( isset( $args['options'] ) ) {
1557 $options = $args['options'];
1558 unset( $args['options'] );
1564 $s = str_replace( '$' . ($n+
1), wfMsgExt( $name, $options, $args ), $s );
1566 $this->addHTML( $this->parse( $s ) );