MediaWiki:JSScripts/ProtectCreation

/*
 * Proteccion a la creacion
 * 
 * Permet als administrators de protegir automaticament la recreacion d'una pagina
 * en l'ajustant a WP:PPC al moment de la confirmacion de supression
 * 
 * Autor :
 * Data de darrièra revision : 6 de septembre de 2007
 */

// Code :

function protectCreation() {
  if (!document.getElementById('deleteconfirm')) return;
  var td = document.getElementById('wpWatch').parentNode;
  td.appendChild(document.createElement('br'));
  var label = document.createElement('label');
  var input = document.createElement('input');
  input.setAttribute('name', 'wpProtectCreation');
  input.setAttribute('type', 'checkbox');
  input.setAttribute('id', 'wpProtectCreation');
  input.setAttribute('tabindex', '3');
  label.appendChild(input);
  label.appendChild(document.createTextNode(' Protegir aquesta pagina de la recreacion'));
  td.appendChild(label);
  
  document.getElementById('wpConfirmB').setAttribute('tabindex', '4');
  document.getElementById('wpConfirmB').setAttribute('onclick', 'protectCreationExec();');
}
if(wgAction == 'delete') addOnloadHook(protectCreation);
if(document.URL.indexOf('protectcreation=') != -1) addOnloadHook(protectCreationWindow);

function protectCreationExec() {
  if(!document.getElementById('wpProtectCreation').checked) return;
  var d = new Array('Genièr','Febrièr','Març','Abril','Mai','Junh','Julhet','Agost','Setembre','Octobre','Novembre','Decembre');
  var hui = new Date();
  var adresse = new String('//oc.wikipedia.org/w/index.php?title=Wikipèdia:Paginas_protegidas_a_la_creacion/'+d[hui.getMonth()]+'_'+hui.getFullYear()+'&action=edit&protectcreation='+wgPageName);
  var fenetre = window.open(encodeURI(adresse), 'fProtectCreation', 'menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=800,height=200');
  fenetre.focus();
}

function protectCreationWindow() {
  if(wgPageName.substr(0,40) != 'Wikipèdia:Paginas_protegidas_a_la_creacion/') return;
  window.scrollTo(0,document.documentElement.clientHeight);
  if(document.URL.indexOf('protectcreation=') == -1) return;
  var page = decodeURI(document.URL.substr(document.URL.indexOf('protectcreation=')+16).replace(/_/g, ' '));
  document.editform.wpSummary.value = '+' + page;
  if(page.indexOf(':')!=-1) page = page.substr(page.indexOf(':')+1) + '|ns=' + page.substr(0, page.indexOf(':'));
  document.editform.wpTextbox1.value += '* {{Títol protegit|' + page + '}}';
  document.editform.wpSave.click();
}
//Fin del còde