resourceloader: Audit use of JSON encoding and use json_encode directly
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderModule.php
index 609abb8..02d5802 100644 (file)
@@ -129,9 +129,8 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
         * @return bool
         */
        public function getFlip( $context ) {
-               global $wgContLang;
-
-               return $wgContLang->getDir() !== $context->getDirection();
+               return MediaWikiServices::getInstance()->getContentLanguage()->getDir() !==
+                       $context->getDirection();
        }
 
        /**
@@ -347,7 +346,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
         * Note: It is expected that $context will be made non-optional in the near
         * future.
         *
-        * @param ResourceLoaderContext $context
+        * @param ResourceLoaderContext|null $context
         * @return array List of module names as strings
         */
        public function getDependencies( ResourceLoaderContext $context = null ) {
@@ -417,7 +416,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
 
                        if ( !is_null( $deps ) ) {
                                $this->fileDeps[$vary] = self::expandRelativePaths(
-                                       (array)FormatJson::decode( $deps, true )
+                                       (array)json_decode( $deps, true )
                                );
                        } else {
                                $this->fileDeps[$vary] = [];
@@ -477,7 +476,9 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
                                        return; // T124649; avoid write slams
                                }
 
-                               $deps = FormatJson::encode( $localPaths );
+                               // No needless escaping as this isn't HTML output.
+                               // Only stored in the database and parsed in PHP.
+                               $deps = json_encode( $localPaths, JSON_UNESCAPED_SLASHES );
                                $dbw = wfGetDB( DB_MASTER );
                                $dbw->upsert( 'module_deps',
                                        [