„Benutzer:Lustiger seth/unsigned.js“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
adapted to new mw-interface |
code cosmetica; replaced global wg-vars; init unsigned_edit_choice |
||
Zeile 21: | Zeile 21: | ||
// Dual-licensed under the terms of the GFDL v1.2 or the GPL v2. |
// Dual-licensed under the terms of the GFDL v1.2 or the GPL v2. |
||
if(wgNamespaceNumber>0 && |
if(mw.config.get('wgNamespaceNumber') > 0 && |
||
( mw.config.get('wgAction') === 'edit' |
|||
⚫ | |||
var ssubst = (typeof ssubst == 'undefined'||ssubst)? 'subst:' : ''; |
var ssubst = (typeof ssubst == 'undefined'||ssubst)? 'subst:' : ''; |
||
var max_history_entries = (typeof max_history_entries != 'number' || max_history_entries>36 || max_history_entries<1)? 36 : max_history_entries; |
var max_history_entries = |
||
(typeof max_history_entries != 'number' |
|||
|| max_history_entries > 36 |
|||
|| max_history_entries < 1) ? 36 : max_history_entries; |
|||
var display_used = (display_used!=0 && display_used!=1) ? 1 : display_used; |
var display_used = (display_used!=0 && display_used!=1) ? 1 : display_used; |
||
var max_nofe = |
var max_nofe = 500; // number of fetched edits |
||
function get_last_sunday_of_month(year, month){ |
function get_last_sunday_of_month(year, month){ |
||
var last_sunday = -1; |
var last_sunday = -1; |
||
var d = new Date(year,month,22); |
var d = new Date(year,month,22); |
||
for(var day=1; month==d.getUTCMonth(); ++day){ |
for(var day=1; month == d.getUTCMonth(); ++day){ |
||
if(d.getDay()==0) last_sunday = 22-1+day; |
if(d.getDay() == 0) last_sunday = 22-1+day; |
||
d = new Date(Date.UTC(year,month,22,0,0,0)+day*24*60*60*1000); |
d = new Date(Date.UTC(year,month,22,0,0,0)+day*24*60*60*1000); |
||
} |
} |
||
Zeile 40: | Zeile 45: | ||
function is_dst(year, month, day, hours){ |
function is_dst(year, month, day, hours){ |
||
var to_check = Date.UTC(year, month, day, hours, 0, 0); |
var to_check = Date.UTC(year, month, day, hours, 0, 0); |
||
var begin_dst = Date.UTC(year, 2, get_last_sunday_of_month(year, 2), 1, 0, 0); |
// 2 = march |
||
var begin_dst = Date.UTC(year, 2, get_last_sunday_of_month(year, 2), 1, 0, 0); |
|||
// 9 = october |
|||
var end_dst = Date.UTC(year, 9, get_last_sunday_of_month(year, 9), 1, 0, 0); |
var end_dst = Date.UTC(year, 9, get_last_sunday_of_month(year, 9), 1, 0, 0); |
||
return (begin_dst<=to_check && to_check<end_dst); |
return (begin_dst<=to_check && to_check<end_dst); |
||
} |
} |
||
Zeile 47: | Zeile 54: | ||
function is_elem_of_arr(elem, arr){ |
function is_elem_of_arr(elem, arr){ |
||
for(var i=0;i<arr.length;++i){ |
for(var i=0;i<arr.length;++i){ |
||
if(arr[i]==elem) |
if(arr[i] == elem) |
||
return 1; |
return 1; |
||
} |
} |
||
Zeile 57: | Zeile 64: | ||
if(document.editform){ |
if(document.editform){ |
||
var txtarea = document.editform.wpTextbox1.value; |
var txtarea = document.editform.wpTextbox1.value; |
||
// |
// localizable strings start |
||
if(mw.config.get('wgContentLanguage')=='de') |
if(mw.config.get('wgContentLanguage') == 'de') |
||
sigs = txtarea.match(/\d?\d[:.]\d\d, \d?\d\. (?:jan|feb|mär|apr|mai|jun|jul|aug|sep|okt|nov|dez)\.? 2\d{3}(?: \(CES?T\))?|2\d{3}-\d\d-\d\d[T ]?\d\d:\d\d(?:Z|[-+]\d\d:\d\d)?/gi); |
sigs = txtarea.match(/\d?\d[:.]\d\d, \d?\d\. (?:jan|feb|mär|apr|mai|jun|jul|aug|sep|okt|nov|dez)\.? 2\d{3}(?: \(CES?T\))?|2\d{3}-\d\d-\d\d[T ]?\d\d:\d\d(?:Z|[-+]\d\d:\d\d)?/gi); |
||
else |
else |
||
sigs = txtarea.match(/\d?\d[:.]\d\d, \d?\d (?:january|february|march|april|may|june|july|august|september|october|november|december) 2\d{3}(?: \(UTC\))?|2\d{3}-\d\d-\d\d[T ]?\d\d:\d\d(?:Z|[-+]\d\d:\d\d)?/gi); |
sigs = txtarea.match(/\d?\d[:.]\d\d, \d?\d (?:january|february|march|april|may|june|july|august|september|october|november|december) 2\d{3}(?: \(UTC\))?|2\d{3}-\d\d-\d\d[T ]?\d\d:\d\d(?:Z|[-+]\d\d:\d\d)?/gi); |
||
// |
// localizable strings end |
||
} |
} |
||
return(sigs==null)? new Array() : sigs; |
return(sigs == null)? new Array() : sigs; |
||
} |
} |
||
Zeile 71: | Zeile 78: | ||
var months = new Object(); |
var months = new Object(); |
||
var re_normal; |
var re_normal; |
||
// |
// localizable strings start |
||
if(mw.config.get('wgContentLanguage')=='de'){ |
if(mw.config.get('wgContentLanguage') == 'de'){ |
||
months["jan"] = 1; |
months["jan"] = 1; |
||
months["feb"] = 2; |
months["feb"] = 2; |
||
Zeile 101: | Zeile 108: | ||
re_normal = /(\d?\d)[:.](\d\d), (\d?\d) (january|february|march|april|may|june|july|august|september|october|november|december) (2\d{3})((?: \(UTC\))?)/i; |
re_normal = /(\d?\d)[:.](\d\d), (\d?\d) (january|february|march|april|may|june|july|august|september|october|november|december) (2\d{3})((?: \(UTC\))?)/i; |
||
} |
} |
||
// |
// localizable strings end |
||
var re_iso = /(2\d{3})-(\d\d)-(\d\d)[T ]?(\d\d):(\d\d)((?:Z|[-+]\d\d:\d\d)?)/; |
var re_iso = /(2\d{3})-(\d\d)-(\d\d)[T ]?(\d\d):(\d\d)((?:Z|[-+]\d\d:\d\d)?)/; |
||
var year, month, day, h, min, date_obj, offset; |
var year, month, day, h, min, date_obj, offset; |
||
Zeile 113: | Zeile 120: | ||
year = RegExp.$5; |
year = RegExp.$5; |
||
offset = RegExp.$6; |
offset = RegExp.$6; |
||
offset = (offset==' (CEST)')? 2 : ((offset==' (CET)')? 1 : ((offset==' (UTC)')? 0 : '?')); |
offset = (offset == ' (CEST)') ? 2 : |
||
((offset == ' (CET)') ? 1 : |
|||
((offset == ' (UTC)') ? 0 : |
|||
'?')); |
|||
}else if(re_iso.exec(sigs[i])){ |
}else if(re_iso.exec(sigs[i])){ |
||
year = RegExp.$1; |
year = RegExp.$1; |
||
Zeile 121: | Zeile 131: | ||
min = RegExp.$5; |
min = RegExp.$5; |
||
offset = RegExp.$6; |
offset = RegExp.$6; |
||
offset = (offset=='Z')? 0 : ((offset=='')? '?': ((offset.substr(0,1)=='-')? -1:1)*((1*offset.substr(1,2))+(offset.substr(4,2)/60))); |
offset = (offset == 'Z') ? 0 : |
||
((offset == '') ? '?': |
|||
((offset.substr(0,1) == '-') ? -1 : 1 |
|||
) * ((1 * offset.substr(1,2)) + (offset.substr(4,2) / 60))); |
|||
} |
} |
||
date_obj = new Date(year, month-1, day, h, min, 0); |
date_obj = new Date(year, month-1, day, h, min, 0); |
||
if(offset=='?'){ |
if(offset == '?'){ |
||
sigs_ms.push(date_obj.getTime() - 1*60*60*1000); |
sigs_ms.push(date_obj.getTime() - 1*60*60*1000); |
||
sigs_ms.push(date_obj.getTime() - 2*60*60*1000); |
sigs_ms.push(date_obj.getTime() - 2*60*60*1000); |
||
Zeile 144: | Zeile 157: | ||
function addSigWikiCode(){ |
function addSigWikiCode(){ |
||
// |
// from rev 28011729 of |
||
// [[:en:Wikipedia:WikiProject_User_scripts/Scripts/Get_tidy_title]] |
|||
function aswcGet_tidy_title(){ // |
function aswcGet_tidy_title(){ // get the URL version of the page title |
||
var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; |
var editlk = |
||
document.getElementById('ca-edit').getElementsByTagName('a')[0].href; |
|||
// cut everything up to "title=" from the start and everything past "&action=edit" from the end |
// cut everything up to "title=" from the start and everything past |
||
// "&action=edit" from the end |
|||
editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit') |
editlk = editlk.substring( |
||
editlk.indexOf('title=') + 6, |
|||
editlk.lastIndexOf('&action=edit') |
|||
⚫ | |||
return editlk // |
return editlk; // the result from this function might be needed unescape()ed |
||
}; |
}; |
||
// |
// localizable strings start |
||
var lsMonth_names = ["January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December "], |
var lsMonth_names = ["January ", "February ", "March ", "April ", "May ", |
||
"June ", "July ", "August ", "September ", "October ", "November ", |
|||
"December "], |
|||
lsConflict = "Edit conflict.", |
lsConflict = "Edit conflict.", |
||
lsDialog1 = "Please select an edit below or type '>' for older edits:\n\n", |
lsDialog1 = "Please select an edit below or type '>' for older edits:\n\n", |
||
Zeile 160: | Zeile 181: | ||
lsNoXMLHTTP = "Couldn't get XMLHTTP!", |
lsNoXMLHTTP = "Couldn't get XMLHTTP!", |
||
lsMinor = "m "; |
lsMinor = "m "; |
||
if(mw.config.get('wgContentLanguage')=='de'){ |
if(mw.config.get('wgContentLanguage') == 'de'){ |
||
lsMonth_names = ["Jan. ", "Feb. ", "Mär. ", "Apr. ", "Mai ", "Jun. ", "Jul. ", |
lsMonth_names = ["Jan. ", "Feb. ", "Mär. ", "Apr. ", "Mai ", "Jun. ", "Jul. ", |
||
"Aug. ", "Sep. ", "Okt. ", "Nov. ", "Dez. "]; |
|||
} |
} |
||
if(mw.config.get('wgUserLanguage')=='de'){ |
if(mw.config.get('wgUserLanguage') == 'de'){ |
||
lsConflict = "Edit-Konflikt.", |
lsConflict = "Edit-Konflikt.", |
||
lsDialog1 = "Bitte wähle einen Edit oder tippe '>' für ältere Edits:\n\n", |
lsDialog1 = "Bitte wähle einen Edit oder tippe '>' für ältere Edits:\n\n", |
||
Zeile 171: | Zeile 193: | ||
lsMinor = "K "; |
lsMinor = "K "; |
||
} |
} |
||
// |
// localizable strings end |
||
// try to use native XMLHTTP |
|||
var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : false; |
|||
if(!xmlhttp && window.ActiveXObject){ // ActiveX XMLHTTP |
if(!xmlhttp && window.ActiveXObject){ // ActiveX XMLHTTP |
||
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); |
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); |
||
if(!xmlhttp) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); |
if(!xmlhttp) |
||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); |
|||
} |
} |
||
if(!xmlhttp) return alert(lsNoXMLHTTP); // No XMLHTTP |
if(!xmlhttp) |
||
return alert(lsNoXMLHTTP); // No XMLHTTP |
|||
xmlhttp.open("GET", mw.config.get('wgScriptPath')+"/api.php?format=xml&action=query&prop=revisions&rvlimit=" + max_nofe + "&rvcomments&titles=" + aswcGet_tidy_title()); |
// get timestamp, user, summary of last x edits |
||
xmlhttp.open("GET", mw.config.get('wgScriptPath') + |
|||
"/api.php?format=xml&action=query&prop=revisions&rvlimit=" + max_nofe + |
|||
"&rvcomments&titles=" + aswcGet_tidy_title()); |
|||
var history_offset = 0; |
var history_offset = 0; |
||
xmlhttp.onreadystatechange = function(){ |
xmlhttp.onreadystatechange = function(){ |
||
if(xmlhttp.readyState!=4) return; |
if(xmlhttp.readyState!=4) |
||
return; |
|||
if(!xmlhttp) return alert("Error: "+lsNoXMLHTTP + "\n" + xmlhttp.status + ": " + xmlhttp.statusText |
if(!xmlhttp) |
||
return alert("Error: " + lsNoXMLHTTP + "\n" + xmlhttp.status + ": " + |
|||
xmlhttp.statusText); // no XMLHTTP |
|||
var xmldoc = xmlhttp.responseXML; |
var xmldoc = xmlhttp.responseXML; |
||
// IE workaround suggested by [[User:Olliminatore]] |
// IE workaround suggested by [[User:Olliminatore]] |
||
// !FIXME: IE6 can't read XML??? |
|||
if(!xmldoc.documentElement && window.ActiveXObject){ |
|||
document.body.style.backgroundColor = "#CCCCFF"; // |
document.body.style.backgroundColor = "#CCCCFF"; // debugging aid |
||
xmldoc = new ActiveXObject("Microsoft.XMLDOM"); |
xmldoc = new ActiveXObject("Microsoft.XMLDOM"); |
||
xmldoc.async = false; |
xmldoc.async = false; |
||
xmldoc.loadXML(xmlhttp.responseText); |
xmldoc.loadXML(xmlhttp.responseText); |
||
} |
} |
||
var revisions = xmldoc.documentElement.getElementsByTagName("rev"); |
// get the revisions |
||
var revisions = xmldoc.documentElement.getElementsByTagName("rev"); |
|||
if(revisions.length < 1) return alert(lsNoRev); // |
if(revisions.length < 1) |
||
return alert(lsNoRev); // no revisions |
|||
// get rid of non-numeric characters in timestamp |
|||
var t = revisions[0].getAttribute("timestamp").replace(/[^0-9]/g, ""); |
|||
⚫ | |||
// detect an edit conflict |
|||
⚫ | |||
return alert(lsConflict); |
return alert(lsConflict); |
||
var dialog_text; |
var dialog_text; |
||
Zeile 202: | Zeile 238: | ||
var minor; |
var minor; |
||
var is_used; |
var is_used; |
||
var nos2n; |
var nos2n; // mapping of number of signatures -> number of all entries |
||
var sigdates = sig2ms(get_all_sig_dates_from_textarea()); |
var sigdates = sig2ms(get_all_sig_dates_from_textarea()); |
||
var update_dialog_text = 1; |
var update_dialog_text = 1; |
||
Zeile 210: | Zeile 246: | ||
dialog_text = lsDialog1; |
dialog_text = lsDialog1; |
||
nos2n = []; |
nos2n = []; |
||
// extract edit data and build dialog text |
|||
for(var n=history_offset; n<revisions.length; ++n){ |
|||
minor = (revisions[n].getAttribute("minor") != null)? lsMinor : ""; |
minor = (revisions[n].getAttribute("minor") != null)? lsMinor : ""; |
||
edit_data[n] = {timestamp: revisions[n].getAttribute("timestamp").replace(/[^0-9]/g, ""), |
edit_data[n] = { |
||
timestamp: revisions[n].getAttribute("timestamp").replace(/[^0-9]/g, ""), |
|||
user: revisions[n].getAttribute("user"), |
|||
comment: revisions[n].getAttribute("comment") |
|||
⚫ | |||
⚫ | |||
is_used = |
|||
⚫ | |||
'(used) ' : ''; |
|||
if(is_used == '' || display_used == 1){ |
|||
nos2n.push(n); |
nos2n.push(n); |
||
dialog_text += ("[" + (nos2n.length-1).toString(max_history_entries).toUpperCase() + "] " + edit_data[n].timestamp.replace(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/g, "$1-$2-$3 $4:$5:$6" |
dialog_text += ("[" + |
||
(nos2n.length-1).toString(max_history_entries).toUpperCase() + |
|||
"] " + |
|||
edit_data[n].timestamp.replace( |
|||
/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/g, |
|||
"$1-$2-$3 $4:$5:$6" |
|||
) + |
|||
edit_data[n].user + ": " + minor + ((edit_data[n].comment == null)? "–": edit_data[n].comment)).substring(0, 80) + "\n"; |
|||
" " + is_used + edit_data[n].user + ": " + minor + |
|||
((edit_data[n].comment == null) ? "–" : |
|||
edit_data[n].comment) |
|||
).substring(0, 80) + "\n"; |
|||
} |
} |
||
if(nos2n.length==max_history_entries) |
if(nos2n.length == max_history_entries) |
||
break; |
|||
} |
} |
||
} |
} |
||
var unsigned_edit_choice = null; |
|||
if(edit_data.length == 1) |
|||
unsigned_edit_choice = 0; // no choice |
|||
else // if(is_gecko) // for Mozilla, def in wikibits.js |
else // if(is_gecko) // for Mozilla, def in wikibits.js |
||
unsigned_edit_choice = prompt(dialog_text + "\n" + lsDialog2, "0"); |
|||
//else{ // for IE or other |
//else{ // for IE or other |
||
// alert(dialog_text); |
// alert(dialog_text); |
||
Zeile 238: | Zeile 291: | ||
continue; |
continue; |
||
}else if(unsigned_edit_choice == '<'){ |
}else if(unsigned_edit_choice == '<'){ |
||
// actually that's not correct, but it should be sufficient |
|||
history_offset = Math.max(0, history_offset-max_history_entries); |
|||
update_dialog_text = 1; |
update_dialog_text = 1; |
||
continue; |
continue; |
||
}else if(isNaN(unsigned_edit_choice = parseInt(unsigned_edit_choice, max_history_entries))){ |
}else if(isNaN(unsigned_edit_choice = |
||
parseInt(unsigned_edit_choice, max_history_entries))){ |
|||
return alert(lsInvalid1); // |
return alert(lsInvalid1); // non-numeric input |
||
} else{ |
} else{ |
||
var unsigned_edit = edit_data[nos2n[unsigned_edit_choice]]; |
var unsigned_edit = edit_data[nos2n[unsigned_edit_choice]]; |
||
Zeile 252: | Zeile 307: | ||
var day = (t.substring(6, 8) - 0); |
var day = (t.substring(6, 8) - 0); |
||
var hours = parseInt(t.substring(8, 10), 10); |
var hours = parseInt(t.substring(8, 10), 10); |
||
var tzcode = 'UTC'; // |
var tzcode = 'UTC'; // the data returned by app.php is UTC |
||
// |
// localizable strings start |
||
if(mw.config.get('wgContentLanguage')=='de'){ |
if(mw.config.get('wgContentLanguage') == 'de'){ |
||
// add timezone offset |
// add timezone offset |
||
// daylight saving time (true, false) |
|||
var time_offset = (is_dst(year, month-1, day, hours)) ? 2 : 1; |
|||
// LOCALIZABLE STRINGS END |
|||
// localizable strings end |
|||
tzcode = (time_offset == 2)? 'CEST' : 'CET'; |
tzcode = (time_offset == 2)? 'CEST' : 'CET'; |
||
// get UTC time in msec |
// get UTC time in msec |
||
Zeile 270: | Zeile 326: | ||
day = ''+day+'.'; |
day = ''+day+'.'; |
||
} |
} |
||
if(hours<10) hours = '0'+hours; |
if(hours < 10) |
||
hours = '0' + hours; |
|||
// format and insert the tag |
|||
mw.toolbar.insertTags("{{"+ssubst+"unsigned|" + unsigned_edit.user + "|" + hours + ":" + t.substring(10, 12) + ", " + day + " " + lsMonth_names[month - 1] + year + " (" + tzcode + ")|ALT=nicht}}", "", ""); |
mw.toolbar.insertTags( |
||
"{{"+ssubst+"unsigned|" + unsigned_edit.user + "|" + hours + ":" + |
|||
t.substring(10, 12) + ", " + day + " " + lsMonth_names[month - 1] + |
|||
year + " (" + tzcode + ")|ALT=nicht}}", "", ""); |
|||
return; |
return; |
||
Zeile 280: | Zeile 340: | ||
}; |
}; |
||
jQuery( function() { |
jQuery( |
||
function() { |
|||
mw.loader.using( [ "mediawiki.toolbar", "mediawiki.util" ], |
mw.loader.using( [ "mediawiki.toolbar", "mediawiki.util" ], |
||
function() { |
function() { |
||
var unsigned_title = 'Unsigned'; |
var unsigned_title = 'Unsigned'; |
||
var unsigned_tooltip = 'add a missing signature'; |
var unsigned_tooltip = 'add a missing signature'; |
||
if(mw.config.get('wgUserLanguage')=='de'){ |
if(mw.config.get('wgUserLanguage') == 'de'){ |
||
unsigned_title = 'Unsigniert'; |
unsigned_title = 'Unsigniert'; |
||
unsigned_tooltip = 'Trage eine fehlende Signatur nach.'; |
unsigned_tooltip = 'Trage eine fehlende Signatur nach.'; |
||
} |
|||
if(!mw.config.get('wgIsArticle')){ |
|||
mw.util.addPortletLink( |
|||
'p-cactions', |
|||
"javascript:addSigWikiCode();", |
|||
/* localizable strings start */ |
|||
unsigned_title , |
|||
"ca-unsigned", |
|||
unsigned_tooltip, "" |
|||
/* localizable strings end */ |
|||
); |
|||
} |
|||
} |
} |
||
); |
|||
⚫ | |||
} |
|||
mw.util.addPortletLink('p-cactions', "javascript:addSigWikiCode();", /* LOCALIZABLE STRINGS START */ unsigned_title , "ca-unsigned", unsigned_tooltip, "" /* LOCALIZABLE STRINGS END */); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
//</nowiki></pre> |
//</nowiki></pre> |
Version vom 8. Februar 2015, 13:00 Uhr
/* ******** unsigned.js ******** */
//
// Usage:
// * see http://de.wikipedia.org/wiki/user_talk:lustiger_seth/unsigned.js#Benutzung
// Just put the following line
// importScriptURI('//de.wikipedia.org/w/index.php?title=user:lustiger_seth/unsigned.js&action=raw&ctype=text/javascript&smaxage=2678400');
// without the beginning "// " to your [[Special:MyPage/common.js]] (or [[Special:MyPage/monobook.js]] or [[Special:MyPage/vector.js]])
//
// Description:
// * MARK SEMI-AUTOMATICALLY UNSIGNED COMMENTS ON TALK PAGES
//
// Authors:
// * based on [[user:Olliminatore/unsigned.js]] (old and buggy version 1.3) which was based on [[:en:User:Invitatious/unsigned2.js]].
// * updated/changed by [[user:lustiger_seth|seth]]
//
// New features in this version (compared to [[user:Olliminatore/unsigned.js]]):
// * You can now choose any signature (it doesn't need to be one of the last 10 any longer). Used signatures will be marked. Some bugfixes, see history (here and monobook.js) and talk page.
// * compatible with vector and monobook
//
//<pre><nowiki>
// Dual-licensed under the terms of the GFDL v1.2 or the GPL v2.
if(mw.config.get('wgNamespaceNumber') > 0 &&
( mw.config.get('wgAction') === 'edit'
|| mw.config.get('wgAction') === 'submit')){
var ssubst = (typeof ssubst == 'undefined'||ssubst)? 'subst:' : '';
var max_history_entries =
(typeof max_history_entries != 'number'
|| max_history_entries > 36
|| max_history_entries < 1) ? 36 : max_history_entries;
var display_used = (display_used!=0 && display_used!=1) ? 1 : display_used;
var max_nofe = 500; // number of fetched edits
function get_last_sunday_of_month(year, month){
var last_sunday = -1;
var d = new Date(year,month,22);
for(var day=1; month == d.getUTCMonth(); ++day){
if(d.getDay() == 0) last_sunday = 22-1+day;
d = new Date(Date.UTC(year,month,22,0,0,0)+day*24*60*60*1000);
}
return last_sunday;
}
// is_daylight_saving_time
function is_dst(year, month, day, hours){
var to_check = Date.UTC(year, month, day, hours, 0, 0);
// 2 = march
var begin_dst = Date.UTC(year, 2, get_last_sunday_of_month(year, 2), 1, 0, 0);
// 9 = october
var end_dst = Date.UTC(year, 9, get_last_sunday_of_month(year, 9), 1, 0, 0);
return (begin_dst<=to_check && to_check<end_dst);
}
function is_elem_of_arr(elem, arr){
for(var i=0;i<arr.length;++i){
if(arr[i] == elem)
return 1;
}
return 0;
}
function get_all_sig_dates_from_textarea(){
var sigs = new Array();
if(document.editform){
var txtarea = document.editform.wpTextbox1.value;
// localizable strings start
if(mw.config.get('wgContentLanguage') == 'de')
sigs = txtarea.match(/\d?\d[:.]\d\d, \d?\d\. (?:jan|feb|mär|apr|mai|jun|jul|aug|sep|okt|nov|dez)\.? 2\d{3}(?: \(CES?T\))?|2\d{3}-\d\d-\d\d[T ]?\d\d:\d\d(?:Z|[-+]\d\d:\d\d)?/gi);
else
sigs = txtarea.match(/\d?\d[:.]\d\d, \d?\d (?:january|february|march|april|may|june|july|august|september|october|november|december) 2\d{3}(?: \(UTC\))?|2\d{3}-\d\d-\d\d[T ]?\d\d:\d\d(?:Z|[-+]\d\d:\d\d)?/gi);
// localizable strings end
}
return(sigs == null)? new Array() : sigs;
}
function sig2ms(sigs){
var sigs_ms = new Array();
var months = new Object();
var re_normal;
// localizable strings start
if(mw.config.get('wgContentLanguage') == 'de'){
months["jan"] = 1;
months["feb"] = 2;
months["mär"] = 3;
months["apr"] = 4;
months["mai"] = 5;
months["jun"] = 6;
months["jul"] = 7;
months["aug"] = 8;
months["sep"] = 9;
months["okt"] = 10;
months["nov"] = 11;
months["dez"] = 12;
re_normal = /(\d?\d)[:.](\d\d), (\d?\d)\. (jan|feb|mär|apr|mai|jun|jul|aug|sep|okt|nov|dez)\.? (2\d{3})((?: \((?:UTC|CES?T)\))?)/i;
}else{
months["january"] = 1;
months["february"] = 2;
months["march"] = 3;
months["april"] = 4;
months["may"] = 5;
months["june"] = 6;
months["july"] = 7;
months["august"] = 8;
months["september"] = 9;
months["october"] = 10;
months["november"] = 11;
months["december"] = 12;
re_normal = /(\d?\d)[:.](\d\d), (\d?\d) (january|february|march|april|may|june|july|august|september|october|november|december) (2\d{3})((?: \(UTC\))?)/i;
}
// localizable strings end
var re_iso = /(2\d{3})-(\d\d)-(\d\d)[T ]?(\d\d):(\d\d)((?:Z|[-+]\d\d:\d\d)?)/;
var year, month, day, h, min, date_obj, offset;
for(var i=0;i<sigs.length;++i){
if(re_normal.exec(sigs[i])){
h = RegExp.$1;
min = RegExp.$2;
day = RegExp.$3;
month = RegExp.$4;
month = months[month.toLowerCase()];
year = RegExp.$5;
offset = RegExp.$6;
offset = (offset == ' (CEST)') ? 2 :
((offset == ' (CET)') ? 1 :
((offset == ' (UTC)') ? 0 :
'?'));
}else if(re_iso.exec(sigs[i])){
year = RegExp.$1;
month = RegExp.$2;
day = RegExp.$3;
h = RegExp.$4;
min = RegExp.$5;
offset = RegExp.$6;
offset = (offset == 'Z') ? 0 :
((offset == '') ? '?':
((offset.substr(0,1) == '-') ? -1 : 1
) * ((1 * offset.substr(1,2)) + (offset.substr(4,2) / 60)));
}
date_obj = new Date(year, month-1, day, h, min, 0);
if(offset == '?'){
sigs_ms.push(date_obj.getTime() - 1*60*60*1000);
sigs_ms.push(date_obj.getTime() - 2*60*60*1000);
}else
sigs_ms.push(date_obj.getTime() - offset*60*60*1000);
}
return sigs_ms;
}
function timestamp2ms(t){
var year = t.substring(0, 4);
var month = t.substring(4, 6);
var day = (t.substring(6, 8) - 0);
var hours = parseInt(t.substring(8, 10), 10);
var min = parseInt(t.substring(10, 12), 10);
ms = new Date(year, month-1, day, hours, min, 0).getTime();
return ms;
}
function addSigWikiCode(){
// from rev 28011729 of
// [[:en:Wikipedia:WikiProject_User_scripts/Scripts/Get_tidy_title]]
function aswcGet_tidy_title(){ // get the URL version of the page title
var editlk =
document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
// cut everything up to "title=" from the start and everything past
// "&action=edit" from the end
editlk = editlk.substring(
editlk.indexOf('title=') + 6,
editlk.lastIndexOf('&action=edit')
);
return editlk; // the result from this function might be needed unescape()ed
};
// localizable strings start
var lsMonth_names = ["January ", "February ", "March ", "April ", "May ",
"June ", "July ", "August ", "September ", "October ", "November ",
"December "],
lsConflict = "Edit conflict.",
lsDialog1 = "Please select an edit below or type '>' for older edits:\n\n",
lsDialog2 = "Unsigned edit number:",
lsInvalid1 = "Please enter a valid number or cancel this operation.",
lsNoRev = "No revisions found. Does the page exist?",
lsNoXMLHTTP = "Couldn't get XMLHTTP!",
lsMinor = "m ";
if(mw.config.get('wgContentLanguage') == 'de'){
lsMonth_names = ["Jan. ", "Feb. ", "Mär. ", "Apr. ", "Mai ", "Jun. ", "Jul. ",
"Aug. ", "Sep. ", "Okt. ", "Nov. ", "Dez. "];
}
if(mw.config.get('wgUserLanguage') == 'de'){
lsConflict = "Edit-Konflikt.",
lsDialog1 = "Bitte wähle einen Edit oder tippe '>' für ältere Edits:\n\n",
lsDialog2 = "Unsigned Edit-Nummer:",
lsInvalid1 = "Bitte eine gültige Zahl eintragen oder diese Operation abbrechen.",
lsNoRev = "Keine Veränderung gefunden. Besteht die Seite?",
lsMinor = "K ";
}
// localizable strings end
// try to use native XMLHTTP
var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : false;
if(!xmlhttp && window.ActiveXObject){ // ActiveX XMLHTTP
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
if(!xmlhttp)
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if(!xmlhttp)
return alert(lsNoXMLHTTP); // No XMLHTTP
// get timestamp, user, summary of last x edits
xmlhttp.open("GET", mw.config.get('wgScriptPath') +
"/api.php?format=xml&action=query&prop=revisions&rvlimit=" + max_nofe +
"&rvcomments&titles=" + aswcGet_tidy_title());
var history_offset = 0;
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState!=4)
return;
if(!xmlhttp)
return alert("Error: " + lsNoXMLHTTP + "\n" + xmlhttp.status + ": " +
xmlhttp.statusText); // no XMLHTTP
var xmldoc = xmlhttp.responseXML;
// IE workaround suggested by [[User:Olliminatore]]
// !FIXME: IE6 can't read XML???
if(!xmldoc.documentElement && window.ActiveXObject){
document.body.style.backgroundColor = "#CCCCFF"; // debugging aid
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async = false;
xmldoc.loadXML(xmlhttp.responseText);
}
// get the revisions
var revisions = xmldoc.documentElement.getElementsByTagName("rev");
if(revisions.length < 1)
return alert(lsNoRev); // no revisions
// get rid of non-numeric characters in timestamp
var t = revisions[0].getAttribute("timestamp").replace(/[^0-9]/g, "");
// detect an edit conflict
if(t != document.editform.wpEdittime.value)
return alert(lsConflict);
var dialog_text;
var edit_data = [];
var minor;
var is_used;
var nos2n; // mapping of number of signatures -> number of all entries
var sigdates = sig2ms(get_all_sig_dates_from_textarea());
var update_dialog_text = 1;
while(true){
if(update_dialog_text){
update_dialog_text = 0;
dialog_text = lsDialog1;
nos2n = [];
// extract edit data and build dialog text
for(var n=history_offset; n<revisions.length; ++n){
minor = (revisions[n].getAttribute("minor") != null)? lsMinor : "";
edit_data[n] = {
timestamp: revisions[n].getAttribute("timestamp").replace(/[^0-9]/g, ""),
user: revisions[n].getAttribute("user"),
comment: revisions[n].getAttribute("comment")
};
is_used =
(is_elem_of_arr(timestamp2ms(edit_data[n].timestamp), sigdates)) ?
'(used) ' : '';
if(is_used == '' || display_used == 1){
nos2n.push(n);
dialog_text += ("[" +
(nos2n.length-1).toString(max_history_entries).toUpperCase() +
"] " +
edit_data[n].timestamp.replace(
/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/g,
"$1-$2-$3 $4:$5:$6"
) +
" " + is_used + edit_data[n].user + ": " + minor +
((edit_data[n].comment == null) ? "–" :
edit_data[n].comment)
).substring(0, 80) + "\n";
}
if(nos2n.length == max_history_entries)
break;
}
}
var unsigned_edit_choice = null;
if(edit_data.length == 1)
unsigned_edit_choice = 0; // no choice
else // if(is_gecko) // for Mozilla, def in wikibits.js
unsigned_edit_choice = prompt(dialog_text + "\n" + lsDialog2, "0");
//else{ // for IE or other
// alert(dialog_text);
// var unsigned_edit_choice = prompt(lsDialog2, "0");
//}
if(unsigned_edit_choice == null){
return; // Cancel button
}else if(unsigned_edit_choice == '>'){
history_offset = Math.min(revisions.length-1, nos2n[nos2n.length-1]);
update_dialog_text = 1;
continue;
}else if(unsigned_edit_choice == '<'){
// actually that's not correct, but it should be sufficient
history_offset = Math.max(0, history_offset-max_history_entries);
update_dialog_text = 1;
continue;
}else if(isNaN(unsigned_edit_choice =
parseInt(unsigned_edit_choice, max_history_entries))){
return alert(lsInvalid1); // non-numeric input
} else{
var unsigned_edit = edit_data[nos2n[unsigned_edit_choice]];
}
t = unsigned_edit.timestamp; // So the full name doesn't have to be used
var year = t.substring(0, 4);
var month = t.substring(4, 6);
var day = (t.substring(6, 8) - 0);
var hours = parseInt(t.substring(8, 10), 10);
var tzcode = 'UTC'; // the data returned by app.php is UTC
// localizable strings start
if(mw.config.get('wgContentLanguage') == 'de'){
// add timezone offset
// daylight saving time (true, false)
var time_offset = (is_dst(year, month-1, day, hours)) ? 2 : 1;
// localizable strings end
tzcode = (time_offset == 2)? 'CEST' : 'CET';
// get UTC time in msec
nd = new Date(year, month-1, day, hours).getTime();
// create new Date object for different
// using timezone offset
nd = new Date(nd + 3600000*time_offset);
year = nd.getFullYear();
month = 1+nd.getMonth();
day = nd.getDate();
hours = nd.getHours();
day = ''+day+'.';
}
if(hours < 10)
hours = '0' + hours;
// format and insert the tag
mw.toolbar.insertTags(
"{{"+ssubst+"unsigned|" + unsigned_edit.user + "|" + hours + ":" +
t.substring(10, 12) + ", " + day + " " + lsMonth_names[month - 1] +
year + " (" + tzcode + ")|ALT=nicht}}", "", "");
return;
}
};
xmlhttp.send(null);
};
jQuery(
function() {
mw.loader.using( [ "mediawiki.toolbar", "mediawiki.util" ],
function() {
var unsigned_title = 'Unsigned';
var unsigned_tooltip = 'add a missing signature';
if(mw.config.get('wgUserLanguage') == 'de'){
unsigned_title = 'Unsigniert';
unsigned_tooltip = 'Trage eine fehlende Signatur nach.';
}
if(!mw.config.get('wgIsArticle')){
mw.util.addPortletLink(
'p-cactions',
"javascript:addSigWikiCode();",
/* localizable strings start */
unsigned_title ,
"ca-unsigned",
unsigned_tooltip, ""
/* localizable strings end */
);
}
}
);
}
);
}
//</nowiki></pre>