diff --git a/extensions/wikidata/module/langs/translation-en.json b/extensions/wikidata/module/langs/translation-en.json index a2c6b8191..50be8999a 100644 --- a/extensions/wikidata/module/langs/translation-en.json +++ b/extensions/wikidata/module/langs/translation-en.json @@ -23,6 +23,9 @@ "wikidata-schema/add-statement": "add statement", "wikidata-schema/add-value": "add value", "wikidata-schema/add-qualifier": "add qualifier", + "wikidata-schema/copy-reference": "copy", + "wikidata-schema/paste-reference": "paste reference", + "wikidata-schema/reference-copied": "copied", "wikidata-schema/add-reference": "add reference", "wikidata-schema/add-reference-snak": "add", "wikidata-schema/property-placeholder": "property", @@ -146,4 +149,4 @@ "warnings-messages/no-unit-provided/body": "Values such as {example_value} on {example_item_entity} are expected to have units.", "warnings-messages/invalid-entity-type/title": "{property_entity} used on items", "warnings-messages/invalid-entity-type/body": "Uses of {property_entity} on items such as {example_entity} are invalid." -} \ No newline at end of file +} diff --git a/extensions/wikidata/module/langs/translation-fr.json b/extensions/wikidata/module/langs/translation-fr.json index 0280f78fe..2924caee2 100644 --- a/extensions/wikidata/module/langs/translation-fr.json +++ b/extensions/wikidata/module/langs/translation-fr.json @@ -20,6 +20,9 @@ "wikidata-schema/add-statement": "ajouter une déclaration", "wikidata-schema/add-value": "ajouter une valeur", "wikidata-schema/add-qualifier": "ajouter un qualificatif", + "wikidata-schema/copy-reference": "copier", + "wikidata-schema/paste-reference": "coller une référence", + "wikidata-schema/reference-copied": "copiée", "wikidata-schema/add-reference": "ajouter une référence", "wikidata-schema/add-reference-snak": "ajouter", "wikidata-schema/property-placeholder": "propriété", @@ -139,4 +142,4 @@ "warnings-messages/no-unit-provided/body": "Des valeurs telles que {example_value} sur {example_item_entity} devraient avoir des unités.", "warnings-messages/invalid-entity-type/title": "{property_entity} utilisée sur des éléments", "warnings-messages/invalid-entity-type/body": "Les utilisations de {property_entity} sur des éléments tels que {example_entity} sont invalides." -} \ No newline at end of file +} diff --git a/extensions/wikidata/module/scripts/dialogs/schema-alignment-dialog.js b/extensions/wikidata/module/scripts/dialogs/schema-alignment-dialog.js index f9a1ebc8b..cc3770773 100644 --- a/extensions/wikidata/module/scripts/dialogs/schema-alignment-dialog.js +++ b/extensions/wikidata/module/scripts/dialogs/schema-alignment-dialog.js @@ -244,12 +244,18 @@ SchemaAlignmentDialog._reset = function(schema) { if (!this._schema.itemDocuments.length) { // this._addItem(); } + + this._copiedReference = null; }; SchemaAlignmentDialog._save = function(onDone) { var self = this; var schema = this.getJSON(); + if (schema === null) { + alert($.i18n('wikidata-schema/incomplete-schema-could-not-be-saved')); + } + Refine.postProcess( "wikidata", "save-wikibase-schema", @@ -394,17 +400,32 @@ SchemaAlignmentDialog._addItem = function(json) { SchemaAlignmentDialog._itemToJSON = function (item) { var statementGroupLst = new Array(); - item.find('.wbs-statement-group').each(function () { - statementGroupLst.push(SchemaAlignmentDialog._statementGroupToJSON($(this))); + var statementsDom = item.find('.wbs-statement-group'); + statementsDom.each(function () { + var statementGroupJSON = SchemaAlignmentDialog._statementGroupToJSON($(this)); + if (statementGroupJSON !== null) { + statementGroupLst.push(statementGroupJSON); + } }); var nameDescLst = new Array(); - item.find('.wbs-namedesc').each(function () { - nameDescLst.push(SchemaAlignmentDialog._nameDescToJSON($(this))); + var nameDescsDom = item.find('.wbs-namedesc'); + nameDescsDom.each(function () { + var nameDescJSON = SchemaAlignmentDialog._nameDescToJSON($(this)); + if (nameDescJSON !== null) { + nameDescLst.push(nameDescJSON); + } }); var inputContainer = item.find(".wbs-item-input").first(); - return {subject: SchemaAlignmentDialog._inputContainerToJSON(inputContainer), + var subjectJSON = SchemaAlignmentDialog._inputContainerToJSON(inputContainer); + if (subjectJSON !== null && + statementGroupLst.length === statementsDom.length && + nameDescLst.length === nameDescsDom.length) { + return {subject: subjectJSON, statementGroups: statementGroupLst, nameDescs: nameDescLst}; + } else { + return null; + } }; /************************** @@ -513,12 +534,21 @@ SchemaAlignmentDialog._addStatementGroup = function(item, json) { SchemaAlignmentDialog._statementGroupToJSON = function (statementGroup) { var lst = new Array(); - statementGroup.find('.wbs-statement-container').first().children('.wbs-statement').each(function () { - lst.push(SchemaAlignmentDialog._statementToJSON($(this))); + var domStatements = statementGroup.find('.wbs-statement-container').first().children('.wbs-statement'); + domStatements.each(function () { + var statementJSON = SchemaAlignmentDialog._statementToJSON($(this)); + if (statementJSON !== null) { + lst.push(statementJSON); + } }); var inputContainer = statementGroup.find(".wbs-prop-input").first(); - return {property: SchemaAlignmentDialog._inputContainerToJSON(inputContainer), - statements: lst}; + var propertyJSON = SchemaAlignmentDialog._inputContainerToJSON(inputContainer); + if (propertyJSON !== null && domStatements.length === lst.length && lst.length > 0) { + return {property: propertyJSON, + statements: lst}; + } else { + return null; + } }; /************** @@ -593,6 +623,28 @@ SchemaAlignmentDialog._addStatement = function(container, datatype, json) { e.preventDefault(); }).appendTo(toolbar3); SchemaAlignmentDialog._plusButton($.i18n('wikidata-schema/add-reference'), addReferenceButton); + + var pasteToolbar = $('
').addClass('wbs-toolbar').appendTo(referencesToggleContainer); + var referencePaste = $('') + .addClass('wbs-paste-reference') + .appendTo(pasteToolbar) + .hide(); + var pasteIcon = $('').addClass('wbs-icon').appendTo(referencePaste); + var referencePasteButton = $('') + .addClass('wbs-paste-reference-button') + .text($.i18n('wikidata-schema/paste-reference')) + .appendTo(referencePaste) + .click(function(e) { + if (SchemaAlignmentDialog._copiedReference !== null) { + SchemaAlignmentDialog._addReference(referenceContainer, SchemaAlignmentDialog._copiedReference); + SchemaAlignmentDialog._updateReferencesNumber(referenceContainer); + referencePaste.hide(); + SchemaAlignmentDialog._hasChanged(); + } + e.preventDefault(); + e.stopPropagation(); + }); + if (references) { for (var i = 0; i != references.length; i++) { SchemaAlignmentDialog._addReference(referenceContainer, references[i]); @@ -607,17 +659,32 @@ SchemaAlignmentDialog._statementToJSON = function (statement) { var inputContainer = statement.find(".wbs-target-input").first(); var qualifiersList = new Array(); var referencesList = new Array(); - statement.find('.wbs-qualifier-container').first().children().each(function () { - qualifiersList.push(SchemaAlignmentDialog._qualifierToJSON($(this))); + var qualifiersDom = statement.find('.wbs-qualifier-container').first().children(); + qualifiersDom.each(function () { + var qualifierJSON = SchemaAlignmentDialog._qualifierToJSON($(this)); + if (qualifierJSON !== null) { + qualifiersList.push(qualifierJSON); + } }); - statement.find('.wbs-reference-container').first().children().each(function () { - referencesList.push(SchemaAlignmentDialog._referenceToJSON($(this))); + var referencesDom = statement.find('.wbs-reference-container').first().children(); + referencesDom.each(function () { + var referenceJSON = SchemaAlignmentDialog._referenceToJSON($(this)); + if (referenceJSON !== null) { + referencesList.push(referenceJSON); + } }); - return { - value:SchemaAlignmentDialog._inputContainerToJSON(inputContainer), + var valueJSON = SchemaAlignmentDialog._inputContainerToJSON(inputContainer); + if (referencesList.length === referencesDom.length && + qualifiersList.length === qualifiersDom.length && + valueJSON !== null) { + return { + value: valueJSON, qualifiers: qualifiersList, references: referencesList, - }; + }; + } else { + return null; + } }; /************** @@ -655,10 +722,16 @@ SchemaAlignmentDialog._addQualifier = function(container, json) { SchemaAlignmentDialog._qualifierToJSON = function(elem) { var prop = elem.find(".wbs-prop-input").first(); var target = elem.find(".wbs-target-input").first(); - return { - prop: SchemaAlignmentDialog._inputContainerToJSON(prop), - value: SchemaAlignmentDialog._inputContainerToJSON(target), - }; + var propJSON = SchemaAlignmentDialog._inputContainerToJSON(prop); + var valueJSON = SchemaAlignmentDialog._inputContainerToJSON(target); + if (propJSON !== null && valueJSON !== null) { + return { + prop: propJSON, + value: valueJSON, + }; + } else { + return null; + } } /************** @@ -673,6 +746,20 @@ SchemaAlignmentDialog._addReference = function(container, json) { var reference = $('
').addClass('wbs-reference').appendTo(container); var referenceHeader = $('
').addClass('wbs-reference-header').appendTo(reference); + var referenceCopy = $('').addClass('wbs-copy-reference').appendTo(referenceHeader); + var referenceCopyIcon = $('').addClass('wbs-icon').appendTo(referenceCopy); + var copyButton = $('') + .addClass('wbs-copy-reference-button') + .text($.i18n('wikidata-schema/copy-reference')) + .appendTo(referenceCopy) + .click(function(e) { + if (SchemaAlignmentDialog._copyReference(reference)) { + $(this).text($.i18n('wikidata-schema/reference-copied')) + .parent().addClass('wbs-copied-reference'); + container.parent().parent().find('.wbs-paste-reference').hide(); + } + e.preventDefault(); + }); var toolbarRef = $('
').addClass('wbs-toolbar').appendTo(referenceHeader); SchemaAlignmentDialog._makeDeleteButton().click(function(e) { reference.remove(); @@ -703,9 +790,16 @@ SchemaAlignmentDialog._referenceToJSON = function(reference) { var snaks = reference.find('.wbs-qualifier-container').first().children(); var snaksList = new Array(); snaks.each(function () { - snaksList.push(SchemaAlignmentDialog._qualifierToJSON($(this))); + var qualifier = SchemaAlignmentDialog._qualifierToJSON($(this)); + if (qualifier !== null) { + snaksList.push(qualifier); + } }); - return {snaks:snaksList}; + if (snaksList.length === snaks.length) { + return {snaks:snaksList}; + } else { + return null; + } } SchemaAlignmentDialog._updateReferencesNumber = function(container) { @@ -715,6 +809,22 @@ SchemaAlignmentDialog._updateReferencesNumber = function(container) { a.html(childrenCount+$.i18n('wikidata-schema/nb-references')); } +SchemaAlignmentDialog._copyReference = function(reference) { + // mark any other copied reference as not copied + $('.wbs-copy-reference-button') + .text($.i18n('wikidata-schema/copy-reference')); + $('.wbs-copy-reference') + .removeClass('wbs-copied-reference'); + var copiedReference = SchemaAlignmentDialog._referenceToJSON(reference); + if (copiedReference !== null) { + SchemaAlignmentDialog._copiedReference = copiedReference; + $('.wbs-paste-reference').show(); + return true; + } else { + return false; + } +} + /************************ * FIELD INITIALIZATION * ************************/ @@ -1076,7 +1186,7 @@ SchemaAlignmentDialog.setupStringInputValidation = function(input, regex) { SchemaAlignmentDialog._inputContainerToJSON = function (inputContainer) { var data = inputContainer.data(); - if (data) { + if (data && 'jsonValue' in data) { return data.jsonValue; } else { return null; @@ -1095,13 +1205,21 @@ SchemaAlignmentDialog._removeStatement = function(statement) { SchemaAlignmentDialog.getJSON = function() { var list = new Array(); - $('#schema-alignment-statements-container .wbs-item').each(function () { - list.push(SchemaAlignmentDialog._itemToJSON($(this))); + var itemsDom = $('#schema-alignment-statements-container .wbs-item'); + itemsDom.each(function () { + var itemJSON = SchemaAlignmentDialog._itemToJSON($(this)); + if (itemJSON !== null) { + list.push(itemJSON); + } }); - return { + if (list.length === itemsDom.length) { + return { 'itemDocuments': list, 'wikibasePrefix': this._wikibasePrefix, - }; + }; + } else { + return null; + } }; SchemaAlignmentDialog._hasChanged = function() { @@ -1130,6 +1248,10 @@ SchemaAlignmentDialog.preview = function() { this.issueSpinner.show(); this.previewSpinner.show(); var schema = this.getJSON(); + if (schema === null) { + $('.invalid-schema-warning').show(); + return; + } $.post( "command/wikidata/preview-wikibase-schema?" + $.param({ project: theProject.id }), { schema: JSON.stringify(schema), engine: JSON.stringify(ui.browsingEngine.getJSON()) }, diff --git a/extensions/wikidata/module/styles/dialogs/schema-alignment-dialog.css b/extensions/wikidata/module/styles/dialogs/schema-alignment-dialog.css index 03561fede..2ae8fa79d 100644 --- a/extensions/wikidata/module/styles/dialogs/schema-alignment-dialog.css +++ b/extensions/wikidata/module/styles/dialogs/schema-alignment-dialog.css @@ -143,6 +143,7 @@ opacity: 0.7; } + .wbs-remove .wbs-icon { background-image:linear-gradient(transparent,transparent),url("data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%2224%22%20height=%2224%22%20viewBox=%220%200%2024%2024%22%3E%20%3Cg%20id=%22remove%22%3E%20%3Cpath%20id=%22trash-can%22%20d=%22M12%2010h-1v6h1v-6zm-2%200H9v6h1v-6zm4%200h-1v6h1v-6zm0-4V5H9v1H6v3h1v7.966l1%201.03v-.073V18h6.984l.016-.018v.015l1-1.03V9h1V6h-3zm1%2011H8V9h7v8zm1-9H7V7h9v1z%22/%3E%20%3C/g%3E%20%3C/svg%3E"); } @@ -211,7 +212,8 @@ .wbs-remove, .wbs-add-item, .wbs-add-statement-group, .wbs-add-statement, -.wbs-add-qualifier, .wbs-add-reference, .wbs-add-namedesc { +.wbs-add-qualifier, .wbs-add-reference, .wbs-add-namedesc, +.wbs-copy-reference-button, .wbs-paste-reference-button { color: #0645ad !important; font-size: 0.9em; cursor: pointer; @@ -250,6 +252,10 @@ color: gray; } +.schema-alignment-dialog-preview .wbs-prop-input { + float: left; +} + .schema-alignment-dialog-preview .wbs-qualifier .wbs-statement-container { display: table-cell; vertical-align: bottom; @@ -303,7 +309,7 @@ .wbs-qualifier, .wbs-reference { position: relative; - overflow-x: hidden; + overflow: hidden; } .wbs-qualifier .wbs-right { @@ -318,14 +324,50 @@ } .wbs-references-toggle { - width: 12em; margin: 5px; + margin-right: 0px; } .wbs-references-toggle a { color: #0645ad !important; } +.wbs-copy-reference { + float: left; + padding: 2px; +} + +.wbs-copied-reference { + opacity: 0.6; +} + +.wbs-copied-reference .wbs-copy-reference-button { + color: black !important; + cursor: default; +} + +.wbs-copied-reference span:hover { + text-decoration: none; +} + +.wbs-paste-reference .wbs-icon, +.wbs-copy-reference .wbs-icon { + height: 13px; + width: 13px; + background-size: 13px 13px; + opacity: 0.6; + margin-right: 2px; +} + +/* source: Font Awesome by Dave Gandy. https://commons.wikimedia.org/wiki/File:Paste_font_awesome.svg */ +.wbs-paste-reference .wbs-icon { + background-image: url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg version='1.1' viewBox='0 -256 1900 1900' xmlns='http://www.w3.org/2000/svg' xmlns:cc='http://creativecommons.org/ns%23' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23'%3E%3Cmetadata%3E%3Crdf:RDF%3E%3Ccc:Work rdf:about=''%3E%3Cdc:format%3Eimage/svg+xml%3C/dc:format%3E%3Cdc:type rdf:resource='http://purl.org/dc/dcmitype/StillImage'/%3E%3C/cc:Work%3E%3C/rdf:RDF%3E%3C/metadata%3E%3Cg transform='matrix(1 0 0 -1 53.153 1325.1)'%3E%3Cpath d='m768-128h896v640h-416q-40 0-68 28t-28 68v416h-384v-1152zm256 1440v64q0 13-9.5 22.5t-22.5 9.5h-704q-13 0-22.5-9.5t-9.5-22.5v-64q0-13 9.5-22.5t22.5-9.5h704q13 0 22.5 9.5t9.5 22.5zm256-672h299l-299 299v-299zm512-128v-672q0-40-28-68t-68-28h-960q-40 0-68 28t-28 68v160h-544q-40 0-68 28t-28 68v1344q0 40 28 68t68 28h1088q40 0 68-28t28-68v-328q21-13 36-28l408-408q28-28 48-76t20-88z' fill='currentColor'/%3E%3C/g%3E%3C/svg%3E%0A"); +} + +/* source: Font Awesome by Dave Gandy. https://commons.wikimedia.org/wiki/File:Copy_font_awesome.svg */ +.wbs-copy-reference .wbs-icon { + background-image: url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg version='1.1' viewBox='0 -256 1850 1850' xmlns='http://www.w3.org/2000/svg' xmlns:cc='http://creativecommons.org/ns%23' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns%23'%3E%3Cmetadata%3E%3Crdf:RDF%3E%3Ccc:Work rdf:about=''%3E%3Cdc:format%3Eimage/svg+xml%3C/dc:format%3E%3Cdc:type rdf:resource='http://purl.org/dc/dcmitype/StillImage'/%3E%3C/cc:Work%3E%3C/rdf:RDF%3E%3C/metadata%3E%3Cg transform='matrix(1 0 0 -1 37.966 1305.5)'%3E%3Cpath d='m1696 1152q40 0 68-28t28-68v-1216q0-40-28-68t-68-28h-960q-40 0-68 28t-28 68v288h-544q-40 0-68 28t-28 68v672q0 40 20 88t48 76l408 408q28 28 76 48t88 20h416q40 0 68-28t28-68v-328q68 40 128 40h416zm-544-213-299-299h299v299zm-640 384-299-299h299v299zm196-647 316 316v416h-384v-416q0-40-28-68t-68-28h-416v-640h512v256q0 40 20 88t48 76zm956-804v1152h-384v-416q0-40-28-68t-68-28h-416v-640h896z' fill='currentColor'/%3E%3C/g%3E%3C/svg%3E"); +} .wbs-references-toggle .triangle-icon { background: transparent url(data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%20standalone%3D%22no%22%3F%3E%0A%3Csvg%0A%20%20%20xmlns%3Adc%3D%22http%3A//purl.org/dc/elements/1.1/%22%0A%20%20%20xmlns%3Acc%3D%22http%3A//creativecommons.org/ns%23%22%0A%20%20%20xmlns%3Ardf%3D%22http%3A//www.w3.org/1999/02/22-rdf-syntax-ns%23%22%0A%20%20%20xmlns%3Asvg%3D%22http%3A//www.w3.org/2000/svg%22%0A%20%20%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%0A%20%20%20id%3D%22svg8%22%0A%20%20%20version%3D%221.1%22%0A%20%20%20viewBox%3D%220%200%202.6458332%202.6458332%22%0A%20%20%20height%3D%2210%22%0A%20%20%20width%3D%2210%22%3E%0A%20%20%3Cdefs%0A%20%20%20%20%20id%3D%22defs2%22%20/%3E%0A%20%20%3Cmetadata%0A%20%20%20%20%20id%3D%22metadata5%22%3E%0A%20%20%20%20%3Crdf%3ARDF%3E%0A%20%20%20%20%20%20%3Ccc%3AWork%0A%20%20%20%20%20%20%20%20%20rdf%3Aabout%3D%22%22%3E%0A%20%20%20%20%20%20%20%20%3Cdc%3Aformat%3Eimage/svg+xml%3C/dc%3Aformat%3E%0A%20%20%20%20%20%20%20%20%3Cdc%3Atype%0A%20%20%20%20%20%20%20%20%20%20%20rdf%3Aresource%3D%22http%3A//purl.org/dc/dcmitype/StillImage%22%20/%3E%0A%20%20%20%20%20%20%20%20%3Cdc%3Atitle%3E%3C/dc%3Atitle%3E%0A%20%20%20%20%20%20%3C/cc%3AWork%3E%0A%20%20%20%20%3C/rdf%3ARDF%3E%0A%20%20%3C/metadata%3E%0A%20%20%3Cg%0A%20%20%20%20%20transform%3D%22translate%280%2C-294.35416%29%22%0A%20%20%20%20%20id%3D%22layer1%22%3E%0A%20%20%20%20%3Cpath%0A%20%20%20%20%20%20%20id%3D%22path12%22%0A%20%20%20%20%20%20%20d%3D%22m%200.21601809%2C294.5035%202.28763941%2C1.14744%20-2.29850705%2C1.20871%20z%22%0A%20%20%20%20%20%20%20style%3D%22fill%3A%23645eea%3Bfill-opacity%3A1%3Bfill-rule%3Aevenodd%3Bstroke%3A%23645eea%3Bstroke-width%3A0.06161711px%3Bstroke-linecap%3Abutt%3Bstroke-linejoin%3Amiter%3Bstroke-opacity%3A1%22%20/%3E%0A%20%20%3C/g%3E%0A%3C/svg%3E%0A) no-repeat center center;