Μετά την αποθήκευση πρέπει να καθαρίσετε την κρυφή μνήμη (cache) του browser σας για να δείτε τις αλλαγές: Σε Chrome, Firefox, Safari, Internet Explorer και Edge: Κρατήστε πατημένο το Shift και κάντε κλικ στο κουμπί Ανανέωση στην μπάρα εργαλείων.

/**
 * wef-history
 *
 * This script displays in the history pages of Wikipedia changes of the corresponding Wikidata item.
 *
 * Author : H4stings.
 */

// Doc :
// 1. Add in your commons.js file : importScript('User:H4stings/wef-history.js'); 
// 2. Go to any Revision history page, it shoud work !
//

//////////////////////ZONE PERSONNALISABLE//////////////////////
if (typeof cacherModifLabel == 'undefined') { //hide wbsetlabel
  cacherModifLabel = true;
}
if (typeof cacherModifAlias == 'undefined') { //hide wbsetaliases
  cacherModifAlias = true;
}
if (typeof cacherModifLiens == 'undefined') { //hide wbsetsitelink & clientsitelink
  cacherModifLiens = true;
}
if (typeof afficherTout == 'undefined') { //display all
  afficherTout = false;
}
if (afficherTout === true) { //afficher tout
  cacherModifLabel = false;
  cacherModifAlias = false;
  cacherModifLiens = false;
}
/////////////////FIN DE LA ZONE PERSONNALISABLE/////////////////

/** @const liée au script initial */
var version = 1455143959;

try {
	mw.loader.addSource( "ruwiki", "//ru.wikipedia.org/w/load.php" );
	mw.loader.register( 'ext.gadget.wefcore', version, [ 'jquery.ui', //
	'jquery.ui', //
	'jquery.ui', //
	'jquery.uls.data', //
	'mediawiki.ForeignApi', //
	], undefined, 'ruwiki' );
	mw.loader.register( 'ext.gadget.isbnjs', version, undefined, undefined, 'ruwiki' );
	mw.loader.register( 'ext.gadget.wefflags', version, undefined, undefined, 'ruwiki' );
	mw.loader.register( 'ext.gadget.wefcore', version, [ 'mediawiki.api' ], undefined, 'ruwiki' );
} catch ( error ) {
	// already registered
}

