Index: trunk/extensions/Wikidata/OmegaWiki/Fetcher.php |
— | — | @@ -1,56 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -interface Fetcher { |
5 | | - public function __construct($attributeLevel, $attribute); |
6 | | - public function fetch($keyPath); |
7 | | -} |
8 | | - |
9 | | -class DefaultFetcher implements Fetcher { |
10 | | - protected $attributeLevel; |
11 | | - protected $attribute; |
12 | | - |
13 | | - public function __construct($attributeLevel, $attribute) { |
14 | | - $this->attributeLevel = $attributeLevel; |
15 | | - $this->attribute = $attribute; |
16 | | - } |
17 | | - public function fetch($keyPath) { |
18 | | - if ($keyPath->peek($this->attributeLevel)->getStructure()->supportsAttribute($this->attribute)) |
19 | | - return $keyPath->peek($this->attributeLevel)->getAttributeValue($this->attribute); |
20 | | - else |
21 | | - return null; # FIXME: Should not happen, check should leave when the reason of the attribute not being support by the record is determined |
22 | | - } |
23 | | -} |
24 | | - |
25 | | -class ObjectIdFetcher extends DefaultFetcher { |
26 | | -// protected $objectIdAttributeLevel; |
27 | | -// protected $objectIdAttribute; |
28 | | -// |
29 | | -// public function __construct($objectIdAttributeLevel, $objectIdAttribute) { |
30 | | -// $this->objectIdAttributeLevel = $objectIdAttributeLevel; |
31 | | -// $this->objectIdAttribute = $objectIdAttribute; |
32 | | -// } |
33 | | -// public function fetch($keyPath, $record) { |
34 | | -// return $keyPath->peek($this->objectIdAttributeLevel)->getAttributeValue($this->objectIdAttribute); |
35 | | -// } |
36 | | - function __tostring(){ |
37 | | - $attributeLevel=$this->attributeLevel; |
38 | | - $attribute=$this->attribute; |
39 | | - return "ObjectIdFetcher($attributeLevel, $attribute)"; |
40 | | - } |
41 | | - |
42 | | -} |
43 | | - |
44 | | -class DefinitionObjectIdFetcher extends DefaultFetcher { |
45 | | - public function fetch($keyPath) { |
46 | | - $definedMeaningId = $keyPath->peek($this->attributeLevel)->getAttributeValue($this->attribute); |
47 | | - return getDefinedMeaningDefinitionId($definedMeaningId); |
48 | | - } |
49 | | - |
50 | | - function __tostring(){ |
51 | | - $attributeLevel=$this->attributeLevel; |
52 | | - $attribute=$this->attribute; |
53 | | - return "DefinitionObjectIdFetcher($attributeLevel, $attribute)"; |
54 | | - } |
55 | | -} |
56 | | - |
57 | | - |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -1,12 +1,12 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -require_once('Editor.php'); |
5 | | -require_once('OmegaWikiAttributes.php'); |
6 | | -require_once('WikiDataBootstrappedMeanings.php'); |
7 | | -require_once('Fetcher.php'); |
8 | | -require_once('WikiDataGlobals.php'); |
9 | | -require_once('GotoSourceTemplate.php'); |
10 | | -require_once('ViewInformation.php'); |
| 4 | +require_once("Editor.php"); |
| 5 | +require_once("OmegaWikiAttributes.php"); |
| 6 | +require_once("WikiDataBootstrappedMeanings.php"); |
| 7 | +require_once("ContextFetcher.php"); |
| 8 | +require_once("WikiDataGlobals.php"); |
| 9 | +require_once("GotoSourceTemplate.php"); |
| 10 | +require_once("ViewInformation.php"); |
11 | 11 | |
12 | 12 | class DummyViewer extends Viewer { |
13 | 13 | public function view(IdStack $idPath, $value) { |
— | — | @@ -179,16 +179,15 @@ |
180 | 180 | } |
181 | 181 | |
182 | 182 | function initializeObjectAttributeEditors(ViewInformation $viewInformation) { |
183 | | - |
184 | | - $o=OmegaWikiAttributes::getInstance($viewInformation); |
185 | 183 | global |
186 | | - |
187 | 184 | $textValueObjectAttributesEditors, |
188 | 185 | $linkValueObjectAttributesEditors, |
189 | 186 | $translatedTextValueObjectAttributesEditors, |
190 | 187 | $optionValueObjectAttributesEditors, $annotationMeaningName, |
191 | 188 | $wgPropertyAttributeName; |
192 | 189 | |
| 190 | + $o=OmegaWikiAttributes::getInstance($viewInformation); |
| 191 | + |
193 | 192 | $linkValueObjectAttributesEditors = array(); |
194 | 193 | $textValueObjectAttributesEditors = array(); |
195 | 194 | $translatedTextValueObjectAttributesEditors = array(); |
— | — | @@ -223,7 +222,6 @@ |
224 | 223 | } |
225 | 224 | |
226 | 225 | function getTransactionEditor(Attribute $attribute) { |
227 | | - |
228 | 226 | $o=OmegaWikiAttributes::getInstance(); |
229 | 227 | |
230 | 228 | $transactionEditor = new RecordTableCellEditor($attribute); |
— | — | @@ -234,7 +232,6 @@ |
235 | 233 | } |
236 | 234 | |
237 | 235 | function createTableLifeSpanEditor(Attribute $attribute) { |
238 | | - |
239 | 236 | $o=OmegaWikiAttributes::getInstance(); |
240 | 237 | |
241 | 238 | $result = new RecordTableCellEditor($attribute); |
— | — | @@ -245,10 +242,10 @@ |
246 | 243 | } |
247 | 244 | |
248 | 245 | function getTableLifeSpanEditor($showRecordLifeSpan) { |
| 246 | + global |
| 247 | + $wgRequest; |
249 | 248 | |
250 | 249 | $o=OmegaWikiAttributes::getInstance(); |
251 | | - global |
252 | | - $wgRequest; |
253 | 250 | |
254 | 251 | $result = array(); |
255 | 252 | |
— | — | @@ -270,12 +267,10 @@ |
271 | 268 | } |
272 | 269 | |
273 | 270 | function getDefinitionEditor(ViewInformation $viewInformation) { |
| 271 | + global |
| 272 | + $wgPopupAnnotationName, $definitionMeaningName, $wgPropertyAttributeName; |
274 | 273 | |
275 | 274 | $o=OmegaWikiAttributes::getInstance(); |
276 | | - global |
277 | | - $wgPopupAnnotationName, |
278 | | - $definitionMeaningName, |
279 | | - $wgPropertyAttributeName; |
280 | 275 | |
281 | 276 | $editor = new RecordDivListEditor($o->definition); |
282 | 277 | $editor->addEditor(getTranslatedTextEditor( |
— | — | @@ -302,27 +297,28 @@ |
303 | 298 | return $editor; |
304 | 299 | } |
305 | 300 | |
306 | | -function createPropertyToColumnFilterEditors(ViewInformation $viewInformation, Attribute $idAttribute, $levelsFromDefinedMeaning, $levelName) { |
| 301 | +function createPropertyToColumnFilterEditors(ViewInformation $viewInformation, Attribute $idAttribute, $levelsToLookUpwards, $levelName) { |
307 | 302 | $result = array(); |
308 | 303 | |
309 | 304 | foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter) { |
310 | 305 | $attribute = $propertyToColumnFilter->getAttribute(); |
311 | 306 | $propertyCaption = $propertyToColumnFilter->getPropertyCaption(); |
312 | | - $result[] = createObjectAttributesEditor($viewInformation, $attribute, $propertyCaption, $idAttribute, $levelsFromDefinedMeaning, $levelName); |
| 307 | + $result[] = createObjectAttributesEditor($viewInformation, $attribute, $propertyCaption, $idAttribute, $levelsToLookUpwards, $levelName); |
313 | 308 | } |
314 | 309 | |
315 | 310 | return $result; |
316 | 311 | } |
317 | 312 | |
318 | | -function addPropertyToColumnFilterEditors(Editor $editor, ViewInformation $viewInformation, Attribute $idAttribute, $levelsFromDefinedMeaning, $levelName) { |
319 | | - foreach (createPropertyToColumnFilterEditors($viewInformation, $idAttribute, $levelsFromDefinedMeaning, $levelName) as $propertyToColumnEditor) { |
| 313 | +function addPropertyToColumnFilterEditors(Editor $editor, ViewInformation $viewInformation, Attribute $idAttribute, $levelsToLookUpwards, $levelName) { |
| 314 | + foreach (createPropertyToColumnFilterEditors($viewInformation, $idAttribute, $levelsToLookUpwards, $levelName) as $propertyToColumnEditor) { |
320 | 315 | $attribute = $propertyToColumnEditor->getAttribute(); |
321 | 316 | $editor->addEditor(new PopUpEditor($propertyToColumnEditor, $attribute->name)); |
322 | 317 | } |
323 | 318 | } |
324 | 319 | |
325 | 320 | function getTranslatedTextEditor(Attribute $attribute, UpdateController $updateController, UpdateAttributeController $updateAttributeController, ViewInformation $viewInformation) { |
326 | | - $o=OmegaWikiAttributes::getInstance(); |
| 321 | + $o=OmegaWikiAttributes::getInstance(); |
| 322 | + |
327 | 323 | if ($viewInformation->filterLanguageId == 0 || $viewInformation->showRecordLifeSpan) { |
328 | 324 | $editor = new RecordSetTableEditor($attribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, true, $updateController); |
329 | 325 | |
— | — | @@ -338,15 +334,14 @@ |
339 | 335 | return $editor; |
340 | 336 | } |
341 | 337 | |
342 | | -function addObjectAttributesEditors(Editor $objectAttributesEditor, ViewInformation $viewInformation, Fetcher $objectIdFetcher, $levelDefinedMeaningName, Fetcher $dmObjectIdFetcher) { |
343 | | - $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($viewInformation, new TextAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher)); |
344 | | - $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($viewInformation, new TranslatedTextAttributeValuesController($objectIdFetcher, $viewInformation->filterLanguageId), $levelDefinedMeaningName, $dmObjectIdFetcher)); |
345 | | - $objectAttributesEditor->addEditor(getLinkAttributeValuesEditor($viewInformation, new LinkAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher)); |
346 | | - $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($viewInformation, new OptionAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher)); |
| 338 | +function addObjectAttributesEditors(Editor $objectAttributesEditor, ViewInformation $viewInformation, ContextFetcher $annotatedObjectIdFetcher, $annotationLevelName, ContextFetcher $definedMeaningIdFetcher) { |
| 339 | + $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($viewInformation, new TextAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $definedMeaningIdFetcher)); |
| 340 | + $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($viewInformation, new TranslatedTextAttributeValuesController($annotatedObjectIdFetcher, $viewInformation->filterLanguageId), $annotationLevelName, $definedMeaningIdFetcher)); |
| 341 | + $objectAttributesEditor->addEditor(getLinkAttributeValuesEditor($viewInformation, new LinkAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $definedMeaningIdFetcher)); |
| 342 | + $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($viewInformation, new OptionAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $definedMeaningIdFetcher)); |
347 | 343 | } |
348 | 344 | |
349 | | -function createObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, $propertyCaption, Attribute $idAttribute, $levelsFromDefinedMeaning, $levelName) { |
350 | | - |
| 345 | +function createObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, $propertyCaption, Attribute $idAttribute, $levelsToLookUpwards, $levelName) { |
351 | 346 | $o=OmegaWikiAttributes::getInstance(); |
352 | 347 | |
353 | 348 | $result = new ObjectAttributeValuesEditor($attribute, $propertyCaption, $viewInformation); |
— | — | @@ -356,14 +351,13 @@ |
357 | 352 | $viewInformation, |
358 | 353 | new ObjectIdFetcher(0, $idAttribute), |
359 | 354 | $levelName, |
360 | | - new ObjectIdFetcher($levelsFromDefinedMeaning, $o->definedMeaningId) |
| 355 | + new ObjectIdFetcher($levelsToLookUpwards, $o->definedMeaningId) |
361 | 356 | ); |
362 | 357 | |
363 | 358 | return $result; |
364 | 359 | } |
365 | 360 | |
366 | | -function createDefinitionObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, $propertyCaption, Attribute $idAttribute, $levelsFromDefinedMeaning, $levelName) { |
367 | | - |
| 361 | +function createDefinitionObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, $propertyCaption, Attribute $idAttribute, $levelsToLookUpwards, $levelName) { |
368 | 362 | $o=OmegaWikiAttributes::getInstance(); |
369 | 363 | |
370 | 364 | $result = new ObjectAttributeValuesEditor($attribute, $propertyCaption, $viewInformation); |
— | — | @@ -373,14 +367,13 @@ |
374 | 368 | $viewInformation, |
375 | 369 | new DefinitionObjectIdFetcher(0, $idAttribute), |
376 | 370 | $levelName, |
377 | | - new ObjectIdFetcher($levelsFromDefinedMeaning, $o->definedMeaningId) |
| 371 | + new ObjectIdFetcher($levelsToLookUpwards, $o->definedMeaningId) |
378 | 372 | ); |
379 | 373 | |
380 | 374 | return $result; |
381 | 375 | } |
382 | 376 | |
383 | 377 | function getAlternativeDefinitionsEditor(ViewInformation $viewInformation) { |
384 | | - |
385 | 378 | $o=OmegaWikiAttributes::getInstance(); |
386 | 379 | |
387 | 380 | $editor = new RecordSetTableEditor( |
— | — | @@ -407,7 +400,6 @@ |
408 | 401 | } |
409 | 402 | |
410 | 403 | function getExpressionTableCellEditor(Attribute $attribute, ViewInformation $viewInformation) { |
411 | | - |
412 | 404 | $o=OmegaWikiAttributes::getInstance(); |
413 | 405 | |
414 | 406 | if ($viewInformation->filterLanguageId == 0) { |
— | — | @@ -422,7 +414,6 @@ |
423 | 415 | } |
424 | 416 | |
425 | 417 | function getClassAttributesEditor(ViewInformation $viewInformation) { |
426 | | - |
427 | 418 | $o=OmegaWikiAttributes::getInstance(); |
428 | 419 | |
429 | 420 | $tableEditor = new RecordSetTableEditor($o->classAttributes, new SimplePermissionController(true), new ShowEditFieldForClassesChecker(0, $o->definedMeaningId), new AllowAddController(true), true, false, new ClassAttributesController()); |
— | — | @@ -437,14 +428,11 @@ |
438 | 429 | } |
439 | 430 | |
440 | 431 | function getSynonymsAndTranslationsEditor(ViewInformation $viewInformation) { |
| 432 | + global |
| 433 | + $wgPopupAnnotationName, $synTransMeaningName, $wgPropertyAttributeName; |
441 | 434 | |
442 | 435 | $o=OmegaWikiAttributes::getInstance(); |
443 | | - global |
444 | 436 | |
445 | | - $wgPopupAnnotationName, |
446 | | - $synTransMeaningName, |
447 | | - $wgPropertyAttributeName; |
448 | | - |
449 | 437 | $tableEditor = new RecordSetTableEditor( |
450 | 438 | $o->synonymsAndTranslations, |
451 | 439 | new SimplePermissionController(true), |
— | — | @@ -471,13 +459,12 @@ |
472 | 460 | } |
473 | 461 | |
474 | 462 | function getDefinedMeaningRelationsEditor(ViewInformation $viewInformation) { |
475 | | - |
476 | | - $o=OmegaWikiAttributes::getInstance(); |
477 | 463 | global |
478 | | - |
479 | 464 | $relationsObjectAttributesEditor, $relationMeaningName, $wgPopupAnnotationName, |
480 | 465 | $wgPropertyAttributeName; |
481 | 466 | |
| 467 | + $o=OmegaWikiAttributes::getInstance(); |
| 468 | + |
482 | 469 | $editor = new RecordSetTableEditor($o->relations, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningRelationController()); |
483 | 470 | $editor->addEditor(new RelationTypeReferenceEditor($o->relationType, new SimplePermissionController(false), true)); |
484 | 471 | $editor->addEditor(new DefinedMeaningReferenceEditor($o->otherDefinedMeaning, new SimplePermissionController(false), true)); |
— | — | @@ -495,13 +482,12 @@ |
496 | 483 | } |
497 | 484 | |
498 | 485 | function getDefinedMeaningReciprocalRelationsEditor(ViewInformation $viewInformation) { |
499 | | - |
500 | | - $o=OmegaWikiAttributes::getInstance(); |
501 | 486 | global |
502 | | - |
503 | | - $relationsObjectAttributesEditor, $relationMeaningName, $wgPopupAnnotationName, |
| 487 | + $relationsObjectAttributesEditor, $relationMeaningName, $wgPopupAnnotationName, |
504 | 488 | $wgPropertyAttributeName; |
505 | 489 | |
| 490 | + $o=OmegaWikiAttributes::getInstance(); |
| 491 | + |
506 | 492 | $editor = new RecordSetTableEditor($o->reciprocalRelations, new SimplePermissionController(false), new ShowEditFieldChecker(true), new AllowAddController(false), false, false, null); |
507 | 493 | $editor->addEditor(new DefinedMeaningReferenceEditor($o->otherDefinedMeaning, new SimplePermissionController(false), true)); |
508 | 494 | $editor->addEditor(new RelationTypeReferenceEditor($o->relationType, new SimplePermissionController(false), true)); |
— | — | @@ -519,7 +505,6 @@ |
520 | 506 | } |
521 | 507 | |
522 | 508 | function getDefinedMeaningClassMembershipEditor(ViewInformation $viewInformation) { |
523 | | - |
524 | 509 | $o=OmegaWikiAttributes::getInstance(); |
525 | 510 | |
526 | 511 | $editor = new RecordSetTableEditor($o->classMembership, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningClassMembershipController()); |
— | — | @@ -555,12 +540,11 @@ |
556 | 541 | } |
557 | 542 | |
558 | 543 | function getDefinedMeaningCollectionMembershipEditor(ViewInformation $viewInformation) { |
559 | | - |
560 | | - $o=OmegaWikiAttributes::getInstance(); |
561 | 544 | global |
562 | | - |
563 | 545 | $wgGotoSourceTemplates; |
564 | 546 | |
| 547 | + $o=OmegaWikiAttributes::getInstance(); |
| 548 | + |
565 | 549 | $editor = new RecordSetTableEditor($o->collectionMembership, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningCollectionController()); |
566 | 550 | $editor->addEditor(new CollectionReferenceEditor($o->collectionMeaning, new SimplePermissionController(false), true)); |
567 | 551 | $editor->addEditor(new ShortTextEditor($o->sourceIdentifier, new SimplePermissionController(true), true)); |
— | — | @@ -578,11 +562,11 @@ |
579 | 563 | $editor->addEditor(new PopUpEditor($columnEditor, $columnEditor->getAttribute()->name)); |
580 | 564 | } |
581 | 565 | |
582 | | -function getTextAttributeValuesEditor(ViewInformation $viewInformation, $controller, $levelDefinedMeaningName, Fetcher $objectIdFetcher) { |
| 566 | +function getTextAttributeValuesEditor(ViewInformation $viewInformation, $controller, $levelDefinedMeaningName, ContextFetcher $objectIdFetcher) { |
| 567 | + global |
| 568 | + $textValueObjectAttributesEditors; |
583 | 569 | |
584 | 570 | $o=OmegaWikiAttributes::getInstance(); |
585 | | - global |
586 | | - $textValueObjectAttributesEditors; |
587 | 571 | |
588 | 572 | $editor = new RecordSetTableEditor($o->textAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller); |
589 | 573 | $editor->addEditor(new TextAttributeEditor($o->textAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher)); |
— | — | @@ -594,11 +578,11 @@ |
595 | 579 | return $editor; |
596 | 580 | } |
597 | 581 | |
598 | | -function getLinkAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName, Fetcher $objectIdFetcher) { |
| 582 | +function getLinkAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName, ContextFetcher $objectIdFetcher) { |
| 583 | + global |
| 584 | + $linkValueObjectAttributesEditors; |
599 | 585 | |
600 | 586 | $o=OmegaWikiAttributes::getInstance(); |
601 | | - global |
602 | | - $linkValueObjectAttributesEditors; |
603 | 587 | |
604 | 588 | $editor = new RecordSetTableEditor($o->linkAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller); |
605 | 589 | $editor->addEditor(new LinkAttributeEditor($o->linkAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher)); |
— | — | @@ -619,13 +603,12 @@ |
620 | 604 | return $editor; |
621 | 605 | } |
622 | 606 | |
623 | | -function getTranslatedTextAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName, Fetcher $objectIdFetcher) { |
624 | | - |
625 | | - $o=OmegaWikiAttributes::getInstance(); |
| 607 | +function getTranslatedTextAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName, ContextFetcher $objectIdFetcher) { |
626 | 608 | global |
627 | | - |
628 | 609 | $translatedTextValueObjectAttributesEditors; |
629 | 610 | |
| 611 | + $o=OmegaWikiAttributes::getInstance(); |
| 612 | + |
630 | 613 | $editor = new RecordSetTableEditor($o->translatedTextAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller); |
631 | 614 | $editor->addEditor(new TranslatedTextAttributeEditor($o->translatedTextAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher)); |
632 | 615 | $editor->addEditor(getTranslatedTextEditor( |
— | — | @@ -641,13 +624,12 @@ |
642 | 625 | return $editor; |
643 | 626 | } |
644 | 627 | |
645 | | -function getOptionAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName, Fetcher $objectIdFetcher) { |
646 | | - |
647 | | - $o=OmegaWikiAttributes::getInstance(); |
| 628 | +function getOptionAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName, ContextFetcher $objectIdFetcher) { |
648 | 629 | global |
649 | | - |
650 | 630 | $optionValueObjectAttributesEditors; |
651 | 631 | |
| 632 | + $o=OmegaWikiAttributes::getInstance(); |
| 633 | + |
652 | 634 | $editor = new RecordSetTableEditor($o->optionAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller); |
653 | 635 | |
654 | 636 | $editor->addEditor(new OptionAttributeEditor($o->optionAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher)); |
— | — | @@ -660,7 +642,6 @@ |
661 | 643 | } |
662 | 644 | |
663 | 645 | function getOptionAttributeOptionsEditor() { |
664 | | - |
665 | 646 | $o=OmegaWikiAttributes::getInstance(); |
666 | 647 | |
667 | 648 | $editor = new RecordSetTableEditor($o->optionAttributeOptions, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new OptionAttributeOptionsController()); |
— | — | @@ -671,7 +652,6 @@ |
672 | 653 | } |
673 | 654 | |
674 | 655 | function getExpressionMeaningsEditor(Attribute $attribute, $allowAdd, ViewInformation $viewInformation) { |
675 | | - |
676 | 656 | $o=OmegaWikiAttributes::getInstance(); |
677 | 657 | |
678 | 658 | $definedMeaningEditor = getDefinedMeaningEditor($viewInformation); |
— | — | @@ -687,7 +667,6 @@ |
688 | 668 | } |
689 | 669 | |
690 | 670 | function getExpressionsEditor($spelling, ViewInformation $viewInformation) { |
691 | | - |
692 | 671 | $o=OmegaWikiAttributes::getInstance(); |
693 | 672 | |
694 | 673 | $expressionMeaningsRecordEditor = new RecordUnorderedListEditor($o->expressionMeanings, 3); |
— | — | @@ -736,13 +715,11 @@ |
737 | 716 | } |
738 | 717 | |
739 | 718 | function getDefinedMeaningEditor(ViewInformation $viewInformation) { |
740 | | - |
741 | | - $o=OmegaWikiAttributes::getInstance(); |
742 | 719 | global |
743 | 720 | $wdDefinedMeaningAttributesOrder, $definedMeaningMeaningName, |
744 | | - |
745 | | - $relationMeaningName, |
746 | | - $wgPropertyAttributeName; |
| 721 | + $relationMeaningName, $wgPropertyAttributeName; |
| 722 | + |
| 723 | + $o=OmegaWikiAttributes::getInstance(); |
747 | 724 | |
748 | 725 | $definitionEditor = getDefinitionEditor($viewInformation); |
749 | 726 | $alternativeDefinitionsEditor = getAlternativeDefinitionsEditor($viewInformation); |
Index: trunk/extensions/Wikidata/OmegaWiki/ContextFetcher.php |
— | — | @@ -0,0 +1,60 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Interface ContextFetcher is used to look upwards in a keyPath in |
| 6 | + * search for a specific attribute value. This attribute value establishes a |
| 7 | + * context for an operation that works within a hierarchy of Records (like an Editor does). |
| 8 | + * |
| 9 | + * It might be better to adopt another strategy that pushes the desired context |
| 10 | + * down the hierarchy of Editors instead of letting an Editor look up the hierarchy. |
| 11 | + * We possibly can extend/replace the IdStack to store context during rendering. |
| 12 | + */ |
| 13 | + |
| 14 | +interface ContextFetcher { |
| 15 | + public function fetch($keyPath); |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * Class DefaultContextFetcher implements ContextFetcher by looking up a specified number of levels |
| 20 | + * in the keypath and returning the value for the specified attribute. |
| 21 | + */ |
| 22 | + |
| 23 | +class DefaultContextFetcher implements ContextFetcher { |
| 24 | + protected $levelsToLookUp; |
| 25 | + protected $attribute; |
| 26 | + |
| 27 | + public function __construct($levelsToLookUp, $attribute) { |
| 28 | + $this->levelsToLookUp = $levelsToLookUp; |
| 29 | + $this->attribute = $attribute; |
| 30 | + } |
| 31 | + public function fetch($keyPath) { |
| 32 | + if ($keyPath->peek($this->levelsToLookUp)->getStructure()->supportsAttribute($this->attribute)) |
| 33 | + return $keyPath->peek($this->levelsToLookUp)->getAttributeValue($this->attribute); |
| 34 | + else |
| 35 | + return null; # FIXME: Should not happen, check should leave when the reason of the attribute not being support by the record is determined |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +class ObjectIdFetcher extends DefaultContextFetcher { |
| 40 | + function __tostring(){ |
| 41 | + $levelsToLookUp = $this->attributeLevel; |
| 42 | + $attribute = $this->attribute; |
| 43 | + |
| 44 | + return "ObjectIdFetcher($levelsToLookUp, $attribute)"; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +class DefinitionObjectIdFetcher extends DefaultContextFetcher { |
| 49 | + public function fetch($keyPath) { |
| 50 | + $definedMeaningId = $keyPath->peek($this->levelsToLookUp)->getAttributeValue($this->attribute); |
| 51 | + return getDefinedMeaningDefinitionId($definedMeaningId); |
| 52 | + } |
| 53 | + |
| 54 | + function __tostring(){ |
| 55 | + $levelsToLookUp = $this->attributeLevel; |
| 56 | + $attribute = $this->attribute; |
| 57 | + return "DefinitionObjectIdFetcher($levelsToLookUp, $attribute)"; |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | + |
Property changes on: trunk/extensions/Wikidata/OmegaWiki/ContextFetcher.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 62 | + native |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | require_once("type.php"); |
7 | 7 | require_once("GotoSourceTemplate.php"); |
8 | 8 | require_once("Wikidata.php"); |
| 9 | +require_once("ContextFetcher.php"); |
9 | 10 | |
10 | 11 | function addCollapsablePrefixToClass($class) { |
11 | 12 | return "collapsable-$class"; |
— | — | @@ -1230,7 +1231,7 @@ |
1231 | 1232 | protected $attributesLevelName; |
1232 | 1233 | protected $objectIdFetcher; |
1233 | 1234 | |
1234 | | - public function __construct(Attribute $attribute = null, PermissionController $permissionController, $isAddField, $attributesLevelName, Fetcher $objectIdFetcher) { |
| 1235 | + public function __construct(Attribute $attribute = null, PermissionController $permissionController, $isAddField, $attributesLevelName, ContextFetcher $objectIdFetcher) { |
1235 | 1236 | parent::__construct($attribute, $permissionController, $isAddField); |
1236 | 1237 | |
1237 | 1238 | $this->attributesLevelName = $attributesLevelName; |