r23676 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23675‎ | r23676 | r23677 >
Date:18:08, 3 July 2007
Author:proes
Status:old
Tags:
Comment:
* Converted initializeOmegaWikiAttributes() to use ViewInformation
* Fixed problems in SpecialDatasearch.php
* Solved bug in equalRecords()
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Record.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Search.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialDatasearch.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialNeedsTranslation.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialTransaction.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/ViewInformation.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Wikidata.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -2,8 +2,9 @@
33
44 require_once("Attribute.php");
55 require_once("WikiDataGlobals.php");
 6+require_once("ViewInformation.php");
67
7 -function initializeOmegaWikiAttributes($filterOnLanguage, $hasMetaDataAttributes=false) {
 8+function initializeOmegaWikiAttributes(ViewInformation $viewInformation) {
89 global
910 $languageAttribute, $spellingAttribute, $textAttribute,
1011 $wgLanguageAttributeName, $wgSpellingAttributeName, $wgTextAttributeName;
@@ -29,7 +30,7 @@
3031 global
3132 $expressionStructure, $expressionAttribute, $wgExpressionAttributeName;
3233
33 - if ($filterOnLanguage)
 34+ if ($viewInformation->filterOnLanguage())
3435 $expressionAttribute = new Attribute("expression", $wgSpellingAttributeName, "spelling");
3536 else {
3637 $expressionStructure = new Structure("expression", $languageAttribute, $spellingAttribute);
@@ -122,7 +123,7 @@
123124
124125 $definitionIdAttribute = new Attribute("definition-id", "Definition identifier", "integer");
125126
126 - if ($filterOnLanguage && !$hasMetaDataAttributes)
 127+ if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes())
127128 $alternativeDefinitionAttribute = new Attribute("alternative-definition", $wgAlternativeDefinitionAttributeName, "text");
128129 else
129130 $alternativeDefinitionAttribute = new Attribute("alternative-definition", $wgAlternativeDefinitionAttributeName, $translatedTextStructure);
@@ -142,7 +143,7 @@
143144 $wgSynonymsAttributeName, $wgSynonymsAndTranslationsAttributeName, $wgSynonymsAndTranslationsAttributeId,
144145 $synonymsTranslationsStructure;
145146
146 - if ($filterOnLanguage)
 147+ if ($viewInformation->filterOnLanguage())
147148 $synonymsAndTranslationsCaption = $wgSynonymsAttributeName;
148149 else
149150 $synonymsAndTranslationsCaption = $wgSynonymsAndTranslationsAttributeName;
@@ -161,7 +162,7 @@
162163 $translatedTextAttributeAttribute = new Attribute("translated-text-attribute", $wgTranslatedTextAttributeAttributeName, $definedMeaningReferenceType);
163164 $translatedTextValueIdAttribute = new Attribute("translated-text-value-id", "Translated text value identifier", "translated-text-value-id");
164165
165 - if ($filterOnLanguage && !$hasMetaDataAttributes)
 166+ if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes())
166167 $translatedTextValueAttribute = new Attribute("translated-text-value", $wgTranslatedTextAttributeValueAttributeName, "text");
167168 else
168169 $translatedTextValueAttribute = new Attribute("translated-text", $wgTranslatedTextAttributeValueAttributeName, $translatedTextStructure);
@@ -213,7 +214,7 @@
214215 $definitionAttribute, $translatedTextAttribute, $classAttributesAttribute,
215216 $wgDefinitionAttributeName, $wgTranslatedTextAttributeName;
216217
217 - if ($filterOnLanguage && !$hasMetaDataAttributes)
 218+ if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes())
