Index: trunk/extensions/Wikidata/WiktionaryZ/Controller.php |
— | — | @@ -488,6 +488,38 @@ |
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
| 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 | + |
492 | 524 | class TranslatedTextAttributeValuesController extends ObjectAttributeValuesController { |
493 | 525 | protected $filterLanguageId; |
494 | 526 | |
Index: trunk/extensions/Wikidata/WiktionaryZ/Expression.php |
— | — | @@ -603,7 +603,7 @@ |
604 | 604 | function createTextAttributeValue($objectId, $textAttributeId, $text, $textValueAttributeId) { |
605 | 605 | $dbr = &wfGetDB(DB_MASTER); |
606 | 606 | $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() .")"); |
608 | 608 | } |
609 | 609 | |
610 | 610 | function removeTextAttributeValue($textValueAttributeId) { |
— | — | @@ -627,6 +627,38 @@ |
628 | 628 | return $dbr->fetchObject($queryResult); |
629 | 629 | } |
630 | 630 | |
| 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 | + |
631 | 663 | function createTranslatedTextAttributeValue($valueId, $objectId, $attributeId, $translatedContentId) { |
632 | 664 | $dbr = &wfGetDB(DB_MASTER); |
633 | 665 | $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 @@ |
143 | 143 | $textAttributeAttribute = new Attribute("text-attribute", "Attribute", new RecordSetType($definedMeaningReferenceStructure)); |
144 | 144 | $textAttributeValuesStructure = new Structure($textAttributeIdAttribute, $textAttributeObjectAttribute, $textAttributeAttribute, $textAttribute, $objectAttributesAttribute); |
145 | 145 | $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)); |
146 | 156 | |
147 | 157 | global |
148 | 158 | $optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionAttribute, $optionAttributeValuesAttribute; |
Index: trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZEditors.php |
— | — | @@ -13,6 +13,7 @@ |
14 | 14 | $synonymsAndTranslationsObjectAttributesEditor, $syntransIdAttribute, |
15 | 15 | $relationsObjectAttributesEditor, $relationIdAttribute, |
16 | 16 | $textValueObjectAttributesEditor, $textAttributeIdAttribute, |
| 17 | + $urlValueObjectAttributesEditor, $urlAttributeIdAttribute, |
17 | 18 | $translatedTextValueObjectAttributesEditor, $translatedTextAttributeIdAttribute, |
18 | 19 | $optionValueObjectAttributesEditor, $optionAttributeIdAttribute, |
19 | 20 | $definedMeaningMeaningName, $definitionMeaningName, |
— | — | @@ -24,6 +25,7 @@ |
25 | 26 | $synonymsAndTranslationsObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5); |
26 | 27 | $relationsObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5); |
27 | 28 | $textValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5); |
| 29 | + $urlValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5); |
28 | 30 | $translatedTextValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5); |
29 | 31 | $optionValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5); |
30 | 32 | |
— | — | @@ -32,6 +34,7 @@ |
33 | 35 | setObjectAttributesEditor($synonymsAndTranslationsObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $syntransIdAttribute), $synTransMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute)); |
34 | 36 | setObjectAttributesEditor($relationsObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $relationIdAttribute), $relationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute)); |
35 | 37 | 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)); |
36 | 39 | setObjectAttributesEditor($translatedTextValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $translatedTextAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute)); |
37 | 40 | setObjectAttributesEditor($optionValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $optionAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute)); |
38 | 41 | } |
— | — | @@ -117,6 +120,7 @@ |
118 | 121 | function setObjectAttributesEditor($objectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, $objectIdFetcher, $levelDefinedMeaningName, $dmObjectIdFetcher) { |
119 | 122 | $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new TextAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher)); |
120 | 123 | $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority, new TranslatedTextAttributeValuesController($objectIdFetcher, $filterLanguageId), $levelDefinedMeaningName, $dmObjectIdFetcher)); |
| 124 | + $objectAttributesEditor->addEditor(getURLAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new URLAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher)); |
121 | 125 | $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new OptionAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher)); |
122 | 126 | } |
123 | 127 | |
— | — | @@ -252,6 +256,20 @@ |
253 | 257 | return $editor; |
254 | 258 | } |
255 | 259 | |
| 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 | + |
256 | 274 | function getTranslatedTextAttributeValuesEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) { |
257 | 275 | global |
258 | 276 | $translatedTextAttributeAttribute, $translatedTextValueAttribute, $translatedTextAttributeValuesAttribute, $translatedTextValueObjectAttributesEditor; |
Index: trunk/extensions/Wikidata/WiktionaryZ/Editor.php |
— | — | @@ -864,7 +864,7 @@ |
865 | 865 | } |
866 | 866 | |
867 | 867 | public function getEditHTML($idPath, $value) { |
868 | | - return getTextBox($this->updateId($idPath->getId()), $value); |
| 868 | + return getTextBox($this->updateId($idPath->getId()), $value); |
869 | 869 | } |
870 | 870 | |
871 | 871 | public function add($idPath) { |
— | — | @@ -882,6 +882,17 @@ |
883 | 883 | } |
884 | 884 | } |
885 | 885 | |
| 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 | + |
886 | 897 | class BooleanEditor extends ScalarEditor { |
887 | 898 | protected $defaultValue; |
888 | 899 | |
Index: trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZRecordSets.php |
— | — | @@ -504,13 +504,16 @@ |
505 | 505 | |
506 | 506 | function getObjectAttributesRecord($objectId, $filterLanguageId, $queryTransactionInformation) { |
507 | 507 | global |
508 | | - $objectAttributesAttribute, $objectIdAttribute, $textAttributeValuesAttribute, $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute; |
| 508 | + $objectAttributesAttribute, $objectIdAttribute, |
| 509 | + $urlAttributeValuesAttribute, $textAttributeValuesAttribute, |
| 510 | + $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute; |
509 | 511 | |
510 | 512 | $record = new ArrayRecord($objectAttributesAttribute->type->getStructure()); |
511 | 513 | |
512 | 514 | $record->setAttributeValue($objectIdAttribute, $objectId); |
513 | 515 | $record->setAttributeValue($textAttributeValuesAttribute, getTextAttributesValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation)); |
514 | 516 | $record->setAttributeValue($translatedTextAttributeValuesAttribute, getTranslatedTextAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation)); |
| 517 | + $record->setAttributeValue($urlAttributeValuesAttribute, getURLAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation)); |
515 | 518 | $record->setAttributeValue($optionAttributeValuesAttribute, getOptionAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation)); |
516 | 519 | |
517 | 520 | return $record; |
— | — | @@ -763,6 +766,34 @@ |
764 | 767 | return $recordSet; |
765 | 768 | } |
766 | 769 | |
| 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 | + |
767 | 798 | function getTranslatedTextAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) { |
768 | 799 | global |
769 | 800 | $translatedTextAttributeIdAttribute, $translatedContentAttributeValuesTable, $translatedTextAttributeAttribute, |
Index: trunk/extensions/Wikidata/WiktionaryZ/WikiDataTables.php |
— | — | @@ -15,7 +15,8 @@ |
16 | 16 | global |
17 | 17 | $tables, $meaningRelationsTable, $classMembershipsTable, $collectionMembershipsTable, $syntransTable, |
18 | 18 | $translatedContentTable, $alternativeDefinitionsTable, $translatedContentAttributeValuesTable, $transactionsTable, |
19 | | - $textAttributeValuesTable, $optionAttributeOptionsTable, $optionAttributeValuesTable, $classAttributesTable; |
| 19 | + $textAttributeValuesTable, $optionAttributeOptionsTable, $optionAttributeValuesTable, $classAttributesTable, |
| 20 | + $urlAttributeValuesTable; |
20 | 21 | |
21 | 22 | $transactionsTable = new Table('transactions', false, array('transaction_id')); |
22 | 23 | $meaningRelationsTable = new Table('uw_meaning_relations', true, array('relation_id')); |
— | — | @@ -28,6 +29,7 @@ |
29 | 30 | |
30 | 31 | $translatedContentAttributeValuesTable = new Table('uw_translated_content_attribute_values', true, array('value_id')); |
31 | 32 | $textAttributeValuesTable = new Table('uw_text_attribute_values', true, array('value_id')); |
| 33 | +$urlAttributeValuesTable = new Table('uw_url_attribute_values', true, array('value_id')); |
32 | 34 | $optionAttributeOptionsTable = new Table('uw_option_attribute_options', true, array('attribute_id', 'option_mid')); |
33 | 35 | $optionAttributeValuesTable = new Table('uw_option_attribute_values', true, array('value_id')); |
34 | 36 | $urlAttributeValuesTable = new Table('uw_url_attribute_values', true, array('value_id')); |