https://bugzilla.wikimedia.org/show_bug.cgi?id=37013

       Web browser: ---
             Bug #: 37013
           Summary: ResourceLoader does not check dependencies for
                    existance
           Product: MediaWiki
           Version: 1.18.2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: Unprioritized
         Component: ResourceLoader
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected],
                    [email protected]
    Classification: Unclassified
   Mobile Platform: ---


I developed my extension in 1.18wmf1 then in 1.20 master. One of ResourceLoader
modules, defined by extension has the following dependency:

            'dependencies' => 'mediawiki.jqueryMsg',

The 'mediawiki.jqueryMsg' module and it's script is present in 1.18wmf1, 1.19,
1.20 master, but I was really surprised that in 1.18.2 it does not exists so
the page scripts where my extension module is requested were broken with the
following Chrome console errors:

Uncaught Error: Unknown dependency: mediawiki.jqueryMsg load.php:9427
Uncaught TypeError: Cannot read property 'options' of undefined GmapFunc:255
Uncaught TypeError: Cannot read property 'tokens' of undefined GmapFunc:260

Can I try to catch the client-side error in load.php? I don't know how.
Instead, I implemented the following server-side method to check whether the
dependent modules actually exists:

    static protected function checkAllModulesExists() {
        $allModules = array_keys( self::$mapModules );
        foreach ( self::$mapModules as $moduleName => $moduleDefinition ) {
            if ( !array_key_exists( 'dependencies', $moduleDefinition ) ) {
                continue;
            }
            if ( is_array( $moduleDefinition['dependencies'] ) ) {
                $allModules += $moduleDefinition['dependencies'];
            } else {
                # We do not check for multiple matches in values:
                # it would only decrease performance in this case.
                $allModules[] = $moduleDefinition['dependencies'];
            }
        }
        $nonExistantModules = array_diff(
            $allModules,
            self::$out->getResourceLoader()->getModuleNames()
        );
        if ( count( $nonExistantModules ) > 0 ) {
            throw new MWException( 'Cannot find requested module(s): ' .
                implode( ',', $nonExistantModules ) .
                ' in ' . __METHOD__
            );
        }
    }

Which produces the following page message, at least (that is more informative
than Chrome console message):

Cannot find requested module(s): mediawiki.jqueryMsg in
GMFn::checkAllModulesExists

It would be nice if ResourceLoader itself checked the dependencies of added
modules.

-- 
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
You are on the CC list for the bug.

_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to