MediaWiki:FileUploadWizard.js: Difference between revisions

Content deleted Content added
per edit request at Wikipedia talk:File Upload Wizard, thanks User:The wub
per tper
 
(17 intermediate revisions by 5 users not shown)
Line 16:
// ================================================================
function fuwGlobal() {
 
// Loading the accompanying .css
mw.loader.load( mw.config.get('wgServer') + mw.config.get('wgScriptPath') +
'/index.php?title=MediaWiki:FileUploadWizard.css&action=raw&ctype=text/css',
'text/css' );
 
// see if user is logged in, autoconfirmed, experienced etc.
Line 27 ⟶ 22:
fuwSetVisible('warningLoggedOut', (this.userStatus == 'anon'));
fuwSetVisible('warningNotConfirmed', (this.userStatus == 'notAutoconfirmed'));
ifthis.disabled = ((this.userStatus == 'anon') || (this.userStatus == 'notAutoconfirmed')) {;
if (this.disabled) {
return;
}
Line 46 ⟶ 42:
this.ScriptForm = frm;
 
// create the TargetForm element that contains the filenamefile selector
// input box, together with hidden input controls.
// This is the form that is actually submitted to the api.php.
frm = fuwGet('TargetForm');
if (! frm) {
frm = document.createElement('form');
frm.id = "TargetForm";
frm.method = "post";
frm.enctype = "multipart/form-data";
// "enctype" doesn't work properly on IE; need "encoding" instead:
frm.encoding = "multipart/form-data";
// we'll submit via api.php, not index.php, mainly because that
// allows us to use a proper edit summary different from the page content
frm.action = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php';
 
// However, since api.php sends back a response page that humans won't want to read,
// we'll have to channel that response away and discard it. We'll use a hidden iframe
// for that purpose.
// Unfortunately, it doesn't seem possible to submit file upload content through an
// Xmlhtml object via Ajax.
frm.target = "TargetIFrame";
//testing:
//frm.target = "_blank";
var area = fuwGet('placeholderTargetForm');
var parent = area.parentNode;
Line 105 ⟶ 82:
filebox.size = fuwDefaultTextboxLength;
filebox.onchange = fuwValidateFile;
filebox.accept = 'image/png,image/jpeg,image/gif,image/svg+xml,image/tiff,image/x-xcf,application/pdf,image/vnd.djvu,audio/ogg,video/ogg,audio/rtp-midi,audio/mp3,image/webp,video/webm,audio/opus,video/mpeg,audio/wav,audio/flac';
fuwAppendInput('file', filebox);
 
// createDefault hidden controlsvalues for sendingAPI the remaining APIcall parameters:
this.UploadOptions = {
fuwMakeHiddenfield('action', 'upload', 'apiAction');
filename : '',
fuwMakeHiddenfield('format', 'xml', 'apiFormat');
text : '',
fuwMakeHiddenfield('filename', '', 'apiFilename');
comment : '',
fuwMakeHiddenfield('text', '', 'apiText');
ignorewarnings : 1,
fuwMakeHiddenfield('comment', '', 'apiComment');
watch : 1
fuwMakeHiddenfield('token', mw.user.tokens.get('csrfToken'), 'apiToken');
};
fuwMakeHiddenfield('ignorewarnings', 1, 'apiIgnorewarnings');
fuwMakeHiddenfield('watch', 1, 'apiWatch');
 
if (fuwTesting) {
Line 123 ⟶ 99:
fuwMakeHiddenfield('recreate', 1, 'SandboxRecreate');
}
 
// create a hidden IFrame to send the api.php response to
var ifr = document.createElement('iframe');
ifr.id = "TargetIFrame";
ifr.name = "TargetIFrame";
//ifr.setAttribute('style', 'float:right;width:150px;height:150px;');
ifr.style.display = "none";
ifr.src = "";
 
fuwAppendInput('TargetIFrame', ifr);
 
if (fuwTesting) {
Line 204 ⟶ 170:
'ThirdPartyEvidenceOptionNone'],
// choice of PD status in OptionPDOld subsection
'PDOldOptions' : ['PDUS1923PDUSExpired','PDURAA','PDFormality','PDOldOther'],
// choice of PD status in OptionPDOther subsection
'PDOtherOptions': ['PDOtherUSGov','PDOtherOfficial','PDOtherSimple',
Line 285 ⟶ 251:
[],
['Reserve no rights'],
['cc-zeroself|cc0',
'CC-zeroCC0 Universal Public Domain Dedication'],
[]
],
Line 322 ⟶ 288:
['PD-USGov-NASA','NASA'],
['PD-USGov-Military-Navy','US Navy'],
['PD-USGov-DOC-NOAA','US National Oceanic and Atmospheric Administration'],
['PD-USGov-Military-Air_Force','US Air Force'],
['PD-USGov-Military-Army','US Army'],
['PD-USGov-CIAInterior-WFUSGS','CIAUnited WorldStates FactbookGeological Survey'],
['PD-USGov-USGS','United States Geological Survey']
],
'IneligibleLicense' :
Line 332 ⟶ 297:
['', 'please select one...'],
['PD-shape','Item consists solely of simple geometric shapes'],
['PD-textsimple','Item consists solely of a few individual words or letters'],
['PD-textlogo','Logo or similar item consisting solely of letters and simple geometric shapes'],
['PD-chem','Chemical structural formula'],
Line 342 ⟶ 307:
['Non-free 2D art', '2-dimensional artwork (painting, drawing etc.)'],
['Non-free historic image', 'Unique historic photograph'],
['Non-free fair use in', 'something else (please describe in description field on top)']
],
'NF3DLicense' :
Line 356 ⟶ 321:
['Non-free book cover', 'Cover page of a book'],
['Non-free album cover', 'Cover of a sound recording (album, single, song, CD)'],
['Non-free video game cover', 'Cover of a video/computer game'],
['Non-free magazine cover', 'Cover page of a magazine'],
['Non-free video cover', 'Cover of a video'],
Line 362 ⟶ 327:
['Non-free product cover', 'Cover of some commercial product'],
['Non-free title-card', 'Title screen of a TV programme'],
['Non-free moviefilm poster', 'MovieFilm poster'],
['Non-free poster', 'Official poster of an event'],
['Non-free fair use in', 'something else (please describe in description field on top)']
],
'NFExcerptLicense' :
Line 371 ⟶ 336:
['Non-free television screenshot', 'Television screenshot'],
['Non-free film screenshot', 'Movie screenshot'],
['Non-free video game screenshot', 'GameVideo game screenshot'],
['Non-free video screenshot', 'Video screenshot'],
['Non-free music video screenshot', 'Music video screenshot'],
Line 383 ⟶ 348:
['Non-free computer icon', 'Computer icon'],
['Non-free newspaper image', 'Page from a newspaper'],
['Non-free fair use in', 'something else (please describe in description field on top)']
],
'NFLogoLicense' :
Line 450 ⟶ 415:
['Some permissions granted, but not completely free'],
['Non-free promotional', 'From promotional press kit'],
['Non-free file with NCno commercial use license', 'Permission granted, but only for educational and/or non-commercial purposes'],
['Non-free file with NDno derivative works license', 'Permission granted, but no derivative works allowed'],
['Non-free with permission', 'Permission granted, but only for Wikipedia'],
[]
Line 1,014 ⟶ 979:
(opts.PDOtherUSGov ? opts.USGovLicense : null) ||
(opts.PDOtherSimple ? opts.IneligibleLicense : null) ||
(opts.PDUS1923PDUSExpired ? 'PD-US-1923expired' : null) ||
(opts.PDURAA ? 'PD-URAA' : null) ||
(opts.PDFormality ? 'PD-US' : null);
Line 1,233 ⟶ 1,198:
"<br/>\n" + opts.NFSubjectPurpose) : null)
);
// I hate FURs filled with trivial/predictable/redundant verbiage,
descFields.Replaceability = "Any derivative work based upon the artwork would be a copyright violation, so creation of a free image is not possible.";
// so we'll just cut it short. And don't anybody dare complain that
descFields.Commercial = "The use of a low resolution image of the artwork will not impact the commercial viability of the art.";
// that's not a valid FUR.
descFields.Replaceability = "n.a.";
descFields.Commercial = "n.a.";
break;
 
