resourceloader: Use upsert() instead of replace() for module_deps write
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderModule.php
index 3e94460..fd74a82 100644 (file)
  * @author Roan Kattouw
  */
 
+use MediaWiki\MediaWikiServices;
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerInterface;
 use Psr\Log\NullLogger;
+use Wikimedia\ScopedCallback;
 
 /**
  * Abstraction for ResourceLoader modules, with name registration and maxage functionality.
@@ -186,7 +188,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
        public function getConfig() {
                if ( $this->config === null ) {
                        // Ugh, fall back to default
-                       $this->config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
+                       $this->config = MediaWikiServices::getInstance()->getMainConfig();
                }
 
                return $this->config;
@@ -329,14 +331,13 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
        }
 
        /**
-        * Where on the HTML page should this module's JS be loaded?
-        *  - 'top': in the "<head>"
-        *  - 'bottom': at the bottom of the "<body>"
+        * From where in the page HTML should this module be loaded?
         *
+        * @deprecated since 1.29 Obsolete. All modules load async from `<head>`.
         * @return string
         */
        public function getPosition() {
-               return 'bottom';
+               return 'top';
        }
 
        /**
@@ -475,14 +476,18 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
                                }
 
                                $vary = $context->getSkin() . '|' . $context->getLanguage();
+                               // Use relative paths to avoid ghost entries when $IP changes (T111481)
+                               $deps = FormatJson::encode( self::getRelativePaths( $localFileRefs ) );
                                $dbw = wfGetDB( DB_MASTER );
-                               $dbw->replace( 'module_deps',
-                                       [ [ 'md_module', 'md_skin' ] ],
+                               $dbw->upsert( 'module_deps',
                                        [
                                                'md_module' => $this->getName(),
                                                'md_skin' => $vary,
-                                               // Use relative paths to avoid ghost entries when $IP changes (T111481)
-                                               'md_deps' => FormatJson::encode( self::getRelativePaths( $localFileRefs ) ),
+                                               'md_deps' => $deps,
+                                       ],
+                                       [ 'md_module', 'md_skin' ],
+                                       [
+                                               'md_deps' => $deps,
                                        ]
                                );