r25226 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25225‎ | r25226 | r25227 >
Date:10:00, 28 August 2007
Author:proes
Status:old
Tags:
Comment:
Introduced Structure->supportsAttribute. This check is disabled by default but can be turned on for debugging. After all problems exposed by the check have been solved, the check will be turned on permanently.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Attribute.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Fetcher.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Record.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -106,20 +106,20 @@
107107 $t->expression = new Attribute("expression", wfMsgSc("Spelling"), "spelling");
108108 else {
109109 $t->expressionStructure = new Structure("expression", $t->language, $t->spelling);
110 - $t->expression = new Attribute(null, wfMsgSc("Expression"), $t->expressionStructure);
 110+ $t->expression = new Attribute("expression", wfMsgSc("Expression"), $t->expressionStructure);
111111 }
112112
113113 $t->definedMeaningId = new Attribute("defined-meaning-id", "Defined meaning identifier", "defined-meaning-id");
114114 $t->definedMeaningDefiningExpression = new Attribute("defined-meaning-defining-expression", "Defined meaning defining expression", "short-text");
115115 $t->definedMeaningCompleteDefiningExpressionStructure =
116 - new Structure("defined-meaning-full-defining-expression",
 116+ new Structure("defined-meaning-complete-defining-expression",
117117 $t->definedMeaningDefiningExpression,
118118 $t->expressionId,
119119 $t->language
120120 );
121121 #try this
122122 $t->definedMeaningCompleteDefiningExpressionStructure->setStructureType("expression");
123 - $t->definedMeaningCompleteDefiningExpression=new Attribute(null, "Defining expression", $t->definedMeaningCompleteDefiningExpressionStructure);
 123+ $t->definedMeaningCompleteDefiningExpression = new Attribute(null, "Defining expression", $t->definedMeaningCompleteDefiningExpressionStructure);
124124 global
125125 $definedMeaningReferenceType;
126126
@@ -160,7 +160,7 @@
161161 $wgRelationsAttributeId, $wgIncomingRelationsAttributeId ;
162162
163163 $t->relationStructure = new Structure("relations", $t->relationId, $t->relationType, $t->otherDefinedMeaning, $t->objectAttributes);
164 - $t->relations = new Attribute(null, wfMsgSc("Relations"), $t->relationStructure);
 164+ $t->relations = new Attribute("relations", wfMsgSc("Relations"), $t->relationStructure);
165165 $t->reciprocalRelations = new Attribute("reciprocal-relations", wfMsgSc("IncomingRelations"), $t->relationStructure);
166166 $t->translatedTextId = new Attribute("translated-text-id", "Translated text ID", "integer");
167167 $t->translatedTextStructure = new Structure("translated-text", $t->language, $t->text);
@@ -178,7 +178,6 @@
179179 $wgAlternativeDefinitionsAttributeId;
180180
181181 $t->alternativeDefinitionsStructure = new Structure("alternative-definitions", $t->definitionId, $t->alternativeDefinition, $t->source);
182 -
183182 $t->alternativeDefinitions = new Attribute(null, wfMsgSc("AlternativeDefinitions"), $t->alternativeDefinitionsStructure);
184183
185184 global
@@ -201,7 +200,7 @@
202201 if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes())
203202 $t->translatedTextValue = new Attribute("translated-text-value", wfMsgSc("TranslatedTextAttributeValue"), "text");
204203 else
205 - $t->translatedTextValue = new Attribute("translated-text", wfMsgSc("TranslatedTextAttributeValue"), $t->translatedTextStructure);
 204+ $t->translatedTextValue = new Attribute("translated-text-value", wfMsgSc("TranslatedTextAttributeValue"), $t->translatedTextStructure);
