33753c0f811e57568d68ae3f9bf76b03fb1e9c88
2 if ( ! defined( 'MEDIAWIKI' ) )
9 var $mMetatags = array(), $mKeywords = array(), $mLinktags = array();
10 var $mExtStyles = array();
11 var $mPagetitle = '', $mBodytext = '', $mDebugtext = '';
12 var $mHTMLtitle = '', $mHTMLtitleFromPagetitle = true, $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();
368 * Override the last modified timestamp
370 * @param $timestamp String: new timestamp, in a format readable by
373 public function setLastModified( $timestamp ) {
374 $this->mLastModified
= wfTimestamp( TS_RFC2822
, $timestamp );
379 * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
381 * @param $policy String: the literal string to output as the contents of
382 * the meta tag. Will be parsed according to the spec and output in
386 public function setRobotPolicy( $policy ) {
387 $policy = Article
::formatRobotPolicy( $policy );
389 if( isset( $policy['index'] ) ){
390 $this->setIndexPolicy( $policy['index'] );
392 if( isset( $policy['follow'] ) ){
393 $this->setFollowPolicy( $policy['follow'] );
398 * Set the index policy for the page, but leave the follow policy un-
401 * @param $policy string Either 'index' or 'noindex'.
404 public function setIndexPolicy( $policy ) {
405 $policy = trim( $policy );
406 if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
407 $this->mIndexPolicy
= $policy;
412 * Set the follow policy for the page, but leave the index policy un-
415 * @param $policy String: either 'follow' or 'nofollow'.
418 public function setFollowPolicy( $policy ) {
419 $policy = trim( $policy );
420 if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
421 $this->mFollowPolicy
= $policy;
427 * Set the new value of the "action text", this will be added to the
428 * "HTML title", separated from it with " - ".
430 * @param $text String: new value of the "action text"
432 public function setPageTitleActionText( $text ) {
433 $this->mPageTitleActionText
= $text;
437 * Get the value of the "action text"
441 public function getPageTitleActionText() {
442 if ( isset( $this->mPageTitleActionText
) ) {
443 return $this->mPageTitleActionText
;
448 * "HTML title" means the contents of <title>.
449 * It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
450 * If $name is from page title, it can only override names which are also from page title,
451 * but if it is not from page title, it can override all other names.
453 public function setHTMLTitle( $name, $frompagetitle = false ) {
454 if ( $frompagetitle && $this->mHTMLtitleFromPagetitle
) {
455 $this->mHTMLtitle
= $name;
457 elseif ( $this->mHTMLtitleFromPagetitle
) {
458 $this->mHTMLtitle
= $name;
459 $this->mHTMLtitleFromPagetitle
= false;
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 ) ), true );
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
;
555 * Set the page as printable, i.e. it'll be displayed with with all
556 * print styles included
558 public function setPrintable() {
559 $this->mPrintable
= true;
563 * Return whether the page is "printable"
567 public function isPrintable() {
568 return $this->mPrintable
;
573 * Disable output completely, i.e. calling output() will have no effect
575 public function disable() {
576 $this->mDoNothing
= true;
580 * Return whether the output will be completely disabled
584 public function isDisabled() {
585 return $this->mDoNothing
;
590 * Show an "add new section" link?
594 public function showNewSectionLink() {
595 return $this->mNewSectionLink
;
599 * Forcibly hide the new section link?
603 public function forceHideNewSectionLink() {
604 return $this->mHideNewSectionLink
;
609 * Add or remove feed links in the page header
610 * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
611 * for the new version
614 * @param $show Boolean: true: add default feeds, false: remove all feeds
616 public function setSyndicated( $show = true ) {
618 $this->setFeedAppendQuery( false );
620 $this->mFeedLinks
= array();
625 * Add default feeds to the page header
626 * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
627 * for the new version
630 * @param $val String: query to append to feed links or false to output
633 public function setFeedAppendQuery( $val ) {
634 global $wgAdvertisedFeedTypes;
636 $this->mFeedLinks
= array();
638 foreach ( $wgAdvertisedFeedTypes as $type ) {
639 $query = "feed=$type";
640 if ( is_string( $val ) ) {
641 $query .= '&' . $val;
643 $this->mFeedLinks
[$type] = $this->getTitle()->getLocalURL( $query );
648 * Add a feed link to the page header
650 * @param $format String: feed type, should be a key of $wgFeedClasses
651 * @param $href String: URL
653 public function addFeedLink( $format, $href ) {
654 $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
;
730 * Add new language links
732 * @param $newLinkArray Associative array mapping language code to the page
735 public function addLanguageLinks( $newLinkArray ) {
736 $this->mLanguageLinks +
= $newLinkArray;
740 * Reset the language links and add new language links
742 * @param $newLinkArray Associative array mapping language code to the page
745 public function setLanguageLinks( $newLinkArray ) {
746 $this->mLanguageLinks
= $newLinkArray;
750 * Get the list of language links
752 * @return Associative array mapping language code to the page name
754 public function getLanguageLinks() {
755 return $this->mLanguageLinks
;
760 * Add an array of categories, with names in the keys
762 * @param $categories Associative array mapping category name to its sort key
764 public function addCategoryLinks( $categories ) {
765 global $wgUser, $wgContLang;
767 if ( !is_array( $categories ) ||
count( $categories ) == 0 ) {
771 # Add the links to a LinkBatch
772 $arr = array( NS_CATEGORY
=> $categories );
774 $lb->setArray( $arr );
776 # Fetch existence plus the hiddencat property
777 $dbr = wfGetDB( DB_SLAVE
);
778 $pageTable = $dbr->tableName( 'page' );
779 $where = $lb->constructSet( 'page', $dbr );
780 $propsTable = $dbr->tableName( 'page_props' );
781 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, pp_value
782 FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
783 $res = $dbr->query( $sql, __METHOD__
);
785 # Add the results to the link cache
786 $lb->addResultToCache( LinkCache
::singleton(), $res );
788 # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
789 $categories = array_combine( array_keys( $categories ),
790 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 ) )
809 $text = $wgContLang->convertHtml( $title->getText() );
810 $this->mCategories
[] = $title->getText();
811 $this->mCategoryLinks
[$type][] = $sk->link( $title, $text );
817 * Reset the category links (but not the category list) and add $categories
819 * @param $categories Associative array mapping category name to its sort key
821 public function setCategoryLinks( $categories ) {
822 $this->mCategoryLinks
= array();
823 $this->addCategoryLinks( $categories );
827 * Get the list of category links, in a 2-D array with the following format:
828 * $arr[$type][] = $link, where $type is either "normal" or "hidden" (for
829 * hidden categories) and $link a HTML fragment with a link to the category
834 public function getCategoryLinks() {
835 return $this->mCategoryLinks
;
839 * Get the list of category names this page belongs to
841 * @return Array of strings
843 public function getCategories() {
844 return $this->mCategories
;
849 * Suppress the quickbar from the output, only for skin supporting
852 public function suppressQuickbar() {
853 $this->mSuppressQuickbar
= true;
857 * Return whether the quickbar should be suppressed from the output
861 public function isQuickbarSuppressed() {
862 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
;
884 * Prepend $text to the body HTML
886 * @param $text String: HTML
888 public function prependHTML( $text ) {
889 $this->mBodytext
= $text . $this->mBodytext
;
893 * Append $text to the body HTML
895 * @param $text String: HTML
897 public function addHTML( $text ) {
898 $this->mBodytext
.= $text;
902 * Clear the body HTML
904 public function clearHTML() {
905 $this->mBodytext
= '';
911 * @return String: HTML
913 public function getHTML() {
914 return $this->mBodytext
;
919 * Add $text to the debug output
921 * @param $text String: debug text
923 public function debug( $text ) {
924 $this->mDebugtext
.= $text;
929 * @deprecated use parserOptions() instead
931 public function setParserOptions( $options ) {
932 wfDeprecated( __METHOD__
);
933 return $this->parserOptions( $options );
937 * Get/set the ParserOptions object to use for wikitext parsing
939 * @param $options either the ParserOption to use or null to only get the
940 * current ParserOption object
941 * @return current ParserOption object
943 public function parserOptions( $options = null ) {
944 if ( !$this->mParserOptions
) {
945 $this->mParserOptions
= new ParserOptions
;
947 return wfSetVar( $this->mParserOptions
, $options );
951 * Set the revision ID which will be seen by the wiki text parser
952 * for things such as embedded {{REVISIONID}} variable use.
954 * @param $revid Mixed: an positive integer, or null
955 * @return Mixed: previous value
957 public function setRevisionId( $revid ) {
958 $val = is_null( $revid ) ?
null : intval( $revid );
959 return wfSetVar( $this->mRevisionId
, $val );
963 * Get the current revision ID
967 public function getRevisionId() {
968 return $this->mRevisionId
;
972 * Convert wikitext to HTML and add it to the buffer
973 * Default assumes that the current page title will be used.
975 * @param $text String
976 * @param $linestart Boolean: is this the start of a line?
978 public function addWikiText( $text, $linestart = true ) {
979 $title = $this->getTitle(); // Work arround E_STRICT
980 $this->addWikiTextTitle( $text, $title, $linestart );
984 * Add wikitext with a custom Title object
986 * @param $text String: wikitext
987 * @param $title Title object
988 * @param $linestart Boolean: is this the start of a line?
990 public function addWikiTextWithTitle( $text, &$title, $linestart = true ) {
991 $this->addWikiTextTitle( $text, $title, $linestart );
995 * Add wikitext with a custom Title object and
997 * @param $text String: wikitext
998 * @param $title Title object
999 * @param $linestart Boolean: is this the start of a line?
1001 function addWikiTextTitleTidy( $text, &$title, $linestart = true ) {
1002 $this->addWikiTextTitle( $text, $title, $linestart, true );
1006 * Add wikitext with tidy enabled
1008 * @param $text String: wikitext
1009 * @param $linestart Boolean: is this the start of a line?
1011 public function addWikiTextTidy( $text, $linestart = true ) {
1012 $title = $this->getTitle();
1013 $this->addWikiTextTitleTidy($text, $title, $linestart);
1017 * Add wikitext with a custom Title object
1019 * @param $text String: wikitext
1020 * @param $title Title object
1021 * @param $linestart Boolean: is this the start of a line?
1022 * @param $tidy Boolean: whether to use tidy
1024 public function addWikiTextTitle( $text, &$title, $linestart, $tidy = false ) {
1027 wfProfileIn( __METHOD__
);
1029 wfIncrStats( 'pcache_not_possible' );
1031 $popts = $this->parserOptions();
1032 $oldTidy = $popts->setTidy( $tidy );
1034 $parserOutput = $wgParser->parse( $text, $title, $popts,
1035 $linestart, true, $this->mRevisionId
);
1037 $popts->setTidy( $oldTidy );
1039 $this->addParserOutput( $parserOutput );
1041 wfProfileOut( __METHOD__
);
1045 * Add wikitext to the buffer, assuming that this is the primary text for a page view
1046 * Saves the text into the parser cache if possible.
1048 * @param $text String: wikitext
1049 * @param $article Article object
1050 * @param $cache Boolean
1051 * @deprecated Use Article::outputWikitext
1053 public function addPrimaryWikiText( $text, $article, $cache = true ) {
1056 wfDeprecated( __METHOD__
);
1058 $popts = $this->parserOptions();
1059 $popts->setTidy(true);
1060 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
1061 $popts, true, true, $this->mRevisionId
);
1062 $popts->setTidy(false);
1063 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
1064 $parserCache = ParserCache
::singleton();
1065 $parserCache->save( $parserOutput, $article, $popts);
1068 $this->addParserOutput( $parserOutput );
1072 * @deprecated use addWikiTextTidy()
1074 public function addSecondaryWikiText( $text, $linestart = true ) {
1075 wfDeprecated( __METHOD__
);
1076 $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 global $wgExemptFromUserRobotsControl, $wgContentNamespaces;
1088 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
1089 $this->addCategoryLinks( $parserOutput->getCategories() );
1090 $this->mNewSectionLink
= $parserOutput->getNewSection();
1091 $this->mHideNewSectionLink
= $parserOutput->getHideNewSection();
1093 $this->mParseWarnings
= $parserOutput->getWarnings();
1094 if ( $parserOutput->getCacheTime() == -1 ) {
1095 $this->enableClientCache( false );
1097 $this->mNoGallery
= $parserOutput->getNoGallery();
1098 $this->mHeadItems
= array_merge( $this->mHeadItems
, $parserOutput->getHeadItems() );
1100 foreach ( (array)$parserOutput->mTemplateIds
as $ns => $dbks ) {
1101 if ( isset( $this->mTemplateIds
[$ns] ) ) {
1102 $this->mTemplateIds
[$ns] = $dbks +
$this->mTemplateIds
[$ns];
1104 $this->mTemplateIds
[$ns] = $dbks;
1108 $title = $parserOutput->getTitleText();
1109 if ( $title != '' ) {
1110 $this->setPageTitle( $title );
1113 // Hooks registered in the object
1114 global $wgParserOutputHooks;
1115 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
1116 list( $hookName, $data ) = $hookInfo;
1117 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
1118 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
1122 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
1126 * Add a ParserOutput object
1128 * @param $parserOutput ParserOutput
1130 function addParserOutput( &$parserOutput ) {
1131 $this->addParserOutputNoText( $parserOutput );
1132 $text = $parserOutput->getText();
1133 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
1134 $this->addHTML( $text );
1139 * Add the output of a QuickTemplate to the output buffer
1141 * @param $template QuickTemplate
1143 public function addTemplate( &$template ) {
1145 $template->execute();
1146 $this->addHTML( ob_get_contents() );
1151 * Parse wikitext and return the HTML.
1153 * @param $text String
1154 * @param $linestart Boolean: is this the start of a line?
1155 * @param $interface Boolean: use interface language ($wgLang instead of
1156 * $wgContLang) while parsing language sensitive magic
1157 * words like GRAMMAR and PLURAL
1158 * @return String: HTML
1160 public function parse( $text, $linestart = true, $interface = false ) {
1162 if( is_null( $this->getTitle() ) ) {
1163 throw new MWException( 'Empty $mTitle in ' . __METHOD__
);
1165 $popts = $this->parserOptions();
1166 if ( $interface) { $popts->setInterfaceMessage(true); }
1167 $parserOutput = $wgParser->parse( $text, $this->getTitle(), $popts,
1168 $linestart, true, $this->mRevisionId
);
1169 if ( $interface) { $popts->setInterfaceMessage(false); }
1170 return $parserOutput->getText();
1174 * Parse wikitext, strip paragraphs, and return the HTML.
1176 * @param $text String
1177 * @param $linestart Boolean: is this the start of a line?
1178 * @param $interface Boolean: use interface language ($wgLang instead of
1179 * $wgContLang) while parsing language sensitive magic
1180 * words like GRAMMAR and PLURAL
1181 * @return String: HTML
1183 public function parseInline( $text, $linestart = true, $interface = false ) {
1184 $parsed = $this->parse( $text, $linestart, $interface );
1187 if ( preg_match( '/^<p>(.*)\n?<\/p>\n?/sU', $parsed, $m ) ) {
1197 * @param $article Article
1198 * @return Boolean: true if successful, else false.
1200 public function tryParserCache( &$article ) {
1201 wfDeprecated( __METHOD__
);
1202 $parserOutput = ParserCache
::singleton()->get( $article, $article->getParserOptions() );
1204 if ($parserOutput !== false) {
1205 $this->addParserOutput( $parserOutput );
1213 * Set the value of the "s-maxage" part of the "Cache-control" HTTP header
1215 * @param $maxage Integer: maximum cache time on the Squid, in seconds.
1217 public function setSquidMaxage( $maxage ) {
1218 $this->mSquidMaxage
= $maxage;
1222 * Use enableClientCache(false) to force it to send nocache headers
1226 public function enableClientCache( $state ) {
1227 return wfSetVar( $this->mEnableClientCache
, $state );
1231 * Get the list of cookies that will influence on the cache
1235 function getCacheVaryCookies() {
1236 global $wgCookiePrefix, $wgCacheVaryCookies;
1238 if ( $cookies === null ) {
1239 $cookies = array_merge(
1241 "{$wgCookiePrefix}Token",
1242 "{$wgCookiePrefix}LoggedOut",
1247 wfRunHooks('GetCacheVaryCookies', array( $this, &$cookies ) );
1253 * Return whether this page is not cacheable because "useskin" or "uselang"
1254 * url parameters were passed
1258 function uncacheableBecauseRequestVars() {
1260 return $wgRequest->getText('useskin', false) === false
1261 && $wgRequest->getText('uselang', false) === false;
1265 * Check if the request has a cache-varying cookie header
1266 * If it does, it's very important that we don't allow public caching
1270 function haveCacheVaryCookies() {
1272 $cookieHeader = $wgRequest->getHeader( 'cookie' );
1273 if ( $cookieHeader === false ) {
1276 $cvCookies = $this->getCacheVaryCookies();
1277 foreach ( $cvCookies as $cookieName ) {
1278 # Check for a simple string match, like the way squid does it
1279 if ( strpos( $cookieHeader, $cookieName ) ) {
1280 wfDebug( __METHOD__
.": found $cookieName\n" );
1284 wfDebug( __METHOD__
.": no cache-varying cookies found\n" );
1289 * Add an HTTP header that will influence on the cache
1291 * @param $header String: header name
1292 * @param $option either an Array or null
1294 public function addVaryHeader( $header, $option = null ) {
1295 if ( !array_key_exists( $header, $this->mVaryHeader
) ) {
1296 $this->mVaryHeader
[$header] = $option;
1298 elseif( is_array( $option ) ) {
1299 if( is_array( $this->mVaryHeader
[$header] ) ) {
1300 $this->mVaryHeader
[$header] = array_merge( $this->mVaryHeader
[$header], $option );
1303 $this->mVaryHeader
[$header] = $option;
1306 $this->mVaryHeader
[$header] = array_unique( $this->mVaryHeader
[$header] );
1310 * Get a complete X-Vary-Options header
1314 public function getXVO() {
1315 $cvCookies = $this->getCacheVaryCookies();
1317 $cookiesOption = array();
1318 foreach ( $cvCookies as $cookieName ) {
1319 $cookiesOption[] = 'string-contains=' . $cookieName;
1321 $this->addVaryHeader( 'Cookie', $cookiesOption );
1324 foreach( $this->mVaryHeader
as $header => $option ) {
1325 $newheader = $header;
1326 if( is_array( $option ) )
1327 $newheader .= ';' . implode( ';', $option );
1328 $headers[] = $newheader;
1330 $xvo = 'X-Vary-Options: ' . implode( ',', $headers );
1336 * bug 21672: Add Accept-Language to Vary and XVO headers
1337 * if there's no 'variant' parameter existed in GET.
1340 * /w/index.php?title=Main_page should always be served; but
1341 * /w/index.php?title=Main_page&variant=zh-cn should never be served.
1343 function addAcceptLanguage() {
1344 global $wgRequest, $wgContLang;
1345 if( !$wgRequest->getCheck('variant') && $wgContLang->hasVariants() ) {
1346 $variants = $wgContLang->getVariants();
1347 $aloption = array();
1348 foreach ( $variants as $variant ) {
1349 if( $variant === $wgContLang->getCode() )
1352 $aloption[] = "string-contains=$variant";
1354 $this->addVaryHeader( 'Accept-Language', $aloption );
1359 * Send cache control HTTP headers
1361 public function sendCacheControl() {
1362 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
1364 $response = $wgRequest->response();
1365 if ($wgUseETag && $this->mETag
)
1366 $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
) {
1380 if( $wgUseSquid && session_id() == '' &&
1381 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 && !$this->haveCacheVaryCookies() )
1384 # We'll purge the proxy cache explicitly, but require end user agents
1385 # to revalidate against the proxy on each visit.
1386 # Surrogate-Control controls our Squid, Cache-Control downstream caches
1387 wfDebug( __METHOD__
. ": proxy caching with ESI; {$this->mLastModified} **\n", false );
1388 # start with a shorter timeout for initial testing
1389 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
1390 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
1391 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
1393 # We'll purge the proxy cache for anons explicitly, but require end user agents
1394 # to revalidate against the proxy on each visit.
1395 # IMPORTANT! The Squid needs to replace the Cache-Control header with
1396 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
1397 wfDebug( __METHOD__
. ": local proxy caching; {$this->mLastModified} **\n", false );
1398 # start with a shorter timeout for initial testing
1399 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
1400 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
1403 # We do want clients to cache if they can, but they *must* check for updates
1404 # on revisiting the page.
1405 wfDebug( __METHOD__
. ": private caching; {$this->mLastModified} **\n", false );
1406 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1407 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
1409 if($this->mLastModified
) {
1410 $response->header( "Last-Modified: {$this->mLastModified}" );
1413 wfDebug( __METHOD__
. ": no caching **\n", false );
1415 # In general, the absence of a last modified header should be enough to prevent
1416 # the client from using its cache. We send a few other things just to make sure.
1417 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1418 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
1419 $response->header( 'Pragma: no-cache' );
1424 * Get the message associed with the HTTP response code $code
1426 * @param $code Integer: status code
1427 * @return String or null: message or null if $code is not in the list of
1430 public static function getStatusMessage( $code ) {
1431 static $statusMessage = array(
1433 101 => 'Switching Protocols',
1434 102 => 'Processing',
1438 203 => 'Non-Authoritative Information',
1439 204 => 'No Content',
1440 205 => 'Reset Content',
1441 206 => 'Partial Content',
1442 207 => 'Multi-Status',
1443 300 => 'Multiple Choices',
1444 301 => 'Moved Permanently',
1447 304 => 'Not Modified',
1449 307 => 'Temporary Redirect',
1450 400 => 'Bad Request',
1451 401 => 'Unauthorized',
1452 402 => 'Payment Required',
1455 405 => 'Method Not Allowed',
1456 406 => 'Not Acceptable',
1457 407 => 'Proxy Authentication Required',
1458 408 => 'Request Timeout',
1461 411 => 'Length Required',
1462 412 => 'Precondition Failed',
1463 413 => 'Request Entity Too Large',
1464 414 => 'Request-URI Too Large',
1465 415 => 'Unsupported Media Type',
1466 416 => 'Request Range Not Satisfiable',
1467 417 => 'Expectation Failed',
1468 422 => 'Unprocessable Entity',
1470 424 => 'Failed Dependency',
1471 500 => 'Internal Server Error',
1472 501 => 'Not Implemented',
1473 502 => 'Bad Gateway',
1474 503 => 'Service Unavailable',
1475 504 => 'Gateway Timeout',
1476 505 => 'HTTP Version Not Supported',
1477 507 => 'Insufficient Storage'
1479 return isset( $statusMessage[$code] ) ?
$statusMessage[$code] : null;
1483 * Finally, all the text has been munged and accumulated into
1484 * the object, let's actually output it:
1486 public function output() {
1487 global $wgUser, $wgOutputEncoding, $wgRequest;
1488 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
1489 global $wgUseAjax, $wgAjaxWatch;
1490 global $wgEnableMWSuggest, $wgUniversalEditButton;
1493 if( $this->mDoNothing
){
1496 wfProfileIn( __METHOD__
);
1497 if ( $this->mRedirect
!= '' ) {
1498 # Standards require redirect URLs to be absolute
1499 $this->mRedirect
= wfExpandUrl( $this->mRedirect
);
1500 if( $this->mRedirectCode
== '301' ||
$this->mRedirectCode
== '303' ) {
1501 if( !$wgDebugRedirects ) {
1502 $message = self
::getStatusMessage( $this->mRedirectCode
);
1503 $wgRequest->response()->header( "HTTP/1.1 {$this->mRedirectCode} $message" );
1505 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
1507 $this->sendCacheControl();
1509 $wgRequest->response()->header( "Content-Type: text/html; charset=utf-8" );
1510 if( $wgDebugRedirects ) {
1511 $url = htmlspecialchars( $this->mRedirect
);
1512 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
1513 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
1514 print "</body>\n</html>\n";
1516 $wgRequest->response()->header( 'Location: ' . $this->mRedirect
);
1518 wfProfileOut( __METHOD__
);
1520 } elseif ( $this->mStatusCode
) {
1521 $message = self
::getStatusMessage( $this->mStatusCode
);
1523 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $message );
1526 $sk = $wgUser->getSkin();
1529 $this->addScriptFile( 'ajax.js' );
1531 wfRunHooks( 'AjaxAddScript', array( &$this ) );
1533 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
1534 $this->addScriptFile( 'ajaxwatch.js' );
1537 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
1538 $this->addScriptFile( 'mwsuggest.js' );
1542 if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
1543 $this->addScriptFile( 'rightclickedit.js' );
1546 if( $wgUniversalEditButton ) {
1547 if( isset( $wgArticle ) && $this->getTitle() && $this->getTitle()->quickUserCan( 'edit' )
1548 && ( $this->getTitle()->exists() ||
$this->getTitle()->quickUserCan( 'create' ) ) ) {
1549 // Original UniversalEditButton
1550 $msg = wfMsg('edit');
1551 $this->addLink( array(
1552 'rel' => 'alternate',
1553 'type' => 'application/x-wiki',
1555 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1557 // Alternate edit link
1558 $this->addLink( array(
1561 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1566 # Buffer output; final headers may depend on later processing
1569 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
1570 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
1572 if ($this->mArticleBodyOnly
) {
1573 $this->out($this->mBodytext
);
1575 // Hook that allows last minute changes to the output page, e.g.
1576 // adding of CSS or Javascript by extensions.
1577 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
1579 wfProfileIn( 'Output-skin' );
1580 $sk->outputPage( $this );
1581 wfProfileOut( 'Output-skin' );
1584 $this->sendCacheControl();
1586 wfProfileOut( __METHOD__
);
1590 * Actually output something with print(). Performs an iconv to the
1591 * output encoding, if needed.
1593 * @param $ins String: the string to output
1595 public function out( $ins ) {
1596 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
1597 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
1600 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
1601 if ( false === $outs ) { $outs = $ins; }
1609 public static function setEncodings() {
1610 global $wgInputEncoding, $wgOutputEncoding;
1613 $wgInputEncoding = strtolower( $wgInputEncoding );
1615 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
1616 $wgOutputEncoding = strtolower( $wgOutputEncoding );
1619 $wgOutputEncoding = $wgInputEncoding;
1623 * @deprecated use wfReportTime() instead.
1627 public function reportTime() {
1628 wfDeprecated( __METHOD__
);
1629 $time = wfReportTime();
1634 * Produce a "user is blocked" page.
1636 * @param $return Boolean: whether to have a "return to $wgTitle" message or not.
1639 function blockedPage( $return = true ) {
1640 global $wgUser, $wgContLang, $wgLang;
1642 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
1643 $this->setRobotPolicy( 'noindex,nofollow' );
1644 $this->setArticleRelated( false );
1646 $name = User
::whoIs( $wgUser->blockedBy() );
1647 $reason = $wgUser->blockedFor();
1648 if( $reason == '' ) {
1649 $reason = wfMsg( 'blockednoreason' );
1651 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW
, $wgUser->mBlock
->mTimestamp
), true );
1654 $link = '[[' . $wgContLang->getNsText( NS_USER
) . ":{$name}|{$name}]]";
1656 $blockid = $wgUser->mBlock
->mId
;
1658 $blockExpiry = $wgUser->mBlock
->mExpiry
;
1659 if ( $blockExpiry == 'infinity' ) {
1660 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
1661 // Search for localization in 'ipboptions'
1662 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1663 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
1664 if ( strpos( $option, ":" ) === false )
1666 list( $show, $value ) = explode( ":", $option );
1667 if ( $value == 'infinite' ||
$value == 'indefinite' ) {
1668 $blockExpiry = $show;
1673 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW
, $blockExpiry ), true );
1676 if ( $wgUser->mBlock
->mAuto
) {
1677 $msg = 'autoblockedtext';
1679 $msg = 'blockedtext';
1682 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
1683 * This could be a username, an ip range, or a single ip. */
1684 $intended = $wgUser->mBlock
->mAddress
;
1686 $this->addWikiMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
1688 # Don't auto-return to special pages
1690 $return = $this->getTitle()->getNamespace() > -1 ?
$this->getTitle() : null;
1691 $this->returnToMain( null, $return );
1696 * Output a standard error page
1698 * @param $title String: message key for page title
1699 * @param $msg String: message key for page text
1700 * @param $params Array: message parameters
1702 public function showErrorPage( $title, $msg, $params = array() ) {
1703 if ( $this->getTitle() ) {
1704 $this->mDebugtext
.= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n";
1706 $this->setPageTitle( wfMsg( $title ) );
1707 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1708 $this->setRobotPolicy( 'noindex,nofollow' );
1709 $this->setArticleRelated( false );
1710 $this->enableClientCache( false );
1711 $this->mRedirect
= '';
1712 $this->mBodytext
= '';
1714 array_unshift( $params, 'parse' );
1715 array_unshift( $params, $msg );
1716 $this->addHTML( call_user_func_array( 'wfMsgExt', $params ) );
1718 $this->returnToMain();
1722 * Output a standard permission error page
1724 * @param $errors Array: error message keys
1725 * @param $action String: action that was denied or null if unknown
1727 public function showPermissionsErrorPage( $errors, $action = null ) {
1728 $this->mDebugtext
.= 'Original title: ' .
1729 $this->getTitle()->getPrefixedText() . "\n";
1730 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
1731 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
1732 $this->setRobotPolicy( 'noindex,nofollow' );
1733 $this->setArticleRelated( false );
1734 $this->enableClientCache( false );
1735 $this->mRedirect
= '';
1736 $this->mBodytext
= '';
1737 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
1741 * Display an error page indicating that a given version of MediaWiki is
1742 * required to use it
1744 * @param $version Mixed: the version of MediaWiki needed to use the page
1746 public function versionRequired( $version ) {
1747 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
1748 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
1749 $this->setRobotPolicy( 'noindex,nofollow' );
1750 $this->setArticleRelated( false );
1751 $this->mBodytext
= '';
1753 $this->addWikiMsg( 'versionrequiredtext', $version );
1754 $this->returnToMain();
1758 * Display an error page noting that a given permission bit is required.
1760 * @param $permission String: key required
1762 public function permissionRequired( $permission ) {
1765 $this->setPageTitle( wfMsg( 'badaccess' ) );
1766 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1767 $this->setRobotPolicy( 'noindex,nofollow' );
1768 $this->setArticleRelated( false );
1769 $this->mBodytext
= '';
1771 $groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
1772 User
::getGroupsWithPermission( $permission ) );
1774 $this->addWikiMsg( 'badaccess-groups',
1775 $wgLang->commaList( $groups ),
1778 $this->addWikiMsg( 'badaccess-group0' );
1780 $this->returnToMain();
1784 * @deprecated use permissionRequired()
1786 public function sysopRequired() {
1787 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
1791 * @deprecated use permissionRequired()
1793 public function developerRequired() {
1794 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
1798 * Produce the stock "please login to use the wiki" page
1800 public function loginToUse() {
1801 global $wgUser, $wgContLang;
1803 if( $wgUser->isLoggedIn() ) {
1804 $this->permissionRequired( 'read' );
1808 $skin = $wgUser->getSkin();
1810 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1811 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1812 $this->setRobotPolicy( 'noindex,nofollow' );
1813 $this->setArticleFlag( false );
1815 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1816 $loginLink = $skin->link(
1818 wfMsgHtml( 'loginreqlink' ),
1820 array( 'returnto' => $this->getTitle()->getPrefixedText() ),
1821 array( 'known', 'noclasses' )
1823 $this->addHTML( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1824 $this->addHTML( "\n<!--" . $this->getTitle()->getPrefixedUrl() . "-->" );
1826 # Don't return to the main page if the user can't read it
1827 # otherwise we'll end up in a pointless loop
1828 $mainPage = Title
::newMainPage();
1829 if( $mainPage->userCanRead() )
1830 $this->returnToMain( null, $mainPage );
1834 * Format a list of error messages
1836 * @param $errors An array of arrays returned by Title::getUserPermissionsErrors
1837 * @param $action String: action that was denied or null if unknown
1838 * @return String: the wikitext error-messages, formatted into a list.
1840 public function formatPermissionsErrorMessage( $errors, $action = null ) {
1841 if ($action == null) {
1842 $text = wfMsgNoTrans( 'permissionserrorstext', count($errors)). "\n\n";
1845 $action_desc = wfMsgNoTrans( "action-$action" );
1846 $text = wfMsgNoTrans( 'permissionserrorstext-withaction', count($errors), $action_desc ) . "\n\n";
1849 if (count( $errors ) > 1) {
1850 $text .= '<ul class="permissions-errors">' . "\n";
1852 foreach( $errors as $error )
1855 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1860 $text .= "<div class=\"permissions-errors\">\n" . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . "\n</div>";
1867 * Display a page stating that the Wiki is in read-only mode,
1868 * and optionally show the source of the page that the user
1869 * was trying to edit. Should only be called (for this
1870 * purpose) after wfReadOnly() has returned true.
1872 * For historical reasons, this function is _also_ used to
1873 * show the error message when a user tries to edit a page
1874 * they are not allowed to edit. (Unless it's because they're
1875 * blocked, then we show blockedPage() instead.) In this
1876 * case, the second parameter should be set to true and a list
1877 * of reasons supplied as the third parameter.
1879 * @todo Needs to be split into multiple functions.
1881 * @param $source String: source code to show (or null).
1882 * @param $protected Boolean: is this a permissions error?
1883 * @param $reasons Array: list of reasons for this error, as returned by Title::getUserPermissionsErrors().
1884 * @param $action String: action that was denied or null if unknown
1886 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
1888 $skin = $wgUser->getSkin();
1890 $this->setRobotPolicy( 'noindex,nofollow' );
1891 $this->setArticleRelated( false );
1893 // If no reason is given, just supply a default "I can't let you do
1894 // that, Dave" message. Should only occur if called by legacy code.
1895 if ( $protected && empty($reasons) ) {
1896 $reasons[] = array( 'badaccess-group0' );
1899 if ( !empty($reasons) ) {
1900 // Permissions error
1902 $this->setPageTitle( wfMsg( 'viewsource' ) );
1911 array( 'known', 'noclasses' )
1916 $this->setPageTitle( wfMsg( 'badaccess' ) );
1918 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) );
1920 // Wiki is read only
1921 $this->setPageTitle( wfMsg( 'readonly' ) );
1922 $reason = wfReadOnlyReason();
1923 $this->wrapWikiMsg( "<div class='mw-readonly-error'>\n$1</div>", array( 'readonlytext', $reason ) );
1926 // Show source, if supplied
1927 if( is_string( $source ) ) {
1928 $this->addWikiMsg( 'viewsourcetext' );
1931 'id' => 'wpTextbox1',
1932 'name' => 'wpTextbox1',
1933 'cols' => $wgUser->getOption( 'cols' ),
1934 'rows' => $wgUser->getOption( 'rows' ),
1935 'readonly' => 'readonly'
1937 $this->addHTML( Html
::element( 'textarea', $params, $source ) );
1939 // Show templates used by this article
1940 $skin = $wgUser->getSkin();
1941 $article = new Article( $this->getTitle() );
1942 $this->addHTML( "<div class='templatesUsed'>
1943 {$skin->formatTemplates( $article->getUsedTemplates() )}
1948 # If the title doesn't exist, it's fairly pointless to print a return
1949 # link to it. After all, you just tried editing it and couldn't, so
1950 # what's there to do there?
1951 if( $this->getTitle()->exists() ) {
1952 $this->returnToMain( null, $this->getTitle() );
1957 public function errorpage( $title, $msg ) {
1958 wfDeprecated( __METHOD__
);
1959 throw new ErrorPageError( $title, $msg );
1963 public function databaseError( $fname, $sql, $error, $errno ) {
1964 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1968 public function fatalError( $message ) {
1969 wfDeprecated( __METHOD__
);
1970 throw new FatalError( $message );
1974 public function unexpectedValueError( $name, $val ) {
1975 wfDeprecated( __METHOD__
);
1976 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1980 public function fileCopyError( $old, $new ) {
1981 wfDeprecated( __METHOD__
);
1982 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1986 public function fileRenameError( $old, $new ) {
1987 wfDeprecated( __METHOD__
);
1988 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1992 public function fileDeleteError( $name ) {
1993 wfDeprecated( __METHOD__
);
1994 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1998 public function fileNotFoundError( $name ) {
1999 wfDeprecated( __METHOD__
);
2000 throw new FatalError( wfMsg( 'filenotfound', $name ) );
2003 public function showFatalError( $message ) {
2004 $this->setPageTitle( wfMsg( "internalerror" ) );
2005 $this->setRobotPolicy( "noindex,nofollow" );
2006 $this->setArticleRelated( false );
2007 $this->enableClientCache( false );
2008 $this->mRedirect
= '';
2009 $this->mBodytext
= $message;
2012 public function showUnexpectedValueError( $name, $val ) {
2013 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
2016 public function showFileCopyError( $old, $new ) {
2017 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
2020 public function showFileRenameError( $old, $new ) {
2021 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
2024 public function showFileDeleteError( $name ) {
2025 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
2028 public function showFileNotFoundError( $name ) {
2029 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
2033 * Add a "return to" link pointing to a specified title
2035 * @param $title Title to link
2036 * @param $query String: query string
2037 * @param $text String text of the link (input is not escaped)
2039 public function addReturnTo( $title, $query=array(), $text=null ) {
2041 $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullUrl() ) );
2044 $wgUser->getSkin()->link( $title, $text, array(), $query )
2046 $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
2050 * Add a "return to" link pointing to a specified title,
2051 * or the title indicated in the request, or else the main page
2053 * @param $unused No longer used
2054 * @param $returnto Title or String to return to
2055 * @param $returntoquery String: query string for the return to link
2057 public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
2060 if ( $returnto == null ) {
2061 $returnto = $wgRequest->getText( 'returnto' );
2064 if ( $returntoquery == null ) {
2065 $returntoquery = $wgRequest->getText( 'returntoquery' );
2068 if ( $returnto === '' ) {
2069 $returnto = Title
::newMainPage();
2072 if ( is_object( $returnto ) ) {
2073 $titleObj = $returnto;
2075 $titleObj = Title
::newFromText( $returnto );
2077 if ( !is_object( $titleObj ) ) {
2078 $titleObj = Title
::newMainPage();
2081 $this->addReturnTo( $titleObj, $returntoquery );
2085 * @param $sk Skin The given Skin
2086 * @param $includeStyle Unused (?)
2087 * @return String: The doctype, opening <html>, and head element.
2089 public function headElement( Skin
$sk, $includeStyle = true ) {
2090 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
2091 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
2092 global $wgContLang, $wgUseTrackbacks, $wgStyleVersion, $wgHtml5, $wgWellFormedXml;
2093 global $wgUser, $wgRequest, $wgLang;
2095 if ( $sk->commonPrintStylesheet() ) {
2096 $this->addStyle( 'common/wikiprintable.css', 'print' );
2098 $sk->setupUserCss( $this );
2102 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
2103 $ret .= "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
2106 if ( $this->getHTMLTitle() == '' ) {
2107 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ) );
2110 $dir = $wgContLang->getDir();
2112 $htmlAttribs = array( 'lang' => $wgContLanguageCode, 'dir' => $dir );
2114 if ( $wgWellFormedXml ) {
2115 # Unknown elements and attributes are okay in XML, but unknown
2116 # named entities are well-formedness errors and will break XML
2117 # parsers. Thus we need a doctype that gives us appropriate
2118 # entity definitions. The HTML5 spec permits four legacy
2119 # doctypes as obsolete but conforming, so let's pick one of
2120 # those, although it makes our pages look like XHTML1 Strict.
2121 # Isn't compatibility great?
2122 $ret .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
2125 $ret .= "<!doctype html>\n";
2127 if ( $wgHtml5Version ) {
2128 $htmlAttribs['version'] = $wgHtml5Version;
2131 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
2132 $htmlAttribs['xmlns'] = $wgXhtmlDefaultNamespace;
2133 foreach ( $wgXhtmlNamespaces as $tag => $ns ) {
2134 $htmlAttribs["xmlns:$tag"] = $ns;
2136 $this->addMeta( 'http:Content-Type', "$wgMimeType; charset=$wgOutputEncoding" );
2138 $ret .= Html
::openElement( 'html', $htmlAttribs ) . "\n";
2140 $openHead = Html
::openElement( 'head' );
2142 # Don't bother with the newline if $head == ''
2143 $ret .= "$openHead\n";
2145 $ret .= "<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
2148 # More succinct than <meta http-equiv=Content-Type>, has the
2150 $ret .= Html
::element( 'meta', array( 'charset' => $wgOutputEncoding ) ) . "\n";
2153 $ret .= implode( "\n", array(
2154 $this->getHeadLinks(),
2155 $this->buildCssLinks(),
2156 $this->getHeadScripts( $sk ),
2157 $this->getHeadItems(),
2159 if ( $sk->usercss
) {
2160 $ret .= Html
::inlineStyle( $sk->usercss
);
2163 if ( $wgUseTrackbacks && $this->isArticleRelated() ) {
2164 $ret .= $this->getTitle()->trackbackRDF();
2167 $closeHead = Html
::closeElement( 'head' );
2169 $ret .= "$closeHead\n";
2172 $bodyAttrs = array();
2174 # Crazy edit-on-double-click stuff
2175 $action = $wgRequest->getVal( 'action', 'view' );
2177 if ( $this->getTitle()->getNamespace() != NS_SPECIAL
2178 && !in_array( $action, array( 'edit', 'submit' ) )
2179 && $wgUser->getOption( 'editondblclick' ) ) {
2180 $bodyAttrs['ondblclick'] = "document.location = '" . Xml
::escapeJsString( $this->getTitle()->getEditURL() ) . "'";
2184 $bodyAttrs['class'] = "mediawiki $dir";
2186 if ( $wgLang->capitalizeAllNouns() ) {
2187 # A <body> class is probably not the best way to do this . . .
2188 $bodyAttrs['class'] .= ' capitalize-all-nouns';
2190 $bodyAttrs['class'] .= ' ns-' . $this->getTitle()->getNamespace();
2191 if ( $this->getTitle()->getNamespace() == NS_SPECIAL
) {
2192 $bodyAttrs['class'] .= ' ns-special';
2193 } elseif ( $this->getTitle()->isTalkPage() ) {
2194 $bodyAttrs['class'] .= ' ns-talk';
2196 $bodyAttrs['class'] .= ' ns-subject';
2198 $bodyAttrs['class'] .= ' ' . Sanitizer
::escapeClass( 'page-' . $this->getTitle()->getPrefixedText() );
2199 $bodyAttrs['class'] .= ' skin-' . Sanitizer
::escapeClass( $wgUser->getSkin()->getSkinName() );
2201 $ret .= Html
::openElement( 'body', $bodyAttrs ) . "\n";
2207 * Gets the global variables and mScripts; also adds userjs to the end if
2210 * @param $sk Skin object to use
2211 * @return String: HTML fragment
2213 function getHeadScripts( Skin
$sk ) {
2214 global $wgUser, $wgRequest, $wgJsMimeType, $wgUseSiteJs;
2215 global $wgStylePath, $wgStyleVersion;
2217 $scripts = Skin
::makeGlobalVariablesScript( $sk->getSkinName() );
2218 $scripts .= Html
::linkedScript( "{$wgStylePath}/common/wikibits.js?$wgStyleVersion" );
2220 //add site JS if enabled:
2221 if( $wgUseSiteJs ) {
2222 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
2223 $this->addScriptFile( Skin
::makeUrl( '-',
2224 "action=raw$jsCache&gen=js&useskin=" .
2225 urlencode( $sk->getSkinName() )
2230 //add user js if enabled:
2231 if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
2232 $action = $wgRequest->getVal( 'action', 'view' );
2233 if( $this->mTitle
&& $this->mTitle
->isJsSubpage() and $sk->userCanPreview( $action ) ) {
2234 # XXX: additional security check/prompt?
2235 $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
2237 $userpage = $wgUser->getUserPage();
2238 $names = array( 'common', $sk->getSkinName() );
2239 foreach( $names as $name ) {
2240 $scriptpage = Title
::makeTitleSafe(
2242 $userpage->getDBkey() . '/' . $name . '.js'
2244 if ( $scriptpage && $scriptpage->exists() ) {
2245 $userjs = $scriptpage->getLocalURL( 'action=raw&ctype=' . $wgJsMimeType );
2246 $this->addScriptFile( $userjs );
2252 $scripts .= "\n" . $this->mScripts
;
2257 * Add default \<meta\> tags
2259 protected function addDefaultMeta() {
2260 global $wgVersion, $wgHtml5;
2262 static $called = false;
2264 # Don't run this twice
2270 $this->addMeta( 'http:Content-Style-Type', 'text/css' ); //bug 15835
2272 $this->addMeta( 'generator', "MediaWiki $wgVersion" );
2274 $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
2275 if( $p !== 'index,follow' ) {
2276 // http://www.robotstxt.org/wc/meta-user.html
2277 // Only show if it's different from the default robots policy
2278 $this->addMeta( 'robots', $p );
2281 if ( count( $this->mKeywords
) > 0 ) {
2283 "/<.*?" . ">/" => '',
2286 $this->addMeta( 'keywords', preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
) ) );
2291 * @return string HTML tag links to be put in the header.
2293 public function getHeadLinks() {
2294 global $wgRequest, $wgFeed;
2296 // Ideally this should happen earlier, somewhere. :P
2297 $this->addDefaultMeta();
2301 foreach ( $this->mMetatags
as $tag ) {
2302 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
2304 $tag[0] = substr( $tag[0], 5 );
2308 $tags[] = Html
::element( 'meta',
2311 'content' => $tag[1] ) );
2313 foreach ( $this->mLinktags
as $tag ) {
2314 $tags[] = Html
::element( 'link', $tag );
2318 foreach( $this->getSyndicationLinks() as $format => $link ) {
2319 # Use the page name for the title (accessed through $wgTitle since
2320 # there's no other way). In principle, this could lead to issues
2321 # with having the same name for different feeds corresponding to
2322 # the same page, but we can't avoid that at this low a level.
2324 $tags[] = $this->feedLink(
2327 # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
2328 wfMsg( "page-{$format}-feed", $this->getTitle()->getPrefixedText() ) );
2331 # Recent changes feed should appear on every page (except recentchanges,
2332 # that would be redundant). Put it after the per-page feed to avoid
2333 # changing existing behavior. It's still available, probably via a
2334 # menu in your browser. Some sites might have a different feed they'd
2335 # like to promote instead of the RC feed (maybe like a "Recent New Articles"
2336 # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined.
2337 # If so, use it instead.
2339 global $wgOverrideSiteFeed, $wgSitename, $wgAdvertisedFeedTypes;
2340 $rctitle = SpecialPage
::getTitleFor( 'Recentchanges' );
2342 if ( $wgOverrideSiteFeed ) {
2343 foreach ( $wgOverrideSiteFeed as $type => $feedUrl ) {
2344 $tags[] = $this->feedLink (
2346 htmlspecialchars( $feedUrl ),
2347 wfMsg( "site-{$type}-feed", $wgSitename ) );
2349 } elseif ( $this->getTitle()->getPrefixedText() != $rctitle->getPrefixedText() ) {
2350 foreach ( $wgAdvertisedFeedTypes as $format ) {
2351 $tags[] = $this->feedLink(
2353 $rctitle->getLocalURL( "feed={$format}" ),
2354 wfMsg( "site-{$format}-feed", $wgSitename ) ); # For grep: 'site-rss-feed', 'site-atom-feed'.
2359 return implode( "\n", $tags );
2363 * Generate a <link rel/> for a feed.
2365 * @param $type String: feed type
2366 * @param $url String: URL to the feed
2367 * @param $text String: value of the "title" attribute
2368 * @return String: HTML fragment
2370 private function feedLink( $type, $url, $text ) {
2371 return Html
::element( 'link', array(
2372 'rel' => 'alternate',
2373 'type' => "application/$type+xml",
2379 * Add a local or specified stylesheet, with the given media options.
2380 * Meant primarily for internal use...
2382 * @param $style String: URL to the file
2383 * @param $media String: to specify a media type, 'screen', 'printable', 'handheld' or any.
2384 * @param $condition String: for IE conditional comments, specifying an IE version
2385 * @param $dir String: set to 'rtl' or 'ltr' for direction-specific sheets
2387 public function addStyle( $style, $media='', $condition='', $dir='' ) {
2389 // Even though we expect the media type to be lowercase, but here we
2390 // force it to lowercase to be safe.
2392 $options['media'] = $media;
2394 $options['condition'] = $condition;
2396 $options['dir'] = $dir;
2397 $this->styles
[$style] = $options;
2401 * Adds inline CSS styles
2402 * @param $style_css Mixed: inline CSS
2404 public function addInlineStyle( $style_css ){
2405 $this->mScripts
.= Html
::inlineStyle( $style_css );
2409 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
2410 * These will be applied to various media & IE conditionals.
2412 public function buildCssLinks() {
2414 foreach( $this->styles
as $file => $options ) {
2415 $link = $this->styleLink( $file, $options );
2420 return implode( "\n", $links );
2424 * Generate \<link\> tags for stylesheets
2426 * @param $style String: URL to the file
2427 * @param $options Array: option, can contain 'condition', 'dir', 'media'
2429 * @return String: HTML fragment
2431 protected function styleLink( $style, $options ) {
2434 if( isset( $options['dir'] ) ) {
2436 $siteDir = $wgContLang->getDir();
2437 if( $siteDir != $options['dir'] )
2441 if( isset( $options['media'] ) ) {
2442 $media = $this->transformCssMedia( $options['media'] );
2443 if( is_null( $media ) ) {
2450 if( substr( $style, 0, 1 ) == '/' ||
2451 substr( $style, 0, 5 ) == 'http:' ||
2452 substr( $style, 0, 6 ) == 'https:' ) {
2455 global $wgStylePath, $wgStyleVersion;
2456 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
2459 $link = Html
::linkedStyle( $url, $media );
2461 if( isset( $options['condition'] ) ) {
2462 $condition = htmlspecialchars( $options['condition'] );
2463 $link = "<!--[if $condition]>$link<![endif]-->";
2469 * Transform "media" attribute based on request parameters
2471 * @param $media String: current value of the "media" attribute
2472 * @return String: modified value of the "media" attribute
2474 function transformCssMedia( $media ) {
2475 global $wgRequest, $wgHandheldForIPhone;
2477 // Switch in on-screen display for media testing
2479 'printable' => 'print',
2480 'handheld' => 'handheld',
2482 foreach( $switches as $switch => $targetMedia ) {
2483 if( $wgRequest->getBool( $switch ) ) {
2484 if( $media == $targetMedia ) {
2486 } elseif( $media == 'screen' ) {
2492 // Expand longer media queries as iPhone doesn't grok 'handheld'
2493 if( $wgHandheldForIPhone ) {
2494 $mediaAliases = array(
2495 'screen' => 'screen and (min-device-width: 481px)',
2496 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
2499 if( isset( $mediaAliases[$media] ) ) {
2500 $media = $mediaAliases[$media];
2508 * Turn off regular page output and return an error reponse
2509 * for when rate limiting has triggered.
2511 public function rateLimited() {
2512 $this->setPageTitle(wfMsg('actionthrottled'));
2513 $this->setRobotPolicy( 'noindex,follow' );
2514 $this->setArticleRelated( false );
2515 $this->enableClientCache( false );
2516 $this->mRedirect
= '';
2518 $this->setStatusCode(503);
2519 $this->addWikiMsg( 'actionthrottledtext' );
2521 $this->returnToMain( null, $this->getTitle() );
2525 * Show a warning about slave lag
2527 * If the lag is higher than $wgSlaveLagCritical seconds,
2528 * then the warning is a bit more obvious. If the lag is
2529 * lower than $wgSlaveLagWarning, then no warning is shown.
2531 * @param $lag Integer: slave lag
2533 public function showLagWarning( $lag ) {
2534 global $wgSlaveLagWarning, $wgSlaveLagCritical, $wgLang;
2535 if( $lag >= $wgSlaveLagWarning ) {
2536 $message = $lag < $wgSlaveLagCritical
2539 $wrap = Html
::rawElement( 'div', array( 'class' => "mw-{$message}" ), "\n$1\n" );
2540 $this->wrapWikiMsg( "$wrap\n", array( $message, $wgLang->formatNum( $lag ) ) );
2545 * Add a wikitext-formatted message to the output.
2546 * This is equivalent to:
2548 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
2550 public function addWikiMsg( /*...*/ ) {
2551 $args = func_get_args();
2552 $name = array_shift( $args );
2553 $this->addWikiMsgArray( $name, $args );
2557 * Add a wikitext-formatted message to the output.
2558 * Like addWikiMsg() except the parameters are taken as an array
2559 * instead of a variable argument list.
2561 * $options is passed through to wfMsgExt(), see that function for details.
2563 public function addWikiMsgArray( $name, $args, $options = array() ) {
2564 $options[] = 'parse';
2565 $text = wfMsgExt( $name, $options, $args );
2566 $this->addHTML( $text );
2570 * This function takes a number of message/argument specifications, wraps them in
2571 * some overall structure, and then parses the result and adds it to the output.
2573 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
2574 * on. The subsequent arguments may either be strings, in which case they are the
2575 * message names, or arrays, in which case the first element is the message name,
2576 * and subsequent elements are the parameters to that message.
2578 * The special named parameter 'options' in a message specification array is passed
2579 * through to the $options parameter of wfMsgExt().
2581 * Don't use this for messages that are not in users interface language.
2585 * $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>", 'some-error' );
2589 * $wgOut->addWikiText( "<div class='error'>\n" . wfMsgNoTrans( 'some-error' ) . "</div>" );
2591 * The newline after opening div is needed in some wikitext. See bug 19226.
2593 public function wrapWikiMsg( $wrap /*, ...*/ ) {
2594 $msgSpecs = func_get_args();
2595 array_shift( $msgSpecs );
2596 $msgSpecs = array_values( $msgSpecs );
2598 foreach ( $msgSpecs as $n => $spec ) {
2600 if ( is_array( $spec ) ) {
2602 $name = array_shift( $args );
2603 if ( isset( $args['options'] ) ) {
2604 $options = $args['options'];
2605 unset( $args['options'] );
2611 $s = str_replace( '$' . ( $n +
1 ), wfMsgExt( $name, $options, $args ), $s );
2613 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );
2617 * Include jQuery core. Use this to avoid loading it multiple times
2618 * before we get a usable script loader.
2620 * @param $modules Array: list of jQuery modules which should be loaded
2621 * @return Array: the list of modules which were not loaded.
2624 public function includeJQuery( $modules = array() ) {
2625 global $wgStylePath, $wgStyleVersion;
2627 $supportedModules = array( /** TODO: add things here */ );
2628 $unsupported = array_diff( $modules, $supportedModules );
2630 $url = "$wgStylePath/common/jquery.min.js?$wgStyleVersion";
2631 if ( !$this->mJQueryDone
) {
2632 $this->mJQueryDone
= true;
2633 $this->mScripts
= Html
::linkedScript( $url ) . "\n" . $this->mScripts
;
2635 return $unsupported;