if ( mw.config.get( 'wgAction' ) === 'history' ) {

	mw.loader.using( [ 'mediawiki.api', 'mediawiki.ForeignApi', 'ext.gadget.wefcore' ], function() {

		var notifyOptions = {
			autoHide: true,
			tag: 'WEF-history',
		};

		var i18n = {
			actionObtain: 'Ανάκτηση αλλαγών Wikidata',
			actionIntegrate: 'Εμφάνιση αλλαγών Wikidata',

			linePartLetter: 'd',
			linePartTooltip: 'Wikidata',
			linePartChange: 'διαφ.',
			linePartHistory: 'ιστορικό',

			// the same as in watchlist
			monthes: [ "Ιανουαρίου", "Φεβρουαρίου", "Μαρτίου", "Απριλίου", "Μαΐου", "Ιουνίου", "Ιουλίου", "Αυγούστου", "Σεπτεμβρίου", "Οκτωβρίου", "Νοεμβρίου", "Δεκεμβρίου" ],
			revMonthes: { "Ιανουαρίου" : 1, "Φεβρουαρίου" : 2, "Μαρτίου": 3, "Απριλίου" : 4, "Μαΐου" : 5, "Ιουνίου": 6, "Ιουλίου" : 7, "Αυγούστου" : 8, "Σεπτεμβρίου": 9, "Οκτωβρίου" : 10, "Νοεμβρίου" : 11, "Δεκεμβρίου": 12 }, // works only for french wikipedia. has to be translated. 
			
			dico : { "wbsetsitelink-add" : "Sitelink added", "wbsetsitelink-set" : "Sitelink modified", "wbsetsitelink-remove" : "Sitelink removed", "wbsetlabel-add" : "Label added", "wbsetlabel-set" : "changed label", "wbsetlabel-remove" : "removed label", "wbsetdescription-add" : "Description added", "wbsetdescription-set" : "Description modified", "wbsetdescription-remove" : "Description removed", "wbeditentity-update" : "Item updated", "wbeditentity-override" : "Overrode item'", "wbeditentity-create" : "Item created", "wbsetaliases-set" : "Changed aliase(s)", "wbsetaliases-remove" : "Removed aliase(s)", "wbsetaliases-add" : "Added aliase(s)", "wblinktitles-create" : "Entité créée pour connecter les pages", "wblinktitles-connect" : "Lien de langue ajouté pour connecter les pages", "wbsetclaimvalue" : "Created claim", "wbremoveclaims" : "Deleted claim", "wbremoveclaims-remove" : "Deleted claim", "wbcreateclaim-value" : "Created Claim", "wbcreateclaim-novalue" : "Created novalue claim", "wbcreateclaim-somevalue" : "Created somevalue claim", "wbsetclaim-update" : "Updated claim", "wbsetclaim-create" : "Created claim", "wbsetclaim-update-qualifiers" : "Updated qualifers", "wbsetclaim-update-references" : "Updated references", "wbsetclaim-update-rank" : "Updated claim rank", "wbsetreference" : "Modified reference", "wbsetreference-add" : "Added reference", "wbcreateclaim-create" : "Created claim", "wbmergeitems-from" : "Merged item from", "wbsetqualifier-add" : "Added qualifier", "wbremovereferences-remove" : "Removed reference" },
			reP : /\[\[Property\:(P[0-9]*)\]\]/,
	        reQ : /\[\[(Q[0-9]*)\]\]/,
	        reD : /\/\* ([^: ]*)/,
	        //reH : /([0-9]+) (\w+) ([0-9][0-9][0-9][0-9]) à ([0-9][0-9]):([0-9][0-9])/, // /!\ works only for french wikipedia. has to be rewritted for each wikipedia  
	        reH : /([0-9][0-9]):([0-9][0-9]), ([0-9]+) (\w+) ([0-9][0-9][0-9][0-9])/,  //14:52, 13 September 2014
		};

        var entityId = null;
        // [[Property:P910]]: [[Q7804038]]"
        var revs = null;

		function affichage() {
			//"use strict";
			
			mw.notify( i18n.actionIntegrate, notifyOptions );
			
		    //affichage des révisions
		    $.each(revs, function(keyr, valr){
		        //console.log("diff : " + valr.comment + " | " + valr.timestamp);
		        try {
		            generateWatchlistLine( valr, i18n.dico );
		        } catch ( error ) {
		            mw.log.warn( "Can't add change line", error );
		        }
			});
		}
		
		function showChanges() {
			//"use strict";
		               
		    mw.notify( i18n.actionObtain, notifyOptions );
						
		    if ( mw.config.get( 'wgArticleId' ) ) {
		        WEF_Utils.getEntityIdDeferred().done( function( entityId ) {
		            if ( !WEF_Utils.isEmpty( entityId ) ) {
						//api des modifs à afficher
		                console.log( 'https://www.wikidata.org/w/api.php?action=query&prop=revisions&rvlimit=50&titles=' + entityId );
		                WEF_Utils.getWikidataApi().get( {
						    rvlimit: 50,
						    titles: entityId,
						    prop: 'revisions',
						    action: 'query',
						} ).done( function( result ) {
						    
		                    //en principe, y'a qu'une page...
		                    var page=result.query.pages;
							var listePQ = "";
		                    $.each(page, function(key, val){
		                        //console.log ("id page " + key);
		                        revs=val.revisions;
		                        //1ere boucle pour lister les P & Q qu'on va devoir traduire
		                    	$.each(revs, function(keyr, valr){
		                        	//console.log ("valr.comment " + valr.comment);
		                            if (valr.comment){
		                                var res1 = i18n.reP.exec(valr.comment);
		                                if (res1 !== null){
		                                    if (listePQ.indexOf(res1[1])==-1) { 
		                                  		listePQ = listePQ + "|" + res1[1];
		                                  	}
		                                }
		                                var res2 = i18n.reQ.exec(valr.comment);
		                                if (res2 !== null){
		                                    if (listePQ.indexOf(res2[1])==-1) { 
		                                    	listePQ = listePQ + "|" + res2[1]; 
		                                    }
		                                }
		                                //console.log (res1 + " " + res2);
		                            }
		                        });
		                    });
		                    listePQ = listePQ.substring(1);
		                    completedico(listePQ);
						} );
		            }
		        });
		    }
		}

		function completedico(liste) {
			//"use strict";
						
			//2e api de récup pour construire le i18n.dico des labels
	        console.log("https://www.wikidata.org/w/api.php?action=wbgetentities&ids=" + liste + "&props=labels&languages=en");
	        WEF_Utils.getWikidataApi().get( {
	            action: 'wbgetentities',
	            props: 'labels',
	            languages: 'el',
	            ids: liste,
	            format: 'json',
	        } ).done( function( result ) {
	            //faire un i18n.dico avec P/Q => label
	            var entities=result.entities;
	            $.each(entities, function(keyr, valr){
	                //i18n.dico[keyr] = valr.labels.el.value;
	                if(valr.labels && valr.labels.el && valr.labels.el.value){
	           			//console.log(keyr + " " + valr + " " + valr.labels.el.value);
	                	i18n.dico[keyr] = valr.labels.el.value;
	                }else{
	                	i18n.dico[keyr] = keyr;
	                }
	            });
	        	//console.log (i18n.dico);
	        	affichage();
	        });
        }
        
		function pad( src ) {
			"use strict";

			if ( src < 10 ) {
				return "0" + src;
			} else {
				return "" + src;
			}
		}
		
		function generateWatchlistLine( jEntry, dico ) {
			//"use strict";

			var id = jEntry.revid;
			var testSummary =  jEntry.comment;
			//console.log( "id "+ id + " summary "+ testSummary );

			//if (false) {
            if (testSummary.indexOf("|en") == -1 && ((testSummary.indexOf("wbsetlabel") > -1 && cacherModifLabel) 
            	|| (testSummary.indexOf("wbsetaliases") > -1 && cacherModifAlias) || (testSummary.indexOf("wbsetsitelink") > -1 && cacherModifLiens)  
            	|| (testSummary.indexOf("clientsitelink") > -1 && cacherModifLiens) || (testSummary.indexOf("wbsetdescription") > -1) ) ) {
				console.log( "diff " + id + " hided because not el");
				
			}else{
				var changeUrl = "https://www.wikidata.org/w/index.php?diff=" + id;
				var author = jEntry.user;
				var updated = new Date(jEntry.timestamp);
                var dateAff = updated.getDate() + ' ' + i18n.monthes[updated.getMonth()] + ' ' + updated.getFullYear();
                var heureAff = pad( updated.getHours() ) + ':' + pad( updated.getMinutes() );
                //traduction commentaire sur la base du i18n.dico
                var resSum1 = i18n.reP.exec(testSummary);
                if (resSum1 !== null && i18n.dico[resSum1[1]] !== null){
                    testSummary = testSummary.replace("[[Property:"+resSum1[1]+"]]", i18n.dico[resSum1[1]] + " <small>(<a href=\"https://www.wikidata.org/wiki/Property:"+resSum1[1]+"\">Property:"+resSum1[1]+"</a>)</small>");
                }
                var resSum2 = i18n.reQ.exec(testSummary);
                if (resSum2 !== null && i18n.dico[resSum2[1]] !== null){
                    testSummary = testSummary.replace("[["+resSum2[1]+"]]", i18n.dico[resSum2[1]] + " <small>(<a href=\"https://www.wikidata.org/wiki/"+resSum2[1]+"\">"+resSum2[1]+"</a>)</small>");
                }
                var resSum3 = i18n.reD.exec(testSummary);
                if (resSum3 !== null && typeof i18n.dico[resSum3[1]] != 'undefined'){
                    testSummary = testSummary.replace(resSum3[1], i18n.dico[resSum3[1]]+" ");
                }
                testSummary = testSummary.replace("/*", "<span class=\"autocomment\">");
                testSummary = testSummary.replace("*/", "</span>");
                
                var txt = "<li id=\"wef-history\"><span>"
                	+ "<abbr style=\"font-size:bold; margin-left:0.5em;\" title=\"" + i18n.linePartTooltip + "\">" + i18n.linePartLetter + "</abbr> <span class=\"mw-changeslist-separator\">. .</span> "
                	+ "(<a href=\"https://www.wikidata.org/w/index.php?diff=" + id + "\">diff</a>)</span> <span class=\"mw-changeslist-separator\">. . . . .</span> "
                	+ "<span class=\"mw-changeslist-date\">" + dateAff + " à " + heureAff + "</span> "
                	+ "<span class=\"history-user\">" + author + "</span><span class=\"mw-changeslist-separator\">. .</span> "
                	+ "<span class=\"comment\">" + testSummary + "</span></li>";
                insertChang (txt, updated) ;
			}
		}

		function insertChang( txt, updated ) {
			"use strict";

	        $('div#pagehistory > li ').each(function(){
				//console.log (this + " " + $(this).text());
				//si c'est pas du wikidata 
				if ($(this).text().substr(0,1) != 'd'){
					var resH = i18n.reH.exec($(this).text());
	                if (resH !== null){
			        	var d = new Date( parseInt(resH[5]), parseInt(i18n.revMonthes[resH[4]]-1), parseInt(pad(resH[3])), parseInt(resH[1]), parseInt(resH[2]), 0);
			        	if (d<updated) {
			        		$(this).before(txt);
			        		return false;
			        	}
	                }
				}
			});
		}
        
		{
			mw.loader.using( [ 'ext.gadget.wefcore', ], function() {
				showChanges();
			} );
		}
	} );
}