r25441 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25440‎ | r25441 | r25442 >
Date:15:55, 3 September 2007
Author:proes
Status:old
Tags:
Comment:
Simplified object annotation a bit and thereby solved problem with recursive annotating:
* Added getDefinedMeaningId() to IdStack
* Removed ContextFetcher from AttributeEditor
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/ContextFetcher.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -247,6 +247,7 @@
248248 $t->definedMeaning = new Attribute(null, wfMsgSc("DefinedMeaning"),
249249 new Structure(
250250 "defined-meaning",
 251+ $t->definedMeaningId,
251252 $t->definedMeaningCompleteDefiningExpression,
252253 $t->definition,
253254 $t->classAttributes,
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -41,7 +41,6 @@
4242
4343 foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter)
4444 $this->recordSetTableEditor->addEditor(new DummyViewer($propertyToColumnFilter->getAttribute()));
45 -
4645
4746 $o=OmegaWikiAttributes::getInstance();
4847
@@ -284,33 +283,33 @@
285284 $attribute = $propertyToColumnFilter->getAttribute();
286285 $propertyCaption = $propertyToColumnFilter->getPropertyCaption();
287286 $editor->addEditor(new PopUpEditor(
288 - createDefinitionObjectAttributesEditor($viewInformation, $attribute, $propertyCaption, $o->definedMeaningId, 0, $definitionMeaningName),
 287+ createDefinitionObjectAttributesEditor($viewInformation, $attribute, $propertyCaption, $o->definedMeaningId, $definitionMeaningName),
289288 $attribute->name
290289 ));
291290 }
292291
293292 $editor->addEditor(new PopUpEditor(
294 - createDefinitionObjectAttributesEditor($viewInformation, $o->objectAttributes, $wgPropertyAttributeName, $o->definedMeaningId, 0, $definitionMeaningName),
 293+ createDefinitionObjectAttributesEditor($viewInformation, $o->objectAttributes, $wgPropertyAttributeName, $o->definedMeaningId, $definitionMeaningName),
295294 $wgPopupAnnotationName
296295 ));
297296
298297 return $editor;
299298 }
300299
301 -function createPropertyToColumnFilterEditors(ViewInformation $viewInformation, Attribute $idAttribute, $levelsToLookUpwards, $levelName) {
 300+function createPropertyToColumnFilterEditors(ViewInformation $viewInformation, Attribute $idAttribute, $levelName) {
302301 $result = array();
303302
304303 foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter) {
305304 $attribute = $propertyToColumnFilter->getAttribute();
306305 $propertyCaption = $propertyToColumnFilter->getPropertyCaption();
307 - $result[] = createObjectAttributesEditor($viewInformation, $attribute, $propertyCaption, $idAttribute, $levelsToLookUpwards, $levelName);
 306+ $result[] = createObjectAttributesEditor($viewInformation, $attribute, $propertyCaption, $idAttribute, $levelName);
308307 }
309308
310309 return $result;
311310 }
312311
313 -function addPropertyToColumnFilterEditors(Editor $editor, ViewInformation $viewInformation, Attribute $idAttribute, $levelsToLookUpwards, $levelName) {
314 - foreach (createPropertyToColumnFilterEditors($viewInformation, $idAttribute, $levelsToLookUpwards, $levelName) as $propertyToColumnEditor) {
 312+function addPropertyToColumnFilterEditors(Editor $editor, ViewInformation $viewInformation, Attribute $idAttribute, $levelName) {
 313+ foreach (createPropertyToColumnFilterEditors($viewInformation, $idAttribute, $levelName) as $propertyToColumnEditor) {
315314 $attribute = $propertyToColumnEditor->getAttribute();
316315 $editor->addEditor(new PopUpEditor($propertyToColumnEditor, $attribute->name));
317316 }
@@ -334,14 +333,14 @@
335334 return $editor;
336335 }
337336
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));
 337+function addObjectAttributesEditors(Editor $objectAttributesEditor, ViewInformation $viewInformation, ContextFetcher $annotatedObjectIdFetcher, $annotationLevelName) {
 338+ $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($viewInformation, new TextAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName));
 339+ $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($viewInformation, new TranslatedTextAttributeValuesController($annotatedObjectIdFetcher, $viewInformation->filterLanguageId), $annotationLevelName));
 340+ $objectAttributesEditor->addEditor(getLinkAttributeValuesEditor($viewInformation, new LinkAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName));
 341+ $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($viewInformation, new OptionAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName));
