MediaWiki:Gadget-fastbuttons.js e Ajuda:Página de testes/1: diferenças entre as páginas

(Diferenças entre páginas)
Página 1
Página 2
Conteúdo apagado Conteúdo adicionado
adicionando comentários conf solicitado em WP:PA
 
m +correções e simplificações (MediaWiki:Gadget-fastbuttons.js)
 
Linha 31: Linha 31:


/*** Menu [ER] ***/
/*** Menu [ER] ***/
var fbEr = "Regra:";
window.fbEr = "Regra:";
fbEr += " 1 " + [
window.fbEr += " 1 " + [
fbLink("ER|5", "5", "Aparecimento recorrente (se o conteúdo for igual" +
fbLink("ER|5", "5", "Aparecimento recorrente (se o conteúdo for igual" +
" ao eliminado por votação)"),
" ao eliminado por votação)"),
Linha 109: Linha 109:
/*** Menu [ESR] ***/
/*** Menu [ESR] ***/
// FIXME: Update deprecated attributes to CSS: cellspacing --> border-spacing, valign --> vertical-align
// FIXME: Update deprecated attributes to CSS: cellspacing --> border-spacing, valign --> vertical-align
var fbEsr = "<table cellspacing=0 style=\"color:#7D7D7D\"><tr><td valign=top>"
window.fbEsr = "<table cellspacing=0 style=\"color:#7D7D7D\"><tr><td valign=top>"
+ fbLink("subst:ESR-banda|1=~~" + "~~", "banda", "Artigo sobre banda sem fontes e sem notoriedade")
+ fbLink("subst:ESR-banda|1=~~" + "~~", "banda", "Artigo sobre banda sem fontes e sem notoriedade")
+ "|" + fbLink("subst:ESR-bio|1=~~" + "~~", "biografia", "Biografia sem fontes e sem notoriedade")
+ "|" + fbLink("subst:ESR-bio|1=~~" + "~~", "biografia", "Biografia sem fontes e sem notoriedade")
Linha 117: Linha 117:
// TODO: Merge with function fbesbok() defined below, possibly using jQuery
// TODO: Merge with function fbesbok() defined below, possibly using jQuery
// $('#target').keypress()
// $('#target').keypress()
function fbesrok(evt) {
window.fbesrok = function(evt) {
if (window.event && window.event.keyCode == 13) {
if (window.event && window.event.keyCode == 13) {
evt = "ok";
evt = "ok";
Linha 124: Linha 124:
}
}
if (evt == "ok") {
if (evt == "ok") {
fb("subst:ESR", document.getElementById("esrinput").value + " ~~" + "~~");
window.fb("subst:ESR", document.getElementById("esrinput").value + " ~~" + "~~");
}
}
}
};


/*** Menu [esboço] ***/
/*** Menu [esboço] ***/
//FIXME: Update deprecated attributes to CSS: cellspacing --> border-spacing, valign --> vertical-align
//FIXME: Update deprecated attributes to CSS: cellspacing --> border-spacing, valign --> vertical-align
var fbEsb = "<table cellspacing=0 style=\"color:#7D7D7D\">" +
window.fbEsb = "<table cellspacing=0 style=\"color:#7D7D7D\">" +
"<tr><td valign=top>" +
"<tr><td valign=top>" +
fbLink("mínimo", "mínimo", "Artigo com apenas uma frase") +
fbLink("mínimo", "mínimo", "Artigo com apenas uma frase") +
Linha 143: Linha 143:


//TODO: Merge with function fbesrok() defined above, possibly using $('#target').keypress()
//TODO: Merge with function fbesrok() defined above, possibly using $('#target').keypress()
function fbesbok(evt) {
window.fbesbok = function (evt) {
if (window.event && window.event.keyCode == 13) {
if (window.event && window.event.keyCode == 13) {
evt = "ok";
evt = "ok";
Linha 150: Linha 150:
}
}
if (evt == "ok") {
if (evt == "ok") {
fb("esboço-" + document.getElementById("esbinput").value);
window.fb("esboço-" + document.getElementById("esbinput").value);
}
}
}
};


/*** Menu [manuteção] ***/
/*** Menu [manuteção] ***/
var fbMan = [
window.fbMan = [
fbLink("subst:wkf", "wikificar", "Não está formatado de acordo com o livro" +
fbLink("subst:wkf", "wikificar", "Não está formatado de acordo com o livro" +
" de estilo"),
" de estilo"),
Linha 186: Linha 186:
}
}
fbtitulo = encodeURIComponent(fbtitulo);
fbtitulo = encodeURIComponent(fbtitulo);
var fbbus = "<span class=\"plainlinks\"><a href=\"http://www.google.com/search?&as_eq=wikipedia&as_epq="
window.fbbus = "<span class=\"plainlinks\"><a href=\"http://www.google.com/search?&as_eq=wikipedia&as_epq="
+ fbtitulo + "\" class=\"external text\">Google</a> — <a href=\"http://news.google.com/archivesearch?&as_src=-newswire+-wire+-presswire+-PR+-press+-release&as_epq="
+ fbtitulo + "\" class=\"external text\">Google</a> — <a href=\"http://news.google.com/archivesearch?&as_src=-newswire+-wire+-presswire+-PR+-press+-release&as_epq="
+ fbtitulo + "\" class=\"external text\">notícias</a>, <a href=\"http://books.google.com/books?&as_brr=0&as_epq="
+ fbtitulo + "\" class=\"external text\">notícias</a>, <a href=\"http://books.google.com/books?&as_brr=0&as_epq="
Linha 267: Linha 267:
* TODO: Replace ocurrences of this function by something like $(...).html()
* TODO: Replace ocurrences of this function by something like $(...).html()
*/
*/
function fbabrir(menu) {
window.fbabrir = function (menu) {
fb2.innerHTML = menu;
fb2.innerHTML = menu;
}
};


/* Função de edição
/* Função de edição
Linha 277: Linha 277:
* @return: {boolean} Returns false if the user canceled or the page already has a template
* @return: {boolean} Returns false if the user canceled or the page already has a template
*/
*/
function fb(fbedit, fbtxt) {
window.fb = function (fbedit, fbtxt) {
var txtbox = document.getElementById("wpTextbox1");
var txtbox = document.getElementById("wpTextbox1");
if (fbtxt === null) {
if (fbtxt === null) {
Linha 418: Linha 418:
}
}
}
}
}
};




