/** * Register mwEmbeed resource set * * Adds modules to ResourceLoader */ public static function register($mwEmbedResourcePath) { global $IP, $wgExtensionMessagesFiles; $fullResourcePath = $IP . '/' . $mwEmbedResourcePath; // Get the module name from the end of the path: $modulePathParts = explode('/', $mwEmbedResourcePath); $moduleName = array_pop($modulePathParts); if (!is_dir($fullResourcePath)) { throw new MWException(__METHOD__ . " not given readable path: " . htmlspecialchars($mwEmbedResourcePath)); } if (substr($mwEmbedResourcePath, -1) == '/') { throw new MWException(__METHOD__ . " path has trailing slash: " . htmlspecialchars($mwEmbedResourcePath)); } // Add module messages if present: $msgFileName = $fullResourcePath . '/' . $moduleName . '.i18n'; if (is_file($msgFileName . '.json')) { $wgExtensionMessagesFiles['MwEmbed.' . $moduleName] = $msgFileName . '.json'; } elseif (is_file($msgFileName . '.php')) { $wgExtensionMessagesFiles['MwEmbed.' . $moduleName] = $msgFileName . '.php'; } // Get the mwEmbed module resource registration: $moduleResourceFileName = $fullResourcePath . '/' . $moduleName; if (is_file($moduleResourceFileName . '.json')) { $resourceList = json_decode(file_get_contents($moduleResourceFileName . '.json'), TRUE); } else { $resourceList = (include $moduleResourceFileName . '.php'); } // Look for special 'messages' => 'moduleFile' key and load all modules file messages: foreach ($resourceList as $name => $resources) { if (isset($resources['messageFile']) && is_file($fullResourcePath . '/' . $resources['messageFile'])) { $resourceList[$name]['messages'] = array(); $ext = pathinfo($fullResourcePath . '/' . $resources['messageFile'], PATHINFO_EXTENSION); switch ($ext) { case "json": $messages = json_decode(file_get_contents($fullResourcePath . '/' . $resources['messageFile']), TRUE); break; case "php": include $fullResourcePath . '/' . $resources['messageFile']; break; } foreach ($messages['en'] as $msgKey => $na) { $resourceList[$name]['messages'][] = $msgKey; } } } // Check for module loader: if (is_file($fullResourcePath . '/' . $moduleName . '.loader.js')) { $resourceList[$moduleName . '.loader'] = array('loaderScripts' => $moduleName . '.loader.js'); } // Check for module config ( @@TODO support per-module config ) $configPathFileName = $fullResourcePath . '/' . $moduleName . '.config'; if (is_file($configPathFileName . '.json')) { $moduleConfigObj = json_decode(file_get_contents($configPathFileName . '.json'), TRUE); self::$moduleConfig = array_merge(self::$moduleConfig, $moduleConfigObj); } elseif (is_file($configPathFileName . '.php')) { self::$moduleConfig = array_merge(self::$moduleConfig, include $configPathFileName . '.php'); } // Add the resource list into the module set with its provided path self::$moduleSet[$mwEmbedResourcePath] = $resourceList; }
/** * Register mwEmbeed resource set based on the * * Adds modules to ResourceLoader */ public static function register($mwEmbedResourcePath) { global $IP, $wgExtensionMessagesFiles; $localResourcePath = $IP . '/' . $mwEmbedResourcePath; // Get the module name from the end of the path: $modulePathParts = explode('/', $mwEmbedResourcePath); $moduleName = array_pop($modulePathParts); if (!is_dir($localResourcePath)) { throw new MWException(__METHOD__ . " not given readable path: " . htmlspecialchars($localResourcePath)); } if (substr($mwEmbedResourcePath, -1) == '/') { throw new MWException(__METHOD__ . " path has trailing slash: " . htmlspecialchars($localResourcePath)); } // Add module messages if present: if (is_file($localResourcePath . '/' . $moduleName . '.i18n.php')) { $wgExtensionMessagesFiles['MwEmbed.' . $moduleName] = $localResourcePath . '/' . $moduleName . '.i18n.php'; } // Check that resource file is present: $resourceListFilePath = $localResourcePath . '/' . $moduleName . '.php'; if (!is_file($resourceListFilePath)) { throw new MWException(__METHOD__ . " mwEmbed Module is missing resource list: " . htmlspecialchars($resourceListFilePath)); } // Get the mwEmbed module resource registration: $resourceList = (include $resourceListFilePath); // Look for special 'messages' => 'moduleFile' key and load all modules file messages: foreach ($resourceList as $name => $resources) { if (isset($resources['messageFile']) && is_file($localResourcePath . '/' . $resources['messageFile'])) { $resourceList[$name]['messages'] = array(); include $localResourcePath . '/' . $resources['messageFile']; foreach ($messages['en'] as $msgKey => $na) { $resourceList[$name]['messages'][] = $msgKey; } } } // Check for module loader: if (is_file($localResourcePath . '/' . $moduleName . '.loader.js')) { $resourceList[$moduleName . '.loader'] = array('loaderScripts' => $moduleName . '.loader.js'); } // Check for module config ( @@TODO support per-module config ) $configPath = $localResourcePath . '/' . $moduleName . '.config.php'; if (is_file($configPath)) { self::$moduleConfig = array_merge(self::$moduleConfig, include $configPath); } // Add the resource list into the module set with its provided path self::$moduleSet[$mwEmbedResourcePath] = $resourceList; }