r23749 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23748‎ | r23749 | r23750 >
Date:18:11, 5 July 2007
Author:proes
Status:old
Tags:
Comment:
* Solved problem with suggestion drop down for URL attributes
* Annotation attributes can be filtered to separate columns for the definition level
* Filtering for other annotation levels is pending
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/PropertyToColumnFilter.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/RecordSet.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/ViewInformation.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php
@@ -92,13 +92,13 @@
9393 $wgSourceIdentifierAttributeName = "Source identifier";
9494 $wgTextAttributeAttributeName = "Property";
9595 $wgTextAttributeName = "Text";
96 -$wgTextAttributeValuesAttributeName = "Plain text properties";
 96+$wgTextAttributeValuesAttributeName = "Plain texts";
9797 $wgTranslatedTextAttributeAttributeName = "Property";
9898 $wgTranslatedTextAttributeName = "Translated text";
9999 $wgTranslatedTextAttributeValueAttributeName = "Text";
100 -$wgTranslatedTextAttributeValuesAttributeName = "Translatable text properties";
 100+$wgTranslatedTextAttributeValuesAttributeName = "Translatable texts";
101101 $wgUrlAttributeAttributeName = "Property";
102 -$wgUrlAttributeValuesAttributeName = "URL properties";
 102+$wgUrlAttributeValuesAttributeName = "URLs";
103103
104104 // Go to source templates
105105
Index: trunk/extensions/Wikidata/OmegaWiki/PropertyToColumnFilter.php
@@ -1,14 +1,18 @@
22 <?php
33
 4+require_once('Attribute.php');
 5+
46 class PropertyToColumnFilter {
5 - public $identifier; // The identifier of the attribute that will be created
6 - public $caption; // The caption of the attribute that will be created
77 public $attributeIDs; // Array containing the defined meaning ids of the attributes that should be filtered
 8+ protected $attribute; // Attribute
89
910 public function __construct($identifier, $caption, array $attributeIDs) {
10 - $this->identifier = $identifier;
11 - $this->caption = $caption;
1211 $this->attributeIDs = $attributeIDs;
 12+ $this->attribute = new Attribute($identifier, $caption, "will-be-specified-later");
 13+ }
 14+
 15+ public function getAttribute() {
 16+ return $this->attribute;
1317 }
1418 }
1519
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php
@@ -72,7 +72,7 @@
7373 $sql = getSQLToSelectPossibleAttributes($objectId, $attributesLevel, 'TEXT');
7474 break;
7575 case 'url-attribute':
76 - $sql = getSQLToSelectPossibleAttributes($objectId, $attributesLevel, 'URL');
 76+ $sql = getSQLToSelectPossibleAttributes($objectId, $attributesLevel, 'TEXT');
7777 break;
7878 case 'language':
7979 require_once('languages.php');
@@ -118,6 +118,7 @@
119119 $query == 'option-attribute' or
120120 $query == 'translated-text-attribute' or
121121 $query == 'text-attribute' or
 122+ $query == 'url-attribute' or
122123 $query == 'collection')
123124 $searchCondition = " WHERE $rowText LIKE " . $dbr->addQuotes("$search%");
124125 else
@@ -231,7 +232,7 @@
232233 $sqlActual = getSQLToSelectPossibleAttributesForLanguage($objectId, $attributesLevel, $attributesType, $wgUser->getOption('language'));
233234 $sqlFallback = getSQLToSelectPossibleAttributesForLanguage($objectId, $attributesLevel, $attributesType, 'en');
234235
235 - return constructSQLWithFallback($sqlActual, $sqlFallback, array("attribute_mid", "spelling"));
 236+ return constructSQLWithFallback($sqlActual, $sqlFallback, array("attribute_mid", "spelling"));
236237 }
237238
238239 # language is the 2 letter wikimedia code. use "<ANY>" if you don't want language filtering
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -311,6 +311,21 @@
312312 $objectAttributesStructure = new Structure("object-attributes", $objectIdAttribute, $textAttributeValuesAttribute, $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute);
313313 $objectAttributesAttribute->setAttributeType($objectAttributesStructure);
314314 $definedMeaningAttributesAttribute->setAttributeType($objectAttributesStructure);
 315+
 316+ $annotatedAttributes = array(
 317+ $definitionAttribute,
 318+ $synonymsAndTranslationsAttribute,
 319+ $relationsAttribute,
 320+ $reciprocalRelationsAttribute
 321+ );
 322+
 323+ foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter) {
 324+ $attribute = $propertyToColumnFilter->getAttribute();
 325+ $attribute->setAttributeType($objectAttributesStructure);
 326+
 327+ foreach ($annotatedAttributes as $annotatedAttribute)
 328+ $annotatedAttribute->type->addAttribute($attribute);
 329+ }
315330
316331 global $wdDefinedMeaningAttributesOrder;
317332
Index: trunk/extensions/Wikidata/OmegaWiki/RecordSet.php
@@ -58,6 +58,10 @@
5959 public function add($record) {
6060 $this->records[] = $record;
6161 }
 62+
 63+ public function remove($index) {
 64+ array_splice($this->records, $index, 1);
 65+ }
6266
6367 public function addRecord($values) {
6468 $record = new ArrayRecord($this->structure);
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -16,7 +16,6 @@
1717 $translatedTextValueObjectAttributesEditor, $translatedTextAttributeIdAttribute,
1818 $optionValueObjectAttributesEditor, $optionAttributeIdAttribute, $annotationMeaningName;
1919
20 -
2120 $textValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
2221 $urlValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
2322 $translatedTextValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
@@ -74,8 +73,17 @@
7574 new DefinedMeaningFilteredDefinitionController($viewInformation->filterLanguageId),
7675 $viewInformation
7776 ));
 77+
 78+ foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter) {
 79+ $attribute = $propertyToColumnFilter->getAttribute();
 80+ $editor->addEditor(new PopUpEditor(
 81+ createDefinitionObjectAttributesEditor($viewInformation, $attribute, $definedMeaningIdAttribute, 0, $definitionMeaningName),
 82+ $attribute->name
 83+ ));
 84+ }
 85+
7886 $editor->addEditor(new PopUpEditor(
79 - createObjectAttributesEditor($viewInformation, $objectAttributesAttribute, $definedMeaningIdAttribute, 0, $definitionMeaningName),
 87+ createDefinitionObjectAttributesEditor($viewInformation, $objectAttributesAttribute, $definedMeaningIdAttribute, 0, $definitionMeaningName),
8088 $wgPopupAnnotationName
8189 ));
8290
@@ -125,6 +133,23 @@
126134 return $result;
127135 }
128136
 137+function createDefinitionObjectAttributesEditor(ViewInformation $viewInformation, Attribute $attribute, Attribute $idAttribute, $levelsFromDefinedMeaning, $levelName) {
 138+ global
 139+ $objectAttributesAttribute, $definedMeaningIdAttribute;
 140+
 141+ $result = new RecordUnorderedListEditor($attribute, 5);
 142+
 143+ setObjectAttributesEditor(
 144+ $result,
 145+ $viewInformation,
 146+ new DefinitionObjectIdFetcher(0, $idAttribute),
 147+ $levelName,
 148+ new ObjectIdFetcher($levelsFromDefinedMeaning, $definedMeaningIdAttribute)
 149+ );
 150+
 151+ return $result;
 152+}
 153+
129154 function getAlternativeDefinitionsEditor(ViewInformation $viewInformation) {
130155 global
131156 $alternativeDefinitionsAttribute, $alternativeDefinitionAttribute, $sourceAttribute;
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
@@ -522,20 +522,29 @@
523523 $definitionId = getDefinedMeaningDefinitionId($definedMeaningId);
524524 $record = new ArrayRecord(new Structure($definitionAttribute));
525525 $record->setAttributeValue($translatedTextAttribute, getTranslatedContentValue($definitionId, $viewInformation));
526 - $record->setAttributeValue($objectAttributesAttribute, getObjectAttributesRecord($definitionId, $viewInformation, $objectAttributesAttribute->id));
 526+
 527+ $objectAttributesRecord = getObjectAttributesRecord($definitionId, $viewInformation, $objectAttributesAttribute->id);
 528+ $record->setAttributeValue($objectAttributesAttribute, $objectAttributesRecord);
 529+
 530+ foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter) {
 531+ $record->setAttributeValue(
 532+ $propertyToColumnFilter->getAttribute(),
 533+ filterObjectAttributesRecord($objectAttributesRecord, $propertyToColumnFilter->attributeIDs)
 534+ );
 535+ }
