User:Codeispoetry/filePortlet.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>

 // Diese Funktion baut das datei-Portlet auf. 
 function buildFilePortlet ()
 {
   if (isImage)
   {
   ins_box           = document.createElement('div');
   ins_box.className = 'portlet';
   ins_box.id        = 'p-file';
   ins_box.innerHTML = '<h5>datei</h5><div class="pBody"><ul>' + 
    '<li id="t-info"><a href="#" onclick="insertInformation()">Vorlage Information</a></li>' + 
    '<li id="t-badname"><a href="#" onclick="markAsBadname()">Badname</a></li>' + 
    '<li id="t-dupl"><a href="#" onclick="markAsDuplicate()">Duplicate</a></li>' + 
    '<li id="t-speed<"><a href="#" onclick="requestSpeedy()">Speedy</a></li>' + 
    '<li id="t-copyvio"><a href="#" onclick="markAsCopyvio()">Copyvio</a></li>' + 
    '<li id="t-nfd"><a href="#" onclick="nominateForDeletion()">Nominate for Deletion</a></li>' + 
    '<li id="t-npd"><a href="#" onclick="markAsNp()">Missing Permission</a></li>' + 
    '<li id="t-nsd"><a href="#" onclick="markAsNs()">Missing Source</a></li>' + 
    '<li id="t-nld"><a href="#" onclick="markAsNl()">Missing Licensing</a></li>' + 
    '<li id="t-what"><a href="http://tools.wikimedia.de/~magnus/whatisthat.php?image=' + encodeURIComponent(mw.config.get('wgPageName')) + '&doit=Do+it%21">What is that?</a></li>' + 
    '</ul></div>';
   document.getElementById('p-tb').parentNode.insertBefore(ins_box,document.getElementById('p-tb'));
   }
 }

 // Ab hier folgen Funktionen, die aus dem datei-Portlet aufgerufen werden.
 function insertInformation()
 {
  insertText('{{Information\n|Description=\n|Source=\n|Date=\n|Author=\n|Permission=\n|other_versions=\n}}', 2, '{{information}}', false);
 }

 function markAsBadname()
 {
  var newName = prompt("Right name?","");
  if (newName.indexOf('Image:') == -1) 
    newName = 'Image:' + newName;
  insertText('{{Bad name|' + newName + '}}', 2, 'Bad name ' + newName, true);
 }

 function markAsCopyvio()
 {
  var uploader = getUploader();
  if (!uploader) return;
  var reason = prompt('Copyvio reason?','');
  // Open new window for the user page
  openWindow(wgScript + '?title=User_talk:' + uploader + 
                        '&action=edit' + 
                        '&text=' + encodeURIComponent('\n{{subst:copyvionote|' + wgPageName + '}}\n~~~~\n') + 
                        '&wo=3' + 
                        '&subject=' + encodeURIComponent('Warning: Copyvio') +
                        '&autoedit=true');

  insertText('{{subst:copyvio|' + reason + '}}', 2, 'Copyvio', true);
 }

 function markAsDuplicate()
 {
  var newName = prompt("Other file?","");
  if (newName.indexOf('Image:') == -1) 
    newName = 'Image:' + newName;
  insertText('{{Duplicate|' + newName + '}}', 2, 'Duplicate ' + newName, true);
 }

 function markAsNp()
 {
  var uploader = getUploader();
  if (!uploader) return;
  // Open new window for the user page
  openWindow(wgScript + '?title=User_talk:' + uploader + 
                        '&action=edit' + 
                        '&text=' + encodeURIComponent('\n{{subst:image permission|' + wgPageName + '}}\n~~~~\n') + 
                        '&wo=3' + 
                        '&subject=' + encodeURIComponent('Warning: image missing permission information') +
                        '&autoedit=true');

  insertText('{{subst:npd}}', 3, 'marking image as missing essential permission information. If this is not fixed this image might be deleted after 7 days.', true);
 }

 function markAsNs()
 {
  insertText('{{subst:nsd}}', 2, 'marking image as missing essential source information. If this is not fixed this image might be deleted after 7 days.', true);
  var uploader = getUploader();
  if (!uploader) return;
  // Open new window for the user page
  openWindow(wgScript + '?title=User_talk:' + uploader + 
                        '&action=edit' + 
                        '&text=' + encodeURIComponent('\n {{subst:image source|' + wgPageName + '}}\n~~~~\n') + 
                        '&wo=3' + 
                        '&subject=' + encodeURIComponent('Warning: image missing sourcing information') +
                        '&autoedit=true');
 }

 function markAsNl()
 {
  insertText('{{subst:nld}}', 2, 'marking image as missing essential license information. If this is not fixed this image might be deleted after 7 days.', true);
  var uploader = getUploader();
  if (!uploader) return;
  // Open new window for the user page
  openWindow(wgScript + '?title=User_talk:' + uploader + 
                        '&action=edit' + 
                        '&text=' + encodeURIComponent('\n {{subst:image source|' + wgPageName + '}}\n~~~~\n') + 
                        '&wo=3' + 
                        '&subject=' + encodeURIComponent('Warning: image missing sourcing information') +
                        '&autoedit=true');
 }

 function nominateForDeletion()
 {
  var reason = prompt(nfd_prompt, '');
  if (!reason) return;
  var uploader = getUploader();
  if (!uploader) return;

  openWindow(wgScript + '?title=User_talk:' + uploader +
                        '&action=edit' + 
                        '&text=' + encodeURIComponent('\n{{subst:idw|' + wgPageName + '}}\n~~~~\n') + 
                        '&wo=3' + 
                        '&subject=' + encodeURIComponent('Image deletion warning: ' + wgPageName) +
                        '&autoedit=true');

  openWindow(wgScript + '?title=Commons:Deletion_requests/' + wgPageName +
                        '&action=edit' +
                        '&text=' + encodeURIComponent('{{subst:delete2|image=' + wgPageName + '|reason=' + reason + '~~~~}}') +
                        '&wo=1' + 
                        '&subject=' + encodeURIComponent('Nominating [[' + wgPageName + ']]') +
                        '&autoedit=true');

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();

  openWindow(wgScript + '?title=Commons:Deletion_requests/' + timestamp +
                        '&action=edit' +
                        '&text=' + encodeURIComponent( '{{subst:delete3|pg=' + wgPageName + '}}') +
                        '&wo=3' + 
                        '&subject=' + encodeURIComponent('Nominating [[' + wgPageName + ']]') +
                        '&autoedit=true');

  insertText('{{' + nfd_deleteTemplate + '|reason=' + reason + '}}', 2, 'Nominating image for deletion', true);

}

 // Hier wird das datei-Portlet endgültig aufgebaut.
 addOnloadHook(buildFilePortlet);

 // Dieser Button ist noch nicht woanders eingebunden, macht aber auch nur in diesem Namespace Sinn.
 includePage( 'MediaWiki:Check-usage.js' );

 // helperFunctions (Nur für Debugzwecke einbinden)
 // includePage('User:Codeispoetry/helperFunctions.js');
 //</nowiki>