206205
207206 $t->translatedTextAttributeValuesStructure = new Structure("translated-text-attribute-values",$t->translatedTextAttributeId, $t->attributeObjectId, $t->translatedTextAttribute, $t->translatedTextValueId, $t->translatedTextValue, $t->objectAttributes);
208207 $t->translatedTextAttributeValues = new Attribute(null, wfMsgSc("TranslatedTextAttributeValues"), $t->translatedTextAttributeValuesStructure);
@@ -220,20 +219,20 @@
221220 $t->linkAttribute = new Attribute("link-attribute", wfMsgSc("LinkAttribute"), $t->definedMeaningReferenceStructure);
222221 $t->linkAttributeValuesStructure = new Structure("link-attribute-values", $t->linkAttributeId, $t->linkAttributeObject, $t->linkAttribute, $t->link, $t->objectAttributes);
223222 $t->linkAttributeValues = new Attribute(null, wfMsgSc("LinkAttributeValues"), $t->linkAttributeValuesStructure);
224 - $t->optionAttributeId = new Attribute('option-attribute-id', 'Attribute identifier', 'object-id');
225 - $t->optionAttributeObject = new Attribute('option-attribute-object-id', 'Attribute object', 'object-id');
226 - $t->optionAttribute = new Attribute('option-attribute', wfMsgSc("OptionAttribute"), $definedMeaningReferenceType);
227 - $t->optionAttributeOption = new Attribute('option-attribute-option', wfMsgSc("OptionAttributeOption"), $definedMeaningReferenceType);
228 - $t->optionAttributeValuesStructure = new Structure('option-attribute-values', $t->optionAttributeId, $t->optionAttribute, $t->optionAttributeObject, $t->optionAttributeOption, $t->objectAttributes);
 223+ $t->optionAttributeId = new Attribute("option-attribute-id", "Attribute identifier", "object-id");
 224+ $t->optionAttributeObject = new Attribute("option-attribute-object-id", "Attribute object", "object-id");
 225+ $t->optionAttribute = new Attribute("option-attribute", wfMsgSc("OptionAttribute"), $definedMeaningReferenceType);
 226+ $t->optionAttributeOption = new Attribute("option-attribute-option", wfMsgSc("OptionAttributeOption"), $definedMeaningReferenceType);
 227+ $t->optionAttributeValuesStructure = new Structure("option-attribute-values", $t->optionAttributeId, $t->optionAttribute, $t->optionAttributeObject, $t->optionAttributeOption, $t->objectAttributes);
229228 $t->optionAttributeValues = new Attribute(null, wfMsgSc("OptionAttributeValues"), $t->optionAttributeValuesStructure);
230 - $t->optionAttributeOptionId = new Attribute('option-attribute-option-id', 'Option identifier', 'object-id');
231 - $t->optionAttributeOptionsStructure = new Structure('option-attribute-options', $t->optionAttributeOptionId, $t->optionAttribute, $t->optionAttributeOption, $t->language);
 229+ $t->optionAttributeOptionId = new Attribute("option-attribute-option-id", "Option identifier", "object-id");
 230+ $t->optionAttributeOptionsStructure = new Structure("option-attribute-options", $t->optionAttributeOptionId, $t->optionAttribute, $t->optionAttributeOption, $t->language);
232231 $t->optionAttributeOptions = new Attribute(null, wfMsgSc("OptionAttributeOptions"), $t->optionAttributeOptionsStructure);
233232
234233 if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes())
235234 $t->translatedText = new Attribute("translated-text", wfMsgSc("Text"), "text");
236235 else
237 - $t->translatedText = new Attribute(null, wfMsgSc("TranslatedText"), $t->translatedTextStructure);
 236+ $t->translatedText = new Attribute("translated-text", wfMsgSc("TranslatedText"), $t->translatedTextStructure);
238237
239238 $t->definition = new Attribute(null, wfMsgSc("Definition"), new Structure("definition", $t->translatedText, $t->objectAttributes));
240239
@@ -250,6 +249,7 @@
251250 $t->definedMeaning = new Attribute(null, wfMsgSc("DefinedMeaning"),
252251 new Structure(
253252 "defined-meaning",
 253+ $t->definedMeaningCompleteDefiningExpression,
254254 $t->definition,
255255 $t->classAttributes,
256256 $t->alternativeDefinitions,
@@ -258,11 +258,12 @@
259259 $t->reciprocalRelations,
260260 $t->classMembership,
261261 $t->collectionMembership,
262 - $t->definedMeaningAttributes)
 262+ $t->definedMeaningAttributes
 263+ )
263264 );
264265
265 - $t->expressionMeaningStructure = new Structure("expression-exact-meanings", $t->definedMeaningId, $t->text, $t->definedMeaning);
266 - $t->expressionExactMeanings = new Attribute(null, wfMsgSc("ExactMeanings"), $t->expressionMeaningStructure);
 266+ $t->expressionMeaningStructure = new Structure($t->definedMeaningId, $t->text, $t->definedMeaning);
 267+ $t->expressionExactMeanings = new Attribute("expression-exact-meanings", wfMsgSc("ExactMeanings"), $t->expressionMeaningStructure);
