r17052 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17051‎ | r17052 | r17053 >
Date:14:55, 16 October 2006
Author:proes
Status:old
Tags:
Comment:
Moved transaction classes and tables to separate files
Modified paths:
  • /trunk/extensions/Wikidata/WiktionaryZ/Transaction.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/WikiDataTables.php (added) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZRecordSets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/WiktionaryZ/Transaction.php
@@ -1,7 +1,100 @@
22 <?php
33
44 require_once('Attribute.php');
 5+require_once('Record.php');
 6+require_once('RecordSet.php');
57
 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+
699 global
7100 $updateTransactionId;
8101
@@ -47,9 +140,10 @@
48141 }
49142
50143 global
51 - $userAttribute, $timestampAttribute, $transactionStructure, $addTransactionAttribute, $removeTransactionAttribute,
 144+ $transactionIdAttribute, $userAttribute, $timestampAttribute, $transactionStructure, $addTransactionAttribute, $removeTransactionAttribute,
52145 $recordLifeSpanAttribute, $recordLifeSpanStructure;
53146
 147+$transactionIdAttribute = new Attribute('transaction-id', 'Transaction ID', 'integer');
54148 $userAttribute = new Attribute('user', 'User', 'user');
55149 $timestampAttribute = new Attribute('timestamp', 'Time', 'timestamp');
56150 $transactionStructure = new Structure($userAttribute, $timestampAttribute);
@@ -81,11 +175,10 @@
82176
83177 function getTransactionTuple($transactionId) {
84178 global
85 - $transactionStructure, $userAttribute, $timestampAttribute, $wgUser, $wgContLang;
 179+ $transactionStructure, $transactionIdAttribute, $userAttribute, $timestampAttribute, $wgUser, $wgContLang;
86180
87181 $result = new ArrayRecord($transactionStructure);
88 -// $result->setAttributeValue($userAttribute, "");
89 -// $result->setAttributeValue($timestampAttribute, "");
 182+ $result->setAttributeValue($transactionIdAttribute, $transactionId);
90183
91184 if ($transactionId > 0) {
92185 $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 @@
66 require_once('RecordSet.php');
77 require_once('Expression.php');
88 require_once('Transaction.php');
 9+require_once('WikiDataTables.php');
910
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 -
12311 function queryRecordSet($transactionInformation, $keyAttribute, $fieldAttributeMapping, $table, $restrictions, $orderBy = array()) {
12412 $dbr =& wfGetDB(DB_SLAVE);
12513
@@ -135,8 +23,10 @@
13624 $allAttributes = $attributes;
13725
13826 $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);
14131
14232 if (count($orderBy) > 0)
14333 $query .= " ORDER BY " . implode(', ', $orderBy);
@@ -524,7 +414,7 @@
525415 array("object_id=$definedMeaningId")
526416 );
527417
528 - $recordSet->getStructure->attributes[] = $textValueAttribute;
 418+ $recordSet->getStructure()->attributes[] = $textValueAttribute;
529419
530420 expandTranslatedContentsInRecordSet($recordSet, $textValueIdAttribute, $textValueAttribute, $queryTransactionInformation);
531421 expandDefinedMeaningReferencesInRecordSet($recordSet, array($textAttributeAttribute));