-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathWikibaseMediaInfo.entitytypes.php
345 lines (326 loc) · 13 KB
/
WikibaseMediaInfo.entitytypes.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<?php
/**
* Definition of the media info entity type.
* The array returned by the code below is supposed to be merged into $wgWBRepoEntityTypes.
*
* @note: Keep in sync with Wikibase
*
* @note: This is bootstrap code, it is executed for EVERY request. Avoid instantiating
* objects or loading classes here!
*
* @license GPL-2.0-or-later
* @author Bene* < [email protected] >
*/
use MediaWiki\Language\Language;
use MediaWiki\MediaWikiServices;
use MediaWiki\Site\SiteLookup;
use MediaWiki\Title\Title;
use Wikibase\DataAccess\EntitySource;
use Wikibase\DataModel\Deserializers\DeserializerFactory;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\NumericPropertyId;
use Wikibase\DataModel\Serializers\SerializerFactory;
use Wikibase\DataModel\Services\EntityId\EntityIdFormatter;
use Wikibase\DataModel\Services\Lookup\InProcessCachingDataTypeLookup;
use Wikibase\Lib\DataTypeDefinitions;
use Wikibase\Lib\EntityTypeDefinitions as Def;
use Wikibase\Lib\EntityTypeDefinitions;
use Wikibase\Lib\SettingsArray;
use Wikibase\Lib\Store\CachingPropertyOrderProvider;
use Wikibase\Lib\Store\EntityContentDataCodec;
use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Lib\Store\Sql\WikiPageEntityDataLoader;
use Wikibase\Lib\Store\Sql\WikiPageEntityMetaDataLookup;
use Wikibase\Lib\Store\TitleLookupBasedEntityExistenceChecker;
use Wikibase\Lib\Store\TitleLookupBasedEntityRedirectChecker;
use Wikibase\Lib\Store\TitleLookupBasedEntityTitleTextLookup;
use Wikibase\Lib\Store\TitleLookupBasedEntityUrlLookup;
use Wikibase\Lib\Store\WikiPagePropertyOrderProvider;
use Wikibase\Lib\TermLanguageFallbackChain;
use Wikibase\MediaInfo\ChangeOp\Deserialization\MediaInfoChangeOpDeserializer;
use Wikibase\MediaInfo\Content\MediaInfoContent;
use Wikibase\MediaInfo\DataAccess\Store\EntityIdFixingRevisionLookup;
use Wikibase\MediaInfo\DataAccess\Store\FilePageRedirectHandlingRevisionLookup;
use Wikibase\MediaInfo\DataModel\MediaInfo;
use Wikibase\MediaInfo\DataModel\MediaInfoId;
use Wikibase\MediaInfo\DataModel\Serialization\MediaInfoDeserializer;
use Wikibase\MediaInfo\DataModel\Serialization\MediaInfoSerializer;
use Wikibase\MediaInfo\DataModel\Services\Diff\MediaInfoDiffer;
use Wikibase\MediaInfo\DataModel\Services\Diff\MediaInfoPatcher;
use Wikibase\MediaInfo\Diff\BasicMediaInfoDiffVisualizer;
use Wikibase\MediaInfo\Rdf\MediaInfoRdfBuilder;
use Wikibase\MediaInfo\Rdf\MediaInfoSpecificComponentsRdfBuilder;
use Wikibase\MediaInfo\Search\MediaInfoFieldDefinitions;
use Wikibase\MediaInfo\Services\MediaInfoEntityQuery;
use Wikibase\MediaInfo\Services\MediaInfoPrefetchingTermLookup;
use Wikibase\MediaInfo\Services\MediaInfoServices;
use Wikibase\MediaInfo\View\MediaInfoEntityStatementsView;
use Wikibase\MediaInfo\View\MediaInfoEntityTermsView;
use Wikibase\MediaInfo\View\MediaInfoView;
use Wikibase\Repo\Diff\ClaimDiffer;
use Wikibase\Repo\Diff\ClaimDifferenceVisualizer;
use Wikibase\Repo\MediaWikiLocalizedTextProvider;
use Wikibase\Repo\Rdf\DedupeBag;
use Wikibase\Repo\Rdf\EntityMentionListener;
use Wikibase\Repo\Rdf\FullStatementRdfBuilderFactory;
use Wikibase\Repo\Rdf\RdfVocabulary;
use Wikibase\Repo\Rdf\TermsRdfBuilder;
use Wikibase\Repo\Rdf\TruthyStatementRdfBuilderFactory;
use Wikibase\Repo\Rdf\ValueSnakRdfBuilderFactory;
use Wikibase\Repo\WikibaseRepo;
use Wikibase\Search\Elastic\Fields\DescriptionsProviderFieldDefinitions;
use Wikibase\Search\Elastic\Fields\LabelsProviderFieldDefinitions;
use Wikibase\Search\Elastic\Fields\StatementProviderFieldDefinitions;
use Wikimedia\Purtle\RdfWriter;
return [
MediaInfo::ENTITY_TYPE => [
Def::STORAGE_SERIALIZER_FACTORY_CALLBACK => static function ( SerializerFactory $serializerFactory ) {
return new MediaInfoSerializer(
$serializerFactory->newTermListSerializer(),
$serializerFactory->newStatementListSerializer()
);
},
Def::SERIALIZER_FACTORY_CALLBACK => static function ( SerializerFactory $serializerFactory ) {
return new MediaInfoSerializer(
$serializerFactory->newTermListSerializer(),
$serializerFactory->newStatementListSerializer()
);
},
Def::DESERIALIZER_FACTORY_CALLBACK => static function ( DeserializerFactory $deserializerFactory ) {
return new MediaInfoDeserializer(
$deserializerFactory->newEntityIdDeserializer(),
$deserializerFactory->newTermListDeserializer(),
$deserializerFactory->newStatementListDeserializer()
);
},
Def::VIEW_FACTORY_CALLBACK => static function (
Language $language,
TermLanguageFallbackChain $termFallbackChain,
EntityDocument $entity
) {
$services = MediaWikiServices::getInstance();
$mwConfig = $services->getMainConfig();
$languageCode = $language->getCode();
// Use a MediaInfo-specific EntityTermsView class instead of the default one
$langDirLookup = WikibaseRepo::getLanguageDirectionalityLookup( $services );
$textProvider = new MediaWikiLocalizedTextProvider( $language );
$mediaInfoEntityTermsView = new MediaInfoEntityTermsView(
WikibaseRepo::getLanguageNameLookupFactory( $services )->getForLanguage( $language ),
$langDirLookup,
$textProvider,
$termFallbackChain
);
// Use a MediaInfo-specific EntityStatementView class
$propertyOrderProvider = new CachingPropertyOrderProvider(
new WikiPagePropertyOrderProvider(
$services->getWikiPageFactory(),
Title::newFromText( 'MediaWiki:Wikibase-SortedProperties' )
),
$services->getObjectCacheFactory()->getLocalClusterInstance()
);
$defaultPropertyIdsForView = [];
$properties = $mwConfig->get( 'MediaInfoProperties' ) ?? [];
foreach ( $properties as $propertyId ) {
$defaultPropertyIdsForView[] = new NumericPropertyId( $propertyId );
}
$statementsView = new MediaInfoEntityStatementsView(
$propertyOrderProvider,
$textProvider,
$defaultPropertyIdsForView,
WikibaseRepo::getSnakFormatterFactory( $services ),
WikibaseRepo::getValueFormatterFactory( $services ),
WikibaseRepo::getBaseDataModelSerializerFactory( $services ),
$languageCode,
$properties
);
return new MediaInfoView(
$mediaInfoEntityTermsView,
$languageCode,
$statementsView
);
},
Def::CONTENT_MODEL_ID => MediaInfoContent::CONTENT_MODEL_ID,
Def::SEARCH_FIELD_DEFINITIONS => static function ( array $languageCodes, SettingsArray $searchSettings ) {
$services = MediaWikiServices::getInstance();
$configFactory = $services->getConfigFactory();
return new MediaInfoFieldDefinitions(
new LabelsProviderFieldDefinitions( $languageCodes ),
new DescriptionsProviderFieldDefinitions( $languageCodes, $configFactory ),
StatementProviderFieldDefinitions::newFromSettings(
new InProcessCachingDataTypeLookup(
WikibaseRepo::getPropertyDataTypeLookup( $services ) ),
WikibaseRepo::getDataTypeDefinitions( $services )
->getSearchIndexDataFormatterCallbacks(),
$searchSettings,
WikibaseRepo::getLogger( $services )
)
);
},
Def::CONTENT_HANDLER_FACTORY_CALLBACK => static function () {
return MediaInfoServices::getMediaInfoHandler();
},
Def::ENTITY_ID_PATTERN => MediaInfoId::PATTERN,
Def::ENTITY_ID_BUILDER => static function ( $serialization ) {
return new MediaInfoId( $serialization );
},
Def::ENTITY_ID_COMPOSER_CALLBACK => static function ( $uniquePart ) {
return new MediaInfoId( 'M' . $uniquePart );
},
Def::ENTITY_DIFFER_STRATEGY_BUILDER => static function () {
return new MediaInfoDiffer();
},
Def::ENTITY_PATCHER_STRATEGY_BUILDER => static function () {
return new MediaInfoPatcher();
},
Def::ENTITY_FACTORY_CALLBACK => static function () {
return new MediaInfo();
},
// Identifier of a resource loader module that, when `require`d, returns a function
// returning a deserializer
Def::JS_DESERIALIZER_FACTORY_FUNCTION => 'wikibase.mediainfo.getDeserializer',
Def::CHANGEOP_DESERIALIZER_CALLBACK => static function () {
$changeOpDeserializerFactory = WikibaseRepo::getChangeOpDeserializerFactory();
return new MediaInfoChangeOpDeserializer(
$changeOpDeserializerFactory->getLabelsChangeOpDeserializer(),
$changeOpDeserializerFactory->getDescriptionsChangeOpDeserializer(),
$changeOpDeserializerFactory->getClaimsChangeOpDeserializer()
);
},
Def::ENTITY_DIFF_VISUALIZER_CALLBACK => static function (
MessageLocalizer $messageLocalizer,
ClaimDiffer $claimDiffer,
ClaimDifferenceVisualizer $claimDiffView,
SiteLookup $siteLookup,
EntityIdFormatter $entityIdFormatter
) {
return new BasicMediaInfoDiffVisualizer(
$messageLocalizer,
$claimDiffer,
$claimDiffView
);
},
Def::ENTITY_METADATA_ACCESSOR_CALLBACK => static function ( $dbName, $repoName ) {
$entityNamespaceLookup = WikibaseRepo::getEntityNamespaceLookup();
$entityQuery = new MediaInfoEntityQuery(
$entityNamespaceLookup,
MediaWikiServices::getInstance()->getSlotRoleStore()
);
$entitySource = WikibaseRepo::getEntitySourceDefinitions()
->getDatabaseSourceForEntityType( MediaInfo::ENTITY_TYPE );
return new WikiPageEntityMetaDataLookup(
$entityNamespaceLookup,
$entityQuery,
$entitySource,
WikibaseRepo::getRepoDomainDbFactory()->newForEntitySource( $entitySource ),
WikibaseRepo::getLogger()
);
},
Def::RDF_BUILDER_FACTORY_CALLBACK => static function (
$flavorFlags,
RdfVocabulary $vocabulary,
RdfWriter $writer,
EntityMentionListener $tracker,
DedupeBag $dedupe
) {
$services = MediaWikiServices::getInstance();
$entityTypeDefinitions = WikibaseRepo::getEntityTypeDefinitions( $services );
$termsRdfBuilder = new TermsRdfBuilder(
$vocabulary,
$writer,
$entityTypeDefinitions->get( EntityTypeDefinitions::RDF_LABEL_PREDICATES )
);
$propertyDataLookup = WikibaseRepo::getPropertyDataTypeLookup();
$valueSnakRdfBuilderFactory = new ValueSnakRdfBuilderFactory(
WikibaseRepo::getDataTypeDefinitions( $services )
->getRdfBuilderFactoryCallbacks( DataTypeDefinitions::PREFIXED_MODE ),
WikibaseRepo::getLogger( $services )
);
$truthyStatementRdfBuilderFactory = new TruthyStatementRdfBuilderFactory(
$dedupe,
$vocabulary,
$writer,
$valueSnakRdfBuilderFactory,
$tracker,
$propertyDataLookup
);
$fullStatementRdfBuilderFactory = new FullStatementRdfBuilderFactory(
$vocabulary,
$writer,
$valueSnakRdfBuilderFactory,
$tracker,
$dedupe,
$propertyDataLookup
);
$mediaInfoSpecificComponentsRdfBuilder = new MediaInfoSpecificComponentsRdfBuilder(
$vocabulary,
$writer,
MediaInfoServices::getMediaInfoHandler(),
MediaWikiServices::getInstance()->getRepoGroup()
);
return new MediaInfoRdfBuilder(
$flavorFlags,
$termsRdfBuilder,
$truthyStatementRdfBuilderFactory,
$fullStatementRdfBuilderFactory,
$mediaInfoSpecificComponentsRdfBuilder
);
},
Def::RDF_LABEL_PREDICATES => [
[ RdfVocabulary::NS_SCHEMA_ORG, 'caption' ],
[ 'rdfs', 'label' ],
],
Def::ENTITY_REVISION_LOOKUP_FACTORY_CALLBACK => static function (
EntityRevisionLookup $defaultLookup
) {
$services = MediaWikiServices::getInstance();
$revisionStoreFactory = $services->getRevisionStoreFactory();
$blobStoreFactory = $services->getBlobStoreFactory();
// TODO: this all scaffolding should probably be somehow moved to Wikibase Repo or so?
$databaseName = WikibaseRepo::getEntitySourceDefinitions()
->getDatabaseSourceForEntityType( MediaInfo::ENTITY_TYPE )->getDatabaseName();
$contentCodec = new EntityContentDataCodec(
WikibaseRepo::getEntityIdParser( $services ),
WikibaseRepo::getStorageEntitySerializer( $services ),
WikibaseRepo::getInternalFormatEntityDeserializer(),
WikibaseRepo::getDataAccessSettings( $services )->maxSerializedEntitySizeInBytes()
);
return new FilePageRedirectHandlingRevisionLookup(
new EntityIdFixingRevisionLookup(
$defaultLookup,
WikibaseRepo::getLogger( $services )
),
$revisionStoreFactory->getRevisionStore( $databaseName ),
new WikiPageEntityDataLoader(
$contentCodec,
$blobStoreFactory->newBlobStore( $databaseName ),
$databaseName
)
);
},
Def::PREFETCHING_TERM_LOOKUP_CALLBACK => static function ( EntitySource $entitySource ) {
return new MediaInfoPrefetchingTermLookup( WikibaseRepo::getEntityRevisionLookup() );
},
Def::ENTITY_ID_LOOKUP_CALLBACK => static function () {
return MediaInfoServices::getMediaInfoIdLookup();
},
Def::LUA_ENTITY_MODULE => 'mw.wikibase.mediainfo.entity',
Def::URL_LOOKUP_CALLBACK => static function () {
return new TitleLookupBasedEntityUrlLookup( WikibaseRepo::getEntityTitleLookup() );
},
Def::EXISTENCE_CHECKER_CALLBACK => static function () {
$services = MediaWikiServices::getInstance();
return new TitleLookupBasedEntityExistenceChecker(
WikibaseRepo::getEntityTitleLookup( $services ),
$services->getLinkBatchFactory()
);
},
Def::TITLE_TEXT_LOOKUP_CALLBACK => static function () {
return new TitleLookupBasedEntityTitleTextLookup(
WikibaseRepo::getEntityTitleLookup()
);
},
Def::REDIRECT_CHECKER_CALLBACK => static function () {
return new TitleLookupBasedEntityRedirectChecker( WikibaseRepo::getEntityTitleLookup() );
},
]
];