resourceloader: Derive from existing Context object in ClientHtml
It was previously creating a fresh context object, and then manually imported some query parameters, and then *also* created a derivative context object (so that it can copy over the "getContentOverrideCallback" value and to allow the consumer to also use setVersion/setModules). The reason for this indirection was that I wanted to re-use the query string parsing logic of ResourceLoaderContext::__construct, instead of interpreting it here. However that extra indirection is rather fragile as it could easily forget some other things to inherit manually. And, per T249189, it means there is no process cache shared between the two. This is exactly what DerivativeResourceLoaderContext is for, and if there is a missing feature in it, we should add it, instead of working around it (note to self...). For now, though, it can actually be used as-is. Changes: * Use DerivativeResourceLoaderContext directly. * Set the 'only' and 'user' values directly using the setter methods after creating the derivative object. * Also set 'raw' correctly. This was previously handled by $extraQuery being passed to ResourceLoaderContext::__construct, but now needs to be done manually. Bug: T249189 Change-Id: I4173ec75bef4fe9fee39663b1348c077414d3627
This commit is contained in:
parent
f4a9324e5a
commit
dba33a0508
1 changed files with 7 additions and 8 deletions
|
|
@ -362,18 +362,17 @@ JAVASCRIPT;
|
|||
private static function makeContext( ResourceLoaderContext $mainContext, $group, $type,
|
||||
array $extraQuery = []
|
||||
) {
|
||||
// Create new ResourceLoaderContext so that $extraQuery is supported (eg. for 'sync=1').
|
||||
$req = new FauxRequest( array_merge( $mainContext->getRequest()->getValues(), $extraQuery ) );
|
||||
// Allow caller to setVersion() and setModules()
|
||||
$ret = new DerivativeResourceLoaderContext( $mainContext );
|
||||
// Set 'only' if not combined
|
||||
$req->setVal( 'only', $type === ResourceLoaderModule::TYPE_COMBINED ? null : $type );
|
||||
$ret->setOnly( $type === ResourceLoaderModule::TYPE_COMBINED ? null : $type );
|
||||
// Remove user parameter in most cases
|
||||
if ( $group !== 'user' && $group !== 'private' ) {
|
||||
$req->setVal( 'user', null );
|
||||
$ret->setUser( null );
|
||||
}
|
||||
if ( isset( $extraQuery['raw'] ) ) {
|
||||
$ret->setRaw( true );
|
||||
}
|
||||
$context = new ResourceLoaderContext( $mainContext->getResourceLoader(), $req );
|
||||
// Allow caller to setVersion() and setModules()
|
||||
$ret = new DerivativeResourceLoaderContext( $context );
|
||||
$ret->setContentOverrideCallback( $mainContext->getContentOverrideCallback() );
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue