Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
importScript( 'MediaWiki:EditPage.js' );

function normalizeTitle(str)
{
 return str;
}

var eiEditting = false;
function eiCategory()
{
 if (eiEditting) return;
 eiEditting = true;

 var categories = [];
 var page = new EditPage(wgPageName, function () 
 {
  var text = page.textData;
  var reCat = /\[\[Category\:(.*?)\]\]/g;

  var match;
  while ((match = reCat.exec(text)) != null)
  {
   categories.push(normalizeTitle(match[1]));
  }
  
  var catlinks = document.getElementById('catlinks').getElementsByTagName('a');
  for (var i = 0; i < catlinks.length; i++)
  {
   var el = catlinks[i];
   if (el.hasAttribute('title')) 
   {
    if (categories.indexOf(el.getAttribute('title').substr(9)) != -1)
    {
     var inputBox = document.createElement('input');     
     inputBox.setAttribute('value', el.getAttribute('title').substr(9));
     el.parentNode.replaceChild(inputBox, el);
    }
   }
  }
 });
}
$(function () 
{
 addEvent(document.getElementById('catlinks'), 'click', eiCategory);
});
//</source>