527536
528537 return $record;
529538 }
530539
531540 function getObjectAttributesRecord($objectId, ViewInformation $viewInformation, $structuralOverride = null) {
532541 global
533 - $objectAttributesAttribute, $objectIdAttribute,
 542+ $objectIdAttribute,
534543 $urlAttributeValuesAttribute, $textAttributeValuesAttribute,
535544 $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute,
536545 $definedMeaningAttributesAttribute;
537546
538547 if ($structuralOverride)
539 - $record = new ArrayRecord(new Structure($structuralOverride,$definedMeaningAttributesAttribute));
 548+ $record = new ArrayRecord(new Structure($structuralOverride, $definedMeaningAttributesAttribute));
540549 else
541550 $record = new ArrayRecord(new Structure($definedMeaningAttributesAttribute));
542551
@@ -548,6 +557,65 @@
549558 return $record;
550559 }
551560
 561+function filterAttributeValues(RecordSet $sourceRecordSet, Attribute $attributeAttribute, array &$attributeIds) {
 562+ global
 563+ $definedMeaningIdAttribute;
 564+
 565+ $result = new ArrayRecordSet($sourceRecordSet->getStructure(), $sourceRecordSet->getKey());
 566+ $i = 0;
 567+
 568+ while ($i < $sourceRecordSet->getRecordCount()) {
 569+ $record = $sourceRecordSet->getRecord($i);
 570+
 571+ if (in_array($record->getAttributeValue($attributeAttribute)->getAttributeValue($definedMeaningIdAttribute), $attributeIds)) {
 572+ $result->add($record);
 573+ $sourceRecordSet->remove($i);
 574+ }
 575+ else
 576+ $i++;
 577+ }
 578+
 579+ return $result;
 580+}
 581+
 582+function filterObjectAttributesRecord(Record $sourceRecord, array &$attributeIds) {
 583+ global
 584+ $definedMeaningAttributesAttribute, $objectIdAttribute,
 585+ $textAttributeValuesAttribute, $textAttributeAttribute,
 586+ $translatedTextAttributeAttribute, $translatedTextAttributeValuesAttribute,
 587+ $urlAttributeAttribute, $urlAttributeValuesAttribute,
 588+ $optionAttributeAttribute, $optionAttributeValuesAttribute;
 589+
 590+ $result = new ArrayRecord(new Structure($definedMeaningAttributesAttribute));
 591+ $result->setAttributeValue($objectIdAttribute, $sourceRecord->getAttributeValue($objectIdAttribute));
 592+
 593+ $result->setAttributeValue($textAttributeValuesAttribute, filterAttributeValues(
 594+ $sourceRecord->getAttributeValue($textAttributeValuesAttribute),
 595+ $textAttributeAttribute,
 596+ $attributeIds
 597+ ));
 598+
 599+ $result->setAttributeValue($translatedTextAttributeValuesAttribute, filterAttributeValues(
 600+ $sourceRecord->getAttributeValue($translatedTextAttributeValuesAttribute),
 601+ $translatedTextAttributeAttribute,
 602+ $attributeIds
 603+ ));
 604+
 605+ $result->setAttributeValue($urlAttributeValuesAttribute, filterAttributeValues(
 606+ $sourceRecord->getAttributeValue($urlAttributeValuesAttribute),
 607+ $urlAttributeAttribute,
 608+ $attributeIds
 609+ ));
 610+
 611+ $result->setAttributeValue($optionAttributeValuesAttribute, filterAttributeValues(
 612+ $sourceRecord->getAttributeValue($optionAttributeValuesAttribute),
 613+ $optionAttributeAttribute,
 614+ $attributeIds
 615+ ));
 616+
 617+ return $result;
 618+}
 619+
552620 function getTranslatedContentValue($translatedContentId, ViewInformation $viewInformation) {
553621 global
554622 $textAttribute;
@@ -648,22 +716,22 @@
649717 expandExpressionReferencesInRecordSet($recordSet, array($expressionAttribute));
650718 else
651719 expandExpressionSpellingsInRecordSet($recordSet, array($expressionAttribute));
652 - //add object attributes attribute to the generated structure
653 - //and expand the records
654 - $recordSet->getStructure()->addAttribute($objectAttributesAttribute);
655 - expandObjectAttributesAttribute($recordSet, $syntransIdAttribute, $viewInformation);
 720+
 721+ expandObjectAttributesAttribute($recordSet, $objectAttributesAttribute, $syntransIdAttribute, $viewInformation);
656722 return $recordSet;
657723 }
658724
659 -function expandObjectAttributesAttribute(RecordSet $recordSet, Attribute $objectIdAttribute, ViewInformation $viewInformation) {
 725+function expandObjectAttributesAttribute(RecordSet $recordSet, Attribute $attributeToExpand, Attribute $objectIdAttribute, ViewInformation $viewInformation) {
660726 global
661 - $objectAttributesAttribute,
662727 $textAttributeObjectAttribute, $textAttributeValuesAttribute,
663728 $translatedTextAttributeObjectAttribute, $translatedTextAttributeValuesAttribute,
664729 $urlAttributeObjectAttribute, $urlAttributeValuesAttribute,
665730 $optionAttributeObjectAttribute, $optionAttributeValuesAttribute;
666731
667 - $objectAttributesRecordStructure = $objectAttributesAttribute->type;
 732+ $recordSetStructure = $recordSet->getStructure();
 733+ $recordSetStructure->addAttribute($attributeToExpand);
 734+
 735+ $objectAttributesRecordStructure = $attributeToExpand->type;
668736 $objectIds = getUniqueIdsInRecordSet($recordSet, array($objectIdAttribute));
669737
670738 if (count($objectIds) > 0) {
@@ -750,7 +818,7 @@
751819 $objectAttributesRecord->setAttributeValue($urlAttributeValuesAttribute, $urlAttributeValuesRecordSet);
752820 $objectAttributesRecord->setAttributeValue($optionAttributeValuesAttribute, $optionAttributeValuesRecordSet);
753821
754 - $record->setAttributeValue($objectAttributesAttribute, $objectAttributesRecord);
 822+ $record->setAttributeValue($attributeToExpand, $objectAttributesRecord);
755823 }
756824 }
757825 }
@@ -794,12 +862,7 @@
795863 );
796864
797865 expandDefinedMeaningReferencesInRecordSet($recordSet, array($relationTypeAttribute, $otherDefinedMeaningAttribute));
798 -
799 - //add object attributes attribute to the generated structure
800 - //and expand the records
801 - $struct=$recordSet->getStructure();
802 - $struct->addAttribute($objectAttributesAttribute);
803 - expandObjectAttributesAttribute($recordSet, $relationIdAttribute, $viewInformation);
 866+ expandObjectAttributesAttribute($recordSet, $objectAttributesAttribute, $relationIdAttribute, $viewInformation);
804867
805868 return $recordSet;
806869 }
@@ -825,12 +888,7 @@
826889 );
827890
828891 expandDefinedMeaningReferencesInRecordSet($recordSet, array($relationTypeAttribute, $otherDefinedMeaningAttribute));
829 -
830 - //add object attributes attribute to the generated structure
831 - //and expand the records
832 - $struct=$recordSet->getStructure();
833 - $struct->addAttribute($objectAttributesAttribute);
834 - expandObjectAttributesAttribute($recordSet, $relationIdAttribute, $viewInformation);
 892+ expandObjectAttributesAttribute($recordSet, $objectAttributesAttribute, $relationIdAttribute, $viewInformation);
835893
836894 return $recordSet;
837895 }
@@ -857,12 +915,7 @@
858916 );
859917
860918 expandDefinedMeaningReferencesInRecordSet($recordSet, array($possibleSynonymAttribute));
861 -
862 - //add object attributes attribute to the generated structure
863 - //and expand the records
864 - $struct=$recordSet->getStructure();
865 - $struct->addAttribute($objectAttributesAttribute);
866 - expandObjectAttributesAttribute($recordSet, $possiblySynonymousIdAttribute, $viewInformation);
 919+ expandObjectAttributesAttribute($recordSet, $objectAttributesAttribute, $possiblySynonymousIdAttribute, $viewInformation);
867920
868921 return $recordSet;
869922 }
@@ -929,11 +982,7 @@
930983 );
931984
932985 expandDefinedMeaningReferencesInRecordSet($recordSet, array($textAttributeAttribute));
933 -
934 - //add object attributes attribute to the generated structure
935 - //and expand the records
936 - $recordSet->getStructure()->addAttribute($objectAttributesAttribute);
937 - expandObjectAttributesAttribute($recordSet, $textAttributeIdAttribute, $viewInformation);
 986+ expandObjectAttributesAttribute($recordSet, $objectAttributesAttribute, $textAttributeIdAttribute, $viewInformation);
938987
939988 return $recordSet;
940989 }
@@ -959,11 +1008,7 @@
9601009 );
9611010
9621011 expandDefinedMeaningReferencesInRecordSet($recordSet, array($urlAttributeAttribute));
963 -
964 - //add object attributes attribute to the generated structure
965 - //and expand the records
966 - $recordSet->getStructure()->addAttribute($objectAttributesAttribute);
967 - expandObjectAttributesAttribute($recordSet, $urlAttributeIdAttribute, $viewInformation);
 1012+ expandObjectAttributesAttribute($recordSet, $objectAttributesAttribute, $urlAttributeIdAttribute, $viewInformation);
9681013
9691014 return $recordSet;
9701015 }
@@ -992,11 +1037,7 @@
9931038
9941039 expandTranslatedContentsInRecordSet($recordSet, $translatedTextValueIdAttribute, $translatedTextValueAttribute, $viewInformation);
9951040 expandDefinedMeaningReferencesInRecordSet($recordSet, array($translatedTextAttributeAttribute));
996 -
997 - //add object attributes attribute to the generated structure
998 - //and expand the records
999 - $recordSet->getStructure()->addAttribute($objectAttributesAttribute);
1000 - expandObjectAttributesAttribute($recordSet, $translatedTextAttributeIdAttribute, $viewInformation);
 1041+ expandObjectAttributesAttribute($recordSet, $objectAttributesAttribute, $translatedTextAttributeIdAttribute, $viewInformation);
10011042 return $recordSet;
10021043 }
10031044
@@ -1043,12 +1084,8 @@
10441085
10451086 expandOptionsInRecordSet($recordSet, $viewInformation);
10461087 expandDefinedMeaningReferencesInRecordSet($recordSet, array($optionAttributeAttribute, $optionAttributeOptionAttribute));
 1088+ expandObjectAttributesAttribute($recordSet, $objectAttributesAttribute, $optionAttributeIdAttribute, $viewInformation);
10471089
1048 - /* Add object attributes attribute to the generated structure
1049 - and expand the records. */
1050 - $recordSet->getStructure()->addAttribute($objectAttributesAttribute);
1051 - expandObjectAttributesAttribute($recordSet, $optionAttributeIdAttribute, $viewInformation);
1052 -
10531090 return $recordSet;
10541091 }
10551092
Index: trunk/extensions/Wikidata/OmegaWiki/ViewInformation.php
@@ -24,6 +24,7 @@
2525 $this->possiblySynonymousRelationTypeId = 0;
2626 $this->queryTransactionInformation;
2727 $this->showRecordLifeSpan = false;
 28+ $this->propertyToColumnFilters = array();
2829 }
2930
3031 public function hasMetaDataAttributes() {
@@ -37,6 +38,10 @@
3839 public function setPropertyToColumnFilters(array $propertyToColumnFilters) {
3940 $this->propertyToColumnFilters = $propertyToColumnFilters;
4041 }
 42+
 43+ public function getPropertyToColumnFilters() {
 44+ return $this->propertyToColumnFilters;
 45+ }
4146 }
4247
4348 ?>

Status & tagging log