Example #1
0
 /**
  * Register a module with the ResourceLoader system.
  *
  * @param mixed $name Name of module as a string or List of name/object pairs as an array
  * @param array $info Module info array. For backwards compatibility with 1.17alpha,
  *   this may also be a ResourceLoaderModule object. Optional when using
  *   multiple-registration calling style.
  * @throws MWException If a duplicate module registration is attempted
  * @throws MWException If a module name contains illegal characters (pipes or commas)
  * @throws MWException If something other than a ResourceLoaderModule is being registered
  * @return bool False if there were any errors, in which case one or more modules were
  *   not registered
  */
 public function register($name, $info = null)
 {
     // Allow multiple modules to be registered in one call
     $registrations = is_array($name) ? $name : array($name => $info);
     foreach ($registrations as $name => $info) {
         // Disallow duplicate registrations
         if (isset($this->moduleInfos[$name])) {
             // A module has already been registered by this name
             throw new MWException('ResourceLoader duplicate registration error. ' . 'Another module has already been registered as ' . $name);
         }
         // Check $name for validity
         if (!self::isValidModuleName($name)) {
             throw new MWException("ResourceLoader module name '{$name}' is invalid, " . "see ResourceLoader::isValidModuleName()");
         }
         // Attach module
         if ($info instanceof ResourceLoaderModule) {
             $this->moduleInfos[$name] = array('object' => $info);
             $info->setName($name);
             $this->modules[$name] = $info;
         } elseif (is_array($info)) {
             // New calling convention
             $this->moduleInfos[$name] = $info;
         } else {
             throw new MWException('ResourceLoader module info type error for module \'' . $name . '\': expected ResourceLoaderModule or array (got: ' . gettype($info) . ')');
         }
         // Last-minute changes
         // Apply custom skin-defined styles to existing modules.
         if ($this->isFileModule($name)) {
             foreach ($this->config->get('ResourceModuleSkinStyles') as $skinName => $skinStyles) {
                 // If this module already defines skinStyles for this skin, ignore $wgResourceModuleSkinStyles.
                 if (isset($this->moduleInfos[$name]['skinStyles'][$skinName])) {
                     continue;
                 }
                 // If $name is preceded with a '+', the defined style files will be added to 'default'
                 // skinStyles, otherwise 'default' will be ignored as it normally would be.
                 if (isset($skinStyles[$name])) {
                     $paths = (array) $skinStyles[$name];
                     $styleFiles = array();
                 } elseif (isset($skinStyles['+' . $name])) {
                     $paths = (array) $skinStyles['+' . $name];
                     $styleFiles = isset($this->moduleInfos[$name]['skinStyles']['default']) ? (array) $this->moduleInfos[$name]['skinStyles']['default'] : array();
                 } else {
                     continue;
                 }
                 // Add new file paths, remapping them to refer to our directories and not use settings
                 // from the module we're modifying, which come from the base definition.
                 list($localBasePath, $remoteBasePath) = ResourceLoaderFileModule::extractBasePaths($skinStyles);
                 foreach ($paths as $path) {
                     $styleFiles[] = new ResourceLoaderFilePath($path, $localBasePath, $remoteBasePath);
                 }
                 $this->moduleInfos[$name]['skinStyles'][$skinName] = $styleFiles;
             }
         }
     }
 }