-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathWikibaseLexeme.mediawiki-services.php
217 lines (208 loc) · 8.24 KB
/
WikibaseLexeme.mediawiki-services.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
<?php
use MediaWiki\MediaWikiServices;
use Wikibase\DataModel\Deserializers\TermDeserializer;
use Wikibase\DataModel\Entity\ItemIdParser;
use Wikibase\DataModel\Services\Statement\GuidGenerator;
use Wikibase\Lexeme\DataAccess\ChangeOp\Validation\LemmaTermValidator;
use Wikibase\Lexeme\DataAccess\ChangeOp\Validation\LexemeTermLanguageValidator;
use Wikibase\Lexeme\DataAccess\ChangeOp\Validation\LexemeTermSerializationValidator;
use Wikibase\Lexeme\DataAccess\Store\EntityLookupLemmaLookup;
use Wikibase\Lexeme\DataAccess\Store\MediaWikiLexemeRedirector;
use Wikibase\Lexeme\Domain\EntityReferenceExtractors\FormsStatementEntityReferenceExtractor;
use Wikibase\Lexeme\Domain\EntityReferenceExtractors\LexemeStatementEntityReferenceExtractor;
use Wikibase\Lexeme\Domain\EntityReferenceExtractors\SensesStatementEntityReferenceExtractor;
use Wikibase\Lexeme\Domain\Merge\LexemeFormsMerger;
use Wikibase\Lexeme\Domain\Merge\LexemeMerger;
use Wikibase\Lexeme\Domain\Merge\LexemeSensesMerger;
use Wikibase\Lexeme\Domain\Merge\NoCrossReferencingLexemeStatements;
use Wikibase\Lexeme\Interactors\MergeLexemes\MergeLexemesInteractor;
use Wikibase\Lexeme\Presentation\ChangeOp\Deserialization\EditFormChangeOpDeserializer;
use Wikibase\Lexeme\Presentation\ChangeOp\Deserialization\ItemIdListDeserializer;
use Wikibase\Lexeme\Presentation\ChangeOp\Deserialization\RepresentationsChangeOpDeserializer;
use Wikibase\Lexeme\WikibaseLexemeServices;
use Wikibase\Lib\StaticContentLanguages;
use Wikibase\Lib\Store\CachingItemOrderProvider;
use Wikibase\Lib\Store\ItemOrderProvider;
use Wikibase\Lib\Store\LookupConstants;
use Wikibase\Lib\Store\WikiPageItemOrderProvider;
use Wikibase\Lib\UnionContentLanguages;
use Wikibase\Lib\WikibaseContentLanguages;
use Wikibase\Repo\ChangeOp\Deserialization\ClaimsChangeOpDeserializer;
use Wikibase\Repo\EntityReferenceExtractors\StatementEntityReferenceExtractor;
use Wikibase\Repo\Store\Store;
use Wikibase\Repo\Validators\EntityExistsValidator;
use Wikibase\Repo\WikibaseRepo;
// TODO Replace by framework-agnostic DI container.
// Pimple e.g. is well known in the free world and yet part of mediawiki-vendor
// Challenge: Dedicated API endpoints (e.g. AddForm) need to have it passed w/o singletons/globals
return call_user_func( static function () {
// TODO Problem when removing a code after such a Lexeme exists in DB?!
// These are not supported by Wikibase for monolingual text and some should probably not be supported here either,
// but keep these for backwards compatibility.
$additionalTermLanguages = [
'bat-smg',
'be-x-old',
'ccp-beng', // T272442
'cdz-beng', // T371773
'de-formal',
'eo-hsistemo', // T257422
'eo-xsistemo', // T257422
'es-formal',
'fiu-vro',
'ha-arab', // T282512
'hu-formal',
'ksy-beng', // T371773
'kyw-beng', // T371773
'kyw-deva', // T371773
'lad-hebr', // T308794
'mjx-beng', // T371773
'nl-informal',
'nn-hognorsk', // T235344
'pt-ao1990', // T270043
'pt-colb1945', // T270043
'rhg-rohg', // T272442
'roa-rup',
'sat-latn', // T262967
'sat-beng', // T262967
'sat-orya', // T262967
'simple',
'sux-latn', // T282512
'sux-xsux', // T282512
'syl-beng', // T267480
'txo-beng', // T371773
'zh-classical',
'zh-min-nan',
'zh-yue',
];
return [
'WikibaseLexemeTermLanguages' => static function (
MediaWikiServices $mediawikiServices
) use (
$additionalTermLanguages
): UnionContentLanguages {
return new UnionContentLanguages(
new StaticContentLanguages( $additionalTermLanguages ),
WikibaseContentLanguages::getDefaultMonolingualTextLanguages(
$mediawikiServices->getLanguageNameUtils()
)
);
},
'WikibaseLexemeMobileView' =>
static function ( MediaWikiServices $mediawikiServices ): bool {
if ( $mediawikiServices->hasService( 'MobileFrontend.Context' ) ) {
$mobileContext = $mediawikiServices->getService( 'MobileFrontend.Context' );
return $mobileContext->shouldDisplayMobileView();
}
return false;
},
'WikibaseLexemeLemmaLookup' =>
static function ( MediaWikiServices $mediawikiServices ): EntityLookupLemmaLookup {
return new EntityLookupLemmaLookup( WikibaseRepo::getEntityLookup( $mediawikiServices ) );
},
'WikibaseLexemeLemmaTermValidator' => static function (
MediaWikiServices $services
): LemmaTermValidator {
// TODO: move to setting
return new LemmaTermValidator( LemmaTermValidator::LEMMA_MAX_LENGTH );
},
'WikibaseLexemeEditFormChangeOpDeserializer' => static function (
MediaWikiServices $mediaWikiServices
): EditFormChangeOpDeserializer {
$entityLookup = WikibaseRepo::getStore( $mediaWikiServices )->getEntityLookup(
Store::LOOKUP_CACHING_DISABLED,
LookupConstants::LATEST_FROM_MASTER
);
return new EditFormChangeOpDeserializer(
new RepresentationsChangeOpDeserializer(
new TermDeserializer(),
WikibaseRepo::getStringNormalizer( $mediaWikiServices ),
new LexemeTermSerializationValidator(
new LexemeTermLanguageValidator(
WikibaseLexemeServices::getTermLanguages( $mediaWikiServices )
)
)
),
new ItemIdListDeserializer( new ItemIdParser() ),
new ClaimsChangeOpDeserializer(
WikibaseRepo::getExternalFormatStatementDeserializer( $mediaWikiServices ),
WikibaseRepo::getChangeOpFactoryProvider( $mediaWikiServices )
->getStatementChangeOpFactory()
),
new EntityExistsValidator( $entityLookup, 'item' )
);
},
'WikibaseLexemeGrammaticalFeaturesOrderProvider' => static function (
MediaWikiServices $mediaWikiServices
): ItemOrderProvider {
$grammaticalFeaturesOrderProvider = new CachingItemOrderProvider(
new WikiPageItemOrderProvider(
$mediaWikiServices->getWikiPageFactory(),
$mediaWikiServices->getTitleFactory()
->makeTitle( NS_MEDIAWIKI, 'WikibaseLexeme-SortedGrammaticalFeatures' )
),
$mediaWikiServices->getObjectCacheFactory()->getLocalClusterInstance(),
'wikibaseLexeme-grammaticalFeaturesOrderProvider'
);
return $grammaticalFeaturesOrderProvider;
},
'WikibaseLexemeMergeLexemesInteractor' => static function (
MediaWikiServices $mediaWikiServices
): MergeLexemesInteractor {
// this service wiring creates quite a few intermediate services,
// which so far haven’t been needed as separate services;
// there’s no particular reason against extracting them either, though,
// if that’s needed in future :)
$baseExtractor = new StatementEntityReferenceExtractor(
WikibaseRepo::getItemUrlParser( $mediaWikiServices )
);
$noCrossReferencingLexemeStatements = new NoCrossReferencingLexemeStatements(
new LexemeStatementEntityReferenceExtractor(
$baseExtractor,
new FormsStatementEntityReferenceExtractor( $baseExtractor ),
new SensesStatementEntityReferenceExtractor( $baseExtractor )
)
);
$statementsMerger = WikibaseRepo::getChangeOpFactoryProvider( $mediaWikiServices )
->getMergeFactory()
->getStatementsMerger();
$guidGenerator = new GuidGenerator();
$lexemeMerger = new LexemeMerger(
$statementsMerger,
new LexemeFormsMerger(
$statementsMerger,
$guidGenerator
),
new LexemeSensesMerger(
$guidGenerator
),
$noCrossReferencingLexemeStatements
);
$entityPermissionChecker = WikibaseRepo::getEntityPermissionChecker( $mediaWikiServices );
$store = WikibaseRepo::getStore( $mediaWikiServices );
$entityRevisionLookup = $store->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED );
$summaryFormatter = WikibaseRepo::getSummaryFormatter( $mediaWikiServices );
$entityTitleStoreLookup = WikibaseRepo::getEntityTitleStoreLookup( $mediaWikiServices );
$lexemeRedirector = new MediaWikiLexemeRedirector(
$entityRevisionLookup,
WikibaseRepo::getEntityStore( $mediaWikiServices ),
$entityPermissionChecker,
$summaryFormatter,
WikibaseRepo::getEditFilterHookRunner( $mediaWikiServices ),
$store->getEntityRedirectLookup(),
$entityTitleStoreLookup,
$mediaWikiServices->getTempUserCreator()
);
return new MergeLexemesInteractor(
$lexemeMerger,
$summaryFormatter,
$lexemeRedirector,
$entityPermissionChecker,
$mediaWikiServices->getPermissionManager(),
$entityTitleStoreLookup,
$mediaWikiServices->getWatchedItemStore(),
$entityRevisionLookup,
WikibaseRepo::getEditEntityFactory( $mediaWikiServices )
);
},
];
} );