218219 $translatedTextAttribute = new Attribute("translated-text", $wgTextAttributeName, "text");
219220 else
220221 $translatedTextAttribute = new Attribute(null, $wgTranslatedTextAttributeName, $translatedTextStructure);
@@ -292,9 +293,6 @@
293294 $collectionMembershipAttribute->id,
294295 $definedMeaningAttributesAttribute->id
295296 );
296 -
297 -
298 -
299297 }
300298
301299
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -940,7 +940,7 @@
941941 protected $addText = "";
942942 protected $controller;
943943
944 - public function __construct(Attribute $attribute = null, PermissionController $permissionController, $isAddField, $truncate=false, $truncateAt=0, UpdateController $controller = null) {
 944+ public function __construct(Attribute $attribute = null, PermissionController $permissionController, $isAddField, $truncate=false, $truncateAt=0, UpdateAttributeController $controller = null) {
945945 parent::__construct($attribute, $permissionController, $isAddField);
946946
947947 $this->truncate = $truncate;
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php
@@ -50,7 +50,7 @@
5151 * Please check if it still works correctly. Peter-Jan Roes.
5252 */
5353 public function save() {
54 - initializeOmegaWikiAttributes($this->filterLanguageId != 0, false);
 54+ initializeOmegaWikiAttributes($this->viewInformation);
5555 initializeObjectAttributeEditors($this->viewInformation);
5656
5757 $definedMeaningId = $this->getDefinedMeaningID();
Index: trunk/extensions/Wikidata/OmegaWiki/ViewInformation.php
@@ -25,6 +25,14 @@
2626 $this->showRecordLifeSpan = false;
2727 $this->showAuthority = false;
2828 }
 29+
 30+ public function hasMetaDataAttributes() {
 31+ return $this->showRecordLifeSpan || $this->showAuthority;
 32+ }
 33+
 34+ public function filterOnLanguage() {
 35+ return $this->filterOnLanguage != 0;
 36+ }
2937 }
3038
3139 ?>
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialTransaction.php
@@ -28,8 +28,9 @@
2929 require_once("Editor.php");
3030 require_once("Controller.php");
3131 require_once("type.php");
 32+ require_once("ViewInformation.php");
3233
33 - initializeOmegaWikiAttributes(false, false);
 34+ initializeOmegaWikiAttributes(new ViewInformation());
3435 initializeAttributes();
3536
3637 @$fromTransactionId = (int) $_GET['from-transaction']; # FIXME - check parameter
Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php
@@ -99,7 +99,7 @@
100100
101101 $this->viewInformation = $viewInformation;
102102
103 - initializeOmegaWikiAttributes($this->filterLanguageId != 0);
 103+ initializeOmegaWikiAttributes($viewInformation);
104104 initializeObjectAttributeEditors($viewInformation);
105105 }
106106
@@ -133,7 +133,7 @@
134134
135135 $this->viewInformation = $viewInformation;
136136
137 - initializeOmegaWikiAttributes($this->filterLanguageId != 0, false);
 137+ initializeOmegaWikiAttributes($this->viewInformation);
138138 initializeObjectAttributeEditors($this->viewInformation);
139139 }
140140
@@ -188,7 +188,7 @@
189189
190190 $this->viewInformation = $viewInformation;
191191
192 - initializeOmegaWikiAttributes($this->filterLanguageId != 0, false);
 192+ initializeOmegaWikiAttributes($this->viewInformation);
193193 initializeObjectAttributeEditors($this->viewInformation);
194194
195195 return true;
@@ -245,7 +245,7 @@
246246
247247 $this->viewInformation = $viewInformation;
248248
249 - initializeOmegaWikiAttributes($this->filterLanguageId != 0, true);
 249+ initializeOmegaWikiAttributes($this->viewInformation);
250250 initializeObjectAttributeEditors($viewInformation);
251251 }
252252
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialDatasearch.php
@@ -19,6 +19,8 @@
2020 protected $externalIdentifierAttribute;
2121 protected $collectionAttribute;
2222 protected $collectionMemberAttribute;
 23+ protected $externalIdentifierMatchStructure;
 24+
2325 protected $spellingAttribute;
2426 protected $languageAttribute;
2527
@@ -37,12 +39,13 @@
3840 require_once("WikiDataGlobals.php");
3941 require_once("forms.php");
4042 require_once("type.php");
 43+ require_once("ViewInformation.php");
4144 require_once("WikiDataAPI.php");
4245 require_once("OmegaWikiAttributes.php");
4346 require_once("OmegaWikiRecordSets.php");
4447 require_once("OmegaWikiEditors.php");
4548
46 - initializeOmegaWikiAttributes(false, false);
 49+ initializeOmegaWikiAttributes(new ViewInformation());
4750
4851 global
4952 $definedMeaningReferenceType;
@@ -62,6 +65,12 @@
6366 $this->externalIdentifierAttribute = new Attribute("external-identifier", "External identifier", "short-text");
6467 $this->collectionAttribute = new Attribute("collection", "Collection", $definedMeaningReferenceType);
6568 $this->collectionMemberAttribute = new Attribute("collection-member", "Collection member", $definedMeaningReferenceType);
 69+
 70+ $this->externalIdentifierMatchStructure = new Structure(
 71+ $this->externalIdentifierAttribute,
 72+ $this->collectionAttribute,
 73+ $this->collectionMemberAttribute
 74+ );
6675 }
6776
6877 function execute($parameter) {
@@ -221,10 +230,10 @@
222231
223232 function getWordsSearchResultAsRecordSet($queryResult) {
224233 global
225 - $idAttribute;
 234+ $definedMeaningIdAttribute;
226235
227236 $dbr =& wfGetDB(DB_SLAVE);
228 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $this->expressionAttribute, $this->meaningAttribute), new Structure($idAttribute));
 237+ $recordSet = new ArrayRecordSet(new Structure($definedMeaningIdAttribute, $this->expressionAttribute, $this->meaningAttribute), new Structure($definedMeaningIdAttribute));
229238
230239 while ($row = $dbr->fetchObject($queryResult)) {
231240 $expressionRecord = new ArrayRecord($this->expressionStructure);
Index: trunk/extensions/Wikidata/OmegaWiki/Search.php
@@ -44,7 +44,7 @@
4545
4646 function getSearchResultAsRecordSet($queryResult) {
4747 global
48 - $idAttribute, $definedMeaningReferenceType;
 48+ $definedMeaningIdAttribute, $definedMeaningReferenceType;
4949
5050 $dbr =& wfGetDB(DB_SLAVE);
5151 $spellingAttribute = new Attribute("found-word", "Found word", "short-text");
@@ -59,7 +59,7 @@
6060 $meaningStructure = new Structure($definedMeaningAttribute, $definitionAttribute);
6161 $meaningAttribute = new Attribute("meaning", "Meaning", $meaningStructure);
6262
63 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $expressionAttribute, $meaningAttribute), new Structure($idAttribute));
 63+ $recordSet = new ArrayRecordSet(new Structure($definedMeaningIdAttribute, $expressionAttribute, $meaningAttribute), new Structure($definedMeaningIdAttribute));
6464
6565 while ($row = $dbr->fetchObject($queryResult)) {
6666 $expressionRecord = new ArrayRecord($expressionStructure);
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -91,24 +91,24 @@
9292 global
9393 $definitionAttribute, $translatedTextAttribute, $definitionObjectAttributesEditor, $wgPopupAnnotationName;
9494
95 - if ($viewInformation->filterLanguageId == 0)
96 - $controller = new DefinedMeaningDefinitionController();
97 - else
98 - $controller = new DefinedMeaningFilteredDefinitionController($viewInformation->filterLanguageId);
99 -
10095 $editor = new RecordDivListEditor($definitionAttribute);
101 - $editor->addEditor(getTranslatedTextEditor($translatedTextAttribute, $controller, $viewInformation));
 96+ $editor->addEditor(getTranslatedTextEditor(
 97+ $translatedTextAttribute,
 98+ new DefinedMeaningDefinitionController(),
 99+ new DefinedMeaningFilteredDefinitionController($viewInformation->filterLanguageId),
 100+ $viewInformation
 101+ ));
102102 $editor->addEditor(new PopUpEditor($definitionObjectAttributesEditor, $wgPopupAnnotationName));
103103
104104 return $editor;
105105 }
106106
107 -function getTranslatedTextEditor(Attribute $attribute, UpdateController $controller, ViewInformation $viewInformation) {
 107+function getTranslatedTextEditor(Attribute $attribute, UpdateController $updateController, UpdateAttributeController $updateAttributeController, ViewInformation $viewInformation) {
108108 global
109109 $languageAttribute, $textAttribute;
110110
111111 if ($viewInformation->filterLanguageId == 0 || $viewInformation->showRecordLifeSpan) {
112 - $editor = new RecordSetTableEditor($attribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, true, $controller);
 112+ $editor = new RecordSetTableEditor($attribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, true, $updateController);
113113
114114 if ($viewInformation->filterLanguageId == 0)
115115 $editor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true));
@@ -117,7 +117,7 @@
118118 addTableMetadataEditors($editor, $viewInformation);
119119 }
120120 else
121 - $editor = new TextEditor($attribute, new SimplePermissionController(true), true, false, 0, $controller);
 121+ $editor = new TextEditor($attribute, new SimplePermissionController(true), true, false, 0, $updateAttributeController);
