Use DB domain in JobQueueGroup and make WikiMap domain ID methods stricter
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index 052c5b3..2fc81e3 100644 (file)
@@ -37,7 +37,7 @@ use Wikimedia\WrappedString;
  */
 class ResourceLoader implements LoggerAwareInterface {
        /** @var int */
-       protected static $filterCacheVersion = 8;
+       const CACHE_VERSION = 8;
 
        /** @var bool */
        protected static $debugMode = null;
@@ -199,7 +199,8 @@ class ResourceLoader implements LoggerAwareInterface {
                        'resourceloader',
                        'filter',
                        $filter,
-                       self::$filterCacheVersion, md5( $data )
+                       self::CACHE_VERSION,
+                       md5( $data )
                );
 
                $result = $cache->get( $key );
@@ -549,11 +550,7 @@ class ResourceLoader implements LoggerAwareInterface {
                                $object->setConfig( $this->getConfig() );
                                $object->setLogger( $this->logger );
                        } else {
-                               if ( !isset( $info['class'] ) ) {
-                                       $class = ResourceLoaderFileModule::class;
-                               } else {
-                                       $class = $info['class'];
-                               }
+                               $class = $info['class'] ?? ResourceLoaderFileModule::class;
                                /** @var ResourceLoaderModule $object */
                                $object = new $class( $info );
                                $object->setConfig( $this->getConfig() );
@@ -1363,7 +1360,7 @@ MESSAGE;
         * - new XmlJsCode( '{}' )
         * - new stdClass() // (object) []
         *
-        * @param Array $array
+        * @param array $array
         */
        private static function trimArray( array &$array ) {
                $i = count( $array );
@@ -1523,13 +1520,21 @@ MESSAGE;
         *
         * @param array $configuration List of configuration values keyed by variable name
         * @return string JavaScript code
+        * @throws Exception
         */
        public static function makeConfigSetScript( array $configuration ) {
-               return Xml::encodeJsCall(
+               $js = Xml::encodeJsCall(
                        'mw.config.set',
                        [ $configuration ],
                        self::inDebugMode()
                );
+               if ( $js === false ) {
+                       throw new Exception(
+                               'JSON serialization of config data failed. ' .
+                               'This usually means the config data is not valid UTF-8.'
+                       );
+               }
+               return $js;
        }
 
        /**