343342 }
344343
345 -function createObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, $propertyCaption, Attribute $idAttribute, $levelsToLookUpwards, $levelName) {
 344+function createObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, $propertyCaption, Attribute $idAttribute, $levelName) {
346345 $o=OmegaWikiAttributes::getInstance();
347346
348347 $result = new ObjectAttributeValuesEditor($attribute, $propertyCaption, $viewInformation);
@@ -350,14 +349,13 @@
351350 $result,
352351 $viewInformation,
353352 new ObjectIdFetcher(0, $idAttribute),
354 - $levelName,
355 - new ObjectIdFetcher($levelsToLookUpwards, $o->definedMeaningId)
 353+ $levelName
356354 );
357355
358356 return $result;
359357 }
360358
361 -function createDefinitionObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, $propertyCaption, Attribute $idAttribute, $levelsToLookUpwards, $levelName) {
 359+function createDefinitionObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, $propertyCaption, Attribute $idAttribute, $levelName) {
362360 $o=OmegaWikiAttributes::getInstance();
363361
364362 $result = new ObjectAttributeValuesEditor($attribute, $propertyCaption, $viewInformation);
@@ -366,8 +364,7 @@
367365 $result,
368366 $viewInformation,
369367 new DefinitionObjectIdFetcher(0, $idAttribute),
370 - $levelName,
371 - new ObjectIdFetcher($levelsToLookUpwards, $o->definedMeaningId)
 368+ $levelName
372369 );
373370
374371 return $result;
@@ -446,10 +443,10 @@
447444 $tableEditor->addEditor(getExpressionTableCellEditor($o->expression, $viewInformation));
448445 $tableEditor->addEditor(new BooleanEditor($o->identicalMeaning, new SimplePermissionController(true), true, true));
449446
450 - addPropertyToColumnFilterEditors($tableEditor, $viewInformation, $o->syntransId, 1, $synTransMeaningName);
 447+ addPropertyToColumnFilterEditors($tableEditor, $viewInformation, $o->syntransId, $synTransMeaningName);
451448
452449 $tableEditor->addEditor(new PopUpEditor(
453 - createObjectAttributesEditor($viewInformation, $o->objectAttributes, $wgPropertyAttributeName, $o->syntransId, 1, $synTransMeaningName),
 450+ createObjectAttributesEditor($viewInformation, $o->objectAttributes, $wgPropertyAttributeName, $o->syntransId, $synTransMeaningName),
454451 $wgPopupAnnotationName
455452 ));
456453
@@ -469,10 +466,10 @@
470467 $editor->addEditor(new RelationTypeReferenceEditor($o->relationType, new SimplePermissionController(false), true));
471468 $editor->addEditor(new DefinedMeaningReferenceEditor($o->otherDefinedMeaning, new SimplePermissionController(false), true));
472469
473 - addPropertyToColumnFilterEditors($editor, $viewInformation, $o->relationId, 1, $relationMeaningName);
 470+ addPropertyToColumnFilterEditors($editor, $viewInformation, $o->relationId, $relationMeaningName);
474471
475472 $editor->addEditor(new PopUpEditor(
476 - createObjectAttributesEditor($viewInformation, $o->objectAttributes, $wgPropertyAttributeName, $o->relationId, 1, $relationMeaningName),
 473+ createObjectAttributesEditor($viewInformation, $o->objectAttributes, $wgPropertyAttributeName, $o->relationId, $relationMeaningName),
477474 $wgPopupAnnotationName
478475 ));
479476
@@ -492,10 +489,10 @@
493490 $editor->addEditor(new DefinedMeaningReferenceEditor($o->otherDefinedMeaning, new SimplePermissionController(false), true));
494491 $editor->addEditor(new RelationTypeReferenceEditor($o->relationType, new SimplePermissionController(false), true));
495492
496 - addPropertyToColumnFilterEditors($editor, $viewInformation, $o->relationId, 1, $relationMeaningName);
 493+ addPropertyToColumnFilterEditors($editor, $viewInformation, $o->relationId, $relationMeaningName);
