///////////////////////////////////////////////////////////////////////////
// Sol tabloda bekleyen değişiklikleri listeleyen bir kutucuk oluşturur. //
// //
// Kaynak: [[:en:User:Joshua_Scott/Scripts/pendingchanges.js]]//
// Yazan: [[:en:User:Joshua Scott]] & [[:en:User:TheJosh]] //
// Türkçeleştiren: [[Kullanıcı:Vito Genovese]] //
// Bilgi: [[VP:BDK]] //
///////////////////////////////////////////////////////////////////////////
var pendch_http;
var pendch_enabled;
var pendch_num_pages;
var pendch_refresh;
var pendch_num_idle_req;
var pendch_curr_idle_req;
var pendch_diffonly;
var pendch_str_no_ajax = "Bekleyen Değişiklikler kutusu ile ilgili bir problem var. Tarayıcınız desteklenmiyor!";
var pendch_str_box_title = "Bekleyen değişiklikler";
var pendch_str_box_title_updating = "Bekleyen değ. (günc.)";
var pendch_str_box_title_failed = "Bekleyen değişiklikler (güncelleme başarısız)";
var pendch_str_enable = "Bu kutuyu etkinleştir";
var pendch_str_disable = "Bu kutuyu devre dışı bırak";
$( pendch_init );
/* initalise */
function pendch_init() {
var diff = document.getElementById("difference");
if (!diff || document.getElementById('mw-panel') === null) {
return;
}
if (window.location.toString().search(/diffonly=1/) != -1) {
var currURL = window.location.toString();
var newURL=currURL.replace(/diffonly=1/,diffonly=0);
console.log(diff.innerHTML);
if (diff.innerHTML.search(/Show page below diff/) == -1) {
diff.innerHTML += ' (<a href="' + newURL + '">Sayfayı farkın altında göster</a>)';
}
}
// allow user settings through
if (pendch_enabled == null) {
pendch_enabled = false;
}
if (pendch_num_pages == null) {
pendch_num_pages = 10;
}
if (pendch_refresh == null) {
pendch_refresh = 10;
}
if (pendch_num_idle_req == null) {
pendch_num_idle_req = 60;
}
if(pendch_diffonly == null) {
pendch_diffonly = 1;
}
// A few limits to be nice to the servers
if (pendch_num_pages > 50) {
pendch_num_pages = 50;
}
if (pendch_num_pages < 1) {
pendch_num_pages = 1;
}
if (pendch_refresh < 2) {
pendch_refresh = 2;
}
if (pendch_num_idle_req > 1000) {
pendch_num_idle_req = 1000;
}
if (pendch_num_idle_req < 5) {
pendch_num_idle_req = 5;
}
// get our cookie
if (document.cookie.length > 0) {
var c_start = document.cookie.indexOf("pendch_show_box=");
if (c_start != -1) {
c_start = c_start + 16;
var c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) {
c_end = document.cookie.length;
}
if (document.cookie.substring(c_start, c_end) == "yes") {
pendch_enabled = true;
} else {
pendch_enabled = false;
}
}
}
// Either make a request or show nothing
pendch_curr_idle_req = 0;
if (pendch_enabled == true) {
pendch_ajax_request();
} else {
pendch_draw_disabled_box();
}
}
/* init ajax */
function pendch_create_request() {
try {
pendch_http = new XMLHttpRequest();
} catch (e) {
try {
pendch_http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
pendch_http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
return false;
}
}
}
pendch_http.onreadystatechange = function() {
if(pendch_http.readyState == 4) pendch_ajax_response();
}
return true;
}
/* make a request */
function pendch_ajax_request() {
// if we have done too many requests, disable the box
pendch_curr_idle_req++;
if (pendch_curr_idle_req > pendch_num_idle_req) {
pendch_disable_box();
}
// check we are enabled
if (pendch_enabled == false) return;
// firstly, inform the user
var cur_box = document.getElementById('p-pendingchanges');
if (cur_box != null) {
cur_box.firstChild.firstChild.data = pendch_str_box_title_updating;
}
if (pendch_create_request () == false) {
if (cur_box != null) {
cur_box.firstChild.firstChild.data = pendch_str_box_title_failed;
} else {
alert (pendch_str_no_ajax);
}
}
// Get the current time
var dateobj = new Date();
var now = Math.floor(dateobj.getTime() / 1000.0);
// Go back 5 mins in time
//now -= (60 * 5);
// Then make the request
pendch_http.open("GET", "/w/api.php?action=query&format=xml&list=oldreviewedpages&ornamespace=0|4&orlimit=" + pendch_num_pages, true);
pendch_http.send(null);
}
function pendch_draw_disabled_box() {
if (mw.config.get('skin') == 'vector') {
pendch_draw_disabled_box_vector();
} else {
pendch_draw_disabled_box_monobook();
}
}
function pendch_ajax_response() {
if (mw.config.get('skin') == 'vector') {
pendch_ajax_response_vector();
} else {
pendch_ajax_response_monobook();
}
// and do it again in 5 secs
setTimeout("pendch_ajax_request()", pendch_refresh * 1000);
}
function pendch_disable_box() {
pendch_enabled = false;
pendch_draw_disabled_box();
document.cookie = "pendch_show_box=no; path=/";
}
function pendch_enable_box() {
pendch_enabled = true;
pendch_curr_idle_req = 0;
document.cookie = "pendch_show_box=yes; path=/";
pendch_ajax_request();
}
/* Draw disabled (monobook) */
function pendch_draw_disabled_box_monobook() {
// Container div
var link_div = document.createElement('div');
link_div.className = 'pBody';
var div = document.createElement('div');
div.setAttribute('id', 'p-pendingchanges');
div.className = 'portlet';
var heading = document.createElement('h3');
heading.appendChild(document.createTextNode(pendch_str_box_title));
div.appendChild(heading);
div.appendChild(link_div);
// enable link
var p = document.createElement('p');
p.style.fontSize = 'x-small';
p.style.margin = '0px';
var a = document.createElement('a');
a.appendChild(document.createTextNode(pendch_str_enable));
a.onclick = pendch_enable_box;
p.appendChild(a);
link_div.appendChild(p);
// now replace the div
var old_div = document.getElementById('p-pendingchanges');
var side_col = document.getElementById('column-one');
if (old_div != null) {
side_col.replaceChild(div, old_div);
} else {
var node = document.getElementById('p-search');
side_col.insertBefore(div, node);
}
}
/* Draw response (monobook) */
function pendch_ajax_response_monobook() {
var items = pendch_http.responseXML.getElementsByTagName('p');
// create the div that holds all the pending changes links
var link_div = document.createElement('div');
link_div.className = 'pBody';
var list = document.createElement('ul');
link_div.appendChild(list);
// populate the list with 10 links.
for (var i = 0; i < items.length; i++) {
var item_name = items[i].getAttribute('title');
var old_id = items[i].getAttribute('stable_revid');
var under_review = items[i].getAttribute('under_review');
item_name = item_name.replace(/&/, "%26");
var item_url = mw.config.get('wgScript') + '?title=' + item_name + '&diff=cur&oldid=' + old_id + '&diffonly=' + pendch_diffonly;
a = document.createElement('a');
a.setAttribute('href', item_url);
a.appendChild(document.createTextNode(item_name));
var li = document.createElement('li');
li.appendChild(a);
if (under_review == "1") {
li.setAttribute('style','background-color: yellow;');
}
list.appendChild(li);
}
// Container div
var div = document.createElement('div');
div.setAttribute('id', 'p-pendingchanges');
div.className = 'portlet';
var heading = document.createElement('h3');
heading.appendChild(document.createTextNode(pendch_str_box_title));
div.appendChild(heading);
div.appendChild(link_div);
// disable link
var p = document.createElement('p');
p.style.fontSize = 'x-small';
p.style.margin = '0px';
p.style.textAlign = 'right';
a = document.createElement('a');
a.appendChild(document.createTextNode(pendch_str_disable));
a.onclick = pendch_disable_box;
p.appendChild(a);
link_div.appendChild(p);
// now replace the div
var old_div = document.getElementById('p-pendingchanges');
var side_col = document.getElementById('column-one');
if (old_div != null) {
side_col.replaceChild(div, old_div);
} else {
var node = document.getElementById('p-search');
side_col.insertBefore(div, node);
}
}
/* Draw disabled box (vector skin) */
function pendch_draw_disabled_box_vector() {
// Container div
var link_div = document.createElement('div');
link_div.className = 'body';
link_div.style.display = "block";
var div = document.createElement('div');
div.setAttribute('id', 'p-pendingchanges');
div.className = 'portal collapsed';
var heading = document.createElement('h3');
heading.appendChild(document.createTextNode(pendch_str_box_title));
div.appendChild(heading);
div.appendChild(link_div);
// enable link
var p = document.createElement('p');
p.style.fontSize = 'x-small';
p.style.margin = '0px';
var a = document.createElement('a');
a.appendChild(document.createTextNode(pendch_str_enable));
a.onclick = pendch_enable_box;
p.appendChild(a);
// add later
// now replace the div
var old_div = document.getElementById('p-pendingchanges');
var side_col = document.getElementById('mw-panel');
if (old_div != null) {
side_col.replaceChild(div, old_div);
} else {
var node = document.getElementById('p-interaction');
side_col.insertBefore(div, node);
}
link_div.appendChild(p);
}
/* Draw response (vector skin) */
function pendch_ajax_response_vector() {
var items = pendch_http.responseXML.getElementsByTagName('p');
// create the div that holds all the pending changes links
var link_div = document.createElement('div');
link_div.className = 'body';
link_div.style.display = "block";
var list = document.createElement('ul');
link_div.appendChild(list);
// populate the list with 10 links.
for (var i = 0; i < items.length; i++) {
var item_name = items[i].getAttribute('title');
var old_id = items[i].getAttribute('stable_revid');
var under_review = items[i].getAttribute('under_review');
item_name = item_name.replace(/&/, "%26");
var item_url = mw.config.get('wgScript') + '?title=' + item_name + '&diff=cur&oldid=' + old_id + '&diffonly=' + pendch_diffonly;
a = document.createElement('a');
a.setAttribute('href', item_url);
//a.style.fontSize = 'x-small';
a.appendChild(document.createTextNode(item_name));
var li = document.createElement('li');
li.appendChild(a);
if(under_review == "1") {
li.setAttribute('style','background-color: yellow;');
}
list.appendChild(li);
}
// Container div
var div = document.createElement('div');
div.setAttribute('id', 'p-pendingchanges');
div.className = 'portal expanded';
var heading = document.createElement('h3');
heading.appendChild(document.createTextNode(pendch_str_box_title));
div.appendChild(heading);
div.appendChild(link_div);
// disable link
var p = document.createElement('p');
p.style.fontSize = 'x-small';
p.style.margin = '0px';
p.style.textAlign = 'left';
a = document.createElement('a');
a.appendChild(document.createTextNode(pendch_str_disable));
a.onclick = pendch_disable_box;
p.appendChild(a);
// add later
// now replace the div
var old_div = document.getElementById('p-pendingchanges');
var side_col = document.getElementById('mw-panel');
if (old_div != null) {
side_col.replaceChild(div, old_div);
} else {
var node = document.getElementById('p-interaction');
side_col.insertBefore(div, node);
}
link_div.appendChild(p);
}
function pendch_toggle( $element ) {
$.cookie( 'vector-nav-' + $element.parent().attr( 'id' ), $element.parent().is( '.collapsed' ) );
if( $element.parent().is('.collapsed') ) {
pendch_enable_box();
} else {
pendch_disable_box();
}
$element
.parent()
.toggleClass( 'expanded' )
.toggleClass( 'collapsed' )
.find( 'div.body' )
.slideToggle( 'fast' );
}