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 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
476 $this->addCategoryLinks( $parserOutput->getCategories() );
477 $this->mNewSectionLink
= $parserOutput->getNewSection();
478 $this->addKeywords( $parserOutput );
479 $this->mParseWarnings
= $parserOutput->getWarnings();
480 if ( $parserOutput->getCacheTime() == -1 ) {
481 $this->enableClientCache( false );
483 $this->mNoGallery
= $parserOutput->getNoGallery();
484 $this->mHeadItems
= array_merge( $this->mHeadItems
, (array)$parserOutput->mHeadItems
);
486 $this->mTemplateIds
= wfArrayMerge( $this->mTemplateIds
, (array)$parserOutput->mTemplateIds
);
489 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
490 $this->setPageTitle( $dt );
492 // Hooks registered in the object
493 global $wgParserOutputHooks;
494 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
495 list( $hookName, $data ) = $hookInfo;
496 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
497 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
501 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
506 * @param ParserOutput &$parserOutput
508 function addParserOutput( &$parserOutput ) {
509 $this->addParserOutputNoText( $parserOutput );
510 $text = $parserOutput->getText();
511 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
512 $this->addHTML( $text );
516 * Add wikitext to the buffer, assuming that this is the primary text for a page view
517 * Saves the text into the parser cache if possible.
519 * @param string $text
520 * @param Article $article
522 * @deprecated Use Article::outputWikitext
524 public function addPrimaryWikiText( $text, $article, $cache = true ) {
525 global $wgParser, $wgUser;
527 wfDeprecated( __METHOD__
);
529 $popts = $this->parserOptions();
530 $popts->setTidy(true);
531 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
532 $popts, true, true, $this->mRevisionId
);
533 $popts->setTidy(false);
534 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
535 $parserCache = ParserCache
::singleton();
536 $parserCache->save( $parserOutput, $article, $wgUser );
539 $this->addParserOutput( $parserOutput );
543 * @deprecated use addWikiTextTidy()
545 public function addSecondaryWikiText( $text, $linestart = true ) {
547 wfDeprecated( __METHOD__
);
548 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
552 * Add wikitext with tidy enabled
554 public function addWikiTextTidy( $text, $linestart = true ) {
556 $this->addWikiTextTitleTidy($text, $wgTitle, $linestart);
561 * Add the output of a QuickTemplate to the output buffer
563 * @param QuickTemplate $template
565 public function addTemplate( &$template ) {
567 $template->execute();
568 $this->addHTML( ob_get_contents() );
573 * Parse wikitext and return the HTML.
575 * @param string $text
576 * @param bool $linestart Is this the start of a line?
577 * @param bool $interface ??
579 public function parse( $text, $linestart = true, $interface = false ) {
580 global $wgParser, $wgTitle;
581 $popts = $this->parserOptions();
582 if ( $interface) { $popts->setInterfaceMessage(true); }
583 $parserOutput = $wgParser->parse( $text, $wgTitle, $popts,
584 $linestart, true, $this->mRevisionId
);
585 if ( $interface) { $popts->setInterfaceMessage(false); }
586 return $parserOutput->getText();
590 * @param Article $article
593 * @return bool True if successful, else false.
595 public function tryParserCache( &$article, $user ) {
596 $parserCache = ParserCache
::singleton();
597 $parserOutput = $parserCache->get( $article, $user );
598 if ( $parserOutput !== false ) {
599 $this->addParserOutput( $parserOutput );
607 * @param int $maxage Maximum cache time on the Squid, in seconds.
609 public function setSquidMaxage( $maxage ) {
610 $this->mSquidMaxage
= $maxage;
614 * Use enableClientCache(false) to force it to send nocache headers
617 public function enableClientCache( $state ) {
618 return wfSetVar( $this->mEnableClientCache
, $state );
621 function getCacheVaryCookies() {
622 global $wgCookiePrefix, $wgCacheVaryCookies;
624 if ( $cookies === null ) {
625 $cookies = array_merge(
627 "{$wgCookiePrefix}Token",
628 "{$wgCookiePrefix}LoggedOut",
633 wfRunHooks('GetCacheVaryCookies', array( $this, &$cookies ) );
638 function uncacheableBecauseRequestVars() {
640 return $wgRequest->getText('useskin', false) === false
641 && $wgRequest->getText('uselang', false) === false;
645 * Check if the request has a cache-varying cookie header
646 * If it does, it's very important that we don't allow public caching
648 function haveCacheVaryCookies() {
649 global $wgRequest, $wgCookiePrefix;
650 $cookieHeader = $wgRequest->getHeader( 'cookie' );
651 if ( $cookieHeader === false ) {
654 $cvCookies = $this->getCacheVaryCookies();
655 foreach ( $cvCookies as $cookieName ) {
656 # Check for a simple string match, like the way squid does it
657 if ( strpos( $cookieHeader, $cookieName ) ) {
658 wfDebug( __METHOD__
.": found $cookieName\n" );
662 wfDebug( __METHOD__
.": no cache-varying cookies found\n" );
666 /** Get a complete X-Vary-Options header */
667 public function getXVO() {
668 global $wgCookiePrefix;
669 $cvCookies = $this->getCacheVaryCookies();
670 $xvo = 'X-Vary-Options: Accept-Encoding;list-contains=gzip,Cookie;';
672 foreach ( $cvCookies as $cookieName ) {
678 $xvo .= 'string-contains=' . $cookieName;
683 public function sendCacheControl() {
684 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
686 $response = $wgRequest->response();
687 if ($wgUseETag && $this->mETag
)
688 $response->header("ETag: $this->mETag");
690 # don't serve compressed data to clients who can't handle it
691 # maintain different caches for logged-in users and non-logged in ones
692 $response->header( 'Vary: Accept-Encoding, Cookie' );
694 # Add an X-Vary-Options header for Squid with Wikimedia patches
695 $response->header( $this->getXVO() );
697 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache
) {
698 if( $wgUseSquid && session_id() == '' &&
699 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 && !$this->haveCacheVaryCookies() )
702 # We'll purge the proxy cache explicitly, but require end user agents
703 # to revalidate against the proxy on each visit.
704 # Surrogate-Control controls our Squid, Cache-Control downstream caches
705 wfDebug( __METHOD__
. ": proxy caching with ESI; {$this->mLastModified} **\n", false );
706 # start with a shorter timeout for initial testing
707 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
708 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
709 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
711 # We'll purge the proxy cache for anons explicitly, but require end user agents
712 # to revalidate against the proxy on each visit.
713 # IMPORTANT! The Squid needs to replace the Cache-Control header with
714 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
715 wfDebug( __METHOD__
. ": local proxy caching; {$this->mLastModified} **\n", false );
716 # start with a shorter timeout for initial testing
717 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
718 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
721 # We do want clients to cache if they can, but they *must* check for updates
722 # on revisiting the page.
723 wfDebug( __METHOD__
. ": private caching; {$this->mLastModified} **\n", false );
724 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
725 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
727 if($this->mLastModified
) $response->header( "Last-modified: {$this->mLastModified}" );
729 wfDebug( __METHOD__
. ": no caching **\n", false );
731 # In general, the absence of a last modified header should be enough to prevent
732 # the client from using its cache. We send a few other things just to make sure.
733 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
734 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
735 $response->header( 'Pragma: no-cache' );
740 * Finally, all the text has been munged and accumulated into
741 * the object, let's actually output it:
743 public function output() {
744 global $wgUser, $wgOutputEncoding, $wgRequest;
745 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
746 global $wgJsMimeType, $wgUseAjax, $wgAjaxSearch, $wgAjaxWatch;
747 global $wgServer, $wgEnableMWSuggest;
749 if( $this->mDoNothing
){
753 wfProfileIn( __METHOD__
);
755 if ( '' != $this->mRedirect
) {
756 # Standards require redirect URLs to be absolute
757 $this->mRedirect
= wfExpandUrl( $this->mRedirect
);
758 if( $this->mRedirectCode
== '301') {
759 if( !$wgDebugRedirects ) {
760 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
762 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
765 $this->sendCacheControl();
767 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
768 if( $wgDebugRedirects ) {
769 $url = htmlspecialchars( $this->mRedirect
);
770 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
771 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
772 print "</body>\n</html>\n";
774 $wgRequest->response()->header( 'Location: '.$this->mRedirect
);
776 wfProfileOut( __METHOD__
);
779 elseif ( $this->mStatusCode
)
781 $statusMessage = array(
783 101 => 'Switching Protocols',
788 203 => 'Non-Authoritative Information',
790 205 => 'Reset Content',
791 206 => 'Partial Content',
792 207 => 'Multi-Status',
793 300 => 'Multiple Choices',
794 301 => 'Moved Permanently',
797 304 => 'Not Modified',
799 307 => 'Temporary Redirect',
800 400 => 'Bad Request',
801 401 => 'Unauthorized',
802 402 => 'Payment Required',
805 405 => 'Method Not Allowed',
806 406 => 'Not Acceptable',
807 407 => 'Proxy Authentication Required',
808 408 => 'Request Timeout',
811 411 => 'Length Required',
812 412 => 'Precondition Failed',
813 413 => 'Request Entity Too Large',
814 414 => 'Request-URI Too Large',
815 415 => 'Unsupported Media Type',
816 416 => 'Request Range Not Satisfiable',
817 417 => 'Expectation Failed',
818 422 => 'Unprocessable Entity',
820 424 => 'Failed Dependency',
821 500 => 'Internal Server Error',
822 501 => 'Not Implemented',
823 502 => 'Bad Gateway',
824 503 => 'Service Unavailable',
825 504 => 'Gateway Timeout',
826 505 => 'HTTP Version Not Supported',
827 507 => 'Insufficient Storage'
830 if ( $statusMessage[$this->mStatusCode
] )
831 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
834 $sk = $wgUser->getSkin();
837 $this->addScriptFile( 'ajax.js' );
839 wfRunHooks( 'AjaxAddScript', array( &$this ) );
841 if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) {
842 $this->addScriptFile( 'ajaxsearch.js' );
843 $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
846 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
847 $this->addScriptFile( 'ajaxwatch.js' );
850 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
851 $this->addScriptFile( 'mwsuggest.js' );
855 if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
856 $this->addScriptFile( 'rightclickedit.js' );
860 # Buffer output; final headers may depend on later processing
863 # Disable temporary placeholders, so that the skin produces HTML
864 $sk->postParseLinkColour( false );
866 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
867 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
869 if ($this->mArticleBodyOnly
) {
870 $this->out($this->mBodytext
);
872 // Hook that allows last minute changes to the output page, e.g.
873 // adding of CSS or Javascript by extensions.
874 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
876 wfProfileIn( 'Output-skin' );
877 $sk->outputPage( $this );
878 wfProfileOut( 'Output-skin' );
881 $this->sendCacheControl();
883 wfProfileOut( __METHOD__
);
890 public function out( $ins ) {
891 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
892 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
895 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
896 if ( false === $outs ) { $outs = $ins; }
904 public static function setEncodings() {
905 global $wgInputEncoding, $wgOutputEncoding;
906 global $wgUser, $wgContLang;
908 $wgInputEncoding = strtolower( $wgInputEncoding );
910 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
911 $wgOutputEncoding = strtolower( $wgOutputEncoding );
914 $wgOutputEncoding = $wgInputEncoding;
918 * Deprecated, use wfReportTime() instead.
922 public function reportTime() {
923 wfDeprecated( __METHOD__
);
924 $time = wfReportTime();
929 * Produce a "user is blocked" page.
931 * @param bool $return Whether to have a "return to $wgTitle" message or not.
934 function blockedPage( $return = true ) {
935 global $wgUser, $wgContLang, $wgTitle, $wgLang;
937 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
938 $this->setRobotPolicy( 'noindex,nofollow' );
939 $this->setArticleRelated( false );
941 $name = User
::whoIs( $wgUser->blockedBy() );
942 $reason = $wgUser->blockedFor();
943 if( $reason == '' ) {
944 $reason = wfMsg( 'blockednoreason' );
946 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
949 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
951 $blockid = $wgUser->mBlock
->mId
;
953 $blockExpiry = $wgUser->mBlock
->mExpiry
;
954 if ( $blockExpiry == 'infinity' ) {
955 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
956 // Search for localization in 'ipboptions'
957 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
958 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
959 if ( strpos( $option, ":" ) === false )
961 list( $show, $value ) = explode( ":", $option );
962 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
963 $blockExpiry = $show;
968 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
971 if ( $wgUser->mBlock
->mAuto
) {
972 $msg = 'autoblockedtext';
974 $msg = 'blockedtext';
977 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
978 * This could be a username, an ip range, or a single ip. */
979 $intended = $wgUser->mBlock
->mAddress
;
981 $this->addWikiMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
983 # Don't auto-return to special pages
985 $return = $wgTitle->getNamespace() > -1 ?
$wgTitle : NULL;
986 $this->returnToMain( null, $return );
991 * Output a standard error page
993 * @param string $title Message key for page title
994 * @param string $msg Message key for page text
995 * @param array $params Message parameters
997 public function showErrorPage( $title, $msg, $params = array() ) {
999 if ( isset($wgTitle) ) {
1000 $this->mDebugtext
.= 'Original title: ' . $wgTitle->getPrefixedText() . "\n";
1002 $this->setPageTitle( wfMsg( $title ) );
1003 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1004 $this->setRobotPolicy( 'noindex,nofollow' );
1005 $this->setArticleRelated( false );
1006 $this->enableClientCache( false );
1007 $this->mRedirect
= '';
1008 $this->mBodytext
= '';
1010 array_unshift( $params, 'parse' );
1011 array_unshift( $params, $msg );
1012 $this->addHtml( call_user_func_array( 'wfMsgExt', $params ) );
1014 $this->returnToMain();
1018 * Output a standard permission error page
1020 * @param array $errors Error message keys
1022 public function showPermissionsErrorPage( $errors, $action = null )
1026 $this->mDebugtext
.= 'Original title: ' .
1027 $wgTitle->getPrefixedText() . "\n";
1028 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
1029 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
1030 $this->setRobotPolicy( 'noindex,nofollow' );
1031 $this->setArticleRelated( false );
1032 $this->enableClientCache( false );
1033 $this->mRedirect
= '';
1034 $this->mBodytext
= '';
1035 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
1039 public function errorpage( $title, $msg ) {
1040 wfDeprecated( __METHOD__
);
1041 throw new ErrorPageError( $title, $msg );
1045 * Display an error page indicating that a given version of MediaWiki is
1046 * required to use it
1048 * @param mixed $version The version of MediaWiki needed to use the page
1050 public function versionRequired( $version ) {
1051 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
1052 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
1053 $this->setRobotPolicy( 'noindex,nofollow' );
1054 $this->setArticleRelated( false );
1055 $this->mBodytext
= '';
1057 $this->addWikiMsg( 'versionrequiredtext', $version );
1058 $this->returnToMain();
1062 * Display an error page noting that a given permission bit is required.
1064 * @param string $permission key required
1066 public function permissionRequired( $permission ) {
1067 global $wgGroupPermissions, $wgUser;
1069 $this->setPageTitle( wfMsg( 'badaccess' ) );
1070 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1071 $this->setRobotPolicy( 'noindex,nofollow' );
1072 $this->setArticleRelated( false );
1073 $this->mBodytext
= '';
1076 foreach( $wgGroupPermissions as $key => $value ) {
1077 if( isset( $value[$permission] ) && $value[$permission] == true ) {
1078 $groupName = User
::getGroupName( $key );
1079 $groupPage = User
::getGroupPage( $key );
1081 $skin = $wgUser->getSkin();
1082 $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
1084 $groups[] = $groupName;
1088 $n = count( $groups );
1089 $groups = implode( ', ', $groups );
1094 $message = wfMsgHtml( "badaccess-group$n", $groups );
1097 $message = wfMsgHtml( 'badaccess-groups', $groups );
1099 $this->addHtml( $message );
1100 $this->returnToMain();
1104 * Use permissionRequired.
1107 public function sysopRequired() {
1108 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
1112 * Use permissionRequired.
1115 public function developerRequired() {
1116 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
1120 * Produce the stock "please login to use the wiki" page
1122 public function loginToUse() {
1123 global $wgUser, $wgTitle, $wgContLang;
1125 if( $wgUser->isLoggedIn() ) {
1126 $this->permissionRequired( 'read' );
1130 $skin = $wgUser->getSkin();
1132 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1133 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1134 $this->setRobotPolicy( 'noindex,nofollow' );
1135 $this->setArticleFlag( false );
1137 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1138 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1139 $this->addHtml( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1140 $this->addHtml( "\n<!--" . $wgTitle->getPrefixedUrl() . "-->" );
1142 # Don't return to the main page if the user can't read it
1143 # otherwise we'll end up in a pointless loop
1144 $mainPage = Title
::newMainPage();
1145 if( $mainPage->userCanRead() )
1146 $this->returnToMain( null, $mainPage );
1150 public function databaseError( $fname, $sql, $error, $errno ) {
1151 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1155 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
1156 * @return string The wikitext error-messages, formatted into a list.
1158 public function formatPermissionsErrorMessage( $errors, $action = null ) {
1159 if ($action == null) {
1160 $text = wfMsgNoTrans( 'permissionserrorstext', count($errors)). "\n\n";
1162 $action_desc = wfMsg( "right-$action" );
1163 $action_desc[0] = strtolower($action_desc[0]);
1164 $text = wfMsgNoTrans( 'permissionserrorstext-withaction', count($errors), $action_desc ) . "\n\n";
1167 if (count( $errors ) > 1) {
1168 $text .= '<ul class="permissions-errors">' . "\n";
1170 foreach( $errors as $error )
1173 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1178 $text .= '<div class="permissions-errors">' . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . '</div>';
1185 * Display a page stating that the Wiki is in read-only mode,
1186 * and optionally show the source of the page that the user
1187 * was trying to edit. Should only be called (for this
1188 * purpose) after wfReadOnly() has returned true.
1190 * For historical reasons, this function is _also_ used to
1191 * show the error message when a user tries to edit a page
1192 * they are not allowed to edit. (Unless it's because they're
1193 * blocked, then we show blockedPage() instead.) In this
1194 * case, the second parameter should be set to true and a list
1195 * of reasons supplied as the third parameter.
1197 * @todo Needs to be split into multiple functions.
1199 * @param string $source Source code to show (or null).
1200 * @param bool $protected Is this a permissions error?
1201 * @param array $reasons List of reasons for this error, as returned by Title::getUserPermissionsErrors().
1203 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
1204 global $wgUser, $wgTitle;
1205 $skin = $wgUser->getSkin();
1207 $this->setRobotPolicy( 'noindex,nofollow' );
1208 $this->setArticleRelated( false );
1210 // If no reason is given, just supply a default "I can't let you do
1211 // that, Dave" message. Should only occur if called by legacy code.
1212 if ( $protected && empty($reasons) ) {
1213 $reasons[] = array( 'badaccess-group0' );
1216 if ( !empty($reasons) ) {
1217 // Permissions error
1219 $this->setPageTitle( wfMsg( 'viewsource' ) );
1220 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
1222 $this->setPageTitle( wfMsg( 'badaccess' ) );
1224 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) );
1226 // Wiki is read only
1227 $this->setPageTitle( wfMsg( 'readonly' ) );
1228 $reason = wfReadOnlyReason();
1229 $this->addWikiMsg( 'readonlytext', $reason );
1232 // Show source, if supplied
1233 if( is_string( $source ) ) {
1234 $this->addWikiMsg( 'viewsourcetext' );
1235 $text = Xml
::openElement( 'textarea',
1236 array( 'id' => 'wpTextbox1',
1237 'name' => 'wpTextbox1',
1238 'cols' => $wgUser->getOption( 'cols' ),
1239 'rows' => $wgUser->getOption( 'rows' ),
1240 'readonly' => 'readonly' ) );
1241 $text .= htmlspecialchars( $source );
1242 $text .= Xml
::closeElement( 'textarea' );
1243 $this->addHTML( $text );
1245 // Show templates used by this article
1246 $skin = $wgUser->getSkin();
1247 $article = new Article( $wgTitle );
1248 $this->addHTML( $skin->formatTemplates( $article->getUsedTemplates() ) );
1251 # If the title doesn't exist, it's fairly pointless to print a return
1252 # link to it. After all, you just tried editing it and couldn't, so
1253 # what's there to do there?
1254 if( $wgTitle->exists() ) {
1255 $this->returnToMain( null, $wgTitle );
1260 public function fatalError( $message ) {
1261 wfDeprecated( __METHOD__
);
1262 throw new FatalError( $message );
1266 public function unexpectedValueError( $name, $val ) {
1267 wfDeprecated( __METHOD__
);
1268 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1272 public function fileCopyError( $old, $new ) {
1273 wfDeprecated( __METHOD__
);
1274 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1278 public function fileRenameError( $old, $new ) {
1279 wfDeprecated( __METHOD__
);
1280 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1284 public function fileDeleteError( $name ) {
1285 wfDeprecated( __METHOD__
);
1286 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1290 public function fileNotFoundError( $name ) {
1291 wfDeprecated( __METHOD__
);
1292 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1295 public function showFatalError( $message ) {
1296 $this->setPageTitle( wfMsg( "internalerror" ) );
1297 $this->setRobotPolicy( "noindex,nofollow" );
1298 $this->setArticleRelated( false );
1299 $this->enableClientCache( false );
1300 $this->mRedirect
= '';
1301 $this->mBodytext
= $message;
1304 public function showUnexpectedValueError( $name, $val ) {
1305 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1308 public function showFileCopyError( $old, $new ) {
1309 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1312 public function showFileRenameError( $old, $new ) {
1313 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1316 public function showFileDeleteError( $name ) {
1317 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1320 public function showFileNotFoundError( $name ) {
1321 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1325 * Add a "return to" link pointing to a specified title
1327 * @param Title $title Title to link
1329 public function addReturnTo( $title ) {
1331 $link = wfMsg( 'returnto', $wgUser->getSkin()->makeLinkObj( $title ) );
1332 $this->addHtml( "<p>{$link}</p>\n" );
1336 * Add a "return to" link pointing to a specified title,
1337 * or the title indicated in the request, or else the main page
1339 * @param null $unused No longer used
1340 * @param Title $returnto Title to return to
1342 public function returnToMain( $unused = null, $returnto = NULL ) {
1345 if ( $returnto == NULL ) {
1346 $returnto = $wgRequest->getText( 'returnto' );
1349 if ( '' === $returnto ) {
1350 $returnto = Title
::newMainPage();
1353 if ( is_object( $returnto ) ) {
1354 $titleObj = $returnto;
1356 $titleObj = Title
::newFromText( $returnto );
1358 if ( !is_object( $titleObj ) ) {
1359 $titleObj = Title
::newMainPage();
1362 $this->addReturnTo( $titleObj );
1366 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
1367 * and uses the first 10 of them for META keywords
1369 * @param ParserOutput &$parserOutput
1371 private function addKeywords( &$parserOutput ) {
1373 $this->addKeyword( $wgTitle->getPrefixedText() );
1375 $links2d =& $parserOutput->getLinks();
1376 if ( !is_array( $links2d ) ) {
1379 foreach ( $links2d as $dbkeys ) {
1380 foreach( $dbkeys as $dbkey => $unused ) {
1381 $this->addKeyword( $dbkey );
1382 if ( ++
$count > 10 ) {
1390 * @return string The doctype, opening <html>, and head element.
1392 public function headElement() {
1393 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1394 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1395 global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
1397 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
1398 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
1403 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
1405 if ( '' == $this->getHTMLTitle() ) {
1406 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1409 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
1410 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1411 foreach($wgXhtmlNamespaces as $tag => $ns) {
1412 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1414 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1415 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
1416 $this->addMeta( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" );
1418 $ret .= $this->getHeadLinks();
1419 global $wgStylePath;
1420 if( $this->isPrintable() ) {
1423 $media = "media='print'";
1425 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
1426 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
1428 $sk = $wgUser->getSkin();
1429 $ret .= $sk->getHeadScripts( $this->mAllowUserJs
);
1430 $ret .= $this->mScripts
;
1431 $ret .= $sk->getUserStyles();
1432 $ret .= $this->getHeadItems();
1434 if ($wgUseTrackbacks && $this->isArticleRelated())
1435 $ret .= $wgTitle->trackbackRDF();
1437 $ret .= "</head>\n";
1441 protected function addDefaultMeta() {
1443 $this->addMeta( "generator", "MediaWiki $wgVersion" );
1445 $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
1446 if( $p !== 'index,follow' ) {
1447 // http://www.robotstxt.org/wc/meta-user.html
1448 // Only show if it's different from the default robots policy
1449 $this->addMeta( 'robots', $p );
1452 if ( count( $this->mKeywords
) > 0 ) {
1457 $this->addMeta( 'keywords', preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
) ) );
1462 * @return string HTML tag links to be put in the header.
1464 public function getHeadLinks() {
1465 global $wgRequest, $wgFeed;
1467 // Ideally this should happen earlier, somewhere. :P
1468 $this->addDefaultMeta();
1472 foreach ( $this->mMetatags
as $tag ) {
1473 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1475 $tag[0] = substr( $tag[0], 5 );
1479 $tags[] = Xml
::element( 'meta',
1482 'content' => $tag[1] ) );
1484 foreach ( $this->mLinktags
as $tag ) {
1485 $tags[] = Xml
::element( 'link', $tag );
1490 foreach( $this->getSyndicationLinks() as $format => $link ) {
1491 # Use the page name for the title (accessed through $wgTitle since
1492 # there's no other way). In principle, this could lead to issues
1493 # with having the same name for different feeds corresponding to
1494 # the same page, but we can't avoid that at this low a level.
1496 $tags[] = $this->feedLink(
1499 wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) ); # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
1502 # Recent changes feed should appear on every page (except recentchanges,
1503 # that would be redundant). Put it after the per-page feed to avoid
1504 # changing existing behavior. It's still available, probably via a
1505 # menu in your browser.
1507 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
1508 if ( $wgTitle->getPrefixedText() != $rctitle->getPrefixedText() ) {
1511 $tags[] = $this->feedLink(
1513 $rctitle->getFullURL( 'feed=rss' ),
1514 wfMsg( 'site-rss-feed', $wgSitename ) );
1515 $tags[] = $this->feedLink(
1517 $rctitle->getFullURL( 'feed=atom' ),
1518 wfMsg( 'site-atom-feed', $wgSitename ) );
1522 return implode( "\n\t\t", $tags ) . "\n";
1526 * Return URLs for each supported syndication format for this page.
1527 * @return array associating format keys with URLs
1529 public function getSyndicationLinks() {
1530 global $wgTitle, $wgFeedClasses;
1533 if( $this->isSyndicated() ) {
1534 if( is_string( $this->getFeedAppendQuery() ) ) {
1535 $appendQuery = "&" . $this->getFeedAppendQuery();
1540 foreach( $wgFeedClasses as $format => $class ) {
1541 $links[$format] = $wgTitle->getLocalUrl( "feed=$format{$appendQuery}" );
1548 * Generate a <link rel/> for an RSS feed.
1550 private function feedLink( $type, $url, $text ) {
1551 return Xml
::element( 'link', array(
1552 'rel' => 'alternate',
1553 'type' => "application/$type+xml",
1559 * Turn off regular page output and return an error reponse
1560 * for when rate limiting has triggered.
1562 public function rateLimited() {
1565 $this->setPageTitle(wfMsg('actionthrottled'));
1566 $this->setRobotPolicy( 'noindex,follow' );
1567 $this->setArticleRelated( false );
1568 $this->enableClientCache( false );
1569 $this->mRedirect
= '';
1571 $this->setStatusCode(503);
1572 $this->addWikiMsg( 'actionthrottledtext' );
1574 $this->returnToMain( null, $wgTitle );
1578 * Show an "add new section" link?
1582 public function showNewSectionLink() {
1583 return $this->mNewSectionLink
;
1587 * Show a warning about slave lag
1589 * If the lag is higher than $wgSlaveLagCritical seconds,
1590 * then the warning is a bit more obvious. If the lag is
1591 * lower than $wgSlaveLagWarning, then no warning is shown.
1593 * @param int $lag Slave lag
1595 public function showLagWarning( $lag ) {
1596 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1597 if( $lag >= $wgSlaveLagWarning ) {
1598 $message = $lag < $wgSlaveLagCritical
1601 $warning = wfMsgExt( $message, 'parse', $lag );
1602 $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );
1607 * Add a wikitext-formatted message to the output.
1608 * This is equivalent to:
1610 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
1612 public function addWikiMsg( /*...*/ ) {
1613 $args = func_get_args();
1614 $name = array_shift( $args );
1615 $this->addWikiMsgArray( $name, $args );
1619 * Add a wikitext-formatted message to the output.
1620 * Like addWikiMsg() except the parameters are taken as an array
1621 * instead of a variable argument list.
1623 * $options is passed through to wfMsgExt(), see that function for details.
1625 public function addWikiMsgArray( $name, $args, $options = array() ) {
1626 $options[] = 'parse';
1627 $text = wfMsgExt( $name, $options, $args );
1628 $this->addHTML( $text );
1632 * This function takes a number of message/argument specifications, wraps them in
1633 * some overall structure, and then parses the result and adds it to the output.
1635 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
1636 * on. The subsequent arguments may either be strings, in which case they are the
1637 * message names, or an arrays, in which case the first element is the message name,
1638 * and subsequent elements are the parameters to that message.
1640 * The special named parameter 'options' in a message specification array is passed
1641 * through to the $options parameter of wfMsgExt().
1643 * Don't use this for messages that are not in users interface language.
1647 * $wgOut->wrapWikiMsg( '<div class="error">$1</div>', 'some-error' );
1651 * $wgOut->addWikiText( '<div class="error">' . wfMsgNoTrans( 'some-error' ) . '</div>' );
1653 public function wrapWikiMsg( $wrap /*, ...*/ ) {
1654 $msgSpecs = func_get_args();
1655 array_shift( $msgSpecs );
1656 $msgSpecs = array_values( $msgSpecs );
1658 foreach ( $msgSpecs as $n => $spec ) {
1660 if ( is_array( $spec ) ) {
1662 $name = array_shift( $args );
1663 if ( isset( $args['options'] ) ) {
1664 $options = $args['options'];
1665 unset( $args['options'] );
1671 $s = str_replace( '$' . ($n+
1), wfMsgExt( $name, $options, $args ), $s );
1673 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );