-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathWikibaseLexeme.datatypes.php
156 lines (143 loc) · 5.73 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* Definition of data types for use with Wikibase.
* The array returned by the code below is supposed to be merged into the Repo data types.
* 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 MediaWiki\MediaWikiServices;
use ValueFormatters\FormatterOptions;
use Wikibase\Lexeme\Domain\Model\Form;
use Wikibase\Lexeme\Domain\Model\Lexeme;
use Wikibase\Lexeme\Domain\Model\Sense;
use Wikibase\Lexeme\Presentation\Formatters\FormIdHtmlFormatter;
use Wikibase\Lexeme\Presentation\Formatters\FormIdTextFormatter;
use Wikibase\Lexeme\Presentation\Formatters\LexemeIdHtmlFormatter;
use Wikibase\Lexeme\Presentation\Formatters\RedirectedLexemeSubEntityIdHtmlFormatter;
use Wikibase\Lexeme\Presentation\Formatters\SenseIdHtmlFormatter;
use Wikibase\Lexeme\Presentation\Formatters\SenseIdTextFormatter;
use Wikibase\Lib\Formatters\EntityIdValueFormatter;
use Wikibase\Lib\Formatters\NonExistingEntityIdHtmlFormatter;
use Wikibase\Lib\Formatters\SnakFormat;
use Wikibase\Lib\Formatters\SnakFormatter;
use Wikibase\Lib\LanguageFallbackIndicator;
use Wikibase\Repo\MediaWikiLocalizedTextProvider;
use Wikibase\Repo\WikibaseRepo;
return [
'PT:wikibase-lexeme' => [
'expert-module' => 'wikibase.experts.Lexeme',
'validator-factory-callback' => static function () {
$factory = WikibaseRepo::getDefaultValidatorBuilders();
return $factory->getEntityValidators( Lexeme::ENTITY_TYPE );
},
'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) {
$snakFormat = new SnakFormat();
if ( $snakFormat->getBaseFormat( $format ) === SnakFormatter::FORMAT_HTML ) {
$userLanguage = WikibaseRepo::getUserLanguage();
$labelDescriptionLookup = WikibaseRepo::getFallbackLabelDescriptionLookupFactory()
->newLabelDescriptionLookup( $userLanguage );
return new EntityIdValueFormatter(
new LexemeIdHtmlFormatter(
WikibaseRepo::getEntityLookup(),
$labelDescriptionLookup,
WikibaseRepo::getEntityTitleLookup(),
new MediaWikiLocalizedTextProvider( $userLanguage ),
new NonExistingEntityIdHtmlFormatter(
'wikibaselexeme-deletedentity-'
)
)
);
}
return WikibaseRepo::getDefaultValueFormatterBuilders()
->newEntityIdFormatter( $format, $options );
},
'value-type' => 'wikibase-entityid',
],
'PT:wikibase-form' => [
'expert-module' => 'wikibase.experts.Form',
'validator-factory-callback' => static function () {
$factory = WikibaseRepo::getDefaultValidatorBuilders();
return $factory->getEntityValidators( Form::ENTITY_TYPE );
},
'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) {
$mwServices = MediaWikiServices::getInstance();
$userLanguage = WikibaseRepo::getUserLanguage( $mwServices );
$revisionLookup = WikibaseRepo::getEntityRevisionLookup( $mwServices );
$textProvider = new MediaWikiLocalizedTextProvider( $userLanguage );
$snakFormat = new SnakFormat();
if ( $snakFormat->getBaseFormat( $format ) === SnakFormatter::FORMAT_HTML ) {
$titleLookup = WikibaseRepo::getEntityTitleLookup( $mwServices );
$baseFormatter = new FormIdHtmlFormatter(
$revisionLookup,
WikibaseRepo::getFallbackLabelDescriptionLookupFactory( $mwServices )
->newLabelDescriptionLookup( $userLanguage ),
$titleLookup,
$textProvider,
new RedirectedLexemeSubEntityIdHtmlFormatter( $titleLookup ),
$mwServices->getLanguageFactory()
);
} else {
$baseFormatter = new FormIdTextFormatter(
$revisionLookup,
$textProvider
);
}
return new EntityIdValueFormatter(
$baseFormatter
);
},
'value-type' => 'wikibase-entityid',
],
'PT:wikibase-sense' => [
'expert-module' => 'wikibase.experts.Sense',
'validator-factory-callback' => static function () {
$factory = WikibaseRepo::getDefaultValidatorBuilders();
return $factory->getEntityValidators( Sense::ENTITY_TYPE );
},
'formatter-factory-callback' => static function ( $format, FormatterOptions $options ) {
$mwServices = MediaWikiServices::getInstance();
$revisionLookup = WikibaseRepo::getEntityRevisionLookup( $mwServices );
$language = WikibaseRepo::getUserLanguage( $mwServices ); // TODO get from $options (T281799)
$localizedTextProvider = new MediaWikiLocalizedTextProvider( $language );
$entityIdLabelFormatter = WikibaseRepo::getEntityIdLabelFormatterFactory( $mwServices )
->getEntityIdFormatter( $language );
$languageFallbackChainFactory = WikibaseRepo::getLanguageFallbackChainFactory();
$fallbackChain = $languageFallbackChainFactory->newFromLanguage( $language );
$snakFormat = new SnakFormat();
if ( $snakFormat->getBaseFormat( $format ) === SnakFormatter::FORMAT_HTML ) {
$titleLookup = WikibaseRepo::getEntityTitleLookup( $mwServices );
$languageNameLookup = WikibaseRepo::getLanguageNameLookupFactory( $mwServices )
->getForLanguage( $language );
return new EntityIdValueFormatter(
new SenseIdHtmlFormatter(
$titleLookup,
$revisionLookup,
$localizedTextProvider,
$fallbackChain,
new LanguageFallbackIndicator( $languageNameLookup ),
$mwServices->getLanguageFactory(),
$entityIdLabelFormatter
)
);
}
return new EntityIdValueFormatter(
new SenseIdTextFormatter(
$revisionLookup,
$localizedTextProvider,
$entityIdLabelFormatter
)
);
},
'value-type' => 'wikibase-entityid',
],
];