r25641 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25640‎ | r25641 | r25642 >
Date:15:44, 7 September 2007
Author:proes
Status:old
Tags:
Comment:
Changed interface UpdateController to use an IdStack on add() instead of a RecordStack
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Controller.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/Controller.php
@@ -3,7 +3,7 @@
44 require_once("OmegaWikiAttributes.php");
55
66 interface UpdateController {
7 - public function add($keyPath, $record);
 7+ public function add(IdStack $idPath, $record);
88 public function remove($keyPath);
99 public function update($keyPath, $record);
1010 }
@@ -40,9 +40,20 @@
4141 }
4242 }
4343
44 -class DefinedMeaningDefinitionController implements UpdateController {
45 - public function add($keyPath, $record) {
46 - $definedMeaningId = $keyPath->peek(0)->definedMeaningId;
 44+class DefaultUpdateController implements UpdateController {
 45+ public function add(IdStack $idPath, $record) {
 46+ }
 47+
 48+ public function remove($keyPath) {
 49+ }
 50+
 51+ public function update($keyPath, $record) {
 52+ }
 53+}
 54+
 55+class DefinedMeaningDefinitionController extends DefaultUpdateController {
 56+ public function add(IdStack $idPath, $record) {
 57+ $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId;
4758 $languageId = $record->language;
4859 $text = $record->text;
4960
@@ -81,15 +92,15 @@
8293 }
8394 }
8495
85 -class DefinedMeaningAlternativeDefinitionsController implements UpdateController {
 96+class DefinedMeaningAlternativeDefinitionsController extends DefaultUpdateController {
8697 protected $filterLanguageId;
8798
8899 public function __construct($filterLanguageId) {
89100 $this->filterLanguageId = $filterLanguageId;
90101 }
91102
92 - public function add($keyPath, $record) {
93 - $definedMeaningId = $keyPath->peek(0)->definedMeaningId;
 103+ public function add(IdStack $idPath, $record) {
 104+ $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId;
94105 $alternativeDefinition = $record->alternativeDefinition;
95106 $sourceId = $record->source;
96107
@@ -113,14 +124,11 @@
114125 $definitionId = $keyPath->peek(0)->definitionId;
115126 removeDefinedMeaningAlternativeDefinition($definedMeaningId, $definitionId);
116127 }
117 -
118 - public function update($keyPath, $record) {
119 - }
120128 }
121129
122 -class DefinedMeaningAlternativeDefinitionController implements UpdateController {
123 - public function add($keyPath, $record) {
124 - $definitionId = $keyPath->peek(0)->definitionId;
 130+class DefinedMeaningAlternativeDefinitionController extends DefaultUpdateController {
 131+ public function add(IdStack $idPath, $record) {
 132+ $definitionId = $idPath->getKeyStack()->peek(0)->definitionId;
125133 $languageId = $record->language;
126134 $text = $record->text;
127135
@@ -160,15 +168,15 @@
161169 }
162170 }
163171
164 -class SynonymTranslationController implements UpdateController {
 172+class SynonymTranslationController extends DefaultUpdateController {
165173 protected $filterLanguageId;
166174
167175 public function __construct($filterLanguageId) {
168176 $this->filterLanguageId = $filterLanguageId;
169177 }
170178
171 - public function add($keyPath, $record) {
172 - $definedMeaningId = $keyPath->peek(0)->definedMeaningId;
 179+ public function add(IdStack $idPath, $record) {
 180+ $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId;
173181 $expressionValue = $record->expression;
174182
175183 if ($this->filterLanguageId == 0) {
@@ -202,9 +210,9 @@
203211 }
204212 }
205213
206 -class ClassAttributesController implements UpdateController {
207 - public function add($keyPath, $record) {
208 - $definedMeaningId = $keyPath->peek(0)->definedMeaningId;
 214+class ClassAttributesController extends DefaultUpdateController {
 215+ public function add(IdStack $idPath, $record) {
 216+ $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId;
209217 $attributeLevelId = $record->classAttributeLevel;
210218 $attributeMeaningId = $record->classAttributeAttribute;
211219 $attributeType = $record->classAttributeType;
@@ -217,12 +225,9 @@
218226 $classAttributeId = $keyPath->peek(0)->classAttributeId;
219227 removeClassAttributeWithId($classAttributeId);
220228 }
221 -
222 - public function update($keyPath, $record) {
223 - }
224229 }
225230
226 -class GroupedRelationTypeController implements UpdateController {
 231+class GroupedRelationTypeController extends DefaultUpdateController {
227232 protected $relationTypeId;
228233 protected $groupedRelationIdAttribute;
229234 protected $otherDefinedMeaningAttribute;
@@ -233,8 +238,8 @@
234239 $this->otherDefinedMeaningAttribute = $otherDefinedMeaningAttribute;
235240 }
236241
237 - public function add($keyPath, $record) {
238 - $definedMeaningId = $keyPath->peek(0)->definedMeaningId;
 242+ public function add(IdStack $idPath, $record) {
 243+ $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId;
239244 $otherDefinedMeaningId = $record->getAttributeValue($this->otherDefinedMeaningAttribute);
240245
241246 if ($otherDefinedMeaningId != 0)
@@ -245,14 +250,11 @@
246251 $relationId = $keyPath->peek(0)->getAttributeValue($this->groupedRelationIdAttribute);
247252 removeRelationWithId($relationId);
248253 }
249 -
250 - public function update($keyPath, $record) {
251 - }
252254 }
253255
254 -class DefinedMeaningClassMembershipController implements UpdateController {
255 - public function add($keyPath, $record) {
256 - $definedMeaningId = $keyPath->peek(0)->definedMeaningId;
 256+class DefinedMeaningClassMembershipController extends DefaultUpdateController {
 257+ public function add(IdStack $idPath, $record) {
 258+ $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId;
257259 $classId = $record->class;
258260
259261 if ($classId != 0)
@@ -262,14 +264,11 @@
263265 public function remove($keyPath) {
264266 removeClassMembershipWithId($keyPath->peek(0)->classMembershipId);
265267 }
266 -
267 - public function update($keyPath, $record) {
268 - }
269268 }
270269
271 -class DefinedMeaningCollectionController implements UpdateController {
272 - public function add($keyPath, $record) {
273 - $definedMeaningId = $keyPath->peek(0)->definedMeaningId;
 270+class DefinedMeaningCollectionController extends DefaultUpdateController {
 271+ public function add(IdStack $idPath, $record) {
 272+ $definedMeaningId = $idPath->getKeyStack()->peek(0)->definedMeaningId;
274273 $collectionMeaningId = $record->collectionMeaning;
275274 $internalId = $record->sourceIdentifier;
276275
@@ -294,17 +293,17 @@
295294 }
296295 }
297296
298 -class ExpressionMeaningController implements UpdateController {
 297+class ExpressionMeaningController extends DefaultUpdateController {
299298 protected $filterLanguageId;
300299
301300 public function __construct($filterLanguageId) {
302301 $this->filterLanguageId = $filterLanguageId;
303302 }
304303
305 - public function add($keyPath, $record) {
 304+ public function add(IdStack $idPath, $record) {
306305 $definition = $record->definedMeaning->definition;
307306 $translatedContent = $definition->translatedText;
308 - $expressionId = $keyPath->peek(0)->expressionId;
 307+ $expressionId = $idPath->getKeyStack()->peek(0)->expressionId;
309308
310309 if ($this->filterLanguageId == 0) {
311310 if ($translatedContent->getRecordCount() > 0) {
@@ -320,15 +319,9 @@
321320 else if ($translatedContent != "")
322321 createNewDefinedMeaning($expressionId, $this->filterLanguageId, $translatedContent);
323322 }
324 -
325 - public function remove($keyPath) {
326 - }
327 -
328 - public function update($keyPath, $record) {
329 - }
330323 }
331324
332 -class ExpressionController implements UpdateController {
 325+class ExpressionController extends DefaultUpdateController {
333326 protected $spelling;
334327 protected $filterLanguageId;
335328
@@ -337,7 +330,7 @@
338331 $this->filterLanguageId = $filterLanguageId;
339332 }
340333
341 - public function add($keyPath, $record) {
 334+ public function add(IdStack $idPath, $record) {
342335 if ($this->filterLanguageId == 0)
343336 $expressionLanguageId = $record->expression->language;
344337 else
@@ -370,25 +363,30 @@
371364 }
372365 }
373366 }
374 -
375 - public function remove($keyPath) {
376 - }
377 -
378 - public function update($keyPath, $record) {
379 - }
380367 }
381368
382 -abstract class ObjectAttributeValuesController implements UpdateController {
 369+class ObjectAttributeValuesController extends DefaultUpdateController {
383370 protected $objectIdFetcher;
384371
385 - public function __construct($objectIdFetcher) {
 372+ public function __construct(ContextFetcher $objectIdFetcher) {
386373 $this->objectIdFetcher = $objectIdFetcher;
387374 }
388375 }
389376
390377 class DefinedMeaningAttributeValuesController extends ObjectAttributeValuesController {
391 - public function add($keyPath, $record) {
392 - $objectId = $this->objectIdFetcher->fetch($keyPath);
 378+ protected $attributeIDFilter;
 379+
 380+ public function __construct(ContextFetcher $objectIdFetcher, AttributeIDFilter $attributeIDFilter) {
 381+ parent::__construct($objectIdFetcher);
 382+
 383+ $this->attributeIDFilter = $attributeIDFilter;
 384+ }
 385+
 386+ public function add(IdStack $idPath, $record) {
 387+// if ($this->allowedAttributeIDs != null && count($this->allowedAttributeIDs) == 1)
 388+// echo "Allowed attribute: " . $this->allowedAttributeIDs[0];
 389+
 390+ $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
393391 $definedMeaningAttributeId = $record->relationType;
394392 $definedMeaningValue = $record->otherDefinedMeaning;
395393
@@ -400,16 +398,14 @@
401399 $valueId = $keyPath->peek(0)->relationId;
402400 removeRelationWithId($valueId);
403401 }
404 -
405 - public function update($keyPath, $record) {
406 - }
407402 }
408403
409404 class TextAttributeValuesController extends ObjectAttributeValuesController {
410 - public function add($keyPath, $record) {
411 - $objectId = $this->objectIdFetcher->fetch($keyPath);
 405+ public function add(IdStack $idPath, $record) {
 406+ $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
412407 $textAttributeId = $record->textAttribute;
413408 $text = $record->text;
 409+
414410 if ($textAttributeId != 0 && $text != '')
415411 addTextAttributeValue($objectId, $textAttributeId, $text);
416412 }
@@ -437,8 +433,8 @@
438434 return $url;
439435 }
440436
441 - public function add($keyPath, $record) {
442 - $objectId = $this->objectIdFetcher->fetch($keyPath);
 437+ public function add(IdStack $idPath, $record) {
 438+ $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
443439 $linkAttributeId = $record->linkAttribute;
444440 $linkValue = $record->link;
445441 $label = $linkValue->linkLabel;
@@ -473,8 +469,8 @@
474470 $this->filterLanguageId = $filterLanguageId;
475471 }
476472
477 - public function add($keyPath, $record) {
478 - $objectId = $this->objectIdFetcher->fetch($keyPath);
 473+ public function add(IdStack $idPath, $record) {
 474+ $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
479475 $textValue = $record->translatedTextValue;
480476 $textAttributeId = $record->translatedTextAttribute;
481477
@@ -499,14 +495,11 @@
500496 $valueId = $keyPath->peek(0)->translatedTextAttributeId;
501497 removeTranslatedTextAttributeValue($valueId);
502498 }
503 -
504 - public function update($keyPath, $record) {
505 - }
506499 }
507500
508 -class TranslatedTextAttributeValueController implements UpdateController {
509 - public function add($keyPath, $record) {
510 - $valueId = $keyPath->peek(0)->translatedTextAttributeId;
 501+class TranslatedTextAttributeValueController extends DefaultUpdateController {
 502+ public function add(IdStack $idPath, $record) {
 503+ $valueId = $idPath->getKeyStack()->peek(0)->translatedTextAttributeId;
511504 $languageId = $record->language;
512505 $text = $record->text;
513506 $translatedTextAttribute = getTranslatedTextAttribute($valueId);
@@ -551,8 +544,8 @@
552545 }
553546
554547 class OptionAttributeValuesController extends ObjectAttributeValuesController {
555 - public function add($keyPath, $record) {
556 - $objectId = $this->objectIdFetcher->fetch($keyPath);
 548+ public function add(IdStack $idPath, $record) {
 549+ $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
557550 $optionId = $record->optionAttributeOption;
558551
559552 if ($optionId)
@@ -563,13 +556,11 @@
564557 $valueId = $keyPath->peek(0)->optionAttributeId;
565558 removeOptionAttributeValue($valueId);
566559 }
567 -
568 - public function update($keyPath, $record) {}
569560 }
570561
571 -class OptionAttributeOptionsController implements UpdateController {
572 - public function add($keyPath, $record) {
573 - $attributeId = $keyPath->peek(0)->classAttributeId;
 562+class OptionAttributeOptionsController extends DefaultUpdateController {
 563+ public function add(IdStack $idPath, $record) {
 564+ $attributeId = $idPath->getKeyStack()->peek(0)->classAttributeId;
574565 $optionMeaningId = $record->optionAttributeOption;
575566 $languageId = $record->language;
576567
@@ -581,9 +572,6 @@
582573 $optionId = $keyPath->peek(0)->optionAttributeOptionId;
583574 removeOptionAttributeOption($optionId);
584575 }
585 -
586 - public function update($keyPath, $record) {
587 - }
588576 }
589577
590578 class AlternativeDefinitionsPermissionController implements PermissionController {
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -426,7 +426,7 @@
427427 $attributeIDFilter = $objectAttributesEditor->getAttributeIDfilter();
428428 $annotationLevelName = $objectAttributesEditor->getLevelName();
429429
430 - $objectAttributesEditor->addEditor(getDefinedMeaningAttributeValuesEditor($viewInformation, new DefinedMeaningAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter));
 430+ $objectAttributesEditor->addEditor(getDefinedMeaningAttributeValuesEditor($viewInformation, new DefinedMeaningAttributeValuesController($annotatedObjectIdFetcher, $attributeIDFilter), $annotationLevelName, $attributeIDFilter));
431431 $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($viewInformation, new TextAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter));
432432 $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($viewInformation, new TranslatedTextAttributeValuesController($annotatedObjectIdFetcher, $viewInformation->filterLanguageId), $annotationLevelName, $attributeIDFilter));
433433 $objectAttributesEditor->addEditor(getLinkAttributeValuesEditor($viewInformation, new LinkAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter));
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -482,7 +482,7 @@
483483 if (count($addStructure->getAttributes()) > 0) {
484484 $addEditors = $this->getAddEditors();
485485 $record = $this->getAddRecord($idPath, $addStructure, $addEditors);
486 - $this->controller->add($idPath->getKeyStack(), $record);
 486+ $this->controller->add($idPath, $record);
487487 }
488488 }
489489
@@ -2181,7 +2181,7 @@
21822182 $idPath->popKey();
21832183 }
21842184 else
2185 - $this->controller->add($idPath->getKeyStack(), $this->recordEditor->getAddValue($idPath));
 2185+ $this->controller->add($idPath, $this->recordEditor->getAddValue($idPath));
21862186 }
21872187
21882188 public function setRecordEditor(Editor $recordEditor) {

Status & tagging log