Skip to content

Commit aa83b62

Browse files
Migrate WikibaseRepoEntitySearchHelperCallbacks hook
Apparently we previously hadn’t documented this one in hooks-php.md, so add a pointer to the hook interface now. We might remove this file later (not sure), but as long as we have it, I think it’s better if it lists all the hooks. Bug: T391444 Change-Id: I027fce3d1922d645f55b7f2b2725e5e66ecf9679
1 parent 81ec56e commit aa83b62

File tree

5 files changed

+52
-16
lines changed

5 files changed

+52
-16
lines changed

docs/topics/hooks-php.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ See @ref Wikibase::Repo::Hooks::WikibaseRepoOnParserOutputUpdaterConstructionHoo
4848
#### GetEntityByLinkedTitleLookup {#GetEntityByLinkedTitleLookup}
4949
See @ref Wikibase::Repo::Hooks::GetEntityByLinkedTitleLookupHook.
5050

51+
### WikibaseRepoEntitySearchHelperCallbacks {#WikibaseRepoEntitySearchHelperCallbacks}
52+
See @ref Wikibase::Repo::Hooks::WikibaseRepoEntitySearchHelperCallbacks.
53+
5154
Client
5255
------------------------------------------------------------
5356

repo/WikibaseRepo.ServiceWiring.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,8 @@ function ( EntityNamespaceLookup $nsLookup, DatabaseEntitySource $source ): Enti
994994
$callbacks = WikibaseRepo::getEntityTypeDefinitions( $services )
995995
->get( EntityTypeDefinitions::ENTITY_SEARCH_CALLBACK );
996996

997-
$services->getHookContainer()->run( 'WikibaseRepoEntitySearchHelperCallbacks', [ &$callbacks ] );
997+
WikibaseRepo::getHookRunner( $services )
998+
->onWikibaseRepoEntitySearchHelperCallbacks( $callbacks );
998999

9991000
return $callbacks;
10001001
},
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare( strict_types = 1 );
4+
5+
namespace Wikibase\Repo\Hooks;
6+
7+
/**
8+
* This is a hook handler interface, see docs/Hooks.md in MediaWiki core.
9+
* Use the hook name "WikibaseRepoEntitySearchHelperCallbacks" to register
10+
* handlers implementing this interface.
11+
*
12+
* @license GPL-2.0-or-later
13+
*/
14+
interface WikibaseRepoEntitySearchHelperCallbacksHook {
15+
16+
/**
17+
* Define or modify entity search helper callbacks.
18+
*
19+
* This hook is called when the entity search is initialized.
20+
* $callbacks is an associative array from entity type to callback:
21+
* each callback takes a {@link \MediaWiki\Request\WebRequest WebRequest} parameter
22+
* and returns an {@link \Wikibase\Repo\Api\EntitySearchHelper EntitySearchHelper}.
23+
* Usually, these callbacks are defined via the entity type definitions,
24+
* using the {@link \Wikibase\Lib\EntityTypeDefinitions::ENTITY_SEARCH_CALLBACK ENTITY_SEARCH_CALLBACK} key;
25+
* however, it is possible to change the callbacks via this hook,
26+
* or even to install additional searchable entity types that are not registered as entity types.
27+
*
28+
* @param callable[] &$callbacks
29+
*/
30+
public function onWikibaseRepoEntitySearchHelperCallbacks( array &$callbacks ): void;
31+
32+
}

repo/includes/Hooks/WikibaseRepoHookRunner.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class WikibaseRepoHookRunner implements
2323
WikibaseChangeNotificationHook,
2424
WikibaseContentModelMappingHook,
2525
WikibaseRepoDataTypesHook,
26+
WikibaseRepoEntitySearchHelperCallbacksHook,
2627
WikibaseRepoEntityTypesHook,
2728
WikibaseRepoOnParserOutputUpdaterConstructionHook,
2829
WikibaseRepoSearchableEntityScopesMessagesHook,
@@ -82,6 +83,13 @@ public function onWikibaseRepoDataTypes( array &$dataTypeDefinitions ): void {
8283
);
8384
}
8485

86+
public function onWikibaseRepoEntitySearchHelperCallbacks( array &$callbacks ): void {
87+
$this->hookContainer->run( 'WikibaseRepoEntitySearchHelperCallbacks',
88+
[ &$callbacks ],
89+
[ 'abortable' => false ]
90+
);
91+
}
92+
8593
public function onWikibaseRepoEntityTypes( array &$entityTypeDefinitions ): void {
8694
/**
8795
* Warning: This hook runs as part of an early initialization service

repo/tests/phpunit/unit/ServiceWiring/EntitySearchHelperCallbacksTest.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
namespace Wikibase\Repo\Tests\Unit\ServiceWiring;
66

7-
use MediaWiki\HookContainer\HookContainer;
8-
use MediaWiki\HookContainer\StaticHookRegistry;
97
use Wikibase\Lib\EntityTypeDefinitions;
108
use Wikibase\Repo\Tests\Unit\ServiceWiringTestCase;
11-
use Wikimedia\ObjectFactory\ObjectFactory;
129

1310
/**
1411
* @coversNothing
@@ -32,18 +29,13 @@ public function testConstruction(): void {
3229
EntityTypeDefinitions::ENTITY_SEARCH_CALLBACK => $callable2,
3330
],
3431
] ) );
35-
$this->serviceContainer->expects( $this->once() )
36-
->method( 'getHookContainer' )
37-
->willReturn( new HookContainer(
38-
new StaticHookRegistry( [
39-
'WikibaseRepoEntitySearchHelperCallbacks' => [
40-
'callback' => function ( &$callbacks ) use ( $callable3 ) {
41-
$callbacks['type3'] = $callable3;
42-
},
43-
],
44-
] ),
45-
$this->createMock( ObjectFactory::class )
46-
) );
32+
$this->configureHookRunner( [
33+
'WikibaseRepoEntitySearchHelperCallbacks' => [
34+
function ( &$callbacks ) use ( $callable3 ) {
35+
$callbacks['type3'] = $callable3;
36+
},
37+
],
38+
] );
4739

4840
$this->assertSame( [
4941
'type1' => $callable1,

0 commit comments

Comments
 (0)