r23889 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23888‎ | r23889 | r23890 >
Date:08:48, 9 July 2007
Author:proes
Status:old
Tags:
Comment:
Introduced TableColumnsToAttributesMapping
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialTransaction.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -216,8 +216,12 @@
217217
218218 global
219219 $urlAttribute, $urlAttributeIdAttribute, $urlAttributeObjectAttribute, $urlAttributeAttribute, $urlAttributeValuesStructure, $urlAttributeValuesAttribute,
220 - $wgUrlAttributeValuesAttributeName, $wgUrlAttributeAttributeName;
 220+ $wgUrlAttributeValuesAttributeName, $wgUrlAttributeAttributeName, $hyperLinkAttribute, $hyperLinkLabelAttribute, $hyperLinkURLAttribute;
221221
 222+ $hyperLinkLabelAttribute = new Attribute("label", "Label", "short-text");
 223+ $hyperLinkURLAttribute = new Attribute("url", "URL", "url");
 224+ $hyperLinkAttribute = new Attribute("hyperlink", "Link", new Structure($hyperLinkLabelAttribute, $hyperLinkURLAttribute));
 225+
222226 $urlAttribute = new Attribute("url", "URL", "url");
223227 $urlAttributeIdAttribute = new Attribute("url-attribute-id", "Attribute identifier", "object-id");
224228 $urlAttributeObjectAttribute = new Attribute("url-attribute-object-id", "Attribute object", "object-id");
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialTransaction.php
@@ -407,8 +407,8 @@
408408 'transaction-id',
409409 $queryTransactionInformation,
410410 $transactionIdAttribute,
411 - array(
412 - 'transaction_id' => $transactionIdAttribute
 411+ new TableColumnsToAttributesMapping(
 412+ new TableColumnsToAttribute(array('transaction_id'), $transactionIdAttribute)
413413 ),
414414 $transactionsTable,
415415 $restrictions,
Index: trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php
@@ -2,6 +2,62 @@
33
44 require_once('Transaction.php');
55
 6+class TableColumnsToAttribute {
 7+ protected $tableColumns;
 8+ protected $attribute;
 9+
 10+ public function __construct(array $tableColumns, Attribute $attribute) {
 11+ $this->tableColumns = $tableColumns;
 12+ $this->attribute = $attribute;
 13+ }
 14+
 15+ public function getTableColumns() {
 16+ return $this->tableColumns;
 17+ }
 18+
 19+ public function getAttribute() {
 20+ return $this->attribute;
 21+ }
 22+}
 23+
 24+class TableColumnsToAttributesMapping {
 25+ protected $tableColumnsToAttributes;
 26+
 27+ public function __construct($tableColumnsToAttributes) {
 28+ if (is_array($tableColumnsToAttributes))
 29+ $this->tableColumnsToAttributes = $tableColumnsToAttributes;
 30+ else
 31+ $this->tableColumnsToAttributes = func_get_args();
 32+ }
 33+
 34+ public function getSelectColumns() {
 35+ $result = array();
 36+
 37+ foreach ($this->tableColumnsToAttributes as $tableColumnToAttribute)
 38+ foreach($tableColumnToAttribute->getTableColumns() as $tableColumn)
 39+ $result[] = $tableColumn;
 40+
 41+ return $result;
 42+ }
 43+
 44+ public function getAttributes() {
 45+ $result = array();
 46+
 47+ foreach ($this->tableColumnsToAttributes as $tableColumnToAttribute)
 48+ $result[] = $tableColumnToAttribute->getAttribute();
 49+
 50+ return $result;
 51+ }
 52+
 53+ public function getCount() {
 54+ return count($this->tableColumnsToAttributes);
 55+ }
 56+
 57+ public function getMapping($index) {
 58+ return $this->tableColumnsToAttributes[$index];
 59+ }
 60+}
 61+
662 function getTransactedSQL(QueryTransactionInformation $transactionInformation, array $selectFields, Table $table, array $restrictions, array $orderBy = array(), $count = -1, $offset = 0) {
763 $tableNames = array($table->getIdentifier());
864
@@ -34,11 +90,22 @@
3591 return $query;
3692 }
3793
38 -function queryRecordSet($recordSetStructureId, QueryTransactionInformation $transactionInformation, Attribute $keyAttribute, array $fieldAttributeMapping, Table $table, array $restrictions, array $orderBy = array(), $count = -1, $offset = 0) {
 94+function getRecordFromRow($row, $columnIndex, Structure $structure) {
 95+ $result = new ArrayRecord($structure);
 96+
 97+ foreach ($structure->getAttributes() as $attribute) {
 98+ $result->setAttributeValue($attribute, $row[$columnIndex]);
 99+ $columnIndex++;
 100+ }
 101+
 102+ return $result;
 103+}
 104+
 105+function queryRecordSet($recordSetStructureId, QueryTransactionInformation $transactionInformation, Attribute $keyAttribute, TableColumnsToAttributesMapping $tableColumnsToAttributeMapping, Table $table, array $restrictions, array $orderBy = array(), $count = -1, $offset = 0) {
39106 $dbr =& wfGetDB(DB_SLAVE);
40107
41 - $selectFields = array_keys($fieldAttributeMapping);
42 - $attributes = array_values($fieldAttributeMapping);
 108+ $selectFields = $tableColumnsToAttributeMapping->getSelectColumns();
 109+ $attributes = $tableColumnsToAttributeMapping->getAttributes();
43110
44111 if ($table->isVersioned)
45112 $allAttributes = array_merge($attributes, $transactionInformation->versioningAttributes());
@@ -57,10 +124,22 @@
58125
59126 while ($row = $dbr->fetchRow($queryResult)) {
60127 $record = new ArrayRecord($structure);
 128+ $columnIndex = 0;
61129
62 - for ($i = 0; $i < count($attributes); $i++)
63 - $record->setAttributeValue($attributes[$i], $row[$i]);
 130+ for ($i = 0; $i < $tableColumnsToAttributeMapping->getCount(); $i++) {
 131+ $mapping = $tableColumnsToAttributeMapping->getMapping($i);
 132+ $attribute = $mapping->getAttribute();
 133+ $tableColumns = $mapping->getTableColumns();
64134
 135+ if (count($tableColumns) == 1)
 136+ $value = $row[$columnIndex];
 137+ else
 138+ $value = getRecordFromRow($row, $columnIndex, $attribute->getStructure());
 139+
 140+ $record->setAttributeValue($attribute, $value);
 141+ $columnIndex += count($tableColumns);
 142+ }
 143+
65144 $transactionInformation->setVersioningAttributes($record, $row);
66145 $recordSet->add($record);
67146 }
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
@@ -468,11 +468,11 @@
469469 $classAttributesStructure->getStructureType(),
470470 $viewInformation->queryTransactionInformation,
471471 $classAttributeIdAttribute,
472 - array(
473 - 'object_id' => $classAttributeIdAttribute,
474 - 'level_mid' => $classAttributeLevelAttribute,
475 - 'attribute_mid' => $classAttributeAttributeAttribute,
476 - 'attribute_type' => $classAttributeTypeAttribute
 472+ new TableColumnsToAttributesMapping(
 473+ new TableColumnsToAttribute(array('object_id'), $classAttributeIdAttribute),
 474+ new TableColumnsToAttribute(array('level_mid'), $classAttributeLevelAttribute),
 475+ new TableColumnsToAttribute(array('attribute_mid'), $classAttributeAttributeAttribute),
 476+ new TableColumnsToAttribute(array('attribute_type'),$classAttributeTypeAttribute)
477477 ),
478478 $classAttributesTable,
479479 array("class_mid=$definedMeaningId")
@@ -504,9 +504,9 @@
505505 $alternativeDefinitionsStructure->getStructureType(),
506506 $viewInformation->queryTransactionInformation,
507507 $definitionIdAttribute,
508 - array(
509 - 'meaning_text_tcid' => $definitionIdAttribute,
510 - 'source_id' => $sourceAttribute
 508+ new TableColumnsToAttributesMapping(
 509+ new TableColumnsToAttribute(array('meaning_text_tcid'), $definitionIdAttribute),
 510+ new TableColumnsToAttribute(array('source_id'), $sourceAttribute)
511511 ),
512512 $alternativeDefinitionsTable,
513513 array("meaning_mid=$definedMeaningId")
@@ -663,9 +663,9 @@
664664 $translatedTextStructure->getStructureType(),
665665 $viewInformation->queryTransactionInformation,
666666 $languageAttribute,
667 - array(
668 - 'language_id' => $languageAttribute,
669 - 'text_id' => $textAttribute
 667+ new TableColumnsToAttributesMapping(
 668+ new TableColumnsToAttribute(array('language_id'), $languageAttribute),
 669+ new TableColumnsToAttribute(array('text_id'), $textAttribute)
670670 ),
671671 $translatedContentTable,
672672 array("translated_content_id=$translatedContentId")
@@ -684,9 +684,9 @@
685685 null,
686686 $viewInformation->queryTransactionInformation,
687687 $languageAttribute,
688 - array(
689 - 'language_id' => $languageAttribute,
690 - 'text_id' => $textAttribute
 688+ new TableColumnsToAttributesMapping(
 689+ new TableColumnsToAttribute(array('language_id'), $languageAttribute),
 690+ new TableColumnsToAttribute(array('text_id'), $textAttribute)
691691 ),
692692 $translatedContentTable,
693693 array(
@@ -721,10 +721,10 @@
722722 $synonymsTranslationsStructure->getStructureType(),
723723 $viewInformation->queryTransactionInformation,
724724 $syntransIdAttribute,
725 - array(
726 - 'syntrans_sid' => $syntransIdAttribute,
727 - 'expression_id' => $expressionAttribute,
728 - 'identical_meaning' => $identicalMeaningAttribute
 725+ new TableColumnsToAttributesMapping(
 726+ new TableColumnsToAttribute(array('syntrans_sid'), $syntransIdAttribute),
 727+ new TableColumnsToAttribute(array('expression_id'), $expressionAttribute),
 728+ new TableColumnsToAttribute(array('identical_meaning'),$identicalMeaningAttribute)
729729 ),
730730 $syntransTable,
731731 $restrictions
@@ -868,10 +868,10 @@
869869 $relationStructure->getStructureType(),
870870 $viewInformation->queryTransactionInformation,
871871 $relationIdAttribute,
872 - array(
873 - 'relation_id' => $relationIdAttribute,
874 - 'relationtype_mid' => $relationTypeAttribute,
875 - 'meaning2_mid' => $otherDefinedMeaningAttribute
 872+ new TableColumnsToAttributesMapping(
 873+ new TableColumnsToAttribute(array('relation_id'), $relationIdAttribute),
 874+ new TableColumnsToAttribute(array('relationtype_mid'), $relationTypeAttribute),
 875+ new TableColumnsToAttribute(array('meaning2_mid'), $otherDefinedMeaningAttribute)
876876 ),
877877 $meaningRelationsTable,
878878 $restrictions,
@@ -894,10 +894,10 @@
895895 $reciprocalRelationsAttribute->id,
896896 $viewInformation->queryTransactionInformation,
897897 $relationIdAttribute,
898 - array(
899 - 'relation_id' => $relationIdAttribute,
900 - 'relationtype_mid' => $relationTypeAttribute,
901 - 'meaning1_mid' => $otherDefinedMeaningAttribute
 898+ new TableColumnsToAttributesMapping(
 899+ new TableColumnsToAttribute(array('relation_id'), $relationIdAttribute),
 900+ new TableColumnsToAttribute(array('relationtype_mid'), $relationTypeAttribute),
 901+ new TableColumnsToAttribute(array('meaning1_mid'), $otherDefinedMeaningAttribute)
902902 ),
903903 $meaningRelationsTable,
904904 array("meaning2_mid=$definedMeaningId"),
@@ -919,9 +919,9 @@
920920 null,
921921 $viewInformation->queryTransactionInformation,
922922 $possiblySynonymousIdAttribute,
923 - array(
924 - 'relation_id' => $possiblySynonymousIdAttribute,
925 - 'meaning2_mid' => $possibleSynonymAttribute
 923+ new TableColumnsToAttributesMapping(
 924+ new TableColumnsToAttribute(array('relation_id'), $possiblySynonymousIdAttribute),
 925+ new TableColumnsToAttribute(array('meaning2_mid'), $possibleSynonymAttribute)
926926 ),
927927 $meaningRelationsTable,
928928 array(
@@ -957,9 +957,9 @@
958958 $collectionMembershipStructure->getStructureType(),
959959 $viewInformation->queryTransactionInformation,
960960 $collectionIdAttribute,
961 - array(
962 - 'collection_id' => $collectionIdAttribute,
963 - 'internal_member_id' => $sourceIdentifierAttribute
 961+ new TableColumnsToAttributesMapping(
 962+ new TableColumnsToAttribute(array('collection_id'), $collectionIdAttribute),
 963+ new TableColumnsToAttribute(array('internal_member_id'), $sourceIdentifierAttribute)
964964 ),
965965 $collectionMembershipsTable,
966966 array("member_mid=$definedMeaningId")
@@ -988,11 +988,11 @@
989989 $textAttributeValuesStructure->getStructureType(),
990990 $viewInformation->queryTransactionInformation,
991991 $textAttributeIdAttribute,
992 - array(
993 - 'value_id' => $textAttributeIdAttribute,
994 - 'object_id' => $textAttributeObjectAttribute,
995 - 'attribute_mid' => $textAttributeAttribute,
996 - 'text' => $textAttribute
 992+ new TableColumnsToAttributesMapping(
 993+ new TableColumnsToAttribute(array('value_id'), $textAttributeIdAttribute),
 994+ new TableColumnsToAttribute(array('object_id'), $textAttributeObjectAttribute),
 995+ new TableColumnsToAttribute(array('attribute_mid'), $textAttributeAttribute),
 996+ new TableColumnsToAttribute(array('text'), $textAttribute)
997997 ),
998998 $textAttributeValuesTable,
999999 array("object_id IN (" . implode(", ", $objectIds) . ")")
@@ -1014,11 +1014,11 @@
10151015 $urlAttributeValuesStructure->getStructureType(),
10161016 $viewInformation->queryTransactionInformation,
10171017 $urlAttributeIdAttribute,
1018 - array(
1019 - 'value_id' => $urlAttributeIdAttribute,
1020 - 'object_id' => $urlAttributeObjectAttribute,
1021 - 'attribute_mid' => $urlAttributeAttribute,
1022 - 'url' => $urlAttribute
 1018+ new TableColumnsToAttributesMapping(
 1019+ new TableColumnsToAttribute(array('value_id'), $urlAttributeIdAttribute),
 1020+ new TableColumnsToAttribute(array('object_id'), $urlAttributeObjectAttribute),
 1021+ new TableColumnsToAttribute(array('attribute_mid'), $urlAttributeAttribute),
 1022+ new TableColumnsToAttribute(array('url'), $urlAttribute)
10231023 ),
10241024 $urlAttributeValuesTable,
10251025 array("object_id IN (" . implode(", ", $objectIds) . ")")
@@ -1040,11 +1040,11 @@
10411041 $translatedTextAttributeValuesStructure->getStructureType(),
10421042 $viewInformation->queryTransactionInformation,
10431043 $translatedTextAttributeIdAttribute,
1044 - array(
1045 - 'value_id' => $translatedTextAttributeIdAttribute,
1046 - 'object_id' => $translatedTextAttributeObjectAttribute,
1047 - 'attribute_mid' => $translatedTextAttributeAttribute,
1048 - 'value_tcid' => $translatedTextValueIdAttribute
 1044+ new TableColumnsToAttributesMapping(
 1045+ new TableColumnsToAttribute(array('value_id'), $translatedTextAttributeIdAttribute),
 1046+ new TableColumnsToAttribute(array('object_id'), $translatedTextAttributeObjectAttribute),
 1047+ new TableColumnsToAttribute(array('attribute_mid'), $translatedTextAttributeAttribute),
 1048+ new TableColumnsToAttribute(array('value_tcid'), $translatedTextValueIdAttribute)
10491049 ),
10501050 $translatedContentAttributeValuesTable,
10511051 array("object_id IN (" . implode(", ", $objectIds) . ")")
@@ -1066,11 +1066,11 @@
10671067 null,
10681068 $viewInformation->queryTransactionInformation,
10691069 $optionAttributeOptionIdAttribute,
1070 - array(
1071 - 'option_id' => $optionAttributeOptionIdAttribute,
1072 - 'attribute_id' => $optionAttributeAttribute,
1073 - 'option_mid' => $optionAttributeOptionAttribute,
1074 - 'language_id' => $languageAttribute
 1070+ new TableColumnsToAttributesMapping(
 1071+ new TableColumnsToAttribute(array('option_id'), $optionAttributeOptionIdAttribute),
 1072+ new TableColumnsToAttribute(array('attribute_id'), $optionAttributeAttribute),
 1073+ new TableColumnsToAttribute(array('option_mid'), $optionAttributeOptionAttribute),
 1074+ new TableColumnsToAttribute(array('language_id'), $languageAttribute)
10751075 ),
10761076 $optionAttributeOptionsTable,
10771077 array('attribute_id = ' . $attributeId)
@@ -1090,10 +1090,10 @@
10911091 $optionAttributeValuesStructure->getStructureType(),
10921092 $viewInformation->queryTransactionInformation,
10931093 $optionAttributeIdAttribute,
1094 - array(
1095 - 'value_id' => $optionAttributeIdAttribute,
1096 - 'object_id' => $optionAttributeObjectAttribute,
1097 - 'option_id' => $optionAttributeOptionIdAttribute
 1094+ new TableColumnsToAttributesMapping(
 1095+ new TableColumnsToAttribute(array('value_id'), $optionAttributeIdAttribute),
 1096+ new TableColumnsToAttribute(array('object_id'), $optionAttributeObjectAttribute),
 1097+ new TableColumnsToAttribute(array('option_id'), $optionAttributeOptionIdAttribute)
10981098 ),
10991099 $optionAttributeValuesTable,
11001100 array("object_id IN (" . implode(", ", $objectIds) . ")")
@@ -1118,9 +1118,9 @@
11191119 null,
11201120 $viewInformation->queryTransactionInformation,
11211121 $optionAttributeOptionIdAttribute,
1122 - array(
1123 - 'attribute_id' => $optionAttributeIdAttribute,
1124 - 'option_mid' => $optionAttributeOptionAttribute
 1122+ new TableColumnsToAttributesMapping(
 1123+ new TableColumnsToAttribute(array('attribute_id'), $optionAttributeIdAttribute),
 1124+ new TableColumnsToAttribute(array('option_mid'), $optionAttributeOptionAttribute)
11251125 ),
11261126 $optionAttributeOptionsTable,
11271127 array('option_id = ' . $record->getAttributeValue($optionAttributeOptionIdAttribute))
@@ -1136,7 +1136,7 @@
11371137 null,
11381138 $viewInformation->queryTransactionInformation,
11391139 $optionAttributeIdAttribute,
1140 - array('attribute_mid' => $optionAttributeAttribute),
 1140+ new TableColumnsToAttributesMapping(new TableColumnsToAttribute(array('attribute_mid'), $optionAttributeAttribute)),
11411141 $classAttributesTable,
11421142 array('object_id = ' . $optionRecord->getAttributeValue($optionAttributeIdAttribute))
11431143 );
@@ -1158,9 +1158,9 @@
11591159 $classMembershipStructure->getStructureType(),
11601160 $viewInformation->queryTransactionInformation,
11611161 $classMembershipIdAttribute,
1162 - array(
1163 - 'class_membership_id' => $classMembershipIdAttribute,
1164 - 'class_mid' => $classAttribute
 1162+ new TableColumnsToAttributesMapping(
 1163+ new TableColumnsToAttribute(array('class_membership_id'), $classMembershipIdAttribute),
 1164+ new TableColumnsToAttribute(array('class_mid'), $classAttribute)
11651165 ),
11661166 $classMembershipsTable,
11671167 array("class_member_mid=$definedMeaningId")

Status & tagging log