mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 23:24:39 +00:00
Merge "Update documentation and signatures of hook handlers"
This commit is contained in:
commit
ac6e03cc0d
|
@ -104,11 +104,20 @@ class PopupsHooks {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Hook handler for the ResourceLoaderStartUpModule that makes static configuration visible to
|
||||||
|
* the frontend. These variables end in the only "startup" ResourceLoader module that is loaded
|
||||||
|
* before all others.
|
||||||
|
*
|
||||||
|
* Dynamic configuration that depends on the context needs to be published via the
|
||||||
|
* MakeGlobalVariablesScript hook.
|
||||||
|
*
|
||||||
* @param array &$vars Array of variables to be added into the output of the startup module
|
* @param array &$vars Array of variables to be added into the output of the startup module
|
||||||
|
* @param string $skin
|
||||||
*/
|
*/
|
||||||
public static function onResourceLoaderGetConfigVars( array &$vars ) {
|
public static function onResourceLoaderGetConfigVars( array &$vars, $skin ) {
|
||||||
/** @var \Config $config */
|
/** @var \Config $config */
|
||||||
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||||
|
|
||||||
$vars['wgPopupsVirtualPageViews'] = $config->get( 'PopupsVirtualPageViews' );
|
$vars['wgPopupsVirtualPageViews'] = $config->get( 'PopupsVirtualPageViews' );
|
||||||
$vars['wgPopupsGateway'] = $config->get( 'PopupsGateway' );
|
$vars['wgPopupsGateway'] = $config->get( 'PopupsGateway' );
|
||||||
$vars['wgPopupsEventLogging'] = $config->get( 'PopupsEventLogging' );
|
$vars['wgPopupsEventLogging'] = $config->get( 'PopupsEventLogging' );
|
||||||
|
@ -117,7 +126,8 @@ class PopupsHooks {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MakeGlobalVariablesScript hook handler.
|
* Hook handler publishing dynamic configuration that depends on the context, e.g. the page or
|
||||||
|
* the users settings. These variables end in an inline <script> in the documents head.
|
||||||
*
|
*
|
||||||
* Variables added:
|
* Variables added:
|
||||||
* * `wgPopupsReferencePreviews' - The server's notion of whether or not the reference
|
* * `wgPopupsReferencePreviews' - The server's notion of whether or not the reference
|
||||||
|
@ -130,9 +140,9 @@ class PopupsHooks {
|
||||||
* user has enabled conflicting Navigational Popups Gadget.
|
* user has enabled conflicting Navigational Popups Gadget.
|
||||||
*
|
*
|
||||||
* @param array &$vars variables to be added into the output of OutputPage::headElement
|
* @param array &$vars variables to be added into the output of OutputPage::headElement
|
||||||
* @param OutputPage $out OutputPage instance calling the hook
|
* @param \IContextSource $out OutputPage instance calling the hook
|
||||||
*/
|
*/
|
||||||
public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $out ) {
|
public static function onMakeGlobalVariablesScript( array &$vars, \IContextSource $out ) {
|
||||||
/** @var PopupsContext $context */
|
/** @var PopupsContext $context */
|
||||||
$context = MediaWikiServices::getInstance()->getService( 'Popups.Context' );
|
$context = MediaWikiServices::getInstance()->getService( 'Popups.Context' );
|
||||||
/** @var \Config $config */
|
/** @var \Config $config */
|
||||||
|
@ -142,7 +152,8 @@ class PopupsHooks {
|
||||||
$vars['wgPopupsReferencePreviews'] = self::isReferencePreviewsEnabled( $user, $config );
|
$vars['wgPopupsReferencePreviews'] = self::isReferencePreviewsEnabled( $user, $config );
|
||||||
$vars['wgPopupsShouldSendModuleToUser'] = $context->shouldSendModuleToUser( $user );
|
$vars['wgPopupsShouldSendModuleToUser'] = $context->shouldSendModuleToUser( $user );
|
||||||
$vars['wgPopupsConflictsWithNavPopupGadget'] = $context->conflictsWithNavPopupsGadget(
|
$vars['wgPopupsConflictsWithNavPopupGadget'] = $context->conflictsWithNavPopupsGadget(
|
||||||
$user );
|
$user
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,7 +177,7 @@ class PopupsHooks {
|
||||||
*
|
*
|
||||||
* @param array &$wgDefaultUserOptions Reference to default options array
|
* @param array &$wgDefaultUserOptions Reference to default options array
|
||||||
*/
|
*/
|
||||||
public static function onUserGetDefaultOptions( &$wgDefaultUserOptions ) {
|
public static function onUserGetDefaultOptions( array &$wgDefaultUserOptions ) {
|
||||||
/** @var \Config $config */
|
/** @var \Config $config */
|
||||||
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
||||||
'wgPopupsStatsvSamplingRate' => 0
|
'wgPopupsStatsvSamplingRate' => 0
|
||||||
];
|
];
|
||||||
$this->setMwGlobals( $config );
|
$this->setMwGlobals( $config );
|
||||||
PopupsHooks::onResourceLoaderGetConfigVars( $vars );
|
PopupsHooks::onResourceLoaderGetConfigVars( $vars, '' );
|
||||||
$this->assertCount( 6, $vars, 'A configuration is retrieved.' );
|
$this->assertCount( 6, $vars, 'A configuration is retrieved.' );
|
||||||
|
|
||||||
foreach ( $config as $key => $value ) {
|
foreach ( $config as $key => $value ) {
|
||||||
|
|
Loading…
Reference in a new issue