Merge "mediawiki.language: Respect $wgTranslateNumerals in convertNumber()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 23 May 2015 15:15:54 +0000 (15:15 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 23 May 2015 15:15:54 +0000 (15:15 +0000)
1  2 
includes/resourceloader/ResourceLoaderStartUpModule.php

  
  class ResourceLoaderStartUpModule extends ResourceLoaderModule {
  
 -      /* Protected Members */
 -
 -      protected $modifiedTime = array();
 +      // Cache for getConfigSettings() as it's called by multiple methods
        protected $configVars = array();
        protected $targets = array( 'desktop', 'mobile' );
  
 -      /* Protected Methods */
 -
        /**
         * @param ResourceLoaderContext $context
         * @return array
@@@ -78,6 -82,7 +78,7 @@@
                        'wgServerName' => $conf->get( 'ServerName' ),
                        'wgUserLanguage' => $context->getLanguage(),
                        'wgContentLanguage' => $wgContLang->getCode(),
+                       'wgTranslateNumerals' => $conf->get( 'TranslateNumerals' ),
                        'wgVersion' => $conf->get( 'Version' ),
                        'wgEnableAPI' => $conf->get( 'EnableAPI' ),
                        'wgEnableWriteAPI' => $conf->get( 'EnableWriteAPI' ),
         * data send to the client.
         *
         * @param array &$registryData Modules keyed by name with properties:
 -       *  - number 'version'
 +       *  - string 'version'
         *  - array 'dependencies'
         *  - string|null 'group'
         *  - string 'source'
                                continue;
                        }
  
 -                      // Coerce module timestamp to UNIX timestamp.
 -                      // getModifiedTime() is supposed to return a UNIX timestamp, but custom implementations
 -                      // might forget. TODO: Maybe emit warning?
 -                      $moduleMtime = wfTimestamp( TS_UNIX, $module->getModifiedTime( $context ) );
 +                      $versionHash = $module->getVersionHash( $context );
 +                      if ( strlen( $versionHash ) !== 8 ) {
 +                              // Module implementation either broken or deviated from ResourceLoader::makeHash
 +                              // Asserted by tests/phpunit/structure/ResourcesTest.
 +                              $versionHash = ResourceLoader::makeHash( $versionHash );
 +                      }
  
                        $skipFunction = $module->getSkipFunction();
                        if ( $skipFunction !== null && !ResourceLoader::inDebugMode() ) {
                                );
                        }
  
 -                      $mtime = max(
 -                              $moduleMtime,
 -                              wfTimestamp( TS_UNIX, $this->getConfig()->get( 'CacheEpoch' ) )
 -                      );
 -
                        $registryData[$name] = array(
 -                              // Convert to numbers as wfTimestamp always returns a string, even for TS_UNIX
 -                              'version' => (int) $mtime,
 +                              'version' => $versionHash,
                                'dependencies' => $module->getDependencies(),
                                'group' => $module->getGroup(),
                                'source' => $module->getSource(),
                                continue;
                        }
  
 -                      // Call mw.loader.register(name, timestamp, dependencies, group, source, skip)
 +                      // Call mw.loader.register(name, version, dependencies, group, source, skip)
                        $registrations[] = array(
                                $name,
                                $data['version'],
                return $out;
        }
  
 -      /* Methods */
 -
        /**
         * @return bool
         */
         * @return string
         */
        public static function getStartupModulesUrl( ResourceLoaderContext $context ) {
 +              $rl = $context->getResourceLoader();
                $moduleNames = self::getStartupModules();
  
 -              // Get the latest version
 -              $loader = $context->getResourceLoader();
 -              $version = 1;
 -              foreach ( $moduleNames as $moduleName ) {
 -                      $version = max( $version,
 -                              $loader->getModule( $moduleName )->getModifiedTime( $context )
 -                      );
 -              }
 -
                $query = array(
                        'modules' => ResourceLoader::makePackedModulesString( $moduleNames ),
                        'only' => 'scripts',
                        'lang' => $context->getLanguage(),
                        'skin' => $context->getSkin(),
                        'debug' => $context->getDebug() ? 'true' : 'false',
 -                      'version' => wfTimestamp( TS_ISO_8601_BASIC, $version )
 +                      'version' => $rl->getCombinedVersion( $context, $moduleNames ),
                );
                // Ensure uniform query order
                ksort( $query );
        }
  
        /**
 +       * Get the definition summary for this module.
 +       *
         * @param ResourceLoaderContext $context
 -       * @return array|mixed
 +       * @return array
         */
 -      public function getModifiedTime( ResourceLoaderContext $context ) {
 +      public function getDefinitionSummary( ResourceLoaderContext $context ) {
                global $IP;
 +              $summary = parent::getDefinitionSummary( $context );
 +              $summary[] = array(
 +                      // Detect changes to variables exposed in mw.config (T30899).
 +                      'vars' => $this->getConfigSettings( $context ),
 +                      // Changes how getScript() creates mw.Map for mw.config
 +                      'wgLegacyJavaScriptGlobals' => $this->getConfig()->get( 'LegacyJavaScriptGlobals' ),
 +                      // Detect changes to the module registrations
 +                      'moduleHashes' => $this->getAllModuleHashes( $context ),
  
 -              $hash = $context->getHash();
 -              if ( isset( $this->modifiedTime[$hash] ) ) {
 -                      return $this->modifiedTime[$hash];
 -              }
 -
 -              // Call preloadModuleInfo() on ALL modules as we're about
 -              // to call getModifiedTime() on all of them
 -              $loader = $context->getResourceLoader();
 -              $loader->preloadModuleInfo( $loader->getModuleNames(), $context );
 -
 -              $time = max(
 -                      wfTimestamp( TS_UNIX, $this->getConfig()->get( 'CacheEpoch' ) ),
 -                      filemtime( "$IP/resources/src/startup.js" ),
 -                      $this->getHashMtime( $context )
 +                      'fileMtimes' => array(
 +                              filemtime( "$IP/resources/src/startup.js" ),
 +                      ),
                );
 -
 -              // ATTENTION!: Because of the line below, this is not going to cause
 -              // infinite recursion - think carefully before making changes to this
 -              // code!
 -              // Pre-populate modifiedTime with something because the loop over
 -              // all modules below includes the startup module (this module).
 -              $this->modifiedTime[$hash] = 1;
 -
 -              foreach ( $loader->getModuleNames() as $name ) {
 -                      $module = $loader->getModule( $name );
 -                      $time = max( $time, $module->getModifiedTime( $context ) );
 -              }
 -
 -              $this->modifiedTime[$hash] = $time;
 -              return $this->modifiedTime[$hash];
 +              return $summary;
        }
  
        /**
 -       * Hash of all dynamic data embedded in getScript().
 -       *
 -       * Detect changes to mw.config settings embedded in #getScript (bug 28899).
 +       * Helper method for getDefinitionSummary().
         *
         * @param ResourceLoaderContext $context
 -       * @return string Hash
 +       * @return string SHA-1
         */
 -      public function getModifiedHash( ResourceLoaderContext $context ) {
 -              $data = array(
 -                      'vars' => $this->getConfigSettings( $context ),
 -                      'wgLegacyJavaScriptGlobals' => $this->getConfig()->get( 'LegacyJavaScriptGlobals' ),
 -              );
 -
 -              return md5( serialize( $data ) );
 +      protected function getAllModuleHashes( ResourceLoaderContext $context ) {
 +              $rl = $context->getResourceLoader();
 +              // Preload for getCombinedVersion()
 +              $rl->preloadModuleInfo( $rl->getModuleNames(), $context );
 +
 +              // ATTENTION: Because of the line below, this is not going to cause infinite recursion.
 +              // Think carefully before making changes to this code!
 +              // Pre-populate versionHash with something because the loop over all modules below includes
 +              // the startup module (this module).
 +              // See ResourceLoaderModule::getVersionHash() for usage of this cache.
 +              $this->versionHash[ $context->getHash() ] = null;
 +
 +              return $rl->getCombinedVersion( $context, $rl->getModuleNames() );
        }
  
        /**