Revert r87635, r87637, r87639, r87643 (MW_MIN_PHP_VERSION etc.): breaks HipHop support.
[lhc/web/wiklou.git] / includes / OutputPage.php
index 67a634d..6b079e6 100644 (file)
@@ -10,9 +10,9 @@ if ( !defined( 'MEDIAWIKI' ) ) {
  *
  * This class is used to prepare the final rendering. A skin is then
  * applied to the output parameters (links, javascript, html, categories ...).
- * 
+ *
  * Another class (fixme) handles sending the whole page to the client.
- * 
+ *
  * Some comments comes from a pairing session between Zak Greant and Ashar Voultoiz
  * in November 2010.
  *
@@ -1161,7 +1161,7 @@ class OutputPage {
        /**
         * Return whether user JavaScript is allowed for this page
         * @deprecated since 1.18 Load modules with ResourceLoader, and origin and
-        *     trustworthiness is identified and enforced automagically. 
+        *     trustworthiness is identified and enforced automagically.
         * @return Boolean
         */
        public function isUserJsAllowed() {
@@ -1672,11 +1672,11 @@ class OutputPage {
        }
 
        /**
-        * Set a flag which will cause an X-Frame-Options header appropriate for 
-        * edit pages to be sent. The header value is controlled by 
+        * Set a flag which will cause an X-Frame-Options header appropriate for
+        * edit pages to be sent. The header value is controlled by
         * $wgEditPageFrameOptions.
         *
-        * This is the default for special pages. If you display a CSRF-protected 
+        * This is the default for special pages. If you display a CSRF-protected
         * form on an ordinary view page, then you need to call this function.
         */
        public function preventClickjacking( $enable = true ) {
@@ -1693,8 +1693,8 @@ class OutputPage {
        }
 
        /**
-        * Get the X-Frame-Options header value (without the name part), or false 
-        * if there isn't one. This is used by Skin to determine whether to enable 
+        * Get the X-Frame-Options header value (without the name part), or false
+        * if there isn't one. This is used by Skin to determine whether to enable
         * JavaScript frame-breaking, for clients that don't support X-Frame-Options.
         */
        public function getFrameOptions() {
@@ -1838,7 +1838,6 @@ class OutputPage {
         * the object, let's actually output it:
         */
        public function output() {
-               global $wgOutputEncoding;
                global $wgLanguageCode, $wgDebugRedirects, $wgMimeType;
 
                if( $this->mDoNothing ) {
@@ -1882,7 +1881,7 @@ class OutputPage {
                # Buffer output; final headers may depend on later processing
                ob_start();
 
-               $response->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
+               $response->header( "Content-type: $wgMimeType; charset=UTF-8" );
                $response->header( 'Content-language: ' . $wgLanguageCode );
 
                // Prevent framing, if requested
@@ -1913,22 +1912,12 @@ class OutputPage {
        }
 
        /**
-        * Actually output something with print(). Performs an iconv to the
-        * output encoding, if needed.
+        * Actually output something with print().
         *
         * @param $ins String: the string to output
         */
        public function out( $ins ) {
-               global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
-               if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
-                       $outs = $ins;
-               } else {
-                       $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
-                       if ( false === $outs ) {
-                               $outs = $ins;
-                       }
-               }
-               print $outs;
+               print $ins;
        }
 
        /**
@@ -2158,16 +2147,7 @@ class OutputPage {
         * for when rate limiting has triggered.
         */
        public function rateLimited() {
-               $this->setPageTitle( wfMsg( 'actionthrottled' ) );
-               $this->setRobotPolicy( 'noindex,follow' );
-               $this->setArticleRelated( false );
-               $this->enableClientCache( false );
-               $this->mRedirect = '';
-               $this->clearHTML();
-               $this->setStatusCode( 503 );
-               $this->addWikiMsg( 'actionthrottledtext' );
-
-               $this->returnToMain( null, $this->getTitle() );
+               throw new ThrottledError;
        }
 
        /**
@@ -2378,6 +2358,7 @@ class OutputPage {
                if( $this->getUser()->getBoolOption( 'editsectiononrightclick' ) ) {
                        $this->addModules( 'mediawiki.action.view.rightClickEdit' );
                }
+               $this->addModules( 'mediawiki.action.view.tablesorting' );
        }
 
        /**
@@ -2390,7 +2371,7 @@ class OutputPage {
                        $this->mResourceLoader = new ResourceLoader();
                }
                return $this->mResourceLoader;
-       }               
+       }
 
        /**
         * TODO: Document
@@ -2405,7 +2386,6 @@ class OutputPage {
                        $wgResourceLoaderInlinePrivateModules;
                // Lazy-load ResourceLoader
                // TODO: Should this be a static function of ResourceLoader instead?
-               // TODO: Divide off modules starting with "user", and add the user parameter to them
                $baseQuery = array(
                        'lang' => $this->getContext()->getLang()->getCode(),
                        'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false',
@@ -2469,7 +2449,7 @@ class OutputPage {
                        if ( ( $group === 'user' || $group === 'private' ) && $this->getUser()->isLoggedIn() ) {
                                $query['user'] = $this->getUser()->getName();
                        }
-                       
+
                        // Create a fake request based on the one we are about to make so modules return
                        // correct timestamp and emptiness data
                        $context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
@@ -2483,9 +2463,9 @@ class OutputPage {
                        if ( $modules === array() ) {
                                continue;
                        }
-                       
-                       $query['modules'] = implode( '|', array_keys( $modules ) );
-                       
+
+                       $query['modules'] = ResourceLoader::makePackedModulesString( array_keys( $modules ) );
+
                        // Support inlining of private modules if configured as such
                        if ( $group === 'private' && $wgResourceLoaderInlinePrivateModules ) {
                                if ( $only == ResourceLoaderModule::TYPE_STYLES ) {
@@ -2554,14 +2534,14 @@ class OutputPage {
        function getHeadScripts( Skin $sk ) {
                // Startup - this will immediately load jquery and mediawiki modules
                $scripts = $this->makeResourceLoaderLink( $sk, 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true );
-               
+
                // Load config before anything else
                $scripts .= Html::inlineScript(
                        ResourceLoader::makeLoaderConditionalScript(
                                ResourceLoader::makeConfigSetScript( $this->getJSVars() )
                        )
                );
-               
+
                // Script and Messages "only" requests marked for top inclusion
                // Messages should go first
                $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleMessages( true, 'top' ), ResourceLoaderModule::TYPE_MESSAGES );
@@ -2581,14 +2561,14 @@ class OutputPage {
 
                return $scripts;
        }
-       
+
        /**
         * JS stuff to put at the bottom of the <body>: modules marked with position 'bottom',
         * legacy scripts ($this->mScripts), user preferences, site JS and user JS
         */
        function getBottomScripts( Skin $sk ) {
                global $wgUseSiteJs, $wgAllowUserJs;
-               
+
                // Script and Messages "only" requests marked for bottom inclusion
                // Messages should go first
                $scripts = $this->makeResourceLoaderLink( $sk, $this->getModuleMessages( true, 'bottom' ), ResourceLoaderModule::TYPE_MESSAGES );
@@ -2600,13 +2580,11 @@ class OutputPage {
                if ( $modules ) {
                        $scripts .= Html::inlineScript(
                                ResourceLoader::makeLoaderConditionalScript(
-                                       Xml::encodeJsCall( 'mw.loader.load', array( $modules ) ) .
-                                       // the go() call is unnecessary if we inserted top modules, but we don't know for sure that we did
-                                       Xml::encodeJsCall( 'mw.loader.go', array() )
+                                       Xml::encodeJsCall( 'mw.loader.load', array( $modules ) )
                                )
                        );
                }
-               
+
                // Legacy Scripts
                $scripts .= "\n" . $this->mScripts;
 
@@ -2633,13 +2611,13 @@ class OutputPage {
                        }
                }
                $scripts .= $this->makeResourceLoaderLink( $sk, $userScripts, ResourceLoaderModule::TYPE_SCRIPTS );
-               
+
                return $scripts;
        }
 
        /**
         * Get an array containing global JS variables
-        * 
+        *
         * Do not add things here which can be evaluated in
         * ResourceLoaderStartupScript - in other words, without state.
         * You will only be adding bloat to the page and causing page caches to
@@ -2671,6 +2649,7 @@ class OutputPage {
                        'wgUserGroups' => $this->getUser()->getEffectiveGroups(),
                        'wgCategories' => $this->getCategories(),
                        'wgBreakFrames' => $this->getFrameOptions() == 'DENY',
+                       'wgIsMainPage' => $title->isMainPage(),
                );
                if ( $wgContLang->hasVariants() ) {
                        $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
@@ -2681,10 +2660,10 @@ class OutputPage {
                if ( $wgUseAjax && $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
                        $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $this->getUser() );
                }
-               
+
                // Allow extensions to add their custom variables to the global JS variables
                wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
-               
+
                return $vars;
        }
 
@@ -2693,7 +2672,7 @@ class OutputPage {
         */
        public function getHeadLinks( Skin $sk, $addContentType = false ) {
                global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI,
-                       $wgSitename, $wgVersion, $wgHtml5, $wgMimeType, $wgOutputEncoding,
+                       $wgSitename, $wgVersion, $wgHtml5, $wgMimeType,
                        $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes,
                        $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf,
                        $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang,
@@ -2705,11 +2684,11 @@ class OutputPage {
                        if ( $wgHtml5 ) {
                                # More succinct than <meta http-equiv=Content-Type>, has the
                                # same effect
-                               $tags[] = Html::element( 'meta', array( 'charset' => $wgOutputEncoding ) );
+                               $tags[] = Html::element( 'meta', array( 'charset' => 'UTF-8' ) );
                        } else {
                                $tags[] = Html::element( 'meta', array(
                                        'http-equiv' => 'Content-Type',
-                                       'content' => "$wgMimeType; charset=$wgOutputEncoding"
+                                       'content' => "$wgMimeType; charset=UTF-8"
                                ) );
                                $tags[] = Html::element( 'meta', array(  // bug 15835
                                        'http-equiv' => 'Content-Style-Type',
@@ -3016,7 +2995,7 @@ class OutputPage {
                // Add marker tag to mark the place where the client-side loader should inject dynamic styles
                // We use a <meta> tag with a made-up name for this because that's valid HTML
                $ret .= Html::element( 'meta', array( 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ) ) . "\n";
-               
+
                // Add site, private and user styles
                // 'private' at present only contains user.options, so put that before 'user'
                // Any future private modules will likely have a similar user-specific character