forked from wikimedia/mediawiki-extensions-WikibaseLexeme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWikibaseLexeme.datatypes.php
85 lines (79 loc) · 2.82 KB
/
WikibaseLexeme.datatypes.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
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
<?php
/**
* Definition of data types for use with Wikibase.
* The array returned by the code below is supposed to be merged into $wgWBRepoDataTypes.
* It defines the formatters used by the repo to display data values of different types.
*
* @note: This is bootstrap code, it is executed for EVERY request. Avoid instantiating
* objects or loading classes here!
*
* @note: 'validator-factory-callback' fields delegate to a global instance of
* ValidatorsBuilders
*
* @see ValidatorsBuilders
* @see docs/datatypes.wiki in the Wikibase.git repository for documentation
*
* @license GPL-2.0-or-later
*/
use ValueFormatters\FormatterOptions;
use Wikibase\Lexeme\DataModel\Lexeme;
use Wikibase\Lexeme\PropertyType\FormIdFormatter;
use Wikibase\Lexeme\PropertyType\LexemeIdHtmlFormatter;
use Wikibase\Lexeme\PropertyType\SenseIdFormatter;
use Wikibase\Lib\EntityIdValueFormatter;
use Wikibase\Lib\SnakFormatter;
use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookup;
use Wikibase\Repo\MediaWikiLocalizedTextProvider;
use Wikibase\Repo\WikibaseRepo;
return [
'PT:wikibase-lexeme' => [
'expert-module' => 'wikibase.experts.Lexeme',
'validator-factory-callback' => function() {
$factory = WikibaseRepo::getDefaultValidatorBuilders();
return $factory->getEntityValidators( Lexeme::ENTITY_TYPE );
},
'formatter-factory-callback' => function ( $format, FormatterOptions $options ) {
if ( $format === SnakFormatter::FORMAT_HTML ) {
$wikibaseRepo = WikibaseRepo::getDefaultInstance();
$userLanguage = $wikibaseRepo->getUserLanguage();
// TODO: Use LanguageFallbackLabelDescriptionLookupFactory instead?
$labelDescriptionLookup = new LanguageFallbackLabelDescriptionLookup(
$wikibaseRepo->getTermLookup(),
$wikibaseRepo->getLanguageFallbackChainFactory()
->newFromLanguage( $userLanguage )
);
return new EntityIdValueFormatter(
new LexemeIdHtmlFormatter(
$wikibaseRepo->getEntityLookup(),
$labelDescriptionLookup,
$wikibaseRepo->getEntityTitleLookup(),
new MediaWikiLocalizedTextProvider( $userLanguage->getCode() )
)
);
}
return WikibaseRepo::getDefaultValueFormatterBuilders()
->newEntityIdFormatter( $format, $options );
},
'value-type' => 'wikibase-entityid',
],
'PT:wikibase-lexeme-form' => [
'expert-module' => 'wikibase.experts.Form',
'validator-factory-callback' => function() {
return [];
},
'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
return new FormIdFormatter();
},
'value-type' => 'string',
],
'PT:wikibase-lexeme-sense' => [
'expert-module' => 'wikibase.experts.Sense',
'validator-factory-callback' => function() {
return [];
},
'formatter-factory-callback' => function( $format, FormatterOptions $options ) {
return new SenseIdFormatter();
},
'value-type' => 'string',
],
];