2 if ( ! defined( 'MEDIAWIKI' ) )
9 var $mMetatags, $mKeywords;
10 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
11 var $mHTMLtitle, $mIsarticle, $mPrintable;
12 var $mSubtitle, $mRedirect, $mStatusCode;
13 var $mLastModified, $mETag, $mCategoryLinks;
14 var $mScripts, $mLinkColours, $mPageLinkTitle;
17 var $mSuppressQuickbar;
20 var $mContainsOldMagic, $mContainsNewMagic;
21 var $mIsArticleRelated;
22 protected $mParserOptions; // lazy initialised, use parserOptions()
23 var $mShowFeedLinks = false;
24 var $mFeedLinksAppendQuery = false;
25 var $mEnableClientCache = true;
26 var $mArticleBodyOnly = false;
28 var $mNewSectionLink = false;
29 var $mNoGallery = false;
30 var $mPageTitleActionText = '';
31 var $mParseWarnings = array();
33 private $mIndexPolicy = 'index';
34 private $mFollowPolicy = 'follow';
38 * Initialise private variables
40 function __construct() {
41 global $wgAllowUserJs;
42 $this->mAllowUserJs
= $wgAllowUserJs;
43 $this->mMetatags
= $this->mKeywords
= $this->mLinktags
= array();
44 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
45 $this->mRedirect
= $this->mLastModified
= $this->mSubtitle
=
46 $this->mDebugtext
= $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,
91 'type' => 'text/css' ) );
95 * Add a JavaScript file out of skins/common, or a given relative path.
96 * @param string $file filename in skins/common or complete on-server path (/foo/bar.js)
98 function addScriptFile( $file ) {
99 global $wgStylePath, $wgStyleVersion, $wgJsMimeType;
100 if( substr( $file, 0, 1 ) == '/' ) {
103 $path = "{$wgStylePath}/common/{$file}";
105 $encPath = htmlspecialchars( $path );
106 $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$path?$wgStyleVersion\"></script>\n" );
110 * Add a self-contained script tag with the given contents
111 * @param string $script JavaScript text, no <script> tags
113 function addInlineScript( $script ) {
114 global $wgJsMimeType;
115 $this->mScripts
.= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
118 function getScript() {
119 return $this->mScripts
. $this->getHeadItems();
122 function getHeadItems() {
124 foreach ( $this->mHeadItems
as $item ) {
130 function addHeadItem( $name, $value ) {
131 $this->mHeadItems
[$name] = $value;
134 function hasHeadItem( $name ) {
135 return isset( $this->mHeadItems
[$name] );
138 function setETag($tag) { $this->mETag
= $tag; }
139 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
140 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
142 function addLink( $linkarr ) {
143 # $linkarr should be an associative array of attributes. We'll escape on output.
144 array_push( $this->mLinktags
, $linkarr );
147 function addMetadataLink( $linkarr ) {
148 # note: buggy CC software only reads first "meta" link
149 static $haveMeta = false;
150 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
151 $this->addLink( $linkarr );
156 * checkLastModified tells the client to use the client-cached page if
157 * possible. If sucessful, the OutputPage is disabled so that
158 * any future call to OutputPage->output() have no effect.
160 * @return bool True iff cache-ok headers was sent.
162 function checkLastModified ( $timestamp ) {
163 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
165 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
166 wfDebug( __METHOD__
. ": CACHE DISABLED, NO TIMESTAMP\n" );
169 if( !$wgCachePages ) {
170 wfDebug( __METHOD__
. ": CACHE DISABLED\n", false );
173 if( $wgUser->getOption( 'nocache' ) ) {
174 wfDebug( __METHOD__
. ": USER DISABLED CACHE\n", false );
178 $timestamp=wfTimestamp(TS_MW
,$timestamp);
179 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
, $wgCacheEpoch ) );
181 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
182 # IE sends sizes after the date like this:
183 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
184 # this breaks strtotime().
185 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
187 wfSuppressWarnings(); // E_STRICT system time bitching
188 $modsinceTime = strtotime( $modsince );
191 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
192 wfDebug( __METHOD__
. ": -- client send If-Modified-Since: " . $modsince . "\n", false );
193 wfDebug( __METHOD__
. ": -- we might send Last-Modified : $lastmod\n", false );
194 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
195 # Make sure you're in a place you can leave when you call us!
196 $wgRequest->response()->header( "HTTP/1.0 304 Not Modified" );
197 $this->mLastModified
= $lastmod;
198 $this->sendCacheControl();
199 wfDebug( __METHOD__
. ": CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
202 // Don't output a compressed blob when using ob_gzhandler;
203 // it's technically against HTTP spec and seems to confuse
204 // Firefox when the response gets split over two packets.
205 wfClearOutputBuffers();
209 wfDebug( __METHOD__
. ": READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
210 $this->mLastModified
= $lastmod;
213 wfDebug( __METHOD__
. ": client did not send If-Modified-Since header\n", false );
214 $this->mLastModified
= $lastmod;
218 function setPageTitleActionText( $text ) {
219 $this->mPageTitleActionText
= $text;
222 function getPageTitleActionText () {
223 if ( isset( $this->mPageTitleActionText
) ) {
224 return $this->mPageTitleActionText
;
229 * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
231 * @param $policy string The literal string to output as the contents of
232 * the meta tag. Will be parsed according to the spec and output in
236 public function setRobotPolicy( $policy ) {
237 $policy = explode( ',', $policy );
238 $policy = array_map( 'trim', $policy );
240 # The default policy is follow, so if nothing is said explicitly, we
242 if( in_array( 'nofollow', $policy ) ) {
243 $this->mFollowPolicy
= 'nofollow';
245 $this->mFollowPolicy
= 'follow';
248 if( in_array( 'noindex', $policy ) ) {
249 $this->mIndexPolicy
= 'noindex';
251 $this->mIndexPolicy
= 'index';
256 * Set the index policy for the page, but leave the follow policy un-
259 * @param $policy string Either 'index' or 'noindex'.
262 public function setIndexPolicy( $policy ) {
263 $policy = trim( $policy );
264 if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
265 $this->mIndexPolicy
= $policy;
270 * Set the follow policy for the page, but leave the index policy un-
273 * @param $policy string Either 'follow' or 'nofollow'.
276 public function setFollowPolicy( $policy ) {
277 $policy = trim( $policy );
278 if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
279 $this->mFollowPolicy
= $policy;
283 public function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
284 public function setPageTitle( $name ) {
285 global $action, $wgContLang;
286 $name = $wgContLang->convert($name, true);
287 $this->mPagetitle
= $name;
288 if(!empty($action)) {
289 $taction = $this->getPageTitleActionText();
290 if( !empty( $taction ) ) {
291 $name .= ' - '.$taction;
295 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
297 public function getHTMLTitle() { return $this->mHTMLtitle
; }
298 public function getPageTitle() { return $this->mPagetitle
; }
299 public function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
300 public function appendSubtitle( $str ) { $this->mSubtitle
.= /*$this->parse(*/$str/*)*/; } // @bug 2514
301 public function getSubtitle() { return $this->mSubtitle
; }
302 public function isArticle() { return $this->mIsarticle
; }
303 public function setPrintable() { $this->mPrintable
= true; }
304 public function isPrintable() { return $this->mPrintable
; }
305 public function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
306 public function isSyndicated() { return $this->mShowFeedLinks
; }
307 public function setFeedAppendQuery( $val ) { $this->mFeedLinksAppendQuery
= $val; }
308 public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery
; }
309 public function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
310 public function getOnloadHandler() { return $this->mOnloadHandler
; }
311 public function disable() { $this->mDoNothing
= true; }
313 public function setArticleRelated( $v ) {
314 $this->mIsArticleRelated
= $v;
316 $this->mIsarticle
= false;
319 public function setArticleFlag( $v ) {
320 $this->mIsarticle
= $v;
322 $this->mIsArticleRelated
= $v;
326 public function isArticleRelated() { return $this->mIsArticleRelated
; }
328 public function getLanguageLinks() { return $this->mLanguageLinks
; }
329 public function addLanguageLinks($newLinkArray) {
330 $this->mLanguageLinks +
= $newLinkArray;
332 public function setLanguageLinks($newLinkArray) {
333 $this->mLanguageLinks
= $newLinkArray;
336 public function getCategoryLinks() {
337 return $this->mCategoryLinks
;
341 * Add an array of categories, with names in the keys
343 public function addCategoryLinks( $categories ) {
344 global $wgUser, $wgContLang;
346 if ( !is_array( $categories ) ||
count( $categories ) == 0 ) {
350 # Add the links to a LinkBatch
351 $arr = array( NS_CATEGORY
=> $categories );
353 $lb->setArray( $arr );
355 # Fetch existence plus the hiddencat property
356 $dbr = wfGetDB( DB_SLAVE
);
357 $pageTable = $dbr->tableName( 'page' );
358 $where = $lb->constructSet( 'page', $dbr );
359 $propsTable = $dbr->tableName( 'page_props' );
360 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, pp_value
361 FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
362 $res = $dbr->query( $sql, __METHOD__
);
364 # Add the results to the link cache
365 $lb->addResultToCache( LinkCache
::singleton(), $res );
367 # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
368 $categories = array_combine( array_keys( $categories ),
369 array_fill( 0, count( $categories ), 'normal' ) );
371 # Mark hidden categories
372 foreach ( $res as $row ) {
373 if ( isset( $row->pp_value
) ) {
374 $categories[$row->page_title
] = 'hidden';
378 # Add the remaining categories to the skin
379 if ( wfRunHooks( 'OutputPageMakeCategoryLinks', array( &$this, $categories, &$this->mCategoryLinks
) ) ) {
380 $sk = $wgUser->getSkin();
381 foreach ( $categories as $category => $type ) {
382 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
383 $text = $wgContLang->convertHtml( $title->getText() );
384 $this->mCategoryLinks
[$type][] = $sk->makeLinkObj( $title, $text );
389 public function setCategoryLinks($categories) {
390 $this->mCategoryLinks
= array();
391 $this->addCategoryLinks($categories);
394 public function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
395 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
397 public function disallowUserJs() { $this->mAllowUserJs
= false; }
398 public function isUserJsAllowed() { return $this->mAllowUserJs
; }
400 public function addHTML( $text ) { $this->mBodytext
.= $text; }
401 public function clearHTML() { $this->mBodytext
= ''; }
402 public function getHTML() { return $this->mBodytext
; }
403 public function debug( $text ) { $this->mDebugtext
.= $text; }
406 public function setParserOptions( $options ) {
407 wfDeprecated( __METHOD__
);
408 return $this->parserOptions( $options );
411 public function parserOptions( $options = null ) {
412 if ( !$this->mParserOptions
) {
413 $this->mParserOptions
= new ParserOptions
;
415 return wfSetVar( $this->mParserOptions
, $options );
419 * Set the revision ID which will be seen by the wiki text parser
420 * for things such as embedded {{REVISIONID}} variable use.
421 * @param mixed $revid an integer, or NULL
422 * @return mixed previous value
424 public function setRevisionId( $revid ) {
425 $val = is_null( $revid ) ?
null : intval( $revid );
426 return wfSetVar( $this->mRevisionId
, $val );
430 * Convert wikitext to HTML and add it to the buffer
431 * Default assumes that the current page title will
434 * @param string $text
435 * @param bool $linestart
437 public function addWikiText( $text, $linestart = true ) {
439 $this->addWikiTextTitle($text, $wgTitle, $linestart);
442 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
443 $this->addWikiTextTitle($text, $title, $linestart);
446 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
447 $this->addWikiTextTitle( $text, $title, $linestart, true );
450 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
453 wfProfileIn( __METHOD__
);
455 wfIncrStats( 'pcache_not_possible' );
457 $popts = $this->parserOptions();
458 $oldTidy = $popts->setTidy( $tidy );
460 $parserOutput = $wgParser->parse( $text, $title, $popts,
461 $linestart, true, $this->mRevisionId
);
463 $popts->setTidy( $oldTidy );
465 $this->addParserOutput( $parserOutput );
467 wfProfileOut( __METHOD__
);
472 * @param ParserOutput object &$parserOutput
474 public function addParserOutputNoText( &$parserOutput ) {
475 global $wgAllowUserRobotsControl;
477 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
478 $this->addCategoryLinks( $parserOutput->getCategories() );
479 $this->mNewSectionLink
= $parserOutput->getNewSection();
480 if( $wgAllowUserRobotsControl ) {
481 # FIXME: This probably overrides $wgArticleRobotPolicies, is that wise?
482 $this->setIndexPolicy( $parserOutput->getIndexPolicy() );
484 $this->addKeywords( $parserOutput );
485 $this->mParseWarnings
= $parserOutput->getWarnings();
486 if ( $parserOutput->getCacheTime() == -1 ) {
487 $this->enableClientCache( false );
489 $this->mNoGallery
= $parserOutput->getNoGallery();
490 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
492 $this->mTemplateIds
= wfArrayMerge( $this->mTemplateIds
, (array)$parserOutput->mTemplateIds
);
495 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
496 $this->setPageTitle( $dt );
498 // Hooks registered in the object
499 global $wgParserOutputHooks;
500 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
501 list( $hookName, $data ) = $hookInfo;
502 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
503 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
507 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
512 * @param ParserOutput &$parserOutput
514 function addParserOutput( &$parserOutput ) {
515 $this->addParserOutputNoText( $parserOutput );
516 $text = $parserOutput->getText();
517 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
518 $this->addHTML( $text );
522 * Add wikitext to the buffer, assuming that this is the primary text for a page view
523 * Saves the text into the parser cache if possible.
525 * @param string $text
526 * @param Article $article
528 * @deprecated Use Article::outputWikitext
530 public function addPrimaryWikiText( $text, $article, $cache = true ) {
531 global $wgParser, $wgUser;
533 wfDeprecated( __METHOD__
);
535 $popts = $this->parserOptions();
536 $popts->setTidy(true);
537 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
538 $popts, true, true, $this->mRevisionId
);
539 $popts->setTidy(false);
540 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
541 $parserCache = ParserCache
::singleton();
542 $parserCache->save( $parserOutput, $article, $wgUser );
545 $this->addParserOutput( $parserOutput );
549 * @deprecated use addWikiTextTidy()
551 public function addSecondaryWikiText( $text, $linestart = true ) {
553 wfDeprecated( __METHOD__
);
554 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
558 * Add wikitext with tidy enabled
560 public function addWikiTextTidy( $text, $linestart = true ) {
562 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
567 * Add the output of a QuickTemplate to the output buffer
569 * @param QuickTemplate $template
571 public function addTemplate( &$template ) {
573 $template->execute();
574 $this->addHTML( ob_get_contents() );
579 * Parse wikitext and return the HTML.
581 * @param string $text
582 * @param bool $linestart Is this the start of a line?
583 * @param bool $interface ??
585 public function parse( $text, $linestart = true, $interface = false ) {
586 global $wgParser, $wgTitle;
587 $popts = $this->parserOptions();
588 if ( $interface) { $popts->setInterfaceMessage(true); }
589 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
590 $linestart, true, $this->mRevisionId
);
591 if ( $interface) { $popts->setInterfaceMessage(false); }
592 return $parserOutput->getText();
596 * @param Article $article
599 * @return bool True if successful, else false.
601 public function tryParserCache( &$article, $user ) {
602 $parserCache = ParserCache
::singleton();
603 $parserOutput = $parserCache->get( $article, $user );
604 if ( $parserOutput !== false ) {
605 $this->addParserOutput( $parserOutput );
613 * @param int $maxage Maximum cache time on the Squid, in seconds.
615 public function setSquidMaxage( $maxage ) {
616 $this->mSquidMaxage
= $maxage;
620 * Use enableClientCache(false) to force it to send nocache headers
623 public function enableClientCache( $state ) {
624 return wfSetVar( $this->mEnableClientCache
, $state );
627 function getCacheVaryCookies() {
628 global $wgCookiePrefix, $wgCacheVaryCookies;
630 if ( $cookies === null ) {
631 $cookies = array_merge(
633 "{$wgCookiePrefix}Token",
634 "{$wgCookiePrefix}LoggedOut",
639 wfRunHooks('GetCacheVaryCookies', array( $this, &$cookies ) );
644 function uncacheableBecauseRequestVars() {
646 return $wgRequest->getText('useskin', false) === false
647 && $wgRequest->getText('uselang', false) === false;
651 * Check if the request has a cache-varying cookie header
652 * If it does, it's very important that we don't allow public caching
654 function haveCacheVaryCookies() {
655 global $wgRequest, $wgCookiePrefix;
656 $cookieHeader = $wgRequest->getHeader( 'cookie' );
657 if ( $cookieHeader === false ) {
660 $cvCookies = $this->getCacheVaryCookies();
661 foreach ( $cvCookies as $cookieName ) {
662 # Check for a simple string match, like the way squid does it
663 if ( strpos( $cookieHeader, $cookieName ) ) {
664 wfDebug( __METHOD__
.": found $cookieName\n" );
668 wfDebug( __METHOD__
.": no cache-varying cookies found\n" );
672 /** Get a complete X-Vary-Options header */
673 public function getXVO() {
674 global $wgCookiePrefix;
675 $cvCookies = $this->getCacheVaryCookies();
676 $xvo = 'X-Vary-Options: Accept-Encoding;list-contains=gzip,Cookie;';
678 foreach ( $cvCookies as $cookieName ) {
684 $xvo .= 'string-contains=' . $cookieName;
689 public function sendCacheControl() {
690 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
692 $response = $wgRequest->response();
693 if ($wgUseETag && $this->mETag
)
694 $response->header("ETag: $this->mETag");
696 # don't serve compressed data to clients who can't handle it
697 # maintain different caches for logged-in users and non-logged in ones
698 $response->header( 'Vary: Accept-Encoding, Cookie' );
700 # Add an X-Vary-Options header for Squid with Wikimedia patches
701 $response->header( $this->getXVO() );
703 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache
) {
704 if( $wgUseSquid && session_id() == '' &&
705 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 && !$this->haveCacheVaryCookies() )
708 # We'll purge the proxy cache explicitly, but require end user agents
709 # to revalidate against the proxy on each visit.
710 # Surrogate-Control controls our Squid, Cache-Control downstream caches
711 wfDebug( __METHOD__
. ": proxy caching with ESI; {$this->mLastModified} **\n", false );
712 # start with a shorter timeout for initial testing
713 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
714 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
715 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
717 # We'll purge the proxy cache for anons explicitly, but require end user agents
718 # to revalidate against the proxy on each visit.
719 # IMPORTANT! The Squid needs to replace the Cache-Control header with
720 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
721 wfDebug( __METHOD__
. ": local proxy caching; {$this->mLastModified} **\n", false );
722 # start with a shorter timeout for initial testing
723 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
724 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
727 # We do want clients to cache if they can, but they *must* check for updates
728 # on revisiting the page.
729 wfDebug( __METHOD__
. ": private caching; {$this->mLastModified} **\n", false );
730 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
731 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
733 if($this->mLastModified
) $response->header( "Last-modified: {$this->mLastModified}" );
735 wfDebug( __METHOD__
. ": no caching **\n", false );
737 # In general, the absence of a last modified header should be enough to prevent
738 # the client from using its cache. We send a few other things just to make sure.
739 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
740 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
741 $response->header( 'Pragma: no-cache' );
746 * Finally, all the text has been munged and accumulated into
747 * the object, let's actually output it:
749 public function output() {
750 global $wgUser, $wgOutputEncoding, $wgRequest;
751 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
752 global $wgJsMimeType, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
753 global $wgServer, $wgEnableMWSuggest;
755 if( $this->mDoNothing
){
759 wfProfileIn( __METHOD__
);
761 if ( '' != $this->mRedirect
) {
762 # Standards require redirect URLs to be absolute
763 $this->mRedirect
= wfExpandUrl( $this->mRedirect
);
764 if( $this->mRedirectCode
== '301') {
765 if( !$wgDebugRedirects ) {
766 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
768 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
771 $this->sendCacheControl();
773 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
774 if( $wgDebugRedirects ) {
775 $url = htmlspecialchars( $this->mRedirect
);
776 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
777 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
778 print "</body>\n</html>\n";
780 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
782 wfProfileOut( __METHOD__
);
785 elseif ( $this->mStatusCode
)
787 $statusMessage = array(
789 101 => 'Switching Protocols',
794 203 => 'Non-Authoritative Information',
796 205 => 'Reset Content',
797 206 => 'Partial Content',
798 207 => 'Multi-Status',
799 300 => 'Multiple Choices',
800 301 => 'Moved Permanently',
803 304 => 'Not Modified',
805 307 => 'Temporary Redirect',
806 400 => 'Bad Request',
807 401 => 'Unauthorized',
808 402 => 'Payment Required',
811 405 => 'Method Not Allowed',
812 406 => 'Not Acceptable',
813 407 => 'Proxy Authentication Required',
814 408 => 'Request Timeout',
817 411 => 'Length Required',
818 412 => 'Precondition Failed',
819 413 => 'Request Entity Too Large',
820 414 => 'Request-URI Too Large',
821 415 => 'Unsupported Media Type',
822 416 => 'Request Range Not Satisfiable',
823 417 => 'Expectation Failed',
824 422 => 'Unprocessable Entity',
826 424 => 'Failed Dependency',
827 500 => 'Internal Server Error',
828 501 => 'Not Implemented',
829 502 => 'Bad Gateway',
830 503 => 'Service Unavailable',
831 504 => 'Gateway Timeout',
832 505 => 'HTTP Version Not Supported',
833 507 => 'Insufficient Storage'
836 if ( $statusMessage[$this->mStatusCode
] )
837 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
840 $sk = $wgUser->getSkin();
843 $this->addScriptFile( 'ajax.js' );
845 wfRunHooks( 'AjaxAddScript', array( &$this ) );
847 if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) {
848 $this->addScriptFile( 'ajaxsearch.js' );
849 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
852 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
853 $this->addScriptFile( 'ajaxwatch.js' );
856 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
857 $this->addScriptFile( 'mwsuggest.js' );
861 if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
862 $this->addScriptFile( 'rightclickedit.js' );
866 # Buffer output; final headers may depend on later processing
869 # Disable temporary placeholders, so that the skin produces HTML
870 $sk->postParseLinkColour( false );
872 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
873 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
875 if ($this->mArticleBodyOnly
) {
876 $this->out($this->mBodytext
);
878 // Hook that allows last minute changes to the output page, e.g.
879 // adding of CSS or Javascript by extensions.
880 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
882 wfProfileIn( 'Output-skin' );
883 $sk->outputPage( $this );
884 wfProfileOut( 'Output-skin' );
887 $this->sendCacheControl();
889 wfProfileOut( __METHOD__
);
896 public function out( $ins ) {
897 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
898 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
901 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
902 if ( false === $outs ) { $outs = $ins; }
910 public static function setEncodings() {
911 global $wgInputEncoding, $wgOutputEncoding;
912 global $wgUser, $wgContLang;
914 $wgInputEncoding = strtolower( $wgInputEncoding );
916 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
917 $wgOutputEncoding = strtolower( $wgOutputEncoding );
920 $wgOutputEncoding = $wgInputEncoding;
924 * Deprecated, use wfReportTime() instead.
928 public function reportTime() {
929 wfDeprecated( __METHOD__
);
930 $time = wfReportTime();
935 * Produce a "user is blocked" page.
937 * @param bool $return Whether to have a "return to $wgTitle" message or not.
940 function blockedPage( $return = true ) {
941 global $wgUser, $wgContLang, $wgTitle, $wgLang;
943 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
944 $this->setRobotPolicy( 'noindex,nofollow' );
945 $this->setArticleRelated( false );
947 $name = User
::whoIs( $wgUser->blockedBy() );
948 $reason = $wgUser->blockedFor();
949 if( $reason == '' ) {
950 $reason = wfMsg( 'blockednoreason' );
952 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
955 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
957 $blockid = $wgUser->mBlock
->mId
;
959 $blockExpiry = $wgUser->mBlock
->mExpiry
;
960 if ( $blockExpiry == 'infinity' ) {
961 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
962 // Search for localization in 'ipboptions'
963 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
964 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
965 if ( strpos( $option, ":" ) === false )
967 list( $show, $value ) = explode( ":", $option );
968 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
969 $blockExpiry = $show;
974 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
977 if ( $wgUser->mBlock
->mAuto
) {
978 $msg = 'autoblockedtext';
980 $msg = 'blockedtext';
983 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
984 * This could be a username, an ip range, or a single ip. */
985 $intended = $wgUser->mBlock
->mAddress
;
987 $this->addWikiMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
989 # Don't auto-return to special pages
991 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle : NULL;
992 $this->returnToMain( null, $return );
997 * Output a standard error page
999 * @param string $title Message key for page title
1000 * @param string $msg Message key for page text
1001 * @param array $params Message parameters
1003 public function showErrorPage( $title, $msg, $params = array() ) {
1005 if ( isset($wgTitle) ) {
1006 $this->mDebugtext
.= 'Original title: ' . $wgTitle->getPrefixedText() . "\n";
1008 $this->setPageTitle( wfMsg( $title ) );
1009 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1010 $this->setRobotPolicy( 'noindex,nofollow' );
1011 $this->setArticleRelated( false );
1012 $this->enableClientCache( false );
1013 $this->mRedirect
= '';
1014 $this->mBodytext
= '';
1016 array_unshift( $params, 'parse' );
1017 array_unshift( $params, $msg );
1018 $this->addHtml( call_user_func_array( 'wfMsgExt', $params ) );
1020 $this->returnToMain();
1024 * Output a standard permission error page
1026 * @param array $errors Error message keys
1028 public function showPermissionsErrorPage( $errors, $action = null )
1032 $this->mDebugtext
.= 'Original title: ' .
1033 $wgTitle->getPrefixedText() . "\n";
1034 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
1035 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
1036 $this->setRobotPolicy( 'noindex,nofollow' );
1037 $this->setArticleRelated( false );
1038 $this->enableClientCache( false );
1039 $this->mRedirect
= '';
1040 $this->mBodytext
= '';
1041 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
1045 public function errorpage( $title, $msg ) {
1046 wfDeprecated( __METHOD__
);
1047 throw new ErrorPageError( $title, $msg );
1051 * Display an error page indicating that a given version of MediaWiki is
1052 * required to use it
1054 * @param mixed $version The version of MediaWiki needed to use the page
1056 public function versionRequired( $version ) {
1057 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
1058 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
1059 $this->setRobotPolicy( 'noindex,nofollow' );
1060 $this->setArticleRelated( false );
1061 $this->mBodytext
= '';
1063 $this->addWikiMsg( 'versionrequiredtext', $version );
1064 $this->returnToMain();
1068 * Display an error page noting that a given permission bit is required.
1070 * @param string $permission key required
1072 public function permissionRequired( $permission ) {
1073 global $wgGroupPermissions, $wgUser;
1075 $this->setPageTitle( wfMsg( 'badaccess' ) );
1076 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1077 $this->setRobotPolicy( 'noindex,nofollow' );
1078 $this->setArticleRelated( false );
1079 $this->mBodytext
= '';
1082 foreach( $wgGroupPermissions as $key => $value ) {
1083 if( isset( $value[$permission] ) && $value[$permission] == true ) {
1084 $groupName = User
::getGroupName( $key );
1085 $groupPage = User
::getGroupPage( $key );
1087 $skin = $wgUser->getSkin();
1088 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
1090 $groups[] = $groupName;
1094 $n = count( $groups );
1095 $groups = implode( ', ', $groups );
1100 $message = wfMsgHtml( "badaccess-group$n", $groups );
1103 $message = wfMsgHtml( 'badaccess-groups', $groups );
1105 $this->addHtml( $message );
1106 $this->returnToMain();
1110 * Use permissionRequired.
1113 public function sysopRequired() {
1114 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
1118 * Use permissionRequired.
1121 public function developerRequired() {
1122 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
1126 * Produce the stock "please login to use the wiki" page
1128 public function loginToUse() {
1129 global $wgUser, $wgTitle, $wgContLang;
1131 if( $wgUser->isLoggedIn() ) {
1132 $this->permissionRequired( 'read' );
1136 $skin = $wgUser->getSkin();
1138 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1139 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1140 $this->setRobotPolicy( 'noindex,nofollow' );
1141 $this->setArticleFlag( false );
1143 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1144 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1145 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1146 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
1148 # Don't return to the main page if the user can't read it
1149 # otherwise we'll end up in a pointless loop
1150 $mainPage = Title
::newMainPage();
1151 if( $mainPage->userCanRead() )
1152 $this->returnToMain( null, $mainPage );
1156 public function databaseError( $fname, $sql, $error, $errno ) {
1157 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1161 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
1162 * @return string The wikitext error-messages, formatted into a list.
1164 public function formatPermissionsErrorMessage( $errors, $action = null ) {
1165 if ($action == null) {
1166 $text = wfMsgNoTrans( 'permissionserrorstext', count($errors)). "\n\n";
1168 $action_desc = wfMsg( "right-$action" );
1169 $action_desc[0] = strtolower($action_desc[0]);
1170 $text = wfMsgNoTrans( 'permissionserrorstext-withaction', count($errors), $action_desc ) . "\n\n";
1173 if (count( $errors ) > 1) {
1174 $text .= '<ul class="permissions-errors">' . "\n";
1176 foreach( $errors as $error )
1179 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1184 $text .= '<div class="permissions-errors">' . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . '</div>';
1191 * Display a page stating that the Wiki is in read-only mode,
1192 * and optionally show the source of the page that the user
1193 * was trying to edit. Should only be called (for this
1194 * purpose) after wfReadOnly() has returned true.
1196 * For historical reasons, this function is _also_ used to
1197 * show the error message when a user tries to edit a page
1198 * they are not allowed to edit. (Unless it's because they're
1199 * blocked, then we show blockedPage() instead.) In this
1200 * case, the second parameter should be set to true and a list
1201 * of reasons supplied as the third parameter.
1203 * @todo Needs to be split into multiple functions.
1205 * @param string $source Source code to show (or null).
1206 * @param bool $protected Is this a permissions error?
1207 * @param array $reasons List of reasons for this error, as returned by Title::getUserPermissionsErrors().
1209 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
1210 global $wgUser, $wgTitle;
1211 $skin = $wgUser->getSkin();
1213 $this->setRobotPolicy( 'noindex,nofollow' );
1214 $this->setArticleRelated( false );
1216 // If no reason is given, just supply a default "I can't let you do
1217 // that, Dave" message. Should only occur if called by legacy code.
1218 if ( $protected && empty($reasons) ) {
1219 $reasons[] = array( 'badaccess-group0' );
1222 if ( !empty($reasons) ) {
1223 // Permissions error
1225 $this->setPageTitle( wfMsg( 'viewsource' ) );
1226 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1228 $this->setPageTitle( wfMsg( 'badaccess' ) );
1230 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) );
1232 // Wiki is read only
1233 $this->setPageTitle( wfMsg( 'readonly' ) );
1234 $reason = wfReadOnlyReason();
1235 $this->addWikiMsg( 'readonlytext', $reason );
1238 // Show source, if supplied
1239 if( is_string( $source ) ) {
1240 $this->addWikiMsg( 'viewsourcetext' );
1241 $text = Xml
::openElement( 'textarea',
1242 array( 'id' => 'wpTextbox1',
1243 'name' => 'wpTextbox1',
1244 'cols' => $wgUser->getOption( 'cols' ),
1245 'rows' => $wgUser->getOption( 'rows' ),
1246 'readonly' => 'readonly' ) );
1247 $text .= htmlspecialchars( $source );
1248 $text .= Xml
::closeElement( 'textarea' );
1249 $this->addHTML( $text );
1251 // Show templates used by this article
1252 $skin = $wgUser->getSkin();
1253 $article = new Article( $wgTitle );
1254 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1257 # If the title doesn't exist, it's fairly pointless to print a return
1258 # link to it. After all, you just tried editing it and couldn't, so
1259 # what's there to do there?
1260 if( $wgTitle->exists() ) {
1261 $this->returnToMain( null, $wgTitle );
1266 public function fatalError( $message ) {
1267 wfDeprecated( __METHOD__
);
1268 throw new FatalError( $message );
1272 public function unexpectedValueError( $name, $val ) {
1273 wfDeprecated( __METHOD__
);
1274 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1278 public function fileCopyError( $old, $new ) {
1279 wfDeprecated( __METHOD__
);
1280 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1284 public function fileRenameError( $old, $new ) {
1285 wfDeprecated( __METHOD__
);
1286 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1290 public function fileDeleteError( $name ) {
1291 wfDeprecated( __METHOD__
);
1292 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1296 public function fileNotFoundError( $name ) {
1297 wfDeprecated( __METHOD__
);
1298 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1301 public function showFatalError( $message ) {
1302 $this->setPageTitle( wfMsg( "internalerror" ) );
1303 $this->setRobotPolicy( "noindex,nofollow" );
1304 $this->setArticleRelated( false );
1305 $this->enableClientCache( false );
1306 $this->mRedirect
= '';
1307 $this->mBodytext
= $message;
1310 public function showUnexpectedValueError( $name, $val ) {
1311 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1314 public function showFileCopyError( $old, $new ) {
1315 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1318 public function showFileRenameError( $old, $new ) {
1319 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1322 public function showFileDeleteError( $name ) {
1323 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1326 public function showFileNotFoundError( $name ) {
1327 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1331 * Add a "return to" link pointing to a specified title
1333 * @param Title $title Title to link
1335 public function addReturnTo( $title ) {
1337 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1338 $this->addHtml( "<p>{$link}</p>\n" );
1342 * Add a "return to" link pointing to a specified title,
1343 * or the title indicated in the request, or else the main page
1345 * @param null $unused No longer used
1346 * @param Title $returnto Title to return to
1348 public function returnToMain( $unused = null, $returnto = NULL ) {
1351 if ( $returnto == NULL ) {
1352 $returnto = $wgRequest->getText( 'returnto' );
1355 if ( '' === $returnto ) {
1356 $returnto = Title
::newMainPage();
1359 if ( is_object( $returnto ) ) {
1360 $titleObj = $returnto;
1362 $titleObj = Title
::newFromText( $returnto );
1364 if ( !is_object( $titleObj ) ) {
1365 $titleObj = Title
::newMainPage();
1368 $this->addReturnTo( $titleObj );
1372 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1373 * and uses the first 10 of them for META keywords
1375 * @param ParserOutput &$parserOutput
1377 private function addKeywords( &$parserOutput ) {
1379 $this->addKeyword( $wgTitle->getPrefixedText() );
1381 $links2d =& $parserOutput->getLinks();
1382 if ( !is_array( $links2d ) ) {
1385 foreach ( $links2d as $dbkeys ) {
1386 foreach( $dbkeys as $dbkey => $unused ) {
1387 $this->addKeyword( $dbkey );
1388 if ( ++
$count > 10 ) {
1396 * @return string The doctype, opening <html>, and head element.
1398 public function headElement() {
1399 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1400 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1401 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1403 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1404 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1409 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1411 if ( '' == $this->getHTMLTitle() ) {
1412 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1415 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1416 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1417 foreach($wgXhtmlNamespaces as $tag => $ns) {
1418 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1420 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1421 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1422 $this->addMeta( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" );
1424 $ret .= $this->getHeadLinks();
1425 global $wgStylePath;
1426 if( $this->isPrintable() ) {
1429 $media = "media='print'";
1431 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1432 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1434 $sk = $wgUser->getSkin();
1435 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1436 $ret .= $this->mScripts
;
1437 $ret .= $sk->getUserStyles();
1438 $ret .= $this->getHeadItems();
1440 if ($wgUseTrackbacks && $this->isArticleRelated())
1441 $ret .= $wgTitle->trackbackRDF();
1443 $ret .= "</head>\n";
1447 protected function addDefaultMeta() {
1449 $this->addMeta( "generator", "MediaWiki $wgVersion" );
1451 $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
1452 if( $p !== 'index,follow' ) {
1453 // http://www.robotstxt.org/wc/meta-user.html
1454 // Only show if it's different from the default robots policy
1455 $this->addMeta( 'robots', $p );
1458 if ( count( $this->mKeywords
) > 0 ) {
1463 $this->addMeta( 'keywords', preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
) ) );
1468 * @return string HTML tag links to be put in the header.
1470 public function getHeadLinks() {
1471 global $wgRequest, $wgFeed;
1473 // Ideally this should happen earlier, somewhere. :P
1474 $this->addDefaultMeta();
1478 foreach ( $this->mMetatags
as $tag ) {
1479 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1481 $tag[0] = substr( $tag[0], 5 );
1485 $tags[] = Xml
::element( 'meta',
1488 'content' => $tag[1] ) );
1490 foreach ( $this->mLinktags
as $tag ) {
1491 $tags[] = Xml
::element( 'link', $tag );
1496 foreach( $this->getSyndicationLinks() as $format => $link ) {
1497 # Use the page name for the title (accessed through $wgTitle since
1498 # there's no other way). In principle, this could lead to issues
1499 # with having the same name for different feeds corresponding to
1500 # the same page, but we can't avoid that at this low a level.
1502 $tags[] = $this->feedLink(
1505 wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) ); # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
1508 # Recent changes feed should appear on every page (except recentchanges,
1509 # that would be redundant). Put it after the per-page feed to avoid
1510 # changing existing behavior. It's still available, probably via a
1511 # menu in your browser.
1513 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
1514 if ( $wgTitle->getPrefixedText() != $rctitle->getPrefixedText() ) {
1517 $tags[] = $this->feedLink(
1519 $rctitle->getFullURL( 'feed=rss' ),
1520 wfMsg( 'site-rss-feed', $wgSitename ) );
1521 $tags[] = $this->feedLink(
1523 $rctitle->getFullURL( 'feed=atom' ),
1524 wfMsg( 'site-atom-feed', $wgSitename ) );
1528 return implode( "\n\t\t", $tags ) . "\n";
1532 * Return URLs for each supported syndication format for this page.
1533 * @return array associating format keys with URLs
1535 public function getSyndicationLinks() {
1536 global $wgTitle, $wgFeedClasses;
1539 if( $this->isSyndicated() ) {
1540 if( is_string( $this->getFeedAppendQuery() ) ) {
1541 $appendQuery = "&" . $this->getFeedAppendQuery();
1546 foreach( $wgFeedClasses as $format => $class ) {
1547 $links[$format] = $wgTitle->getLocalUrl( "feed=$format{$appendQuery}" );
1554 * Generate a <link rel/> for an RSS feed.
1556 private function feedLink( $type, $url, $text ) {
1557 return Xml
::element( 'link', array(
1558 'rel' => 'alternate',
1559 'type' => "application/$type+xml",
1565 * Turn off regular page output and return an error reponse
1566 * for when rate limiting has triggered.
1568 public function rateLimited() {
1571 $this->setPageTitle(wfMsg('actionthrottled'));
1572 $this->setRobotPolicy( 'noindex,follow' );
1573 $this->setArticleRelated( false );
1574 $this->enableClientCache( false );
1575 $this->mRedirect
= '';
1577 $this->setStatusCode(503);
1578 $this->addWikiMsg( 'actionthrottledtext' );
1580 $this->returnToMain( null, $wgTitle );
1584 * Show an "add new section" link?
1588 public function showNewSectionLink() {
1589 return $this->mNewSectionLink
;
1593 * Show a warning about slave lag
1595 * If the lag is higher than $wgSlaveLagCritical seconds,
1596 * then the warning is a bit more obvious. If the lag is
1597 * lower than $wgSlaveLagWarning, then no warning is shown.
1599 * @param int $lag Slave lag
1601 public function showLagWarning( $lag ) {
1602 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1603 if( $lag >= $wgSlaveLagWarning ) {
1604 $message = $lag < $wgSlaveLagCritical
1607 $warning = wfMsgExt( $message, 'parse', $lag );
1608 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );
1613 * Add a wikitext-formatted message to the output.
1614 * This is equivalent to:
1616 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
1618 public function addWikiMsg( /*...*/ ) {
1619 $args = func_get_args();
1620 $name = array_shift( $args );
1621 $this->addWikiMsgArray( $name, $args );
1625 * Add a wikitext-formatted message to the output.
1626 * Like addWikiMsg() except the parameters are taken as an array
1627 * instead of a variable argument list.
1629 * $options is passed through to wfMsgExt(), see that function for details.
1631 public function addWikiMsgArray( $name, $args, $options = array() ) {
1632 $options[] = 'parse';
1633 $text = wfMsgExt( $name, $options, $args );
1634 $this->addHTML( $text );
1638 * This function takes a number of message/argument specifications, wraps them in
1639 * some overall structure, and then parses the result and adds it to the output.
1641 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
1642 * on. The subsequent arguments may either be strings, in which case they are the
1643 * message names, or an arrays, in which case the first element is the message name,
1644 * and subsequent elements are the parameters to that message.
1646 * The special named parameter 'options' in a message specification array is passed
1647 * through to the $options parameter of wfMsgExt().
1649 * Don't use this for messages that are not in users interface language.
1653 * $wgOut->wrapWikiMsg( '<div class="error">$1</div>', 'some-error' );
1657 * $wgOut->addWikiText( '<div class="error">' . wfMsgNoTrans( 'some-error' ) . '</div>' );
1659 public function wrapWikiMsg( $wrap /*, ...*/ ) {
1660 $msgSpecs = func_get_args();
1661 array_shift( $msgSpecs );
1662 $msgSpecs = array_values( $msgSpecs );
1664 foreach ( $msgSpecs as $n => $spec ) {
1666 if ( is_array( $spec ) ) {
1668 $name = array_shift( $args );
1669 if ( isset( $args['options'] ) ) {
1670 $options = $args['options'];
1671 unset( $args['options'] );
1677 $s = str_replace( '$' . ($n+
1), wfMsgExt( $name, $options, $args ), $s );
1679 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );