பயனர்:Logicwiki/Hoomanfunction.js
குறிப்பு - சேமித்த பின்னர், நீங்கள் செய்த மாற்றங்களைக் காண்பதற்கு உங்கள் உலவியின் இடைமாற்று அகற்றப்பட வேண்டும்.
- மொஸில்லா பயர்பாக்ஸ் / சபாரி: Shift+Reload, அல்லது Ctrl-F5 அல்லது Ctrl-R (⌘-R Mac ல்)
- கூகிள் குரோம் Ctrl-Shift-R அழுத்தவும். (⌘-Shift-R Mac ல்) ;
- இண்டர்நெட் எக்ஸ்ப்ளோரர்: Ctrl-Refresh அல்லது Ctrl-F5 ஐ அழுத்தவும்.
- ஒபேரா: Tools → Preferences இல் இடைமாற்றை அகற்றவும்;
/*
* Some JS functions
* [[m:User:Hoo man]]; Version 1.5.0; 2011-04-19;
* PLEASE DO NOT COPY AND PASTE
*/
//several global vars often used
if(!layout) {
var layout = {};
}
if(!http_request) {
if (window.XMLHttpRequest) {
var http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
var http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
}
// wiki information
if(mw.config.get('wgServer').indexOf('secure.wikimedia') != -1) {
var secureServer = true;
//the following is a bit tricky, cause it's quite hard to find out on which wiki we are from secure.wikimedia.org
var tmp = mw.config.get('wgScriptPath').split('/');
var langCode = tmp[2];
var wikiCode = tmp[1];
//some /wikipedia/ projects on secure are on $1.wikimedia.org... I really hope the following gets at least most of them
if(wikiCode == 'wikipedia' && langCode.length > 3 && langCode != 'test' && langCode != 'test2' && langCode != 'simple' && langCode != 'minnan' && langCode.indexOf('-') == -1) {
wikiCode = 'wikimedia';
}
}else{
var secureServer = false;
var langCode = mw.config.get('wgServer').substring(7, mw.config.get('wgServer').indexOf('.', 7));
var wikiCode = mw.config.get('wgServer').substring(7 + langCode.length + 1, mw.config.get('wgServer').indexOf('.org'));
}
//Browser
if(navigator.userAgent.indexOf('MSIE') != -1) {
var isIE = true;
}
var hoofr = {
//can show something while eg. data gets transfered
inProcess : function(startStop, message, mode) {
if(startStop == 'start') {
if(!document.getElementById('inProcess')) {
layout.inProcess = document.createElement('div');
layout.inProcess.id = 'inProcess';
layout.inProcess.innerHTML = message;
document.getElementsByTagName('body')[0].appendChild(layout.inProcess);
layout.inProcess = document.getElementById('inProcess');
}else{
layout.inProcess.innerHTML = message;
layout.inProcess.style.display = '';
}
if(mode == 'textbox') {
layout.inProcess.className = 'inProcessTextBox';
}else{
layout.inProcess.className = 'inProcess';
}
return layout.inProcess;
}else{
layout.inProcess.style.display = 'none';
return layout.inProcess;
}
},
//add tool links (in p-personal) or using mw.util.addPortletLink()
addToolLink : function(name, target, id, method) {
if(!method) {
method = hoofrConfig.toolLinkMethod;
}
if(method == 'toolbar' && !(skin == 'monobook' || skin == 'vector' )) {
//toolbar is only (well) working in monobook an vector, so we have to use smth. else on other skins
method = 'p-cactions';
}
if(!id) {
id = 'tool_link_' + (Math.ceil(Math.random()*1000));
}
if(method == 'toolbar') {
sep = ' - ';
if(!document.getElementById('toolLinks')) {
layout.toolLinks = document.createElement('div');
layout.toolLinks.id = 'toolLinks';
layout.toolLinks.innerHTML = '<a class="toolLinks" id="' + id + '" href="' + target + '">' + name + '</a>';
document.getElementById('p-personal').appendChild(layout.toolLinks);
}else{
layout.toolLinks.innerHTML = layout.toolLinks.innerHTML + sep + '<a class="toolLinks" id="' + id + '" href="' + target + '">' + name + '</a>';
}
}else{
mw.util.addPortletLink(method, target, name, id);
}
return id;
},
//this function can do severall things with two objects (method):
//add: add the second object to the first one (no overwritte, recursive)
//put: like add, but not recursive
objectDiff : function(firstObject, secondObject, method) {
if(!method) {
method = 'add';
}
if(typeof(firstObject) == 'undefined') {
return secondObject;
}
if(method == 'add') {
for(var i in secondObject) {
if(typeof(firstObject[i]) == 'undefined') {
firstObject[i] = secondObject[i];
}else if(typeof(secondObject[i]) == 'object') {
//recursive
firstObject[i] = this.objectDiff(firstObject[i], secondObject[i]);
}
}
return firstObject;
}else if(method == 'put') {
for(var i in secondObject) {
if(typeof(firstObject[i]) == 'undefined') {
firstObject[i] = secondObject[i];
}
}
return firstObject;
}
},
//creates a movable popup
popup : {
init : function (id, width, height, title, buttonName, buttonOnClick) {
origId = id;
id = 'popup_' + id; //to make sure this wont collide with other objects
if(!document.getElementById(id)) {
layout[id] = {};
layout[id].wrapper = document.createElement('div');
layout[id].wrapper.id = origId;
layout[id].wrapper.className = 'popupWrapper';
if(width) {
layout[id].wrapper.style.width = (width + 10) + 'px';
if(!window.innerWidth) {
layout[id].wrapper.style.left = ((document.documentElement.clientWidth / 2) - (width / 2)) + 'px';
}else{
layout[id].wrapper.style.left = ((window.innerWidth / 2) - (width / 2)) + 'px';
}
}else{
if(!window.innerWidth) {
layout[id].wrapper.style.left = (document.documentElement.clientWidth / 2) + 'px';
}else{
layout[id].wrapper.style.left = (window.innerWidth / 2) + 'px';
}
}
if(height) {
layout[id].wrapper.style.height = (height + 70) + 'px';
if(!window.innerWidth) {
layout[id].wrapper.style.top = ((document.documentElement.clientHeight / 2) - (height / 2)) + 'px';
}else{
layout[id].wrapper.style.top = ((window.innerHeight / 2) - (height / 2)) + 'px';
}
}else{
if(!window.innerWidth) {
layout[id].wrapper.style.top = (document.documentElement.clientHeight / 2) + 'px';
}else{
layout[id].wrapper.style.top = (window.innerHeight / 2) + 'px';
}
}
//resize thingys
layout[id].wrapper.innerHTML = '<div class="popupWindowResizeArea popupWindowResizeAreaRight" onMouseDown="hoofr.popup.resizeInit(event, this.parentNode.id)"></div>';
layout[id].wrapper.innerHTML += '<div class="popupWindowResizeArea popupWindowResizeAreaBottom" onMouseDown="hoofr.popup.resizeInit(event, this.parentNode.id)"></div>';
document.getElementsByTagName('body')[0].appendChild(layout[id].wrapper);
//titlebar
layout[id].titleBar = document.createElement('div');
layout[id].titleBar.id = origId + 'TitleBar';
layout[id].titleBar.className = 'popupTitleBar';
layout[id].titleBar.innerHTML = '<span class="popupTitleBarContent">' + title + '</span><span class="popupWindowClose" onClick="hoofr.popup.close(\'' + id + '\')">X</span>';
layout[id].titleBar.setAttribute('onMouseDown', 'hoofr.popup.dragInit(event, this.parentNode.id)');
layout[id].wrapper.appendChild(layout[id].titleBar);
//content container
layout[id].container = document.createElement('div');
layout[id].container.id = origId + 'Container';
layout[id].container.className = 'popupContainer';
layout[id].container.style.width = width + 'px';
layout[id].container.style.height = height + 'px';
layout[id].wrapper.appendChild(layout[id].container);
//close and (if given) custom button
layout[id].buttonArea = document.createElement('div');
layout[id].buttonArea.id = origId + 'ButtonArea';
layout[id].buttonArea.className = 'popupButtonArea';
layout[id].buttonArea.innerHTML = '<button type="button" class="popupButton" onClick="hoofr.popup.close(\'' + id + '\')">' + hoofrConfig.closeButtonText + '</button>';
if(buttonName) {
layout[id].buttonArea.innerHTML += '<button type="button" class="popupButton" onClick=\'' + buttonOnClick + '\'>' + buttonName + '</button>'
}
layout[id].wrapper.appendChild(layout[id].buttonArea);
return layout[id].container;
}else{
return false;
}
},
close : function(id) {
//id = 'popup_' + id;
layout[id].wrapper.style.display = 'none';
},
dragInit : function(event, id) {
var x, y;
id = 'popup_' + id;
hoofr.popup.dragObjekt.id = id;
//get cursor position
if(isIE) {
x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
}else{
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}
hoofr.popup.dragObjekt.cursorStartX = x;
hoofr.popup.dragObjekt.cursorStartY = y;
hoofr.popup.dragObjekt.startLeft = parseInt(layout[id].wrapper.style.left, 10);
hoofr.popup.dragObjekt.startTop = parseInt(layout[id].wrapper.style.top, 10);
if(isNaN(hoofr.popup.dragObjekt.startLeft)) {
hoofr.popup.dragObjekt.startLeft = 0;
}
if(isNaN(hoofr.popup.dragObjekt.startTop)) {
hoofr.popup.dragObjekt.startTop = 0;
}
//get all mousemove on the page and abort move an mouseup
if(isIE) {
document.attachEvent('onmousemove', hoofr.popup.dragMove);
document.attachEvent('onmouseup', hoofr.popup.stop);
window.event.cancelBubble = true;
window.event.returnValue = false;
}else{
document.addEventListener('mousemove', hoofr.popup.dragMove, true);
document.addEventListener('mouseup', hoofr.popup.stop, true);
event.preventDefault();
}
},
dragMove : function(event) {
var x, y;
id = hoofr.popup.dragObjekt.id;
if(isIE) {
x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
}else{
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}
//Move it
layout[id].wrapper.style.left = (hoofr.popup.dragObjekt.startLeft + x - hoofr.popup.dragObjekt.cursorStartX) + 'px';
layout[id].wrapper.style.top = (hoofr.popup.dragObjekt.startTop + y - hoofr.popup.dragObjekt.cursorStartY) + 'px';
if(isIE) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}else{
event.preventDefault();
}
},
resizeInit : function(event, id) {
var x, y;
hoofr.popup.dragObjekt.id = id;
id = 'popup_' + id;
//get cursor position
if(isIE) {
x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
}else{
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}
hoofr.popup.dragObjekt.cursorStartX = x;
hoofr.popup.dragObjekt.cursorStartY = y;
hoofr.popup.dragObjekt.wrapperOldWidth = parseInt(layout[id].wrapper.style.width, 10);
hoofr.popup.dragObjekt.wrapperOldHeight = parseInt(layout[id].wrapper.style.height, 10);
hoofr.popup.dragObjekt.containerOldHeight = parseInt(layout[id].container.style.height, 10);
hoofr.popup.dragObjekt.containerOldWidth = parseInt(layout[id].container.style.width, 10);
//get all mousemove on the page and abort move an mouseup
if(isIE) {
document.attachEvent('onmousemove', hoofr.popup.resizeDo);
document.attachEvent('onmouseup', hoofr.popup.stop);
window.event.cancelBubble = true;
window.event.returnValue = false;
}else{
document.addEventListener('mousemove', hoofr.popup.resizeDo, true);
document.addEventListener('mouseup', hoofr.popup.stop, true);
event.preventDefault();
}
},
resizeDo : function(event) {
var x, y;
id = hoofr.popup.dragObjekt.id;
id = 'popup_' + id;
if(isIE) {
x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
}else{
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}
//Resize it
layout[id].wrapper.style.width = (hoofr.popup.dragObjekt.wrapperOldWidth + x - hoofr.popup.dragObjekt.cursorStartX) + 'px';
layout[id].wrapper.style.height = (hoofr.popup.dragObjekt.wrapperOldHeight + y - hoofr.popup.dragObjekt.cursorStartY) + 'px';
layout[id].container.style.width = (hoofr.popup.dragObjekt.containerOldWidth + x - hoofr.popup.dragObjekt.cursorStartX) + 'px';
layout[id].container.style.height = (hoofr.popup.dragObjekt.containerOldHeight + y - hoofr.popup.dragObjekt.cursorStartY) + 'px';
if(isIE) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}else{
event.preventDefault();
}
},
stop : function(event) {
//remove eventlisteners
if(isIE) {
document.detachEvent('onmousemove', hoofr.popup.dragMove);
document.detachEvent('onmousemove', hoofr.popup.resizeDo);
document.detachEvent('onmouseup', hoofr.popup.stop);
}else{
document.removeEventListener('mousemove', hoofr.popup.dragMove, true);
document.removeEventListener('mousemove', hoofr.popup.resizeDo, true);
document.removeEventListener('mouseup', hoofr.popup.stop, true);
}
},
dragObjekt : {}
},
//MediaWiki API related functions
getEditToken : function(pageName, returnLastRevision) {
url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&intoken=edit&titles=' + encodeURIComponent(pageName) + '&format=xml';
if(!returnLastRevision) {
url += '&prop=info';
}else{
url += '&prop=info|revisions';
}
http_request.open("GET", url, false);
http_request.send(null);
if(http_request.readyState == 4 && http_request.status == 200) {
editToken = http_request.responseXML.getElementsByTagName('page')[0].getAttribute('edittoken');
if(returnLastRevision) {
var info = {};
var tmp = http_request.responseXML.getElementsByTagName('rev')[0];
info.editToken = editToken;
info.timestamp = tmp.getAttribute('timestamp');
info.user = tmp.getAttribute('user');
info.revid = tmp.getAttribute('revid');
info.comment = tmp.getAttribute('comment');
return info;
}
return editToken;
}else{
return false;
}
},
getPage : function(pageName, revision) {
url = mw.config.get('wgServer') + mw.config.get('wgScript') + '?action=raw';
if(pageName) {
url += '&title=' + encodeURIComponent(pageName);
}
if(revision) {
url += '&oldid=' + revision;
}
http_request.open("GET", url, false);
http_request.send(null);
if(http_request.readyState == 4 && http_request.status == 200) {
// succes ;-)
return http_request.responseText;
}else{
return false;
}
},
editPage : function(pageName, text, summary, minor, editToken, basetimestamp) {
//build the (post) request
if(!editToken) {
editToken = this.getEditToken(pageName);
}
var params = 'action=edit&title=' + encodeURIComponent(pageName) + '&text=' + encodeURIComponent(text) + '&format=xml&token=' + encodeURIComponent(editToken);
if(summary) {
params += '&summary=' + encodeURIComponent(summary);
}
if(minor) {
params += '&minor=1';
}
if(basetimestamp) {
params += '&basetimestamp=' + basetimestamp;
}
http_request.open("POST", mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php', false);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
http_request.setRequestHeader("Content-length", params.length);
http_request.setRequestHeader("Connection", "close");
//send it
http_request.send(params);
if(http_request.readyState == 4 && http_request.status == 200) {
// success!?
response = http_request.responseXML;
if(response.getElementsByTagName('edit')[0]) {
//succes!
var result = http_request.responseXML.getElementsByTagName('edit')[0].getAttribute('result');
}else{
//something went wrong :(
var result = http_request.responseXML.getElementsByTagName('error')[0].getAttribute('info');
}
if(result == "Success") {
return true;
}else{
return result;
}
}else{
return false;
}
}
};
//default config
if(typeof(hoofrConfig) == 'undefined') hoofrConfig = {};
if(typeof(hoofrDefaultConfig) == 'undefined') hoofrDefaultConfig = {};
hoofrDefaultConfig.globalCssUrl = 'http://meta.wikimedia.org/w/index.php?title=User:Hoo_man/tool.css&action=raw&ctype=text/css';
//to change anything just add one of the following lines to your own .js and replace 'hoofrDefaultConfig' with 'hoofrConfig'
//must be either "toolbar" or "p-cactions", "p-personal", "p-navigation", "p-tb"
hoofrDefaultConfig.toolLinkMethod = 'toolbar';
//hoofr.popup close button text
hoofrDefaultConfig.closeButtonText = 'Close';
hoofrConfig = hoofr.objectDiff(hoofrConfig, hoofrDefaultConfig);
//mw.loader.load(hoofrConfig.globalCssUrl, 'text/css');
importStylesheetURI(hoofrConfig.globalCssUrl); //https://bugzilla.wikimedia.org/show_bug.cgi?id=28413