MediaWiki:Gadget-EmptyDetect.js

/*! * Adopted from Wikidata * auto detect that the item is previously merged with which item * Written by me inside MediaWiki:Gadget-Merge.js * now its code is extracted but currently is not a separate gadget * and auto enabled with Merge.js * * @author User:Ebraminio  */

/*jslint browser: true, regexp: true, indent: 2, unparam: true*/ /*jshint unused: false*/ /*global $, mw, mergeTool*/ $(function {  'use strict';  if (mw.config.get('wgNamespaceNumber') !== 0 || !mw.config.exists('wbEntityId')) { return; }  mw.hook('wikibase.entityPage.entityLoaded').add(function (entity) { // give up if there is a link on item if (entity.sitelinks !== undefined) { return; } new mw.Api.get({     action: 'query',      prop: 'revisions',      titles: mw.config.get('wbEntityId'),      rvlimit: 1,      rvprop: 'content',      format: 'json',      rvdir: 'newer'    }).then(function (x) {      var itemOldEntity, site, title;      itemOldEntity = JSON.parse($.map(x.query.pages, function (x) { return x; })[0].revisions[0]['*']);      // if previous item had not any site link, give up      if (itemOldEntity.links === undefined) { return; }

// put last item site link on local variables $.map(itemOldEntity.links, function (x, y) { site = y; title = x.name; });

new mw.Api.get({       action: 'wbgetentities',        sites: site,        titles: title      }).then(function (x) {        // if query not contains any entity, give up        if (x.entities['-1'] !== undefined) { return; }

var dest = $.map(x.entities, function (x, y) { return y; })[0].toUpperCase;

mw.notify(         $(' ').append( 'Might have been merged with ', $('' + dest + ''), ' ',           window.mergeTool === undefined ? '' : $('').append($(' ', { src: '//upload.wikimedia.org/wikipedia/commons/thumb/1/10/Pictogram_voting_merge.svg/15px-Pictogram_voting_merge.svg.png' }).click(function (event) { event.preventDefault; mergeTool.launchDialog(dest); })) ),         {            autoHide: false          }        ); });   });  }); });