/* Consulta a API do MediaWiki usando AJAX
/* Consulta a API do MediaWiki usando AJAX
* @param: {string} fapi An abreviation such as "esb", "afl", "PV",
* @param: {string} fapi An abreviation such as "esb", "afl", "PV",
* @param: {string} url The url of the API query
* @param: {string} url The url of the API query
* TODO: Use jQuery functions
* FIXME: @deprecated Use jQuery AJAX functions (see [[mw:RL/JD#ajax.js]] )
*/
*/
function fbajax(fapi, url) {
function fbajax(fapi, url) {
Linha 435: Linha 435:
fajax.onreadystatechange = function () {
fajax.onreadystatechange = function () {
if (fajax.readyState == 4 && fajax.status == 200) {
if (fajax.readyState == 4 && fajax.status == 200) {
fbapi(fapi, fajax.responseXML);
window.fbapi(fapi, fajax.responseXML);
}
}
};
};
Linha 441: Linha 441:


/* Callback function for API calls
/* Callback function for API calls
* @param {string} fapi An abreviation such as "esb", "afl", "PV",
* @param {string} fapi An abreviation such as "esb", "afl", "PV",
* @param {Object} api
* @param {Object} api HTML code???
*/
*/
function fbapi(fapi, api) {
window.fbapi = function (fapi, api) {
var url, esb, i, pages, charnum, title, tamanho, coment, user;
var url, esb, i, pages = '', charnum = 0, title, tamanho, coment, user;
if (!api) {
if (!api) {
url = mw.config.get('wgScriptPath') + "/api.php?format=xml&action=query&";
url = mw.config.get('wgScriptPath') + "/api.php?format=xml&action=query&";
// TODO: Criar um objeto { 'esb': ..., 'afl':... } com um item para cada "fabi"
if (fapi == "esb") {
switch ( fapi ) {
esb = document.getElementById("esbinput");
case 'esb':
if (esbtxt == esb.value || esbtxt2 == esb.value) {
esb = document.getElementById("esbinput");
return;
if (esbtxt == esb.value || esbtxt2 == esb.value) {
}
return;
esbtxt = esb.value;
}
if (esbtxt == esb.value.substr(0, (esb.value.length - 1))) {
esbtxt = esb.value;
return;
if (esbtxt == esb.value.substr(0, (esb.value.length - 1))) {
}
return;
url += "list=allpages&apnamespace=10&aplimit=1&apprefix=" +
}
url += "list=allpages&aplimit=1&apnamespace=10&apprefix=" +
encodeURI("Esboço-") + encodeURIComponent(esb.value);
encodeURI("Esboço-") + encodeURIComponent(esb.value);
break;
} else if (fapi == "afl") {
case 'afl':
url += "list=backlinks&bllimit=1&blfilterredir=nonredirects" +
url += "list=backlinks&bllimit=1&blfilterredir=nonredirects" +
"&blnamespace=0&bltitle=" +
"&blnamespace=0&bltitle=" +
encodeURIComponent(mw.config.get('wgPageName'));
encodeURIComponent(mw.config.get('wgPageName'));
break;
} else if (fapi == "PV") {
case 'PV':
url += "list=watchlist&wlexcludeuser=" +
url += "list=watchlist&wlexcludeuser=" +
encodeURIComponent(mw.config.get('wgUserName')) +
encodeURIComponent(mw.config.get('wgUserName')) +
"&wlprop=user|comment|title|sizes";
"&wlprop=user|comment|title|sizes";
break;
} else if (fapi == "PN") {
case 'PN':
url += "list=recentchanges&rctype=new&rcnamespace=0" +
url += "list=recentchanges&rctype=new&rcnamespace=0" +
"&rcshow=!patrolled&rcprop=user|comment|title|sizes|ids";
"&rcshow=!patrolled&rcprop=user|comment|title|sizes|ids";
break;
} else if (fapi == "MR") {
case 'MR':
url += "list=recentchanges&rctype=edit&rcnamespace=0" +
url += "list=recentchanges&rctype=edit&rcnamespace=0" +
"&rcshow=anon&rcprop=user|comment|title|sizes";
"&rcshow=anon&rcprop=user|comment|title|sizes";
break;
} else if (fapi == "usu") {
case 'usu':
user = mw.config.get('wgTitle');
user = mw.config.get('wgTitle');
if (user.indexOf('/') > -1) {
user = user.substring(0, user.indexOf('/'));
if (user.indexOf('/') > -1) {
user = user.substring(0, user.indexOf('/'));
}
}
url += "list=allusers&aulimit=1&aufrom=" +
url += "list=allusers&aulimit=1&aufrom=" +
encodeURIComponent(user) + "&auprop=editcount|registration";
encodeURIComponent(user) + "&auprop=editcount|registration";
break;
}
}
fbajax(fapi, url);
fbajax(fapi, url);
} else {
} else {
/** Processamento da resposta do API **/
/** Processamento da resposta do API **/
if (fapi == "afl") { // Afluentes
switch ( fapi ) {
case 'afl':
var info = "(";
// Afluentes
info += (document.getElementById("Refer.C3.AAncias")
var info = "(";
info += (document.getElementById("Refer.C3.AAncias")
|| document.getElementById("Notas_e_refer.C3.AAncias")) ?
|| document.getElementById("Notas_e_refer.C3.AAncias")) ?
"ref" :
"ref" :
"<span style=\"color:red\">ref</span>";
"<span style=\"color:red\">ref</span>";
var catline = document.getElementById("mw-normal-catlinks");
var catline = document.getElementById("mw-normal-catlinks");
// FIXME: Do not do screen scraping to get this info!
// FIXME: Do not do screen scraping to get this info!
if (catline && catline.innerHTML.indexOf("><a href=\"" + mw.config.get('wgArticlePath').replace('$1', '')) > -1) {
if (catline && catline.innerHTML.indexOf("><a href=\"" + mw.config.get('wgArticlePath').replace('$1', '')) > -1) {
info += " · cat";
info += " · cat";
} else {
} else {
info += " · <span style=\"color:red\" title=\"Esta página ainda não foi categorizada\">cat</span>";
info += " · <span style=\"color:red\" title=\"Esta página ainda não foi categorizada\">cat</span>";
}
}
info += (document.getElementById("p-lang")) ?
info += (document.getElementById("p-lang")) ?
" · iw" :
" · iw" :
" · <span style=\"color:red\" title=\"Esta página ainda não" +
" · <span style=\"color:red\" title=\"Esta página ainda não" +
" possui links para outros idiomas\">iw</span>";
" possui links para outros idiomas\">iw</span>";
api = api.getElementsByTagName("bl");
api = api.getElementsByTagName("bl");
if (api[0]) {
if (api && api.length) {
info += " · <a href=\"" +
info += " · <a href=\"" +
mw.util.wikiGetlink( 'Especial:Páginas afluentes/' + mw.config.get('wgPageName') ) +
mw.util.wikiGetlink( 'Especial:Páginas afluentes/' + mw.config.get('wgPageName') ) +
"\" title=\"afluentes\">afl</a>)";
"\" title=\"afluentes\">afl</a>)";
} else {
} else {
info += " · <span style=\"color:red\">afl</span>)";
info += " · <span style=\"color:red\">afl</span>)";
}
}
url = mw.config.get('wgScriptPath') +
url = mw.config.get('wgScriptPath') +
"/api.php?format=xml&action=query&prop=categories&titles=" +
"/api.php?format=xml&action=query&prop=categories&titles=" +
mw.config.get('wgFormattedNamespaces')[ mw.config.get('wgNamespaceNumber') + 1 ] +
mw.config.get('wgFormattedNamespaces')[ mw.config.get('wgNamespaceNumber') + 1 ] +
encodeURIComponent( mw.config.get('wgTitle') );
encodeURIComponent( mw.config.get('wgTitle') );
fb2.innerHTML = info;
fb2.innerHTML = info;
if (document.getElementById("ca-talk").className != "new") {
if (document.getElementById("ca-talk").className != "new") {
fbajax("qualidade", url);
fbajax("qualidade", url);
} else {
} else {
var hidcat = document.getElementById("mw-hidden-catlinks");
var hidcat = document.getElementById("mw-hidden-catlinks");
if (hidcat) {
if (hidcat) {
hidcat = hidcat.innerHTML;
hidcat = hidcat.innerHTML;
if (hidcat.indexOf("!Artigos de qualidade") > -1) {
if (hidcat.indexOf("!Artigos de qualidade") > -1) {
hidcat = hidcat.substr(hidcat.indexOf("!Artigos de qualidade") + 22, 1);
hidcat = hidcat.substr(hidcat.indexOf("!Artigos de qualidade") + 22, 1);
if (hidcat == "d") {
if (hidcat == "d") {
hidcat = "?";
hidcat = "?";
}
}
fb2.innerHTML += "<span title='Qualidade do artigo'> Q-<b>" +
fb2.innerHTML += "<span title='Qualidade do artigo'> Q-<b>" +
hidcat + "</b></span>";
hidcat + "</b></span>";
}
}
}
}
}
}
break;
} else if (fapi == "qualidade") { // Qualidade do artigo
case 'qualidade':
// Qualidade do artigo
api = api.getElementsByTagName("cl");
api = api.getElementsByTagName("cl");
if (api) {
if (api) {
var apicat;
var apicat;
for (i = 0; i < api.length; i++) {
for (i = 0; i < api.length; i++) {
if (!api[i]){
continue;
}
apicat = api[i].getAttribute("title");
apicat = api[i].getAttribute("title");
if (apicat.indexOf("!Artigos de qualidade") > -1) {
if (apicat.indexOf("!Artigos de qualidade") > -1) {
Linha 549: Linha 564:
return;
return;
}
}
} else if (fapi == "esb") {
break;
case 'esb':
// Esboço temático
// Esboço temático
api = api.getElementsByTagName("p");
api = api.getElementsByTagName("p");
if (api) {
if (api && api.length) {
api = api[0].getAttribute("title")
api = api[0].getAttribute("title")
.replace(/Predefinição:Esboço-/gi, "");
.replace(/Predefinição:Esboço-/gi, "");
Linha 581: Linha 597:
}
}
}
}
} else if (fapi == "PV") {
break;
case 'PV':
// Páginas vigiadas
// Páginas vigiadas
api = api.getElementsByTagName("item");
api = api.getElementsByTagName("item");
charnum = 0;
for (i = 0; i < api.length && i < 10; i++) {
if (!api[i]){
for (i = 0; i < 10; i++) {
continue;
}
title = api[i].getAttribute("title");
title = api[i].getAttribute("title");
charnum += title.length;
charnum += title.length;
Linha 602: Linha 621:
coment = coment.replace("[[Ajuda:Guia de edição/Menus e" +
coment = coment.replace("[[Ajuda:Guia de edição/Menus e" +
" ferramentas/Sumário de edição|?]]", "");
" ferramentas/Sumário de edição|?]]", "");
if (i === 0) {
if ( i > 0){
pages += ' | ';
pages = "";
}
} else {
pages += " |";
pages += "<a href=\"" + mw.util.wikiGetlink( title ) +
}
pages += " <a href=\"" + mw.util.wikiGetlink( title ) +
"?diff=last\" title=\"(" + tamanho + ") " +
"?diff=last\" title=\"(" + tamanho + ") " +
api[i].getAttribute("user") + " " + coment + "\">" +
api[i].getAttribute("user") + " " + coment + "\">" +
Linha 613: Linha 630:
}
}
fb2.innerHTML = pages;
fb2.innerHTML = pages;
break;
} else if (fapi == "PN") { // Páginas novas
case 'PN':
// Páginas novas
api = api.getElementsByTagName("rc");
api = api.getElementsByTagName("rc");
charnum = 0;
for (i = 0; i < api.length && i < 10; i++) {
if (!api[i]){
for (i = 0; i < 10; i++) {
continue;
}
title = api[i].getAttribute("title");
title = api[i].getAttribute("title");
charnum += title.length;
charnum += title.length;
Linha 627: Linha 648:
coment = "(" + coment.replace("[[Ajuda:SEA|?]] ", "") + ")";
coment = "(" + coment.replace("[[Ajuda:SEA|?]] ", "") + ")";
}
}
if (i === 0) {
if ( i > 0){
pages += ' | ';
pages = "";
}
} else {
pages += " |";
pages += "<a href=\"" + mw.util.wikiGetlink( title )
}
pages += " <a href=\"" + mw.util.wikiGetlink( title )
+ "?redirect=no&rcid=" + api[i].getAttribute("rcid")
+ "?redirect=no&rcid=" + api[i].getAttribute("rcid")
+ "\" title=\"(" + tamanho + ") " +
+ "\" title=\"(" + tamanho + ") " +
Linha 639: Linha 658:
}
}
fb2.innerHTML = pages;
fb2.innerHTML = pages;
break;
} else if (fapi == "MR") { // Mudanças recentes
case 'MR':
// Mudanças recentes
api = api.getElementsByTagName("rc");
api = api.getElementsByTagName("rc");
charnum = 0;
for (i = 0; i < api.length && i < 10; i++) {
if (!api[i]){
for (i = 0; i < 10; i++) {
continue;
}
title = api[i].getAttribute("title");
title = api[i].getAttribute("title");
charnum += title.length;
charnum += title.length;
Linha 657: Linha 680:
coment = "(" + coment.replace("*/", ":") + ")";
coment = "(" + coment.replace("*/", ":") + ")";
}
}
if (i === 0) {
if ( i > 0){
pages += ' | ';
pages = "";
}
} else {
pages += "<a href=\"" + mw.util.wikiGetlink( title )
pages += " |";
}
pages += " <a href=\"" + mw.util.wikiGetlink( title )
+ "?diff=last\" title=\"(" + tamanho + ") "
+ "?diff=last\" title=\"(" + tamanho + ") "
+ api[i].getAttribute("user") + " "
+ api[i].getAttribute("user") + " "
Linha 668: Linha 689:
}
}
fb2.innerHTML = pages;
fb2.innerHTML = pages;
break;
} else if (fapi == "usu") { // Informações do usuário
case 'usu':
// Informações do usuário
api = api.getElementsByTagName("u");
api = api.getElementsByTagName("u");
var registro = api[0].getAttribute("registration");
if ( api && api.length ) {
var registro = api[0].getAttribute("registration");
registro = registro.substr(8, 2) + "/" + registro.substr(5, 2) +
registro = registro.substr(8, 2) + "/" + registro.substr(5, 2) +
"/" + registro.substr(0, 4);
"/" + registro.substr(0, 4);
user = mw.config.get('wgTitle');
user = mw.config.get('wgTitle');
if (user.indexOf("/") > -1) {
if (user.indexOf("/") > -1) {
user = user.substring(0, user.indexOf("/"));
user = user.substring(0, user.indexOf("/"));
}
}
var encUser = encodeURI(user);
var encUser = encodeURI(user);
fb2.innerHTML =
fb2.innerHTML =
"<span style=\"color:black\">" +
"<span style=\"color:black\">" +
api[0].getAttribute("editcount") +
api[0].getAttribute("editcount") +
"</span> edições desde <span style=\"color:black\">" +
"</span> edições desde <span style=\"color:black\">" +
registro + "</span> | <a href=\"" +
registro + "</span> | <a href=\"" +
mw.util.wikiGetlink( 'Especial:Contribuições/' ) +
mw.util.wikiGetlink( 'Especial:Contribuições/' ) +
encUser +
encUser +
"\">contribuições</a> | <a href=\"" +
"\">contribuições</a> | <a href=\"" +
mw.util.wikiGetlink( 'Especial:Registo/' ) +
mw.util.wikiGetlink( 'Especial:Registo/' ) +
encUser +
encUser +
"\">registros</a> | <a href=\"" +
"\">registros</a> | <a href=\"" +
mw.util.wikiGetlink( 'Especial:Registo' ) +
mw.util.wikiGetlink( 'Especial:Registo' ) +
"?type=block&page=Usu%C3%A1rio%3A" +
"?type=block&page=Usu%C3%A1rio%3A" +
encUser +
encUser +
"\">registros de bloqueio</a> | <span class=\"plainlinks\">" +
"\">registros de bloqueio</a> | <span class=\"plainlinks\">" +
"<a href=\"http://toolserver.org/~river/cgi-bin/count_edits?user=" +
"<a href=\"http://toolserver.org/~river/cgi-bin/count_edits?user=" +
encUser +
encUser +
"&dbname=ptwiki_p\" class=\"external text\">contador de edições</a></span>";
"&dbname=ptwiki_p\" class=\"external text\">contador de edições</a></span>";
} else {
return;
}
break;
}
}
}
}
}
};


/* Executes the gadget when document is ready */
/* Executes the gadget when document is ready */
Linha 745: Linha 773:
" onClick='fbabrir(fbbus)'>busca</a>]";
" onClick='fbabrir(fbbus)'>busca</a>]";
if (mw.config.get('wgAction') === "view") {
if (mw.config.get('wgAction') === "view") {
fbapi("afl");
window.fbapi("afl");
}
}
} else {
} else {
Linha 782: Linha 810:
fbsalve = (fbedit !== null);
fbsalve = (fbedit !== null);
if (fbsalve) {
if (fbsalve) {
fb(fbedit, mw.util.getParamValue('fbtxt') || '');
window.fb(fbedit, mw.util.getParamValue('fbtxt') || '');
}
}
break;
break;