267268 $t->expressionApproximateMeanings = new Attribute("expression-approximate-meanings", wfMsgSc("ApproximateMeanings"), $t->expressionMeaningStructure);
268269 # bug found here also: $t->expressionAoproximateMeaning_S_
269270 $t->expressionMeaningsStructure = new Structure("expression-meanings", $t->expressionExactMeanings, $t->expressionApproximateMeanings);
@@ -270,22 +271,27 @@
271272 $t->expressionsStructure = new Structure("expressions", $t->expressionId, $t->expression, $t->expressionMeanings);
272273 $t->expressions = new Attribute(null, wfMsgSc("Expressions"), $t->expressionsStructure);
273274 $t->objectId = new Attribute("object-id", "Object identifier", "object-id");
274 - $t->objectAttributesStructure = new Structure("object-attributes", $t->objectId, $t->textAttributeValues, $t->translatedTextAttributeValues, $t->optionAttributeValues);
 275+ $t->objectAttributesStructure = new Structure("object-attributes", $t->objectId, $t->textAttributeValues, $t->translatedTextAttributeValues, $t->linkAttributeValues, $t->optionAttributeValues);
275276 $t->objectAttributes->setAttributeType($t->objectAttributesStructure);
276277 $t->definedMeaningAttributes->setAttributeType($t->objectAttributesStructure);
277278
278 - $t->annotatedAttributes = array(
 279+ $annotatedAttributes = array(
 280+ $t->definedMeaning,
279281 $t->definition,
280282 $t->synonymsAndTranslations,
281283 $t->relations,
282 - $t->reciprocalRelations
 284+ $t->reciprocalRelations,
 285+ $t->textAttributeValues,
 286+ $t->linkAttributeValues,
 287+ $t->translatedTextAttributeValues,
 288+ $t->optionAttributeValues
283289 );
284290
285291 foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter) {
286292 $attribute = $propertyToColumnFilter->getAttribute();
287293 $attribute->setAttributeType($t->objectAttributesStructure);
288294
289 - foreach ($t->annotatedAttributes as $annotatedAttribute)
 295+ foreach ($annotatedAttributes as $annotatedAttribute)
290296 $annotatedAttribute->type->addAttribute($attribute);
291297 }
292298 $t->in_setup=False;
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -1289,13 +1289,11 @@
12901290 public function add(IdStack $idPath) {
12911291 if ($this->isAddField) {
12921292
1293 - $o=OmegaWikiAttributes::getInstance();
1294 -
1295 - $syntransId = $idPath->getKeyStack()->peek(0)->syntransId;
 1293+ $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
12961294 $parameters = array(
12971295 'attributesLevel' => $this->attributesLevelName,
1298 - 'attributesObjectId' => $this->objectIdFetcher->fetch($idPath->getKeyStack()),
1299 - 'onUpdate' => 'updateSelectOptions(\'' . $this->addId($idPath->getId()) . '-option\',' . $syntransId
 1296+ 'attributesObjectId' => $objectId,
 1297+ 'onUpdate' => 'updateSelectOptions(\'' . $this->addId($idPath->getId()) . '-option\',' . $objectId
13001298 );
13011299 return getSuggest($this->addId($idPath->getId()), $this->suggestType(), $parameters);
13021300 }
Index: trunk/extensions/Wikidata/OmegaWiki/Attribute.php
@@ -42,16 +42,15 @@
4343 }
4444
4545 class Structure {
46 -
47 - private $structure;
 46+ private $attributes;
4847 private $type;
4948
5049 public function getAttributes() {
51 - return $this->structure;
 50+ return $this->attributes;
5251 }
5352
54 - public function addAttribute($attribute) {
55 - $this->structure[]=$attribute;
 53+ public function addAttribute(Attribute $attribute) {
 54+ $this->attributes[] = $attribute;
5655 }
5756
5857 public function getStructureType() {
@@ -59,7 +58,7 @@
6059 }
6160
6261 public function setStructureType($type) {
63 - $this->type=$type;
 62+ $this->type = $type;
6463 }
6564
6665
@@ -78,22 +77,22 @@
7978
8079 # We're trying to be clever.
8180 $args=func_get_args();
82 - $this->structure=null;
 81+ $this->attributes=null;
8382
8483 if($args[0] instanceof Attribute) {
85 - $this->structure=$args;
 84+ $this->attributes=$args;
8685 } elseif(is_array($args[0])) {
87 - $this->structure=$args[0];
 86+ $this->attributes=$args[0];
8887 }
8988
90 - if(is_array($this->structure)) {
 89+ if(is_array($this->attributes)) {
9190 # We don't know what to call an unnamed
9291 # structure with multiple attributes.
93 - if(sizeof($this->structure)>1) {
 92+ if(sizeof($this->attributes) > 1) {
9493 $this->type='anonymous-structure';
9594 # Meh, just one Attribute. Let's eat it.
96 - } elseif(sizeof($this->structure)==1) {
97 - $this->type=$this->structure[0]->id;
 95+ } elseif(sizeof($this->attributes)==1) {
 96+ $this->type=$this->attributes[0]->id;
9897 } else {
9998 $this->type='empty-structure';
10099 }
@@ -102,16 +101,48 @@
103102 } elseif(is_string($args[0]) && !empty($args[0])) {
104103 $this->type=$args[0];
105104 if(is_array($args[1])) {
106 - $this->structure=$args[1];
 105+ $this->attributes = $args[1];
107106 } else {
108107 array_shift($args);
109 - $this->structure=$args;
 108+ $this->attributes = $args;
110109 }
111110 } else {
112111 # WTF?
113112 throw new Exception("Invalid structure constructor: ".print_r($args,true));
114113 }
115114 }
 115+
 116+ public function supportsAttributeId($attributeId) {
 117+// $result = false;
 118+// $i = 0;
 119+//
 120+// while (!$result && $i < count($this->attributes)) {
 121+// $result = $this->attributes[$i]->id == $attributeId;
 122+// $i++;
 123+// }
 124+//
 125+// return $result;
 126+ return true;
 127+ }
 128+
 129+ public function supportsAttribute(Attribute $attribute) {
 130+ return $this->supportsAttributeId($attribute->id);
 131+ }
 132+
 133+ public function __tostring() {
 134+ $result = "{";
 135+
 136+ if (count($this->attributes) > 0) {
 137+ $result .= $this->attributes[0]->id;
 138+
 139+ for ($i = 1; $i < count($this->attributes); $i++)
 140+ $result .= ", " . $this->attributes[$i]->id;
 141+ }
 142+
 143+ $result .= "}";
 144+
 145+ return $result;
 146+ }
116147 }
117148
118149
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
@@ -523,7 +523,7 @@
524524 $o=OmegaWikiAttributes::getInstance();
525525
526526 $definitionId = getDefinedMeaningDefinitionId($definedMeaningId);
527 - $record = new ArrayRecord(new Structure($o->definition));
 527+ $record = new ArrayRecord($o->definition->type);
528528 $record->translatedText = getTranslatedContentValue($definitionId, $viewInformation);
529529
530530 $objectAttributesRecord = getObjectAttributesRecord($definitionId, $viewInformation, $o->objectAttributes->id);
@@ -553,13 +553,12 @@
554554 }
555555
556556 function getObjectAttributesRecord($objectId, ViewInformation $viewInformation, $structuralOverride = null) {
557 -
558557 $o=OmegaWikiAttributes::getInstance();
559558
560559 if ($structuralOverride)
561 - $record = new ArrayRecord(new Structure($structuralOverride, $o->definedMeaningAttributes));
 560+ $record = new ArrayRecord(new Structure($structuralOverride, $o->definedMeaningAttributes->type->getAttributes()));
562561 else
563 - $record = new ArrayRecord(new Structure($o->definedMeaningAttributes));
 562+ $record = new ArrayRecord($o->definedMeaningAttributes->type);
564563
565564 $record->objectId = $objectId;
566565 $record->textAttributeValues = getTextAttributesValuesRecordSet(array($objectId), $viewInformation);
@@ -571,9 +570,6 @@
572571 }
573572
574573 function filterAttributeValues(RecordSet $sourceRecordSet, Attribute $attributeAttribute, array &$attributeIds) {
575 -
576 - $o=OmegaWikiAttributes::getInstance();
577 -
578574 $result = new ArrayRecordSet($sourceRecordSet->getStructure(), $sourceRecordSet->getKey());
579575 $i = 0;
580576
@@ -744,6 +740,9 @@
745741
746742 $recordSetStructure = $recordSet->getStructure();
747743 $recordSetStructure->addAttribute($attributeToExpand);
 744+
 745+ foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter)
 746+ $recordSetStructure->addAttribute($propertyToColumnFilter->getAttribute());
748747
749748 $objectAttributesRecordStructure = $attributeToExpand->type;
750749 $objectIds = getUniqueIdsInRecordSet($recordSet, array($objectIdAttribute));
@@ -825,7 +824,7 @@
826825 $optionAttributeValuesRecordSet = $emptyOptionAttributesRecordSet;
827826
828827 $objectAttributesRecord = new ArrayRecord($objectAttributesRecordStructure);
829 - $objectAttributesRecord->setAttributeValue($objectIdAttribute, $objectId);
 828+ $objectAttributesRecord->objectId = $objectId;
830829 $objectAttributesRecord->textAttributeValues = $textAttributeValuesRecordSet;
831830 $objectAttributesRecord->translatedTextAttributeValues = $translatedTextAttributeValuesRecordSet;
832831 $objectAttributesRecord->linkAttributeValues = $linkAttributeValuesRecordSet;
@@ -963,7 +962,9 @@
964963 array("member_mid=$definedMeaningId")
965964 );
966965
967 - $recordSet->getStructure()->addAttribute($o->collectionMeaning);
 966+ $structure = $recordSet->getStructure();
 967+ $structure->addAttribute($o->collectionMeaning);
 968+ $structure->addAttribute($o->gotoSource);