Line 1,263 ⟶ 1,226:
"<br/>\n" + opts.NF3DPurpose) : null)
);
descFields.Replaceability = "n.Any derivative work based upon the artwork would be a copyright violation, so creation of a free image is not possible.";
descFields.Commercial = "The use =of "n.a low resolution image of the artwork will not impact the commercial viability of the art.";
descFields["Other information"] = (
opts.NF3DOptionSame ?
Line 1,281 ⟶ 1,244:
descFields.Purpose = opts.NFPurpose;
descFields.Replaceability_text = opts.NFReplaceableText;
descFields.Replaceability = "n.The software or website from which the screenshot is taken is copyrighted and not released under a free license, so creation of a free image is not possible.";
descFields.Commercial = "The use of =a low resolution screenshot from software or "n.a website will not impact the commercial viability of the software or site.";
break;
Line 1,290 ⟶ 1,253:
"to serve as the primary means of visual identification " +
"at the top of the article dedicated to the work in question.";
descFields.Replaceability = "n.Any derivative work based upon the cover art would be a copyright violation, so creation of a free image is not possible.";
descFields.Commercial = "The use of =a low resolution image of "n.a work's cover will not impact the commercial viability of the work.";
break;
Line 1,299 ⟶ 1,262:
"to serve as the primary means of visual identification " +
"at the top of the article dedicated to the entity in question.";
descFields.Replaceability = "n.Any derivative work based upon the logo would be a copyright violation, so creation of a free image is not possible.";
descFields.Commercial = "The use of = "n.a low resolution image of an organization's logo in the article about that organization will not impact the commercial viability of the logo.";
break;
 
Line 1,434 ⟶ 1,397:
fuwSetVisible('placeholderTestForm', true);
}
// writeSet outputup parametersAPI intocall target formparameters
this.UploadOptions.filename = opts.InputName;
// I can't believe IE7 is too stupid to simply understand "this.TargetForm.filename.value".
this.UploadOptions.text = summary;
($('#TargetForm [name="filename"]')[0]).value = opts.InputName;
this.UploadOptions.comment = editSummary;
($('#TargetForm [name="text"]' )[0]).value = summary;
($('#TargetForm [name="comment"]' )[0]).value = editSummary;
($('#TargetForm [name="token"]' )[0]).value = mw.user.tokens.get('csrfToken');
 
}
Line 1,818 ⟶ 1,779:
var nameBox = window.fuw.ScriptForm.InputName;
var name = $.trim(nameBox.value);
name = name.replace(/\.(png|gif|jpg|jpeg|xcf|pdf|mid|ogg|ogv|svg|djvu|tiff|tif|oga|mp3|webp|webm|opus|mpg|mpeg|wav|wave|flac)$/i, "");
 
