2 if ( !defined( 'MEDIAWIKI' ) ) {
10 var $mMetatags = array(), $mKeywords = array(), $mLinktags = array();
11 var $mExtStyles = array();
12 var $mPagetitle = '', $mBodytext = '';
15 * Holds the debug lines that will be outputted as comments in page source if
16 * $wgDebugComments is enabled. See also $wgShowDebug.
17 * TODO: make a getter method for this
19 public $mDebugtext = '';
21 var $mHTMLtitle = '', $mIsarticle = true, $mPrintable = false;
22 var $mSubtitle = '', $mRedirect = '', $mStatusCode;
23 var $mLastModified = '', $mETag = false;
24 var $mCategoryLinks = array(), $mCategories = array(), $mLanguageLinks = array();
26 var $mScripts = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array();
27 var $mInlineMsg = array();
29 var $mTemplateIds = array();
32 var $mSuppressQuickbar = false;
33 var $mDoNothing = false;
34 var $mContainsOldMagic = 0, $mContainsNewMagic = 0;
35 var $mIsArticleRelated = true;
36 protected $mParserOptions = null; // lazy initialised, use parserOptions()
38 var $mFeedLinks = array();
40 var $mEnableClientCache = true;
41 var $mArticleBodyOnly = false;
43 var $mNewSectionLink = false;
44 var $mHideNewSectionLink = false;
45 var $mNoGallery = false;
46 var $mPageTitleActionText = '';
47 var $mParseWarnings = array();
48 var $mSquidMaxage = 0;
49 var $mRevisionId = null;
50 protected $mTitle = null;
53 * An array of stylesheet filenames (relative from skins path), with options
54 * for CSS media, IE conditions, and RTL/LTR direction.
55 * For internal use; add settings in the skin via $this->addStyle()
57 var $styles = array();
60 * Whether to load jQuery core.
62 protected $mJQueryDone = false;
64 private $mIndexPolicy = 'index';
65 private $mFollowPolicy = 'follow';
66 private $mVaryHeader = array(
67 'Accept-Encoding' => array( 'list-contains=gzip' ),
73 * Initialise private variables
75 function __construct() {
76 global $wgAllowUserJs;
77 $this->mAllowUserJs
= $wgAllowUserJs;
81 * Redirect to $url rather than displaying the normal page
83 * @param $url String: URL
84 * @param $responsecode String: HTTP status code
86 public function redirect( $url, $responsecode = '302' ) {
87 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
88 $this->mRedirect
= str_replace( "\n", '', $url );
89 $this->mRedirectCode
= $responsecode;
93 * Get the URL to redirect to, or an empty string if not redirect URL set
97 public function getRedirect() {
98 return $this->mRedirect
;
102 * Set the HTTP status code to send with the output.
104 * @param $statusCode Integer
107 public function setStatusCode( $statusCode ) {
108 $this->mStatusCode
= $statusCode;
112 * Add a new <meta> tag
113 * To add an http-equiv meta tag, precede the name with "http:"
115 * @param $name tag name
116 * @param $val tag value
118 function addMeta( $name, $val ) {
119 array_push( $this->mMetatags
, array( $name, $val ) );
123 * Add a keyword or a list of keywords in the page header
125 * @param $text String or array of strings
127 function addKeyword( $text ) {
128 if( is_array( $text ) ) {
129 $this->mKeywords
= array_merge( $this->mKeywords
, $text );
131 array_push( $this->mKeywords
, $text );
136 * Add a new \<link\> tag to the page header
138 * @param $linkarr Array: associative array of attributes.
140 function addLink( $linkarr ) {
141 array_push( $this->mLinktags
, $linkarr );
145 * Add a new \<link\> with "rel" attribute set to "meta"
147 * @param $linkarr Array: associative array mapping attribute names to their
148 * values, both keys and values will be escaped, and the
149 * "rel" attribute will be automatically added
151 function addMetadataLink( $linkarr ) {
152 # note: buggy CC software only reads first "meta" link
153 static $haveMeta = false;
154 $linkarr['rel'] = $haveMeta ?
'alternate meta' : 'meta';
155 $this->addLink( $linkarr );
160 * Add raw HTML to the list of scripts (including \<script\> tag, etc.)
162 * @param $script String: raw HTML
164 function addScript( $script ) {
165 $this->mScripts
.= $script . "\n";
169 * Register and add a stylesheet from an extension directory.
171 * @param $url String path to sheet. Provide either a full url (beginning
172 * with 'http', etc) or a relative path from the document root
173 * (beginning with '/'). Otherwise it behaves identically to
174 * addStyle() and draws from the /skins folder.
176 public function addExtensionStyle( $url ) {
177 array_push( $this->mExtStyles
, $url );
181 * Get all links added by extensions
185 function getExtStyle() {
186 return $this->mExtStyles
;
190 * Add a JavaScript file out of skins/common, or a given relative path.
192 * @param $file String: filename in skins/common or complete on-server path
194 * @param $version String: style version of the file. Defaults to $wgStyleVersion
196 public function addScriptFile( $file, $version = null ) {
197 global $wgStylePath, $wgStyleVersion;
198 if( substr( $file, 0, 1 ) == '/' ||
preg_match( '#^[a-z]*://#i', $file ) ) {
201 $path = "{$wgStylePath}/common/{$file}";
203 if ( is_null( $version ) )
204 $version = $wgStyleVersion;
205 $this->addScript( Html
::linkedScript( wfAppendQuery( $path, $version ) ) );
209 * Add a self-contained script tag with the given contents
211 * @param $script String: JavaScript text, no <script> tags
213 public function addInlineScript( $script ) {
214 $this->mScripts
.= Html
::inlineScript( "\n$script\n" ) . "\n";
218 * Get all registered JS and CSS tags for the header.
222 function getScript() {
223 return $this->mScripts
. $this->getHeadItems();
227 * Get all header items in a string
231 function getHeadItems() {
233 foreach ( $this->mHeadItems
as $item ) {
240 * Add or replace an header item to the output
242 * @param $name String: item name
243 * @param $value String: raw HTML
245 public function addHeadItem( $name, $value ) {
246 $this->mHeadItems
[$name] = $value;
250 * Check if the header item $name is already set
252 * @param $name String: item name
255 public function hasHeadItem( $name ) {
256 return isset( $this->mHeadItems
[$name] );
260 * Set the value of the ETag HTTP header, only used if $wgUseETag is true
262 * @param $tag String: value of "ETag" header
264 function setETag( $tag ) {
269 * Set whether the output should only contain the body of the article,
270 * without any skin, sidebar, etc.
271 * Used e.g. when calling with "action=render".
273 * @param $only Boolean: whether to output only the body of the article
275 public function setArticleBodyOnly( $only ) {
276 $this->mArticleBodyOnly
= $only;
280 * Return whether the output will contain only the body of the article
284 public function getArticleBodyOnly() {
285 return $this->mArticleBodyOnly
;
289 * checkLastModified tells the client to use the client-cached page if
290 * possible. If sucessful, the OutputPage is disabled so that
291 * any future call to OutputPage->output() have no effect.
293 * Side effect: sets mLastModified for Last-Modified header
295 * @return Boolean: true iff cache-ok headers was sent.
297 public function checkLastModified( $timestamp ) {
298 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
300 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
301 wfDebug( __METHOD__
. ": CACHE DISABLED, NO TIMESTAMP\n" );
304 if( !$wgCachePages ) {
305 wfDebug( __METHOD__
. ": CACHE DISABLED\n", false );
308 if( $wgUser->getOption( 'nocache' ) ) {
309 wfDebug( __METHOD__
. ": USER DISABLED CACHE\n", false );
313 $timestamp = wfTimestamp( TS_MW
, $timestamp );
314 $modifiedTimes = array(
315 'page' => $timestamp,
316 'user' => $wgUser->getTouched(),
317 'epoch' => $wgCacheEpoch
319 wfRunHooks( 'OutputPageCheckLastModified', array( &$modifiedTimes ) );
321 $maxModified = max( $modifiedTimes );
322 $this->mLastModified
= wfTimestamp( TS_RFC2822
, $maxModified );
324 if( empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
325 wfDebug( __METHOD__
. ": client did not send If-Modified-Since header\n", false );
331 foreach ( $modifiedTimes as $name => $value ) {
332 if ( $info !== '' ) {
335 $info .= "$name=" . wfTimestamp( TS_ISO_8601
, $value );
338 # IE sends sizes after the date like this:
339 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
340 # this breaks strtotime().
341 $clientHeader = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
343 wfSuppressWarnings(); // E_STRICT system time bitching
344 $clientHeaderTime = strtotime( $clientHeader );
346 if ( !$clientHeaderTime ) {
347 wfDebug( __METHOD__
. ": unable to parse the client's If-Modified-Since header: $clientHeader\n" );
350 $clientHeaderTime = wfTimestamp( TS_MW
, $clientHeaderTime );
352 wfDebug( __METHOD__
. ": client sent If-Modified-Since: " .
353 wfTimestamp( TS_ISO_8601
, $clientHeaderTime ) . "\n", false );
354 wfDebug( __METHOD__
. ": effective Last-Modified: " .
355 wfTimestamp( TS_ISO_8601
, $maxModified ) . "\n", false );
356 if( $clientHeaderTime < $maxModified ) {
357 wfDebug( __METHOD__
. ": STALE, $info\n", false );
362 # Give a 304 response code and disable body output
363 wfDebug( __METHOD__
. ": NOT MODIFIED, $info\n", false );
364 ini_set( 'zlib.output_compression', 0 );
365 $wgRequest->response()->header( "HTTP/1.1 304 Not Modified" );
366 $this->sendCacheControl();
369 // Don't output a compressed blob when using ob_gzhandler;
370 // it's technically against HTTP spec and seems to confuse
371 // Firefox when the response gets split over two packets.
372 wfClearOutputBuffers();
378 * Override the last modified timestamp
380 * @param $timestamp String: new timestamp, in a format readable by
383 public function setLastModified( $timestamp ) {
384 $this->mLastModified
= wfTimestamp( TS_RFC2822
, $timestamp );
388 * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
390 * @param $policy String: the literal string to output as the contents of
391 * the meta tag. Will be parsed according to the spec and output in
395 public function setRobotPolicy( $policy ) {
396 $policy = Article
::formatRobotPolicy( $policy );
398 if( isset( $policy['index'] ) ) {
399 $this->setIndexPolicy( $policy['index'] );
401 if( isset( $policy['follow'] ) ) {
402 $this->setFollowPolicy( $policy['follow'] );
407 * Set the index policy for the page, but leave the follow policy un-
410 * @param $policy string Either 'index' or 'noindex'.
413 public function setIndexPolicy( $policy ) {
414 $policy = trim( $policy );
415 if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
416 $this->mIndexPolicy
= $policy;
421 * Set the follow policy for the page, but leave the index policy un-
424 * @param $policy String: either 'follow' or 'nofollow'.
427 public function setFollowPolicy( $policy ) {
428 $policy = trim( $policy );
429 if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
430 $this->mFollowPolicy
= $policy;
435 * Set the new value of the "action text", this will be added to the
436 * "HTML title", separated from it with " - ".
438 * @param $text String: new value of the "action text"
440 public function setPageTitleActionText( $text ) {
441 $this->mPageTitleActionText
= $text;
445 * Get the value of the "action text"
449 public function getPageTitleActionText() {
450 if ( isset( $this->mPageTitleActionText
) ) {
451 return $this->mPageTitleActionText
;
456 * "HTML title" means the contents of <title>.
457 * It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
459 public function setHTMLTitle( $name ) {
460 $this->mHTMLtitle
= $name;
464 * Return the "HTML title", i.e. the content of the <title> tag.
468 public function getHTMLTitle() {
469 return $this->mHTMLtitle
;
473 * "Page title" means the contents of \<h1\>. It is stored as a valid HTML fragment.
474 * This function allows good tags like \<sup\> in the \<h1\> tag, but not bad tags like \<script\>.
475 * This function automatically sets \<title\> to the same content as \<h1\> but with all tags removed.
476 * Bad tags that were escaped in \<h1\> will still be escaped in \<title\>, and good tags like \<i\> will be dropped entirely.
478 public function setPageTitle( $name ) {
479 # change "<script>foo&bar</script>" to "<script>foo&bar</script>"
480 # but leave "<i>foobar</i>" alone
481 $nameWithTags = Sanitizer
::normalizeCharReferences( Sanitizer
::removeHTMLtags( $name ) );
482 $this->mPagetitle
= $nameWithTags;
484 $taction = $this->getPageTitleActionText();
485 if( !empty( $taction ) ) {
486 $name .= ' - '.$taction;
489 # change "<i>foo&bar</i>" to "foo&bar"
490 $this->setHTMLTitle( wfMsg( 'pagetitle', Sanitizer
::stripAllTags( $nameWithTags ) ) );
494 * Return the "page title", i.e. the content of the \<h1\> tag.
498 public function getPageTitle() {
499 return $this->mPagetitle
;
503 * Set the Title object to use
505 * @param $t Title object
507 public function setTitle( $t ) {
512 * Get the Title object used in this instance
516 public function getTitle() {
517 if ( $this->mTitle
instanceof Title
) {
518 return $this->mTitle
;
520 wfDebug( __METHOD__
. ' called and $mTitle is null. Return $wgTitle for sanity' );
527 * Replace the subtile with $str
529 * @param $str String: new value of the subtitle
531 public function setSubtitle( $str ) {
532 $this->mSubtitle
= /*$this->parse(*/ $str /*)*/; // @bug 2514
536 * Add $str to the subtitle
538 * @param $str String to add to the subtitle
540 public function appendSubtitle( $str ) {
541 $this->mSubtitle
.= /*$this->parse(*/ $str /*)*/; // @bug 2514
549 public function getSubtitle() {
550 return $this->mSubtitle
;
554 * Set the page as printable, i.e. it'll be displayed with with all
555 * print styles included
557 public function setPrintable() {
558 $this->mPrintable
= true;
562 * Return whether the page is "printable"
566 public function isPrintable() {
567 return $this->mPrintable
;
571 * Disable output completely, i.e. calling output() will have no effect
573 public function disable() {
574 $this->mDoNothing
= true;
578 * Return whether the output will be completely disabled
582 public function isDisabled() {
583 return $this->mDoNothing
;
587 * Show an "add new section" link?
591 public function showNewSectionLink() {
592 return $this->mNewSectionLink
;
596 * Forcibly hide the new section link?
600 public function forceHideNewSectionLink() {
601 return $this->mHideNewSectionLink
;
605 * Add or remove feed links in the page header
606 * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
607 * for the new version
610 * @param $show Boolean: true: add default feeds, false: remove all feeds
612 public function setSyndicated( $show = true ) {
614 $this->setFeedAppendQuery( false );
616 $this->mFeedLinks
= array();
621 * Add default feeds to the page header
622 * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
623 * for the new version
626 * @param $val String: query to append to feed links or false to output
629 public function setFeedAppendQuery( $val ) {
630 global $wgAdvertisedFeedTypes;
632 $this->mFeedLinks
= array();
634 foreach ( $wgAdvertisedFeedTypes as $type ) {
635 $query = "feed=$type";
636 if ( is_string( $val ) ) {
637 $query .= '&' . $val;
639 $this->mFeedLinks
[$type] = $this->getTitle()->getLocalURL( $query );
644 * Add a feed link to the page header
646 * @param $format String: feed type, should be a key of $wgFeedClasses
647 * @param $href String: URL
649 public function addFeedLink( $format, $href ) {
650 global $wgAdvertisedFeedTypes;
652 if ( in_array( $format, $wgAdvertisedFeedTypes ) ) {
653 $this->mFeedLinks
[$format] = $href;
658 * Should we output feed links for this page?
661 public function isSyndicated() {
662 return count( $this->mFeedLinks
) > 0;
666 * Return URLs for each supported syndication format for this page.
667 * @return array associating format keys with URLs
669 public function getSyndicationLinks() {
670 return $this->mFeedLinks
;
674 * Will currently always return null
678 public function getFeedAppendQuery() {
679 return $this->mFeedLinksAppendQuery
;
683 * Set whether the displayed content is related to the source of the
684 * corresponding article on the wiki
685 * Setting true will cause the change "article related" toggle to true
689 public function setArticleFlag( $v ) {
690 $this->mIsarticle
= $v;
692 $this->mIsArticleRelated
= $v;
697 * Return whether the content displayed page is related to the source of
698 * the corresponding article on the wiki
702 public function isArticle() {
703 return $this->mIsarticle
;
707 * Set whether this page is related an article on the wiki
708 * Setting false will cause the change of "article flag" toggle to false
712 public function setArticleRelated( $v ) {
713 $this->mIsArticleRelated
= $v;
715 $this->mIsarticle
= false;
720 * Return whether this page is related an article on the wiki
724 public function isArticleRelated() {
725 return $this->mIsArticleRelated
;
729 * Add new language links
731 * @param $newLinkArray Associative array mapping language code to the page
734 public function addLanguageLinks( $newLinkArray ) {
735 $this->mLanguageLinks +
= $newLinkArray;
739 * Reset the language links and add new language links
741 * @param $newLinkArray Associative array mapping language code to the page
744 public function setLanguageLinks( $newLinkArray ) {
745 $this->mLanguageLinks
= $newLinkArray;
749 * Get the list of language links
751 * @return Associative array mapping language code to the page name
753 public function getLanguageLinks() {
754 return $this->mLanguageLinks
;
758 * Add an array of categories, with names in the keys
760 * @param $categories Associative array mapping category name to its sort key
762 public function addCategoryLinks( $categories ) {
763 global $wgUser, $wgContLang;
765 if ( !is_array( $categories ) ||
count( $categories ) == 0 ) {
769 # Add the links to a LinkBatch
770 $arr = array( NS_CATEGORY
=> $categories );
772 $lb->setArray( $arr );
774 # Fetch existence plus the hiddencat property
775 $dbr = wfGetDB( DB_SLAVE
);
776 $pageTable = $dbr->tableName( 'page' );
777 $where = $lb->constructSet( 'page', $dbr );
778 $propsTable = $dbr->tableName( 'page_props' );
779 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, page_latest, pp_value
780 FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
781 $res = $dbr->query( $sql, __METHOD__
);
783 # Add the results to the link cache
784 $lb->addResultToCache( LinkCache
::singleton(), $res );
786 # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
787 $categories = array_combine(
788 array_keys( $categories ),
789 array_fill( 0, count( $categories ), 'normal' )
792 # Mark hidden categories
793 foreach ( $res as $row ) {
794 if ( isset( $row->pp_value
) ) {
795 $categories[$row->page_title
] = 'hidden';
799 # Add the remaining categories to the skin
800 if ( wfRunHooks( 'OutputPageMakeCategoryLinks', array( &$this, $categories, &$this->mCategoryLinks
) ) ) {
801 $sk = $wgUser->getSkin();
802 foreach ( $categories as $category => $type ) {
803 $origcategory = $category;
804 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
805 $wgContLang->findVariantLink( $category, $title, true );
806 if ( $category != $origcategory ) {
807 if ( array_key_exists( $category, $categories ) ) {
811 $text = $wgContLang->convertHtml( $title->getText() );
812 $this->mCategories
[] = $title->getText();
813 $this->mCategoryLinks
[$type][] = $sk->link( $title, $text );
819 * Reset the category links (but not the category list) and add $categories
821 * @param $categories Associative array mapping category name to its sort key
823 public function setCategoryLinks( $categories ) {
824 $this->mCategoryLinks
= array();
825 $this->addCategoryLinks( $categories );
829 * Get the list of category links, in a 2-D array with the following format:
830 * $arr[$type][] = $link, where $type is either "normal" or "hidden" (for
831 * hidden categories) and $link a HTML fragment with a link to the category
836 public function getCategoryLinks() {
837 return $this->mCategoryLinks
;
841 * Get the list of category names this page belongs to
843 * @return Array of strings
845 public function getCategories() {
846 return $this->mCategories
;
850 * Suppress the quickbar from the output, only for skin supporting
853 public function suppressQuickbar() {
854 $this->mSuppressQuickbar
= true;
858 * Return whether the quickbar should be suppressed from the output
862 public function isQuickbarSuppressed() {
863 return $this->mSuppressQuickbar
;
867 * Remove user JavaScript from scripts to load
869 public function disallowUserJs() {
870 $this->mAllowUserJs
= false;
874 * Return whether user JavaScript is allowed for this page
878 public function isUserJsAllowed() {
879 return $this->mAllowUserJs
;
883 * Prepend $text to the body HTML
885 * @param $text String: HTML
887 public function prependHTML( $text ) {
888 $this->mBodytext
= $text . $this->mBodytext
;
892 * Append $text to the body HTML
894 * @param $text String: HTML
896 public function addHTML( $text ) {
897 $this->mBodytext
.= $text;
901 * Clear the body HTML
903 public function clearHTML() {
904 $this->mBodytext
= '';
910 * @return String: HTML
912 public function getHTML() {
913 return $this->mBodytext
;
917 * Add $text to the debug output
919 * @param $text String: debug text
921 public function debug( $text ) {
922 $this->mDebugtext
.= $text;
926 * @deprecated use parserOptions() instead
928 public function setParserOptions( $options ) {
929 wfDeprecated( __METHOD__
);
930 return $this->parserOptions( $options );
934 * Get/set the ParserOptions object to use for wikitext parsing
936 * @param $options either the ParserOption to use or null to only get the
937 * current ParserOption object
938 * @return current ParserOption object
940 public function parserOptions( $options = null ) {
941 if ( !$this->mParserOptions
) {
942 $this->mParserOptions
= new ParserOptions
;
944 return wfSetVar( $this->mParserOptions
, $options );
948 * Set the revision ID which will be seen by the wiki text parser
949 * for things such as embedded {{REVISIONID}} variable use.
951 * @param $revid Mixed: an positive integer, or null
952 * @return Mixed: previous value
954 public function setRevisionId( $revid ) {
955 $val = is_null( $revid ) ?
null : intval( $revid );
956 return wfSetVar( $this->mRevisionId
, $val );
960 * Get the current revision ID
964 public function getRevisionId() {
965 return $this->mRevisionId
;
969 * Convert wikitext to HTML and add it to the buffer
970 * Default assumes that the current page title will be used.
972 * @param $text String
973 * @param $linestart Boolean: is this the start of a line?
975 public function addWikiText( $text, $linestart = true ) {
976 $title = $this->getTitle(); // Work arround E_STRICT
977 $this->addWikiTextTitle( $text, $title, $linestart );
981 * Add wikitext with a custom Title object
983 * @param $text String: wikitext
984 * @param $title Title object
985 * @param $linestart Boolean: is this the start of a line?
987 public function addWikiTextWithTitle( $text, &$title, $linestart = true ) {
988 $this->addWikiTextTitle( $text, $title, $linestart );
992 * Add wikitext with a custom Title object and
994 * @param $text String: wikitext
995 * @param $title Title object
996 * @param $linestart Boolean: is this the start of a line?
998 function addWikiTextTitleTidy( $text, &$title, $linestart = true ) {
999 $this->addWikiTextTitle( $text, $title, $linestart, true );
1003 * Add wikitext with tidy enabled
1005 * @param $text String: wikitext
1006 * @param $linestart Boolean: is this the start of a line?
1008 public function addWikiTextTidy( $text, $linestart = true ) {
1009 $title = $this->getTitle();
1010 $this->addWikiTextTitleTidy( $text, $title, $linestart );
1014 * Add wikitext with a custom Title object
1016 * @param $text String: wikitext
1017 * @param $title Title object
1018 * @param $linestart Boolean: is this the start of a line?
1019 * @param $tidy Boolean: whether to use tidy
1021 public function addWikiTextTitle( $text, &$title, $linestart, $tidy = false ) {
1024 wfProfileIn( __METHOD__
);
1026 wfIncrStats( 'pcache_not_possible' );
1028 $popts = $this->parserOptions();
1029 $oldTidy = $popts->setTidy( $tidy );
1031 $parserOutput = $wgParser->parse(
1032 $text, $title, $popts,
1033 $linestart, true, $this->mRevisionId
1036 $popts->setTidy( $oldTidy );
1038 $this->addParserOutput( $parserOutput );
1040 wfProfileOut( __METHOD__
);
1044 * Add wikitext to the buffer, assuming that this is the primary text for a page view
1045 * Saves the text into the parser cache if possible.
1047 * @param $text String: wikitext
1048 * @param $article Article object
1049 * @param $cache Boolean
1050 * @deprecated Use Article::outputWikitext
1052 public function addPrimaryWikiText( $text, $article, $cache = true ) {
1055 wfDeprecated( __METHOD__
);
1057 $popts = $this->parserOptions();
1058 $popts->setTidy( true );
1059 $parserOutput = $wgParser->parse(
1060 $text, $article->mTitle
,
1061 $popts, true, true, $this->mRevisionId
1063 $popts->setTidy( false );
1064 if ( $cache && $article && !$parserOutput->isCacheable() ) {
1065 $parserCache = ParserCache
::singleton();
1066 $parserCache->save( $parserOutput, $article, $popts );
1069 $this->addParserOutput( $parserOutput );
1073 * @deprecated use addWikiTextTidy()
1075 public function addSecondaryWikiText( $text, $linestart = true ) {
1076 wfDeprecated( __METHOD__
);
1077 $this->addWikiTextTitleTidy( $text, $this->getTitle(), $linestart );
1081 * Add a ParserOutput object, but without Html
1083 * @param $parserOutput ParserOutput object
1085 public function addParserOutputNoText( &$parserOutput ) {
1086 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
1087 $this->addCategoryLinks( $parserOutput->getCategories() );
1088 $this->mNewSectionLink
= $parserOutput->getNewSection();
1089 $this->mHideNewSectionLink
= $parserOutput->getHideNewSection();
1091 $this->mParseWarnings
= $parserOutput->getWarnings();
1092 if ( !$parserOutput->isCacheable() ) {
1093 $this->enableClientCache( false );
1095 $this->mNoGallery
= $parserOutput->getNoGallery();
1096 $this->mHeadItems
= array_merge( $this->mHeadItems
, $parserOutput->getHeadItems() );
1098 foreach ( (array)$parserOutput->mTemplateIds
as $ns => $dbks ) {
1099 if ( isset( $this->mTemplateIds
[$ns] ) ) {
1100 $this->mTemplateIds
[$ns] = $dbks +
$this->mTemplateIds
[$ns];
1102 $this->mTemplateIds
[$ns] = $dbks;
1106 // Hooks registered in the object
1107 global $wgParserOutputHooks;
1108 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
1109 list( $hookName, $data ) = $hookInfo;
1110 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
1111 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
1115 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
1119 * Add a ParserOutput object
1121 * @param $parserOutput ParserOutput
1123 function addParserOutput( &$parserOutput ) {
1124 $this->addParserOutputNoText( $parserOutput );
1125 $text = $parserOutput->getText();
1126 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
1127 $this->addHTML( $text );
1132 * Add the output of a QuickTemplate to the output buffer
1134 * @param $template QuickTemplate
1136 public function addTemplate( &$template ) {
1138 $template->execute();
1139 $this->addHTML( ob_get_contents() );
1144 * Parse wikitext and return the HTML.
1146 * @param $text String
1147 * @param $linestart Boolean: is this the start of a line?
1148 * @param $interface Boolean: use interface language ($wgLang instead of
1149 * $wgContLang) while parsing language sensitive magic
1150 * words like GRAMMAR and PLURAL
1151 * @return String: HTML
1153 public function parse( $text, $linestart = true, $interface = false ) {
1155 if( is_null( $this->getTitle() ) ) {
1156 throw new MWException( 'Empty $mTitle in ' . __METHOD__
);
1158 $popts = $this->parserOptions();
1160 $popts->setInterfaceMessage( true );
1162 $parserOutput = $wgParser->parse(
1163 $text, $this->getTitle(), $popts,
1164 $linestart, true, $this->mRevisionId
1167 $popts->setInterfaceMessage( false );
1169 return $parserOutput->getText();
1173 * Parse wikitext, strip paragraphs, and return the HTML.
1175 * @param $text String
1176 * @param $linestart Boolean: is this the start of a line?
1177 * @param $interface Boolean: use interface language ($wgLang instead of
1178 * $wgContLang) while parsing language sensitive magic
1179 * words like GRAMMAR and PLURAL
1180 * @return String: HTML
1182 public function parseInline( $text, $linestart = true, $interface = false ) {
1183 $parsed = $this->parse( $text, $linestart, $interface );
1186 if ( preg_match( '/^<p>(.*)\n?<\/p>\n?/sU', $parsed, $m ) ) {
1196 * @param $article Article
1197 * @return Boolean: true if successful, else false.
1199 public function tryParserCache( &$article ) {
1200 wfDeprecated( __METHOD__
);
1201 $parserOutput = ParserCache
::singleton()->get( $article, $article->getParserOptions() );
1203 if ( $parserOutput !== false ) {
1204 $this->addParserOutput( $parserOutput );
1212 * Set the value of the "s-maxage" part of the "Cache-control" HTTP header
1214 * @param $maxage Integer: maximum cache time on the Squid, in seconds.
1216 public function setSquidMaxage( $maxage ) {
1217 $this->mSquidMaxage
= $maxage;
1221 * Use enableClientCache(false) to force it to send nocache headers
1225 public function enableClientCache( $state ) {
1226 return wfSetVar( $this->mEnableClientCache
, $state );
1230 * Get the list of cookies that will influence on the cache
1234 function getCacheVaryCookies() {
1235 global $wgCookiePrefix, $wgCacheVaryCookies;
1237 if ( $cookies === null ) {
1238 $cookies = array_merge(
1240 "{$wgCookiePrefix}Token",
1241 "{$wgCookiePrefix}LoggedOut",
1246 wfRunHooks( 'GetCacheVaryCookies', array( $this, &$cookies ) );
1252 * Return whether this page is not cacheable because "useskin" or "uselang"
1253 * URL parameters were passed.
1257 function uncacheableBecauseRequestVars() {
1259 return $wgRequest->getText( 'useskin', false ) === false
1260 && $wgRequest->getText( 'uselang', false ) === false;
1264 * Check if the request has a cache-varying cookie header
1265 * If it does, it's very important that we don't allow public caching
1269 function haveCacheVaryCookies() {
1271 $cookieHeader = $wgRequest->getHeader( 'cookie' );
1272 if ( $cookieHeader === false ) {
1275 $cvCookies = $this->getCacheVaryCookies();
1276 foreach ( $cvCookies as $cookieName ) {
1277 # Check for a simple string match, like the way squid does it
1278 if ( strpos( $cookieHeader, $cookieName ) ) {
1279 wfDebug( __METHOD__
. ": found $cookieName\n" );
1283 wfDebug( __METHOD__
. ": no cache-varying cookies found\n" );
1288 * Add an HTTP header that will influence on the cache
1290 * @param $header String: header name
1291 * @param $option either an Array or null
1293 public function addVaryHeader( $header, $option = null ) {
1294 if ( !array_key_exists( $header, $this->mVaryHeader
) ) {
1295 $this->mVaryHeader
[$header] = $option;
1296 } elseif( is_array( $option ) ) {
1297 if( is_array( $this->mVaryHeader
[$header] ) ) {
1298 $this->mVaryHeader
[$header] = array_merge( $this->mVaryHeader
[$header], $option );
1300 $this->mVaryHeader
[$header] = $option;
1303 $this->mVaryHeader
[$header] = array_unique( $this->mVaryHeader
[$header] );
1307 * Get a complete X-Vary-Options header
1311 public function getXVO() {
1312 $cvCookies = $this->getCacheVaryCookies();
1314 $cookiesOption = array();
1315 foreach ( $cvCookies as $cookieName ) {
1316 $cookiesOption[] = 'string-contains=' . $cookieName;
1318 $this->addVaryHeader( 'Cookie', $cookiesOption );
1321 foreach( $this->mVaryHeader
as $header => $option ) {
1322 $newheader = $header;
1323 if( is_array( $option ) ) {
1324 $newheader .= ';' . implode( ';', $option );
1326 $headers[] = $newheader;
1328 $xvo = 'X-Vary-Options: ' . implode( ',', $headers );
1334 * bug 21672: Add Accept-Language to Vary and XVO headers
1335 * if there's no 'variant' parameter existed in GET.
1338 * /w/index.php?title=Main_page should always be served; but
1339 * /w/index.php?title=Main_page&variant=zh-cn should never be served.
1341 function addAcceptLanguage() {
1342 global $wgRequest, $wgContLang;
1343 if( !$wgRequest->getCheck( 'variant' ) && $wgContLang->hasVariants() ) {
1344 $variants = $wgContLang->getVariants();
1345 $aloption = array();
1346 foreach ( $variants as $variant ) {
1347 if( $variant === $wgContLang->getCode() ) {
1350 $aloption[] = "string-contains=$variant";
1353 $this->addVaryHeader( 'Accept-Language', $aloption );
1358 * Send cache control HTTP headers
1360 public function sendCacheControl() {
1361 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
1363 $response = $wgRequest->response();
1364 if ( $wgUseETag && $this->mETag
) {
1365 $response->header( "ETag: $this->mETag" );
1368 $this->addAcceptLanguage();
1370 # don't serve compressed data to clients who can't handle it
1371 # maintain different caches for logged-in users and non-logged in ones
1372 $response->header( 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader
) ) );
1375 # Add an X-Vary-Options header for Squid with Wikimedia patches
1376 $response->header( $this->getXVO() );
1379 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache
) {
1381 $wgUseSquid && session_id() == '' && !$this->isPrintable() &&
1382 $this->mSquidMaxage
!= 0 && !$this->haveCacheVaryCookies()
1386 # We'll purge the proxy cache explicitly, but require end user agents
1387 # to revalidate against the proxy on each visit.
1388 # Surrogate-Control controls our Squid, Cache-Control downstream caches
1389 wfDebug( __METHOD__
. ": proxy caching with ESI; {$this->mLastModified} **\n", false );
1390 # start with a shorter timeout for initial testing
1391 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
1392 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
1393 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
1395 # We'll purge the proxy cache for anons explicitly, but require end user agents
1396 # to revalidate against the proxy on each visit.
1397 # IMPORTANT! The Squid needs to replace the Cache-Control header with
1398 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
1399 wfDebug( __METHOD__
. ": local proxy caching; {$this->mLastModified} **\n", false );
1400 # start with a shorter timeout for initial testing
1401 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
1402 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
1405 # We do want clients to cache if they can, but they *must* check for updates
1406 # on revisiting the page.
1407 wfDebug( __METHOD__
. ": private caching; {$this->mLastModified} **\n", false );
1408 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1409 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
1411 if($this->mLastModified
) {
1412 $response->header( "Last-Modified: {$this->mLastModified}" );
1415 wfDebug( __METHOD__
. ": no caching **\n", false );
1417 # In general, the absence of a last modified header should be enough to prevent
1418 # the client from using its cache. We send a few other things just to make sure.
1419 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1420 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
1421 $response->header( 'Pragma: no-cache' );
1426 * Get the message associed with the HTTP response code $code
1428 * @param $code Integer: status code
1429 * @return String or null: message or null if $code is not in the list of
1432 public static function getStatusMessage( $code ) {
1433 static $statusMessage = array(
1435 101 => 'Switching Protocols',
1436 102 => 'Processing',
1440 203 => 'Non-Authoritative Information',
1441 204 => 'No Content',
1442 205 => 'Reset Content',
1443 206 => 'Partial Content',
1444 207 => 'Multi-Status',
1445 300 => 'Multiple Choices',
1446 301 => 'Moved Permanently',
1449 304 => 'Not Modified',
1451 307 => 'Temporary Redirect',
1452 400 => 'Bad Request',
1453 401 => 'Unauthorized',
1454 402 => 'Payment Required',
1457 405 => 'Method Not Allowed',
1458 406 => 'Not Acceptable',
1459 407 => 'Proxy Authentication Required',
1460 408 => 'Request Timeout',
1463 411 => 'Length Required',
1464 412 => 'Precondition Failed',
1465 413 => 'Request Entity Too Large',
1466 414 => 'Request-URI Too Large',
1467 415 => 'Unsupported Media Type',
1468 416 => 'Request Range Not Satisfiable',
1469 417 => 'Expectation Failed',
1470 422 => 'Unprocessable Entity',
1472 424 => 'Failed Dependency',
1473 500 => 'Internal Server Error',
1474 501 => 'Not Implemented',
1475 502 => 'Bad Gateway',
1476 503 => 'Service Unavailable',
1477 504 => 'Gateway Timeout',
1478 505 => 'HTTP Version Not Supported',
1479 507 => 'Insufficient Storage'
1481 return isset( $statusMessage[$code] ) ?
$statusMessage[$code] : null;
1485 * Finally, all the text has been munged and accumulated into
1486 * the object, let's actually output it:
1488 public function output() {
1489 global $wgUser, $wgOutputEncoding, $wgRequest;
1490 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
1491 global $wgUseAjax, $wgAjaxWatch;
1492 global $wgEnableMWSuggest, $wgUniversalEditButton;
1493 global $wgArticle, $wgJQueryOnEveryPage;
1495 if( $this->mDoNothing
) {
1498 wfProfileIn( __METHOD__
);
1499 if ( $this->mRedirect
!= '' ) {
1500 # Standards require redirect URLs to be absolute
1501 $this->mRedirect
= wfExpandUrl( $this->mRedirect
);
1502 if( $this->mRedirectCode
== '301' ||
$this->mRedirectCode
== '303' ) {
1503 if( !$wgDebugRedirects ) {
1504 $message = self
::getStatusMessage( $this->mRedirectCode
);
1505 $wgRequest->response()->header( "HTTP/1.1 {$this->mRedirectCode} $message" );
1507 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
1509 $this->sendCacheControl();
1511 $wgRequest->response()->header( "Content-Type: text/html; charset=utf-8" );
1512 if( $wgDebugRedirects ) {
1513 $url = htmlspecialchars( $this->mRedirect
);
1514 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
1515 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
1516 print "</body>\n</html>\n";
1518 $wgRequest->response()->header( 'Location: ' . $this->mRedirect
);
1520 wfProfileOut( __METHOD__
);
1522 } elseif ( $this->mStatusCode
) {
1523 $message = self
::getStatusMessage( $this->mStatusCode
);
1525 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $message );
1529 $sk = $wgUser->getSkin();
1532 $this->addScriptFile( 'ajax.js' );
1534 wfRunHooks( 'AjaxAddScript', array( &$this ) );
1536 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
1537 $this->includeJQuery();
1538 $this->addScriptFile( 'ajaxwatch.js' );
1541 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
1542 $this->addScriptFile( 'mwsuggest.js' );
1546 if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
1547 $this->addScriptFile( 'rightclickedit.js' );
1550 if( $wgUniversalEditButton ) {
1551 if( isset( $wgArticle ) && $this->getTitle() && $this->getTitle()->quickUserCan( 'edit' )
1552 && ( $this->getTitle()->exists() ||
$this->getTitle()->quickUserCan( 'create' ) ) ) {
1553 // Original UniversalEditButton
1554 $msg = wfMsg( 'edit' );
1555 $this->addLink( array(
1556 'rel' => 'alternate',
1557 'type' => 'application/x-wiki',
1559 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1561 // Alternate edit link
1562 $this->addLink( array(
1565 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1570 if ( $wgJQueryOnEveryPage ) {
1571 $this->includeJQuery();
1574 # Buffer output; final headers may depend on later processing
1577 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
1578 $wgRequest->response()->header( 'Content-language: ' . $wgContLanguageCode );
1580 if ( $this->mArticleBodyOnly
) {
1581 $this->out( $this->mBodytext
);
1583 // Hook that allows last minute changes to the output page, e.g.
1584 // adding of CSS or Javascript by extensions.
1585 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
1587 wfProfileIn( 'Output-skin' );
1588 $sk->outputPage( $this );
1589 wfProfileOut( 'Output-skin' );
1592 $this->sendCacheControl();
1594 wfProfileOut( __METHOD__
);
1598 * Actually output something with print(). Performs an iconv to the
1599 * output encoding, if needed.
1601 * @param $ins String: the string to output
1603 public function out( $ins ) {
1604 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
1605 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
1608 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
1609 if ( false === $outs ) {
1619 public static function setEncodings() {
1620 global $wgInputEncoding, $wgOutputEncoding;
1622 $wgInputEncoding = strtolower( $wgInputEncoding );
1624 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
1625 $wgOutputEncoding = strtolower( $wgOutputEncoding );
1628 $wgOutputEncoding = $wgInputEncoding;
1632 * @deprecated use wfReportTime() instead.
1636 public function reportTime() {
1637 wfDeprecated( __METHOD__
);
1638 $time = wfReportTime();
1643 * Produce a "user is blocked" page.
1645 * @param $return Boolean: whether to have a "return to $wgTitle" message or not.
1648 function blockedPage( $return = true ) {
1649 global $wgUser, $wgContLang, $wgLang;
1651 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
1652 $this->setRobotPolicy( 'noindex,nofollow' );
1653 $this->setArticleRelated( false );
1655 $name = User
::whoIs( $wgUser->blockedBy() );
1656 $reason = $wgUser->blockedFor();
1657 if( $reason == '' ) {
1658 $reason = wfMsg( 'blockednoreason' );
1660 $blockTimestamp = $wgLang->timeanddate(
1661 wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true
1665 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
1667 $blockid = $wgUser->mBlock
->mId
;
1669 $blockExpiry = $wgUser->mBlock
->mExpiry
;
1670 if ( $blockExpiry == 'infinity' ) {
1671 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
1672 // Search for localization in 'ipboptions'
1673 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1674 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
1675 if ( strpos( $option, ':' ) === false ) {
1678 list( $show, $value ) = explode( ':', $option );
1679 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
1680 $blockExpiry = $show;
1685 $blockExpiry = $wgLang->timeanddate(
1686 wfTimestamp( TS_MW
, $blockExpiry ),
1691 if ( $wgUser->mBlock
->mAuto
) {
1692 $msg = 'autoblockedtext';
1694 $msg = 'blockedtext';
1697 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
1698 * This could be a username, an IP range, or a single IP. */
1699 $intended = $wgUser->mBlock
->mAddress
;
1702 $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry,
1703 $intended, $blockTimestamp
1706 # Don't auto-return to special pages
1708 $return = $this->getTitle()->getNamespace() > -1 ?
$this->getTitle() : null;
1709 $this->returnToMain( null, $return );
1714 * Output a standard error page
1716 * @param $title String: message key for page title
1717 * @param $msg String: message key for page text
1718 * @param $params Array: message parameters
1720 public function showErrorPage( $title, $msg, $params = array() ) {
1721 if ( $this->getTitle() ) {
1722 $this->mDebugtext
.= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n";
1724 $this->setPageTitle( wfMsg( $title ) );
1725 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1726 $this->setRobotPolicy( 'noindex,nofollow' );
1727 $this->setArticleRelated( false );
1728 $this->enableClientCache( false );
1729 $this->mRedirect
= '';
1730 $this->mBodytext
= '';
1732 array_unshift( $params, 'parse' );
1733 array_unshift( $params, $msg );
1734 $this->addHTML( call_user_func_array( 'wfMsgExt', $params ) );
1736 $this->returnToMain();
1740 * Output a standard permission error page
1742 * @param $errors Array: error message keys
1743 * @param $action String: action that was denied or null if unknown
1745 public function showPermissionsErrorPage( $errors, $action = null ) {
1746 $this->mDebugtext
.= 'Original title: ' .
1747 $this->getTitle()->getPrefixedText() . "\n";
1748 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
1749 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
1750 $this->setRobotPolicy( 'noindex,nofollow' );
1751 $this->setArticleRelated( false );
1752 $this->enableClientCache( false );
1753 $this->mRedirect
= '';
1754 $this->mBodytext
= '';
1755 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
1759 * Display an error page indicating that a given version of MediaWiki is
1760 * required to use it
1762 * @param $version Mixed: the version of MediaWiki needed to use the page
1764 public function versionRequired( $version ) {
1765 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
1766 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
1767 $this->setRobotPolicy( 'noindex,nofollow' );
1768 $this->setArticleRelated( false );
1769 $this->mBodytext
= '';
1771 $this->addWikiMsg( 'versionrequiredtext', $version );
1772 $this->returnToMain();
1776 * Display an error page noting that a given permission bit is required.
1778 * @param $permission String: key required
1780 public function permissionRequired( $permission ) {
1783 $this->setPageTitle( wfMsg( 'badaccess' ) );
1784 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1785 $this->setRobotPolicy( 'noindex,nofollow' );
1786 $this->setArticleRelated( false );
1787 $this->mBodytext
= '';
1789 $groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
1790 User
::getGroupsWithPermission( $permission ) );
1794 $wgLang->commaList( $groups ),
1798 $this->addWikiMsg( 'badaccess-group0' );
1800 $this->returnToMain();
1804 * Produce the stock "please login to use the wiki" page
1806 public function loginToUse() {
1809 if( $wgUser->isLoggedIn() ) {
1810 $this->permissionRequired( 'read' );
1814 $skin = $wgUser->getSkin();
1816 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1817 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1818 $this->setRobotPolicy( 'noindex,nofollow' );
1819 $this->setArticleFlag( false );
1821 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1822 $loginLink = $skin->link(
1824 wfMsgHtml( 'loginreqlink' ),
1826 array( 'returnto' => $this->getTitle()->getPrefixedText() ),
1827 array( 'known', 'noclasses' )
1829 $this->addHTML( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1830 $this->addHTML( "\n<!--" . $this->getTitle()->getPrefixedUrl() . '-->' );
1832 # Don't return to the main page if the user can't read it
1833 # otherwise we'll end up in a pointless loop
1834 $mainPage = Title
::newMainPage();
1835 if( $mainPage->userCanRead() ) {
1836 $this->returnToMain( null, $mainPage );
1841 * Format a list of error messages
1843 * @param $errors An array of arrays returned by Title::getUserPermissionsErrors
1844 * @param $action String: action that was denied or null if unknown
1845 * @return String: the wikitext error-messages, formatted into a list.
1847 public function formatPermissionsErrorMessage( $errors, $action = null ) {
1848 if ( $action == null ) {
1849 $text = wfMsgNoTrans( 'permissionserrorstext', count( $errors ) ) . "\n\n";
1852 $action_desc = wfMsgNoTrans( "action-$action" );
1853 $text = wfMsgNoTrans(
1854 'permissionserrorstext-withaction',
1860 if ( count( $errors ) > 1 ) {
1861 $text .= '<ul class="permissions-errors">' . "\n";
1863 foreach( $errors as $error ) {
1865 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1870 $text .= "<div class=\"permissions-errors\">\n" .
1871 call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) .
1879 * Display a page stating that the Wiki is in read-only mode,
1880 * and optionally show the source of the page that the user
1881 * was trying to edit. Should only be called (for this
1882 * purpose) after wfReadOnly() has returned true.
1884 * For historical reasons, this function is _also_ used to
1885 * show the error message when a user tries to edit a page
1886 * they are not allowed to edit. (Unless it's because they're
1887 * blocked, then we show blockedPage() instead.) In this
1888 * case, the second parameter should be set to true and a list
1889 * of reasons supplied as the third parameter.
1891 * @todo Needs to be split into multiple functions.
1893 * @param $source String: source code to show (or null).
1894 * @param $protected Boolean: is this a permissions error?
1895 * @param $reasons Array: list of reasons for this error, as returned by Title::getUserPermissionsErrors().
1896 * @param $action String: action that was denied or null if unknown
1898 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
1900 $skin = $wgUser->getSkin();
1902 $this->setRobotPolicy( 'noindex,nofollow' );
1903 $this->setArticleRelated( false );
1905 // If no reason is given, just supply a default "I can't let you do
1906 // that, Dave" message. Should only occur if called by legacy code.
1907 if ( $protected && empty( $reasons ) ) {
1908 $reasons[] = array( 'badaccess-group0' );
1911 if ( !empty( $reasons ) ) {
1912 // Permissions error
1914 $this->setPageTitle( wfMsg( 'viewsource' ) );
1916 wfMsg( 'viewsourcefor', $skin->linkKnown( $this->getTitle() ) )
1919 $this->setPageTitle( wfMsg( 'badaccess' ) );
1921 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) );
1923 // Wiki is read only
1924 $this->setPageTitle( wfMsg( 'readonly' ) );
1925 $reason = wfReadOnlyReason();
1926 $this->wrapWikiMsg( "<div class='mw-readonly-error'>\n$1\n</div>", array( 'readonlytext', $reason ) );
1929 // Show source, if supplied
1930 if( is_string( $source ) ) {
1931 $this->addWikiMsg( 'viewsourcetext' );
1934 'id' => 'wpTextbox1',
1935 'name' => 'wpTextbox1',
1936 'cols' => $wgUser->getOption( 'cols' ),
1937 'rows' => $wgUser->getOption( 'rows' ),
1938 'readonly' => 'readonly'
1940 $this->addHTML( Html
::element( 'textarea', $params, $source ) );
1942 // Show templates used by this article
1943 $skin = $wgUser->getSkin();
1944 $article = new Article( $this->getTitle() );
1945 $this->addHTML( "<div class='templatesUsed'>
1946 {$skin->formatTemplates( $article->getUsedTemplates() )}
1951 # If the title doesn't exist, it's fairly pointless to print a return
1952 # link to it. After all, you just tried editing it and couldn't, so
1953 # what's there to do there?
1954 if( $this->getTitle()->exists() ) {
1955 $this->returnToMain( null, $this->getTitle() );
1960 public function errorpage( $title, $msg ) {
1961 wfDeprecated( __METHOD__
);
1962 throw new ErrorPageError( $title, $msg );
1966 public function databaseError( $fname, $sql, $error, $errno ) {
1967 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1971 public function fatalError( $message ) {
1972 wfDeprecated( __METHOD__
);
1973 throw new FatalError( $message );
1977 public function unexpectedValueError( $name, $val ) {
1978 wfDeprecated( __METHOD__
);
1979 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1983 public function fileCopyError( $old, $new ) {
1984 wfDeprecated( __METHOD__
);
1985 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1989 public function fileRenameError( $old, $new ) {
1990 wfDeprecated( __METHOD__
);
1991 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1995 public function fileDeleteError( $name ) {
1996 wfDeprecated( __METHOD__
);
1997 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
2001 public function fileNotFoundError( $name ) {
2002 wfDeprecated( __METHOD__
);
2003 throw new FatalError( wfMsg( 'filenotfound', $name ) );
2006 public function showFatalError( $message ) {
2007 $this->setPageTitle( wfMsg( 'internalerror' ) );
2008 $this->setRobotPolicy( 'noindex,nofollow' );
2009 $this->setArticleRelated( false );
2010 $this->enableClientCache( false );
2011 $this->mRedirect
= '';
2012 $this->mBodytext
= $message;
2015 public function showUnexpectedValueError( $name, $val ) {
2016 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
2019 public function showFileCopyError( $old, $new ) {
2020 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
2023 public function showFileRenameError( $old, $new ) {
2024 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
2027 public function showFileDeleteError( $name ) {
2028 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
2031 public function showFileNotFoundError( $name ) {
2032 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
2036 * Add a "return to" link pointing to a specified title
2038 * @param $title Title to link
2039 * @param $query String: query string
2040 * @param $text String text of the link (input is not escaped)
2042 public function addReturnTo( $title, $query = array(), $text = null ) {
2044 $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullURL() ) );
2047 $wgUser->getSkin()->link( $title, $text, array(), $query )
2049 $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
2053 * Add a "return to" link pointing to a specified title,
2054 * or the title indicated in the request, or else the main page
2056 * @param $unused No longer used
2057 * @param $returnto Title or String to return to
2058 * @param $returntoquery String: query string for the return to link
2060 public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
2063 if ( $returnto == null ) {
2064 $returnto = $wgRequest->getText( 'returnto' );
2067 if ( $returntoquery == null ) {
2068 $returntoquery = $wgRequest->getText( 'returntoquery' );
2071 if ( $returnto === '' ) {
2072 $returnto = Title
::newMainPage();
2075 if ( is_object( $returnto ) ) {
2076 $titleObj = $returnto;
2078 $titleObj = Title
::newFromText( $returnto );
2080 if ( !is_object( $titleObj ) ) {
2081 $titleObj = Title
::newMainPage();
2084 $this->addReturnTo( $titleObj, $returntoquery );
2088 * @param $sk Skin The given Skin
2089 * @param $includeStyle Boolean: unused
2090 * @return String: The doctype, opening <html>, and head element.
2092 public function headElement( Skin
$sk, $includeStyle = true ) {
2093 global $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
2094 global $wgContLang, $wgUseTrackbacks, $wgStyleVersion, $wgHtml5;
2095 global $wgUser, $wgRequest, $wgLang;
2097 if ( $sk->commonPrintStylesheet() ) {
2098 $this->addStyle( 'common/wikiprintable.css', 'print' );
2100 $sk->setupUserCss( $this );
2102 $ret = Html
::htmlHeader( array( 'lang' => wfUILang()->getCode() ) );
2104 if ( $this->getHTMLTitle() == '' ) {
2105 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ) );
2108 $openHead = Html
::openElement( 'head' );
2110 # Don't bother with the newline if $head == ''
2111 $ret .= "$openHead\n";
2115 # More succinct than <meta http-equiv=Content-Type>, has the
2117 $ret .= Html
::element( 'meta', array( 'charset' => $wgOutputEncoding ) ) . "\n";
2119 $this->addMeta( 'http:Content-Type', "$wgMimeType; charset=$wgOutputEncoding" );
2122 $ret .= Html
::element( 'title', null, $this->getHTMLTitle() ) . "\n";
2124 $ret .= implode( "\n", array(
2125 $this->getHeadLinks(),
2126 $this->buildCssLinks(),
2127 $this->getHeadScripts( $sk ) . $this->getHeadItems(),
2129 if ( $sk->usercss
) {
2130 $ret .= Html
::inlineStyle( $sk->usercss
);
2133 if ( $wgUseTrackbacks && $this->isArticleRelated() ) {
2134 $ret .= $this->getTitle()->trackbackRDF();
2137 $closeHead = Html
::closeElement( 'head' );
2139 $ret .= "$closeHead\n";
2142 $bodyAttrs = array();
2144 # Crazy edit-on-double-click stuff
2145 $action = $wgRequest->getVal( 'action', 'view' );
2148 $this->getTitle()->getNamespace() != NS_SPECIAL
&&
2149 !in_array( $action, array( 'edit', 'submit' ) ) &&
2150 $wgUser->getOption( 'editondblclick' )
2153 $bodyAttrs['ondblclick'] = "document.location = '" . Xml
::escapeJsString( $this->getTitle()->getEditURL() ) . "'";
2157 $dir = wfUILang()->getDir();
2158 $bodyAttrs['class'] = "mediawiki $dir";
2160 if ( $wgLang->capitalizeAllNouns() ) {
2161 # A <body> class is probably not the best way to do this . . .
2162 $bodyAttrs['class'] .= ' capitalize-all-nouns';
2164 $bodyAttrs['class'] .= ' ns-' . $this->getTitle()->getNamespace();
2165 if ( $this->getTitle()->getNamespace() == NS_SPECIAL
) {
2166 $bodyAttrs['class'] .= ' ns-special';
2167 } elseif ( $this->getTitle()->isTalkPage() ) {
2168 $bodyAttrs['class'] .= ' ns-talk';
2170 $bodyAttrs['class'] .= ' ns-subject';
2172 $bodyAttrs['class'] .= ' ' . Sanitizer
::escapeClass( 'page-' . $this->getTitle()->getPrefixedText() );
2173 $bodyAttrs['class'] .= ' skin-' . Sanitizer
::escapeClass( $wgUser->getSkin()->getSkinName() );
2175 $ret .= Html
::openElement( 'body', $bodyAttrs ) . "\n";
2181 * Gets the global variables and mScripts; also adds userjs to the end if
2184 * @param $sk Skin object to use
2185 * @return String: HTML fragment
2187 function getHeadScripts( Skin
$sk ) {
2188 global $wgUser, $wgRequest, $wgJsMimeType, $wgUseSiteJs;
2189 global $wgStylePath, $wgStyleVersion;
2191 $scripts = Skin
::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
2192 $scripts .= Html
::linkedScript( "{$wgStylePath}/common/wikibits.js?$wgStyleVersion" );
2194 // add site JS if enabled
2195 if( $wgUseSiteJs ) {
2196 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
2197 $this->addScriptFile(
2200 "action=raw$jsCache&gen=js&useskin=" .
2201 urlencode( $sk->getSkinName() )
2206 // add user JS if enabled
2207 if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
2208 $action = $wgRequest->getVal( 'action', 'view' );
2209 if( $this->mTitle
&& $this->mTitle
->isJsSubpage() && $sk->userCanPreview( $action ) ) {
2210 # XXX: additional security check/prompt?
2211 $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
2213 $userpage = $wgUser->getUserPage();
2214 $names = array( 'common', $sk->getSkinName() );
2215 foreach( $names as $name ) {
2216 $scriptpage = Title
::makeTitleSafe(
2218 $userpage->getDBkey() . '/' . $name . '.js'
2220 if ( $scriptpage && $scriptpage->exists() && ( $scriptpage->getLength() > 0 ) ) {
2221 $userjs = $scriptpage->getLocalURL( 'action=raw&ctype=' . $wgJsMimeType );
2222 $this->addScriptFile( $userjs, $scriptpage->getLatestRevID() );
2228 $scripts .= "\n" . $this->mScripts
;
2233 * Add default \<meta\> tags
2235 protected function addDefaultMeta() {
2236 global $wgVersion, $wgHtml5;
2238 static $called = false;
2240 # Don't run this twice
2246 $this->addMeta( 'http:Content-Style-Type', 'text/css' ); // bug 15835
2248 $this->addMeta( 'generator', "MediaWiki $wgVersion" );
2250 $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
2251 if( $p !== 'index,follow' ) {
2252 // http://www.robotstxt.org/wc/meta-user.html
2253 // Only show if it's different from the default robots policy
2254 $this->addMeta( 'robots', $p );
2257 if ( count( $this->mKeywords
) > 0 ) {
2259 "/<.*?" . ">/" => '',
2265 array_keys( $strip ),
2266 array_values( $strip ),
2267 implode( ',', $this->mKeywords
)
2274 * @return string HTML tag links to be put in the header.
2276 public function getHeadLinks() {
2279 // Ideally this should happen earlier, somewhere. :P
2280 $this->addDefaultMeta();
2284 foreach ( $this->mMetatags
as $tag ) {
2285 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
2287 $tag[0] = substr( $tag[0], 5 );
2291 $tags[] = Html
::element( 'meta',
2294 'content' => $tag[1]
2298 foreach ( $this->mLinktags
as $tag ) {
2299 $tags[] = Html
::element( 'link', $tag );
2303 foreach( $this->getSyndicationLinks() as $format => $link ) {
2304 # Use the page name for the title (accessed through $wgTitle since
2305 # there's no other way). In principle, this could lead to issues
2306 # with having the same name for different feeds corresponding to
2307 # the same page, but we can't avoid that at this low a level.
2309 $tags[] = $this->feedLink(
2312 # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
2313 wfMsg( "page-{$format}-feed", $this->getTitle()->getPrefixedText() )
2317 # Recent changes feed should appear on every page (except recentchanges,
2318 # that would be redundant). Put it after the per-page feed to avoid
2319 # changing existing behavior. It's still available, probably via a
2320 # menu in your browser. Some sites might have a different feed they'd
2321 # like to promote instead of the RC feed (maybe like a "Recent New Articles"
2322 # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined.
2323 # If so, use it instead.
2325 global $wgOverrideSiteFeed, $wgSitename, $wgAdvertisedFeedTypes;
2326 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
2328 if ( $wgOverrideSiteFeed ) {
2329 foreach ( $wgOverrideSiteFeed as $type => $feedUrl ) {
2330 $tags[] = $this->feedLink(
2332 htmlspecialchars( $feedUrl ),
2333 wfMsg( "site-{$type}-feed", $wgSitename )
2336 } elseif ( $this->getTitle()->getPrefixedText() != $rctitle->getPrefixedText() ) {
2337 foreach ( $wgAdvertisedFeedTypes as $format ) {
2338 $tags[] = $this->feedLink(
2340 $rctitle->getLocalURL( "feed={$format}" ),
2341 wfMsg( "site-{$format}-feed", $wgSitename ) # For grep: 'site-rss-feed', 'site-atom-feed'.
2347 return implode( "\n", $tags );
2351 * Generate a <link rel/> for a feed.
2353 * @param $type String: feed type
2354 * @param $url String: URL to the feed
2355 * @param $text String: value of the "title" attribute
2356 * @return String: HTML fragment
2358 private function feedLink( $type, $url, $text ) {
2359 return Html
::element( 'link', array(
2360 'rel' => 'alternate',
2361 'type' => "application/$type+xml",
2368 * Add a local or specified stylesheet, with the given media options.
2369 * Meant primarily for internal use...
2371 * @param $style String: URL to the file
2372 * @param $media String: to specify a media type, 'screen', 'printable', 'handheld' or any.
2373 * @param $condition String: for IE conditional comments, specifying an IE version
2374 * @param $dir String: set to 'rtl' or 'ltr' for direction-specific sheets
2376 public function addStyle( $style, $media = '', $condition = '', $dir = '' ) {
2378 // Even though we expect the media type to be lowercase, but here we
2379 // force it to lowercase to be safe.
2381 $options['media'] = $media;
2384 $options['condition'] = $condition;
2387 $options['dir'] = $dir;
2389 $this->styles
[$style] = $options;
2393 * Adds inline CSS styles
2394 * @param $style_css Mixed: inline CSS
2396 public function addInlineStyle( $style_css ){
2397 $this->mScripts
.= Html
::inlineStyle( $style_css );
2401 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
2402 * These will be applied to various media & IE conditionals.
2404 public function buildCssLinks() {
2405 return implode( "\n", $this->buildCssLinksArray() );
2408 public function buildCssLinksArray() {
2410 foreach( $this->styles
as $file => $options ) {
2411 $link = $this->styleLink( $file, $options );
2413 $links[$file] = $link;
2420 * Generate \<link\> tags for stylesheets
2422 * @param $style String: URL to the file
2423 * @param $options Array: option, can contain 'condition', 'dir', 'media'
2425 * @return String: HTML fragment
2427 protected function styleLink( $style, $options ) {
2428 if( isset( $options['dir'] ) ) {
2429 $siteDir = wfUILang()->getDir();
2430 if( $siteDir != $options['dir'] ) {
2435 if( isset( $options['media'] ) ) {
2436 $media = $this->transformCssMedia( $options['media'] );
2437 if( is_null( $media ) ) {
2444 if( substr( $style, 0, 1 ) == '/' ||
2445 substr( $style, 0, 5 ) == 'http:' ||
2446 substr( $style, 0, 6 ) == 'https:' ) {
2449 global $wgStylePath, $wgStyleVersion;
2450 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
2453 $link = Html
::linkedStyle( $url, $media );
2455 if( isset( $options['condition'] ) ) {
2456 $condition = htmlspecialchars( $options['condition'] );
2457 $link = "<!--[if $condition]>$link<![endif]-->";
2463 * Transform "media" attribute based on request parameters
2465 * @param $media String: current value of the "media" attribute
2466 * @return String: modified value of the "media" attribute
2468 function transformCssMedia( $media ) {
2469 global $wgRequest, $wgHandheldForIPhone;
2471 // Switch in on-screen display for media testing
2473 'printable' => 'print',
2474 'handheld' => 'handheld',
2476 foreach( $switches as $switch => $targetMedia ) {
2477 if( $wgRequest->getBool( $switch ) ) {
2478 if( $media == $targetMedia ) {
2480 } elseif( $media == 'screen' ) {
2486 // Expand longer media queries as iPhone doesn't grok 'handheld'
2487 if( $wgHandheldForIPhone ) {
2488 $mediaAliases = array(
2489 'screen' => 'screen and (min-device-width: 481px)',
2490 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
2493 if( isset( $mediaAliases[$media] ) ) {
2494 $media = $mediaAliases[$media];
2502 * Turn off regular page output and return an error reponse
2503 * for when rate limiting has triggered.
2505 public function rateLimited() {
2506 $this->setPageTitle( wfMsg( 'actionthrottled' ) );
2507 $this->setRobotPolicy( 'noindex,follow' );
2508 $this->setArticleRelated( false );
2509 $this->enableClientCache( false );
2510 $this->mRedirect
= '';
2512 $this->setStatusCode( 503 );
2513 $this->addWikiMsg( 'actionthrottledtext' );
2515 $this->returnToMain( null, $this->getTitle() );
2519 * Show a warning about slave lag
2521 * If the lag is higher than $wgSlaveLagCritical seconds,
2522 * then the warning is a bit more obvious. If the lag is
2523 * lower than $wgSlaveLagWarning, then no warning is shown.
2525 * @param $lag Integer: slave lag
2527 public function showLagWarning( $lag ) {
2528 global $wgSlaveLagWarning, $wgSlaveLagCritical, $wgLang;
2529 if( $lag >= $wgSlaveLagWarning ) {
2530 $message = $lag < $wgSlaveLagCritical
2533 $wrap = Html
::rawElement( 'div', array( 'class' => "mw-{$message}" ), "\n$1\n" );
2534 $this->wrapWikiMsg( "$wrap\n", array( $message, $wgLang->formatNum( $lag ) ) );
2539 * Add a wikitext-formatted message to the output.
2540 * This is equivalent to:
2542 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
2544 public function addWikiMsg( /*...*/ ) {
2545 $args = func_get_args();
2546 $name = array_shift( $args );
2547 $this->addWikiMsgArray( $name, $args );
2551 * Add a wikitext-formatted message to the output.
2552 * Like addWikiMsg() except the parameters are taken as an array
2553 * instead of a variable argument list.
2555 * $options is passed through to wfMsgExt(), see that function for details.
2557 public function addWikiMsgArray( $name, $args, $options = array() ) {
2558 $options[] = 'parse';
2559 $text = wfMsgExt( $name, $options, $args );
2560 $this->addHTML( $text );
2564 * This function takes a number of message/argument specifications, wraps them in
2565 * some overall structure, and then parses the result and adds it to the output.
2567 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
2568 * on. The subsequent arguments may either be strings, in which case they are the
2569 * message names, or arrays, in which case the first element is the message name,
2570 * and subsequent elements are the parameters to that message.
2572 * The special named parameter 'options' in a message specification array is passed
2573 * through to the $options parameter of wfMsgExt().
2575 * Don't use this for messages that are not in users interface language.
2579 * $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>", 'some-error' );
2583 * $wgOut->addWikiText( "<div class='error'>\n" . wfMsgNoTrans( 'some-error' ) . "\n</div>" );
2585 * The newline after opening div is needed in some wikitext. See bug 19226.
2587 public function wrapWikiMsg( $wrap /*, ...*/ ) {
2588 $msgSpecs = func_get_args();
2589 array_shift( $msgSpecs );
2590 $msgSpecs = array_values( $msgSpecs );
2592 foreach ( $msgSpecs as $n => $spec ) {
2594 if ( is_array( $spec ) ) {
2596 $name = array_shift( $args );
2597 if ( isset( $args['options'] ) ) {
2598 $options = $args['options'];
2599 unset( $args['options'] );
2605 $s = str_replace( '$' . ( $n +
1 ), wfMsgExt( $name, $options, $args ), $s );
2607 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );
2611 * Include jQuery core. Use this to avoid loading it multiple times
2612 * before we get a usable script loader.
2614 * @param $modules Array: list of jQuery modules which should be loaded
2615 * @return Array: the list of modules which were not loaded.
2618 public function includeJQuery( $modules = array() ) {
2619 global $wgStylePath, $wgStyleVersion, $wgJQueryVersion, $wgJQueryMinified;
2621 $supportedModules = array( /** TODO: add things here */ );
2622 $unsupported = array_diff( $modules, $supportedModules );
2624 $min = $wgJQueryMinified ?
'.min' : '';
2625 $url = "$wgStylePath/common/jquery-$wgJQueryVersion$min.js?$wgStyleVersion";
2626 if ( !$this->mJQueryDone
) {
2627 $this->mJQueryDone
= true;
2628 $this->mScripts
= Html
::linkedScript( $url ) . "\n" . $this->mScripts
;
2630 return $unsupported;