968969
969970 for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
970971 $record = $recordSet->getRecord($i);
@@ -1115,6 +1116,9 @@
11161117 global
11171118 $optionAttributeOptionsTable, $classAttributesTable;
11181119
 1120+ $recordSet->getStructure()->addAttribute($o->optionAttributeOption);
 1121+ $recordSet->getStructure()->addAttribute($o->optionAttribute);
 1122+
11191123 for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
11201124 $record = $recordSet->getRecord($i);
11211125
@@ -1171,10 +1175,6 @@
11721176 }
11731177
11741178 function getDefiningExpressionRecord($definedMeaningId) {
1175 -
1176 -
1177 - $o=OmegaWikiAttributes::getInstance();
1178 -
11791179 $o=OmegaWikiAttributes::getInstance();
11801180
11811181 $definingExpression=definingExpressionRow($definedMeaningId);
@@ -1183,5 +1183,4 @@
11841184 $definingExpressionRecord->definedMeaningDefiningExpression = $definingExpression[1];
11851185 $definingExpressionRecord->language = $definingExpression[2];
11861186 return $definingExpressionRecord;
1187 -
11881187 }
Index: trunk/extensions/Wikidata/OmegaWiki/Record.php
@@ -25,9 +25,19 @@
2626 return $this->structure;
2727 }
2828
 29+ protected function getAttributeValueForId($attributeId) {
 30+ if ($this->structure->supportsAttributeId($attributeId)) {
 31+ if (isset($this->values[$attributeId]))
 32+ return $this->values[$attributeId];
 33+ else
 34+ return null;
 35+ }
 36+ else
 37+ throw new Exception("Structure does not support attribute!\n Structure: " . $this->structure . "\n Attribute: " . $attributeId);
 38+ }
 39+
2940 public function getAttributeValue($attribute) {
30 - #FIXME: check if valid
31 - return @$this->values[$attribute->id];
 41+ return $this->getAttributeValueForId($attribute->id);
3242 }
3343
3444 /**
@@ -64,9 +74,15 @@
6575 return $result;
6676 }
6777
 78+ public function setAttributeValueForId($attributeId, $value) {
 79+ if ($this->structure->supportsAttributeId($attributeId))
 80+ $this->values[$attributeId] = $value;
 81+ else
 82+ throw new Exception("Structure does not support attribute!\n Structure: " . $this->structure. "\n Attribute: " . $attributeId);
 83+ }
 84+
6885 public function setAttributeValue(Attribute $attribute, $value) {
69 - #FIXME: check if valid
70 - @$this->values[$attribute->id] = $value;
 86+ $this->setAttributeValueForId($attribute->id, $value);
7187 }
7288
7389 /**
Index: trunk/extensions/Wikidata/OmegaWiki/Fetcher.php
@@ -14,7 +14,10 @@
1515 $this->attribute = $attribute;
1616 }
1717 public function fetch($keyPath) {
18 - return $keyPath->peek($this->attributeLevel)->getAttributeValue($this->attribute);
 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
1922 }
2023 }
2124

Status & tagging log