User:ContinueWithCaution/relicense.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
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.
 function relicense() {
   ////[[Category:User scripts]]
   //To add to your account, add the next line to your monobook.js
   //importScript('User:ContinueWithCaution/relicense.js');
   //Use at your own risk.
   /*
   Copyright (c) 2009 ContinueWithCaution
  
   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:
  
   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.
  
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
  
   */
   if (wgAction == "edit") {
      pagetext = document.editform.wpTextbox1.value;
      result = pagetext.match(/\{\{([^\}]+)\}\}/g);
      for (m in result) {
         result[m] = result[m].substr(2, result[m].length - 4);
         if (/GFDL/i.test(result[m])) { if (!(/GFDL-1\.2/i.test(result[m]))) { pagetext = pagetext.replace("{{"+ result[m] +"}}","{{" + result[m] + "|migration=relicense}}") } else {alert("GFDL 1.2 doesn't meet the criteria!");
         }
      }
   }
document.editform.wpTextbox1.value = pagetext;
document.editform.wpSummary.value = "Migrated page to CC-By-SA-3.0 per [[Commons:License_Migration_Task_Force/Migration]] using [[User:ContinueWithCaution/relicense.js|relicense.js]].";
document.editform.wpMinoredit.checked = true;
document.editform.wpSave.click();
}
else {
alert("You need to be on the edit page");
window.location = wgScript + "?title=" + wgPageName + "&action=edit";
}
}
function addLicenseTab() {
{
mw.util.addPortletLink('p-cactions', 'javascript:relicense()', 'Relicense', 'ca-relicense', "Relicense this page [Open in edit mode first].");
}
}
$(addLicenseTab);