User:Animum/flickrreview.js
Jump to navigation
Jump to search
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.
Documentation for this user script can be added at User:Animum/flickrreview. |
- Report page listing warnings and errors.
//Yes, I know Patstuart has already made one; I just want my own custom copy.
function zeroPad(num) {
return ("0" + num).slice(-2);
}
function flickrReview(isFree, otherLicense, changedLicense) {
var date = new Date();
var templates = new RegExp("(\{\{User:FlickreviewR.*\}\})|(\{\{[fF]lickrr?eview.*?\}\})", "g");
var reviewed = templates.test(document.forms["editform"].wpTextbox1.value);
var addedContent = "\{\{flickrreview\|" + wgUserName + "\|on " + date.getUTCFullYear() + "-" + zeroPad(date.getUTCMonth()+1) + "-" + zeroPad(date.getUTCDate()) + (isFree == false ? "\|" + otherLicense + (changedLicense.length > 0 ? "\|changed=" + changedLicense + "\}\}" : "\}\}") : "\}\}");
if(reviewed) {
document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value.replace(templates, addedContent);
} else {
document.forms["editform"].wpTextbox1.value += "\n" + addedContent;
}
document.forms["editform"].wpSummary.value = "Image is" + (!isFree ? "n't" : "") + " compatible with the licensing policies of Wikimedia Commons.";
document.forms["editform"].wpMinoredit.checked = true;
//document.forms["editform"].submit();
}
function submitData() {
flickrReview(document.getElementById("isFree").checked, document.getElementById("otherLicense").value, document.getElementById("changedLicense").value);
}
function isFreeOnChange() {
document.getElementById("otherLicense").disabled = document.getElementById("isFree").checked;
}
function buildReviewForm() {
document.getElementById("contentSub").innerHTML = '<fieldset style="font-size:10pt;color:black">'
+ '<legend style="color:black">Flickr review</legend>'
+ '<table style="background-color:transparent">'
+ '<tr><td><input type="checkbox" checked=true name="isFree" id="isFree" onchange="isFreeOnChange()" /> Image is compatible with commons</td></tr>'
+ '<tr><td>Other license <small>(incompatible license this image uses)</small>:<sup>†</sup></td><td><input type="text" name="otherLicense" id="otherLicense" /></td></tr>'
+ '<tr><td>Changed license <small>(image was uploaded under this license, but was changed)</small>:<b>*</b></td><td><input type="text" name="changedLicense" id="changedLicense" /></td></tr>'
+ '<tr><td><input type="button" value="Submit" onclick="submitData()" /></td></tr>'
+ '<tr><br /></tr>'
+ '<tr><td style="font-size:8pt"><i>* optional field</i></td></tr>'
+ '<tr><td style="font-size:8pt"><i><sup>†</sup> must be specified if image is incompatible</i></td></tr>'
+ '</table>'
+ '</fieldset>';
document.getElementById("otherLicense").disabled = true;
}
addOnloadHook(function() {
if(wgNamespaceNumber == 6) {
if(/[?&]action=edit/.test(location.href)) {
if(!/&flickrreview=1/.test(location.href)) {
mw.util.addPortletLink("p-cactions", "javascript:buildReviewForm()", "review", "ca-flickrreview");
} else {
buildReviewForm();
}
}
if(wgAction == "view") {
mw.util.addPortletLink("p-cactions", wgScript + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&flickrreview=1", "review", "ca-flickrreview");
}
}
});