-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSemanticWikibase.php
More file actions
110 lines (91 loc) · 3.2 KB
/
SemanticWikibase.php
File metadata and controls
110 lines (91 loc) · 3.2 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
declare( strict_types = 1 );
namespace MediaWiki\Extension\SemanticWikibase;
use MediaWiki\Extension\SemanticWikibase\SMW\SemanticProperty;
use MediaWiki\Extension\SemanticWikibase\Translation\FixedProperties;
use MediaWiki\Extension\SemanticWikibase\Translation\PropertyTypeTranslator;
use MediaWiki\Extension\SemanticWikibase\Translation\TranslatorFactory;
use MediaWiki\Extension\SemanticWikibase\Translation\UserDefinedProperties;
use SMW\DataValueFactory;
use SMW\PropertyRegistry;
use Wikibase\DataModel\Services\Lookup\LegacyAdapterItemLookup;
use Wikibase\DataModel\Services\Lookup\LegacyAdapterPropertyLookup;
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
use Wikibase\Repo\WikibaseRepo;
class SemanticWikibase {
protected static ?self $instance;
private Configuration $config;
public static function getGlobalInstance(): self {
if ( !isset( self::$instance ) ) {
self::$instance = self::newDefault();
}
return self::$instance;
}
protected static function newDefault(): self {
return new static( Configuration::newFromGlobals( $GLOBALS ) );
}
public final function __construct( Configuration $config ) {
$this->config = $config;
}
public function getSemanticDataUpdate(): SemanticDataUpdate {
$entityLookup = WikibaseRepo::getEntityLookup();
return new SemanticDataUpdate(
$this->getTranslatorFactory(),
new LegacyAdapterItemLookup( $entityLookup ),
new LegacyAdapterPropertyLookup( $entityLookup )
);
}
protected function getTranslatorFactory(): TranslatorFactory {
return new TranslatorFactory(
$this->getDataValueFactory(),
$this->getPropertyTypeLookup()
);
}
private function getDataValueFactory(): DataValueFactory {
return DataValueFactory::getInstance();
}
protected function getPropertyTypeLookup(): PropertyDataTypeLookup {
return WikibaseRepo::getPropertyDataTypeLookup();
}
public function registerProperties( PropertyRegistry $propertyRegistry ) {
wfDebug("SWB: register properties ".json_encode($this->getAllProperties()));
foreach ( $this->getAllProperties() as $property ) {
$propertyRegistry->registerProperty(
$property->getId(),
$property->getType(),
$property->getLabel(),
true, #is_visible
true, #is_annotable
false #is_declarative
);
wfDebug("SWB: register property ".$property->getId());
wfDebug("SWB: register property ".$property->getType());
foreach ( $property->getAliases() as $alias ) {
$propertyRegistry->registerPropertyAlias( $property->getId(), $alias );
}
}
}
/**
* @return SemanticProperty[]
*/
private function getAllProperties(): array {
return array_merge(
$this->getFixedProperties()->getAll(),
$this->getUserDefinedProperties()->getAll()
);
}
public function getFixedProperties(): FixedProperties {
return new FixedProperties();
}
public function getUserDefinedProperties(): UserDefinedProperties {
return new UserDefinedProperties(
WikibaseRepo::getWikibaseServices()->getPropertyInfoLookup(),
$this->getPropertyTypeTranslator(),
WikibaseRepo::getTermLookup(),
$this->config->getLanguageCode()
);
}
private function getPropertyTypeTranslator(): PropertyTypeTranslator {
return new PropertyTypeTranslator();
}
}