MediaWiki:InformationToBook.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 to replace the information template with the Book template. 

  Author: based on [[User:Multichill]]'s [[MediaWiki:InformationToArtwork.js]], 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.InformationToBook =
{
  run : function ()
  {
    // Grab the text
    var text = document.getElementById ('wpTextbox1');
    // No text? 
    if (!text) return;
    // Do the actual replace
    text.value = (text.value || "").replace (/\s*\{\{Information\s*\n/i, "\n{{subst:Book/subst|subst=subst:\n");
    // Set edit summary
    var summary = document.getElementById ('wpSummary');
    if (!summary) return;
    var val = summary.value || "";
    summary.value = val + (val ? ' ' : "") + "Replacing [[Template:Information|Information]] with [[Template:Book|Book]]";
    // Are we sure we want to convert?
    var convert = confirm('Are you sure you want to convert the Information template to the Book template?');
    if (!convert) return;
    // Autosave the page
    document.editform.wpSave.click();
  }
};
window.InformationToBook.run();
});

// </nowiki>