497494
498495 $editor->addEditor(new PopUpEditor(
499 - createObjectAttributesEditor($viewInformation, $o->objectAttributes, $wgPropertyAttributeName, $o->relationId, 1, $relationMeaningName),
 496+ createObjectAttributesEditor($viewInformation, $o->objectAttributes, $wgPropertyAttributeName, $o->relationId, $relationMeaningName),
500497 $wgPopupAnnotationName
501498 ));
502499
@@ -562,14 +559,14 @@
563560 $editor->addEditor(new PopUpEditor($columnEditor, $columnEditor->getAttribute()->name));
564561 }
565562
566 -function getTextAttributeValuesEditor(ViewInformation $viewInformation, $controller, $levelDefinedMeaningName, ContextFetcher $objectIdFetcher) {
 563+function getTextAttributeValuesEditor(ViewInformation $viewInformation, $controller, $levelDefinedMeaningName) {
567564 global
568565 $textValueObjectAttributesEditors;
569566
570567 $o=OmegaWikiAttributes::getInstance();
571568
572569 $editor = new RecordSetTableEditor($o->textAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
573 - $editor->addEditor(new TextAttributeEditor($o->textAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
 570+ $editor->addEditor(new TextAttributeEditor($o->textAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName));
574571 $editor->addEditor(new TextEditor($o->text, new SimplePermissionController(true), true));
575572
576573 addPopupEditors($editor, $textValueObjectAttributesEditors);
@@ -578,14 +575,14 @@
579576 return $editor;
580577 }
581578
582 -function getLinkAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName, ContextFetcher $objectIdFetcher) {
 579+function getLinkAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName) {
583580 global
584581 $linkValueObjectAttributesEditors;
585582
586583 $o=OmegaWikiAttributes::getInstance();
587584
588585 $editor = new RecordSetTableEditor($o->linkAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
589 - $editor->addEditor(new LinkAttributeEditor($o->linkAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
 586+ $editor->addEditor(new LinkAttributeEditor($o->linkAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName));
590587
591588 if ($viewInformation->viewOrEdit == "view")
592589 $linkEditor = new LinkEditor($o->link, new SimplePermissionController(true), true);
@@ -603,14 +600,14 @@
604601 return $editor;
605602 }
606603
607 -function getTranslatedTextAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName, ContextFetcher $objectIdFetcher) {
 604+function getTranslatedTextAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName) {
608605 global
609606 $translatedTextValueObjectAttributesEditors;
610607
611608 $o=OmegaWikiAttributes::getInstance();
612609
613610 $editor = new RecordSetTableEditor($o->translatedTextAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
614 - $editor->addEditor(new TranslatedTextAttributeEditor($o->translatedTextAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
 611+ $editor->addEditor(new TranslatedTextAttributeEditor($o->translatedTextAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName));
615612 $editor->addEditor(getTranslatedTextEditor(
616613 $o->translatedTextValue,
617614 new TranslatedTextAttributeValueController(),
@@ -624,7 +621,7 @@
625622 return $editor;
626623 }
627624
628 -function getOptionAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName, ContextFetcher $objectIdFetcher) {
 625+function getOptionAttributeValuesEditor(ViewInformation $viewInformation, UpdateController $controller, $levelDefinedMeaningName) {
629626 global
630627 $optionValueObjectAttributesEditors;
631628
@@ -632,7 +629,7 @@
633630
634631 $editor = new RecordSetTableEditor($o->optionAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
635632
636 - $editor->addEditor(new OptionAttributeEditor($o->optionAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
 633+ $editor->addEditor(new OptionAttributeEditor($o->optionAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName));
637634 $editor->addEditor(new OptionSelectEditor($o->optionAttributeOption, new SimplePermissionController(false), true));
638635
639636 addPopupEditors($editor, $optionValueObjectAttributesEditors);
@@ -737,7 +734,7 @@
738735 $o->possibleSynonym,
739736 $viewInformation->possiblySynonymousRelationTypeId,
740737 $viewInformation,
741 - createObjectAttributesEditor($viewInformation, $o->objectAttributes, $wgPropertyAttributeName, $o->possiblySynonymousId, 1, $relationMeaningName)
 738+ createObjectAttributesEditor($viewInformation, $o->objectAttributes, $wgPropertyAttributeName, $o->possiblySynonymousId, $relationMeaningName)
742739 );
743740
744741 $availableEditors = new AttributeEditorMap();
@@ -753,7 +750,7 @@
754751 foreach (createPropertyToColumnFilterEditors($viewInformation, $o->definedMeaningId, 0, $definedMeaningMeaningName) as $propertyToColumnEditor)
755752 $availableEditors->addEditor($propertyToColumnEditor);
756753
757 - $availableEditors->addEditor(createObjectAttributesEditor($viewInformation, $o->definedMeaningAttributes, $wgPropertyAttributeName, $o->definedMeaningId, 0, $definedMeaningMeaningName));
 754+ $availableEditors->addEditor(createObjectAttributesEditor($viewInformation, $o->definedMeaningAttributes, $wgPropertyAttributeName, $o->definedMeaningId, $definedMeaningMeaningName));
758755
759756 if ($viewInformation->possiblySynonymousRelationTypeId != 0)
760757 $availableEditors->addEditor($possiblySynonymousEditor);
@@ -769,7 +766,8 @@
770767
771768 $definedMeaningEditor->expandEditor($definitionEditor);
772769 $definedMeaningEditor->expandEditor($synonymsAndTranslationsEditor);
773 - return $definedMeaningEditor;
 770+
 771+ return new DefinedMeaningContextEditor($definedMeaningEditor);
774772 }
775773
776774 function createTableViewer($attribute) {
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php
@@ -144,6 +144,7 @@
145145 $o=OmegaWikiAttributes::getInstance();
146146
147147 $record = new ArrayRecord($o->definedMeaning->type);
 148+ $record->definedMeaningId = $id;
148149 $record->definedMeaningCompleteDefiningExpression = getDefiningExpressionRecord($id);
149150 $record->definition = getDefinedMeaningDefinitionRecord($id, $view);
150151 $record->classAttributes = getClassAttributesRecordSet($id, $view);
Index: trunk/extensions/Wikidata/OmegaWiki/ContextFetcher.php
@@ -27,6 +27,7 @@
2828 $this->levelsToLookUp = $levelsToLookUp;
2929 $this->attribute = $attribute;
3030 }
 31+
3132 public function fetch($keyPath) {
3233 if ($keyPath->peek($this->levelsToLookUp)->getStructure()->supportsAttribute($this->attribute))
3334 return $keyPath->peek($this->levelsToLookUp)->getAttributeValue($this->attribute);
@@ -55,6 +56,6 @@
5657 $attribute = $this->attribute;
5758 return "DefinitionObjectIdFetcher($levelsToLookUp, $attribute)";
5859 }
59 -}
 60+}
6061
6162
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -16,12 +16,19 @@
1717 define('EOL',"\n"); # Makes human (and vim :-p) readable output (somewhat...)
1818 #define('EOL',""); # Output only readable by browsers
1919
 20+/**
 21+ * Class IdStack is used to keep track of context during the rendering of
 22+ * a hierarchical structure of Records and RecordSets. The name IdStack might
 23+ * not be accurate anymore and might be renamed to something else like RenderContext.
 24+ */
 25+
2026 class IdStack {
2127 protected $keyStack;
2228 protected $idStack = array();
2329 protected $currentId;
2430 protected $classStack = array();
2531 protected $currentClass;
 32+ protected $definedMeaningIdStack = array(); // Used to keep track of which defined meaning is being rendered
2633
2734 public function __construct($prefix) {
2835 $this->keyStack = new RecordStack();
@@ -89,6 +96,23 @@
9097 public function getKeyStack() {
9198 return $this->keyStack;
9299 }
 100+
 101+ public function pushDefinedMeaningId($definedMeaningId) {
 102+ return $this->definedMeaningIdStack[] = $definedMeaningId;
 103+ }
 104+
 105+ public function popDefinedMeaningId() {
 106+ return array_pop($this->definedMeaningIdStack);
 107+ }
 108+
 109+ public function getDefinedMeaningId() {
 110+ $stackSize = count($this->definedMeaningIdStack);
 111+
 112+ if ($stackSize > 0)
 113+ return $this->definedMeaningIdStack[$stackSize - 1];
 114+ else
 115+ throw new Exception("There is no defined meaning defined in the current context");
 116+ }
93117
94118 public function __tostring() {
95119 return "<object of class IdStack>";
@@ -1229,20 +1253,18 @@
12301254
12311255 class AttributeEditor extends DefinedMeaningReferenceEditor {
12321256 protected $attributesLevelName;
1233 - protected $objectIdFetcher;
12341257
1235 - public function __construct(Attribute $attribute = null, PermissionController $permissionController, $isAddField, $attributesLevelName, ContextFetcher $objectIdFetcher) {
 1258+ public function __construct(Attribute $attribute = null, PermissionController $permissionController, $isAddField, $attributesLevelName) {
12361259 parent::__construct($attribute, $permissionController, $isAddField);
12371260
12381261 $this->attributesLevelName = $attributesLevelName;
1239 - $this->objectIdFetcher = $objectIdFetcher;
12401262 }
12411263
12421264 public function add(IdStack $idPath) {
12431265 if ($this->isAddField) {
12441266 $parameters = array(
12451267 "attributesLevel" => $this->attributesLevelName,
1246 - "attributesObjectId" => $this->objectIdFetcher->fetch($idPath->getKeyStack())
 1268+ "attributesObjectId" => $idPath->getDefinedMeaningId()
12471269 );
12481270
12491271 return getSuggest($this->addId($idPath->getId()), $this->suggestType(), $parameters);
@@ -1283,13 +1305,10 @@
12841306 public function add(IdStack $idPath) {
12851307 if ($this->isAddField) {
12861308 $syntransId = $idPath->getKeyStack()->peek(0)->syntransId;
1287 - $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
12881309
1289 -// echo "SyntransId: $syntransId ObjectId: $objectId\n";
1290 -
12911310 $parameters = array(
12921311 'attributesLevel' => $this->attributesLevelName,
1293 - 'attributesObjectId' => $objectId,
 1312+ 'attributesObjectId' => $idPath->getDefinedMeaningId(),
12941313 'onUpdate' => 'updateSelectOptions(\'' . $this->addId($idPath->getId()) . '-option\',' . $syntransId
12951314 );
12961315 return getSuggest($this->addId($idPath->getId()), $this->suggestType(), $parameters);
@@ -2201,3 +2220,27 @@
22022221 return true;
22032222 }
22042223 }
 2224+
 2225+class DefinedMeaningContextEditor extends WrappingEditor {
 2226+ public function view(IdStack $idPath, $value) {
 2227+ $idPath->pushDefinedMeaningId($value->definedMeaningId);
 2228+ $result = $this->wrappedEditor->view($idPath, $value);
 2229+ $idPath->popDefinedMeaningId();
 2230+
 2231+ return $result;
 2232+ }
 2233+
 2234+ public function edit(IdStack $idPath, $value) {
 2235+ $idPath->pushDefinedMeaningId($value->definedMeaningId);
 2236+ $result = $this->wrappedEditor->edit($idPath, $value);
 2237+ $idPath->popDefinedMeaningId();
 2238+
 2239+ return $result;
 2240+ }
 2241+
 2242+ public function save(IdStack $idPath, $value) {
 2243+ $idPath->pushDefinedMeaningId($value->definedMeaningId);
 2244+ $this->wrappedEditor->save($idPath, $value);
 2245+ $idPath->popDefinedMeaningId();
 2246+ }
 2247+}

Status & tagging log