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;
149 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
150 wfDebug( __METHOD__
. ": CACHE DISABLED, NO TIMESTAMP\n" );
153 if( !$wgCachePages ) {
154 wfDebug( __METHOD__
. ": CACHE DISABLED\n", false );
157 if( $wgUser->getOption( 'nocache' ) ) {
158 wfDebug( __METHOD__
. ": USER DISABLED CACHE\n", false );
162 $timestamp=wfTimestamp(TS_MW
,$timestamp);
163 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
165 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
166 # IE sends sizes after the date like this:
167 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
168 # this breaks strtotime().
169 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
171 wfSuppressWarnings(); // E_STRICT system time bitching
172 $modsinceTime = strtotime( $modsince );
175 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
176 wfDebug( __METHOD__
. ": -- client send If-Modified-Since: " . $modsince . "\n", false );
177 wfDebug( __METHOD__
. ": -- we might send Last-Modified : $lastmod\n", false );
178 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
179 # Make sure you're in a place you can leave when you call us!
180 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
181 $this->mLastModified
= $lastmod;
182 $this->sendCacheControl();
183 wfDebug( __METHOD__
. ": CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
186 // Don't output a compressed blob when using ob_gzhandler;
187 // it's technically against HTTP spec and seems to confuse
188 // Firefox when the response gets split over two packets.
189 wfClearOutputBuffers();
193 wfDebug( __METHOD__
. ": READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
194 $this->mLastModified
= $lastmod;
197 wfDebug( __METHOD__
. ": client did not send If-Modified-Since header\n", false );
198 $this->mLastModified
= $lastmod;
202 function setPageTitleActionText( $text ) {
203 $this->mPageTitleActionText
= $text;
206 function getPageTitleActionText () {
207 if ( isset( $this->mPageTitleActionText
) ) {
208 return $this->mPageTitleActionText
;
212 public function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
213 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
214 public function setPageTitle( $name ) {
215 global $action, $wgContLang;
216 $name = $wgContLang->convert($name, true);
217 $this->mPagetitle
= $name;
218 if(!empty($action)) {
219 $taction = $this->getPageTitleActionText();
220 if( !empty( $taction ) ) {
221 $name .= ' - '.$taction;
225 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
227 public function getHTMLTitle() { return $this->mHTMLtitle
; }
228 public function getPageTitle() { return $this->mPagetitle
; }
229 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
230 public function getSubtitle() { return $this->mSubtitle
; }
231 public function isArticle() { return $this->mIsarticle
; }
232 public function setPrintable() { $this->mPrintable
= true; }
233 public function isPrintable() { return $this->mPrintable
; }
234 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
235 public function isSyndicated() { return $this->mShowFeedLinks
; }
236 public function setFeedAppendQuery( $val ) { $this->mFeedLinksAppendQuery
= $val; }
237 public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery
; }
238 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
239 public function getOnloadHandler() { return $this->mOnloadHandler
; }
240 public function disable() { $this->mDoNothing
= true; }
242 public function setArticleRelated( $v ) {
243 $this->mIsArticleRelated
= $v;
245 $this->mIsarticle
= false;
248 public function setArticleFlag( $v ) {
249 $this->mIsarticle
= $v;
251 $this->mIsArticleRelated
= $v;
255 public function isArticleRelated() { return $this->mIsArticleRelated
; }
257 public function getLanguageLinks() { return $this->mLanguageLinks
; }
258 public function addLanguageLinks($newLinkArray) {
259 $this->mLanguageLinks +
= $newLinkArray;
261 public function setLanguageLinks($newLinkArray) {
262 $this->mLanguageLinks
= $newLinkArray;
265 public function getCategoryLinks() {
266 return $this->mCategoryLinks
;
270 * Add an array of categories, with names in the keys
272 public function addCategoryLinks( $categories ) {
273 global $wgUser, $wgContLang;
275 if ( !is_array( $categories ) ||
count( $categories ) == 0 ) {
279 # Add the links to a LinkBatch
280 $arr = array( NS_CATEGORY
=> $categories );
282 $lb->setArray( $arr );
284 # Fetch existence plus the hiddencat property
285 $dbr = wfGetDB( DB_SLAVE
);
286 $pageTable = $dbr->tableName( 'page' );
287 $where = $lb->constructSet( 'page', $dbr );
288 $propsTable = $dbr->tableName( 'page_props' );
289 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, pp_value
290 FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
291 $res = $dbr->query( $sql, __METHOD__
);
293 # Add the results to the link cache
294 $lb->addResultToCache( LinkCache
::singleton(), $res );
296 # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
297 $categories = array_combine( array_keys( $categories ),
298 array_fill( 0, count( $categories ), 'normal' ) );
300 # Mark hidden categories
301 foreach ( $res as $row ) {
302 if ( isset( $row->pp_value
) ) {
303 $categories[$row->page_title
] = 'hidden';
307 # Add the remaining categories to the skin
308 $sk = $wgUser->getSkin();
309 foreach ( $categories as $category => $type ) {
310 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
311 $text = $wgContLang->convertHtml( $title->getText() );
312 $this->mCategoryLinks
[$type][] = $sk->makeLinkObj( $title, $text );
316 public function setCategoryLinks($categories) {
317 $this->mCategoryLinks
= array();
318 $this->addCategoryLinks($categories);
321 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
322 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
324 public function disallowUserJs() { $this->mAllowUserJs
= false; }
325 public function isUserJsAllowed() { return $this->mAllowUserJs
; }
327 public function addHTML( $text ) { $this->mBodytext
.= $text; }
328 public function clearHTML() { $this->mBodytext
= ''; }
329 public function getHTML() { return $this->mBodytext
; }
330 public function debug( $text ) { $this->mDebugtext
.= $text; }
333 public function setParserOptions( $options ) {
334 wfDeprecated( __METHOD__
);
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 wfProfileIn( __METHOD__
);
382 wfIncrStats( 'pcache_not_possible' );
384 $popts = $this->parserOptions();
385 $oldTidy = $popts->setTidy( $tidy );
387 $parserOutput = $wgParser->parse( $text, $title, $popts,
388 $linestart, true, $this->mRevisionId
);
390 $popts->setTidy( $oldTidy );
392 $this->addParserOutput( $parserOutput );
394 wfProfileOut( __METHOD__
);
399 * @param ParserOutput object &$parserOutput
401 public function addParserOutputNoText( &$parserOutput ) {
402 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
403 $this->addCategoryLinks( $parserOutput->getCategories() );
404 $this->mNewSectionLink
= $parserOutput->getNewSection();
405 $this->addKeywords( $parserOutput );
406 $this->mParseWarnings
= $parserOutput->getWarnings();
407 if ( $parserOutput->getCacheTime() == -1 ) {
408 $this->enableClientCache( false );
410 $this->mNoGallery
= $parserOutput->getNoGallery();
411 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
413 $this->mTemplateIds +
= (array)$parserOutput->mTemplateIds
;
416 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
417 $this->setPageTitle( $dt );
419 // Hooks registered in the object
420 global $wgParserOutputHooks;
421 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
422 list( $hookName, $data ) = $hookInfo;
423 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
424 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
428 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
433 * @param ParserOutput &$parserOutput
435 function addParserOutput( &$parserOutput ) {
436 $this->addParserOutputNoText( $parserOutput );
437 $text = $parserOutput->getText();
438 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
439 $this->addHTML( $text );
443 * Add wikitext to the buffer, assuming that this is the primary text for a page view
444 * Saves the text into the parser cache if possible.
446 * @param string $text
447 * @param Article $article
449 * @deprecated Use Article::outputWikitext
451 public function addPrimaryWikiText( $text, $article, $cache = true ) {
452 global $wgParser, $wgUser;
454 wfDeprecated( __METHOD__
);
456 $popts = $this->parserOptions();
457 $popts->setTidy(true);
458 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
459 $popts, true, true, $this->mRevisionId
);
460 $popts->setTidy(false);
461 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
462 $parserCache = ParserCache
::singleton();
463 $parserCache->save( $parserOutput, $article, $wgUser );
466 $this->addParserOutput( $parserOutput );
470 * @deprecated use addWikiTextTidy()
472 public function addSecondaryWikiText( $text, $linestart = true ) {
474 wfDeprecated( __METHOD__
);
475 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
479 * Add wikitext with tidy enabled
481 public function addWikiTextTidy( $text, $linestart = true ) {
483 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
488 * Add the output of a QuickTemplate to the output buffer
490 * @param QuickTemplate $template
492 public function addTemplate( &$template ) {
494 $template->execute();
495 $this->addHTML( ob_get_contents() );
500 * Parse wikitext and return the HTML.
502 * @param string $text
503 * @param bool $linestart Is this the start of a line?
504 * @param bool $interface ??
506 public function parse( $text, $linestart = true, $interface = false ) {
507 global $wgParser, $wgTitle;
508 $popts = $this->parserOptions();
509 if ( $interface) { $popts->setInterfaceMessage(true); }
510 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
511 $linestart, true, $this->mRevisionId
);
512 if ( $interface) { $popts->setInterfaceMessage(false); }
513 return $parserOutput->getText();
517 * @param Article $article
520 * @return bool True if successful, else false.
522 public function tryParserCache( &$article, $user ) {
523 $parserCache = ParserCache
::singleton();
524 $parserOutput = $parserCache->get( $article, $user );
525 if ( $parserOutput !== false ) {
526 $this->addParserOutput( $parserOutput );
534 * @param int $maxage Maximum cache time on the Squid, in seconds.
536 public function setSquidMaxage( $maxage ) {
537 $this->mSquidMaxage
= $maxage;
541 * Use enableClientCache(false) to force it to send nocache headers
544 public function enableClientCache( $state ) {
545 return wfSetVar( $this->mEnableClientCache
, $state );
548 function getCacheVaryCookies() {
549 global $wgCookiePrefix, $wgCacheVaryCookies;
551 if ( $cookies === null ) {
552 $cookies = array_merge(
554 "{$wgCookiePrefix}Token",
555 "{$wgCookiePrefix}LoggedOut",
560 wfRunHooks('GetCacheVaryCookies', array( $this, &$cookies ) );
565 function uncacheableBecauseRequestVars() {
567 return $wgRequest->getText('useskin', false) === false
568 && $wgRequest->getText('uselang', false) === false;
572 * Check if the request has a cache-varying cookie header
573 * If it does, it's very important that we don't allow public caching
575 function haveCacheVaryCookies() {
576 global $wgRequest, $wgCookiePrefix;
577 $cookieHeader = $wgRequest->getHeader( 'cookie' );
578 if ( $cookieHeader === false ) {
581 $cvCookies = $this->getCacheVaryCookies();
582 foreach ( $cvCookies as $cookieName ) {
583 # Check for a simple string match, like the way squid does it
584 if ( strpos( $cookieHeader, $cookieName ) ) {
585 wfDebug( __METHOD__
.": found $cookieName\n" );
589 wfDebug( __METHOD__
.": no cache-varying cookies found\n" );
593 /** Get a complete X-Vary-Options header */
594 public function getXVO() {
595 global $wgCookiePrefix;
596 $cvCookies = $this->getCacheVaryCookies();
597 $xvo = 'X-Vary-Options: Accept-Encoding;list-contains=gzip,Cookie;';
599 foreach ( $cvCookies as $cookieName ) {
605 $xvo .= 'string-contains=' . $cookieName;
610 public function sendCacheControl() {
611 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
613 $response = $wgRequest->response();
614 if ($wgUseETag && $this->mETag
)
615 $response->header("ETag: $this->mETag");
617 # don't serve compressed data to clients who can't handle it
618 # maintain different caches for logged-in users and non-logged in ones
619 $response->header( 'Vary: Accept-Encoding, Cookie' );
621 # Add an X-Vary-Options header for Squid with Wikimedia patches
622 $response->header( $this->getXVO() );
624 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache
) {
625 if( $wgUseSquid && session_id() == '' &&
626 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 && !$this->haveCacheVaryCookies() )
629 # We'll purge the proxy cache explicitly, but require end user agents
630 # to revalidate against the proxy on each visit.
631 # Surrogate-Control controls our Squid, Cache-Control downstream caches
632 wfDebug( __METHOD__
. ": proxy caching with ESI; {$this->mLastModified} **\n", false );
633 # start with a shorter timeout for initial testing
634 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
635 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
636 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
638 # We'll purge the proxy cache for anons explicitly, but require end user agents
639 # to revalidate against the proxy on each visit.
640 # IMPORTANT! The Squid needs to replace the Cache-Control header with
641 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
642 wfDebug( __METHOD__
. ": local proxy caching; {$this->mLastModified} **\n", false );
643 # start with a shorter timeout for initial testing
644 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
645 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
648 # We do want clients to cache if they can, but they *must* check for updates
649 # on revisiting the page.
650 wfDebug( __METHOD__
. ": private caching; {$this->mLastModified} **\n", false );
651 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
652 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
654 if($this->mLastModified
) $response->header( "Last-modified: {$this->mLastModified}" );
656 wfDebug( __METHOD__
. ": no caching **\n", false );
658 # In general, the absence of a last modified header should be enough to prevent
659 # the client from using its cache. We send a few other things just to make sure.
660 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
661 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
662 $response->header( 'Pragma: no-cache' );
667 * Finally, all the text has been munged and accumulated into
668 * the object, let's actually output it:
670 public function output() {
671 global $wgUser, $wgOutputEncoding, $wgRequest;
672 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
673 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
674 global $wgServer, $wgStyleVersion, $wgEnableMWSuggest;
676 if( $this->mDoNothing
){
680 wfProfileIn( __METHOD__
);
682 if ( '' != $this->mRedirect
) {
683 # Standards require redirect URLs to be absolute
684 $this->mRedirect
= wfExpandUrl( $this->mRedirect
);
685 if( $this->mRedirectCode
== '301') {
686 if( !$wgDebugRedirects ) {
687 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
689 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
692 $this->sendCacheControl();
694 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
695 if( $wgDebugRedirects ) {
696 $url = htmlspecialchars( $this->mRedirect
);
697 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
698 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
699 print "</body>\n</html>\n";
701 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
703 wfProfileOut( __METHOD__
);
706 elseif ( $this->mStatusCode
)
708 $statusMessage = array(
710 101 => 'Switching Protocols',
715 203 => 'Non-Authoritative Information',
717 205 => 'Reset Content',
718 206 => 'Partial Content',
719 207 => 'Multi-Status',
720 300 => 'Multiple Choices',
721 301 => 'Moved Permanently',
724 304 => 'Not Modified',
726 307 => 'Temporary Redirect',
727 400 => 'Bad Request',
728 401 => 'Unauthorized',
729 402 => 'Payment Required',
732 405 => 'Method Not Allowed',
733 406 => 'Not Acceptable',
734 407 => 'Proxy Authentication Required',
735 408 => 'Request Timeout',
738 411 => 'Length Required',
739 412 => 'Precondition Failed',
740 413 => 'Request Entity Too Large',
741 414 => 'Request-URI Too Large',
742 415 => 'Unsupported Media Type',
743 416 => 'Request Range Not Satisfiable',
744 417 => 'Expectation Failed',
745 422 => 'Unprocessable Entity',
747 424 => 'Failed Dependency',
748 500 => 'Internal Server Error',
749 501 => 'Not Implemented',
750 502 => 'Bad Gateway',
751 503 => 'Service Unavailable',
752 504 => 'Gateway Timeout',
753 505 => 'HTTP Version Not Supported',
754 507 => 'Insufficient Storage'
757 if ( $statusMessage[$this->mStatusCode
] )
758 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
761 $sk = $wgUser->getSkin();
764 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
766 wfRunHooks( 'AjaxAddScript', array( &$this ) );
768 if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) {
769 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
770 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
773 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
774 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
777 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
778 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/mwsuggest.js?$wgStyleVersion\"></script>\n" );
783 # Buffer output; final headers may depend on later processing
786 # Disable temporary placeholders, so that the skin produces HTML
787 $sk->postParseLinkColour( false );
789 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
790 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
792 if ($this->mArticleBodyOnly
) {
793 $this->out($this->mBodytext
);
795 // Hook that allows last minute changes to the output page, e.g.
796 // adding of CSS or Javascript by extensions.
797 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
799 wfProfileIn( 'Output-skin' );
800 $sk->outputPage( $this );
801 wfProfileOut( 'Output-skin' );
804 $this->sendCacheControl();
806 wfProfileOut( __METHOD__
);
813 public function out( $ins ) {
814 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
815 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
818 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
819 if ( false === $outs ) { $outs = $ins; }
827 public static function setEncodings() {
828 global $wgInputEncoding, $wgOutputEncoding;
829 global $wgUser, $wgContLang;
831 $wgInputEncoding = strtolower( $wgInputEncoding );
833 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
834 $wgOutputEncoding = strtolower( $wgOutputEncoding );
837 $wgOutputEncoding = $wgInputEncoding;
841 * Deprecated, use wfReportTime() instead.
845 public function reportTime() {
846 wfDeprecated( __METHOD__
);
847 $time = wfReportTime();
852 * Produce a "user is blocked" page.
854 * @param bool $return Whether to have a "return to $wgTitle" message or not.
857 function blockedPage( $return = true ) {
858 global $wgUser, $wgContLang, $wgTitle, $wgLang;
860 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
861 $this->setRobotpolicy( 'noindex,nofollow' );
862 $this->setArticleRelated( false );
864 $name = User
::whoIs( $wgUser->blockedBy() );
865 $reason = $wgUser->blockedFor();
866 if( $reason == '' ) {
867 $reason = wfMsg( 'blockednoreason' );
869 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
872 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
874 $blockid = $wgUser->mBlock
->mId
;
876 $blockExpiry = $wgUser->mBlock
->mExpiry
;
877 if ( $blockExpiry == 'infinity' ) {
878 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
879 // Search for localization in 'ipboptions'
880 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
881 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
882 if ( strpos( $option, ":" ) === false )
884 list( $show, $value ) = explode( ":", $option );
885 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
886 $blockExpiry = $show;
891 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
894 if ( $wgUser->mBlock
->mAuto
) {
895 $msg = 'autoblockedtext';
897 $msg = 'blockedtext';
900 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
901 * This could be a username, an ip range, or a single ip. */
902 $intended = $wgUser->mBlock
->mAddress
;
904 $this->addWikiMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
906 # Don't auto-return to special pages
908 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle : NULL;
909 $this->returnToMain( null, $return );
914 * Output a standard error page
916 * @param string $title Message key for page title
917 * @param string $msg Message key for page text
918 * @param array $params Message parameters
920 public function showErrorPage( $title, $msg, $params = array() ) {
922 if ( isset($wgTitle) ) {
923 $this->mDebugtext
.= 'Original title: ' . $wgTitle->getPrefixedText() . "\n";
925 $this->setPageTitle( wfMsg( $title ) );
926 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
927 $this->setRobotpolicy( 'noindex,nofollow' );
928 $this->setArticleRelated( false );
929 $this->enableClientCache( false );
930 $this->mRedirect
= '';
931 $this->mBodytext
= '';
933 array_unshift( $params, 'parse' );
934 array_unshift( $params, $msg );
935 $this->addHtml( call_user_func_array( 'wfMsgExt', $params ) );
937 $this->returnToMain();
941 * Output a standard permission error page
943 * @param array $errors Error message keys
945 public function showPermissionsErrorPage( $errors )
949 $this->mDebugtext
.= 'Original title: ' .
950 $wgTitle->getPrefixedText() . "\n";
951 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
952 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
953 $this->setRobotpolicy( 'noindex,nofollow' );
954 $this->setArticleRelated( false );
955 $this->enableClientCache( false );
956 $this->mRedirect
= '';
957 $this->mBodytext
= '';
958 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors ) );
962 public function errorpage( $title, $msg ) {
963 wfDeprecated( __METHOD__
);
964 throw new ErrorPageError( $title, $msg );
968 * Display an error page indicating that a given version of MediaWiki is
971 * @param mixed $version The version of MediaWiki needed to use the page
973 public function versionRequired( $version ) {
974 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
975 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
976 $this->setRobotpolicy( 'noindex,nofollow' );
977 $this->setArticleRelated( false );
978 $this->mBodytext
= '';
980 $this->addWikiMsg( 'versionrequiredtext', $version );
981 $this->returnToMain();
985 * Display an error page noting that a given permission bit is required.
987 * @param string $permission key required
989 public function permissionRequired( $permission ) {
990 global $wgGroupPermissions, $wgUser;
992 $this->setPageTitle( wfMsg( 'badaccess' ) );
993 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
994 $this->setRobotpolicy( 'noindex,nofollow' );
995 $this->setArticleRelated( false );
996 $this->mBodytext
= '';
999 foreach( $wgGroupPermissions as $key => $value ) {
1000 if( isset( $value[$permission] ) && $value[$permission] == true ) {
1001 $groupName = User
::getGroupName( $key );
1002 $groupPage = User
::getGroupPage( $key );
1004 $skin = $wgUser->getSkin();
1005 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
1007 $groups[] = $groupName;
1011 $n = count( $groups );
1012 $groups = implode( ', ', $groups );
1017 $message = wfMsgHtml( "badaccess-group$n", $groups );
1020 $message = wfMsgHtml( 'badaccess-groups', $groups );
1022 $this->addHtml( $message );
1023 $this->returnToMain();
1027 * Use permissionRequired.
1030 public function sysopRequired() {
1031 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
1035 * Use permissionRequired.
1038 public function developerRequired() {
1039 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
1043 * Produce the stock "please login to use the wiki" page
1045 public function loginToUse() {
1046 global $wgUser, $wgTitle, $wgContLang;
1048 if( $wgUser->isLoggedIn() ) {
1049 $this->permissionRequired( 'read' );
1053 $skin = $wgUser->getSkin();
1055 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1056 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1057 $this->setRobotPolicy( 'noindex,nofollow' );
1058 $this->setArticleFlag( false );
1060 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1061 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1062 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1063 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
1065 # Don't return to the main page if the user can't read it
1066 # otherwise we'll end up in a pointless loop
1067 $mainPage = Title
::newMainPage();
1068 if( $mainPage->userCanRead() )
1069 $this->returnToMain( null, $mainPage );
1073 public function databaseError( $fname, $sql, $error, $errno ) {
1074 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1078 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
1079 * @return string The wikitext error-messages, formatted into a list.
1081 public function formatPermissionsErrorMessage( $errors ) {
1082 $text = wfMsgNoTrans( 'permissionserrorstext', count( $errors ) ) . "\n\n";
1084 if (count( $errors ) > 1) {
1085 $text .= '<ul class="permissions-errors">' . "\n";
1087 foreach( $errors as $error )
1090 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1095 $text .= '<div class="permissions-errors">' . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . '</div>';
1102 * Display a page stating that the Wiki is in read-only mode,
1103 * and optionally show the source of the page that the user
1104 * was trying to edit. Should only be called (for this
1105 * purpose) after wfReadOnly() has returned true.
1107 * For historical reasons, this function is _also_ used to
1108 * show the error message when a user tries to edit a page
1109 * they are not allowed to edit. (Unless it's because they're
1110 * blocked, then we show blockedPage() instead.) In this
1111 * case, the second parameter should be set to true and a list
1112 * of reasons supplied as the third parameter.
1114 * @todo Needs to be split into multiple functions.
1116 * @param string $source Source code to show (or null).
1117 * @param bool $protected Is this a permissions error?
1118 * @param array $reasons List of reasons for this error, as returned by Title::getUserPermissionsErrors().
1120 public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
1121 global $wgUser, $wgTitle;
1122 $skin = $wgUser->getSkin();
1124 $this->setRobotpolicy( 'noindex,nofollow' );
1125 $this->setArticleRelated( false );
1127 // If no reason is given, just supply a default "I can't let you do
1128 // that, Dave" message. Should only occur if called by legacy code.
1129 if ( $protected && empty($reasons) ) {
1130 $reasons[] = array( 'badaccess-group0' );
1133 if ( !empty($reasons) ) {
1134 // Permissions error
1136 $this->setPageTitle( wfMsg( 'viewsource' ) );
1137 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1139 $this->setPageTitle( wfMsg( 'badaccess' ) );
1141 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) );
1143 // Wiki is read only
1144 $this->setPageTitle( wfMsg( 'readonly' ) );
1145 $reason = wfReadOnlyReason();
1146 $this->addWikiMsg( 'readonlytext', $reason );
1149 // Show source, if supplied
1150 if( is_string( $source ) ) {
1151 $this->addWikiMsg( 'viewsourcetext' );
1152 $text = Xml
::openElement( 'textarea',
1153 array( 'id' => 'wpTextbox1',
1154 'name' => 'wpTextbox1',
1155 'cols' => $wgUser->getOption( 'cols' ),
1156 'rows' => $wgUser->getOption( 'rows' ),
1157 'readonly' => 'readonly' ) );
1158 $text .= htmlspecialchars( $source );
1159 $text .= Xml
::closeElement( 'textarea' );
1160 $this->addHTML( $text );
1162 // Show templates used by this article
1163 $skin = $wgUser->getSkin();
1164 $article = new Article( $wgTitle );
1165 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1168 # If the title doesn't exist, it's fairly pointless to print a return
1169 # link to it. After all, you just tried editing it and couldn't, so
1170 # what's there to do there?
1171 if( $wgTitle->exists() ) {
1172 $this->returnToMain( null, $wgTitle );
1177 public function fatalError( $message ) {
1178 wfDeprecated( __METHOD__
);
1179 throw new FatalError( $message );
1183 public function unexpectedValueError( $name, $val ) {
1184 wfDeprecated( __METHOD__
);
1185 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1189 public function fileCopyError( $old, $new ) {
1190 wfDeprecated( __METHOD__
);
1191 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1195 public function fileRenameError( $old, $new ) {
1196 wfDeprecated( __METHOD__
);
1197 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1201 public function fileDeleteError( $name ) {
1202 wfDeprecated( __METHOD__
);
1203 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1207 public function fileNotFoundError( $name ) {
1208 wfDeprecated( __METHOD__
);
1209 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1212 public function showFatalError( $message ) {
1213 $this->setPageTitle( wfMsg( "internalerror" ) );
1214 $this->setRobotpolicy( "noindex,nofollow" );
1215 $this->setArticleRelated( false );
1216 $this->enableClientCache( false );
1217 $this->mRedirect
= '';
1218 $this->mBodytext
= $message;
1221 public function showUnexpectedValueError( $name, $val ) {
1222 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1225 public function showFileCopyError( $old, $new ) {
1226 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1229 public function showFileRenameError( $old, $new ) {
1230 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1233 public function showFileDeleteError( $name ) {
1234 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1237 public function showFileNotFoundError( $name ) {
1238 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1242 * Add a "return to" link pointing to a specified title
1244 * @param Title $title Title to link
1246 public function addReturnTo( $title ) {
1248 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1249 $this->addHtml( "<p>{$link}</p>\n" );
1253 * Add a "return to" link pointing to a specified title,
1254 * or the title indicated in the request, or else the main page
1256 * @param null $unused No longer used
1257 * @param Title $returnto Title to return to
1259 public function returnToMain( $unused = null, $returnto = NULL ) {
1262 if ( $returnto == NULL ) {
1263 $returnto = $wgRequest->getText( 'returnto' );
1266 if ( '' === $returnto ) {
1267 $returnto = Title
::newMainPage();
1270 if ( is_object( $returnto ) ) {
1271 $titleObj = $returnto;
1273 $titleObj = Title
::newFromText( $returnto );
1275 if ( !is_object( $titleObj ) ) {
1276 $titleObj = Title
::newMainPage();
1279 $this->addReturnTo( $titleObj );
1283 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1284 * and uses the first 10 of them for META keywords
1286 * @param ParserOutput &$parserOutput
1288 private function addKeywords( &$parserOutput ) {
1290 $this->addKeyword( $wgTitle->getPrefixedText() );
1292 $links2d =& $parserOutput->getLinks();
1293 if ( !is_array( $links2d ) ) {
1296 foreach ( $links2d as $dbkeys ) {
1297 foreach( $dbkeys as $dbkey => $unused ) {
1298 $this->addKeyword( $dbkey );
1299 if ( ++
$count > 10 ) {
1307 * @return string The doctype, opening <html>, and head element.
1309 public function headElement() {
1310 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1311 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1312 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1314 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1315 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1320 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1322 if ( '' == $this->getHTMLTitle() ) {
1323 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1326 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1327 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1328 foreach($wgXhtmlNamespaces as $tag => $ns) {
1329 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1331 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1332 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1333 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1335 $ret .= $this->getHeadLinks();
1336 global $wgStylePath;
1337 if( $this->isPrintable() ) {
1340 $media = "media='print'";
1342 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1343 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1345 $sk = $wgUser->getSkin();
1346 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1347 $ret .= $this->mScripts
;
1348 $ret .= $sk->getUserStyles();
1349 $ret .= $this->getHeadItems();
1351 if ($wgUseTrackbacks && $this->isArticleRelated())
1352 $ret .= $wgTitle->trackbackRDF();
1354 $ret .= "</head>\n";
1359 * @return string HTML tag links to be put in the header.
1361 public function getHeadLinks() {
1362 global $wgRequest, $wgFeed;
1364 foreach ( $this->mMetatags
as $tag ) {
1365 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1367 $tag[0] = substr( $tag[0], 5 );
1371 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1374 $p = $this->mRobotpolicy
;
1375 if( $p !== '' && $p != 'index,follow' ) {
1376 // http://www.robotstxt.org/wc/meta-user.html
1377 // Only show if it's different from the default robots policy
1378 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1381 if ( count( $this->mKeywords
) > 0 ) {
1386 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1387 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1389 foreach ( $this->mLinktags
as $tag ) {
1390 $ret .= "\t\t<link";
1391 foreach( $tag as $attr => $val ) {
1392 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1398 foreach( $this->getSyndicationLinks() as $format => $link ) {
1399 # Use the page name for the title (accessed through $wgTitle since
1400 # there's no other way). In principle, this could lead to issues
1401 # with having the same name for different feeds corresponding to
1402 # the same page, but we can't avoid that at this low a level.
1405 $ret .= $this->feedLink(
1408 wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) ); # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
1411 # Recent changes feed should appear on every page
1412 # Put it after the per-page feed to avoid changing existing behavior.
1413 # It's still available, probably via a menu in your browser.
1415 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
1416 $ret .= $this->feedLink(
1418 $rctitle->getFullURL( 'feed=rss' ),
1419 wfMsg( 'site-rss-feed', $wgSitename ) );
1420 $ret .= $this->feedLink(
1422 $rctitle->getFullURL( 'feed=atom' ),
1423 wfMsg( 'site-atom-feed', $wgSitename ) );
1430 * Return URLs for each supported syndication format for this page.
1431 * @return array associating format keys with URLs
1433 public function getSyndicationLinks() {
1434 global $wgTitle, $wgFeedClasses;
1437 if( $this->isSyndicated() ) {
1438 if( is_string( $this->getFeedAppendQuery() ) ) {
1439 $appendQuery = "&" . $this->getFeedAppendQuery();
1444 foreach( $wgFeedClasses as $format => $class ) {
1445 $links[$format] = $wgTitle->getLocalUrl( "feed=$format{$appendQuery}" );
1452 * Generate a <link rel/> for an RSS feed.
1454 private function feedLink( $type, $url, $text ) {
1455 return Xml
::element( 'link', array(
1456 'rel' => 'alternate',
1457 'type' => "application/$type+xml",
1459 'href' => $url ) ) . "\n";
1463 * Turn off regular page output and return an error reponse
1464 * for when rate limiting has triggered.
1466 public function rateLimited() {
1469 $this->setPageTitle(wfMsg('actionthrottled'));
1470 $this->setRobotPolicy( 'noindex,follow' );
1471 $this->setArticleRelated( false );
1472 $this->enableClientCache( false );
1473 $this->mRedirect
= '';
1475 $this->setStatusCode(503);
1476 $this->addWikiMsg( 'actionthrottledtext' );
1478 $this->returnToMain( null, $wgTitle );
1482 * Show an "add new section" link?
1486 public function showNewSectionLink() {
1487 return $this->mNewSectionLink
;
1491 * Show a warning about slave lag
1493 * If the lag is higher than $wgSlaveLagCritical seconds,
1494 * then the warning is a bit more obvious. If the lag is
1495 * lower than $wgSlaveLagWarning, then no warning is shown.
1497 * @param int $lag Slave lag
1499 public function showLagWarning( $lag ) {
1500 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1501 if( $lag >= $wgSlaveLagWarning ) {
1502 $message = $lag < $wgSlaveLagCritical
1505 $warning = wfMsgExt( $message, 'parse', $lag );
1506 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );
1511 * Add a wikitext-formatted message to the output.
1512 * This is equivalent to:
1514 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
1516 public function addWikiMsg( /*...*/ ) {
1517 $args = func_get_args();
1518 $name = array_shift( $args );
1519 $this->addWikiMsgArray( $name, $args );
1523 * Add a wikitext-formatted message to the output.
1524 * Like addWikiMsg() except the parameters are taken as an array
1525 * instead of a variable argument list.
1527 * $options is passed through to wfMsgExt(), see that function for details.
1529 public function addWikiMsgArray( $name, $args, $options = array() ) {
1530 $options[] = 'parse';
1531 $text = wfMsgExt( $name, $options, $args );
1532 $this->addHTML( $text );
1536 * This function takes a number of message/argument specifications, wraps them in
1537 * some overall structure, and then parses the result and adds it to the output.
1539 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
1540 * on. The subsequent arguments may either be strings, in which case they are the
1541 * message names, or an arrays, in which case the first element is the message name,
1542 * and subsequent elements are the parameters to that message.
1544 * The special named parameter 'options' in a message specification array is passed
1545 * through to the $options parameter of wfMsgExt().
1547 * Don't use this for messages that are not in users interface language.
1551 * $wgOut->wrapWikiMsg( '<div class="error">$1</div>', 'some-error' );
1555 * $wgOut->addWikiText( '<div class="error">' . wfMsgNoTrans( 'some-error' ) . '</div>' );
1557 public function wrapWikiMsg( $wrap /*, ...*/ ) {
1558 $msgSpecs = func_get_args();
1559 array_shift( $msgSpecs );
1560 $msgSpecs = array_values( $msgSpecs );
1562 foreach ( $msgSpecs as $n => $spec ) {
1564 if ( is_array( $spec ) ) {
1566 $name = array_shift( $args );
1567 if ( isset( $args['options'] ) ) {
1568 $options = $args['options'];
1569 unset( $args['options'] );
1575 $s = str_replace( '$' . ($n+
1), wfMsgExt( $name, $options, $args ), $s );
1577 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );