r19453 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19452‎ | r19453 | r19454 >
Date:15:08, 18 January 2007
Author:proes
Status:old
Tags:
Comment:
Implemented URL attribute values.
Modified paths:
  • /trunk/extensions/Wikidata/WiktionaryZ/Controller.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/Expression.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/WikiDataTables.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZAttributes.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZEditors.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZRecordSets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/WiktionaryZ/Controller.php
@@ -488,6 +488,38 @@
489489 }
490490 }
491491
 492+class URLAttributeValuesController extends ObjectAttributeValuesController {
 493+ public function add($keyPath, $record) {
 494+ global
 495+ $urlAttribute, $urlAttributeAttribute;
 496+
 497+ $objectId = $this->objectIdFetcher->fetch($keyPath);
 498+ $urlAttributeId = $record->getAttributeValue($urlAttributeAttribute);
 499+ $url = $record->getAttributeValue($urlAttribute);
 500+
 501+ if ($urlAttributeId != 0 && $url != '')
 502+ addURLAttributeValue($objectId, $urlAttributeId, $url);
 503+ }
 504+
 505+ public function remove($keyPath) {
 506+ global
 507+ $urlAttributeIdAttribute;
 508+
 509+ $urlId = $keyPath->peek(0)->getAttributeValue($urlAttributeIdAttribute);
 510+ removeURLAttributeValue($urlId);
 511+ }
 512+
 513+ public function update($keyPath, $record) {
 514+ global
 515+ $urlAttributeIdAttribute, $urlAttribute;
 516+
 517+ $urlId = $keyPath->peek(0)->getAttributeValue($urlAttributeIdAttribute);
 518+ $url = $record->getAttributeValue($urlAttribute);
 519+
 520+ updateURLAttributeValue($url, $urlId);
 521+ }
 522+}
 523+
492524 class TranslatedTextAttributeValuesController extends ObjectAttributeValuesController {
493525 protected $filterLanguageId;
494526
Index: trunk/extensions/Wikidata/WiktionaryZ/Expression.php
@@ -603,7 +603,7 @@
604604 function createTextAttributeValue($objectId, $textAttributeId, $text, $textValueAttributeId) {
605605 $dbr = &wfGetDB(DB_MASTER);
606606 $dbr->query("INSERT INTO uw_text_attribute_values (value_id, object_id, attribute_mid, text, add_transaction_id) " .
607 - "VALUES ($textValueAttributeId, $objectId, $textAttributeId, '$text', ". getUpdateTransactionId() .")");
 607+ "VALUES ($textValueAttributeId, $objectId, $textAttributeId, " . $dbr->addQuotes($text) . ", ". getUpdateTransactionId() .")");
608608 }
609609
610610 function removeTextAttributeValue($textValueAttributeId) {
@@ -627,6 +627,38 @@
628628 return $dbr->fetchObject($queryResult);
629629 }
630630
 631+function addURLAttributeValue($objectId, $urlAttributeId, $text) {
 632+ $urlValueAttributeId = newObjectId('uw_url_attribute_values');
 633+ createURLAttributeValue($objectId, $urlAttributeId, $text, $urlValueAttributeId);
 634+}
 635+
 636+function createURLAttributeValue($objectId, $urlAttributeId, $url, $urlValueAttributeId) {
 637+ $dbr = &wfGetDB(DB_MASTER);
 638+ $dbr->query("INSERT INTO uw_url_attribute_values (value_id, object_id, attribute_mid, url, label, add_transaction_id) " .
 639+ "VALUES ($urlValueAttributeId, $objectId, $urlAttributeId, " . $dbr->addQuotes($url) . ", " . $dbr->addQuotes($url) . ", ". getUpdateTransactionId() .")");
 640+}
 641+
 642+function removeURLAttributeValue($urlValueAttributeId) {
 643+ $dbr = &wfGetDB(DB_MASTER);
 644+ $dbr->query("UPDATE uw_url_attribute_values SET remove_transaction_id=". getUpdateTransactionId() .
 645+ " WHERE value_id=$urlValueAttributeId" .
 646+ " AND remove_transaction_id IS NULL");
 647+}
 648+
 649+function updateURLAttributeValue($url, $urlValueAttributeId) {
 650+ $urlValueAttribute = getURLValueAttribute($urlValueAttributeId);
 651+ removeURLAttributeValue($urlValueAttributeId);
 652+ createURLAttributeValue($urlValueAttribute->object_id, $urlValueAttribute->attribute_mid, $url, $urlValueAttributeId);
 653+}
 654+
 655+function getURLValueAttribute($urlValueAttributeId) {
 656+ $dbr = &wfGetDB(DB_SLAVE);
 657+ $queryResult = $dbr->query("SELECT object_id, attribute_mid, url FROM uw_url_attribute_values WHERE value_id=$urlValueAttributeId " .
 658+ " AND " . getLatestTransactionRestriction('uw_url_attribute_values'));
 659+
 660+ return $dbr->fetchObject($queryResult);
 661+}
 662+
