MediaWiki:AddRijksmonument.js

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.
// <nowiki>

/*
  Quick helper script for templates checks. Called via a special link in [[Template:Possible Rijksmonument]]. It will replace the {{Possible Rijksmonument}} template with {{Rijksmonument|<id>}}. The user will be prompted for this id.

  Author: [[User:Multichill]], based on [[MediaWiki:Catcheck.js]] by [[User:Lupo]]
  License: Quadruple licensed GFDL, GPL, LGPL and Creative Commons Attribution 3.0 (CC-BY-3.0)
  
  Choose whichever license of these you like best :-)
*/

/*jshint curly:false*/
/*global mw:false, $:false*/
$(function() {
'use strict';

if (mw.config.get('wgNamespaceNumber') !== 6 || mw.config.get('wgAction') !== 'edit') {
  return;
}

window.AddRijksmonument =
{
  run : function ()
  {
    // Prompt for the id
    var rmid = prompt('What is the id of the Rijksmonument?','Id');
    if (rmid) {
      var text = document.getElementById ('wpTextbox1');
      if (!text) return;
      // Replace the "Possible Rijksmonument" tag, with the "Rijksmonument" tag + id
      text.value = (text.value || "").replace (/\{\{[Pp]ossible[ _][Rr]ijksmonument[^\}\{]*\}\}\n*/g, "\n{{Rijksmonument|" + rmid + "}}\n");
      // Add [[Category:Rijksmonumenten]]
      text.value = text.value + "[[Category:Rijksmonumenten]]";
      // Set edit summary
      var summary = document.getElementById ('wpSummary');
      if (!summary) return;
      var val = summary.value || "";
      summary.value = val + (val ? ' ' : "") + 
        "This is an image of Rijksmonument " + rmid + " - [[:Category:Possible Rijksmonumenten|Help sort out these images!]]";
      // Autosave the page
      document.editform.wpSave.click();
    }
  }
};
window.AddRijksmonument.run();
});

// </nowiki>