122122
123123 return $editor;
124124 }
@@ -133,11 +133,6 @@
134134 global
135135 $alternativeDefinitionsAttribute, $alternativeDefinitionAttribute, $sourceAttribute;
136136
137 - if ($viewInformation->filterLanguageId == 0)
138 - $alternativeDefinitionController = new DefinedMeaningAlternativeDefinitionController();
139 - else
140 - $alternativeDefinitionController = new DefinedMeaningFilteredAlternativeDefinitionController($viewInformation);
141 -
142137 $editor = new RecordSetTableEditor(
143138 $alternativeDefinitionsAttribute,
144139 new SimplePermissionController(true),
@@ -148,7 +143,12 @@
149144 new DefinedMeaningAlternativeDefinitionsController($viewInformation->filterLanguageId)
150145 );
151146
152 - $editor->addEditor(getTranslatedTextEditor($alternativeDefinitionAttribute, $alternativeDefinitionController, $viewInformation));
 147+ $editor->addEditor(getTranslatedTextEditor(
 148+ $alternativeDefinitionAttribute,
 149+ new DefinedMeaningAlternativeDefinitionController(),
 150+ new DefinedMeaningFilteredAlternativeDefinitionController($viewInformation),
 151+ $viewInformation)
 152+ );
153153 $editor->addEditor(new DefinedMeaningReferenceEditor($sourceAttribute, new SimplePermissionController(false), true));
154154
155155 addTableMetadataEditors($editor, $viewInformation);
@@ -328,14 +328,14 @@
329329 $translatedTextAttributeAttribute, $translatedTextValueAttribute, $translatedTextAttributeValuesAttribute,
330330 $translatedTextValueObjectAttributesEditor, $wgPopupAnnotationName;
331331
332 - if ($viewInformation->filterLanguageId == 0)
333 - $translatedTextAttributeValueController = new TranslatedTextAttributeValueController();
334 - else
335 - $translatedTextAttributeValueController = new FilteredTranslatedTextAttributeValueController($viewInformation->filterLanguageId);
336 -
337332 $editor = new RecordSetTableEditor($translatedTextAttributeValuesAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
338333 $editor->addEditor(new TranslatedTextAttributeEditor($translatedTextAttributeAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
339 - $editor->addEditor(getTranslatedTextEditor($translatedTextValueAttribute, $translatedTextAttributeValueController, $viewInformation));
 334+ $editor->addEditor(getTranslatedTextEditor(
 335+ $translatedTextValueAttribute,
 336+ new TranslatedTextAttributeValueController(),
 337+ new FilteredTranslatedTextAttributeValueController($viewInformation->filterLanguageId),
 338+ $viewInformation
 339+ ));
340340 $editor->addEditor(new PopUpEditor($translatedTextValueObjectAttributesEditor, $wgPopupAnnotationName));
341341
342342 addTableMetadataEditors($editor, $viewInformation);
Index: trunk/extensions/Wikidata/OmegaWiki/Record.php
@@ -114,14 +114,14 @@
115115 $attributes = $structure->getAttributes();
116116 $i = 0;
117117
118 - while($result && $i < count($attributes)) {
 118+ while ($result && $i < count($attributes)) {
119119 $attribute = $attributes[$i];
120120 $type = $attribute->type;
121121 $lhsValue = $lhs->getAttributeValue($attribute);
122122 $rhsValue = $rhs->getAttributeValue($attribute);
123123
124124 if ($type instanceof Structure)
125 - $result = equalRecords($type->getStructure(), $lhsValue, $rhsValue);
 125+ $result = $lhsValue instanceof Record && $rhsValue instanceof Record && equalRecords($type, $lhsValue, $rhsValue);
126126 else
127127 $result = $lhsValue == $rhsValue;
128128
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialNeedsTranslation.php
@@ -20,8 +20,9 @@
2121 require_once("forms.php");
2222 require_once("type.php");
2323 require_once("OmegaWikiAttributes.php");
 24+ require_once("ViewInformation.php");
2425
25 - initializeOmegaWikiAttributes(false, false);
 26+ initializeOmegaWikiAttributes(new ViewInformation());
2627 $wgOut->setPageTitle('Expressions needing translation');
2728
2829 $sourceLanguageId = $_GET['from-lang'];

Status & tagging log