MediaWiki talk:Gadget-DuplicateReferences.js
Qualifiers edit
The script deletes qualifiers when a reference is added. Please fix this. Thibaut120094 (talk) 12:12, 30 November 2015 (UTC)
- Added to Phabricator. Sjoerd de Bruin (talk) 12:13, 14 December 2015 (UTC)
Fix edit
{{Editprotected}}
To fix Wikidata:Project chat#Copy reference, the click handler in addCopyLinks
should be like this:
function ( e ) { e.preventDefault(); var $this = $( this ), $parent = $( this ).parent(); if ( !$parent.hasClass( 'wikibase-toolbarbutton-disabled' ) ) { $( '.wikibase-toolbar-button-copy' ) .removeClass( 'wikibase-toolbarbutton-disabled ui-state-disabled' ) .find( 'a' ) .text( mw.msg( 'copy' ) ) .prepend( $( '<span> ').addClass( 'wb-icon' ) ); $parent.addClass( 'wikibase-toolbarbutton-disabled ui-state-disabled' ); $this.text( mw.msg( 'copied' ) ).prepend( $( '<span> ').addClass( 'wb-icon' ) ); var hash = $this.closest( '.wikibase-referenceview' )[0].className.match(/wikibase-referenceview-([0-9a-z]+)/)[1]; var statement = $this.closest( '.wikibase-statementview' ).data( 'wikibase-statementview' ).value(); selectReference( statement.getReferences().toArray().filter( function(v) { return v.getHash() === hash } )[ 0 ] ); } }
And selectReference
like this.
function selectReference( ref ) { selectedReference = ref; selectedReference._hash = null; // set hash to null to create a new reference if ( $( '.wikibase-toolbar-button-insert' ).length === 0 ) { addInsertLinks(); } }
Thanks, Adrian Heine (WMDE) (talk) 11:29, 6 April 2016 (UTC)
{{Editprotected}}
Sorry, the fix wasn't applied correctly. This is the full page text:
/** * Adds a link to copy references and add them to other statements on the same item. * * @see [[MediaWiki:Gadget-DuplicateReferences.css]] * @author Bene* */ ( function ( $, mw ) { 'use strict'; if ( mw.config.get( 'wbEntity' ) === null ) { return; } switch ( mw.config.get( 'wgUserLanguage' ) ) { default: case 'en': mw.messages.set( { 'insert-reference': 'insert reference', 'copy': 'copy', 'saving': 'saving', 'copied': 'copied', 'insert-reference-failed': 'The reference could not be inserted.' } ); break; case 'de': mw.messages.set( { 'insert-reference': 'Einzelnachweis einfügen', 'copy': 'kopieren', 'saving': 'speichern', 'copied': 'kopiert', 'insert-reference-failed': 'Der Einzelnachweis konnte nicht eingefügt werden.' } ); break; case 'fr': mw.messages.set( { 'insert-reference': 'coller la référence', 'copy': 'copier', 'saving': 'enregistrement', 'copied': 'copiée', 'insert-reference-failed': 'La référence ne peut pas être collée.' } ); break; case 'nl': mw.messages.set( { 'insert-reference': 'bron invoegen', 'copy': 'kopiëren', 'saving': 'opslaan', 'copied': 'gekopieerd', 'insert-reference-failed': 'De bron kon niet ingevoegd worden.' } ); break; case 'it': mw.messages.set( { 'insert-reference': 'incolla riferimento', 'copy': 'copia', 'saving': 'copia in corso', 'copied': 'copiato', 'insert-reference-failed': 'il riferimento non può essere copiato' } ); break; } var selectedReference = null; function insertReference( statementview ) { var deferred = $.Deferred(); if ( selectedReference !== null ) { // hack: make stamentview create the qualifiers listview // (https://phabricator.wikimedia.org/T121385) statementview._stopEditingQualifiers(); var statement = statementview.value(); statement.getReferences().addItem( selectedReference ); statementview.options.claimsChanger.setStatement( statement ).done( function ( statement ) { var references = statement.getReferences()._items; // assume we added the reference to the end statementview._addReference( references[references.length - 1] ); deferred.resolve(); } ).fail( function ( error ) { mw.notify( error.getMessage(), { title: mw.msg( 'insert-reference-failed' ), type: 'error' } ); deferred.resolve(); } ); } return deferred.promise(); } function selectReference( ref ) { selectedReference = ref; selectedReference._hash = null; // set hash to null to create a new reference if ( $( '.wikibase-toolbar-button-insert' ).length === 0 ) { addInsertLinks(); } } function addInsertLinks() { // [insert reference] $( '.wikibase-statementview-references .wikibase-toolbar-button-add' ).after( $( '<span>' ) .addClass( 'wikibase-toolbarbutton wikibase-toolbar-item wikibase-toolbar-button wikibase-toolbar-button-insert' ) .append( $( '<a>' ) .attr( 'href', '#' ) .text( mw.msg( 'insert-reference' ) ) .prepend( $( '<span> ').addClass( 'wb-icon' ) ) .click( function ( e ) { e.preventDefault(); var $this = $( this ), $parent = $this.parent(); if ( !$parent.hasClass( 'wikibase-toolbarbutton-disabled' ) ) { $parent.addClass( 'wikibase-toolbarbutton-disabled ui-state-disabled' ); $this.text( mw.msg( 'saving' ) ).prepend( $( '<span> ').addClass( 'wb-icon' ) ); var statementview = $this.parents( '.wikibase-statementview' ).data( 'statementview' ); insertReference( statementview ).done( function() { $parent.removeClass( 'wikibase-toolbarbutton-disabled ui-state-disabled' ); $this.text( mw.msg( 'insert-reference' ) ).prepend( $( '<span> ').addClass( 'wb-icon' ) ) } ); } } ) ) ); } function addCopyLinks( element ) { // [copy] $( element ).find( '.wikibase-referenceview-heading' ).append( $( '<div>' ) .addClass( 'wikibase-copytoolbar-container wikibase-toolbar-container' ) .append( $( '<span>' ) .addClass( 'wikibase-toolbarbutton wikibase-toolbar-item wikibase-toolbar-button wikibase-toolbar-button-copy' ) .append( $( '<a>' ) .attr( 'href', '#' ) .text( mw.msg( 'copy' ) ) .prepend( $( '<span> ').addClass( 'wb-icon' ) ) .click( function ( e ) { e.preventDefault(); var $this = $( this ), $parent = $this.parent(); if ( !$parent.hasClass( 'wikibase-toolbarbutton-disabled' ) ) { $( '.wikibase-toolbar-button-copy' ) .removeClass( 'wikibase-toolbarbutton-disabled ui-state-disabled' ) .find( 'a' ) .text( mw.msg( 'copy' ) ) .prepend( $( '<span> ').addClass( 'wb-icon' ) ); $parent.addClass( 'wikibase-toolbarbutton-disabled ui-state-disabled' ); $this.text( mw.msg( 'copied' ) ).prepend( $( '<span> ').addClass( 'wb-icon' ) ); var hash = $this.closest( '.wikibase-referenceview' )[0].className.match(/wikibase-referenceview-([0-9a-z]+)/)[1]; var statement = $this.closest( '.wikibase-statementview' ).data( 'wikibase-statementview' ).value(); selectReference( statement.getReferences().toArray().filter( function(v) { return v.getHash() === hash } )[ 0 ] ); } } ) ) ) ); } $( function() { addCopyLinks( '.wikibase-statementview' ); // remove [copy] when entering edit mode to avoid clashes $( document ) .on( 'click', '.wikibase-statementview .wikibase-toolbar-button-edit, .wikibase-statementview .wikibase-toolbar-button-add', function() { $( this ).parents( '.wikibase-statementview' ).find( '.wikibase-copytoolbar-container' ).remove(); } ) .on( 'snakviewafterstopediting', function( e ) { var element = $( e.target ).parents( '.wikibase-statementview' ); // ugly hack but there seems to be no proper event to add this setTimeout( function() { addCopyLinks( element ); }, 50 ); } ); } ); } )( jQuery, mediaWiki );
Thanks again, Adrian Heine (WMDE) (talk) 11:14, 7 April 2016 (UTC)
- @Adrian Heine (WMDE): Done ... but it still doesn't seem to work :/ I get "Uncaught TypeError: Cannot read property 'value' of null" whenever I try to insert a copied reference. - Nikki (talk) 12:24, 12 April 2016 (UTC)
{{Editprotected}}
Ok, the following patch resulted in a script that worked for me:
@@ -69,16 +69,14 @@ var deferred = $.Deferred(); if ( selectedReference !== null ) { - // hack: make stamentview create the qualifiers listview - // (https://phabricator.wikimedia.org/T121385) - statementview._stopEditingQualifiers(); var statement = statementview.value(); statement.getReferences().addItem( selectedReference ); statementview.options.claimsChanger.setStatement( statement ).done( function ( statement ) { - var references = statement.getReferences()._items; - // assume we added the reference to the end - statementview._addReference( references[references.length - 1] ); + var options = statementview.options; + options.value = statement; + statementview.destroy(); + $( '<div/>' ).replaceAll( statementview.element ).statementview( options ); deferred.resolve(); } ).fail( function ( error ) { mw.notify( error.getMessage(), {
Thanks, Adrian Heine (WMDE) (talk) 08:01, 13 April 2016 (UTC)
- @Adrian Heine (WMDE): Done - and it seems to finally work :D - Nikki (talk) 08:32, 13 April 2016 (UTC)
Macedonian (mk) version edit
{{Editprotected}}
Hello. Can someone add this for Macedonian. Thanks a lot. --B. Jankuloski (talk) 20:54, 18 July 2016 (UTC)
case 'mk': mw.messages.set( { 'insert-reference': 'вметни навод', 'copy': 'копирај', 'saving': 'зачувувам', 'copied': 'ископирано', 'insert-reference-failed': 'Не можев да го вметнам наводот.' } ); break;
Not working with the August 2016 deployment edit
{{Edit request}}
A quick hack that might help getting this back to work is replacing statementview.options.claimsChanger.setStatement
with statementview._controller._model.save
. But note that this accesses private properties and may break any time again. --Thiemo Mättig (WMDE) 14:50, 5 August 2016 (UTC)
Not working on September 13 (for a few days) edit
Hi, For a few days now, the gadget has ceased working.
When you copy a reference, all seems ok, but when you insert it to another statement, the tool displays a message "saving" ("enregistrement" in French) and nothing else happens. when refreshing the page, the ref is not copied.
Thnaks for fixing this very useful tool. --Hsarrazin (talk) 18:55, 13 September 2016 (UTC)
- I have the same problem - is this being worked on? Waggers (talk) 09:58, 16 September 2016 (UTC)
- The gadget should be working again. Sjoerd de Bruin (talk) 09:38, 21 September 2016 (UTC)
Greek (el) version edit
Hello. Can someone add this for Greek. @Sjoerddebruin:. Thanks a lot. Xaris333 (talk) 23:45, 7 November 2016 (UTC)
case 'el': mw.messages.set( { 'insert-reference': 'προσθήκη παραπομπής', 'copy': 'αντιγραφή', 'saving': 'αποθηκεύεται', 'copied': 'αντιγράφτηκε', 'insert-reference-failed': 'αποτυχημένη προσθήκη παραπομπής.' } ); break;
Polish (pl) version edit
Please insert this code. Sp5uhe (talk) 06:37, 6 February 2017 (UTC)
case 'pl': mw.messages.set( { 'insert-reference': 'wstaw odniesienie', 'copy': 'kopiuj', 'saving': 'zapisywanie', 'copied': 'skopiowano', 'insert-reference-failed': 'Odniesienie nie mogło zostać wstawione.' } ); break;
Fix re-select the reference edit
The statement,
selectedReference._hash = null; // set hash to null to create a new reference
in function selectReference() should be moved to, function insertReference() like this,
if ( selectedReference !== null ) { var statement = statementview.value(); selectedReference._hash = null; // set hash to null to create a new reference statement.getReferences().addItem( selectedReference );
else, the reference can't be re-select. Click "copy" to select reference A, then select reference B, then select reference A again, it will show error "selectedReference is not defined" in javascript console, since it cannot find the reference A by its hash, because its hash is null.
please fix the need to reload an item to be able to apply copied ref edit
Hi,
Before, this was working ok, but for months now, when you add new statement/s, you systematically need to reload the item in order to copy/paste the copied reference... on those statements, which can be pretty annoying, because :
- it takes time to reload,
- the newly added statements are then mixed up with the older ones, because of the re-ordering of the statements, which makes it much harder to find them all to add the reference.
- example : on Gabrielle Vilar (Q35821492), (Bibliothèque nationale de France ID (P268) allowed me to add date of birth (P569), date of death (P570), place of birth (P19), place of death (P20), languages spoken, written or signed (P1412) and to source sex or gender (P21), country of citizenship (P27) and occupation (P106), employer (P108), etc. -> after adding date of birth (P569), date of death (P570), place of birth (P19), place of death (P20), languages spoken, written or signed (P1412), and sourcing sex or gender (P21), I could copy source to country of citizenship (P27) and occupation (P106), but I had to reload the item to re-copy source and then paste it on date of birth (P569), date of death (P570), place of birth (P19), place of death (P20), languages spoken, written or signed (P1412)...
Please : could this be fixed so that a reference can be pasted to any statement, not only those that existed before the current load of the item ? Thanks a lot... --Hsarrazin (talk) 10:41, 29 November 2017 (UTC)
Extend to support copying references between different items? edit
I would find this really useful, so I made a test implementation here using localStorage (expiring after 4 hours). Are there other than me who would find it useful, or would you prefer to keep the widget as it is? Danmichaelo (talk) 20:19, 17 June 2018 (UTC)
prevent creating true duplicates edit
DuplicateReferences happily creates multiple duplicate references for the same statement. Please make it check if the stuff it is going to paste is already there.
What makes the situation worse is the fact that there are often error messages with false negatives when pasting. So one would want to try again, which leads to duplicates. Fixing this would also alleviate part of the problem.--Reseletti (talk) 11:11, 4 September 2019 (UTC)
Gadget not working last 2 days edit
The gadget is not working for ma last 2 days. I can copy a reference and insert it and than I see "saving" message which does not disappear. Refreshing the page after an hour shows that the reference was not copied. Any ideas? --Jarekt (talk) 18:49, 27 September 2019 (UTC)
- Same here today. Getting an JS error in the Firefox console:
TypeError: model is null load.php:12:840
- Raymond (talk) 19:34, 2 October 2019 (UTC)
- Annoying, but there is a drag and drop possibility that can be used. But that gadget is less efficient when the reference needs copying several places or somewhere far away on the page. There is a task, I added tracking for it. Haros (talk) 00:06, 3 October 2019 (UTC)
Norwegian localization edit
{{Editprotected}}
Please insert the following Norwegian translations:
case 'nb':
mw.messages.set( {
'insert-reference': 'sett inn referanse',
'copy': 'kopier',
'saving': 'lagrer',
'copied': 'kopiert',
'insert-reference-failed': 'Referansen kunne ikke settes inn.'
} );
break;
case 'nn':
mw.messages.set( {
'insert-reference': 'sett inn referanse',
'copy': 'kopier',
'saving': 'lagrar',
'copied': 'kopiert',
'insert-reference-failed': 'Referansen kunne ikkje settast inn.'
} );
break;
Jon Harald Søby (talk) 11:35, 1 April 2021 (UTC)
- Done --Hoo man (talk) 13:18, 20 April 2021 (UTC)
sv translation edit
{{Editrequest}}
break; case 'sv': mw.messages.set( { 'insert-reference': 'lägg in referens', 'copy': 'kopiera', 'saving': 'skapar', 'copied': 'kopierad', 'insert-reference-failed': 'kunde inte lägga in referens.' } );
it translation edit
{{Editrequest}}
case 'it': mw.messages.set( { 'insert-reference': 'inserisci nota', 'copy': 'copia', 'saving': 'salvando...', 'copied': 'copiato', 'insert-reference-failed': 'Non è stato possibile inserire la nota.' } );
– The preceding unsigned comment was added by Sannita (talk • contribs) at 23 September 2022 (UTC).
- @Sannita: already has it translation?--Estopedist1 (talk) 08:27, 24 September 2022 (UTC)
- @Estopedist1: I checked and there shouldn't be, but in any case, it can be an update to the current one. --Sannita - not just another it.wiki sysop 12:43, 24 September 2022 (UTC)
- @Sannita: Done. Stang★ 12:15, 28 September 2022 (UTC)
@Sannita, Estopedist1: Thanks for adding the Italian translation! I would propose a little change, because Help:Sources/it (and other guidelines) translate "reference" as "riferimento" (not "nota"), so:
case 'it': mw.messages.set( { 'insert-reference': 'inserisci riferimento', 'copy': 'copia', 'saving': 'salvataggio...', 'copied': 'copiato', 'insert-reference-failed': 'Non è stato possibile inserire il riferimento.' } );
Thanks! --Epìdosis 15:00, 28 September 2022 (UTC)
- @Stang could you fulfill this minor request, so we can finish this edit-request? Estopedist1 (talk) 07:16, 1 October 2022 (UTC)
- @Estopedist1: Sure, done in Special:Diff/1740502062. Stang★ 12:30, 1 October 2022 (UTC)