MediaWiki:Gadget-currentDate.js

// This script is directly copied from wikidata:User:TMg/currentDate.js. /** * This script automatically adds the current date (in ISO form) as a default value whenever * you add a snak with the property "retrieved" (P200, alias "access date"). */ ( function ( $ ) {	$( '.wikibase-statementgrouplistview' ).on( 'valueviewafterstartediting', function( event ) { // Separate multiple property IDs with pipe characters. var currentDateProperties = 'P200';

var $valueview = $( event.target ), valueview = $valueview.data( 'valueview' ), expert = valueview.expert;

if ( valueview.options.dataValueType !== 'time'				|| expert.$input.val			) { return; }

var $snakview = $valueview.closest( '.wikibase-snakview' ), snakview = $snakview.data( 'snakview' ), regex = new RegExp( '^(' + currentDateProperties .replace( /[^P\d]+/gi, '|' ) .replace( /^\||\|$/gi, '' ) + ')$', 'i' );

if ( !regex.test( snakview.value.property ) ) { return; }

var input = expert.$input[0], isoDate = new Date.toISOString.slice( 0, 10 );

expert.$input.val( isoDate ); // FIXME: This accesses a protected property. expert._viewNotifier.notify( 'change' ); input.focus; input.select; } ); } )( jQuery );