Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php |
— | — | @@ -216,8 +216,12 @@ |
217 | 217 | |
218 | 218 | global |
219 | 219 | $urlAttribute, $urlAttributeIdAttribute, $urlAttributeObjectAttribute, $urlAttributeAttribute, $urlAttributeValuesStructure, $urlAttributeValuesAttribute, |
220 | | - $wgUrlAttributeValuesAttributeName, $wgUrlAttributeAttributeName; |
| 220 | + $wgUrlAttributeValuesAttributeName, $wgUrlAttributeAttributeName, $hyperLinkAttribute, $hyperLinkLabelAttribute, $hyperLinkURLAttribute; |
221 | 221 | |
| 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 | + |
222 | 226 | $urlAttribute = new Attribute("url", "URL", "url"); |
223 | 227 | $urlAttributeIdAttribute = new Attribute("url-attribute-id", "Attribute identifier", "object-id"); |
224 | 228 | $urlAttributeObjectAttribute = new Attribute("url-attribute-object-id", "Attribute object", "object-id"); |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialTransaction.php |
— | — | @@ -407,8 +407,8 @@ |
408 | 408 | 'transaction-id', |
409 | 409 | $queryTransactionInformation, |
410 | 410 | $transactionIdAttribute, |
411 | | - array( |
412 | | - 'transaction_id' => $transactionIdAttribute |
| 411 | + new TableColumnsToAttributesMapping( |
| 412 | + new TableColumnsToAttribute(array('transaction_id'), $transactionIdAttribute) |
413 | 413 | ), |
414 | 414 | $transactionsTable, |
415 | 415 | $restrictions, |
Index: trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php |
— | — | @@ -2,6 +2,62 @@ |
3 | 3 | |
4 | 4 | require_once('Transaction.php'); |
5 | 5 | |
| 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 | + |
6 | 62 | function getTransactedSQL(QueryTransactionInformation $transactionInformation, array $selectFields, Table $table, array $restrictions, array $orderBy = array(), $count = -1, $offset = 0) { |
7 | 63 | $tableNames = array($table->getIdentifier()); |
8 | 64 | |
— | — | @@ -34,11 +90,22 @@ |
35 | 91 | return $query; |
36 | 92 | } |
37 | 93 | |
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) { |
39 | 106 | $dbr =& wfGetDB(DB_SLAVE); |
40 | 107 | |
41 | | - $selectFields = array_keys($fieldAttributeMapping); |
42 | | - $attributes = array_values($fieldAttributeMapping); |
| 108 | + $selectFields = $tableColumnsToAttributeMapping->getSelectColumns(); |
| 109 | + $attributes = $tableColumnsToAttributeMapping->getAttributes(); |
43 | 110 | |
44 | 111 | if ($table->isVersioned) |
45 | 112 | $allAttributes = array_merge($attributes, $transactionInformation->versioningAttributes()); |
— | — | @@ -57,10 +124,22 @@ |
58 | 125 | |
59 | 126 | while ($row = $dbr->fetchRow($queryResult)) { |
60 | 127 | $record = new ArrayRecord($structure); |
| 128 | + $columnIndex = 0; |
61 | 129 | |
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(); |
64 | 134 | |
| 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 | + |
65 | 144 | $transactionInformation->setVersioningAttributes($record, $row); |
66 | 145 | $recordSet->add($record); |
67 | 146 | } |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php |
— | — | @@ -468,11 +468,11 @@ |
469 | 469 | $classAttributesStructure->getStructureType(), |
470 | 470 | $viewInformation->queryTransactionInformation, |
471 | 471 | $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) |
477 | 477 | ), |
478 | 478 | $classAttributesTable, |
479 | 479 | array("class_mid=$definedMeaningId") |
— | — | @@ -504,9 +504,9 @@ |
505 | 505 | $alternativeDefinitionsStructure->getStructureType(), |
506 | 506 | $viewInformation->queryTransactionInformation, |
507 | 507 | $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) |
511 | 511 | ), |
512 | 512 | $alternativeDefinitionsTable, |
513 | 513 | array("meaning_mid=$definedMeaningId") |
— | — | @@ -663,9 +663,9 @@ |
664 | 664 | $translatedTextStructure->getStructureType(), |
665 | 665 | $viewInformation->queryTransactionInformation, |
666 | 666 | $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) |
670 | 670 | ), |
671 | 671 | $translatedContentTable, |
672 | 672 | array("translated_content_id=$translatedContentId") |
— | — | @@ -684,9 +684,9 @@ |
685 | 685 | null, |
686 | 686 | $viewInformation->queryTransactionInformation, |
687 | 687 | $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) |
691 | 691 | ), |
692 | 692 | $translatedContentTable, |
693 | 693 | array( |
— | — | @@ -721,10 +721,10 @@ |
722 | 722 | $synonymsTranslationsStructure->getStructureType(), |
723 | 723 | $viewInformation->queryTransactionInformation, |
724 | 724 | $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) |
729 | 729 | ), |
730 | 730 | $syntransTable, |
731 | 731 | $restrictions |
— | — | @@ -868,10 +868,10 @@ |
869 | 869 | $relationStructure->getStructureType(), |
870 | 870 | $viewInformation->queryTransactionInformation, |
871 | 871 | $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) |
876 | 876 | ), |
877 | 877 | $meaningRelationsTable, |
878 | 878 | $restrictions, |
— | — | @@ -894,10 +894,10 @@ |
895 | 895 | $reciprocalRelationsAttribute->id, |
896 | 896 | $viewInformation->queryTransactionInformation, |
897 | 897 | $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) |
902 | 902 | ), |
903 | 903 | $meaningRelationsTable, |
904 | 904 | array("meaning2_mid=$definedMeaningId"), |
— | — | @@ -919,9 +919,9 @@ |
920 | 920 | null, |
921 | 921 | $viewInformation->queryTransactionInformation, |
922 | 922 | $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) |
926 | 926 | ), |
927 | 927 | $meaningRelationsTable, |
928 | 928 | array( |
— | — | @@ -957,9 +957,9 @@ |
958 | 958 | $collectionMembershipStructure->getStructureType(), |
959 | 959 | $viewInformation->queryTransactionInformation, |
960 | 960 | $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) |
964 | 964 | ), |
965 | 965 | $collectionMembershipsTable, |
966 | 966 | array("member_mid=$definedMeaningId") |
— | — | @@ -988,11 +988,11 @@ |
989 | 989 | $textAttributeValuesStructure->getStructureType(), |
990 | 990 | $viewInformation->queryTransactionInformation, |
991 | 991 | $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) |
997 | 997 | ), |
998 | 998 | $textAttributeValuesTable, |
999 | 999 | array("object_id IN (" . implode(", ", $objectIds) . ")") |
— | — | @@ -1014,11 +1014,11 @@ |
1015 | 1015 | $urlAttributeValuesStructure->getStructureType(), |
1016 | 1016 | $viewInformation->queryTransactionInformation, |
1017 | 1017 | $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) |
1023 | 1023 | ), |
1024 | 1024 | $urlAttributeValuesTable, |
1025 | 1025 | array("object_id IN (" . implode(", ", $objectIds) . ")") |
— | — | @@ -1040,11 +1040,11 @@ |
1041 | 1041 | $translatedTextAttributeValuesStructure->getStructureType(), |
1042 | 1042 | $viewInformation->queryTransactionInformation, |
1043 | 1043 | $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) |
1049 | 1049 | ), |
1050 | 1050 | $translatedContentAttributeValuesTable, |
1051 | 1051 | array("object_id IN (" . implode(", ", $objectIds) . ")") |
— | — | @@ -1066,11 +1066,11 @@ |
1067 | 1067 | null, |
1068 | 1068 | $viewInformation->queryTransactionInformation, |
1069 | 1069 | $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) |
1075 | 1075 | ), |
1076 | 1076 | $optionAttributeOptionsTable, |
1077 | 1077 | array('attribute_id = ' . $attributeId) |
— | — | @@ -1090,10 +1090,10 @@ |
1091 | 1091 | $optionAttributeValuesStructure->getStructureType(), |
1092 | 1092 | $viewInformation->queryTransactionInformation, |
1093 | 1093 | $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) |
1098 | 1098 | ), |
1099 | 1099 | $optionAttributeValuesTable, |
1100 | 1100 | array("object_id IN (" . implode(", ", $objectIds) . ")") |
— | — | @@ -1118,9 +1118,9 @@ |
1119 | 1119 | null, |
1120 | 1120 | $viewInformation->queryTransactionInformation, |
1121 | 1121 | $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) |
1125 | 1125 | ), |
1126 | 1126 | $optionAttributeOptionsTable, |
1127 | 1127 | array('option_id = ' . $record->getAttributeValue($optionAttributeOptionIdAttribute)) |
— | — | @@ -1136,7 +1136,7 @@ |
1137 | 1137 | null, |
1138 | 1138 | $viewInformation->queryTransactionInformation, |
1139 | 1139 | $optionAttributeIdAttribute, |
1140 | | - array('attribute_mid' => $optionAttributeAttribute), |
| 1140 | + new TableColumnsToAttributesMapping(new TableColumnsToAttribute(array('attribute_mid'), $optionAttributeAttribute)), |
1141 | 1141 | $classAttributesTable, |
1142 | 1142 | array('object_id = ' . $optionRecord->getAttributeValue($optionAttributeIdAttribute)) |
1143 | 1143 | ); |
— | — | @@ -1158,9 +1158,9 @@ |
1159 | 1159 | $classMembershipStructure->getStructureType(), |
1160 | 1160 | $viewInformation->queryTransactionInformation, |
1161 | 1161 | $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) |
1165 | 1165 | ), |
1166 | 1166 | $classMembershipsTable, |
1167 | 1167 | array("class_member_mid=$definedMeaningId") |