User:Ciencia Al Poder/monaco.js

/////////////// // Botonera y popups (BETA) // @Autor: User:Ciencia Al Poder //

var wikiconf = { namespaces: [ {ns:-2,name:'Media',title:'Media'}, {ns:-1,name:'Special',title:'Especial'}, {ns:0,name:,title:}, {ns:1,name:'Talk',title:'Discusión'}, {ns:2,name:'User',title:'Usuario'}, {ns:3,name:'User_talk',title:'Usuario_Discusión'}, {ns:4,name:'Project',title:'WikiDex'}, {ns:5,name:'Project_talk',title:'WikiDex_Discusión'}, {ns:6,name:'Image',title:'Imagen'}, {ns:7,name:'Image_talk',title:'Imagen_Discusión'}, {ns:8,name:'MediaWiki',title:'MediaWiki'}, {ns:9,name:'MediaWiki_talk',title:'MediaWiki_Discusión'}, {ns:10,name:'Template',title:'Plantilla'}, {ns:11,name:'Template_talk',title:'Plantilla_Discusión'}, {ns:12,name:'Help',title:'Ayuda'}, {ns:13,name:'Help_talk',title:'Ayuda_Discusión'}, {ns:14,name:'Category',title:'Categoría'}, {ns:15,name:'Category_talk',title:'Categoría_Discusión'}, {ns:110,name:'Forum',title:'Forum'}, {ns:111,name:'Forum_talk',title:'Forum_talk'}, {ns:400,name:'Video',title:'Video'}, {ns:401,name:'Video_talk',title:'Video_talk'} ] }

var botonera_prefs = { popups:true };

function Botonera(conf, prefs){

this.wikiconfig = YAHOO.lang.merge(conf||{}); this.prefs = YAHOO.lang.merge(prefs||{}); this.popups = null;

this.init; }

