2 if ( ! defined( 'MEDIAWIKI' ) )
9 var $mMetatags = array(), $mKeywords = array(), $mLinktags = array();
10 var $mExtStyles = array();
11 var $mPagetitle = '', $mBodytext = '', $mDebugtext = '';
12 var $mHTMLtitle = '', $mIsarticle = true, $mPrintable = false;
13 var $mSubtitle = '', $mRedirect = '', $mStatusCode;
14 var $mLastModified = '', $mETag = false;
15 var $mCategoryLinks = array(), $mCategories = array(), $mLanguageLinks = array();
17 var $mScripts = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array();
18 var $mInlineMsg = array();
20 var $mTemplateIds = array();
23 var $mSuppressQuickbar = false;
24 var $mDoNothing = false;
25 var $mContainsOldMagic = 0, $mContainsNewMagic = 0;
26 var $mIsArticleRelated = true;
27 protected $mParserOptions = null; // lazy initialised, use parserOptions()
29 var $mFeedLinks = array();
31 var $mEnableClientCache = true;
32 var $mArticleBodyOnly = false;
34 var $mNewSectionLink = false;
35 var $mHideNewSectionLink = false;
36 var $mNoGallery = false;
37 var $mPageTitleActionText = '';
38 var $mParseWarnings = array();
39 var $mSquidMaxage = 0;
40 var $mRevisionId = null;
41 protected $mTitle = null;
44 * An array of stylesheet filenames (relative from skins path), with options
45 * for CSS media, IE conditions, and RTL/LTR direction.
46 * For internal use; add settings in the skin via $this->addStyle()
48 var $styles = array();
51 * Whether to load jQuery core.
53 protected $mJQueryDone = false;
55 private $mIndexPolicy = 'index';
56 private $mFollowPolicy = 'follow';
57 private $mVaryHeader = array( 'Accept-Encoding' => array('list-contains=gzip'),
63 * Initialise private variables
65 function __construct() {
66 global $wgAllowUserJs;
67 $this->mAllowUserJs
= $wgAllowUserJs;
71 * Redirect to $url rather than displaying the normal page
73 * @param $url String: URL
74 * @param $responsecode String: HTTP status code
76 public function redirect( $url, $responsecode = '302' ) {
77 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
78 $this->mRedirect
= str_replace( "\n", '', $url );
79 $this->mRedirectCode
= $responsecode;
83 * Get the URL to redirect to, or an empty string if not redirect URL set
87 public function getRedirect() {
88 return $this->mRedirect
;
92 * Set the HTTP status code to send with the output.
94 * @param $statusCode Integer
97 public function setStatusCode( $statusCode ) {
98 $this->mStatusCode
= $statusCode;
103 * Add a new <meta> tag
104 * To add an http-equiv meta tag, precede the name with "http:"
106 * @param $name tag name
107 * @param $val tag value
109 function addMeta( $name, $val ) {
110 array_push( $this->mMetatags
, array( $name, $val ) );
114 * Add a keyword or a list of keywords in the page header
116 * @param $text String or array of strings
118 function addKeyword( $text ) {
119 if( is_array( $text ) ) {
120 $this->mKeywords
= array_merge( $this->mKeywords
, $text );
122 array_push( $this->mKeywords
, $text );
127 * Add a new \<link\> tag to the page header
129 * @param $linkarr Array: associative array of attributes.
131 function addLink( $linkarr ) {
132 array_push( $this->mLinktags
, $linkarr );
136 * Add a new \<link\> with "rel" attribute set to "meta"
138 * @param $linkarr Array: associative array mapping attribute names to their
139 * values, both keys and values will be escaped, and the
140 * "rel" attribute will be automatically added
142 function addMetadataLink( $linkarr ) {
143 # note: buggy CC software only reads first "meta" link
144 static $haveMeta = false;
145 $linkarr['rel'] = $haveMeta ?
'alternate meta' : 'meta';
146 $this->addLink( $linkarr );
152 * Add raw HTML to the list of scripts (including \<script\> tag, etc.)
154 * @param $script String: raw HTML
156 function addScript( $script ) {
157 $this->mScripts
.= $script . "\n";
161 * Register and add a stylesheet from an extension directory.
163 * @param $url String path to sheet. Provide either a full url (beginning
164 * with 'http', etc) or a relative path from the document root
165 * (beginning with '/'). Otherwise it behaves identically to
166 * addStyle() and draws from the /skins folder.
168 public function addExtensionStyle( $url ) {
169 array_push( $this->mExtStyles
, $url );
173 * Get all links added by extensions
177 function getExtStyle() {
178 return $this->mExtStyles
;
182 * Add a JavaScript file out of skins/common, or a given relative path.
184 * @param $file String: filename in skins/common or complete on-server path
187 public function addScriptFile( $file ) {
188 global $wgStylePath, $wgStyleVersion;
189 if( substr( $file, 0, 1 ) == '/' ||
preg_match( '#^[a-z]*://#i', $file ) ) {
192 $path = "{$wgStylePath}/common/{$file}";
194 $this->addScript( Html
::linkedScript( wfAppendQuery( $path, $wgStyleVersion ) ) );
198 * Add a self-contained script tag with the given contents
200 * @param $script String: JavaScript text, no <script> tags
202 public function addInlineScript( $script ) {
203 $this->mScripts
.= Html
::inlineScript( "\n$script\n" ) . "\n";
207 * Get all registered JS and CSS tags for the header.
211 function getScript() {
212 return $this->mScripts
. $this->getHeadItems();
216 * Get all header items in a string
220 function getHeadItems() {
222 foreach ( $this->mHeadItems
as $item ) {
229 * Add or replace an header item to the output
231 * @param $name String: item name
232 * @param $value String: raw HTML
234 public function addHeadItem( $name, $value ) {
235 $this->mHeadItems
[$name] = $value;
239 * Check if the header item $name is already set
241 * @param $name String: item name
244 public function hasHeadItem( $name ) {
245 return isset( $this->mHeadItems
[$name] );
249 * Set the value of the ETag HTTP header, only used if $wgUseETag is true
251 * @param $tag String: value of "ETag" header
253 function setETag( $tag ) {
258 * Set whether the output should only contain the body of the article,
259 * without any skin, sidebar, etc.
260 * Used e.g. when calling with "action=render".
262 * @param $only Boolean: whether to output only the body of the article
264 public function setArticleBodyOnly( $only ) {
265 $this->mArticleBodyOnly
= $only;
269 * Return whether the output will contain only the body of the article
273 public function getArticleBodyOnly() {
274 return $this->mArticleBodyOnly
;
279 * checkLastModified tells the client to use the client-cached page if
280 * possible. If sucessful, the OutputPage is disabled so that
281 * any future call to OutputPage->output() have no effect.
283 * Side effect: sets mLastModified for Last-Modified header
285 * @return Boolean: true iff cache-ok headers was sent.
287 public function checkLastModified( $timestamp ) {
288 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
290 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
291 wfDebug( __METHOD__
. ": CACHE DISABLED, NO TIMESTAMP\n" );
294 if( !$wgCachePages ) {
295 wfDebug( __METHOD__
. ": CACHE DISABLED\n", false );
298 if( $wgUser->getOption( 'nocache' ) ) {
299 wfDebug( __METHOD__
. ": USER DISABLED CACHE\n", false );
303 $timestamp = wfTimestamp( TS_MW
, $timestamp );
304 $modifiedTimes = array(
305 'page' => $timestamp,
306 'user' => $wgUser->getTouched(),
307 'epoch' => $wgCacheEpoch
309 wfRunHooks( 'OutputPageCheckLastModified', array( &$modifiedTimes ) );
311 $maxModified = max( $modifiedTimes );
312 $this->mLastModified
= wfTimestamp( TS_RFC2822
, $maxModified );
314 if( empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
315 wfDebug( __METHOD__
. ": client did not send If-Modified-Since header\n", false );
321 foreach ( $modifiedTimes as $name => $value ) {
322 if ( $info !== '' ) {
325 $info .= "$name=" . wfTimestamp( TS_ISO_8601
, $value );
328 # IE sends sizes after the date like this:
329 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
330 # this breaks strtotime().
331 $clientHeader = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
333 wfSuppressWarnings(); // E_STRICT system time bitching
334 $clientHeaderTime = strtotime( $clientHeader );
336 if ( !$clientHeaderTime ) {
337 wfDebug( __METHOD__
. ": unable to parse the client's If-Modified-Since header: $clientHeader\n" );
340 $clientHeaderTime = wfTimestamp( TS_MW
, $clientHeaderTime );
342 wfDebug( __METHOD__
. ": client sent If-Modified-Since: " .
343 wfTimestamp( TS_ISO_8601
, $clientHeaderTime ) . "\n", false );
344 wfDebug( __METHOD__
. ": effective Last-Modified: " .
345 wfTimestamp( TS_ISO_8601
, $maxModified ) . "\n", false );
346 if( $clientHeaderTime < $maxModified ) {
347 wfDebug( __METHOD__
. ": STALE, $info\n", false );
352 # Give a 304 response code and disable body output
353 wfDebug( __METHOD__
. ": NOT MODIFIED, $info\n", false );
354 ini_set('zlib.output_compression', 0);
355 $wgRequest->response()->header( "HTTP/1.1 304 Not Modified" );
356 $this->sendCacheControl();
359 // Don't output a compressed blob when using ob_gzhandler;
360 // it's technically against HTTP spec and seems to confuse
361 // Firefox when the response gets split over two packets.
362 wfClearOutputBuffers();
369 * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
371 * @param $policy String: the literal string to output as the contents of
372 * the meta tag. Will be parsed according to the spec and output in
376 public function setRobotPolicy( $policy ) {
377 $policy = Article
::formatRobotPolicy( $policy );
379 if( isset( $policy['index'] ) ){
380 $this->setIndexPolicy( $policy['index'] );
382 if( isset( $policy['follow'] ) ){
383 $this->setFollowPolicy( $policy['follow'] );
388 * Set the index policy for the page, but leave the follow policy un-
391 * @param $policy string Either 'index' or 'noindex'.
394 public function setIndexPolicy( $policy ) {
395 $policy = trim( $policy );
396 if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
397 $this->mIndexPolicy
= $policy;
402 * Set the follow policy for the page, but leave the index policy un-
405 * @param $policy String: either 'follow' or 'nofollow'.
408 public function setFollowPolicy( $policy ) {
409 $policy = trim( $policy );
410 if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
411 $this->mFollowPolicy
= $policy;
417 * Set the new value of the "action text", this will be added to the
418 * "HTML title", separated from it with " - ".
420 * @param $text String: new value of the "action text"
422 public function setPageTitleActionText( $text ) {
423 $this->mPageTitleActionText
= $text;
427 * Get the value of the "action text"
431 public function getPageTitleActionText() {
432 if ( isset( $this->mPageTitleActionText
) ) {
433 return $this->mPageTitleActionText
;
438 * "HTML title" means the contents of <title>. It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
440 public function setHTMLTitle( $name ) {
441 $this->mHTMLtitle
= $name;
445 * Return the "HTML title", i.e. the content of the <title> tag.
449 public function getHTMLTitle() {
450 return $this->mHTMLtitle
;
454 * "Page title" means the contents of \<h1\>. It is stored as a valid HTML fragment.
455 * This function allows good tags like \<sup\> in the \<h1\> tag, but not bad tags like \<script\>.
456 * This function automatically sets \<title\> to the same content as \<h1\> but with all tags removed.
457 * Bad tags that were escaped in \<h1\> will still be escaped in \<title\>, and good tags like \<i\> will be dropped entirely.
459 public function setPageTitle( $name ) {
460 # change "<script>foo&bar</script>" to "<script>foo&bar</script>"
461 # but leave "<i>foobar</i>" alone
462 $nameWithTags = Sanitizer
::normalizeCharReferences( Sanitizer
::removeHTMLtags( $name ) );
463 $this->mPagetitle
= $nameWithTags;
465 $taction = $this->getPageTitleActionText();
466 if( !empty( $taction ) ) {
467 $name .= ' - '.$taction;
470 # change "<i>foo&bar</i>" to "foo&bar"
471 $this->setHTMLTitle( wfMsg( 'pagetitle', Sanitizer
::stripAllTags( $nameWithTags ) ) );
475 * Return the "page title", i.e. the content of the \<h1\> tag.
479 public function getPageTitle() {
480 return $this->mPagetitle
;
484 * Set the Title object to use
486 * @param $t Title object
488 public function setTitle( $t ) {
493 * Get the Title object used in this instance
497 public function getTitle() {
498 if ( $this->mTitle
instanceof Title
) {
499 return $this->mTitle
;
501 wfDebug( __METHOD__
. ' called and $mTitle is null. Return $wgTitle for sanity' );
508 * Replace the subtile with $str
510 * @param $str String: new value of the subtitle
512 public function setSubtitle( $str ) {
513 $this->mSubtitle
= /*$this->parse(*/ $str /*)*/; // @bug 2514
517 * Add $str to the subtitle
519 * @param $str String to add to the subtitle
521 public function appendSubtitle( $str ) {
522 $this->mSubtitle
.= /*$this->parse(*/ $str /*)*/; // @bug 2514
530 public function getSubtitle() {
531 return $this->mSubtitle
;
536 * Set the page as printable, i.e. it'll be displayed with with all
537 * print styles included
539 public function setPrintable() {
540 $this->mPrintable
= true;
544 * Return whether the page is "printable"
548 public function isPrintable() {
549 return $this->mPrintable
;
554 * Disable output completely, i.e. calling output() will have no effect
556 public function disable() {
557 $this->mDoNothing
= true;
561 * Return whether the output will be completely disabled
565 public function isDisabled() {
566 return $this->mDoNothing
;
571 * Show an "add new section" link?
575 public function showNewSectionLink() {
576 return $this->mNewSectionLink
;
580 * Forcibly hide the new section link?
584 public function forceHideNewSectionLink() {
585 return $this->mHideNewSectionLink
;
590 * Add or remove feed links in the page header
591 * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
592 * for the new version
595 * @param $show Boolean: true: add default feeds, false: remove all feeds
597 public function setSyndicated( $show = true ) {
599 $this->setFeedAppendQuery( false );
601 $this->mFeedLinks
= array();
606 * Add default feeds to the page header
607 * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
608 * for the new version
611 * @param $val String: query to append to feed links or false to output
614 public function setFeedAppendQuery( $val ) {
615 global $wgAdvertisedFeedTypes;
617 $this->mFeedLinks
= array();
619 foreach ( $wgAdvertisedFeedTypes as $type ) {
620 $query = "feed=$type";
621 if ( is_string( $val ) ) {
622 $query .= '&' . $val;
624 $this->mFeedLinks
[$type] = $this->getTitle()->getLocalURL( $query );
629 * Add a feed link to the page header
631 * @param $format String: feed type, should be a key of $wgFeedClasses
632 * @param $href String: URL
634 public function addFeedLink( $format, $href ) {
635 $this->mFeedLinks
[$format] = $href;
639 * Should we output feed links for this page?
642 public function isSyndicated() {
643 return count( $this->mFeedLinks
) > 0;
647 * Return URLs for each supported syndication format for this page.
648 * @return array associating format keys with URLs
650 public function getSyndicationLinks() {
651 return $this->mFeedLinks
;
655 * Will currently always return null
659 public function getFeedAppendQuery() {
660 return $this->mFeedLinksAppendQuery
;
664 * Set whether the displayed content is related to the source of the
665 * corresponding article on the wiki
666 * Setting true will cause the change "article related" toggle to true
670 public function setArticleFlag( $v ) {
671 $this->mIsarticle
= $v;
673 $this->mIsArticleRelated
= $v;
678 * Return whether the content displayed page is related to the source of
679 * the corresponding article on the wiki
683 public function isArticle() {
684 return $this->mIsarticle
;
688 * Set whether this page is related an article on the wiki
689 * Setting false will cause the change of "article flag" toggle to false
693 public function setArticleRelated( $v ) {
694 $this->mIsArticleRelated
= $v;
696 $this->mIsarticle
= false;
701 * Return whether this page is related an article on the wiki
705 public function isArticleRelated() {
706 return $this->mIsArticleRelated
;
711 * Add new language links
713 * @param $newLinkArray Associative array mapping language code to the page
716 public function addLanguageLinks( $newLinkArray ) {
717 $this->mLanguageLinks +
= $newLinkArray;
721 * Reset the language links and add new language links
723 * @param $newLinkArray Associative array mapping language code to the page
726 public function setLanguageLinks( $newLinkArray ) {
727 $this->mLanguageLinks
= $newLinkArray;
731 * Get the list of language links
733 * @return Associative array mapping language code to the page name
735 public function getLanguageLinks() {
736 return $this->mLanguageLinks
;
741 * Add an array of categories, with names in the keys
743 * @param $categories Associative array mapping category name to its sort key
745 public function addCategoryLinks( $categories ) {
746 global $wgUser, $wgContLang;
748 if ( !is_array( $categories ) ||
count( $categories ) == 0 ) {
752 # Add the links to a LinkBatch
753 $arr = array( NS_CATEGORY
=> $categories );
755 $lb->setArray( $arr );
757 # Fetch existence plus the hiddencat property
758 $dbr = wfGetDB( DB_SLAVE
);
759 $pageTable = $dbr->tableName( 'page' );
760 $where = $lb->constructSet( 'page', $dbr );
761 $propsTable = $dbr->tableName( 'page_props' );
762 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, pp_value
763 FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
764 $res = $dbr->query( $sql, __METHOD__
);
766 # Add the results to the link cache
767 $lb->addResultToCache( LinkCache
::singleton(), $res );
769 # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
770 $categories = array_combine( array_keys( $categories ),
771 array_fill( 0, count( $categories ), 'normal' ) );
773 # Mark hidden categories
774 foreach ( $res as $row ) {
775 if ( isset( $row->pp_value
) ) {
776 $categories[$row->page_title
] = 'hidden';
780 # Add the remaining categories to the skin
781 if ( wfRunHooks( 'OutputPageMakeCategoryLinks', array( &$this, $categories, &$this->mCategoryLinks
) ) ) {
782 $sk = $wgUser->getSkin();
783 foreach ( $categories as $category => $type ) {
784 $origcategory = $category;
785 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
786 $wgContLang->findVariantLink( $category, $title, true );
787 if ( $category != $origcategory )
788 if ( array_key_exists( $category, $categories ) )
790 $text = $wgContLang->convertHtml( $title->getText() );
791 $this->mCategories
[] = $title->getText();
792 $this->mCategoryLinks
[$type][] = $sk->link( $title, $text );
798 * Reset the category links (but not the category list) and add $categories
800 * @param $categories Associative array mapping category name to its sort key
802 public function setCategoryLinks( $categories ) {
803 $this->mCategoryLinks
= array();
804 $this->addCategoryLinks( $categories );
808 * Get the list of category links, in a 2-D array with the following format:
809 * $arr[$type][] = $link, where $type is either "normal" or "hidden" (for
810 * hidden categories) and $link a HTML fragment with a link to the category
815 public function getCategoryLinks() {
816 return $this->mCategoryLinks
;
820 * Get the list of category names this page belongs to
822 * @return Array of strings
824 public function getCategories() {
825 return $this->mCategories
;
830 * Suppress the quickbar from the output, only for skin supporting
833 public function suppressQuickbar() {
834 $this->mSuppressQuickbar
= true;
838 * Return whether the quickbar should be suppressed from the output
842 public function isQuickbarSuppressed() {
843 return $this->mSuppressQuickbar
;
848 * Remove user JavaScript from scripts to load
850 public function disallowUserJs() {
851 $this->mAllowUserJs
= false;
855 * Return whether user JavaScript is allowed for this page
859 public function isUserJsAllowed() {
860 return $this->mAllowUserJs
;
865 * Prepend $text to the body HTML
867 * @param $text String: HTML
869 public function prependHTML( $text ) {
870 $this->mBodytext
= $text . $this->mBodytext
;
874 * Append $text to the body HTML
876 * @param $text String: HTML
878 public function addHTML( $text ) {
879 $this->mBodytext
.= $text;
883 * Clear the body HTML
885 public function clearHTML() {
886 $this->mBodytext
= '';
892 * @return String: HTML
894 public function getHTML() {
895 return $this->mBodytext
;
900 * Add $text to the debug output
902 * @param $text String: debug text
904 public function debug( $text ) {
905 $this->mDebugtext
.= $text;
910 * @deprecated use parserOptions() instead
912 public function setParserOptions( $options ) {
913 wfDeprecated( __METHOD__
);
914 return $this->parserOptions( $options );
918 * Get/set the ParserOptions object to use for wikitext parsing
920 * @param $options either the ParserOption to use or null to only get the
921 * current ParserOption object
922 * @return current ParserOption object
924 public function parserOptions( $options = null ) {
925 if ( !$this->mParserOptions
) {
926 $this->mParserOptions
= new ParserOptions
;
928 return wfSetVar( $this->mParserOptions
, $options );
932 * Set the revision ID which will be seen by the wiki text parser
933 * for things such as embedded {{REVISIONID}} variable use.
935 * @param $revid Mixed: an positive integer, or null
936 * @return Mixed: previous value
938 public function setRevisionId( $revid ) {
939 $val = is_null( $revid ) ?
null : intval( $revid );
940 return wfSetVar( $this->mRevisionId
, $val );
944 * Get the current revision ID
948 public function getRevisionId() {
949 return $this->mRevisionId
;
953 * Convert wikitext to HTML and add it to the buffer
954 * Default assumes that the current page title will be used.
956 * @param $text String
957 * @param $linestart Boolean: is this the start of a line?
959 public function addWikiText( $text, $linestart = true ) {
960 $title = $this->getTitle(); // Work arround E_STRICT
961 $this->addWikiTextTitle( $text, $title, $linestart );
965 * Add wikitext with a custom Title object
967 * @param $text String: wikitext
968 * @param $title Title object
969 * @param $linestart Boolean: is this the start of a line?
971 public function addWikiTextWithTitle( $text, &$title, $linestart = true ) {
972 $this->addWikiTextTitle( $text, $title, $linestart );
976 * Add wikitext with a custom Title object and
978 * @param $text String: wikitext
979 * @param $title Title object
980 * @param $linestart Boolean: is this the start of a line?
982 function addWikiTextTitleTidy( $text, &$title, $linestart = true ) {
983 $this->addWikiTextTitle( $text, $title, $linestart, true );
987 * Add wikitext with tidy enabled
989 * @param $text String: wikitext
990 * @param $linestart Boolean: is this the start of a line?
992 public function addWikiTextTidy( $text, $linestart = true ) {
993 $title = $this->getTitle();
994 $this->addWikiTextTitleTidy($text, $title, $linestart);
998 * Add wikitext with a custom Title object
1000 * @param $text String: wikitext
1001 * @param $title Title object
1002 * @param $linestart Boolean: is this the start of a line?
1003 * @param $tidy Boolean: whether to use tidy
1005 public function addWikiTextTitle( $text, &$title, $linestart, $tidy = false ) {
1008 wfProfileIn( __METHOD__
);
1010 wfIncrStats( 'pcache_not_possible' );
1012 $popts = $this->parserOptions();
1013 $oldTidy = $popts->setTidy( $tidy );
1015 $parserOutput = $wgParser->parse( $text, $title, $popts,
1016 $linestart, true, $this->mRevisionId
);
1018 $popts->setTidy( $oldTidy );
1020 $this->addParserOutput( $parserOutput );
1022 wfProfileOut( __METHOD__
);
1026 * Add wikitext to the buffer, assuming that this is the primary text for a page view
1027 * Saves the text into the parser cache if possible.
1029 * @param $text String: wikitext
1030 * @param $article Article object
1031 * @param $cache Boolean
1032 * @deprecated Use Article::outputWikitext
1034 public function addPrimaryWikiText( $text, $article, $cache = true ) {
1037 wfDeprecated( __METHOD__
);
1039 $popts = $this->parserOptions();
1040 $popts->setTidy(true);
1041 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
1042 $popts, true, true, $this->mRevisionId
);
1043 $popts->setTidy(false);
1044 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
1045 $parserCache = ParserCache
::singleton();
1046 $parserCache->save( $parserOutput, $article, $popts);
1049 $this->addParserOutput( $parserOutput );
1053 * @deprecated use addWikiTextTidy()
1055 public function addSecondaryWikiText( $text, $linestart = true ) {
1056 wfDeprecated( __METHOD__
);
1057 $this->addWikiTextTitleTidy($text, $this->getTitle(), $linestart);
1062 * Add a ParserOutput object, but without Html
1064 * @param $parserOutput ParserOutput object
1066 public function addParserOutputNoText( &$parserOutput ) {
1067 global $wgExemptFromUserRobotsControl, $wgContentNamespaces;
1069 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
1070 $this->addCategoryLinks( $parserOutput->getCategories() );
1071 $this->mNewSectionLink
= $parserOutput->getNewSection();
1072 $this->mHideNewSectionLink
= $parserOutput->getHideNewSection();
1074 $this->mParseWarnings
= $parserOutput->getWarnings();
1075 if ( $parserOutput->getCacheTime() == -1 ) {
1076 $this->enableClientCache( false );
1078 $this->mNoGallery
= $parserOutput->getNoGallery();
1079 $this->mHeadItems
= array_merge( $this->mHeadItems
, $parserOutput->getHeadItems() );
1081 foreach ( (array)$parserOutput->mTemplateIds
as $ns => $dbks ) {
1082 if ( isset( $this->mTemplateIds
[$ns] ) ) {
1083 $this->mTemplateIds
[$ns] = $dbks +
$this->mTemplateIds
[$ns];
1085 $this->mTemplateIds
[$ns] = $dbks;
1089 $title = $parserOutput->getTitleText();
1090 if ( $title != '' ) {
1091 $this->setPageTitle( $title );
1094 // Hooks registered in the object
1095 global $wgParserOutputHooks;
1096 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
1097 list( $hookName, $data ) = $hookInfo;
1098 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
1099 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
1103 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
1107 * Add a ParserOutput object
1109 * @param $parserOutput ParserOutput
1111 function addParserOutput( &$parserOutput ) {
1112 $this->addParserOutputNoText( $parserOutput );
1113 $text = $parserOutput->getText();
1114 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
1115 $this->addHTML( $text );
1120 * Add the output of a QuickTemplate to the output buffer
1122 * @param $template QuickTemplate
1124 public function addTemplate( &$template ) {
1126 $template->execute();
1127 $this->addHTML( ob_get_contents() );
1132 * Parse wikitext and return the HTML.
1134 * @param $text String
1135 * @param $linestart Boolean: is this the start of a line?
1136 * @param $interface Boolean: use interface language ($wgLang instead of
1137 * $wgContLang) while parsing language sensitive magic
1138 * words like GRAMMAR and PLURAL
1139 * @return String: HTML
1141 public function parse( $text, $linestart = true, $interface = false ) {
1143 if( is_null( $this->getTitle() ) ) {
1144 throw new MWException( 'Empty $mTitle in ' . __METHOD__
);
1146 $popts = $this->parserOptions();
1147 if ( $interface) { $popts->setInterfaceMessage(true); }
1148 $parserOutput = $wgParser->parse( $text, $this->getTitle(), $popts,
1149 $linestart, true, $this->mRevisionId
);
1150 if ( $interface) { $popts->setInterfaceMessage(false); }
1151 return $parserOutput->getText();
1155 * Parse wikitext, strip paragraphs, and return the HTML.
1157 * @param $text String
1158 * @param $linestart Boolean: is this the start of a line?
1159 * @param $interface Boolean: use interface language ($wgLang instead of
1160 * $wgContLang) while parsing language sensitive magic
1161 * words like GRAMMAR and PLURAL
1162 * @return String: HTML
1164 public function parseInline( $text, $linestart = true, $interface = false ) {
1165 $parsed = $this->parse( $text, $linestart, $interface );
1168 if ( preg_match( '/^<p>(.*)\n?<\/p>\n?/sU', $parsed, $m ) ) {
1178 * @param $article Article
1179 * @return Boolean: true if successful, else false.
1181 public function tryParserCache( &$article ) {
1182 wfDeprecated( __METHOD__
);
1183 $parserOutput = ParserCache
::singleton()->get( $article, $article->getParserOptions() );
1185 if ($parserOutput !== false) {
1186 $this->addParserOutput( $parserOutput );
1194 * Set the value of the "s-maxage" part of the "Cache-control" HTTP header
1196 * @param $maxage Integer: maximum cache time on the Squid, in seconds.
1198 public function setSquidMaxage( $maxage ) {
1199 $this->mSquidMaxage
= $maxage;
1203 * Use enableClientCache(false) to force it to send nocache headers
1207 public function enableClientCache( $state ) {
1208 return wfSetVar( $this->mEnableClientCache
, $state );
1212 * Get the list of cookies that will influence on the cache
1216 function getCacheVaryCookies() {
1217 global $wgCookiePrefix, $wgCacheVaryCookies;
1219 if ( $cookies === null ) {
1220 $cookies = array_merge(
1222 "{$wgCookiePrefix}Token",
1223 "{$wgCookiePrefix}LoggedOut",
1228 wfRunHooks('GetCacheVaryCookies', array( $this, &$cookies ) );
1234 * Return whether this page is not cacheable because "useskin" or "uselang"
1235 * url parameters were passed
1239 function uncacheableBecauseRequestVars() {
1241 return $wgRequest->getText('useskin', false) === false
1242 && $wgRequest->getText('uselang', false) === false;
1246 * Check if the request has a cache-varying cookie header
1247 * If it does, it's very important that we don't allow public caching
1251 function haveCacheVaryCookies() {
1253 $cookieHeader = $wgRequest->getHeader( 'cookie' );
1254 if ( $cookieHeader === false ) {
1257 $cvCookies = $this->getCacheVaryCookies();
1258 foreach ( $cvCookies as $cookieName ) {
1259 # Check for a simple string match, like the way squid does it
1260 if ( strpos( $cookieHeader, $cookieName ) ) {
1261 wfDebug( __METHOD__
.": found $cookieName\n" );
1265 wfDebug( __METHOD__
.": no cache-varying cookies found\n" );
1270 * Add an HTTP header that will influence on the cache
1272 * @param $header String: header name
1273 * @param $option either an Array or null
1275 public function addVaryHeader( $header, $option = null ) {
1276 if ( !array_key_exists( $header, $this->mVaryHeader
) ) {
1277 $this->mVaryHeader
[$header] = $option;
1279 elseif( is_array( $option ) ) {
1280 if( is_array( $this->mVaryHeader
[$header] ) ) {
1281 $this->mVaryHeader
[$header] = array_merge( $this->mVaryHeader
[$header], $option );
1284 $this->mVaryHeader
[$header] = $option;
1287 $this->mVaryHeader
[$header] = array_unique( $this->mVaryHeader
[$header] );
1291 * Get a complete X-Vary-Options header
1295 public function getXVO() {
1296 $cvCookies = $this->getCacheVaryCookies();
1298 $cookiesOption = array();
1299 foreach ( $cvCookies as $cookieName ) {
1300 $cookiesOption[] = 'string-contains=' . $cookieName;
1302 $this->addVaryHeader( 'Cookie', $cookiesOption );
1305 foreach( $this->mVaryHeader
as $header => $option ) {
1306 $newheader = $header;
1307 if( is_array( $option ) )
1308 $newheader .= ';' . implode( ';', $option );
1309 $headers[] = $newheader;
1311 $xvo = 'X-Vary-Options: ' . implode( ',', $headers );
1317 * bug 21672: Add Accept-Language to Vary and XVO headers
1318 * if there's no 'variant' parameter existed in GET.
1321 * /w/index.php?title=Main_page should always be served; but
1322 * /w/index.php?title=Main_page&variant=zh-cn should never be served.
1324 function addAcceptLanguage() {
1325 global $wgRequest, $wgContLang;
1326 if( !$wgRequest->getCheck('variant') && $wgContLang->hasVariants() ) {
1327 $variants = $wgContLang->getVariants();
1328 $aloption = array();
1329 foreach ( $variants as $variant ) {
1330 if( $variant === $wgContLang->getCode() )
1333 $aloption[] = "string-contains=$variant";
1335 $this->addVaryHeader( 'Accept-Language', $aloption );
1340 * Send cache control HTTP headers
1342 public function sendCacheControl() {
1343 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
1345 $response = $wgRequest->response();
1346 if ($wgUseETag && $this->mETag
)
1347 $response->header("ETag: $this->mETag");
1349 $this->addAcceptLanguage();
1351 # don't serve compressed data to clients who can't handle it
1352 # maintain different caches for logged-in users and non-logged in ones
1353 $response->header( 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader
) ) );
1356 # Add an X-Vary-Options header for Squid with Wikimedia patches
1357 $response->header( $this->getXVO() );
1360 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache
) {
1361 if( $wgUseSquid && session_id() == '' &&
1362 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 && !$this->haveCacheVaryCookies() )
1365 # We'll purge the proxy cache explicitly, but require end user agents
1366 # to revalidate against the proxy on each visit.
1367 # Surrogate-Control controls our Squid, Cache-Control downstream caches
1368 wfDebug( __METHOD__
. ": proxy caching with ESI; {$this->mLastModified} **\n", false );
1369 # start with a shorter timeout for initial testing
1370 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
1371 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
1372 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
1374 # We'll purge the proxy cache for anons explicitly, but require end user agents
1375 # to revalidate against the proxy on each visit.
1376 # IMPORTANT! The Squid needs to replace the Cache-Control header with
1377 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
1378 wfDebug( __METHOD__
. ": local proxy caching; {$this->mLastModified} **\n", false );
1379 # start with a shorter timeout for initial testing
1380 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
1381 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
1384 # We do want clients to cache if they can, but they *must* check for updates
1385 # on revisiting the page.
1386 wfDebug( __METHOD__
. ": private caching; {$this->mLastModified} **\n", false );
1387 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1388 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
1390 if($this->mLastModified
) {
1391 $response->header( "Last-Modified: {$this->mLastModified}" );
1394 wfDebug( __METHOD__
. ": no caching **\n", false );
1396 # In general, the absence of a last modified header should be enough to prevent
1397 # the client from using its cache. We send a few other things just to make sure.
1398 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1399 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
1400 $response->header( 'Pragma: no-cache' );
1405 * Get the message associed with the HTTP response code $code
1407 * @param $code Integer: status code
1408 * @return String or null: message or null if $code is not in the list of
1411 public static function getStatusMessage( $code ) {
1412 static $statusMessage = array(
1414 101 => 'Switching Protocols',
1415 102 => 'Processing',
1419 203 => 'Non-Authoritative Information',
1420 204 => 'No Content',
1421 205 => 'Reset Content',
1422 206 => 'Partial Content',
1423 207 => 'Multi-Status',
1424 300 => 'Multiple Choices',
1425 301 => 'Moved Permanently',
1428 304 => 'Not Modified',
1430 307 => 'Temporary Redirect',
1431 400 => 'Bad Request',
1432 401 => 'Unauthorized',
1433 402 => 'Payment Required',
1436 405 => 'Method Not Allowed',
1437 406 => 'Not Acceptable',
1438 407 => 'Proxy Authentication Required',
1439 408 => 'Request Timeout',
1442 411 => 'Length Required',
1443 412 => 'Precondition Failed',
1444 413 => 'Request Entity Too Large',
1445 414 => 'Request-URI Too Large',
1446 415 => 'Unsupported Media Type',
1447 416 => 'Request Range Not Satisfiable',
1448 417 => 'Expectation Failed',
1449 422 => 'Unprocessable Entity',
1451 424 => 'Failed Dependency',
1452 500 => 'Internal Server Error',
1453 501 => 'Not Implemented',
1454 502 => 'Bad Gateway',
1455 503 => 'Service Unavailable',
1456 504 => 'Gateway Timeout',
1457 505 => 'HTTP Version Not Supported',
1458 507 => 'Insufficient Storage'
1460 return isset( $statusMessage[$code] ) ?
$statusMessage[$code] : null;
1464 * Finally, all the text has been munged and accumulated into
1465 * the object, let's actually output it:
1467 public function output() {
1468 global $wgUser, $wgOutputEncoding, $wgRequest;
1469 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
1470 global $wgUseAjax, $wgAjaxWatch;
1471 global $wgEnableMWSuggest, $wgUniversalEditButton;
1474 if( $this->mDoNothing
){
1477 wfProfileIn( __METHOD__
);
1478 if ( $this->mRedirect
!= '' ) {
1479 # Standards require redirect URLs to be absolute
1480 $this->mRedirect
= wfExpandUrl( $this->mRedirect
);
1481 if( $this->mRedirectCode
== '301' ||
$this->mRedirectCode
== '303' ) {
1482 if( !$wgDebugRedirects ) {
1483 $message = self
::getStatusMessage( $this->mRedirectCode
);
1484 $wgRequest->response()->header( "HTTP/1.1 {$this->mRedirectCode} $message" );
1486 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
1488 $this->sendCacheControl();
1490 $wgRequest->response()->header( "Content-Type: text/html; charset=utf-8" );
1491 if( $wgDebugRedirects ) {
1492 $url = htmlspecialchars( $this->mRedirect
);
1493 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
1494 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
1495 print "</body>\n</html>\n";
1497 $wgRequest->response()->header( 'Location: ' . $this->mRedirect
);
1499 wfProfileOut( __METHOD__
);
1501 } elseif ( $this->mStatusCode
) {
1502 $message = self
::getStatusMessage( $this->mStatusCode
);
1504 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $message );
1507 $sk = $wgUser->getSkin();
1510 $this->addScriptFile( 'ajax.js' );
1512 wfRunHooks( 'AjaxAddScript', array( &$this ) );
1514 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
1515 $this->addScriptFile( 'ajaxwatch.js' );
1518 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
1519 $this->addScriptFile( 'mwsuggest.js' );
1523 if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
1524 $this->addScriptFile( 'rightclickedit.js' );
1527 if( $wgUniversalEditButton ) {
1528 if( isset( $wgArticle ) && $this->getTitle() && $this->getTitle()->quickUserCan( 'edit' )
1529 && ( $this->getTitle()->exists() ||
$this->getTitle()->quickUserCan( 'create' ) ) ) {
1530 // Original UniversalEditButton
1531 $msg = wfMsg('edit');
1532 $this->addLink( array(
1533 'rel' => 'alternate',
1534 'type' => 'application/x-wiki',
1536 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1538 // Alternate edit link
1539 $this->addLink( array(
1542 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1547 # Buffer output; final headers may depend on later processing
1550 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
1551 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
1553 if ($this->mArticleBodyOnly
) {
1554 $this->out($this->mBodytext
);
1556 // Hook that allows last minute changes to the output page, e.g.
1557 // adding of CSS or Javascript by extensions.
1558 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
1560 wfProfileIn( 'Output-skin' );
1561 $sk->outputPage( $this );
1562 wfProfileOut( 'Output-skin' );
1565 $this->sendCacheControl();
1567 wfProfileOut( __METHOD__
);
1571 * Actually output something with print(). Performs an iconv to the
1572 * output encoding, if needed.
1574 * @param $ins String: the string to output
1576 public function out( $ins ) {
1577 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
1578 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
1581 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
1582 if ( false === $outs ) { $outs = $ins; }
1590 public static function setEncodings() {
1591 global $wgInputEncoding, $wgOutputEncoding;
1594 $wgInputEncoding = strtolower( $wgInputEncoding );
1596 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
1597 $wgOutputEncoding = strtolower( $wgOutputEncoding );
1600 $wgOutputEncoding = $wgInputEncoding;
1604 * @deprecated use wfReportTime() instead.
1608 public function reportTime() {
1609 wfDeprecated( __METHOD__
);
1610 $time = wfReportTime();
1615 * Produce a "user is blocked" page.
1617 * @param $return Boolean: whether to have a "return to $wgTitle" message or not.
1620 function blockedPage( $return = true ) {
1621 global $wgUser, $wgContLang, $wgLang;
1623 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
1624 $this->setRobotPolicy( 'noindex,nofollow' );
1625 $this->setArticleRelated( false );
1627 $name = User
::whoIs( $wgUser->blockedBy() );
1628 $reason = $wgUser->blockedFor();
1629 if( $reason == '' ) {
1630 $reason = wfMsg( 'blockednoreason' );
1632 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
1635 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
1637 $blockid = $wgUser->mBlock
->mId
;
1639 $blockExpiry = $wgUser->mBlock
->mExpiry
;
1640 if ( $blockExpiry == 'infinity' ) {
1641 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
1642 // Search for localization in 'ipboptions'
1643 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1644 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
1645 if ( strpos( $option, ":" ) === false )
1647 list( $show, $value ) = explode( ":", $option );
1648 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
1649 $blockExpiry = $show;
1654 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
1657 if ( $wgUser->mBlock
->mAuto
) {
1658 $msg = 'autoblockedtext';
1660 $msg = 'blockedtext';
1663 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
1664 * This could be a username, an ip range, or a single ip. */
1665 $intended = $wgUser->mBlock
->mAddress
;
1667 $this->addWikiMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
1669 # Don't auto-return to special pages
1671 $return = $this->getTitle()->getNamespace() > -1 ?
$this->getTitle() : null;
1672 $this->returnToMain( null, $return );
1677 * Output a standard error page
1679 * @param $title String: message key for page title
1680 * @param $msg String: message key for page text
1681 * @param $params Array: message parameters
1683 public function showErrorPage( $title, $msg, $params = array() ) {
1684 if ( $this->getTitle() ) {
1685 $this->mDebugtext
.= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n";
1687 $this->setPageTitle( wfMsg( $title ) );
1688 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1689 $this->setRobotPolicy( 'noindex,nofollow' );
1690 $this->setArticleRelated( false );
1691 $this->enableClientCache( false );
1692 $this->mRedirect
= '';
1693 $this->mBodytext
= '';
1695 array_unshift( $params, 'parse' );
1696 array_unshift( $params, $msg );
1697 $this->addHTML( call_user_func_array( 'wfMsgExt', $params ) );
1699 $this->returnToMain();
1703 * Output a standard permission error page
1705 * @param $errors Array: error message keys
1706 * @param $action String: action that was denied or null if unknown
1708 public function showPermissionsErrorPage( $errors, $action = null ) {
1709 $this->mDebugtext
.= 'Original title: ' .
1710 $this->getTitle()->getPrefixedText() . "\n";
1711 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
1712 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
1713 $this->setRobotPolicy( 'noindex,nofollow' );
1714 $this->setArticleRelated( false );
1715 $this->enableClientCache( false );
1716 $this->mRedirect
= '';
1717 $this->mBodytext
= '';
1718 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
1722 * Display an error page indicating that a given version of MediaWiki is
1723 * required to use it
1725 * @param $version Mixed: the version of MediaWiki needed to use the page
1727 public function versionRequired( $version ) {
1728 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
1729 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
1730 $this->setRobotPolicy( 'noindex,nofollow' );
1731 $this->setArticleRelated( false );
1732 $this->mBodytext
= '';
1734 $this->addWikiMsg( 'versionrequiredtext', $version );
1735 $this->returnToMain();
1739 * Display an error page noting that a given permission bit is required.
1741 * @param $permission String: key required
1743 public function permissionRequired( $permission ) {
1746 $this->setPageTitle( wfMsg( 'badaccess' ) );
1747 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1748 $this->setRobotPolicy( 'noindex,nofollow' );
1749 $this->setArticleRelated( false );
1750 $this->mBodytext
= '';
1752 $groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
1753 User
::getGroupsWithPermission( $permission ) );
1755 $this->addWikiMsg( 'badaccess-groups',
1756 $wgLang->commaList( $groups ),
1759 $this->addWikiMsg( 'badaccess-group0' );
1761 $this->returnToMain();
1765 * @deprecated use permissionRequired()
1767 public function sysopRequired() {
1768 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
1772 * @deprecated use permissionRequired()
1774 public function developerRequired() {
1775 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
1779 * Produce the stock "please login to use the wiki" page
1781 public function loginToUse() {
1782 global $wgUser, $wgContLang;
1784 if( $wgUser->isLoggedIn() ) {
1785 $this->permissionRequired( 'read' );
1789 $skin = $wgUser->getSkin();
1791 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1792 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1793 $this->setRobotPolicy( 'noindex,nofollow' );
1794 $this->setArticleFlag( false );
1796 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1797 $loginLink = $skin->link(
1799 wfMsgHtml( 'loginreqlink' ),
1801 array( 'returnto' => $this->getTitle()->getPrefixedText() ),
1802 array( 'known', 'noclasses' )
1804 $this->addHTML( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1805 $this->addHTML( "\n<!--" . $this->getTitle()->getPrefixedUrl() . "-->" );
1807 # Don't return to the main page if the user can't read it
1808 # otherwise we'll end up in a pointless loop
1809 $mainPage = Title
::newMainPage();
1810 if( $mainPage->userCanRead() )
1811 $this->returnToMain( null, $mainPage );
1815 * Format a list of error messages
1817 * @param $errors An array of arrays returned by Title::getUserPermissionsErrors
1818 * @param $action String: action that was denied or null if unknown
1819 * @return String: the wikitext error-messages, formatted into a list.
1821 public function formatPermissionsErrorMessage( $errors, $action = null ) {
1822 if ($action == null) {
1823 $text = wfMsgNoTrans( 'permissionserrorstext', count($errors)). "\n\n";
1826 $action_desc = wfMsgNoTrans( "action-$action" );
1827 $text = wfMsgNoTrans( 'permissionserrorstext-withaction', count($errors), $action_desc ) . "\n\n";
1830 if (count( $errors ) > 1) {
1831 $text .= '<ul class="permissions-errors">' . "\n";
1833 foreach( $errors as $error )
1836 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1841 $text .= "<div class=\"permissions-errors\">\n" . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . "\n</div>";
1848 * Display a page stating that the Wiki is in read-only mode,
1849 * and optionally show the source of the page that the user
1850 * was trying to edit. Should only be called (for this
1851 * purpose) after wfReadOnly() has returned true.
1853 * For historical reasons, this function is _also_ used to
1854 * show the error message when a user tries to edit a page
1855 * they are not allowed to edit. (Unless it's because they're
1856 * blocked, then we show blockedPage() instead.) In this
1857 * case, the second parameter should be set to true and a list
1858 * of reasons supplied as the third parameter.
1860 * @todo Needs to be split into multiple functions.
1862 * @param $source String: source code to show (or null).
1863 * @param $protected Boolean: is this a permissions error?
1864 * @param $reasons Array: list of reasons for this error, as returned by Title::getUserPermissionsErrors().
1865 * @param $action String: action that was denied or null if unknown
1867 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
1869 $skin = $wgUser->getSkin();
1871 $this->setRobotPolicy( 'noindex,nofollow' );
1872 $this->setArticleRelated( false );
1874 // If no reason is given, just supply a default "I can't let you do
1875 // that, Dave" message. Should only occur if called by legacy code.
1876 if ( $protected && empty($reasons) ) {
1877 $reasons[] = array( 'badaccess-group0' );
1880 if ( !empty($reasons) ) {
1881 // Permissions error
1883 $this->setPageTitle( wfMsg( 'viewsource' ) );
1892 array( 'known', 'noclasses' )
1897 $this->setPageTitle( wfMsg( 'badaccess' ) );
1899 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) );
1901 // Wiki is read only
1902 $this->setPageTitle( wfMsg( 'readonly' ) );
1903 $reason = wfReadOnlyReason();
1904 $this->wrapWikiMsg( '<div class="mw-readonly-error">\n$1</div>', array( 'readonlytext', $reason ) );
1907 // Show source, if supplied
1908 if( is_string( $source ) ) {
1909 $this->addWikiMsg( 'viewsourcetext' );
1912 'id' => 'wpTextbox1',
1913 'name' => 'wpTextbox1',
1914 'cols' => $wgUser->getOption( 'cols' ),
1915 'rows' => $wgUser->getOption( 'rows' ),
1916 'readonly' => 'readonly'
1918 $this->addHTML( Html
::element( 'textarea', $params, $source ) );
1920 // Show templates used by this article
1921 $skin = $wgUser->getSkin();
1922 $article = new Article( $this->getTitle() );
1923 $this->addHTML( "<div class='templatesUsed'>
1924 {$skin->formatTemplates( $article->getUsedTemplates() )}
1929 # If the title doesn't exist, it's fairly pointless to print a return
1930 # link to it. After all, you just tried editing it and couldn't, so
1931 # what's there to do there?
1932 if( $this->getTitle()->exists() ) {
1933 $this->returnToMain( null, $this->getTitle() );
1938 public function errorpage( $title, $msg ) {
1939 wfDeprecated( __METHOD__
);
1940 throw new ErrorPageError( $title, $msg );
1944 public function databaseError( $fname, $sql, $error, $errno ) {
1945 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1949 public function fatalError( $message ) {
1950 wfDeprecated( __METHOD__
);
1951 throw new FatalError( $message );
1955 public function unexpectedValueError( $name, $val ) {
1956 wfDeprecated( __METHOD__
);
1957 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1961 public function fileCopyError( $old, $new ) {
1962 wfDeprecated( __METHOD__
);
1963 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1967 public function fileRenameError( $old, $new ) {
1968 wfDeprecated( __METHOD__
);
1969 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1973 public function fileDeleteError( $name ) {
1974 wfDeprecated( __METHOD__
);
1975 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1979 public function fileNotFoundError( $name ) {
1980 wfDeprecated( __METHOD__
);
1981 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1984 public function showFatalError( $message ) {
1985 $this->setPageTitle( wfMsg( "internalerror" ) );
1986 $this->setRobotPolicy( "noindex,nofollow" );
1987 $this->setArticleRelated( false );
1988 $this->enableClientCache( false );
1989 $this->mRedirect
= '';
1990 $this->mBodytext
= $message;
1993 public function showUnexpectedValueError( $name, $val ) {
1994 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1997 public function showFileCopyError( $old, $new ) {
1998 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
2001 public function showFileRenameError( $old, $new ) {
2002 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
2005 public function showFileDeleteError( $name ) {
2006 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
2009 public function showFileNotFoundError( $name ) {
2010 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
2014 * Add a "return to" link pointing to a specified title
2016 * @param $title Title to link
2017 * @param $query String: query string
2018 * @param $text String text of the link (input is not escaped)
2020 public function addReturnTo( $title, $query=array(), $text=null ) {
2022 $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullUrl() ) );
2025 $wgUser->getSkin()->link( $title, $text, array(), $query )
2027 $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
2031 * Add a "return to" link pointing to a specified title,
2032 * or the title indicated in the request, or else the main page
2034 * @param $unused No longer used
2035 * @param $returnto Title or String to return to
2036 * @param $returntoquery String: query string for the return to link
2038 public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
2041 if ( $returnto == null ) {
2042 $returnto = $wgRequest->getText( 'returnto' );
2045 if ( $returntoquery == null ) {
2046 $returntoquery = $wgRequest->getText( 'returntoquery' );
2049 if ( $returnto === '' ) {
2050 $returnto = Title
::newMainPage();
2053 if ( is_object( $returnto ) ) {
2054 $titleObj = $returnto;
2056 $titleObj = Title
::newFromText( $returnto );
2058 if ( !is_object( $titleObj ) ) {
2059 $titleObj = Title
::newMainPage();
2062 $this->addReturnTo( $titleObj, $returntoquery );
2066 * @param $sk Skin The given Skin
2067 * @param $includeStyle Unused (?)
2068 * @return String: The doctype, opening <html>, and head element.
2070 public function headElement( Skin
$sk, $includeStyle = true ) {
2071 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
2072 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
2073 global $wgContLang, $wgUseTrackbacks, $wgStyleVersion, $wgHtml5, $wgWellFormedXml;
2074 global $wgUser, $wgRequest, $wgLang;
2076 if ( $sk->commonPrintStylesheet() ) {
2077 $this->addStyle( 'common/wikiprintable.css', 'print' );
2079 $sk->setupUserCss( $this );
2083 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
2084 $ret .= "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
2087 if ( $this->getHTMLTitle() == '' ) {
2088 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ) );
2091 $dir = $wgContLang->getDir();
2093 $htmlAttribs = array( 'lang' => $wgContLanguageCode, 'dir' => $dir );
2095 if ( $wgWellFormedXml ) {
2096 # Unknown elements and attributes are okay in XML, but unknown
2097 # named entities are well-formedness errors and will break XML
2098 # parsers. Thus we need a doctype that gives us appropriate
2099 # entity definitions. The HTML5 spec permits four legacy
2100 # doctypes as obsolete but conforming, so let's pick one of
2101 # those, although it makes our pages look like XHTML1 Strict.
2102 # Isn't compatibility great?
2103 $ret .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
2106 $ret .= "<!doctype html>\n";
2108 if ( $wgHtml5Version ) {
2109 $htmlAttribs['version'] = $wgHtml5Version;
2112 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
2113 $htmlAttribs['xmlns'] = $wgXhtmlDefaultNamespace;
2114 foreach ( $wgXhtmlNamespaces as $tag => $ns ) {
2115 $htmlAttribs["xmlns:$tag"] = $ns;
2117 $this->addMeta( 'http:Content-Type', "$wgMimeType; charset=$wgOutputEncoding" );
2119 $ret .= Html
::openElement( 'html', $htmlAttribs ) . "\n";
2121 $openHead = Html
::openElement( 'head' );
2123 # Don't bother with the newline if $head == ''
2124 $ret .= "$openHead\n";
2126 $ret .= "<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
2129 # More succinct than <meta http-equiv=Content-Type>, has the
2131 $ret .= Html
::element( 'meta', array( 'charset' => $wgOutputEncoding ) ) . "\n";
2134 $ret .= implode( "\n", array(
2135 $this->getHeadLinks(),
2136 $this->buildCssLinks(),
2137 $this->getHeadScripts( $sk ),
2138 $this->getHeadItems(),
2140 if ( $sk->usercss
) {
2141 $ret .= Html
::inlineStyle( $sk->usercss
);
2144 if ( $wgUseTrackbacks && $this->isArticleRelated() ) {
2145 $ret .= $this->getTitle()->trackbackRDF();
2148 $closeHead = Html
::closeElement( 'head' );
2150 $ret .= "$closeHead\n";
2153 $bodyAttrs = array();
2155 # Crazy edit-on-double-click stuff
2156 $action = $wgRequest->getVal( 'action', 'view' );
2158 if ( $this->getTitle()->getNamespace() != NS_SPECIAL
2159 && !in_array( $action, array( 'edit', 'submit' ) )
2160 && $wgUser->getOption( 'editondblclick' ) ) {
2161 $bodyAttrs['ondblclick'] = "document.location = '" . Xml
::escapeJsString( $this->getTitle()->getEditURL() ) . "'";
2165 $bodyAttrs['class'] = "mediawiki $dir";
2167 if ( $wgLang->capitalizeAllNouns() ) {
2168 # A <body> class is probably not the best way to do this . . .
2169 $bodyAttrs['class'] .= ' capitalize-all-nouns';
2171 $bodyAttrs['class'] .= ' ns-' . $this->getTitle()->getNamespace();
2172 if ( $this->getTitle()->getNamespace() == NS_SPECIAL
) {
2173 $bodyAttrs['class'] .= ' ns-special';
2174 } elseif ( $this->getTitle()->isTalkPage() ) {
2175 $bodyAttrs['class'] .= ' ns-talk';
2177 $bodyAttrs['class'] .= ' ns-subject';
2179 $bodyAttrs['class'] .= ' ' . Sanitizer
::escapeClass( 'page-' . $this->getTitle()->getPrefixedText() );
2180 $bodyAttrs['class'] .= ' skin-' . Sanitizer
::escapeClass( $wgUser->getSkin()->getSkinName() );
2182 $ret .= Html
::openElement( 'body', $bodyAttrs ) . "\n";
2188 * Gets the global variables and mScripts; also adds userjs to the end if
2191 * @param $sk Skin object to use
2192 * @return String: HTML fragment
2194 function getHeadScripts( Skin
$sk ) {
2195 global $wgUser, $wgRequest, $wgJsMimeType, $wgUseSiteJs;
2196 global $wgStylePath, $wgStyleVersion;
2198 $scripts = Skin
::makeGlobalVariablesScript( $sk->getSkinName() );
2199 $scripts .= Html
::linkedScript( "{$wgStylePath}/common/wikibits.js?$wgStyleVersion" );
2201 //add site JS if enabled:
2202 if( $wgUseSiteJs ) {
2203 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
2204 $this->addScriptFile( Skin
::makeUrl( '-',
2205 "action=raw$jsCache&gen=js&useskin=" .
2206 urlencode( $sk->getSkinName() )
2211 //add user js if enabled:
2212 if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
2213 $action = $wgRequest->getVal( 'action', 'view' );
2214 if( $this->mTitle
&& $this->mTitle
->isJsSubpage() and $sk->userCanPreview( $action ) ) {
2215 # XXX: additional security check/prompt?
2216 $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
2218 $userpage = $wgUser->getUserPage();
2219 $names = array( 'common', $sk->getSkinName() );
2220 foreach( $names as $name ) {
2221 $scriptpage = Title
::makeTitleSafe(
2223 $userpage->getDBkey() . '/' . $name . '.js'
2225 if ( $scriptpage && $scriptpage->exists() ) {
2226 $userjs = $scriptpage->getLocalURL( 'action=raw&ctype=' . $wgJsMimeType );
2227 $this->addScriptFile( $userjs );
2233 $scripts .= "\n" . $this->mScripts
;
2238 * Add default \<meta\> tags
2240 protected function addDefaultMeta() {
2241 global $wgVersion, $wgHtml5;
2243 static $called = false;
2245 # Don't run this twice
2251 $this->addMeta( 'http:Content-Style-Type', 'text/css' ); //bug 15835
2253 $this->addMeta( 'generator', "MediaWiki $wgVersion" );
2255 $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
2256 if( $p !== 'index,follow' ) {
2257 // http://www.robotstxt.org/wc/meta-user.html
2258 // Only show if it's different from the default robots policy
2259 $this->addMeta( 'robots', $p );
2262 if ( count( $this->mKeywords
) > 0 ) {
2264 "/<.*?" . ">/" => '',
2267 $this->addMeta( 'keywords', preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
) ) );
2272 * @return string HTML tag links to be put in the header.
2274 public function getHeadLinks() {
2275 global $wgRequest, $wgFeed;
2277 // Ideally this should happen earlier, somewhere. :P
2278 $this->addDefaultMeta();
2282 foreach ( $this->mMetatags
as $tag ) {
2283 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
2285 $tag[0] = substr( $tag[0], 5 );
2289 $tags[] = Html
::element( 'meta',
2292 'content' => $tag[1] ) );
2294 foreach ( $this->mLinktags
as $tag ) {
2295 $tags[] = Html
::element( 'link', $tag );
2299 foreach( $this->getSyndicationLinks() as $format => $link ) {
2300 # Use the page name for the title (accessed through $wgTitle since
2301 # there's no other way). In principle, this could lead to issues
2302 # with having the same name for different feeds corresponding to
2303 # the same page, but we can't avoid that at this low a level.
2305 $tags[] = $this->feedLink(
2308 # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
2309 wfMsg( "page-{$format}-feed", $this->getTitle()->getPrefixedText() ) );
2312 # Recent changes feed should appear on every page (except recentchanges,
2313 # that would be redundant). Put it after the per-page feed to avoid
2314 # changing existing behavior. It's still available, probably via a
2315 # menu in your browser. Some sites might have a different feed they'd
2316 # like to promote instead of the RC feed (maybe like a "Recent New Articles"
2317 # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined.
2318 # If so, use it instead.
2320 global $wgOverrideSiteFeed, $wgSitename, $wgAdvertisedFeedTypes;
2321 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
2323 if ( $wgOverrideSiteFeed ) {
2324 foreach ( $wgOverrideSiteFeed as $type => $feedUrl ) {
2325 $tags[] = $this->feedLink (
2327 htmlspecialchars( $feedUrl ),
2328 wfMsg( "site-{$type}-feed", $wgSitename ) );
2330 } elseif ( $this->getTitle()->getPrefixedText() != $rctitle->getPrefixedText() ) {
2331 foreach ( $wgAdvertisedFeedTypes as $format ) {
2332 $tags[] = $this->feedLink(
2334 $rctitle->getLocalURL( "feed={$format}" ),
2335 wfMsg( "site-{$format}-feed", $wgSitename ) ); # For grep: 'site-rss-feed', 'site-atom-feed'.
2340 return implode( "\n", $tags );
2344 * Generate a <link rel/> for a feed.
2346 * @param $type String: feed type
2347 * @param $url String: URL to the feed
2348 * @param $text String: value of the "title" attribute
2349 * @return String: HTML fragment
2351 private function feedLink( $type, $url, $text ) {
2352 return Html
::element( 'link', array(
2353 'rel' => 'alternate',
2354 'type' => "application/$type+xml",
2360 * Add a local or specified stylesheet, with the given media options.
2361 * Meant primarily for internal use...
2363 * @param $style String: URL to the file
2364 * @param $media String: to specify a media type, 'screen', 'printable', 'handheld' or any.
2365 * @param $condition String: for IE conditional comments, specifying an IE version
2366 * @param $dir String: set to 'rtl' or 'ltr' for direction-specific sheets
2368 public function addStyle( $style, $media='', $condition='', $dir='' ) {
2370 // Even though we expect the media type to be lowercase, but here we
2371 // force it to lowercase to be safe.
2373 $options['media'] = $media;
2375 $options['condition'] = $condition;
2377 $options['dir'] = $dir;
2378 $this->styles
[$style] = $options;
2382 * Adds inline CSS styles
2383 * @param $style_css Mixed: inline CSS
2385 public function addInlineStyle( $style_css ){
2386 $this->mScripts
.= Html
::inlineStyle( $style_css );
2390 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
2391 * These will be applied to various media & IE conditionals.
2393 public function buildCssLinks() {
2395 foreach( $this->styles
as $file => $options ) {
2396 $link = $this->styleLink( $file, $options );
2401 return implode( "\n", $links );
2405 * Generate \<link\> tags for stylesheets
2407 * @param $style String: URL to the file
2408 * @param $options Array: option, can contain 'condition', 'dir', 'media'
2410 * @return String: HTML fragment
2412 protected function styleLink( $style, $options ) {
2415 if( isset( $options['dir'] ) ) {
2417 $siteDir = $wgContLang->getDir();
2418 if( $siteDir != $options['dir'] )
2422 if( isset( $options['media'] ) ) {
2423 $media = $this->transformCssMedia( $options['media'] );
2424 if( is_null( $media ) ) {
2431 if( substr( $style, 0, 1 ) == '/' ||
2432 substr( $style, 0, 5 ) == 'http:' ||
2433 substr( $style, 0, 6 ) == 'https:' ) {
2436 global $wgStylePath, $wgStyleVersion;
2437 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
2440 $link = Html
::linkedStyle( $url, $media );
2442 if( isset( $options['condition'] ) ) {
2443 $condition = htmlspecialchars( $options['condition'] );
2444 $link = "<!--[if $condition]>$link<![endif]-->";
2450 * Transform "media" attribute based on request parameters
2452 * @param $media String: current value of the "media" attribute
2453 * @return String: modified value of the "media" attribute
2455 function transformCssMedia( $media ) {
2456 global $wgRequest, $wgHandheldForIPhone;
2458 // Switch in on-screen display for media testing
2460 'printable' => 'print',
2461 'handheld' => 'handheld',
2463 foreach( $switches as $switch => $targetMedia ) {
2464 if( $wgRequest->getBool( $switch ) ) {
2465 if( $media == $targetMedia ) {
2467 } elseif( $media == 'screen' ) {
2473 // Expand longer media queries as iPhone doesn't grok 'handheld'
2474 if( $wgHandheldForIPhone ) {
2475 $mediaAliases = array(
2476 'screen' => 'screen and (min-device-width: 481px)',
2477 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
2480 if( isset( $mediaAliases[$media] ) ) {
2481 $media = $mediaAliases[$media];
2489 * Turn off regular page output and return an error reponse
2490 * for when rate limiting has triggered.
2492 public function rateLimited() {
2493 $this->setPageTitle(wfMsg('actionthrottled'));
2494 $this->setRobotPolicy( 'noindex,follow' );
2495 $this->setArticleRelated( false );
2496 $this->enableClientCache( false );
2497 $this->mRedirect
= '';
2499 $this->setStatusCode(503);
2500 $this->addWikiMsg( 'actionthrottledtext' );
2502 $this->returnToMain( null, $this->getTitle() );
2506 * Show a warning about slave lag
2508 * If the lag is higher than $wgSlaveLagCritical seconds,
2509 * then the warning is a bit more obvious. If the lag is
2510 * lower than $wgSlaveLagWarning, then no warning is shown.
2512 * @param $lag Integer: slave lag
2514 public function showLagWarning( $lag ) {
2515 global $wgSlaveLagWarning, $wgSlaveLagCritical, $wgLang;
2516 if( $lag >= $wgSlaveLagWarning ) {
2517 $message = $lag < $wgSlaveLagCritical
2520 $wrap = Html
::rawElement( 'div', array( 'class' => "mw-{$message}" ), "\n$1\n" );
2521 $this->wrapWikiMsg( "$wrap\n", array( $message, $wgLang->formatNum( $lag ) ) );
2526 * Add a wikitext-formatted message to the output.
2527 * This is equivalent to:
2529 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
2531 public function addWikiMsg( /*...*/ ) {
2532 $args = func_get_args();
2533 $name = array_shift( $args );
2534 $this->addWikiMsgArray( $name, $args );
2538 * Add a wikitext-formatted message to the output.
2539 * Like addWikiMsg() except the parameters are taken as an array
2540 * instead of a variable argument list.
2542 * $options is passed through to wfMsgExt(), see that function for details.
2544 public function addWikiMsgArray( $name, $args, $options = array() ) {
2545 $options[] = 'parse';
2546 $text = wfMsgExt( $name, $options, $args );
2547 $this->addHTML( $text );
2551 * This function takes a number of message/argument specifications, wraps them in
2552 * some overall structure, and then parses the result and adds it to the output.
2554 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
2555 * on. The subsequent arguments may either be strings, in which case they are the
2556 * message names, or arrays, in which case the first element is the message name,
2557 * and subsequent elements are the parameters to that message.
2559 * The special named parameter 'options' in a message specification array is passed
2560 * through to the $options parameter of wfMsgExt().
2562 * Don't use this for messages that are not in users interface language.
2566 * $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>", 'some-error' );
2570 * $wgOut->addWikiText( "<div class='error'>\n" . wfMsgNoTrans( 'some-error' ) . "</div>" );
2572 * The newline after opening div is needed in some wikitext. See bug 19226.
2574 public function wrapWikiMsg( $wrap /*, ...*/ ) {
2575 $msgSpecs = func_get_args();
2576 array_shift( $msgSpecs );
2577 $msgSpecs = array_values( $msgSpecs );
2579 foreach ( $msgSpecs as $n => $spec ) {
2581 if ( is_array( $spec ) ) {
2583 $name = array_shift( $args );
2584 if ( isset( $args['options'] ) ) {
2585 $options = $args['options'];
2586 unset( $args['options'] );
2592 $s = str_replace( '$' . ( $n +
1 ), wfMsgExt( $name, $options, $args ), $s );
2594 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );
2598 * Include jQuery core. Use this to avoid loading it multiple times
2599 * before we get a usable script loader.
2601 * @param $modules Array: list of jQuery modules which should be loaded
2602 * @return Array: the list of modules which were not loaded.
2605 public function includeJQuery( $modules = array() ) {
2606 global $wgStylePath, $wgStyleVersion;
2608 $supportedModules = array( /** TODO: add things here */ );
2609 $unsupported = array_diff( $modules, $supportedModules );
2611 $url = "$wgStylePath/common/jquery.min.js?$wgStyleVersion";
2612 if ( !$this->mJQueryDone
) {
2613 $this->mJQueryDone
= true;
2614 $this->mScripts
= Html
::linkedScript( $url ) . "\n" . $this->mScripts
;
2616 return $unsupported;