Index: trunk/extensions/Wikidata/WiktionaryZ/Transaction.php |
— | — | @@ -1,7 +1,100 @@ |
2 | 2 | <?php
|
3 | 3 |
|
4 | 4 | require_once('Attribute.php');
|
| 5 | +require_once('Record.php');
|
| 6 | +require_once('RecordSet.php');
|
5 | 7 |
|
| 8 | +interface QueryTransactionInformation {
|
| 9 | + public function getRestriction($tableName);
|
| 10 | + public function versioningAttributes();
|
| 11 | + public function versioningFields($tableName);
|
| 12 | + public function versioningOrderBy();
|
| 13 | + public function setVersioningAttributes($record, $row);
|
| 14 | +}
|
| 15 | +
|
| 16 | +class QueryLatestTransactionInformation implements QueryTransactionInformation {
|
| 17 | + public function getRestriction($tableName) {
|
| 18 | + return getLatestTransactionRestriction($tableName);
|
| 19 | + }
|
| 20 | +
|
| 21 | + public function versioningAttributes() {
|
| 22 | + return array();
|
| 23 | + }
|
| 24 | +
|
| 25 | + public function versioningFields($tableName) {
|
| 26 | + return array();
|
| 27 | + }
|
| 28 | +
|
| 29 | + public function versioningOrderBy() {
|
| 30 | + return array();
|
| 31 | + }
|
| 32 | +
|
| 33 | + public function setVersioningAttributes($record, $row) {
|
| 34 | + }
|
| 35 | +}
|
| 36 | +
|
| 37 | +class QueryHistoryTransactionInformation implements QueryTransactionInformation {
|
| 38 | + public function getRestriction($tableName) {
|
| 39 | + return "1";
|
| 40 | + }
|
| 41 | +
|
| 42 | + public function versioningAttributes() {
|
| 43 | + global
|
| 44 | + $recordLifeSpanAttribute;
|
| 45 | +
|
| 46 | + return array($recordLifeSpanAttribute);
|
| 47 | + }
|
| 48 | +
|
| 49 | + public function versioningFields($tableName) {
|
| 50 | + return array($tableName . '.add_transaction_id', $tableName . '.remove_transaction_id', $tableName . '.remove_transaction_id IS NULL AS is_live');
|
| 51 | + }
|
| 52 | +
|
| 53 | + public function versioningOrderBy() {
|
| 54 | + return array('is_live DESC', 'add_transaction_id DESC');
|
| 55 | + }
|
| 56 | +
|
| 57 | + public function setVersioningAttributes($record, $row) {
|
| 58 | + global
|
| 59 | + $recordLifeSpanAttribute;
|
| 60 | +
|
| 61 | + $record->setAttributeValue($recordLifeSpanAttribute, getRecordLifeSpanTuple($row['add_transaction_id'], $row['remove_transaction_id']));
|
| 62 | + }
|
| 63 | +}
|
| 64 | +
|
| 65 | +class QueryAtTransactionInformation implements QueryTransactionInformation {
|
| 66 | + protected $transactionId;
|
| 67 | +
|
| 68 | + public function __construct($transactionId) {
|
| 69 | + $this->transactionId = $transactionId;
|
| 70 | + }
|
| 71 | +
|
| 72 | + public function getRestriction($tableName) {
|
| 73 | + return getAtTransactionRestriction($tableName, $this->transactionId);
|
| 74 | + }
|
| 75 | +
|
| 76 | + public function versioningAttributes() {
|
| 77 | + global
|
| 78 | + $recordLifeSpanAttribute;
|
| 79 | +
|
| 80 | + return array($recordLifeSpanAttribute);
|
| 81 | + }
|
| 82 | +
|
| 83 | + public function versioningFields($tableName) {
|
| 84 | + return array($tableName . '.add_transaction_id', $tableName . '.remove_transaction_id', $tableName . '.remove_transaction_id IS NULL AS is_live');
|
| 85 | + }
|
| 86 | +
|
| 87 | + public function versioningOrderBy() {
|
| 88 | + return array();
|
| 89 | + }
|
| 90 | +
|
| 91 | + public function setVersioningAttributes($record, $row) {
|
| 92 | + global
|
| 93 | + $recordLifeSpanAttribute;
|
| 94 | +
|
| 95 | + $record->setAttributeValue($recordLifeSpanAttribute, getRecordLifeSpanTuple($row['add_transaction_id'], $row['remove_transaction_id']));
|
| 96 | + }
|
| 97 | +}
|
| 98 | +
|
6 | 99 | global
|
7 | 100 | $updateTransactionId;
|
8 | 101 |
|
— | — | @@ -47,9 +140,10 @@ |
48 | 141 | }
|
49 | 142 |
|
50 | 143 | global
|
51 | | - $userAttribute, $timestampAttribute, $transactionStructure, $addTransactionAttribute, $removeTransactionAttribute,
|
| 144 | + $transactionIdAttribute, $userAttribute, $timestampAttribute, $transactionStructure, $addTransactionAttribute, $removeTransactionAttribute,
|
52 | 145 | $recordLifeSpanAttribute, $recordLifeSpanStructure;
|
53 | 146 |
|
| 147 | +$transactionIdAttribute = new Attribute('transaction-id', 'Transaction ID', 'integer');
|
54 | 148 | $userAttribute = new Attribute('user', 'User', 'user');
|
55 | 149 | $timestampAttribute = new Attribute('timestamp', 'Time', 'timestamp');
|
56 | 150 | $transactionStructure = new Structure($userAttribute, $timestampAttribute);
|
— | — | @@ -81,11 +175,10 @@ |
82 | 176 |
|
83 | 177 | function getTransactionTuple($transactionId) {
|
84 | 178 | global
|
85 | | - $transactionStructure, $userAttribute, $timestampAttribute, $wgUser, $wgContLang;
|
| 179 | + $transactionStructure, $transactionIdAttribute, $userAttribute, $timestampAttribute, $wgUser, $wgContLang;
|
86 | 180 |
|
87 | 181 | $result = new ArrayRecord($transactionStructure);
|
88 | | -// $result->setAttributeValue($userAttribute, "");
|
89 | | -// $result->setAttributeValue($timestampAttribute, "");
|
| 182 | + $result->setAttributeValue($transactionIdAttribute, $transactionId);
|
90 | 183 |
|
91 | 184 | if ($transactionId > 0) {
|
92 | 185 | $dbr =& wfGetDB(DB_SLAVE);
|
Index: trunk/extensions/Wikidata/WiktionaryZ/WikiDataTables.php |
— | — | @@ -0,0 +1,26 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class Table { |
| 5 | + public $name; |
| 6 | + public $isVersioned; |
| 7 | + |
| 8 | + public function __construct($name, $isVersioned) { |
| 9 | + $this->name = $name; |
| 10 | + $this->isVersioned = $isVersioned; |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +global |
| 15 | + $tables, $meaningRelationsTable, $classMembershipsTable, $collectionMembershipsTable, $syntransTable, |
| 16 | + $translatedContentTable, $alternativeDefinitionsTable, $textAttributeValuesTable, $transactionsTable; |
| 17 | + |
| 18 | +$transactionsTable = new Table('transactions', false); |
| 19 | +$meaningRelationsTable = new Table('uw_meaning_relations', true); |
| 20 | +$classMembershipsTable = new Table('uw_class_membership', true); |
| 21 | +$collectionMembershipsTable = new Table('uw_collection_contents', true); |
| 22 | +$syntransTable = new Table('uw_syntrans', true); |
| 23 | +$translatedContentTable = new Table('translated_content', true); |
| 24 | +$alternativeDefinitionsTable = new Table('uw_alt_meaningtexts', true); |
| 25 | +$textAttributeValuesTable = new Table('uw_text_attribute_values', true); |
| 26 | + |
| 27 | +?> |
Index: trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZRecordSets.php |
— | — | @@ -5,120 +5,8 @@ |
6 | 6 | require_once('RecordSet.php'); |
7 | 7 | require_once('Expression.php'); |
8 | 8 | require_once('Transaction.php'); |
| 9 | +require_once('WikiDataTables.php'); |
9 | 10 | |
10 | | -class Table { |
11 | | - public $name; |
12 | | - public $isVersioned; |
13 | | - |
14 | | - public function __construct($name, $isVersioned) { |
15 | | - $this->name = $name; |
16 | | - $this->isVersioned = $isVersioned; |
17 | | - } |
18 | | -} |
19 | | - |
20 | | -global |
21 | | - $tables, $meaningRelationsTable, $classMembershipsTable, $collectionMembershipsTable, $syntransTable, |
22 | | - $translatedContentTable, $alternativeDefinitionsTable, $textAttributeValuesTable; |
23 | | - |
24 | | -$meaningRelationsTable = new Table('uw_meaning_relations', true); |
25 | | -$classMembershipsTable = new Table('uw_class_membership', true); |
26 | | -$collectionMembershipsTable = new Table('uw_collection_contents', true); |
27 | | -$syntransTable = new Table('uw_syntrans', true); |
28 | | -$translatedContentTable = new Table('translated_content', true); |
29 | | -$alternativeDefinitionsTable = new Table('uw_alt_meaningtexts', true); |
30 | | -$textAttributeValuesTable = new Table('uw_text_attribute_values', true); |
31 | | - |
32 | | -interface QueryTransactionInformation { |
33 | | - public function getRestriction($tableName); |
34 | | - public function versioningAttributes(); |
35 | | - public function versioningFields($tableName); |
36 | | - public function versioningOrderBy(); |
37 | | - public function setVersioningAttributes($record, $row); |
38 | | -} |
39 | | - |
40 | | -class QueryLatestTransactionInformation implements QueryTransactionInformation { |
41 | | - public function getRestriction($tableName) { |
42 | | - return getLatestTransactionRestriction($tableName); |
43 | | - } |
44 | | - |
45 | | - public function versioningAttributes() { |
46 | | - return array(); |
47 | | - } |
48 | | - |
49 | | - public function versioningFields($tableName) { |
50 | | - return array(); |
51 | | - } |
52 | | - |
53 | | - public function versioningOrderBy() { |
54 | | - return array(); |
55 | | - } |
56 | | - |
57 | | - public function setVersioningAttributes($record, $row) { |
58 | | - } |
59 | | -} |
60 | | - |
61 | | -class QueryHistoryTransactionInformation implements QueryTransactionInformation { |
62 | | - public function getRestriction($tableName) { |
63 | | - return "1"; |
64 | | - } |
65 | | - |
66 | | - public function versioningAttributes() { |
67 | | - global |
68 | | - $recordLifeSpanAttribute; |
69 | | - |
70 | | - return array($recordLifeSpanAttribute); |
71 | | - } |
72 | | - |
73 | | - public function versioningFields($tableName) { |
74 | | - return array($tableName . '.add_transaction_id', $tableName . '.remove_transaction_id', $tableName . '.remove_transaction_id IS NULL AS is_live'); |
75 | | - } |
76 | | - |
77 | | - public function versioningOrderBy() { |
78 | | - return array('is_live DESC', 'add_transaction_id DESC'); |
79 | | - } |
80 | | - |
81 | | - public function setVersioningAttributes($record, $row) { |
82 | | - global |
83 | | - $recordLifeSpanAttribute; |
84 | | - |
85 | | - $record->setAttributeValue($recordLifeSpanAttribute, getRecordLifeSpanTuple($row['add_transaction_id'], $row['remove_transaction_id'])); |
86 | | - } |
87 | | -} |
88 | | - |
89 | | -class QueryAtTransactionInformation implements QueryTransactionInformation { |
90 | | - protected $transactionId; |
91 | | - |
92 | | - public function __construct($transactionId) { |
93 | | - $this->transactionId = $transactionId; |
94 | | - } |
95 | | - |
96 | | - public function getRestriction($tableName) { |
97 | | - return getAtTransactionRestriction($tableName, $this->transactionId); |
98 | | - } |
99 | | - |
100 | | - public function versioningAttributes() { |
101 | | - global |
102 | | - $recordLifeSpanAttribute; |
103 | | - |
104 | | - return array($recordLifeSpanAttribute); |
105 | | - } |
106 | | - |
107 | | - public function versioningFields($tableName) { |
108 | | - return array($tableName . '.add_transaction_id', $tableName . '.remove_transaction_id', $tableName . '.remove_transaction_id IS NULL AS is_live'); |
109 | | - } |
110 | | - |
111 | | - public function versioningOrderBy() { |
112 | | - return array(); |
113 | | - } |
114 | | - |
115 | | - public function setVersioningAttributes($record, $row) { |
116 | | - global |
117 | | - $recordLifeSpanAttribute; |
118 | | - |
119 | | - $record->setAttributeValue($recordLifeSpanAttribute, getRecordLifeSpanTuple($row['add_transaction_id'], $row['remove_transaction_id'])); |
120 | | - } |
121 | | -} |
122 | | - |
123 | 11 | function queryRecordSet($transactionInformation, $keyAttribute, $fieldAttributeMapping, $table, $restrictions, $orderBy = array()) { |
124 | 12 | $dbr =& wfGetDB(DB_SLAVE); |
125 | 13 | |
— | — | @@ -135,8 +23,10 @@ |
136 | 24 | $allAttributes = $attributes; |
137 | 25 | |
138 | 26 | $query = "SELECT ". implode(", ", $selectFields) . |
139 | | - " FROM ". $table->name . |
140 | | - " WHERE ". implode(' AND ', $restrictions); |
| 27 | + " FROM ". $table->name; |
| 28 | + |
| 29 | + if (count($restrictions) > 0) |
| 30 | + $query .= " WHERE ". implode(' AND ', $restrictions); |
141 | 31 | |
142 | 32 | if (count($orderBy) > 0) |
143 | 33 | $query .= " ORDER BY " . implode(', ', $orderBy); |
— | — | @@ -524,7 +414,7 @@ |
525 | 415 | array("object_id=$definedMeaningId") |
526 | 416 | ); |
527 | 417 | |
528 | | - $recordSet->getStructure->attributes[] = $textValueAttribute; |
| 418 | + $recordSet->getStructure()->attributes[] = $textValueAttribute; |
529 | 419 | |
530 | 420 | expandTranslatedContentsInRecordSet($recordSet, $textValueIdAttribute, $textValueAttribute, $queryTransactionInformation); |
531 | 421 | expandDefinedMeaningReferencesInRecordSet($recordSet, array($textAttributeAttribute)); |