descFields.Replaceability_text = opts.NFReplaceableText;
descFields.Replaceability = "n.a.";
descFields.Commercial = "n.a.";
break;  
case 'OptionNFCover':
// cover art gets standard rationales.
descFields.Purpose =
"to serve as the primary means of visual identification " +
"at the top of the article dedicated to the work in question.";
descFields.Replaceability = "n.a.";
descFields.Commercial = "n.a.";
break;  
case 'OptionNFLogo':
// logos get standard rationales.
descFields.Purpose =
"to serve as the primary means of visual identification " +
"at the top of the article dedicated to the entity in question.";
descFields.Replaceability = "n.a.";
descFields.Commercial = "n.a.";
break;  
case 'OptionNFPortrait':
// as with other historic photographs, it is useful to have both
// original publication and direct source
descFields.Source = fuwAppendLines([
fuwSurroundString("**Original publication**: ", opts.Publication),
"
\n",
fuwSurroundString("**Immediate source**: ", opts.Source)
]);
descFields.Purpose =
"for visual identification of the person in question, " +
"at the top of his/her biographical article";
descFields.Replaceability = opts.NFReplaceable;
descFields.Commercial = opts.NFCommercial;
descFields['Other information'] =
"The subject of the photograph has been deceased since: " + opts.NFPortraitDeceased;
break;  
case 'OptionNFMisc':
descFields.Source = fuwAppendLines([
fuwSurroundString(
"**Original publication**: ",
opts.Publication,
"
\n**Immediate source:** "),
"",
opts.Source
]);
descFields.Purpose = opts.NFPurpose;
descFields.Replaceability = opts.NFReplaceable;
descFields.Replaceability_text = opts.NFReplaceable_text;
descFields.Commercial = opts.NFCommercial;
break;
};  
if (opts.OptionNonFree) {
// common stuff for all non-free files:  
// Minimality field (same for all NF options):
descFields.Minimality = opts.NFMinimality;  
// append optional "extra license" selector and "AnyOther" fields
// to "Other information" field:
descFields['Other information'] = fuwAppendLines([
descFields['Other information'],
"
\n",
fuwSurroundString('\{\{', opts.NFExtraLicense, '\}\}'),
"
\n",
opts.AnyOther
]);
}
else {
// common stuff for all free files:
descFields.Other_versions = ''
this.otherInfo = fuwAppendLines([this.otherInfo, "\n\n", opts.AnyOther]);  
}  
};  
fuwGlobal.prototype.formatOutput = function(forCommons) {
var baseForm = this.ScriptForm;
var targetForm = this.TargetForm;
if (fuwTesting) {
var testForm = this.TestForm;
}
var opts = this.opts;
var otherInfo = this.otherInfo;
var descFields = this.descFields;  
var summary = "\n";
if (otherInfo) {
summary += "\n;Other information:\n" + fuwPackInfo(otherInfo, forCommons) + "\n";
}  
var editSummary = this.getEditSummary;  
var license = this.getLicense;  
if (forCommons) {
// pack our description info into an url pointing to the
// standard Commons Special:Upload
// with pre-loaded description fields  
summary = fuwSubst("Upload marker added by en.wp UW") + "\n" + summary;
summary = summary.replace(/\{\{OTRS pending\}\}/g, fuwSubst("OP"));  
if (license.special) {
// manually format the whole description page including the license tag, if it
// isn't one of the bare standard licenses in the dropdown box. Otherwise,
// submit description summary and license as two separate url parameters.
summary = summary + "\n\n" + license.special;
}
return (fuwGetCommonsURL +
"?title=Special:Upload" +
"&wpUploadDescription=" +
encodeURIComponent(summary) +
(license.standard ?
("&wpLicense=" + encodeURIComponent(license.standard)) : '') +
"&wpDestFile=" +
encodeURIComponent(opts.InputName));
}
else {
// pack all description into a single "text" parameter to be submitted
// to the local api.php upload.
summary = "==Summary==\n" +
summary +
"\n==Licensing==\n" +
(license.standard ? ("\{\{" + license.standard + "\}\}") : license.special) +
this.getTrackingCategory;  
if (fuwTesting) {
// Testing mode: show our data in the dummy form
// at the bottom of the page.
fuwGet('placeholderSandboxFilename').innerHTML = opts.InputName;
this.TestForm.SandboxSummary.value = editSummary;
this.TestForm.SandboxText.value = summary;
fuwSetVisible('placeholderTestForm', true);
}
// write output parameters into target form
// I can't believe IE7 is too stupid to simply understand "this.TargetForm.filename.value".
($('#TargetForm [name="filename"]')[0]).value = opts.InputName;
($('#TargetForm [name="text"]' )[0]).value = summary;
($('#TargetForm [name="comment"]' )[0]).value = editSummary;
($('#TargetForm [name="token"]' )[0]).value = mw.user.tokens.get('csrfToken');  
}  
};  
function fuwHasUserGroup(group) {
// workaround because old IE versions don't have array.indexOf :-(
for (i = 0; i < mw.config.get('wgUserGroups').length; i++) {
if (mw.config.get('wgUserGroups')[i] == group) {
return true;
}
}
return false
}  
fuwGlobal.prototype.getUserStatus = function {
// function to determine the experience status and userrights of the current user:
// 'anon': not logged in; can't use script.
// 'notAutoconfirmed': can't use local upload, but may use script to prepare upload for Commons
// 'newbie': autoconfirmed but editcount < 100
// (may be used in future to adapt instructions more to newbie needs)
// 'problem': autoconfirmed but has 3 or more image-related warnings or deletion notifications among recent user talk entries
// (may be used in future to produce more strongly worded instructions)
// 'autoconfirmed': regular user
// 'sysop'  
if (mw.config.get('wgUserName')) {
if (fuwHasUserGroup('sysop')) {
this.userStatus = 'sysop';
}
else if (fuwHasUserGroup('autoconfirmed') || fuwHasUserGroup('confirmed')) {
this.userStatus = 'autoconfirmed';
$.ajax({
url : mw.util.wikiScript( 'api' ),
type : 'GET',
dataType: 'xml',
traditional : true,
data: {
format: 'xml',
action: 'query',
meta : 'userinfo',
uiprop: 'editcount',
prop : 'revisions',
titles: 'User talk' + mw.config.get('wgUserName'),
rvprop: 'comment|user',
rvlimit: 30
},
success: function(data) {
// callback func
var fuw = window.fuw;
if (data) {
var ui = data.getElementsByTagName('userinfo');
if (ui) {
var editcount = ui[0].getAttribute('editcount');
if (editcount < 100) {
fuw.userStatus = 'newbie';
}
}
var revs = data.getElementsByTagName('rev');
var countWarn = 0;
for (i = 0; i < revs.length; i++) {
var rev = revs[i];
var usr = rev.getAttribute('user');
var cmt = rev.getAttribute('comment');
if ((usr == 'ImageTaggingBot') ||
(cmt.search(/(tagging for deletion of \[\[File)|(Uploading files missing)|(File (source and )?copyright licensing problem)|(Speedy deletion nomination of \[\[File)|(Notification: listing at \[\[possibly unfree files)/) >= 0)) {
countWarn += 1;
}
}
if (countWarn >= 3) {
fuw.userStatus = 'problem';
}
}
}
});
}
else {
this.userStatus = 'notAutoconfirmed';
}
}
else {
this.userStatus = 'anon';
}
};  
// =================================================================
// Convenience function for getting the regular index.php
// interface of Commons. Not very elegant.
// =================================================================
function fuwGetCommonsURL {
if (document.URL.match(/^https:/))
return "https://commons.wikimedia.org/w/index.php";
else
return "http://commons.wikimedia.org/w/index.php";
}  
// ==================================================================
// functions for building form elements
// ==================================================================
fuwMakeRadiobutton = function(group, option, checked, event) {
// Stupid IE7 doesn't get "value" attribute unless it's created in this convoluted way.
// Annoying.
var node = $('<input type="radio" id="' + option + '" name="' + group + '" value="' + option + '"></input>')[0];
if (checked) node.checked = true;
node.onclick = event || fuwRadioClick;
node.onclick = event || fuwRadioClick;
fuwAppendInput(option, node);
};
fuwMakeTextfield = function(label, event) {
var node = document.createElement('input');
node.type = 'text';
node.name = label;