// name should be at least 10 characters long, excluding file type extension
Line 1,851 ⟶ 1,812:
if (!file || !name) return true;
var extensions = /.+\.(png|gif|jpg|jpeg|xcf|pdf|mid|ogg|ogv|svg|djvu|tiff|tif|oga|mp3|webp|webm|opus|mpg|mpeg|wav|wave|flac)$/i;
var mimetypes = {
"png" : "image/png",
Line 1,858 ⟶ 1,819:
"jpeg" : "image/jpeg",
"xcf" : "image/x-xcf",
"webp" : "image/webp",
"pdf" : "application/pdf",
"mid" : "audio/rtp-midi",
"ogg" : "audio/ogg",
"mp3" : "audio/mp3",
"opus" : "audio/opus",
"wav" : "audio/wav",
"wave" : "audio/wav",
"flac" : "audio/flac",
"ogv" : "video/ogg",
"svg" : "image/svg+xml",
Line 1,866 ⟶ 1,833:
"tiff" : "image/tiff",
"tif" : "image/tiff",
"oga" : "video/ogg",
"webm" : "video/webm",
"mpg" : "video/mpeg",
"mpeg" : "video/mpeg"
};
 
Line 2,178 ⟶ 2,148:
 
// ========================================================
// convenience functionhandler for accessing the contentsAPI of theresponse.
// dummy TargetIFrame
// ========================================================
function fuwGetDocumentFromIFrame(iframe) {
var doc = (iframe.contentDocument ? iframe.contentDocument : iframe.contentWindow.document);
if (doc.XMLDocument) {
doc = doc.XMLDocument;
}
return doc;
}
// ========================================================
// event handler for the dummy TargetIFrame's onload event.
// TO DO: expand stub to add real notification of success,
// link to new file page, instructions about how to include
// file in articles, etc.
// ========================================================
function fuwUploadCompleted(doc) {
var doc = fuwGetDocumentFromIFrame(fuwGet('TargetIFrame'));
if (doc) {
//alert(doc);
Line 2,287 ⟶ 2,245:
alert("Unknown error: upload may have failed.");
}
}
}
}
 
// ========================================================
// clean out dummy IFrame before submitting a request
// ========================================================
function fuwResetTargetIFrame() {
var doc = fuwGetDocumentFromIFrame(fuwGet('TargetIFrame'));
if (doc) {
while (doc.hasChildNodes()) {
doc.removeChild(doc.firstChild);
}
}
Line 2,309 ⟶ 2,255:
var fuw = window.fuw;
var frm = fuw.TargetForm;
 
fuw.collectInput();
fuw.formatOutput(false);
 
// we will use the iframe's onload event to trigger a function that
// adds success notification etc.
fuwResetTargetIFrame();
var ifr = fuwGet('TargetIFrame');
if (ifr.attachEvent) {
// workaround for IE, according to
// http://www.nczonline.net/blog/2009/09/15/iframes-onload-and-documentdomain/
ifr.attachEvent("onload", fuwUploadCompleted);
}
else {
// all other browsers
ifr.onload = fuwUploadCompleted;
}
 
if (fuwTesting) {
Line 2,337 ⟶ 2,268:
fuwSetVisible('fuwWaiting', true);
 
// Upload the file, then add success notification etc.
frm.submit();
// Note that mw.Api doesn't have special support for the XML format, so even when the API
// returns an error, this won't be detected and it will call the success handler.
var api = new mw.Api({
parameters : { format : 'xml' },
ajax : { dataType : 'xml' }
});
api.upload(fuw.TargetForm.file, fuw.UploadOptions).then(fuwUploadCompleted);
 
var opts = window.fuw.opts;
// the API won't overwrite the description page text while overwriting
Line 2,354 ⟶ 2,293:
token : mw.user.tokens.get('csrfToken'),
summary : opts.EditSummary,
text : ($('#TargetForm fuw.[name="text"]')[0])UploadOptions.valuetext
 
}
Line 2,416 ⟶ 2,355:
// onload hook function, loading this script
// ========================================================
$mw.loader.using(['mediawiki.api']).then(function() {
$(function() {
if (fuwGet('UploadScriptArea')) {
window.fuw = new fuwGlobal();
if (! window.fuw.disabled) {
fuwUpdateOptions();
fuwUpdateOptions();
}
}
}
});
});