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, pp_value FROM $pageTable LEFT JOIN $propsTable " .
291 " 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;
549 "{$wgCookiePrefix}Token",
550 "{$wgCookiePrefix}LoggedOut",
554 function uncacheableBecauseRequestVars() {
556 return $wgRequest->getText('useskin', false) === false
557 && $wgRequest->getText('uselang', false) === false;
561 * Check if the request has a cache-varying cookie header
562 * If it does, it's very important that we don't allow public caching
564 function haveCacheVaryCookies() {
565 global $wgRequest, $wgCookiePrefix;
566 $cookieHeader = $wgRequest->getHeader( 'cookie' );
567 if ( $cookieHeader === false ) {
570 $cvCookies = $this->getCacheVaryCookies();
571 foreach ( $cvCookies as $cookieName ) {
572 # Check for a simple string match, like the way squid does it
573 if ( strpos( $cookieHeader, $cookieName ) ) {
574 wfDebug( __METHOD__
.": found $cookieName\n" );
578 wfDebug( __METHOD__
.": no cache-varying cookies found\n" );
582 /** Get a complete X-Vary-Options header */
583 public function getXVO() {
584 global $wgCookiePrefix;
585 $cvCookies = $this->getCacheVaryCookies();
586 $xvo = 'X-Vary-Options: Accept-Encoding;list-contains=gzip,Cookie;';
588 foreach ( $cvCookies as $cookieName ) {
594 $xvo .= 'string-contains=' . $cookieName;
599 public function sendCacheControl() {
600 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
601 $fname = 'OutputPage::sendCacheControl';
603 $response = $wgRequest->response();
604 if ($wgUseETag && $this->mETag
)
605 $response->header("ETag: $this->mETag");
607 # don't serve compressed data to clients who can't handle it
608 # maintain different caches for logged-in users and non-logged in ones
609 $response->header( 'Vary: Accept-Encoding, Cookie' );
611 # Add an X-Vary-Options header for Squid with Wikimedia patches
612 $response->header( $this->getXVO() );
614 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache
) {
615 if( $wgUseSquid && session_id() == '' &&
616 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 && !$this->haveCacheVaryCookies() )
619 # We'll purge the proxy cache explicitly, but require end user agents
620 # to revalidate against the proxy on each visit.
621 # Surrogate-Control controls our Squid, Cache-Control downstream caches
622 wfDebug( "$fname: proxy caching with ESI; {$this->mLastModified} **\n", false );
623 # start with a shorter timeout for initial testing
624 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
625 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
626 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
628 # We'll purge the proxy cache for anons explicitly, but require end user agents
629 # to revalidate against the proxy on each visit.
630 # IMPORTANT! The Squid needs to replace the Cache-Control header with
631 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
632 wfDebug( "$fname: local proxy caching; {$this->mLastModified} **\n", false );
633 # start with a shorter timeout for initial testing
634 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
635 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
638 # We do want clients to cache if they can, but they *must* check for updates
639 # on revisiting the page.
640 wfDebug( "$fname: private caching; {$this->mLastModified} **\n", false );
641 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
642 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
644 if($this->mLastModified
) $response->header( "Last-modified: {$this->mLastModified}" );
646 wfDebug( "$fname: no caching **\n", false );
648 # In general, the absence of a last modified header should be enough to prevent
649 # the client from using its cache. We send a few other things just to make sure.
650 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
651 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
652 $response->header( 'Pragma: no-cache' );
657 * Finally, all the text has been munged and accumulated into
658 * the object, let's actually output it:
660 public function output() {
661 global $wgUser, $wgOutputEncoding, $wgRequest;
662 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
663 global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
664 global $wgServer, $wgStyleVersion;
666 if( $this->mDoNothing
){
669 $fname = 'OutputPage::output';
670 wfProfileIn( $fname );
672 if ( '' != $this->mRedirect
) {
673 # Standards require redirect URLs to be absolute
674 $this->mRedirect
= wfExpandUrl( $this->mRedirect
);
675 if( $this->mRedirectCode
== '301') {
676 if( !$wgDebugRedirects ) {
677 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
679 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
682 $this->sendCacheControl();
684 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
685 if( $wgDebugRedirects ) {
686 $url = htmlspecialchars( $this->mRedirect
);
687 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
688 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
689 print "</body>\n</html>\n";
691 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
693 wfProfileOut( $fname );
696 elseif ( $this->mStatusCode
)
698 $statusMessage = array(
700 101 => 'Switching Protocols',
705 203 => 'Non-Authoritative Information',
707 205 => 'Reset Content',
708 206 => 'Partial Content',
709 207 => 'Multi-Status',
710 300 => 'Multiple Choices',
711 301 => 'Moved Permanently',
714 304 => 'Not Modified',
716 307 => 'Temporary Redirect',
717 400 => 'Bad Request',
718 401 => 'Unauthorized',
719 402 => 'Payment Required',
722 405 => 'Method Not Allowed',
723 406 => 'Not Acceptable',
724 407 => 'Proxy Authentication Required',
725 408 => 'Request Timeout',
728 411 => 'Length Required',
729 412 => 'Precondition Failed',
730 413 => 'Request Entity Too Large',
731 414 => 'Request-URI Too Large',
732 415 => 'Unsupported Media Type',
733 416 => 'Request Range Not Satisfiable',
734 417 => 'Expectation Failed',
735 422 => 'Unprocessable Entity',
737 424 => 'Failed Dependency',
738 500 => 'Internal Server Error',
739 501 => 'Not Implemented',
740 502 => 'Bad Gateway',
741 503 => 'Service Unavailable',
742 504 => 'Gateway Timeout',
743 505 => 'HTTP Version Not Supported',
744 507 => 'Insufficient Storage'
747 if ( $statusMessage[$this->mStatusCode
] )
748 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
751 $sk = $wgUser->getSkin();
754 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
756 wfRunHooks( 'AjaxAddScript', array( &$this ) );
758 if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) {
759 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
760 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
763 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
764 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
770 # Buffer output; final headers may depend on later processing
773 # Disable temporary placeholders, so that the skin produces HTML
774 $sk->postParseLinkColour( false );
776 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
777 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
779 if ($this->mArticleBodyOnly
) {
780 $this->out($this->mBodytext
);
782 wfProfileIn( 'Output-skin' );
783 $sk->outputPage( $this );
784 wfProfileOut( 'Output-skin' );
787 $this->sendCacheControl();
789 wfProfileOut( $fname );
796 public function out( $ins ) {
797 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
798 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
801 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
802 if ( false === $outs ) { $outs = $ins; }
810 public static function setEncodings() {
811 global $wgInputEncoding, $wgOutputEncoding;
812 global $wgUser, $wgContLang;
814 $wgInputEncoding = strtolower( $wgInputEncoding );
816 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
817 $wgOutputEncoding = strtolower( $wgOutputEncoding );
820 $wgOutputEncoding = $wgInputEncoding;
824 * Deprecated, use wfReportTime() instead.
828 public function reportTime() {
829 $time = wfReportTime();
834 * Produce a "user is blocked" page.
836 * @param bool $return Whether to have a "return to $wgTitle" message or not.
839 function blockedPage( $return = true ) {
840 global $wgUser, $wgContLang, $wgTitle, $wgLang;
842 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
843 $this->setRobotpolicy( 'noindex,nofollow' );
844 $this->setArticleRelated( false );
846 $name = User
::whoIs( $wgUser->blockedBy() );
847 $reason = $wgUser->blockedFor();
848 if( $reason == '' ) {
849 $reason = wfMsg( 'blockednoreason' );
851 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
854 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
856 $blockid = $wgUser->mBlock
->mId
;
858 $blockExpiry = $wgUser->mBlock
->mExpiry
;
859 if ( $blockExpiry == 'infinity' ) {
860 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
861 // Search for localization in 'ipboptions'
862 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
863 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
864 if ( strpos( $option, ":" ) === false )
866 list( $show, $value ) = explode( ":", $option );
867 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
868 $blockExpiry = $show;
873 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
876 if ( $wgUser->mBlock
->mAuto
) {
877 $msg = 'autoblockedtext';
879 $msg = 'blockedtext';
882 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
883 * This could be a username, an ip range, or a single ip. */
884 $intended = $wgUser->mBlock
->mAddress
;
886 $this->addWikiMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
888 # Don't auto-return to special pages
890 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle->getPrefixedText() : NULL;
891 $this->returnToMain( false, $return );
896 * Output a standard error page
898 * @param string $title Message key for page title
899 * @param string $msg Message key for page text
900 * @param array $params Message parameters
902 public function showErrorPage( $title, $msg, $params = array() ) {
904 if ( isset($wgTitle) ) {
905 $this->mDebugtext
.= 'Original title: ' . $wgTitle->getPrefixedText() . "\n";
907 $this->setPageTitle( wfMsg( $title ) );
908 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
909 $this->setRobotpolicy( 'noindex,nofollow' );
910 $this->setArticleRelated( false );
911 $this->enableClientCache( false );
912 $this->mRedirect
= '';
913 $this->mBodytext
= '';
915 array_unshift( $params, 'parse' );
916 array_unshift( $params, $msg );
917 $this->addHtml( call_user_func_array( 'wfMsgExt', $params ) );
919 $this->returnToMain( false );
923 * Output a standard permission error page
925 * @param array $errors Error message keys
927 public function showPermissionsErrorPage( $errors )
931 $this->mDebugtext
.= 'Original title: ' .
932 $wgTitle->getPrefixedText() . "\n";
933 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
934 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
935 $this->setRobotpolicy( 'noindex,nofollow' );
936 $this->setArticleRelated( false );
937 $this->enableClientCache( false );
938 $this->mRedirect
= '';
939 $this->mBodytext
= '';
940 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors ) );
944 public function errorpage( $title, $msg ) {
945 throw new ErrorPageError( $title, $msg );
949 * Display an error page indicating that a given version of MediaWiki is
952 * @param mixed $version The version of MediaWiki needed to use the page
954 public function versionRequired( $version ) {
955 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
956 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
957 $this->setRobotpolicy( 'noindex,nofollow' );
958 $this->setArticleRelated( false );
959 $this->mBodytext
= '';
961 $this->addWikiMsg( 'versionrequiredtext', $version );
962 $this->returnToMain();
966 * Display an error page noting that a given permission bit is required.
968 * @param string $permission key required
970 public function permissionRequired( $permission ) {
971 global $wgGroupPermissions, $wgUser;
973 $this->setPageTitle( wfMsg( 'badaccess' ) );
974 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
975 $this->setRobotpolicy( 'noindex,nofollow' );
976 $this->setArticleRelated( false );
977 $this->mBodytext
= '';
980 foreach( $wgGroupPermissions as $key => $value ) {
981 if( isset( $value[$permission] ) && $value[$permission] == true ) {
982 $groupName = User
::getGroupName( $key );
983 $groupPage = User
::getGroupPage( $key );
985 $skin = $wgUser->getSkin();
986 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
988 $groups[] = $groupName;
992 $n = count( $groups );
993 $groups = implode( ', ', $groups );
998 $message = wfMsgHtml( "badaccess-group$n", $groups );
1001 $message = wfMsgHtml( 'badaccess-groups', $groups );
1003 $this->addHtml( $message );
1004 $this->returnToMain( false );
1008 * Use permissionRequired.
1011 public function sysopRequired() {
1012 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
1016 * Use permissionRequired.
1019 public function developerRequired() {
1020 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
1024 * Produce the stock "please login to use the wiki" page
1026 public function loginToUse() {
1027 global $wgUser, $wgTitle, $wgContLang;
1029 if( $wgUser->isLoggedIn() ) {
1030 $this->permissionRequired( 'read' );
1034 $skin = $wgUser->getSkin();
1036 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1037 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1038 $this->setRobotPolicy( 'noindex,nofollow' );
1039 $this->setArticleFlag( false );
1041 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1042 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1043 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1044 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
1046 # Don't return to the main page if the user can't read it
1047 # otherwise we'll end up in a pointless loop
1048 $mainPage = Title
::newMainPage();
1049 if( $mainPage->userCanRead() )
1050 $this->returnToMain( true, $mainPage );
1054 public function databaseError( $fname, $sql, $error, $errno ) {
1055 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1059 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
1060 * @return string The wikitext error-messages, formatted into a list.
1062 public function formatPermissionsErrorMessage( $errors ) {
1063 $text = wfMsgNoTrans( 'permissionserrorstext', count( $errors ) ) . "\n\n";
1065 if (count( $errors ) > 1) {
1066 $text .= '<ul class="permissions-errors">' . "\n";
1068 foreach( $errors as $error )
1071 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1076 $text .= '<div class="permissions-errors">' . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . '</div>';
1083 * Display a page stating that the Wiki is in read-only mode,
1084 * and optionally show the source of the page that the user
1085 * was trying to edit. Should only be called (for this
1086 * purpose) after wfReadOnly() has returned true.
1088 * For historical reasons, this function is _also_ used to
1089 * show the error message when a user tries to edit a page
1090 * they are not allowed to edit. (Unless it's because they're
1091 * blocked, then we show blockedPage() instead.) In this
1092 * case, the second parameter should be set to true and a list
1093 * of reasons supplied as the third parameter.
1095 * @todo Needs to be split into multiple functions.
1097 * @param string $source Source code to show (or null).
1098 * @param bool $protected Is this a permissions error?
1099 * @param array $reasons List of reasons for this error, as returned by Title::getUserPermissionsErrors().
1101 public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
1102 global $wgUser, $wgTitle;
1103 $skin = $wgUser->getSkin();
1105 $this->setRobotpolicy( 'noindex,nofollow' );
1106 $this->setArticleRelated( false );
1108 // If no reason is given, just supply a default "I can't let you do
1109 // that, Dave" message. Should only occur if called by legacy code.
1110 if ( $protected && empty($reasons) ) {
1111 $reasons[] = array( 'badaccess-group0' );
1114 if ( !empty($reasons) ) {
1115 // Permissions error
1117 $this->setPageTitle( wfMsg( 'viewsource' ) );
1118 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1120 $this->setPageTitle( wfMsg( 'badaccess' ) );
1122 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) );
1124 // Wiki is read only
1125 $this->setPageTitle( wfMsg( 'readonly' ) );
1126 $reason = wfReadOnlyReason();
1127 $this->addWikiMsg( 'readonlytext', $reason );
1130 // Show source, if supplied
1131 if( is_string( $source ) ) {
1132 $this->addWikiMsg( 'viewsourcetext' );
1133 $text = wfOpenElement( 'textarea',
1134 array( 'id' => 'wpTextbox1',
1135 'name' => 'wpTextbox1',
1136 'cols' => $wgUser->getOption( 'cols' ),
1137 'rows' => $wgUser->getOption( 'rows' ),
1138 'readonly' => 'readonly' ) );
1139 $text .= htmlspecialchars( $source );
1140 $text .= wfCloseElement( 'textarea' );
1141 $this->addHTML( $text );
1143 // Show templates used by this article
1144 $skin = $wgUser->getSkin();
1145 $article = new Article( $wgTitle );
1146 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1149 # If the title doesn't exist, it's fairly pointless to print a return
1150 # link to it. After all, you just tried editing it and couldn't, so
1151 # what's there to do there?
1152 if( $wgTitle->exists() ) {
1153 $this->returnToMain( false, $wgTitle );
1158 public function fatalError( $message ) {
1159 throw new FatalError( $message );
1163 public function unexpectedValueError( $name, $val ) {
1164 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1168 public function fileCopyError( $old, $new ) {
1169 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1173 public function fileRenameError( $old, $new ) {
1174 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1178 public function fileDeleteError( $name ) {
1179 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1183 public function fileNotFoundError( $name ) {
1184 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1187 public function showFatalError( $message ) {
1188 $this->setPageTitle( wfMsg( "internalerror" ) );
1189 $this->setRobotpolicy( "noindex,nofollow" );
1190 $this->setArticleRelated( false );
1191 $this->enableClientCache( false );
1192 $this->mRedirect
= '';
1193 $this->mBodytext
= $message;
1196 public function showUnexpectedValueError( $name, $val ) {
1197 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1200 public function showFileCopyError( $old, $new ) {
1201 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1204 public function showFileRenameError( $old, $new ) {
1205 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1208 public function showFileDeleteError( $name ) {
1209 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1212 public function showFileNotFoundError( $name ) {
1213 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1217 * Add a "return to" link pointing to a specified title
1219 * @param Title $title Title to link
1221 public function addReturnTo( $title ) {
1223 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1224 $this->addHtml( "<p>{$link}</p>\n" );
1228 * Add a "return to" link pointing to a specified title,
1229 * or the title indicated in the request, or else the main page
1231 * @param null $unused No longer used
1232 * @param Title $returnto Title to return to
1234 public function returnToMain( $unused = null, $returnto = NULL ) {
1237 if ( $returnto == NULL ) {
1238 $returnto = $wgRequest->getText( 'returnto' );
1241 if ( '' === $returnto ) {
1242 $returnto = Title
::newMainPage();
1245 if ( is_object( $returnto ) ) {
1246 $titleObj = $returnto;
1248 $titleObj = Title
::newFromText( $returnto );
1250 if ( !is_object( $titleObj ) ) {
1251 $titleObj = Title
::newMainPage();
1254 $this->addReturnTo( $titleObj );
1258 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1259 * and uses the first 10 of them for META keywords
1261 * @param ParserOutput &$parserOutput
1263 private function addKeywords( &$parserOutput ) {
1265 $this->addKeyword( $wgTitle->getPrefixedText() );
1267 $links2d =& $parserOutput->getLinks();
1268 if ( !is_array( $links2d ) ) {
1271 foreach ( $links2d as $dbkeys ) {
1272 foreach( $dbkeys as $dbkey => $unused ) {
1273 $this->addKeyword( $dbkey );
1274 if ( ++
$count > 10 ) {
1282 * @return string The doctype, opening <html>, and head element.
1284 public function headElement() {
1285 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1286 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1287 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1289 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1290 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1295 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1297 if ( '' == $this->getHTMLTitle() ) {
1298 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1301 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1302 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1303 foreach($wgXhtmlNamespaces as $tag => $ns) {
1304 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1306 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1307 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1308 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
1310 $ret .= $this->getHeadLinks();
1311 global $wgStylePath;
1312 if( $this->isPrintable() ) {
1315 $media = "media='print'";
1317 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1318 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1320 $sk = $wgUser->getSkin();
1321 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1322 $ret .= $this->mScripts
;
1323 $ret .= $sk->getUserStyles();
1324 $ret .= $this->getHeadItems();
1326 if ($wgUseTrackbacks && $this->isArticleRelated())
1327 $ret .= $wgTitle->trackbackRDF();
1329 $ret .= "</head>\n";
1334 * @return string HTML tag links to be put in the header.
1336 public function getHeadLinks() {
1337 global $wgRequest, $wgFeed;
1339 foreach ( $this->mMetatags
as $tag ) {
1340 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1342 $tag[0] = substr( $tag[0], 5 );
1346 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
1349 $p = $this->mRobotpolicy
;
1350 if( $p !== '' && $p != 'index,follow' ) {
1351 // http://www.robotstxt.org/wc/meta-user.html
1352 // Only show if it's different from the default robots policy
1353 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
1356 if ( count( $this->mKeywords
) > 0 ) {
1361 $ret .= "\t\t<meta name=\"keywords\" content=\"" .
1362 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
1364 foreach ( $this->mLinktags
as $tag ) {
1365 $ret .= "\t\t<link";
1366 foreach( $tag as $attr => $val ) {
1367 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
1373 foreach( $this->getSyndicationLinks() as $format => $link ) {
1374 # Use the page name for the title (accessed through $wgTitle since
1375 # there's no other way). In principle, this could lead to issues
1376 # with having the same name for different feeds corresponding to
1377 # the same page, but we can't avoid that at this low a level.
1380 $ret .= $this->feedLink(
1383 wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) ); # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
1386 # Recent changes feed should appear on every page
1387 # Put it after the per-page feed to avoid changing existing behavior.
1388 # It's still available, probably via a menu in your browser.
1390 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
1391 $ret .= $this->feedLink(
1393 $rctitle->getFullURL( 'feed=rss' ),
1394 wfMsg( 'site-rss-feed', $wgSitename ) );
1395 $ret .= $this->feedLink(
1397 $rctitle->getFullURL( 'feed=atom' ),
1398 wfMsg( 'site-atom-feed', $wgSitename ) );
1405 * Return URLs for each supported syndication format for this page.
1406 * @return array associating format keys with URLs
1408 public function getSyndicationLinks() {
1409 global $wgTitle, $wgFeedClasses;
1412 if( $this->isSyndicated() ) {
1413 if( is_string( $this->getFeedAppendQuery() ) ) {
1414 $appendQuery = "&" . $this->getFeedAppendQuery();
1419 foreach( $wgFeedClasses as $format => $class ) {
1420 $links[$format] = $wgTitle->getLocalUrl( "feed=$format{$appendQuery}" );
1427 * Generate a <link rel/> for an RSS feed.
1429 private function feedLink( $type, $url, $text ) {
1430 return Xml
::element( 'link', array(
1431 'rel' => 'alternate',
1432 'type' => "application/$type+xml",
1434 'href' => $url ) ) . "\n";
1438 * Turn off regular page output and return an error reponse
1439 * for when rate limiting has triggered.
1441 public function rateLimited() {
1442 global $wgOut, $wgTitle;
1444 $this->setPageTitle(wfMsg('actionthrottled'));
1445 $this->setRobotPolicy( 'noindex,follow' );
1446 $this->setArticleRelated( false );
1447 $this->enableClientCache( false );
1448 $this->mRedirect
= '';
1450 $this->setStatusCode(503);
1451 $this->addWikiMsg( 'actionthrottledtext' );
1453 $this->returnToMain( false, $wgTitle );
1457 * Show an "add new section" link?
1461 public function showNewSectionLink() {
1462 return $this->mNewSectionLink
;
1466 * Show a warning about slave lag
1468 * If the lag is higher than $wgSlaveLagCritical seconds,
1469 * then the warning is a bit more obvious. If the lag is
1470 * lower than $wgSlaveLagWarning, then no warning is shown.
1472 * @param int $lag Slave lag
1474 public function showLagWarning( $lag ) {
1475 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1476 if( $lag >= $wgSlaveLagWarning ) {
1477 $message = $lag < $wgSlaveLagCritical
1480 $warning = wfMsgExt( $message, 'parse', $lag );
1481 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );
1486 * Add a wikitext-formatted message to the output.
1487 * This is equivalent to:
1489 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
1491 public function addWikiMsg( /*...*/ ) {
1492 $args = func_get_args();
1493 $name = array_shift( $args );
1494 $this->addWikiMsgArray( $name, $args );
1498 * Add a wikitext-formatted message to the output.
1499 * Like addWikiMsg() except the parameters are taken as an array
1500 * instead of a variable argument list.
1502 * $options is passed through to wfMsgExt(), see that function for details.
1504 public function addWikiMsgArray( $name, $args, $options = array() ) {
1505 $options[] = 'parse';
1506 $text = wfMsgExt( $name, $options, $args );
1507 $this->addHTML( $text );
1511 * This function takes a number of message/argument specifications, wraps them in
1512 * some overall structure, and then parses the result and adds it to the output.
1514 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
1515 * on. The subsequent arguments may either be strings, in which case they are the
1516 * message names, or an arrays, in which case the first element is the message name,
1517 * and subsequent elements are the parameters to that message.
1519 * The special named parameter 'options' in a message specification array is passed
1520 * through to the $options parameter of wfMsgExt().
1524 * $wgOut->wrapWikiMsg( '<div class="error">$1</div>', 'some-error' );
1528 * $wgOut->addWikiText( '<div class="error">' . wfMsgNoTrans( 'some-error' ) . '</div>' );
1530 public function wrapWikiMsg( $wrap /*, ...*/ ) {
1531 $msgSpecs = func_get_args();
1532 array_shift( $msgSpecs );
1533 $msgSpecs = array_values( $msgSpecs );
1535 foreach ( $msgSpecs as $n => $spec ) {
1537 if ( is_array( $spec ) ) {
1539 $name = array_shift( $args );
1540 if ( isset( $args['options'] ) ) {
1541 $options = $args['options'];
1542 unset( $args['options'] );
1548 $s = str_replace( '$' . ($n+
1), wfMsgExt( $name, $options, $args ), $s );
1550 $this->addHTML( $this->parse( $s ) );