Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[lhc/web/wiklou.git] / includes / OutputPage.php
index e24cc2f..8a97061 100644 (file)
@@ -223,7 +223,7 @@ class OutputPage extends ContextSource {
         * Instead a new RequestContext should be created and it will implicitly create
         * a OutputPage tied to that context.
         */
-       function __construct( RequestContext $context = null ) {
+       function __construct( IContextSource $context = null ) {
                if ( $context === null ) {
                        # Extensions should use `new RequestContext` instead of `new OutputPage` now.
                        wfDeprecated( __METHOD__ );
@@ -1301,7 +1301,7 @@ class OutputPage extends ContextSource {
         * @return Array (dbKey => array('time' => MW timestamp or null, 'sha1' => sha1 or ''))
         * @since 1.18
         */
-       public function getImageTimeKeys() {
+       public function getFileSearchOptions() {
                return $this->mImageTimeKeys;
        }
 
@@ -1415,7 +1415,7 @@ class OutputPage extends ContextSource {
                        }
                }
                // File versioning...
-               foreach ( (array)$parserOutput->getImageTimeKeys() as $dbk => $data ) {
+               foreach ( (array)$parserOutput->getFileSearchOptions() as $dbk => $data ) {
                        $this->mImageTimeKeys[$dbk] = $data;
                }
 
@@ -1654,12 +1654,12 @@ class OutputPage extends ContextSource {
         *   /w/index.php?title=Main_page&variant=zh-cn should never be served.
         */
        function addAcceptLanguage() {
-               $lang = $this->getTitle()->getPageLanguage();
-               if( !$this->getRequest()->getCheck( 'variant' ) && $lang->hasVariants() ) {
-                       $variants = $lang->getVariants();
+               global $wgContLang;
+               if( !$this->getRequest()->getCheck( 'variant' ) && $wgContLang->hasVariants() ) {
+                       $variants = $wgContLang->getVariants();
                        $aloption = array();
                        foreach ( $variants as $variant ) {
-                               if( $variant === $lang->getCode() ) {
+                               if( $variant === $wgContLang->getCode() ) {
                                        continue;
                                } else {
                                        $aloption[] = 'string-contains=' . $variant;
@@ -2362,21 +2362,6 @@ $distantTemplates
        protected function makeResourceLoaderLink( $modules, $only, $useESI = false, array $extraQuery = array() ) {
                global $wgLoadScript, $wgResourceLoaderUseESI,
                        $wgResourceLoaderInlinePrivateModules;
-               $baseQuery = array(
-                       'lang' => $this->getContext()->getLang()->getCode(),
-                       'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false',
-                       'skin' => $this->getSkin()->getSkinName(),
-               ) + $extraQuery;
-               if ( $only !== ResourceLoaderModule::TYPE_COMBINED ) {
-                       $baseQuery['only'] = $only;
-               }
-               // Propagate printable and handheld parameters if present
-               if ( $this->isPrintable() ) {
-                       $baseQuery['printable'] = 1;
-               }
-               if ( $this->getRequest()->getBool( 'handheld' ) ) {
-                       $baseQuery['handheld'] = 1;
-               }
 
                if ( !count( $modules ) ) {
                        return '';
@@ -2422,14 +2407,26 @@ $distantTemplates
 
                $links = '';
                foreach ( $groups as $group => $modules ) {
-                       $query = $baseQuery;
                        // Special handling for user-specific groups
+                       $user = null;
                        if ( ( $group === 'user' || $group === 'private' ) && $this->getUser()->isLoggedIn() ) {
-                               $query['user'] = $this->getUser()->getName();
+                               $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
+                       $query = ResourceLoader::makeLoaderQuery(
+                               array(), // modules; not determined yet
+                               $this->getContext()->getLang()->getCode(),
+                               $this->getSkin()->getSkinName(),
+                               $user,
+                               null, // version; not determined yet
+                               ResourceLoader::inDebugMode(),
+                               $only === ResourceLoaderModule::TYPE_COMBINED ? null : $only,
+                               $this->isPrintable(),
+                               $this->getRequest()->getBool( 'handheld' ),
+                               $extraQuery
+                       );
                        $context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
                        // Drop modules that know they're empty
                        foreach ( $modules as $key => $module ) {
@@ -2442,8 +2439,6 @@ $distantTemplates
                                continue;
                        }
 
-                       $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 ) {
@@ -2465,6 +2460,7 @@ $distantTemplates
                        // timestamp of these user-changable modules so we can ensure cache misses on change
                        // This should NOT be done for the site group (bug 27564) because anons get that too
                        // and we shouldn't be putting timestamps in Squid-cached HTML
+                       $version = null;
                        if ( $group === 'user' ) {
                                // Get the maximum timestamp
                                $timestamp = 1;
@@ -2472,15 +2468,21 @@ $distantTemplates
                                        $timestamp = max( $timestamp, $module->getModifiedTime( $context ) );
                                }
                                // Add a version parameter so cache will break when things change
-                               $query['version'] = wfTimestamp( TS_ISO_8601_BASIC, $timestamp );
+                               $version = wfTimestamp( TS_ISO_8601_BASIC, $timestamp );
                        }
-                       // Make queries uniform in order
-                       ksort( $query );
-
-                       $url = wfAppendQuery( $wgLoadScript, $query );
-                       // Prevent the IE6 extension check from being triggered (bug 28840)
-                       // by appending a character that's invalid in Windows extensions ('*')
-                       $url .= '&*';
+                       
+                       $url = ResourceLoader::makeLoaderURL(
+                               array_keys( $modules ),
+                               $this->getContext()->getLang()->getCode(),
+                               $this->getSkin()->getSkinName(),
+                               $user,
+                               $version,
+                               ResourceLoader::inDebugMode(),
+                               $only === ResourceLoaderModule::TYPE_COMBINED ? null : $only,
+                               $this->isPrintable(),
+                               $this->getRequest()->getBool( 'handheld' ),
+                               $extraQuery
+                       );
                        if ( $useESI && $wgResourceLoaderUseESI ) {
                                $esi = Xml::element( 'esi:include', array( 'src' => $url ) );
                                if ( $only == ResourceLoaderModule::TYPE_STYLES ) {
@@ -2612,7 +2614,7 @@ $distantTemplates
         * have to be purged on configuration changes.
         */
        protected function getJSVars() {
-               global $wgUseAjax, $wgEnableMWSuggest;
+               global $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
 
                $title = $this->getTitle();
                $ns = $title->getNamespace();
@@ -2638,9 +2640,8 @@ $distantTemplates
                        'wgCategories' => $this->getCategories(),
                        'wgBreakFrames' => $this->getFrameOptions() == 'DENY',
                );
-               $lang = $this->getTitle()->getPageLanguage();
-               if ( $lang->hasVariants() ) {
-                       $vars['wgUserVariant'] = $lang->getPreferredVariant();
+               if ( $wgContLang->hasVariants() ) {
+                       $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
                }
                foreach ( $title->getRestrictionTypes() as $type ) {
                        $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
@@ -2692,7 +2693,7 @@ $distantTemplates
                global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI,
                        $wgSitename, $wgVersion, $wgHtml5, $wgMimeType,
                        $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes,
-                       $wgDisableLangConversion, $wgCanonicalLanguageLinks,
+                       $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang,
                        $wgRightsPage, $wgRightsUrl;
 
                $tags = array();
@@ -2818,16 +2819,14 @@ $distantTemplates
                        ) );
                }
 
-               $lang = $this->getTitle()->getPageLanguage();
-
                # Language variants
                if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
-                       && $lang->hasVariants() ) {
+                       && $wgContLang->hasVariants() ) {
 
-                       $urlvar = $lang->getURLVariant();
+                       $urlvar = $wgContLang->getURLVariant();
 
                        if ( !$urlvar ) {
-                               $variants = $lang->getVariants();
+                               $variants = $wgContLang->getVariants();
                                foreach ( $variants as $_v ) {
                                        $tags[] = Html::element( 'link', array(
                                                'rel' => 'alternate',