Ir al contenido

Usuario:Axxgreazz/Monobook-Suite/quickimgdelete.js

De Wikipedia, la enciclopedia libre

Nota: Después de guardar, debes refrescar la caché de tu navegador para ver los cambios. Internet Explorer: mantén presionada Ctrl mientras pulsas Actualizar. Firefox: mientras presionas Mayús pulsas el botón Actualizar, (o presiona Ctrl-Shift-R). Los usuarios de Google Chrome y Safari pueden simplemente pulsar el botón Recargar. Para más detalles e instrucciones acerca de otros exploradores, véase Ayuda:Cómo limpiar la caché.

// <pre><nowiki> 
/* quickimgdelete.js
 * Current version: 1.2.1
 * =======================================
 * Created by [[User:Howcheng|Howard Cheng]]
 * Released under the [[GNU Public License]] (GPL)
 * Full documentation at [[User talk:Howcheng/quickimgdelete.js]]
 * =======================================
 */
// Should the edits be saved automatically?
var getParamValue = mw.util.getParamValue;
if(window.nfd_autosave == false){}else if(window.nfd_autosave){}else{ nfd_autosave = true; }
if(window.mnx_autosave == false){}else if(window.mnx_autosave){}else{ mnx_autosave = true; }

// String constants
nfd_text = "Nominate for deletion";
nfd_tooltip = "Nominate this image for deletion";
nfd_prompt = "Why do you want to nominate this image for deletion?";
nfd_delReq = "Commons:Deletion_requests";
nfd_deleteTemplate = "delete";
nfd_idwTemplate = "idw";

/*
if (wgUserLanguage != 'en')
{
 includePage( 'MediaWiki:Quick-delete2.js/'   wgUserLanguage );
}
*/

mns_text = "No source";
mns_tooltip = "Mark this image as missing required source information";
mnl_text = "No license";
mnl_tooltip = "Mark this image as missing required licensing information";
mnx_lang = "lang?";
mnx_langquery = "In which language should the msg be given?";

var now = new Date();
var timestamp = now.getUTCFullYear()   '/';
now.getUTCMonth() < 9 ? timestamp  = '0'   (now.getUTCMonth()   1) : timestamp  = (now.getUTCMonth()   1);
timestamp  = '/';
now.getUTCDate() < 10 ? timestamp  = '0'   now.getUTCDate() : timestamp  = now.getUTCDate();
nfd_datePage = nfd_delReq   "/"   timestamp;
var monthsArray = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var timestamp2 = monthsArray[now.getUTCMonth()]   " "   now.getUTCDate();

function openWindow(url) {
  var res = window.open(url, '_blank');
  if (!res) alert("openWindow: window.open() returned null");
}

function getUploader() {
  // Get uploader from first point in the list under "File history"
  // Uploader is stored in second A tag in UL tag under "File history"
  // Returns title of user page (without name space) in URL form
  var el = document.getElementById('filehistory')
  if (!el) {
    alert("getUploader: Cannot find filehistory ... exiting");
    return null;
  }
  while (el.nextSibling) {
    el = el.nextSibling;
    if (el.tagName && el.tagName.toLowerCase() == 'table') 
      break;
  }
  if (!el) {
    alert("getUploader: Cannot find table tag ... exiting");
    return null;
  }

  var as = el.getElementsByTagName('a');

  var re1 = new RegExp((mw.config.get('wgServer')   mw.config.get('wgArticlePath').substr(0, mw.config.get('wgArticlePath').length-2) ).replace(/\./g, '\\.')   'User:(.*)$');
  var re2 = new RegExp((mw.config.get('wgServer')   mw.config.get('wgScript')).replace(/\./g, '\\.')   '\\?title=User:([^&]*)');
  var m;
  for (var k=0; k<as.length; k  ) {
     m = re1.exec(as[k].href);
     if (m) return m[1];
     m = re2.exec(as[k].href);
     if (m) return m[1];
  }
  alert("getUploader: Cannot find uploader ... exiting");
  return null;
}

function nfd_nomForDel() {
  var reason = prompt(nfd_prompt, '');
  if (!reason) return;
  var pagename = encodeURIComponent(mw.config.get('wgPageName'));
  var uploader = getUploader();
  if (!uploader) return;
  openWindow(mw.config.get('wgScript')   '?title=User_talk:'   uploader
       '&action=edit&fakeaction=nfd_warn&target='   pagename);
  openWindow(mw.config.get('wgScript')   '?title='   nfd_delReq   '/'   pagename 
       '&action=edit&fakeaction=nfd_add&target='   pagename   '&reason='
       encodeURIComponent(reason));
  openWindow(mw.config.get('wgScript')   '?title='   nfd_datePage  
     '&action=edit&fakeaction=nfd_add2&target='   pagename);
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  document.location = editlk   '&fakeaction=nfd_delete&reason='   encodeURIComponent(reason);
}

function nfd_addDeleteTemplate() {
  var reason = decodeURIComponent(mw.util.getParamValue('reason'));
  var txt = '{{'   nfd_deleteTemplate   '|'   reason   '}}';
  document.editform.wpTextbox1.value = txt   '\n'   document.editform.wpTextbox1.value;
  document.editform.wpSummary.value = txt;
  if (nfd_autosave) document.editform.wpSave.click();
}

function nfd_addIdwTemplate(target) {
  var txt = '{{subst:'   nfd_idwTemplate   '|'   target   '}}';
  document.editform.wpTextbox1.value  = 
    (document.editform.wpTextbox1.value.length > 0 ? '\n' : '')  
    txt   '~~'   '~~\n';
  document.editform.wpSummary.value = txt;
  if (nfd_autosave) document.editform.wpSave.click();
}