Botonera.prototype = { init:function{ // Sólo FireFox (porque se ha probado) if (!is_gecko || !YAHOO) return; this.getCookiePrefs; if (this.prefs.popups){ if (!this.botonera){ this.botonera = new BotoneraPopups(this.wikiconfig); }			this.botonera.enable; }		this.addEditSectionLinks; if (wgAction == 'delete') this.actionDeleteLinks; //if (wgNamespaceNumber != -1 && wgAction == 'view') this.topEditLinks; if (wgNamespaceNumber > -1 && !wgIsArticle) this.addEditSectionLinks; },	getCookiePrefs:function{ var c = $T.getCookie('botonera'); if (!c) return; var s = c.split('|'); for (var i=0; i 1)?p[1]:''; switch(p[0]){ case 'popups': if(val=='true') this.prefs.popups=true; else if (val=='false') this.prefs.popups=false; break; }		}	},	setCookiePrefs:function{ c = ''; c += 'popups:'+(this.prefs.popups?'true':'false'); $T.setCookie('botonera',c); },	actionDeleteLinks:function{ var wr = $('wpReason'); if (!wr) return; var bc = $T.create('input', {type:'button',value:'Borrar comentario'}); $E.addListener(bc, 'click', function{$('wpReason').value='';}); var bi = $T.create('input', {type:'button',value:'Dejar sólo autor'}); $E.addListener(bi, 'click', function{			var t = $('wpReason'), re = /(\[\[E?special:Contributions\/.+\|.+\]\])/ig, res = null, ma = null;			while ((ma = re.exec(t.value)) != null){				res = ma[0];			}			if (res) t.value='Único autor: '+res;			t.focus;		}); $T.makeChildren([bc,bi], wr.parentNode); },	topEditLinks:function{ var article = new WikiArticle(wgPageName, this.wikiconfig); var s = $T.create('span', {className:'editsection botonera-edittop', style:'float:rigth;'}, [			'[', $T.create('a', {href: article.isTalk ? article.getTalkFullUrl('action=edit&section=0') : article.getFullUrl('action=edit&section=0'), title:'Editar la sección inicial'}, 'editar 0'), '] '			]); if (!wgIsArticle && wgCurRevisionId){ $T.makeChildren([				'[', $T.create('a', {href: article.getFullUrl('action=edit'), title:'Editar desde la última revisión'}, 'editar ult'),'] '			],s); }		var h1 = (document.getElementById('content')||document.getElementById('article')).getElementsByTagName('h1')[0]; h1.parentNode.insertBefore(s,h1); },	addEditSectionLinks: function{ var sec = 1, article = new WikiArticle(wgPageName, this.wikiconfig); for (var i=0, ss=$('bodyContent').getElementsByTagName('span'); i<ss.length; i++){ if (ss[i].className == 'mw-headline'){ var skip = false; for (var j=0, es = ss[i].parentNode.getElementsByTagName('span'); j < es.length; j++){ if ((' '+es[j].className+' ').indexOf(' editsection ') != -1) skip = true; }				if (skip) continue; var es = $T.create('span', {className:'editsection editsection-nf fakeeditsection'}, [					'[', $T.create('a', {href: article.isTalk ? article.getTalkFullUrl('action=edit&section='+sec) : article.getFullUrl('action=edit&section='+sec)}, 'editar'), ']'				]); ss[i].parentNode.appendChild(es); sec++; }		}	} } /****** END Botonera ******/

function BotoneraPopups(conf){

this.wikiconfig = YAHOO.lang.merge(conf||{}); this.elem = null; this.head = null; this.body = null; this.title = null; this.article = null; this.visible = false; }

BotoneraPopups.prototype = { enable:function{ $E.addListener(document.body,'mouseover',this.checkMouseOver,null,this); }, disable:function{ $E.removeListener(document.body,'mouseover',this.checkMouseOver); }, createDialog:function{ var el = $T.create('div', {className:'botonera-dlg'}); this.head = $T.create('div', {className:'hd'}); this.body = $T.create('div', {className:'bd'}); $T.makeChildren([this.head,this.body],el); document.body.appendChild(el); this.elem = el; }, show:function(target){ if (!this.elem) this.createDialog; var article = new WikiArticle(this.title,this.wikiconfig); this.head.innerHTML = ''; var ns = article.article.namespace; if (ns === null || ns.ns < 0){ this.head.appendChild($T.create('a',{className:target.className+' b-article selected', href:article.getFullUrl}, article.toString.length>30?article.toString.substr(0,27)+'...':article.toString)); this.body.innerHTML = ''; } else { $T.makeChildren([			$T.create('a',{className:(article.isTalk?:target.className+' selected')+' b-article', href:article.getFullUrl}, (article.toString.length>30?article.toString.substr(0,27)+'...':article.toString) ),			' ', $T.create('a',{className:'b-edit', href:article.getFullUrl('action=edit')}, 'editar'),			' ', $T.create('a',{className:'b-hist', href:article.getFullUrl('action=history')}, 'historial'),			' ', $T.create('a',{className:(article.isTalk?target.className+' selected':)+' b-talk', href:article.getTalkFullUrl}, 'discusión'),			' ', $T.create('a',{className:'b-edittalk', href:article.getTalkFullUrl('action=edit')}, 'editar discusión'),			' ', $T.create('a',{className:'b-esectalk', href:article.getTalkFullUrl('action=edit&section=new')}, '+'),			' ', $T.create('a',{className:'b-histtalk', href:article.getTalkFullUrl('action=history')}, 'historial discusión')		],this.head); this.body.innerHTML = ''; var params = {}; if (target && target.search){ for (var i=0, p=target.search.substr(1).split('&'); i<p.length;i++){ var ps = p[i].split('='); params[ps[0]] = ps[1]; }		}		switch(ns.name){ case 'User': var ub = $T.create('div',{className:'sec b-userlinks'}); $T.makeChildren([					$T.create('span',{className:'caption'}, 'Usuario:'),					' ', $T.create('a',{className:'b-ucontrib', href:article.getSpecial('Contributions')}, 'Contribuciones'),					' ', $T.create('a',{className:'b-block', href:article.getSpecial('Blockip')}, 'Bloquear'),					' ', $T.create('a',{className:'b-ulog', href:article.getSpecial('Log')}, 'Registros')				],ub); this.body.appendChild(ub); break; }		var cb = $T.create('div',{className:'sec b-articlelinks'}); $T.makeChildren([			$T.create('span',{className:'caption'}, 'Artículo:'),			' ', $T.create('a',{className:'b-delete', href:article.getFullUrl('action=delete')}, 'Borar'),			' ', $T.create('a',{className:'b-protect', href:article.getFullUrl('action=protect')}, 'Proteger'),			' ', $T.create('a',{className:'b-whatlinkshere', href:article.getSpecial('Whatlinkshere')}, 'Lo que enlaza aquí'),			' ', $T.create('a',{className:'b-search', href:article.getSpecial('Search')}, 'Buscar'),			' ', $T.create('a',{className:'b-prefixindex', href:article.getSpecial('Prefixindex')}, 'Buscar por prefijo'),			' ', $T.create('a',{className:'b-log', href:article.getSpecial('Log')}, 'Registros'),			' ', $T.create('a',{className:'b-deletetalk', href:article.getTalkFullUrl('action=delete')}, 'Borar discusión')		],cb); this.body.appendChild(cb); var cdb = $T.create('div',{className:'sec b-deletelinks'}); $T.makeChildren([			$T.create('span',{className:'caption'}, 'Borrado:'),			' ', $T.create('a',{className:'b-d-vand', href:article.getFullUrl('action=delete&wpReason=Vandalismo')}, 'Vandalismo'),			' ', $T.create('a',{className:'b-d-prue', href:article.getFullUrl('action=delete&wpReason=Pruebas de edición')}, 'Pruebas')		],cdb); this.body.appendChild(cdb); var db = $T.create('div',{className:'sec b-diff'}); if (params.oldid){ $T.makeChildren([				$T.create('span',{className:'caption'}, 'Diff:'),				' ', $T.create('a',{className:'b-diffrevcur', href:article.getFullUrl('diff=cur&oldid='+params.oldid)}, 'Diff con lo último'),				' ', $T.create('a',{className:'b-diffcuronly', href:article.getFullUrl('diff=cur&oldid='+params.oldid+'&diffonly=yes')}, 'Solo diff'),				' ', $T.create('a',{className:'b-editthis', href:article.getFullUrl('action=edit&oldid='+params.oldid)}, 'Editar esta revisión'),				' ', $T.create('a',{className:'b-diffprev', href:article.getFullUrl('diff=prev&oldid='+params.oldid)}, '← Diff anterior'),				' ', $T.create('a',{className:'b-diffprevonly', href:article.getFullUrl('diff=prev&oldid='+params.oldid+'&diffonly=yes')}, 'Solo diff'),				' ', $T.create('a',{className:'b-editprev', href:article.getFullUrl('direction=prev&oldid='+params.oldid+'&action=edit')}, '(editar)'),				' ', $T.create('a',{className:'b-diffnext', href:article.getFullUrl('diff=next&oldid='+params.oldid)}, '→ Diff siguiente'), ' ', $T.create('a',{className:'b-diffnextonly', href:article.getFullUrl('diff=next&oldid='+params.oldid+'&diffonly=yes')}, 'Solo diff'), ' ', $T.create('a',{className:'b-editnext', href:article.getFullUrl('direction=next&oldid='+params.oldid+'&action=edit')}, '(editar)'), ],db);		}		this.body.appendChild(db);		var rb = $T.create('div',{className:'sec b-rollback'});		if (params.action && params.action == 'rollback'){			$T.makeChildren([ $T.create('span',{className:'caption'}, 'Rollback:'), ' ', $T.create('a',{className:'b-hiderollback', href:target.pathname+target.search+'&bot=1'}, 'Ocultar rollback') ],rb);		}		this.body.appendChild(rb);	}	if (!this.visible){		$D.setStyle(this.elem, 'display', 'block');		this.visible = true;		$E.addListener(document,'keyup',this.hide,null,this);	}	var tRegion = $D.getRegion(target);	$D.setXY(this.elem, [tRegion.left, tRegion.bottom]); }, hide: function(e){	if ($E.getCharCode(e)!=27) return; //ESC	$D.setStyle(this.elem, 'display', 'none');	this.visible = false;	$E.removeListener(document,'keyup',this.hide); }, checkMouseOver:function(e){	if (!e.ctrlKey) return;	// Comprobamos que no esté dentro del popup	if (this.visible){		var regP = $D.getRegion(this.elem), eXY = $E.getXY(e);		if (eXY[0] >= regP.left && eXY[0] <= regP.right && eXY[1] >= regP.top && eXY[1] <= regP.bottom) return;	}	var a = $E.getTarget(e);	if (a.tagName.toLowerCase == 'img') a = a.parentNode;	if (a.tagName.toLowerCase != 'a') return;	if (a.href.indexOf(wgServer) != 0) return;	var title = ''; if (a.pathname.indexOf(wgArticlePath.replace('$1','')) == 0){ title = a.pathname.replace( wgArticlePath.replace('$1',),  ); } else if (a.pathname == wgScriptPath+wgScript) { var reTitle = /[?&]title=([^&]*)[&]?.*$/; if (reTitle.test(a.search)){ title = reTitle.exec(a.search)[1]; }	}	if (title == '') return; title = decodeURIComponent(title); this.title = title; this.show(a); }

};

/*** END BotoneraDialog ***/

function WikiArticle(title, conf){

this.conf = YAHOO.lang.merge(conf||{}); this.article = null; this.talkpage = null; this.isTalk = false; this.nsCache = {};//{special,main}

this.getArticle(title); }

WikiArticle.prototype = { getArticle: function(title){ this.article = null; var t = (title||'').replace(' ','_'); if (t=='') return; this.article = {}; if (t.indexOf(':')!=-1){ for (var i=0, n=this.conf.namespaces; i<n.length; i++){ if (n[i].name && t.indexOf(n[i].name+':') == 0){ //this.article.namespace = {ns:n[i].ns,name:n[i].name,title:n[i].title}; this.article.namespace = YAHOO.lang.merge(n[i]); this.article.pagename = t.substring(t.indexOf(n[i].name+':')+n[i].name.length+1,t.length); break; } else if (n[i].title && t.indexOf(n[i].title+':') == 0){ this.article.namespace = YAHOO.lang.merge(n[i]);//n[i]; this.article.pagename = t.substring(t.indexOf(n[i].title+':')+n[i].title.length+1,t.length); break; }			}		}		if (!this.article.namespace){ this.article.namespace = {ns:0,name:,title:}; this.article.pagename = t;			this.isTalk = false; }		if (this.article.namespace.ns>=0){ // Si es discusión if (this.article.namespace.ns%2!=0) this.isTalk = true;

for (var i=0, n=this.conf.namespaces; i<n.length; i++){ if (this.isTalk && n[i].ns == this.article.namespace.ns-1){ this.talkpage = YAHOO.lang.merge(this.article); this.article.namespace = YAHOO.lang.merge(n[i]); break; }				if (!this.isTalk && n[i].ns == this.article.namespace.ns+1){ this.talkpage = YAHOO.lang.merge(this.article); this.talkpage.namespace = YAHOO.lang.merge(n[i]); break; }			}		}		if (this.isTalk && !this.talkpage) this.talkpage = false; },	toString:function{ if (!this.article) return ''; if (this.article.namespace && this.article.namespace.title && this.article.namespace.title!='') return this.article.namespace.title+':'+this.article.pagename; return this.article.pagename; },	getFullUrl:function(strArgs){ if (!strArgs) return wgServer+wgArticlePath.replace('$1',this.toString); return wgServer+wgScriptPath+wgScript+'?title='+this.toString+'&'+strArgs; },	getTalkFullUrl:function(strArgs){ if (!this.talkpage) return ''; var talktitle = (this.talkpage.namespace?this.talkpage.namespace.title+':':'') + this.talkpage.pagename; if (!strArgs) return wgServer+wgArticlePath.replace('$1',talktitle); return wgServer+wgScriptPath+wgScript+'?title='+talktitle+'&'+strArgs; },	getSpecial:function(specialpage, strArgs){ if (!this.nsCache.special){ for (var i=0, n=this.conf.namespaces; i<n.length; i++){ if (n[i].ns == -1){ this.nsCache.special = n[i]; break; }			}		}		var ptitle = 'from', pns = 'namespace', fullpagename = this.toString; switch(specialpage){ case 'Blockip': case 'Contributions': fullpagename = this.article.pagename; break; case 'Log': strArgs = 'page='+fullpagename; fullpagename = ''; break; }		if (!this.nsCache.special||!specialpage) return ''; if (!strArgs) return wgServer+wgArticlePath.replace('$1',this.nsCache.special.title+':'+specialpage+'/'+fullpagename); if (!this.article) return wgServer+wgScriptPath+wgScript+'?title='+this.nsCache.special.title+':'+specialpage+'&'+strArgs; return wgServer+wgScriptPath+wgScript+'?title='+this.nsCache.special.title+':'+specialpage+'&'+ptitle+'='+this.article.pagename+'&'+pns+'='+this.article.namespace.ns+(strArgs==?:'&'+strArgs); } };

/******* END WikiArticle *******/

function loadPersonal{ try{ window.botonera = new Botonera(wikiconf, botonera_prefs); InitFindReplace; var c = null; if (wgAction == 'edit' || wgAction == 'submit'){ if (window.location.search.indexOf('undoafter') > 0) c = ($('wpSummary') || $('wpSummaryEnhanced')); else c = $('wpTextbox1'); }		if (c) c.focus; }catch(e){ alert('casque en loadPersonal\n'+e.message); } }

/////////////// // Código a ejecutar aquí: //

$E.onDOMReady(loadPersonal);

//