631663 function createTranslatedTextAttributeValue($valueId, $objectId, $attributeId, $translatedContentId) {
632664 $dbr = &wfGetDB(DB_MASTER);
633665 $dbr->query("INSERT INTO uw_translated_content_attribute_values (value_id, object_id, attribute_mid, value_tcid, add_transaction_id) " .
Index: trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZAttributes.php
@@ -142,6 +142,16 @@
143143 $textAttributeAttribute = new Attribute("text-attribute", "Attribute", new RecordSetType($definedMeaningReferenceStructure));
144144 $textAttributeValuesStructure = new Structure($textAttributeIdAttribute, $textAttributeObjectAttribute, $textAttributeAttribute, $textAttribute, $objectAttributesAttribute);
145145 $textAttributeValuesAttribute = new Attribute("text-attribute-values", "Text attribute values", new RecordSetType($textAttributeValuesStructure));
 146+
 147+ global
 148+ $urlAttribute, $urlAttributeIdAttribute, $urlAttributeObjectAttribute, $urlAttributeAttribute, $urlAttributeValuesStructure, $urlAttributeValuesAttribute;
 149+
 150+ $urlAttribute = new Attribute("url", "URL", "url");
 151+ $urlAttributeIdAttribute = new Attribute("url-attribute-id", "Attribute identifier", "object-id");
 152+ $urlAttributeObjectAttribute = new Attribute("url-attribute-object-id", "Attribute object", "object-id");
 153+ $urlAttributeAttribute = new Attribute("url-attribute", "Attribute", new RecordSetType($definedMeaningReferenceStructure));
 154+ $urlAttributeValuesStructure = new Structure($urlAttributeIdAttribute, $urlAttributeObjectAttribute, $urlAttributeAttribute, $urlAttribute, $objectAttributesAttribute);
 155+ $urlAttributeValuesAttribute = new Attribute("url-attribute-values", "URL attribute values", new RecordSetType($urlAttributeValuesStructure));
146156
147157 global
148158 $optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionAttribute, $optionAttributeValuesAttribute;
Index: trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZEditors.php
@@ -13,6 +13,7 @@
1414 $synonymsAndTranslationsObjectAttributesEditor, $syntransIdAttribute,
1515 $relationsObjectAttributesEditor, $relationIdAttribute,
1616 $textValueObjectAttributesEditor, $textAttributeIdAttribute,
 17+ $urlValueObjectAttributesEditor, $urlAttributeIdAttribute,
1718 $translatedTextValueObjectAttributesEditor, $translatedTextAttributeIdAttribute,
1819 $optionValueObjectAttributesEditor, $optionAttributeIdAttribute,
1920 $definedMeaningMeaningName, $definitionMeaningName,
@@ -24,6 +25,7 @@
2526 $synonymsAndTranslationsObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
2627 $relationsObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
2728 $textValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
 29+ $urlValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
2830 $translatedTextValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
2931 $optionValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
3032
@@ -32,6 +34,7 @@
3335 setObjectAttributesEditor($synonymsAndTranslationsObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $syntransIdAttribute), $synTransMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
3436 setObjectAttributesEditor($relationsObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $relationIdAttribute), $relationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
3537 setObjectAttributesEditor($textValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $textAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
 38+ setObjectAttributesEditor($urlValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $textAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
3639 setObjectAttributesEditor($translatedTextValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $translatedTextAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
3740 setObjectAttributesEditor($optionValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $optionAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
3841 }
@@ -117,6 +120,7 @@
118121 function setObjectAttributesEditor($objectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, $objectIdFetcher, $levelDefinedMeaningName, $dmObjectIdFetcher) {
119122 $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new TextAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher));
120123 $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority, new TranslatedTextAttributeValuesController($objectIdFetcher, $filterLanguageId), $levelDefinedMeaningName, $dmObjectIdFetcher));
 124+ $objectAttributesEditor->addEditor(getURLAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new URLAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher));
121125 $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new OptionAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher));
122126 }
123127
@@ -252,6 +256,20 @@
253257 return $editor;
254258 }
255259
 260+function getURLAttributeValuesEditor($showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) {
 261+ global
 262+ $urlAttributeAttribute, $urlAttribute, $urlAttributeValuesAttribute, $urlValueObjectAttributesEditor;
 263+
 264+ $editor = new RecordSetTableEditor($urlAttributeValuesAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
 265+ $editor->addEditor(new TextAttributeEditor($urlAttributeAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
 266+ $editor->addEditor(new URLEditor($urlAttribute, new SimplePermissionController(true), true));
 267+ $editor->addEditor(new PopUpEditor($urlValueObjectAttributesEditor, 'Annotation'));
 268+
 269+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 270+
 271+ return $editor;
 272+}
 273+
256274 function getTranslatedTextAttributeValuesEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) {
257275 global
258276 $translatedTextAttributeAttribute, $translatedTextValueAttribute, $translatedTextAttributeValuesAttribute, $translatedTextValueObjectAttributesEditor;
Index: trunk/extensions/Wikidata/WiktionaryZ/Editor.php
@@ -864,7 +864,7 @@
865865 }
866866
867867 public function getEditHTML($idPath, $value) {
868 - return getTextBox($this->updateId($idPath->getId()), $value);
 868+ return getTextBox($this->updateId($idPath->getId()), $value);
869869 }
870870
871871 public function add($idPath) {
@@ -882,6 +882,17 @@
883883 }
884884 }
885885
 886+class URLEditor extends ShortTextEditor {
 887+ public function getViewHTML($idPath, $value) {
 888+ global
 889+ $escapedValue;
 890+
 891+ $escapedValue = htmlspecialchars($value);
 892+
 893+ return '<a href="' . $escapedValue . '">' . $escapedValue . '</a>';
 894+ }
 895+}
 896+
886897 class BooleanEditor extends ScalarEditor {
887898 protected $defaultValue;
888899
Index: trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZRecordSets.php
@@ -504,13 +504,16 @@
505505
506506 function getObjectAttributesRecord($objectId, $filterLanguageId, $queryTransactionInformation) {
507507 global
508 - $objectAttributesAttribute, $objectIdAttribute, $textAttributeValuesAttribute, $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute;
 508+ $objectAttributesAttribute, $objectIdAttribute,
 509+ $urlAttributeValuesAttribute, $textAttributeValuesAttribute,
 510+ $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute;
509511
510512 $record = new ArrayRecord($objectAttributesAttribute->type->getStructure());
511513
512514 $record->setAttributeValue($objectIdAttribute, $objectId);
513515 $record->setAttributeValue($textAttributeValuesAttribute, getTextAttributesValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
514516 $record->setAttributeValue($translatedTextAttributeValuesAttribute, getTranslatedTextAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
 517+ $record->setAttributeValue($urlAttributeValuesAttribute, getURLAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
515518 $record->setAttributeValue($optionAttributeValuesAttribute, getOptionAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
516519
517520 return $record;
@@ -763,6 +766,34 @@
764767 return $recordSet;
765768 }
766769
 770+function getURLAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) {
 771+ global
 772+ $urlAttributeValuesTable, $urlAttributeIdAttribute, $urlAttributeObjectAttribute,
 773+ $urlAttributeAttribute, $urlAttribute, $objectAttributesAttribute;
 774+
 775+ $recordSet = queryRecordSet(
 776+ $queryTransactionInformation,
 777+ $urlAttributeIdAttribute,
 778+ array(
 779+ 'value_id' => $urlAttributeIdAttribute,
 780+ 'object_id' => $urlAttributeObjectAttribute,
 781+ 'attribute_mid' => $urlAttributeAttribute,
 782+ 'url' => $urlAttribute
 783+ ),
 784+ $urlAttributeValuesTable,
 785+ array("object_id=$objectId")
 786+ );
 787+
 788+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($urlAttributeAttribute));
 789+
 790+ //add object attributes attribute to the generated structure
 791+ //and expand the records
 792+ $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
 793+ expandObjectAttributesAttribute($recordSet, $urlAttributeIdAttribute, $filterLanguageId, $queryTransactionInformation);
 794+
 795+ return $recordSet;
 796+}
 797+
767798 function getTranslatedTextAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) {
768799 global
769800 $translatedTextAttributeIdAttribute, $translatedContentAttributeValuesTable, $translatedTextAttributeAttribute,
Index: trunk/extensions/Wikidata/WiktionaryZ/WikiDataTables.php
@@ -15,7 +15,8 @@
1616 global
1717 $tables, $meaningRelationsTable, $classMembershipsTable, $collectionMembershipsTable, $syntransTable,
1818 $translatedContentTable, $alternativeDefinitionsTable, $translatedContentAttributeValuesTable, $transactionsTable,
19 - $textAttributeValuesTable, $optionAttributeOptionsTable, $optionAttributeValuesTable, $classAttributesTable;
 19+ $textAttributeValuesTable, $optionAttributeOptionsTable, $optionAttributeValuesTable, $classAttributesTable,
 20+ $urlAttributeValuesTable;
2021
2122 $transactionsTable = new Table('transactions', false, array('transaction_id'));
2223 $meaningRelationsTable = new Table('uw_meaning_relations', true, array('relation_id'));
@@ -28,6 +29,7 @@
2930
3031 $translatedContentAttributeValuesTable = new Table('uw_translated_content_attribute_values', true, array('value_id'));
3132 $textAttributeValuesTable = new Table('uw_text_attribute_values', true, array('value_id'));
 33+$urlAttributeValuesTable = new Table('uw_url_attribute_values', true, array('value_id'));
3234 $optionAttributeOptionsTable = new Table('uw_option_attribute_options', true, array('attribute_id', 'option_mid'));
3335 $optionAttributeValuesTable = new Table('uw_option_attribute_values', true, array('value_id'));
3436 $urlAttributeValuesTable = new Table('uw_url_attribute_values', true, array('value_id'));