forked from Wikidata-lib/PropertySuggester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropertySuggesterHooks.php
54 lines (44 loc) · 1.39 KB
/
PropertySuggesterHooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
use Wikibase\DataModel\Entity\Item;
use Wikibase\Repo\WikibaseRepo;
final class PropertySuggesterHooks {
/**
* Handler for the BeforePageDisplay hook, injects special behaviour
* for PropertySuggestions in the EntitySuggester (if page is in EntityNamespace)
*
*
* @param OutputPage $out
* @param Skin $skin
* @return bool
*/
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
if ( $out->getRequest()->getCheck( 'nosuggestions' ) ) {
return true;
}
$entityNamespaceLookup = WikibaseRepo::getDefaultInstance()->getEntityNamespaceLookup();
$itemNamespace = $entityNamespaceLookup->getEntityNamespace( Item::ENTITY_TYPE );
if ( !is_int( $itemNamespace ) ) {
// try looking up namespace by content model, for any instances of PropertySuggester
// running with older Wikibase prior to ef622b1bc.
$itemNamespace = $entityNamespaceLookup->getEntityNamespace(
CONTENT_MODEL_WIKIBASE_ITEM
);
}
if ( $out->getTitle() === null || $out->getTitle()->getNamespace() !== $itemNamespace ) {
return true;
}
$out->addModules( 'ext.PropertySuggester.EntitySelector' );
return true;
}
/**
* @param DatabaseUpdater $updater
* @return bool
*/
public static function onCreateSchema( DatabaseUpdater $updater ) {
$updater->addExtensionTable(
'wbs_propertypairs',
__DIR__ . '/sql/create_propertypairs.sql'
);
return true;
}
}