API: Add "messagecode" to AuthManager responses
[lhc/web/wiklou.git] / includes / OutputPage.php
index 91fc75c..eb2f7e7 100644 (file)
@@ -534,14 +534,32 @@ class OutputPage extends ContextSource {
                        if ( $module instanceof ResourceLoaderModule
                                && $module->getOrigin() <= $this->getAllowedModules( $type )
                                && ( is_null( $position ) || $module->getPosition() == $position )
-                               && ( !$this->mTarget || in_array( $this->mTarget, $module->getTargets() ) )
                        ) {
+                               if ( $this->mTarget && !in_array( $this->mTarget, $module->getTargets() ) ) {
+                                       $this->warnModuleTargetFilter( $module->getName() );
+                                       continue;
+                               }
                                $filteredModules[] = $val;
                        }
                }
                return $filteredModules;
        }
 
+       private function warnModuleTargetFilter( $moduleName ) {
+               static $warnings = [];
+               if ( isset( $warnings[$this->mTarget][$moduleName] ) ) {
+                       return;
+               }
+               $warnings[$this->mTarget][$moduleName] = true;
+               $this->getResourceLoader()->getLogger()->debug(
+                       'Module "{module}" not loadable on target "{target}".',
+                       [
+                               'module' => $moduleName,
+                               'target' => $this->mTarget,
+                       ]
+               );
+       }
+
        /**
         * Get the list of modules to include on this page
         *
@@ -3697,6 +3715,8 @@ class OutputPage extends ContextSource {
         */
        public static function transformResourcePath( Config $config, $path ) {
                global $IP;
+
+               $localDir = $IP;
                $remotePathPrefix = $config->get( 'ResourceBasePath' );
                if ( $remotePathPrefix === '' ) {
                        // The configured base path is required to be empty string for
@@ -3710,8 +3730,18 @@ class OutputPage extends ContextSource {
                        // - Path is protocol-relative. Fixes T155310. Not supported by RelPath lib.
                        return $path;
                }
+               // For files in resources, extensions/ or skins/, ResourceBasePath is preferred here.
+               // For other misc files in $IP, we'll fallback to that as well. There is, however, a fourth
+               // supported dir/path pair in the configuration (wgUploadDirectory, wgUploadPath)
+               // which is not expected to be in wgResourceBasePath on CDNs. (T155146)
+               $uploadPath = $config->get( 'UploadPath' );
+               if ( strpos( $path, $uploadPath ) === 0 ) {
+                       $localDir = $config->get( 'UploadDirectory' );
+                       $remotePathPrefix = $remotePath = $uploadPath;
+               }
+
                $path = RelPath\getRelativePath( $path, $remotePath );
-               return self::transformFilePath( $remotePathPrefix, $IP, $path );
+               return self::transformFilePath( $remotePathPrefix, $localDir, $path );
        }
 
        /**