r23672 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23671‎ | r23672 | r23673 >
Date:15:50, 3 July 2007
Author:proes
Status:old
Tags:
Comment:
* Added type hints for OmegaWikiRecords.php
* Solved bug: caught typo by using type hints
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Record.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Transaction.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -153,7 +153,7 @@
154154
155155 global
156156 $translatedTextAttributeIdAttribute, $translatedTextValueIdAttribute,
157 - $textAttributeObjectAttribute, $translatedTextAttributeAttribute, $translatedTextValueAttribute, $translatedTextAttributeValuesAttribute,
 157+ $translatedTextAttributeObjectAttribute, $translatedTextAttributeAttribute, $translatedTextValueAttribute, $translatedTextAttributeValuesAttribute,
158158 $translatedTextAttributeValuesStructure, $wgTranslatedTextAttributeValuesAttributeName, $wgTranslatedTextAttributeAttributeName, $wgTranslatedTextAttributeValueAttributeName;
159159
160160 $translatedTextAttributeIdAttribute = new Attribute("translated-text-attribute-id", "Attribute identifier", "object-id");
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
@@ -10,8 +10,7 @@
1111 require_once('DefinedMeaningModel.php');
1212 require_once('ViewInformation.php');
1313
14 -function getSynonymSQLForLanguage($languageId, &$definedMeaningIds) {
15 -
 14+function getSynonymSQLForLanguage($languageId, array &$definedMeaningIds) {
1615 $dc=wdGetDataSetContext();
1716
1817 return
@@ -28,8 +27,7 @@
2928 " GROUP BY {$dc}_defined_meaning.defined_meaning_id";
3029 }
3130
32 -function getSynonymSQLForAnyLanguage(&$definedMeaningIds) {
33 -
 31+function getSynonymSQLForAnyLanguage(array &$definedMeaningIds) {
3432 $dc=wdGetDataSetContext();
3533
3634 return
@@ -45,8 +43,7 @@
4644 " GROUP BY {$dc}_defined_meaning.defined_meaning_id";
4745 }
4846
49 -function getDefiningSQLForLanguage($languageId, &$definedMeaningIds) {
50 -
 47+function getDefiningSQLForLanguage($languageId, array &$definedMeaningIds) {
5148 $dc=wdGetDataSetContext();
5249
5350 return
@@ -64,8 +61,7 @@
6562 " GROUP BY {$dc}_defined_meaning.defined_meaning_id";
6663 }
6764
68 -function fetchDefinedMeaningReferenceRecords($sql, &$definedMeaningIds, &$definedMeaningReferenceRecords, $usedAs='defined-meaning') {
69 -
 65+function fetchDefinedMeaningReferenceRecords($sql, array &$definedMeaningIds, array &$definedMeaningReferenceRecords, $usedAs='defined-meaning') {
7066 $dc=wdGetDataSetContext();
7167
7268 global
@@ -93,7 +89,7 @@
9490 $definedMeaningIds = array_diff($definedMeaningIds, $foundDefinedMeaningIds);
9591 }
9692
97 -function fetchDefinedMeaningDefiningExpressions(&$definedMeaningIds, &$definedMeaningReferenceRecords) {
 93+function fetchDefinedMeaningDefiningExpressions(array &$definedMeaningIds, array &$definedMeaningReferenceRecords) {
9894 global
9995 $definedMeaningReferenceStructure, $definedMeaningIdAttribute, $definedMeaningLabelAttribute,
10096 $definedMeaningDefiningExpressionAttribute;
@@ -137,7 +133,7 @@
138134 return $record;
139135 }
140136
141 -function getDefinedMeaningReferenceRecords($definedMeaningIds, $usedAs) {
 137+function getDefinedMeaningReferenceRecords(array $definedMeaningIds, $usedAs) {
142138 global
143139 $wgUser;
144140
@@ -200,8 +196,7 @@
201197 return $result;
202198 }
203199
204 -function expandDefinedMeaningReferencesInRecordSet($recordSet, $definedMeaningAttributes) {
205 -
 200+function expandDefinedMeaningReferencesInRecordSet(RecordSet $recordSet, array $definedMeaningAttributes) {
206201 $definedMeaningReferenceRecords=array();
207202
208203 foreach($definedMeaningAttributes as $dmatt) {
@@ -220,14 +215,14 @@
221216 }
222217 }
223218
224 -function expandTranslatedContentInRecord($record, $idAttribute, $translatedContentAttribute, ViewInformation $viewInformation) {
 219+function expandTranslatedContentInRecord(Record $record, Attribute $idAttribute, Attribute $translatedContentAttribute, ViewInformation $viewInformation) {
225220 $record->setAttributeValue(
226221 $translatedContentAttribute,
227222 getTranslatedContentValue($record->getAttributeValue($idAttribute), $viewInformation)
228223 );
229224 }
230225
231 -function expandTranslatedContentsInRecordSet($recordSet, $idAttribute, $translatedContentAttribute, ViewInformation $viewInformation) {
 226+function expandTranslatedContentsInRecordSet(RecordSet $recordSet, Attribute $idAttribute, Attribute $translatedContentAttribute, ViewInformation $viewInformation) {
232227 for ($i = 0; $i < $recordSet->getRecordCount(); $i++)
233228 expandTranslatedContentInRecord($recordSet->getRecord($i), $idAttribute, $translatedContentAttribute, $viewInformation);
234229 }
@@ -263,7 +258,7 @@
264259 return array();
265260 }
266261
267 -function expandExpressionReferencesInRecordSet($recordSet, $expressionAttributes) {
 262+function expandExpressionReferencesInRecordSet(RecordSet $recordSet, array $expressionAttributes) {
268263 $expressionReferenceRecords = getExpressionReferenceRecords(getUniqueIdsInRecordSet($recordSet, $expressionAttributes));
269264
270265 for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
@@ -277,7 +272,7 @@
278273 }
279274 }
280275
281 -function getExpressionSpellings($expressionIds) {
 276+function getExpressionSpellings(array $expressionIds) {
282277 global
283278 $expressionAttribute;
284279
@@ -303,7 +298,7 @@
304299 return array();
305300 }
306301
307 -function expandExpressionSpellingsInRecordSet($recordSet, $expressionAttributes) {
 302+function expandExpressionSpellingsInRecordSet(RecordSet $recordSet, array $expressionAttributes) {
308303 $expressionSpellings = getExpressionSpellings(getUniqueIdsInRecordSet($recordSet, $expressionAttributes));
309304
310305 for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
@@ -317,8 +312,7 @@
318313 }
319314 }
320315
321 -function getTextReferences($textIds) {
322 -
 316+function getTextReferences(array $textIds) {
323317 $dc=wdGetDataSetContext();
324318 if (count($textIds) > 0) {
325319 $dbr =& wfGetDB(DB_SLAVE);
@@ -339,7 +333,7 @@
340334 return array();
341335 }
342336
343 -function expandTextReferencesInRecordSet($recordSet, $textAttributes) {
 337+function expandTextReferencesInRecordSet(RecordSet $recordSet, array $textAttributes) {
344338 $textReferences = getTextReferences(getUniqueIdsInRecordSet($recordSet, $textAttributes));
345339
346340 for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
@@ -485,7 +479,7 @@
486480 return $recordSet;
487481 }
488482
489 -function expandOptionAttributeOptionsInRecordSet($recordSet, $attributeIdAttribute, ViewInformation $viewInformation) {
 483+function expandOptionAttributeOptionsInRecordSet(RecordSet $recordSet, Attribute $attributeIdAttribute, ViewInformation $viewInformation) {
490484 global
491485 $definedMeaningIdAttribute, $optionAttributeOptionsAttribute;
492486
@@ -663,7 +657,7 @@
664658 return $recordSet;
665659 }
666660
667 -function expandObjectAttributesAttribute($recordSet, $objectIdAttribute, ViewInformation $viewInformation) {
 661+function expandObjectAttributesAttribute(RecordSet $recordSet, Attribute $objectIdAttribute, ViewInformation $viewInformation) {
668662 global
669663 $objectAttributesAttribute,
670664 $textAttributeObjectAttribute, $textAttributeValuesAttribute,
@@ -776,7 +770,7 @@
777771 return $record;
778772 }
779773
780 -function getDefinedMeaningRelationsRecordSet($definedMeaningId, $filterRelationTypes, ViewInformation $viewInformation) {
 774+function getDefinedMeaningRelationsRecordSet($definedMeaningId, array $filterRelationTypes, ViewInformation $viewInformation) {
781775 global
782776 $meaningRelationsTable, $relationIdAttribute, $relationTypeAttribute,
783777 $objectAttributesAttribute, $otherDefinedMeaningAttribute,
@@ -916,7 +910,7 @@
917911 return $recordSet;
918912 }
919913
920 -function getTextAttributesValuesRecordSet($objectIds, ViewInformation $viewInformation) {
 914+function getTextAttributesValuesRecordSet(array $objectIds, ViewInformation $viewInformation) {
921915 global
922916 $textAttributeValuesTable, $textAttributeIdAttribute, $textAttributeObjectAttribute,
923917 $textAttributeAttribute, $textAttribute, $objectAttributesAttribute,
@@ -946,7 +940,7 @@
947941 return $recordSet;
948942 }
949943
950 -function getURLAttributeValuesRecordSet($objectIds, ViewInformation $viewInformation) {
 944+function getURLAttributeValuesRecordSet(array $objectIds, ViewInformation $viewInformation) {
951945 global
952946 $urlAttributeValuesTable, $urlAttributeIdAttribute, $urlAttributeObjectAttribute,
953947 $urlAttributeAttribute, $urlAttribute, $objectAttributesAttribute,
@@ -976,7 +970,7 @@
977971 return $recordSet;
978972 }
979973
980 -function getTranslatedTextAttributeValuesRecordSet($objectIds, ViewInformation $viewInformation) {
 974+function getTranslatedTextAttributeValuesRecordSet(array $objectIds, ViewInformation $viewInformation) {
981975 global
982976 $translatedTextAttributeIdAttribute, $translatedContentAttributeValuesTable, $translatedTextAttributeAttribute,
983977 $objectAttributesAttribute, $translatedTextAttributeObjectAttribute, $translatedTextValueAttribute, $translatedTextValueIdAttribute,
@@ -1031,7 +1025,7 @@
10321026 return $recordSet;
10331027 }
10341028
1035 -function getOptionAttributeValuesRecordSet($objectIds, ViewInformation $viewInformation) {
 1029+function getOptionAttributeValuesRecordSet(array $objectIds, ViewInformation $viewInformation) {
10361030 global
10371031 $optionAttributeIdAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionIdAttribute, $optionAttributeAttribute,$optionAttributeOptionAttribute, $optionAttributeValuesTable, $objectAttributesAttribute,
10381032 $optionAttributeValuesStructure;
@@ -1061,7 +1055,7 @@
10621056 }
10631057
10641058 /* XXX: This can probably be combined with other functions. In fact, it probably should be. Do it. */
1065 -function expandOptionsInRecordSet($recordSet, ViewInformation $viewInformation) {
 1059+function expandOptionsInRecordSet(RecordSet $recordSet, ViewInformation $viewInformation) {
10661060 global
10671061 $optionAttributeOptionIdAttribute, $optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeOptionAttribute, $optionAttributeOptionsTable, $classAttributesTable;
10681062
Index: trunk/extensions/Wikidata/OmegaWiki/Transaction.php
@@ -4,6 +4,7 @@
55 require_once('Record.php');
66 require_once('RecordSet.php');
77 require_once('Wikidata.php');
 8+
89 interface QueryTransactionInformation {
910 public function getRestriction($table);
1011 public function getTables();
@@ -14,7 +15,7 @@
1516 public function setVersioningAttributes($record, $row);
1617 }
1718
18 -class DefaultQueryTransactionInformation {
 19+class DefaultQueryTransactionInformation implements QueryTransactionInformation {
1920 public function getRestriction($table) {
2021 return "1";
2122 }
Index: trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php
@@ -32,7 +32,7 @@
3333 return $query;
3434 }
3535
36 -function queryRecordSet($recordSetStructureId, $transactionInformation, $keyAttribute, $fieldAttributeMapping, Table $table, $restrictions, $orderBy = array(), $count = -1, $offset = 0) {
 36+function queryRecordSet($recordSetStructureId, QueryTransactionInformation $transactionInformation, Attribute $keyAttribute, $fieldAttributeMapping, Table $table, $restrictions, $orderBy = array(), $count = -1, $offset = 0) {
3737 $dbr =& wfGetDB(DB_SLAVE);
3838
3939 $selectFields = array_keys($fieldAttributeMapping);
Index: trunk/extensions/Wikidata/OmegaWiki/Record.php
@@ -5,8 +5,8 @@
66
77 interface Record {
88 public function getStructure();
9 - public function getAttributeValue($attribute);
10 - public function project($structure);
 9+ public function getAttributeValue(Attribute $attribute);
 10+ public function project(Structure $structure);
1111 }
1212
1313 class ArrayRecord implements Record {
@@ -23,18 +23,18 @@
2424 return $this->structure;
2525 }
2626
27 - public function getAttributeValue($attribute) {
 27+ public function getAttributeValue(Attribute $attribute) {
2828 #FIXME: check if valid
2929 return @$this->values[$attribute->id];
3030 }
3131
3232
33 - public function project($structure) {
 33+ public function project(Structure $structure) {
3434 $result = project($this, $structure);
3535 return $result;
3636 }
3737
38 - public function setAttributeValue($attribute, $value) {
 38+ public function setAttributeValue(Attribute $attribute, $value) {
3939 #FIXME: check if valid
4040 @$this->values[$attribute->id] = $value;
4141 }
@@ -55,7 +55,7 @@
5656 * @param $record Another record object whose values get written into this one
5757 *
5858 */
59 - public function setSubRecord($record) {
 59+ public function setSubRecord(Record $record) {
6060 foreach($record->getStructure()->getAttributes() as $attribute)
6161 $this->values[$attribute->id] = $record->getAttributeValue($attribute);
6262 }
@@ -93,7 +93,7 @@
9494
9595 }
9696
97 -function project($record, $structure) {
 97+function project(Record $record, Structure $structure) {
9898 $result = new ArrayRecord($structure);
9999
100100 foreach ($structure->getAttributes() as $attribute) {
@@ -109,7 +109,7 @@
110110 return $result;
111111 }
112112
113 -function equalRecords($structure, $lhs, $rhs) {
 113+function equalRecords(Structure $structure, Record $lhs, Record $rhs) {
114114 $result = true;
115115 $attributes = $structure->getAttributes();
116116 $i = 0;
@@ -134,7 +134,7 @@
135135 class RecordStack {
136136 protected $stack = array();
137137
138 - public function push($record) {
 138+ public function push(Record $record) {
139139 $this->stack[] = $record;
140140 }
141141

Status & tagging log