r25644 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25643‎ | r25644 | r25645 >
Date:16:31, 7 September 2007
Author:proes
Status:old
Tags:
Comment:
Automatically use the only option when the attribute drop down has only one option when entering attribute values.
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
@@ -367,27 +367,30 @@
368368
369369 class ObjectAttributeValuesController extends DefaultUpdateController {
370370 protected $objectIdFetcher;
 371+ protected $attributeIDFilter;
 372+ protected $levelName;
371373
372 - public function __construct(ContextFetcher $objectIdFetcher) {
 374+ public function __construct(ContextFetcher $objectIdFetcher, $levelName, AttributeIDFilter $attributeIDFilter) {
373375 $this->objectIdFetcher = $objectIdFetcher;
 376+ $this->attributeIDFilter = $attributeIDFilter;
 377+ $this->levelName = $levelName;
374378 }
 379+
 380+ protected function determineAttributeId(IdStack $idPath, $annotationType, $attributeIdFromRecord) {
 381+ $classAttributes = $idPath->getClassAttributes()->filterClassAttributesOnLevelAndType($this->levelName, $annotationType);
 382+ $classAttributes = $this->attributeIDFilter->filter($classAttributes);
 383+
 384+ if (count($classAttributes) == 1)
 385+ return $classAttributes[0];
 386+ else
 387+ return $attributeIdFromRecord;
 388+ }
375389 }
376390
377391 class DefinedMeaningAttributeValuesController extends ObjectAttributeValuesController {
378 - protected $attributeIDFilter;
379 -
380 - public function __construct(ContextFetcher $objectIdFetcher, AttributeIDFilter $attributeIDFilter) {
381 - parent::__construct($objectIdFetcher);
382 -
383 - $this->attributeIDFilter = $attributeIDFilter;
384 - }
385 -
386392 public function add(IdStack $idPath, $record) {
387 -// if ($this->allowedAttributeIDs != null && count($this->allowedAttributeIDs) == 1)
388 -// echo "Allowed attribute: " . $this->allowedAttributeIDs[0];
389 -
390393 $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
391 - $definedMeaningAttributeId = $record->relationType;
 394+ $definedMeaningAttributeId = $this->determineAttributeId($idPath, "DM", $record->relationType);
392395 $definedMeaningValue = $record->otherDefinedMeaning;
393396
394397 if ($definedMeaningAttributeId != 0 && $definedMeaningValue != 0)
@@ -403,7 +406,7 @@
404407 class TextAttributeValuesController extends ObjectAttributeValuesController {
405408 public function add(IdStack $idPath, $record) {
406409 $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
407 - $textAttributeId = $record->textAttribute;
 410+ $textAttributeId = $this->determineAttributeId($idPath, "TEXT", $record->textAttribute);
408411 $text = $record->text;
409412
410413 if ($textAttributeId != 0 && $text != '')
@@ -435,7 +438,7 @@
436439
437440 public function add(IdStack $idPath, $record) {
438441 $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
439 - $linkAttributeId = $record->linkAttribute;
 442+ $linkAttributeId = $this->determineAttributeId($idPath, "URL", $record->linkAttribute);
440443 $linkValue = $record->link;
441444 $label = $linkValue->linkLabel;
442445 $url = $linkValue->linkURL;
@@ -463,8 +466,8 @@
464467 class TranslatedTextAttributeValuesController extends ObjectAttributeValuesController {
465468 protected $filterLanguageId;
466469
467 - public function __construct($objectIdFetcher, $filterLanguageId) {
468 - parent::__construct($objectIdFetcher);
 470+ public function __construct(ContextFetcher $objectIdFetcher, $levelName, AttributeIDFilter $attributeIDFilter, $filterLanguageId) {
 471+ parent::__construct($objectIdFetcher, $levelName, $attributeIDFilter);
469472
470473 $this->filterLanguageId = $filterLanguageId;
471474 }
@@ -472,7 +475,7 @@
473476 public function add(IdStack $idPath, $record) {
474477 $objectId = $this->objectIdFetcher->fetch($idPath->getKeyStack());
475478 $textValue = $record->translatedTextValue;
476 - $textAttributeId = $record->translatedTextAttribute;
 479+ $textAttributeId = $this->determineAttributeId($idPath, "TRNS", $record->translatedTextAttribute);
477480
478481 if ($textAttributeId != 0) {
479482 if ($this->filterLanguageId == 0) {
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -426,11 +426,11 @@
427427 $attributeIDFilter = $objectAttributesEditor->getAttributeIDfilter();
428428 $annotationLevelName = $objectAttributesEditor->getLevelName();
429429
430 - $objectAttributesEditor->addEditor(getDefinedMeaningAttributeValuesEditor($viewInformation, new DefinedMeaningAttributeValuesController($annotatedObjectIdFetcher, $attributeIDFilter), $annotationLevelName, $attributeIDFilter));
431 - $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($viewInformation, new TextAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter));
432 - $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($viewInformation, new TranslatedTextAttributeValuesController($annotatedObjectIdFetcher, $viewInformation->filterLanguageId), $annotationLevelName, $attributeIDFilter));
433 - $objectAttributesEditor->addEditor(getLinkAttributeValuesEditor($viewInformation, new LinkAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter));
434 - $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($viewInformation, new OptionAttributeValuesController($annotatedObjectIdFetcher), $annotationLevelName, $attributeIDFilter));
 430+ $objectAttributesEditor->addEditor(getDefinedMeaningAttributeValuesEditor($viewInformation, new DefinedMeaningAttributeValuesController($annotatedObjectIdFetcher, $annotationLevelName, $attributeIDFilter), $annotationLevelName, $attributeIDFilter));
 431+ $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($viewInformation, new TextAttributeValuesController($annotatedObjectIdFetcher, $annotationLevelName, $attributeIDFilter), $annotationLevelName, $attributeIDFilter));
 432+ $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($viewInformation, new TranslatedTextAttributeValuesController($annotatedObjectIdFetcher, $annotationLevelName, $attributeIDFilter, $viewInformation->filterLanguageId), $annotationLevelName, $attributeIDFilter));
 433+ $objectAttributesEditor->addEditor(getLinkAttributeValuesEditor($viewInformation, new LinkAttributeValuesController($annotatedObjectIdFetcher, $annotationLevelName, $attributeIDFilter), $annotationLevelName, $attributeIDFilter));
 434+ $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($viewInformation, new OptionAttributeValuesController($annotatedObjectIdFetcher, $annotationLevelName, $attributeIDFilter), $annotationLevelName, $attributeIDFilter));
435435 }
436436
437437 function createObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, $propertyCaption, $valueCaption, Attribute $idAttribute, $levelName, AttributeIDFilter $attributeIDFilter) {
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -2355,8 +2355,14 @@
23562356 }
23572357
23582358 public function save(IdStack $idPath, $value) {
2359 - $idPath->pushDefinedMeaningId($value->definedMeaningId);
 2359+ $definedMeaningId = (int) $value->definedMeaningId;
 2360+
 2361+ $idPath->pushDefinedMeaningId($definedMeaningId);
 2362+ $idPath->pushClassAttributes(new ClassAttributes($definedMeaningId));
 2363+
23602364 $this->wrappedEditor->save($idPath, $value);
 2365+
 2366+ $idPath->popClassAttributes();
23612367 $idPath->popDefinedMeaningId();
23622368 }
23632369 }

Status & tagging log