Page MenuHomePhabricator

Add hook for extensions to register into the resource loader
Closed, ResolvedPublic

Description

It'd be nice for extensions to register from a hook so they don't cause ResourceLoader.php and Resources.php to be loaded on every single request.


Version: 1.17.x
Severity: enhancement

Details

Reference
bz25049

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:11 PM
bzimport set Reference to bz25049.

Something like...

// Allow extensions to register modules
wfRunHooks( 'ResourceLoaderBeforeRespond', $context );

...inside of ResourceLoader::respond().

(In reply to comment #1)

Something like...

// Allow extensions to register modules
wfRunHooks( 'ResourceLoaderBeforeRespond', $context );

Pretty much yeah, except the second parameter is an array of parameters.

...inside of ResourceLoader::respond().

Because there are more ResourceLoader:: functions that use registrations, I'd prefer having a function called by all such entry points that then calls this hook once and only once.

In practical terms, something like

protected static function getHookRegistrations( $context ) {

static $done = false;
wfRunHooks( 'ResourceLoaderRegistrations', array( $context ) );
$done = true;

}

Then in all functions using the registration data (including respond(), but also other functions reading from self::$modules), call this function.

This has been done for a while now. The hook is called ResourceLoaderRegisterModules.

Then why isn't it documented in doc/hooks.txt ?

It is as of r73686 - thanks for noticing.