Kullanıcı:İnfoCan/maddegeçmişi.js
Görünüm
Bu sayfaya eklediğiniz kodlar hesabınızı tehlike altına sokacak kötü amaçlı içerik barındırabilir. Başka bir sayfada yer alan betikleri "mw.loader.load", "importScript" veya "iusc" gibi yöntemlerle kullanmadan önce, bu yöntemle içeriği başkaları tarafından kontrol edilebilecek uzaktaki bir betiği dinamik olarak yüklemiş olacağınızı bilmeniz gerekir. Sayfaya eklediğiniz kodun güvenli olup olmadığından emin değilseniz, Köy Çeşmesi'nde deneyimli kullanıcılara danışabilirsiniz. Kod, sayfa önizlemesinde de çalıştırılacaktır. |
//<pre>
//Bu fonksiyon soldaki Araçlar kutusuna bir "Madde geçmişi" bağlantısı ekler, buna tıklanınca
//tartışma sayfasının geçmişi aranıp {{MaddeGeçmişi}} şablonuna yarayabilecek olaylar aranır.
//Daha çok ayrıntı için tartışma sayfasına bakınız. Aşağıdaki betik [[en:User:Dr pda/articlehistory.js]]
//sayfasının kısmen Türkçeye çevirisidir.
//
//Bu fonksiyonu kullanmak için monobook.js dosyanıza {{subst:js|User:İnfoCan/maddegeçmişi.js}}
//veya
// importScript('Kullanıcı:İnfoCan/maddegeçmişi.js');
//ekleyin.
function loadXMLDocAppendingId(url,handler,id)
{
url=url+id;
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
var req = new XMLHttpRequest();
}
// branch for IE/Windows ActiveX version
else if (window.ActiveXObject) {
var req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req) {
req.onreadystatechange = function () {handler(req,id)};
req.open("GET", url, true);
req.send("");
}
}
function getArticleOldid(req,id) {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
var response = req.responseXML.documentElement;
var rv = response.getElementsByTagName('rev');
var spannode = document.getElementById('oldid-'+id);
spannode.innerHTML = rv[0].getAttribute('revid');
var linode = document.getElementById(id);
linode.onclick='';
} else {
alert("There was a problem retrieving the XML data:\n" +
req.statusText);
}
}
}
function getArticleOldidManual(req,id) {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
var response = req.responseXML.documentElement;
var rv = response.getElementsByTagName('rev');
var spannode = document.getElementById('oldid-'+id);
var timestamp = rv[0].getAttribute('timestamp');
timestamp = timestamp.replace(/Z/g,'');
var prettytimestamp = timestamp.replace(/T/,', ');
timestamp = timestamp.replace(/[-T:]/g,'');
var idtime = id.substr(0,4)+'-'+id.substr(4,2)+'-'+id.substr(6,2)+', '+id.substr(8,2)+':'+id.substr(10,2)+':'+id.substr(12,2);
var revid = rv[0].getAttribute('revid');
spannode.innerHTML = ' '+idtime+' tarihinden önceki son versiyon '+prettytimestamp+' tarihindeydi, '+revid+' sürüm numarasıyla. <a href="/w/index.php?title='+articleName+'&action=history&offset='+id+'">Madde geçmişi</a> veya <a href="/w/index.php?title='+talkName+'&action=history&offset='+id+'">tartışma sayfası geçmişine</a> gitmek için bağlantılara tıklayınız.';
} else {
alert("There was a problem retrieving the XML data:\n" +
req.statusText);
}
}
}
function getHistoryMilestones(req) {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
var response = req.responseXML.documentElement;
var revList = response.getElementsByTagName('rev');
var prettylastcomment = '';
var lasttimestamp = '';
var prettylasttimestamp = '';
if(revList.length > 0){
for(var i=0; i<revList.length; i++){
var comment = revList[i].getAttribute('comment');
//strip out headers i.e. /*...*/
prettycomment='';
if(comment) prettycomment=comment.replace(/\/\*.*\*\//,'');
comment=prettycomment.toLowerCase();
var timestamp = revList[i].getAttribute('timestamp');
timestamp = timestamp.replace(/Z/g,'');
var prettytimestamp = timestamp.replace(/T/,', ');
timestamp = timestamp.replace(/[-T:]/g,'');
var output = document.getElementById("article-milestones");
if(comment.match('{{') || comment.match(/seçkin/) || comment.match(/\bmadde\b/) || comment.match('sm.?başarısız') || comment.match('esm') ||comment.match('inceleme')|| comment.match(/\bsm\b/) || comment.match(/\bsma\b/) || comment.match(/\bsl\b/) || comment.match(/\bsla\b/) || comment.match(/\bsp\b/) || comment.match(/\bspa\b/) || comment.match(/\bspoa\b/) || comment.match(/\bkm\b/) || comment.match(/\bkma\b/) || comment.match(/\bkm.?başarısız\b/) || comment.match(/\bkm.?adayı\b/)|| comment.match('kaliteli madde') || comment.match(/\bkmadde\b/) || comment.match(/\bkmi\b/) || comment.match(/\bsmi\b/) || comment.match(/\bsmia\b/) || comment.match(/\bsl\b/) || comment.match(/\bslia\b/) || comment.match(/\bska\b/) || comment.match(/\bsk\b/) || comment.match(/ana.?sayfa/) || comment.match('bm') || comment.match(/\bsas\b/) || comment.match(/\bsam\b/) ||comment.match(/\badaylı/) || comment.match('ihraç') ){
var milestone = document.createElement("li");
spanid='oldid-'+timestamp;
milestone.innerHTML='<b>'+prettytimestamp+'</b> '+prettycomment+' <span id='+spanid+'>(sürümno)</span>';
milestone.id=timestamp;
milestone.onclick=getArticleOldidWrapper;
output.appendChild(milestone);
}
prettylastcomment = prettycomment;
lasttimestamp = timestamp;
prettylasttimestamp = prettytimestamp;
}
var getmore = document.getElementById("getmore");
getmore.innerHTML='(son okunan satır: <b>'+prettylasttimestamp+'</b> '+prettylastcomment+')';
//Get more milestones, if any (if not, the program won't get here again)
loadXMLDocAppendingId(talkQueryURL,getHistoryMilestones,'&rvstart='+(parseInt(lasttimestamp)-1))
}
}
else {
alert("There was a problem retrieving the XML data:\n" +
req.statusText);
}
}
}
function getArticleOldidWrapper(event) {
loadXMLDocAppendingId(articleQueryURL,getArticleOldid,this.id)
}
function manualDate(event)
{
var mydate=prompt("eski sürüm numarasını istediğiniz tarihi girin","")
if (mydate!=null && mydate!=""){
var utc = Date.parse(mydate+' UTC');
var d = new Date();
d.setTime(utc);
if((d.getUTCHours()+d.getUTCMinutes()) == 0){
d.setUTCHours(23);
d.setUTCMinutes(59);
d.setUTCSeconds(59);
}
var timestamp ='';
timestamp += d.getUTCFullYear();
timestamp += (d.getUTCMonth()<9) ? '0'+(d.getUTCMonth()+1) : (d.getUTCMonth()+1);
timestamp += (d.getUTCDate()<10) ? '0'+ d.getUTCDate() : d.getUTCDate();
timestamp += (d.getUTCHours()<10) ? '0'+ d.getUTCHours() : d.getUTCHours();
timestamp += (d.getUTCMinutes()<10) ? '0'+ d.getUTCMinutes() : d.getUTCMinutes();
timestamp += (d.getUTCSeconds()<10) ? '0'+ d.getUTCSeconds() : d.getUTCSeconds();
var dateoldid = document.createElement("p");
dateoldid.id = 'oldid-'+timestamp;
output.parentNode.insertBefore(dateoldid,enterdate.nextSibling);
loadXMLDocAppendingId(articleQueryURL,getArticleOldidManual,timestamp)
}
}
function getArticleHistory(){
output = document.createElement("ul");
output.id = "article-milestones";
var dummy = document.getElementById("siteSub");
dummy.parentNode.insertBefore(output, dummy.nextSibling);
var getmore = document.createElement("p");
getmore.id = 'getmore';
output.parentNode.insertBefore(getmore,output.nextSibling);
enterdate = document.createElement("p");
enterdate.id = 'enterdate';
enterdate.innerHTML='<span style="background-color:lightblue;font-weight:bold;">Tarihi elle girmek için burayı tıklayın</span>';
enterdate.onclick = manualDate;
output.parentNode.insertBefore(enterdate,getmore.nextSibling);
articleName = wgTitle;
//Handle special characters characters, including puncutation, in URL
articleName = encodeURIComponent(articleName);
talkName = 'Talk:'+articleName;
//correctly handle article name when on a Talk page archive
var archiveIndex = articleName.toLowerCase().indexOf("/archive");
articleName = (archiveIndex == -1) ? articleName : articleName.substring(0,archiveIndex);
talkQueryURL = '/w/api.php?action=query&prop=revisions&titles='+talkName+'&rvlimit=500&rvprop=ids|timestamp|comment&format=xml';
articleQueryURL = '/w/api.php?action=query&prop=revisions&titles='+articleName+'&rvlimit=500&rvprop=ids|timestamp|comment&format=xml&rvstart=';
loadXMLDocAppendingId(talkQueryURL,getHistoryMilestones,'');
}
$(function () {
mw.util.addPortletLink('p-tb', 'javascript:getArticleHistory()', 'Madde geçmişi', 't-madde-geçmişi', 'Tartışma sayfasında MaddeGeçmişi şablonu için faydalı olan olayları ara', '', '');
});
//</pre>