function nfd_updateDelReq(target, reason) {
  document.editform.wpTextbox1.value  = 
    (document.editform.wpTextbox1.value.length > 0 ? '\n' : '')  
    '{{subst:delete2|image='   target   '|reason='   reason   ' -- ~~'   '~~}}';
  document.editform.wpSummary.value = 'Nominating [['   target   ']]';
  if (nfd_autosave) document.editform.wpSave.click();
}

function nfd_updateDelReq2(target) {
  document.editform.wpTextbox1.value  = 
    (document.editform.wpTextbox1.value.length > 0 ? '\n' : '=='   timestamp2   '==\n')  
    '{{subst:delete3|pg='   target   '}}';
  document.editform.wpSummary.value = 'Nominating [['   target   ']]';
  if (nfd_autosave) document.editform.wpSave.click();
}


function nfd_onload() 
{
   if (typeof ms_Activa_Quickimgdelete == 'undefined') { ms_Activa_Quickimgdelete = true;}
   if (!msActivarModulo(ms_Activa_Quickimgdelete)) return;

   if (mw.config.get('wgCanonicalNamespace') == "Image") {
    addLink('p-tb', 'javascript:nfd_nomForDel()', msStringU(nfd_text), 'nom-for-del', msStringU(nfd_tooltip));
   }
   var fakeaction = getParamValue('fakeaction');
   if (fakeaction == 'nfd_delete')
     nfd_addDeleteTemplate();
   else if (fakeaction == 'nfd_warn')
     nfd_addIdwTemplate(decodeURIComponent(getParamValue('target')));
   else if (fakeaction == 'nfd_add')
     nfd_updateDelReq(decodeURIComponent(getParamValue('target')), decodeURIComponent(getParamValue('reason')));
   else if (fakeaction == 'nfd_add2')
     nfd_updateDelReq2(decodeURIComponent(getParamValue('target')));
}



function mnx_mark(imagepage_fakeaction, usertalk_fakeaction, message_lang) {
  if (!message_lang) return; //User pressed cancel

  var pagename = encodeURIComponent(mw.config.get('wgPageName'));
  var uploader = getUploader();
  if (!uploader) return;
  openWindow(mw.config.get('wgScript')   '?title=User_talk:'   uploader
       '&action=edit&fakeaction='   usertalk_fakeaction   '&target='   pagename   '&mnx_lang='   message_lang);
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  document.location = editlk   '&fakeaction='   imagepage_fakeaction   '&mnx_lang='   message_lang;
}

function mnx_addTemplate(template, sorl) {
  if (template == 'nsd') template='no source since';
  if (template == 'nld') template='no license';
  if (getParamValue('mnx_lang')) { 
          template = template   '/'   getParamValue('mnx_lang');
          template = template   '|'   'month={{subst:CURRENTMONTHNAME}}|day={{subst:CURRENTDAY}}|year={{subst:CURRENTYEAR}}';
  }
  
  var txt = '{{'   template   '}}';
// this MUST be subst since templates are NSD, NLD  // Correction, see a few lines above currently // it employes "no source since" and "no license" template so it shouldn't be substed.
  document.editform.wpTextbox1.value = txt   '\n'   document.editform.wpTextbox1.value;
  document.editform.wpSummary.value = 'marking image as missing essential '   sorl   ' information. If this is not fixed this image might be deleted after 7 days.';
// this is the edit summary for when you mark the image. you can change it if you want.
// sorl = "source" or "license"
  if (mnx_autosave) document.editform.wpSave.click();
}

function mnx_addUserWarningTemplate(imagetarget) {
  var txt = '{{subst:image source'   (getParamValue('mnx_lang') ? '/'   getParamValue('mnx_lang') : '' )   '|'   imagetarget   '}}';
// add in subst: if you want to subst these warnings
  document.editform.wpTextbox1.value  = '\n'   txt   '~~'   '~~\n';
  document.editform.wpSummary.value = "Warning: image missing source or licensing information.";
// this is the edit summary for when you leave the user warning on the talk page.
// you can change it if you want.
  if (mnx_autosave) document.editform.wpSave.click();
}

function mnx_onload() 
{
   if (typeof ms_Activa_Quickimgdelete == 'undefined') { ms_Activa_Quickimgdelete = true;}
   if (!msActivarModulo(ms_Activa_Quickimgdelete)) return;

   if (mw.config.get('wgNamespaceNumber') == 6) {
     addLink('p-tb', 'javascript:mnx_mark(\'mns_mns\', \'mnx_warn\', \'en\')', msStringU(mns_text), 'mark-no-source', msStringU(mns_tooltip), null, null, 'javascript:mnx_mark(\'mns_mns\', \'mnx_warn\', prompt(\''   msStringU(mnx_langquery)   '\', wgUserLanguage))', msStringU(mnx_lang));
     addLink('p-tb', 'javascript:mnx_mark(\'mnl_mnl\', \'mnx_warn\', \'en\')', msStringU(mnl_text), 'mark-no-license', msStringU(mnl_tooltip), null, null, 'javascript:mnx_mark(\'mnl_mnl\', \'mnx_warn\', prompt(\''   msStringU(mnx_langquery)   '\', wgUserLanguage))', msStringU(mnx_lang));
   }
   var fakeaction = getParamValue('fakeaction');

   if (fakeaction == 'mns_mns'){
     mnx_addTemplate('nsd','source');
}  if (fakeaction == 'mnl_mnl'){
     mnx_addTemplate('nld','license');
}  if (fakeaction == 'mnx_warn'){
     mnx_addUserWarningTemplate(decodeURIComponent(getParamValue('target')));
} }

if ( typeof msActivarModulo !== 'undefined') {
	$(mnx_onload);
	$(nfd_onload);
}

//</nowiki></pre>