Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes2.php |
— | — | @@ -1,372 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -require_once("Attribute.php"); |
5 | | -require_once("WikiDataGlobals.php"); |
6 | | -require_once("ViewInformation.php"); |
7 | | - |
8 | | -/** |
9 | | - * Replacement OmegaWikiAttributes. |
10 | | - * |
11 | | - * This file models the structure of the OmegaWiki database in a |
12 | | - * database-independent fashion. To do so, it follows a simplified |
13 | | - * relational model, consisting of Attribute objects which are hierarchically |
14 | | - * grouped together using Structure objects. See Attribute.php for details. |
15 | | - * |
16 | | - * The actual data is stored in Records, grouped together as RecordSets. |
17 | | - * See Record.php and RecordSet.php for details. |
18 | | - * |
19 | | - * TODO: |
20 | | - * - The current model of a ton of hardcoded globals is highly inadequate |
21 | | - * and should be replaced with a more abstract schema description. |
22 | | - * - Replacing with a single associative array. |
23 | | - * |
24 | | - * - Attribute names are in WikidataGlobals.php, but should really be |
25 | | - * localizable through MediaWiki's wfMsg() function. |
26 | | - * -This is step 2 |
27 | | - * - Records and RecordSets are currently capable of storing most (not all) |
28 | | - * data, but can't actually commit them to the database again. To achieve |
29 | | - * proper separation of architectural layers, the Records should learn |
30 | | - * to talk directly with the DB layer. |
31 | | - * -This is potentially what RecordHelpers are for. |
32 | | - * |
33 | | - */ |
34 | | -function initializeOmegaWikiAttributes(ViewInformation $viewInformation) { |
35 | | - global |
36 | | - $omegaWikiAttributes; |
37 | | - $omegaWikiAttributes= new OmegaWikiAttributes($viewInformation); |
38 | | -} |
39 | | - |
40 | | -class OmegaWikiAttributes { |
41 | | - protected $attributes = null; |
42 | | - function __construct(ViewInformation $viewInformation) { |
43 | | - $this->hardValues(); |
44 | | - } |
45 | | - |
46 | | - /** Hardcoded schema for now. Later refactor to load from file or DB |
47 | | - * |
48 | | - * Naming: keys are previous name minus -"Attribute" |
49 | | - * (-"Structure" is retained) |
50 | | - */ |
51 | | - private function hardValues() { |
52 | | - |
53 | | - $a=$this->attributes; # <- wrist/RSI protection |
54 | | - |
55 | | - # TODO these will be replaced with i18n |
56 | | - global |
57 | | - $wgLanguageAttributeName, $wgSpellingAttributeName, $wgTextAttributeName; |
58 | | - |
59 | | - $a["language"] = new Attribute("language", $wgLanguageAttributeName, "language"); |
60 | | - $a["spelling"] = new Attribute("spelling", $wgSpellingAttributeName, "spelling"); |
61 | | - $a["text"] = new Attribute("text", $wgTextAttributeName, "text"); |
62 | | - |
63 | | - #TODO replace with i18n |
64 | | - global |
65 | | - $wgDefinedMeaningAttributesAttributeName, |
66 | | - $wgDefinedMeaningAttributesAttributeName, |
67 | | - $wgAnnotationAttributeName; |
68 | | - |
69 | | - $a["definedMeaningAttributes"] = new Attribute("defined-meaning-attributes", $wgDefinedMeaningAttributesAttributeName, "will-be-specified-below"); |
70 | | - $a["objectAttributes"] = new Attribute("object-attributes", $wgAnnotationAttributeName, "will-be-specified-below"); |
71 | | - |
72 | | - # TODO replace with i18n |
73 | | - global |
74 | | - $expressionIdAttribute, $identicalMeaningAttribute; |
75 | | - |
76 | | - $a["expressionId"] = new Attribute("expression-id", "Expression Id", "expression-id"); |
77 | | - $a["identicalMeaning"] = new Attribute("indentical-meaning", $wgIdenticalMeaningAttributeName, "boolean"); |
78 | | - |
79 | | - #TODO replace with i18n |
80 | | - global |
81 | | - $wgExpressionAttributeName; |
82 | | - |
83 | | - if ($viewInformation->filterOnLanguage()) |
84 | | - $a["expression"] = new Attribute("expression", $wgSpellingAttributeName, "spelling"); |
85 | | - else { |
86 | | - $a["expressionStructure"] = new Structure("expression", $languageAttribute, $spellingAttribute); |
87 | | - $a["expression"] = new Attribute(null, $wgExpressionAttributeName, $expressionStructure); |
88 | | - } |
89 | | - |
90 | | - global |
91 | | - $definedMeaningIdAttribute, $definedMeaningDefiningExpressionAttribute, |
92 | | - $definedMeaningCompleteDefiningExpressionStructure, |
93 | | - $definedMeaningCompleteDefiningExpressionAttribute; |
94 | | - |
95 | | - $a["definedMeaningId"] = new Attribute("defined-meaning-id", "Defined meaning identifier", "defined-meaning-id"); |
96 | | - $a["definedMeaningDefiningExpression"] = new Attribute("defined-meaning-defining-expression", "Defined meaning defining expression", "short-text"); |
97 | | - |
98 | | - $a["definedMeaningCompleteDefiningExpressionStructure"] = |
99 | | - new Structure("defined-meaning-full-defining-expression", |
100 | | - $definedMeaningDefiningExpressionAttribute, |
101 | | - $expressionIdAttribute, |
102 | | - $languageAttribute |
103 | | - ); |
104 | | - $a["definedMeaningCompleteDefiningExpression"]=new Attribute(null, "Defining expression", $definedMeaningCompleteDefiningExpressionStructure); |
105 | | - |
106 | | - #============================================== |
107 | | - # Done refactoring up to here (to maintain sanity, will do a little every day |
108 | | - # if you want to do a good deed, shift this line down please) |
109 | | - # =============================================== |
110 | | - |
111 | | - global |
112 | | - $definedMeaningReferenceStructure, $definedMeaningLabelAttribute, $definedMeaningReferenceType, |
113 | | - $definedMeaningReferenceAttribute, $wgDefinedMeaningReferenceAttributeName; |
114 | | - |
115 | | - $definedMeaningLabelAttribute = new Attribute("defined-meaning-label", "Defined meaning label", "short-text"); |
116 | | - $definedMeaningReferenceStructure = new Structure("defined-meaning", $definedMeaningIdAttribute, $definedMeaningLabelAttribute, $definedMeaningDefiningExpressionAttribute); |
117 | | - |
118 | | - $definedMeaningReferenceType = $definedMeaningReferenceStructure; |
119 | | - $definedMeaningReferenceAttribute = new Attribute(null, $wgDefinedMeaningReferenceAttributeName, $definedMeaningReferenceType); |
120 | | - |
121 | | - global |
122 | | - $collectionIdAttribute, $collectionMeaningAttribute, $sourceIdentifierAttribute, |
123 | | - $gotoSourceStructure, $gotoSourceAttribute, |
124 | | - $wgCollectionAttributeName, $wgSourceIdentifierAttributeName, $wgGotoSourceAttributeName; |
125 | | - |
126 | | - $collectionIdAttribute = new Attribute("collection", "Collection", "collection-id"); |
127 | | - $collectionMeaningAttribute = new Attribute("collection-meaning", $wgCollectionAttributeName, $definedMeaningReferenceStructure); |
128 | | - $sourceIdentifierAttribute = new Attribute("source-identifier", $wgSourceIdentifierAttributeName, "short-text"); |
129 | | - $gotoSourceStructure = new Structure("goto-source",$collectionIdAttribute, $sourceIdentifierAttribute); |
130 | | - $gotoSourceAttribute = new Attribute(null, $wgGotoSourceAttributeName, $gotoSourceStructure); |
131 | | - |
132 | | - global |
133 | | - $collectionMembershipAttribute, $wgCollectionMembershipAttributeName, $wgCollectionMembershipAttributeId, |
134 | | - $collectionMembershipStructure; |
135 | | - |
136 | | - $collectionMembershipStructure = new Structure("collection-membership",$collectionIdAttribute, $collectionMeaningAttribute, $sourceIdentifierAttribute); |
137 | | - $collectionMembershipAttribute = new Attribute(null, $wgCollectionMembershipAttributeName, $collectionMembershipStructure); |
138 | | - |
139 | | - global |
140 | | - $classMembershipIdAttribute, $classAttribute; |
141 | | - |
142 | | - $classMembershipIdAttribute = new Attribute("class-membership-id", "Class membership id", "integer"); |
143 | | - $classAttribute = new Attribute("class", "Class", $definedMeaningReferenceStructure); |
144 | | - |
145 | | - global |
146 | | - $classMembershipStructure, $classMembershipKeyStructure, $classMembershipAttribute, |
147 | | - $wgClassMembershipAttributeName, $wgClassMembershipAttributeId; |
148 | | - |
149 | | - $classMembershipStructure = new Structure("class-membership", $classMembershipIdAttribute, $classAttribute); |
150 | | - $classMembershipAttribute = new Attribute(null, $wgClassMembershipAttributeName, $classMembershipStructure); |
151 | | - |
152 | | - global |
153 | | - $possiblySynonymousIdAttribute, |
154 | | - $possibleSynonymAttribute, |
155 | | - $wgPossibleSynonymAttributeName, $possiblySynonymousStructure, $possiblySynonymousAttribute, |
156 | | - $wgPossiblySynonymousAttributeName, $wgPossiblySynonymousAttributeId; |
157 | | - |
158 | | - $possiblySynonymousIdAttribute = new Attribute("possibly-synonymous-id", "Possibly synonymous id", "integer"); |
159 | | - $possibleSynonymAttribute = new Attribute("possible-synonym", $wgPossibleSynonymAttributeName, $definedMeaningReferenceStructure); |
160 | | - $possiblySynonymousStructure = new Structure("possibly-synonymous", $possiblySynonymousIdAttribute, $possiblySynonymousAttribute); |
161 | | - $possiblySynonymousAttribute = new Attribute(null, $wgPossiblySynonymousAttributeName, $possiblySynonymousStructure); |
162 | | - |
163 | | - global |
164 | | - $relationIdAttribute, $relationTypeAttribute, $relationTypeType, $otherDefinedMeaningAttribute, |
165 | | - $wgRelationTypeAttributeName, $wgOtherDefinedMeaningAttributeName; |
166 | | - |
167 | | - $relationIdAttribute = new Attribute("relation-id", "Relation identifier", "object-id"); |
168 | | - $relationTypeAttribute = new Attribute("relation-type", $wgRelationTypeAttributeName, $definedMeaningReferenceStructure); |
169 | | - $otherDefinedMeaningAttribute = new Attribute("other-defined-meaning", $wgOtherDefinedMeaningAttributeName, $definedMeaningReferenceType); |
170 | | - |
171 | | - global |
172 | | - $relationsAttribute, $relationStructure, $reciprocalRelationsAttribute, $objectAttributesAttribute, $wgRelationsAttributeName, $wgIncomingRelationsAttributeName, $wgRelationsAttributeId, $wgIncomingRelationsAttributeId, |
173 | | - $repRelStructure; |
174 | | - |
175 | | - $relationStructure = new Structure("relations", $relationIdAttribute, $relationTypeAttribute, $otherDefinedMeaningAttribute, $objectAttributesAttribute); |
176 | | - $relationsAttribute = new Attribute(null, $wgRelationsAttributeName, $relationStructure); |
177 | | - $reciprocalRelationsAttribute = new Attribute("reciprocal-relations", $wgIncomingRelationsAttributeName, $relationStructure); |
178 | | - |
179 | | - global |
180 | | - $translatedTextIdAttribute, $translatedTextStructure; |
181 | | - |
182 | | - $translatedTextIdAttribute = new Attribute("translated-text-id", "Translated text ID", "integer"); |
183 | | - $translatedTextStructure = new Structure("translated-text", $languageAttribute, $textAttribute); |
184 | | - |
185 | | - global |
186 | | - $definitionIdAttribute, $alternativeDefinitionAttribute, $sourceAttribute, |
187 | | - $wgAlternativeDefinitionAttributeName, $wgSourceAttributeName; |
188 | | - |
189 | | - $definitionIdAttribute = new Attribute("definition-id", "Definition identifier", "integer"); |
190 | | - |
191 | | - if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes()) |
192 | | - $alternativeDefinitionAttribute = new Attribute("alternative-definition", $wgAlternativeDefinitionAttributeName, "text"); |
193 | | - else |
194 | | - $alternativeDefinitionAttribute = new Attribute("alternative-definition", $wgAlternativeDefinitionAttributeName, $translatedTextStructure); |
195 | | - |
196 | | - $sourceAttribute = new Attribute("source-id", $wgSourceAttributeName, $definedMeaningReferenceType); |
197 | | - |
198 | | - global |
199 | | - $alternativeDefinitionsAttribute, $wgAlternativeDefinitionsAttributeName, $wgAlternativeDefinitionsAttributeId, |
200 | | - $alternativeDefinitionsStructure; |
201 | | - |
202 | | - $alternativeDefinitionsStructure = new Structure("alternative-definitions", $definitionIdAttribute, $alternativeDefinitionAttribute, $sourceAttribute); |
203 | | - |
204 | | - $alternativeDefinitionsAttribute = new Attribute(null, $wgAlternativeDefinitionsAttributeName, $alternativeDefinitionsStructure); |
205 | | - |
206 | | - global |
207 | | - $synonymsAndTranslationsAttribute, $syntransIdAttribute, |
208 | | - $wgSynonymsAttributeName, $wgSynonymsAndTranslationsAttributeName, $wgSynonymsAndTranslationsAttributeId, |
209 | | - $synonymsTranslationsStructure; |
210 | | - |
211 | | - if ($viewInformation->filterOnLanguage()) |
212 | | - $synonymsAndTranslationsCaption = $wgSynonymsAttributeName; |
213 | | - else |
214 | | - $synonymsAndTranslationsCaption = $wgSynonymsAndTranslationsAttributeName; |
215 | | - |
216 | | - $syntransIdAttribute = new Attribute("syntrans-id", "$synonymsAndTranslationsCaption identifier", "integer"); |
217 | | - $synonymsTranslationsStructure = new Structure("synonyms-translations", $syntransIdAttribute, $expressionAttribute, $identicalMeaningAttribute, $objectAttributesAttribute); |
218 | | - $synonymsAndTranslationsAttribute = new Attribute(null, "$synonymsAndTranslationsCaption", $synonymsTranslationsStructure); |
219 | | - |
220 | | - global |
221 | | - $translatedTextAttributeIdAttribute, $translatedTextValueIdAttribute, |
222 | | - $translatedTextAttributeObjectAttribute, $translatedTextAttributeAttribute, $translatedTextValueAttribute, $translatedTextAttributeValuesAttribute, |
223 | | - $translatedTextAttributeValuesStructure, $wgTranslatedTextAttributeValuesAttributeName, $wgTranslatedTextAttributeAttributeName, $wgTranslatedTextAttributeValueAttributeName; |
224 | | - |
225 | | - $translatedTextAttributeIdAttribute = new Attribute("translated-text-attribute-id", "Attribute identifier", "object-id"); |
226 | | - $translatedTextAttributeObjectAttribute = new Attribute("translated-text-attribute-object-id", "Attribute object", "object-id"); |
227 | | - $translatedTextAttributeAttribute = new Attribute("translated-text-attribute", $wgTranslatedTextAttributeAttributeName, $definedMeaningReferenceType); |
228 | | - $translatedTextValueIdAttribute = new Attribute("translated-text-value-id", "Translated text value identifier", "translated-text-value-id"); |
229 | | - |
230 | | - if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes()) |
231 | | - $translatedTextValueAttribute = new Attribute("translated-text-value", $wgTranslatedTextAttributeValueAttributeName, "text"); |
232 | | - else |
233 | | - $translatedTextValueAttribute = new Attribute("translated-text", $wgTranslatedTextAttributeValueAttributeName, $translatedTextStructure); |
234 | | - |
235 | | - $translatedTextAttributeValuesStructure = new Structure("translated-text-attribute-values",$translatedTextAttributeIdAttribute, $translatedTextAttributeObjectAttribute, $translatedTextAttributeAttribute, $translatedTextValueIdAttribute, $translatedTextValueAttribute, $objectAttributesAttribute); |
236 | | - $translatedTextAttributeValuesAttribute = new Attribute(null, $wgTranslatedTextAttributeValuesAttributeName, $translatedTextAttributeValuesStructure); |
237 | | - |
238 | | - global |
239 | | - $textAttributeIdAttribute, $textAttributeObjectAttribute, $textAttributeAttribute, $textAttributeValuesStructure, |
240 | | - $textAttributeValuesAttribute, |
241 | | - $wgTextAttributeValuesAttributeName, $wgTextAttributeAttributeName; |
242 | | - |
243 | | - $textAttributeIdAttribute = new Attribute("text-attribute-id", "Attribute identifier", "object-id"); |
244 | | - $textAttributeObjectAttribute = new Attribute("text-attribute-object-id", "Attribute object", "object-id"); |
245 | | - $textAttributeAttribute = new Attribute("text-attribute", $wgTextAttributeAttributeName, $definedMeaningReferenceStructure); |
246 | | - $textAttributeValuesStructure = new Structure("text-attribute-values", $textAttributeIdAttribute, $textAttributeObjectAttribute, $textAttributeAttribute, $textAttribute, $objectAttributesAttribute); |
247 | | - $textAttributeValuesAttribute = new Attribute(null, $wgTextAttributeValuesAttributeName, $textAttributeValuesStructure); |
248 | | - |
249 | | - global |
250 | | - $urlAttribute, $urlAttributeIdAttribute, $urlAttributeObjectAttribute, $urlAttributeAttribute, $urlAttributeValuesStructure, $urlAttributeValuesAttribute, |
251 | | - $wgUrlAttributeValuesAttributeName, $wgUrlAttributeAttributeName; |
252 | | - |
253 | | - $urlAttribute = new Attribute("url", "URL", "url"); |
254 | | - $urlAttributeIdAttribute = new Attribute("url-attribute-id", "Attribute identifier", "object-id"); |
255 | | - $urlAttributeObjectAttribute = new Attribute("url-attribute-object-id", "Attribute object", "object-id"); |
256 | | - $urlAttributeAttribute = new Attribute("url-attribute", $wgUrlAttributeAttributeName, $definedMeaningReferenceStructure); |
257 | | - $urlAttributeValuesStructure = new Structure("url-attribute-values", $urlAttributeIdAttribute, $urlAttributeObjectAttribute, $urlAttributeAttribute, $urlAttribute, $objectAttributesAttribute); |
258 | | - $urlAttributeValuesAttribute = new Attribute(null, $wgUrlAttributeValuesAttributeName, $urlAttributeValuesStructure); |
259 | | - |
260 | | - global |
261 | | - $optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionAttribute, $optionAttributeValuesAttribute, |
262 | | - $wgOptionAttributeAttributeName, $wgOptionAttributeOptionAttributeName, $wgOptionAttributeValuesAttributeName, $optionAttributeValuesStructure; |
263 | | - |
264 | | - $optionAttributeIdAttribute = new Attribute('option-attribute-id', 'Attribute identifier', 'object-id'); |
265 | | - $optionAttributeObjectAttribute = new Attribute('option-attribute-object-id', 'Attribute object', 'object-id'); |
266 | | - $optionAttributeAttribute = new Attribute('option-attribute', $wgOptionAttributeAttributeName, $definedMeaningReferenceType); |
267 | | - $optionAttributeOptionAttribute = new Attribute('option-attribute-option', $wgOptionAttributeOptionAttributeName, $definedMeaningReferenceType); |
268 | | - $optionAttributeValuesStructure = new Structure('option-attribute-values', $optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionAttribute, $objectAttributesAttribute); |
269 | | - $optionAttributeValuesAttribute = new Attribute(null, $wgOptionAttributeValuesAttributeName, $optionAttributeValuesStructure); |
270 | | - |
271 | | - global |
272 | | - $optionAttributeOptionIdAttribute, $optionAttributeOptionsAttribute, $wgOptionAttributeOptionsAttributeName; |
273 | | - |
274 | | - $optionAttributeOptionIdAttribute = new Attribute('option-attribute-option-id', 'Option identifier', 'object-id'); |
275 | | - $optionAttributeOptionsStructure = new Structure('option-attribute-options', $optionAttributeOptionIdAttribute, $optionAttributeAttribute, $optionAttributeOptionAttribute, $languageAttribute); |
276 | | - $optionAttributeOptionsAttribute = new Attribute(null, $wgOptionAttributeOptionsAttributeName, $optionAttributeOptionsStructure); |
277 | | - |
278 | | - global |
279 | | - $definitionAttribute, $translatedTextAttribute, $classAttributesAttribute, |
280 | | - $wgDefinitionAttributeName, $wgTranslatedTextAttributeName; |
281 | | - |
282 | | - if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes()) |
283 | | - $translatedTextAttribute = new Attribute("translated-text", $wgTextAttributeName, "text"); |
284 | | - else |
285 | | - $translatedTextAttribute = new Attribute(null, $wgTranslatedTextAttributeName, $translatedTextStructure); |
286 | | - |
287 | | - $definitionAttribute = new Attribute(null, $wgDefinitionAttributeName, new Structure("definition", $translatedTextAttribute, $objectAttributesAttribute)); |
288 | | - |
289 | | - global |
290 | | - $classAttributesStructure, |
291 | | - // $classAttributeClassAttribute, |
292 | | - $classAttributeIdAttribute, $classAttributeAttributeAttribute, $classAttributeLevelAttribute, $classAttributeTypeAttribute, |
293 | | - $wgClassAttributeAttributeAttributeName, $wgClassAttributeLevelAttributeName, |
294 | | - $wgClassAttributeTypeAttributeName, $wgClassAttributesAttributeName, $wgClassAttributesAttributeId; |
295 | | - |
296 | | - $classAttributeIdAttribute = new Attribute("class-attribute-id", "Class attribute identifier", "object-id"); |
297 | | - $classAttributeAttributeAttribute = new Attribute("class-attribute-attribute", $wgClassAttributeAttributeAttributeName, $definedMeaningReferenceStructure); |
298 | | - $classAttributeLevelAttribute = new Attribute("class-attribute-level", $wgClassAttributeLevelAttributeName, $definedMeaningReferenceStructure); |
299 | | - $classAttributeTypeAttribute = new Attribute("class-attribute-type", $wgClassAttributeTypeAttributeName, "short-text"); |
300 | | - $classAttributesStructure = new Structure("class-attributes", $classAttributeIdAttribute, $classAttributeAttributeAttribute, $classAttributeLevelAttribute, $classAttributeTypeAttribute, $optionAttributeOptionsAttribute); |
301 | | - $classAttributesAttribute = new Attribute(null, $wgClassAttributesAttributeName, $classAttributesStructure); |
302 | | - |
303 | | - global |
304 | | - $definedMeaningAttribute, $wgDefinedMeaningAttributeName; |
305 | | - |
306 | | - $definedMeaningAttribute = new Attribute(null, $wgDefinedMeaningAttributeName, |
307 | | - new Structure( |
308 | | - "defined-meaning", |
309 | | - $definitionAttribute, |
310 | | - $classAttributesAttribute, |
311 | | - $alternativeDefinitionsAttribute, |
312 | | - $synonymsAndTranslationsAttribute, |
313 | | - $relationsAttribute, |
314 | | - $reciprocalRelationsAttribute, |
315 | | - $classMembershipAttribute, |
316 | | - $collectionMembershipAttribute, |
317 | | - $definedMeaningAttributesAttribute) |
318 | | - ); |
319 | | - |
320 | | - global |
321 | | - $expressionsAttribute, $expressionMeaningStructure, $expressionExactMeaningsAttribute, $expressionApproximateMeaningsAttribute, |
322 | | - $wgExactMeaningsAttributeName, $wgApproximateMeaningsAttributeName; |
323 | | - |
324 | | - $expressionMeaningStructure = new Structure("expression-exact-meanings", $definedMeaningIdAttribute, $textAttribute, $definedMeaningAttribute); |
325 | | - $expressionExactMeaningsAttribute = new Attribute(null, $wgExactMeaningsAttributeName, $expressionMeaningStructure); |
326 | | - $expressionApproximateMeaningsAttribute = new Attribute("expression-approximate-meanings", $wgApproximateMeaningsAttributeName, $expressionMeaningStructure); |
327 | | - |
328 | | - global |
329 | | - $expressionMeaningsAttribute, $expressionMeaningsStructure, $expressionApproximateMeaningAttribute, |
330 | | - $wgExpressionMeaningsAttributeName, $wgExpressionsAttributeName, |
331 | | - $expressionsStructure; |
332 | | - |
333 | | - $expressionMeaningsStructure = new Structure("expression-meanings", $expressionExactMeaningsAttribute, $expressionApproximateMeaningAttribute); |
334 | | - $expressionMeaningsAttribute = new Attribute(null, $wgExpressionMeaningsAttributeName, $expressionMeaningsStructure); |
335 | | - |
336 | | - $expressionsStructure = new Structure("expressions", $expressionIdAttribute, $expressionAttribute, $expressionMeaningsAttribute); |
337 | | - $expressionsAttribute = new Attribute(null, $wgExpressionsAttributeName, $expressionsStructure); |
338 | | - |
339 | | - global |
340 | | - $objectIdAttribute, $objectAttributesStructure, $wgAnnotationAttributeName; |
341 | | - |
342 | | - $objectIdAttribute = new Attribute("object-id", "Object identifier", "object-id"); |
343 | | - $objectAttributesStructure = new Structure("object-attributes", $objectIdAttribute, $textAttributeValuesAttribute, $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute); |
344 | | - $objectAttributesAttribute->setAttributeType($objectAttributesStructure); |
345 | | - $definedMeaningAttributesAttribute->setAttributeType($objectAttributesStructure); |
346 | | - |
347 | | - global $wdDefinedMeaningAttributesOrder; |
348 | | - |
349 | | - /** |
350 | | - * This global determines the order of the different |
351 | | - * attributes in the user interface. |
352 | | - */ |
353 | | - $wdDefinedMeaningAttributesOrder=array( |
354 | | - $definitionAttribute->id, |
355 | | - $classAttributesAttribute->id, |
356 | | - $alternativeDefinitionsAttribute->id, |
357 | | - $synonymsAndTranslationsAttribute->id, |
358 | | - $possiblySynonymousAttribute->id, |
359 | | - $relationsAttribute->id, |
360 | | - $reciprocalRelationsAttribute->id, |
361 | | - $classMembershipAttribute->id, |
362 | | - $collectionMembershipAttribute->id, |
363 | | - $definedMeaningAttributesAttribute->id |
364 | | - ); |
365 | | - } |
366 | | - |
367 | | - function getAttribute($key) { |
368 | | - $attributes=$this->attributes; |
369 | | - return $attributes[$key]; |
370 | | - } |
371 | | -} |
372 | | - |
373 | | - |
Index: trunk/extensions/Wikidata/OmegaWiki/NeedsTranslationTo.php |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | |
50 | 50 | protected function showExpressionsNeedingTranslation($sourceLanguageId, $destinationLanguageId) { |
51 | 51 | global |
52 | | - $definedMeaningIdAttribute, $expressionIdAttribute, $expressionAttribute, $expressionStructure, $spellingAttribute, $languageAttribute; |
| 52 | + $definedMeaningIdAttribute, $expressionIdAttribute, $expressionAttribute, $expressionStructure, $omegaWikiAttributes; |
53 | 53 | |
54 | 54 | $dc=wdGetDataSetContext(); |
55 | 55 | |
— | — | @@ -72,14 +72,14 @@ |
73 | 73 | |
74 | 74 | while ($row = $dbr->fetchObject($queryResult)) { |
75 | 75 | $expressionRecord = new ArrayRecord($expressionStructure); |
76 | | - $expressionRecord->setAttributeValue($languageAttribute, $row->source_language_id); |
77 | | - $expressionRecord->setAttributeValue($spellingAttribute, $row->source_spelling); |
| 76 | + $expressionRecord->language = $row->source_language_id; |
| 77 | + $expressionRecord->spelling = $row->source_spelling; |
78 | 78 | |
79 | 79 | $recordSet->addRecord(array($row->source_defined_meaning_id, $row->source_expression_id, $expressionRecord, getDefinedMeaningDefinition($row->source_defined_meaning_id))); |
80 | 80 | } |
81 | 81 | |
82 | 82 | $expressionEditor = new RecordTableCellEditor($expressionAttribute); |
83 | | - $expressionEditor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), false)); |
| 83 | + $expressionEditor->addEditor(new LanguageEditor($omegaWikiAttributes->language, new SimplePermissionController(false), false)); |
84 | 84 | $expressionEditor->addEditor(new SpellingEditor($spellingAttribute, new SimplePermissionController(false), false)); |
85 | 85 | |
86 | 86 | $editor = new RecordSetTableEditor(null, new SimplePermissionController(false), new AllowAddController(false), false, false, null); |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php |
— | — | @@ -14,18 +14,38 @@ |
15 | 15 | * The actual data is stored in Records, grouped together as RecordSets. |
16 | 16 | * See Record.php and RecordSet.php for details. |
17 | 17 | * |
| 18 | + * OmegawikiAttributes2.php was running out of date already, so |
| 19 | + * merging here. |
| 20 | + * |
18 | 21 | * TODO: |
19 | 22 | * - The current model of a ton of hardcoded globals is highly inadequate |
20 | 23 | * and should be replaced with a more abstract schema description. |
| 24 | + * -replacing with a single associative array. |
21 | 25 | * - Attribute names are in WikidataGlobals.php, but should really be |
22 | 26 | * localizable through MediaWiki's wfMsg() function. |
| 27 | + * -this is step 2 |
23 | 28 | * - Records and RecordSets are currently capable of storing most (not all) |
24 | 29 | * data, but can't actually commit them to the database again. To achieve |
25 | 30 | * proper separation of architectural layers, the Records should learn |
26 | 31 | * to talk directly with the DB layer. |
27 | | - * |
| 32 | + * -this is what RecordHelpers are for. |
28 | 33 | */ |
29 | | -function initializeOmegaWikiAttributes(ViewInformation $viewInformation) { |
| 34 | + |
| 35 | +function initializeOmegaWikiAttributes(ViewInformation $viewInformation){ |
| 36 | + global |
| 37 | + $omegaWikiAttributes; // It would be even better if this was |
| 38 | + // passed to objects explicitly |
| 39 | + // but one step at a time... |
| 40 | + $omegaWikiAttributes= new OmegaWikiAttributes($viewInformation); |
| 41 | + initializeOmegaWikiAttributesOld($viewInformation); //backward compatibility, will be removed. |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +/** |
| 46 | + * Original initializeOmegaWikiAttributes, Do not call. |
| 47 | + * @deprecated use/update OmegaWikiAttributes->hardValues instead for now. |
| 48 | + */ |
| 49 | +function initializeOmegaWikiAttributesOld(ViewInformation $viewInformation) { |
30 | 50 | global |
31 | 51 | $languageAttribute, $spellingAttribute, $textAttribute, |
32 | 52 | $wgLanguageAttributeName, $wgSpellingAttributeName, $wgTextAttributeName; |
— | — | @@ -72,6 +92,8 @@ |
73 | 93 | $expressionIdAttribute, |
74 | 94 | $languageAttribute |
75 | 95 | ); |
| 96 | + |
| 97 | + # ====== refactored up to this point, do not make changes above this line ==== |
76 | 98 | $definedMeaningCompleteDefiningExpressionAttribute=new Attribute(null, "Defining expression", $definedMeaningCompleteDefiningExpressionStructure); |
77 | 99 | |
78 | 100 | |
— | — | @@ -333,3 +355,86 @@ |
334 | 356 | } |
335 | 357 | |
336 | 358 | |
| 359 | +class OmegaWikiAttributes { |
| 360 | + protected $attributes = array(); |
| 361 | + |
| 362 | + function __construct(ViewInformation $viewInformation) { |
| 363 | + $this->hardValues($viewInformation); |
| 364 | + } |
| 365 | + |
| 366 | + /** Hardcoded schema for now. Later refactor to load from file or DB |
| 367 | + * |
| 368 | + * Naming: keys are previous name minus -"Attribute" |
| 369 | + * (-"Structure" is retained, -"Attributes" is retained) |
| 370 | + */ |
| 371 | + private function hardValues($viewInformation) { |
| 372 | + |
| 373 | + $a=&$this->attributes; # <- wrist/RSI protection |
| 374 | + $t=$this; #<-idem |
| 375 | + |
| 376 | + global |
| 377 | + $wgLanguageAttributeName, $wgSpellingAttributeName, $wgTextAttributeName; |
| 378 | + |
| 379 | + $t->language = new Attribute("language", $wgLanguageAttributeName, "language"); |
| 380 | + $t->spelling = new Attribute("spelling", $wgSpellingAttributeName, "spelling"); |
| 381 | + $t->text= new Attribute("text", $wgTextAttributeName, "text"); |
| 382 | + |
| 383 | + /* |
| 384 | + $a->definedMeaningAttributes = new Attribute("defined-meaning-attributes", $wgDefinedMeaningAttributesAttributeName, "will-be-specified-below"); |
| 385 | + $a["objectAttributes"] = new Attribute("object-attributes", $wgAnnotationAttributeName, "will-be-specified-below"); |
| 386 | + |
| 387 | + # TODO replace with i18n |
| 388 | + global |
| 389 | + $expressionIdAttribute, $identicalMeaningAttribute; |
| 390 | + |
| 391 | + $a["expressionId"] = new Attribute("expression-id", "Expression Id", "expression-id"); |
| 392 | + $a["identicalMeaning"] = new Attribute("indentical-meaning", $wgIdenticalMeaningAttributeName, "boolean"); |
| 393 | + |
| 394 | + #TODO replace with i18n |
| 395 | + global |
| 396 | + $wgExpressionAttributeName; |
| 397 | + |
| 398 | + if ($viewInformation->filterOnLanguage()) |
| 399 | + $a["expression"] = new Attribute("expression", $wgSpellingAttributeName, "spelling"); |
| 400 | + else { |
| 401 | + $a["expressionStructure"] = new Structure("expression", $this->language, $this->spelling); |
| 402 | + $a["expression"] = new Attribute(null, $wgExpressionAttributeName, $expressionStructure); |
| 403 | + } |
| 404 | + |
| 405 | + global |
| 406 | + $definedMeaningIdAttribute, $definedMeaningDefiningExpressionAttribute, |
| 407 | + $definedMeaningCompleteDefiningExpressionStructure, |
| 408 | + $definedMeaningCompleteDefiningExpressionAttribute; |
| 409 | + |
| 410 | + $a["definedMeaningId"] = new Attribute("defined-meaning-id", "Defined meaning identifier", "defined-meaning-id"); |
| 411 | + $a["definedMeaningDefiningExpression"] = new Attribute("defined-meaning-defining-expression", "Defined meaning defining expression", "short-text"); |
| 412 | + |
| 413 | + $a["definedMeaningCompleteDefiningExpressionStructure"] = |
| 414 | + new Structure("defined-meaning-full-defining-expression", |
| 415 | + $definedMeaningDefiningExpressionAttribute, |
| 416 | + $expressionIdAttribute, |
| 417 | + $ |
| 418 | + ); |
| 419 | + $a["definedMeaningCompleteDefiningExpression"]=new Attribute(null, "Defining expression", $definedMeaningCompleteDefiningExpressionStructure); |
| 420 | + ); |
| 421 | + */ |
| 422 | + } |
| 423 | + |
| 424 | + |
| 425 | + protected function __set($key,$value) { |
| 426 | + $attributes=&$this->attributes; |
| 427 | + $attributes[$key]=$value; |
| 428 | + |
| 429 | + } |
| 430 | + |
| 431 | + public function __get($key) { |
| 432 | + $attributes=&$this->attributes; |
| 433 | + if (!array_key_exists($key, $attributes)) { |
| 434 | + throw new Exception("Key does not exist"); |
| 435 | + } |
| 436 | + return $attributes[$key]; |
| 437 | + } |
| 438 | +} |
| 439 | + |
| 440 | + |
| 441 | + |
Index: trunk/extensions/Wikidata/OmegaWiki/Controller.php |
— | — | @@ -43,10 +43,10 @@ |
44 | 44 | class DefinedMeaningDefinitionController implements UpdateController { |
45 | 45 | public function add($keyPath, $record) { |
46 | 46 | global |
47 | | - $definedMeaningIdAttribute, $languageAttribute, $textAttribute; |
| 47 | + $definedMeaningIdAttribute; |
48 | 48 | $definedMeaningId = $keyPath->peek(0)->getAttributeValue($definedMeaningIdAttribute); |
49 | | - $languageId = $record->getAttributeValue($languageAttribute); |
50 | | - $text = $record->getAttributeValue($textAttribute); |
| 49 | + $languageId = $record->language; |
| 50 | + $text = $record->text; |
51 | 51 | |
52 | 52 | if ($languageId != 0 && $text != "") |
53 | 53 | addDefinedMeaningDefinition($definedMeaningId, $languageId, $text); |
— | — | @@ -54,20 +54,20 @@ |
55 | 55 | |
56 | 56 | public function remove($keyPath) { |
57 | 57 | global |
58 | | - $definedMeaningIdAttribute, $languageAttribute; |
| 58 | + $definedMeaningIdAttribute; |
59 | 59 | |
60 | 60 | $definedMeaningId = $keyPath->peek(1)->getAttributeValue($definedMeaningIdAttribute); |
61 | | - $languageId = $keyPath->peek(0)->getAttributeValue($languageAttribute); |
| 61 | + $languageId = $keyPath->peek(0)->language; |
62 | 62 | removeDefinedMeaningDefinition($definedMeaningId, $languageId); |
63 | 63 | } |
64 | 64 | |
65 | 65 | public function update($keyPath, $record) { |
66 | 66 | global |
67 | | - $definedMeaningIdAttribute, $languageAttribute, $textAttribute; |
| 67 | + $definedMeaningIdAttribute; |
68 | 68 | |
69 | 69 | $definedMeaningId = $keyPath->peek(1)->getAttributeValue($definedMeaningIdAttribute); |
70 | | - $languageId = $keyPath->peek(0)->getAttributeValue($languageAttribute); |
71 | | - $text = $record->getAttributeValue($textAttribute); |
| 70 | + $languageId = $keyPath->peek(0)->language; |
| 71 | + $text = $record->text; |
72 | 72 | |
73 | 73 | if ($text != "") |
74 | 74 | updateDefinedMeaningDefinition($definedMeaningId, $languageId, $text); |
— | — | @@ -101,7 +101,7 @@ |
102 | 102 | |
103 | 103 | public function add($keyPath, $record) { |
104 | 104 | global |
105 | | - $definedMeaningIdAttribute, $alternativeDefinitionAttribute, $languageAttribute, $textAttribute, |
| 105 | + $definedMeaningIdAttribute, $alternativeDefinitionAttribute, |
106 | 106 | $sourceAttribute; |
107 | 107 | |
108 | 108 | $definedMeaningId = $keyPath->peek(0)->getAttributeValue($definedMeaningIdAttribute); |
— | — | @@ -112,8 +112,8 @@ |
113 | 113 | if ($alternativeDefinition->getRecordCount() > 0) { |
114 | 114 | $definitionRecord = $alternativeDefinition->getRecord(0); |
115 | 115 | |
116 | | - $languageId = $definitionRecord->getAttributeValue($languageAttribute); |
117 | | - $text = $definitionRecord->getAttributeValue($textAttribute); |
| 116 | + $languageId = $definitionRecord->language; |
| 117 | + $text = $definitionRecord->text; |
118 | 118 | |
119 | 119 | if ($languageId != 0 && $text != '') |
120 | 120 | addDefinedMeaningAlternativeDefinition($definedMeaningId, $languageId, $text, $sourceId); |
— | — | @@ -139,11 +139,11 @@ |
140 | 140 | class DefinedMeaningAlternativeDefinitionController implements UpdateController { |
141 | 141 | public function add($keyPath, $record) { |
142 | 142 | global |
143 | | - $expressionIdAttribute, $definitionIdAttribute, $languageAttribute, $textAttribute; |
| 143 | + $expressionIdAttribute, $definitionIdAttribute ; |
144 | 144 | |
145 | 145 | $definitionId = $keyPath->peek(0)->getAttributeValue($definitionIdAttribute); |
146 | | - $languageId = $record->getAttributeValue($languageAttribute); |
147 | | - $text = $record->getAttributeValue($textAttribute); |
| 146 | + $languageId = $record->language; |
| 147 | + $text = $record->text; |
148 | 148 | |
149 | 149 | if ($languageId != 0 && $text != "") |
150 | 150 | addTranslatedTextIfNotPresent($definitionId, $languageId, $text); |
— | — | @@ -151,21 +151,21 @@ |
152 | 152 | |
153 | 153 | public function remove($keyPath) { |
154 | 154 | global |
155 | | - $definitionIdAttribute, $languageAttribute; |
| 155 | + $definitionIdAttribute; |
156 | 156 | |
157 | 157 | $definitionId = $keyPath->peek(1)->getAttributeValue($definitionIdAttribute); |
158 | | - $languageId = $keyPath->peek(0)->getAttributeValue($languageAttribute); |
| 158 | + $languageId = $keyPath->peek(0)->$language; |
159 | 159 | |
160 | 160 | removeTranslatedText($definitionId, $languageId); |
161 | 161 | } |
162 | 162 | |
163 | 163 | public function update($keyPath, $record) { |
164 | 164 | global |
165 | | - $definitionIdAttribute, $languageAttribute, $textAttribute; |
| 165 | + $definitionIdAttribute; |
166 | 166 | |
167 | 167 | $definitionId = $keyPath->peek(1)->getAttributeValue($definitionIdAttribute); |
168 | | - $languageId = $keyPath->peek(0)->getAttributeValue($languageAttribute); |
169 | | - $text = $record->getAttributeValue($textAttribute); |
| 168 | + $languageId = $keyPath->peek(0)->language; |
| 169 | + $text = $record->text; |
170 | 170 | |
171 | 171 | if ($text != "") |
172 | 172 | updateTranslatedText($definitionId, $languageId, $text); |
— | — | @@ -181,7 +181,7 @@ |
182 | 182 | |
183 | 183 | public function update($keyPath, $value) { |
184 | 184 | global |
185 | | - $definitionIdAttribute, $languageAttribute, $textAttribute; |
| 185 | + $definitionIdAttribute; |
186 | 186 | |
187 | 187 | $definitionId = $keyPath->peek(0)->getAttributeValue($definitionIdAttribute); |
188 | 188 | |
— | — | @@ -199,13 +199,13 @@ |
200 | 200 | |
201 | 201 | public function add($keyPath, $record) { |
202 | 202 | global |
203 | | - $definedMeaningIdAttribute, $expressionAttribute, $languageAttribute, $spellingAttribute, $identicalMeaningAttribute; |
| 203 | + $definedMeaningIdAttribute, $expressionAttribute, $spellingAttribute, $identicalMeaningAttribute; |
204 | 204 | |
205 | 205 | $definedMeaningId = $keyPath->peek(0)->getAttributeValue($definedMeaningIdAttribute); |
206 | 206 | $expressionValue = $record->getAttributeValue($expressionAttribute); |
207 | 207 | |
208 | 208 | if ($this->filterLanguageId == 0) { |
209 | | - $languageId = $expressionValue->getAttributeValue($languageAttribute); |
| 209 | + $languageId = $expressionValue->$language; |
210 | 210 | $spelling = $expressionValue->getAttributeValue($spellingAttribute); |
211 | 211 | } |
212 | 212 | else { |
— | — | @@ -398,7 +398,7 @@ |
399 | 399 | |
400 | 400 | public function add($keyPath, $record) { |
401 | 401 | global |
402 | | - $expressionIdAttribute, $definedMeaningAttribute, $definitionAttribute, $translatedTextAttribute, $languageAttribute, $textAttribute; |
| 402 | + $expressionIdAttribute, $definedMeaningAttribute, $definitionAttribute, $translatedTextAttribute; |
403 | 403 | |
404 | 404 | $definition = $record->getAttributeValue($definedMeaningAttribute)->getAttributeValue($definitionAttribute); |
405 | 405 | $translatedContent = $definition->getAttributeValue($translatedTextAttribute); |
— | — | @@ -408,8 +408,8 @@ |
409 | 409 | if ($translatedContent->getRecordCount() > 0) { |
410 | 410 | $definitionRecord = $translatedContent->getRecord(0); |
411 | 411 | |
412 | | - $text = $definitionRecord->getAttributeValue($textAttribute); |
413 | | - $languageId = $definitionRecord->getAttributeValue($languageAttribute); |
| 412 | + $text = $definitionRecord->text; |
| 413 | + $languageId = $definitionRecord->language; |
414 | 414 | |
415 | 415 | if ($languageId != 0 && $text != "") |
416 | 416 | createNewDefinedMeaning($expressionId, $languageId, $text); |
— | — | @@ -439,10 +439,10 @@ |
440 | 440 | global |
441 | 441 | $expressionAttribute, $expressionMeaningsAttribute, $expressionExactMeaningsAttribute, |
442 | 442 | $definedMeaningAttribute, $definitionAttribute, |
443 | | - $languageAttribute, $textAttribute, $translatedTextAttribute; |
| 443 | + $translatedTextAttribute; |
444 | 444 | |
445 | 445 | if ($this->filterLanguageId == 0) |
446 | | - $expressionLanguageId = $record->getAttributeValue($expressionAttribute)->getAttributeValue($languageAttribute); |
| 446 | + $expressionLanguageId = $record->getAttributeValue($expressionAttribute)->languageAttribute; |
447 | 447 | else |
448 | 448 | $expressionLanguageId = $this->filterLanguageId; |
449 | 449 | |
— | — | @@ -458,8 +458,8 @@ |
459 | 459 | if ($translatedContent->getRecordCount() > 0) { |
460 | 460 | $definitionRecord = $translatedContent->getRecord(0); |
461 | 461 | |
462 | | - $text = $definitionRecord->getAttributeValue($textAttribute); |
463 | | - $languageId = $definitionRecord->getAttributeValue($languageAttribute); |
| 462 | + $text = $definitionRecord->text; |
| 463 | + $languageId = $definitionRecord->language; |
464 | 464 | |
465 | 465 | if ($languageId != 0 && $text != "") { |
466 | 466 | $expression = findOrCreateExpression($this->spelling, $expressionLanguageId); |
— | — | @@ -492,10 +492,10 @@ |
493 | 493 | class TextAttributeValuesController extends ObjectAttributeValuesController { |
494 | 494 | public function add($keyPath, $record) { |
495 | 495 | global |
496 | | - $textAttribute, $textAttributeAttribute; |
| 496 | + $textAttributeAttribute; |
497 | 497 | $objectId = $this->objectIdFetcher->fetch($keyPath); |
498 | 498 | $textAttributeId = $record->getAttributeValue($textAttributeAttribute); |
499 | | - $text = $record->getAttributeValue($textAttribute); |
| 499 | + $text = $record->text; |
500 | 500 | if ($textAttributeId != 0 && $text != '') |
501 | 501 | addTextAttributeValue($objectId, $textAttributeId, $text); |
502 | 502 | } |
— | — | @@ -512,7 +512,7 @@ |
513 | 513 | $textAttributeIdAttribute, $textAttribute; |
514 | 514 | |
515 | 515 | $textId = $keyPath->peek(0)->getAttributeValue($textAttributeIdAttribute); |
516 | | - $text = $record->getAttributeValue($textAttribute); |
| 516 | + $text = $record->text; |
517 | 517 | |
518 | 518 | updateTextAttributeValue($text, $textId); |
519 | 519 | } |
— | — | @@ -566,8 +566,8 @@ |
567 | 567 | |
568 | 568 | public function add($keyPath, $record) { |
569 | 569 | global |
570 | | - $translatedTextValueAttribute, $languageAttribute, |
571 | | - $textAttribute, $translatedTextAttributeAttribute; |
| 570 | + $translatedTextValueAttribute, |
| 571 | + $translatedTextAttributeAttribute; |
572 | 572 | |
573 | 573 | $objectId = $this->objectIdFetcher->fetch($keyPath); |
574 | 574 | $textValue = $record->getAttributeValue($translatedTextValueAttribute); |
— | — | @@ -578,8 +578,8 @@ |
579 | 579 | if ($textValue->getRecordCount() > 0) { |
580 | 580 | $textValueRecord = $textValue->getRecord(0); |
581 | 581 | |
582 | | - $languageId = $textValueRecord->getAttributeValue($languageAttribute); |
583 | | - $text = $textValueRecord->getAttributeValue($textAttribute); |
| 582 | + $languageId = $textValueRecord->languageAttribute; |
| 583 | + $text = $textValueRecord->textAttribute; |
584 | 584 | |
585 | 585 | if ($languageId != 0 && $text != '') |
586 | 586 | addTranslatedTextAttributeValue($objectId, $textAttributeId, $languageId, $text); |
— | — | @@ -605,11 +605,11 @@ |
606 | 606 | class TranslatedTextAttributeValueController implements UpdateController { |
607 | 607 | public function add($keyPath, $record) { |
608 | 608 | global |
609 | | - $translatedTextAttributeIdAttribute, $languageAttribute, $textAttribute; |
| 609 | + $translatedTextAttributeIdAttribute; |
610 | 610 | |
611 | 611 | $valueId = $keyPath->peek(0)->getAttributeValue($translatedTextAttributeIdAttribute); |
612 | | - $languageId = $record->getAttributeValue($languageAttribute); |
613 | | - $text = $record->getAttributeValue($textAttribute); |
| 612 | + $languageId = $record->language; |
| 613 | + $text = $record->text; |
614 | 614 | $translatedTextAttribute = getTranslatedTextAttribute($valueId); |
615 | 615 | |
616 | 616 | if ($languageId != 0 && $text != "") |
— | — | @@ -618,10 +618,10 @@ |
619 | 619 | |
620 | 620 | public function remove($keyPath) { |
621 | 621 | global |
622 | | - $translatedTextAttributeIdAttribute, $languageAttribute; |
| 622 | + $translatedTextAttributeIdAttribute; |
623 | 623 | |
624 | 624 | $valueId = $keyPath->peek(1)->getAttributeValue($translatedTextAttributeIdAttribute); |
625 | | - $languageId = $keyPath->peek(0)->getAttributeValue($languageAttribute); |
| 625 | + $languageId = $keyPath->peek(0)->language; |
626 | 626 | $translatedTextAttribute = getTranslatedTextAttribute($valueId); |
627 | 627 | |
628 | 628 | removeTranslatedText($translatedTextAttribute->value_tcid, $languageId); |
— | — | @@ -629,11 +629,11 @@ |
630 | 630 | |
631 | 631 | public function update($keyPath, $record) { |
632 | 632 | global |
633 | | - $translatedTextAttributeIdAttribute, $languageAttribute, $textAttribute; |
| 633 | + $translatedTextAttributeIdAttribute; |
634 | 634 | |
635 | 635 | $valueId = $keyPath->peek(1)->getAttributeValue($translatedTextAttributeIdAttribute); |
636 | | - $languageId = $keyPath->peek(0)->getAttributeValue($languageAttribute); |
637 | | - $text = $record->getAttributeValue($textAttribute); |
| 636 | + $languageId = $keyPath->peek(0)->language; |
| 637 | + $text = $record->text; |
638 | 638 | $translatedTextAttribute = getTranslatedTextAttribute($valueId); |
639 | 639 | |
640 | 640 | if ($text != "") |
— | — | @@ -650,7 +650,7 @@ |
651 | 651 | |
652 | 652 | public function update($keyPath, $value) { |
653 | 653 | global |
654 | | - $translatedTextAttributeIdAttribute, $languageAttribute, $textAttribute; |
| 654 | + $translatedTextAttributeIdAttribute ; |
655 | 655 | |
656 | 656 | $valueId = $keyPath->peek(0)->getAttributeValue($translatedTextAttributeIdAttribute); |
657 | 657 | $translatedTextAttribute = getTranslatedTextAttribute($valueId); |
— | — | @@ -686,11 +686,11 @@ |
687 | 687 | class OptionAttributeOptionsController implements UpdateController { |
688 | 688 | public function add($keyPath, $record) { |
689 | 689 | global |
690 | | - $classAttributeIdAttribute, $optionAttributeOptionAttribute, $languageAttribute; |
| 690 | + $classAttributeIdAttribute, $optionAttributeOptionAttribute; |
691 | 691 | |
692 | 692 | $attributeId = $keyPath->peek(0)->getAttributeValue($classAttributeIdAttribute); |
693 | 693 | $optionMeaningId = $record->getAttributeValue($optionAttributeOptionAttribute); |
694 | | - $languageId = $record->getAttributeValue($languageAttribute); |
| 694 | + $languageId = $record->language; |
695 | 695 | |
696 | 696 | if ($optionMeaningId) |
697 | 697 | addOptionAttributeOption($attributeId, $optionMeaningId, $languageId); |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | $textValueObjectAttributesEditor, $textAttributeIdAttribute, |
16 | 16 | $linkValueObjectAttributesEditor, $linkAttributeIdAttribute, |
17 | 17 | $translatedTextValueObjectAttributesEditor, $translatedTextAttributeIdAttribute, |
18 | | - $optionValueObjectAttributesEditor, $optionAttributeIdAttribute, $annotationMeaningName; |
| 18 | + $optionValueObjectAttributesEditor, $optionAttributeIdAttribute, $annotationMeaningName, $omegaWikiAttributes; |
19 | 19 | |
20 | 20 | $textValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5); |
21 | 21 | $linkValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5); |
— | — | @@ -109,16 +109,15 @@ |
110 | 110 | } |
111 | 111 | |
112 | 112 | function getTranslatedTextEditor(Attribute $attribute, UpdateController $updateController, UpdateAttributeController $updateAttributeController, ViewInformation $viewInformation) { |
113 | | - global |
114 | | - $languageAttribute, $textAttribute; |
115 | 113 | |
| 114 | + global $omegaWikiAttributes; |
116 | 115 | if ($viewInformation->filterLanguageId == 0 || $viewInformation->showRecordLifeSpan) { |
117 | 116 | $editor = new RecordSetTableEditor($attribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, true, $updateController); |
118 | 117 | |
119 | 118 | if ($viewInformation->filterLanguageId == 0) |
120 | | - $editor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true)); |
| 119 | + $editor->addEditor(new LanguageEditor($omegaWikiAttributes->language, new SimplePermissionController(false), true)); |
121 | 120 | |
122 | | - $editor->addEditor(new TextEditor($textAttribute, new SimplePermissionController(true), true)); |
| 121 | + $editor->addEditor(new TextEditor($omegaWikiAttributes->text, new SimplePermissionController(true), true)); |
123 | 122 | addTableMetadataEditors($editor, $viewInformation); |
124 | 123 | } |
125 | 124 | else |
— | — | @@ -197,12 +196,12 @@ |
198 | 197 | |
199 | 198 | function getExpressionTableCellEditor(Attribute $attribute, ViewInformation $viewInformation) { |
200 | 199 | global |
201 | | - $languageAttribute, $spellingAttribute; |
| 200 | + $omegaWikiAttributes; |
202 | 201 | |
203 | 202 | if ($viewInformation->filterLanguageId == 0) { |
204 | 203 | $editor = new RecordTableCellEditor($attribute); |
205 | | - $editor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true)); |
206 | | - $editor->addEditor(new SpellingEditor($spellingAttribute, new SimplePermissionController(false), true)); |
| 204 | + $editor->addEditor(new LanguageEditor($omegaWikiAttributes->language, new SimplePermissionController(false), true)); |
| 205 | + $editor->addEditor(new SpellingEditor($omegaWikiAttributes->spelling, new SimplePermissionController(false), true)); |
207 | 206 | } |
208 | 207 | else |
209 | 208 | $editor = new SpellingEditor($attribute, new SimplePermissionController(false), true); |
— | — | @@ -428,11 +427,12 @@ |
429 | 428 | |
430 | 429 | function getOptionAttributeOptionsEditor() { |
431 | 430 | global |
432 | | - $optionAttributeAttribute, $optionAttributeOptionAttribute, $languageAttribute, $optionAttributeOptionsAttribute; |
| 431 | + $optionAttributeAttribute, $optionAttributeOptionAttribute, $optionAttributeOptionsAttribute, $omegaWikiAttributes; |
| 432 | + $o=$omegaWikiAttributes; |
433 | 433 | |
434 | 434 | $editor = new RecordSetTableEditor($optionAttributeOptionsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new OptionAttributeOptionsController()); |
435 | 435 | $editor->addEditor(new DefinedMeaningReferenceEditor($optionAttributeOptionAttribute, new SimplePermissionController(false), true)); |
436 | | - $editor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true)); |
| 436 | + $editor->addEditor(new LanguageEditor($o->language, new SimplePermissionController(false), true)); |
437 | 437 | |
438 | 438 | return $editor; |
439 | 439 | } |
— | — | @@ -455,7 +455,7 @@ |
456 | 456 | |
457 | 457 | function getExpressionsEditor($spelling, ViewInformation $viewInformation) { |
458 | 458 | global |
459 | | - $expressionMeaningsAttribute, $expressionExactMeaningsAttribute, $expressionApproximateMeaningsAttribute, $expressionAttribute, $languageAttribute, $expressionsAttribute; |
| 459 | + $expressionMeaningsAttribute, $expressionExactMeaningsAttribute, $expressionApproximateMeaningsAttribute, $expressionAttribute, $expressionsAttribute, $omegaWikiAttributes; |
460 | 460 | |
461 | 461 | $expressionMeaningsRecordEditor = new RecordUnorderedListEditor($expressionMeaningsAttribute, 3); |
462 | 462 | |
— | — | @@ -467,7 +467,7 @@ |
468 | 468 | |
469 | 469 | if ($viewInformation->filterLanguageId == 0) { |
470 | 470 | $expressionEditor = new RecordSpanEditor($expressionAttribute, ': ', ' - '); |
471 | | - $expressionEditor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true)); |
| 471 | + $expressionEditor->addEditor(new LanguageEditor($omegaWikiAttributes->language, new SimplePermissionController(false), true)); |
472 | 472 | |
473 | 473 | $expressionsEditor = new RecordSetListEditor( |
474 | 474 | $expressionsAttribute, |
— | — | @@ -629,13 +629,13 @@ |
630 | 630 | |
631 | 631 | function createTranslatedTextViewer($attribute) { |
632 | 632 | global |
633 | | - $languageAttribute, $textAttribute; |
| 633 | + $textAttribute,$omegaWikiAttributes; |
634 | 634 | |
635 | 635 | $result = createTableViewer($attribute); |
636 | | - $result->addEditor(createLanguageViewer($languageAttribute)); |
| 636 | + $result->addEditor(createLanguageViewer($omegaWikiAttributes->language)); |
637 | 637 | $result->addEditor(createLongTextViewer($textAttribute)); |
638 | 638 | |
639 | 639 | return $result; |
640 | 640 | } |
641 | 641 | |
642 | | -?> |
\ No newline at end of file |
| 642 | +?> |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php |
— | — | @@ -229,7 +229,7 @@ |
230 | 230 | |
231 | 231 | function getExpressionReferenceRecords($expressionIds) { |
232 | 232 | global |
233 | | - $expressionStructure, $languageAttribute, $spellingAttribute; |
| 233 | + $expressionStructure; |
234 | 234 | |
235 | 235 | $dc=wdGetDataSetContext(); |
236 | 236 | |
— | — | @@ -246,8 +246,8 @@ |
247 | 247 | |
248 | 248 | while ($row = $dbr->fetchObject($queryResult)) { |
249 | 249 | $record = new ArrayRecord($expressionStructure); |
250 | | - $record->setAttributeValue($languageAttribute, $row->language_id); |
251 | | - $record->setAttributeValue($spellingAttribute, $row->spelling); |
| 250 | + $record->language = $row->language_id; |
| 251 | + $record->spelling = $row->spelling; |
252 | 252 | |
253 | 253 | $result[$row->expression_id] = $record; |
254 | 254 | } |
— | — | @@ -396,7 +396,7 @@ |
397 | 397 | |
398 | 398 | function getExpressionsRecordSet($spelling, ViewInformation $viewInformation) { |
399 | 399 | global |
400 | | - $expressionIdAttribute, $expressionAttribute, $languageAttribute, $expressionMeaningsAttribute, $expressionsStructure; |
| 400 | + $omegaWikiAttributes, $expressionIdAttribute, $expressionAttribute, $expressionMeaningsAttribute, $expressionsStructure; |
401 | 401 | |
402 | 402 | $dc=wdGetDataSetContext(); |
403 | 403 | |
— | — | @@ -418,11 +418,11 @@ |
419 | 419 | ); |
420 | 420 | |
421 | 421 | $result = new ArrayRecordSet($expressionsStructure, new Structure("expression-id", $expressionIdAttribute)); |
422 | | - $languageStructure = new Structure("language", $languageAttribute); |
| 422 | + $languageStructure = new Structure("language", $omegaWikiAttributes->language); |
423 | 423 | |
424 | 424 | while($expression = $dbr->fetchObject($queryResult)) { |
425 | 425 | $expressionRecord = new ArrayRecord($languageStructure); |
426 | | - $expressionRecord->setAttributeValue($languageAttribute, $expression->language_id); |
| 426 | + $expressionRecord->language = $expression->language_id; |
427 | 427 | |
428 | 428 | $result->addRecord(array( |
429 | 429 | $expression->expression_id, |
— | — | @@ -656,37 +656,41 @@ |
657 | 657 | |
658 | 658 | function getTranslatedContentRecordSet($translatedContentId, ViewInformation $viewInformation) { |
659 | 659 | global |
660 | | - $translatedContentTable, $languageAttribute, $textAttribute, |
661 | | - $translatedTextStructure; |
| 660 | + $translatedContentTable, |
| 661 | + $translatedTextStructure, $omegaWikiAttributes; |
662 | 662 | |
| 663 | + $o=$omegaWikiAttributes; |
| 664 | + |
663 | 665 | $recordSet = queryRecordSet( |
664 | 666 | $translatedTextStructure->getStructureType(), |
665 | 667 | $viewInformation->queryTransactionInformation, |
666 | | - $languageAttribute, |
| 668 | + $o->language, |
667 | 669 | new TableColumnsToAttributesMapping( |
668 | | - new TableColumnsToAttribute(array('language_id'), $languageAttribute), |
669 | | - new TableColumnsToAttribute(array('text_id'), $textAttribute) |
| 670 | + new TableColumnsToAttribute(array('language_id'), $o->language), |
| 671 | + new TableColumnsToAttribute(array('text_id'), $o->text) |
670 | 672 | ), |
671 | 673 | $translatedContentTable, |
672 | 674 | array("translated_content_id=$translatedContentId") |
673 | 675 | ); |
674 | 676 | |
675 | | - expandTextReferencesInRecordSet($recordSet, array($textAttribute)); |
| 677 | + expandTextReferencesInRecordSet($recordSet, array($o->text)); |
676 | 678 | |
677 | 679 | return $recordSet; |
678 | 680 | } |
679 | 681 | |
680 | 682 | function getFilteredTranslatedContentRecordSet($translatedContentId, ViewInformation $viewInformation) { |
681 | 683 | global |
682 | | - $translatedContentTable, $languageAttribute, $textAttribute; |
| 684 | + $translatedContentTable, $omegaWikiAttributes ; |
| 685 | + |
| 686 | + $o=$omegaWikiAttributes; |
683 | 687 | |
684 | 688 | $recordSet = queryRecordSet( |
685 | 689 | null, |
686 | 690 | $viewInformation->queryTransactionInformation, |
687 | | - $languageAttribute, |
| 691 | + $o->language, |
688 | 692 | new TableColumnsToAttributesMapping( |
689 | | - new TableColumnsToAttribute(array('language_id'), $languageAttribute), |
690 | | - new TableColumnsToAttribute(array('text_id'), $textAttribute) |
| 693 | + new TableColumnsToAttribute(array('language_id'), $o->language), |
| 694 | + new TableColumnsToAttribute(array('text_id'), $o->text) |
691 | 695 | ), |
692 | 696 | $translatedContentTable, |
693 | 697 | array( |
— | — | @@ -1061,8 +1065,9 @@ |
1062 | 1066 | |
1063 | 1067 | function getOptionAttributeOptionsRecordSet($attributeId, ViewInformation $viewInformation) { |
1064 | 1068 | global |
1065 | | - $optionAttributeOptionIdAttribute, $optionAttributeAttribute, $optionAttributeOptionAttribute, $languageAttribute, $optionAttributeOptionsTable; |
| 1069 | + $optionAttributeOptionIdAttribute, $optionAttributeAttribute, $optionAttributeOptionAttribute, $omegaWikiAttributes, $optionAttributeOptionsTable; |
1066 | 1070 | |
| 1071 | + $o=$omegaWikiAttributes; |
1067 | 1072 | $recordSet = queryRecordSet( |
1068 | 1073 | null, |
1069 | 1074 | $viewInformation->queryTransactionInformation, |
— | — | @@ -1071,7 +1076,7 @@ |
1072 | 1077 | new TableColumnsToAttribute(array('option_id'), $optionAttributeOptionIdAttribute), |
1073 | 1078 | new TableColumnsToAttribute(array('attribute_id'), $optionAttributeAttribute), |
1074 | 1079 | new TableColumnsToAttribute(array('option_mid'), $optionAttributeOptionAttribute), |
1075 | | - new TableColumnsToAttribute(array('language_id'), $languageAttribute) |
| 1080 | + new TableColumnsToAttribute(array('language_id'), $o->language) |
1076 | 1081 | ), |
1077 | 1082 | $optionAttributeOptionsTable, |
1078 | 1083 | array('attribute_id = ' . $attributeId) |
— | — | @@ -1178,13 +1183,15 @@ |
1179 | 1184 | $definedMeaningCompleteDefiningExpressionAttribute, |
1180 | 1185 | $definedMeaningDefiningExpressionAttribute, |
1181 | 1186 | $expressionIdAttribute, |
1182 | | - $languageAttribute; |
| 1187 | + $omegaWikiAttributes; |
1183 | 1188 | |
| 1189 | + $o=$omegaWikiAttributes; |
| 1190 | + |
1184 | 1191 | $definingExpression=definingExpressionRow($definedMeaningId); |
1185 | 1192 | $definingExpressionRecord = new ArrayRecord($definedMeaningCompleteDefiningExpressionAttribute->type); |
1186 | 1193 | $definingExpressionRecord->setAttributeValue($expressionIdAttribute, $definingExpression[0]); |
1187 | 1194 | $definingExpressionRecord->setAttributeValue($definedMeaningDefiningExpressionAttribute, $definingExpression[1]); |
1188 | | - $definingExpressionRecord->setAttributeValue($languageAttribute, $definingExpression[2]); |
| 1195 | + $definingExpressionRecord->setAttributeValue($o->language, $definingExpression[2]); |
1189 | 1196 | return $definingExpressionRecord; |
1190 | 1197 | |
1191 | | -} |
\ No newline at end of file |
| 1198 | +} |
Index: trunk/extensions/Wikidata/OmegaWiki/Record.php |
— | — | @@ -2,6 +2,7 @@ |
3 | 3 | |
4 | 4 | require_once('Attribute.php'); |
5 | 5 | require_once('RecordHelper.php'); |
| 6 | +require_once('OmegaWikiAttributes.php'); |
6 | 7 | |
7 | 8 | interface Record { |
8 | 9 | public function getStructure(); |
— | — | @@ -13,7 +14,8 @@ |
14 | 15 | protected $structure; |
15 | 16 | protected $values = array(); |
16 | 17 | protected $helper=null; |
17 | | - |
| 18 | + #possibly associate an OmegaWikiAttributes instance (singleton?) here |
| 19 | + |
18 | 20 | public function __construct(Structure $structure) { |
19 | 21 | $this->structure = $structure; |
20 | 22 | $this->helper=RecordHelperFactory::getRecordHelper($this); |
— | — | @@ -28,11 +30,30 @@ |
29 | 31 | return @$this->values[$attribute->id]; |
30 | 32 | } |
31 | 33 | |
| 34 | + |
| 35 | + /** |
| 36 | + * Look up the correct attribute using omegaWikiAttributes |
| 37 | + * and return its value |
| 38 | + */ |
| 39 | + public function __get($attribute_name){ |
| 40 | + global $omegaWikiAttributes; |
| 41 | + return $this->getAttributeValue($omegaWikiAttributes->$attribute_name); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Look up the correct attribute using omegaWikiAttributes |
| 46 | + * and set its value |
| 47 | + */ |
| 48 | + public function __set($attribute_name, $value){ |
| 49 | + global $omegaWikiAttributes; |
| 50 | + return $this->setAttributeValue ($omegaWikiAttributes->$attribute_name, $value); |
| 51 | + } |
32 | 52 | /** |
33 | 53 | * Obtains a value based on the provided key. |
34 | 54 | * In future, this should check against an attributes global with string |
35 | 55 | * lookup, and might even be smart. |
36 | 56 | * For now, this just does a direct lookup. |
| 57 | + * @deprecated use __get and __set instead |
37 | 58 | */ |
38 | 59 | public function getValue ($key) { |
39 | 60 | return @$this->values[$key]; |
— | — | @@ -86,6 +107,7 @@ |
87 | 108 | $rv=$comma; |
88 | 109 | $repr="$key:$value"; |
89 | 110 | #Duck typing (should refactor this to a has_attr() function); |
| 111 | + # ( might be replacable by property_exists() in php 5.1+ ) |
90 | 112 | $methods=get_class_methods(get_class($value)); |
91 | 113 | if (!is_null($methods)) { |
92 | 114 | if (in_array("tostring_indent",$methods)) { |