Usuario:Bawolff/comment.js
Nota: Después de guardar, debes recargar la caché de tu navegador para ver los cambios:
- Mozilla: Pulsa Recargar (o Ctrl-R)
- Internet Explorer / Opera: Ctrl-F5
- Safari: Cmd-R
- Konqueror Ctrl-R.
// <source lang="JavaScript">
// This script has some crappy hacks in it, and won't work as of current on other languages probably
// I would assume this script is
// under the GFDL. it was originally at [[commons:MediaWiki:Extra-tabs.js]]
// written by Dbenbenn, Avatar, Duesentrieb and Arnomane
// modified by User:en:bawolff for en.wikinews and User:Jurock for es.wikinews. Ajax stuff added by
// User:en:TheFearrow
// Switch for people that don't want the extra tabs.
load_extratabs = true;
if (load_extratabs == true)
{
// Translations (variables for internationalisation and localisation):
// project
// It is tempting to replace this with wgServer.replace("http://", "")
var tab_project = 'es.wikinews.org';
var talknamespace = 'Discusión:';
var commentSubpage = '/Comentarios';
var MainPage = 'Portada'
var commentsPreload = 'Plantilla:Comentarios_preload'
var commentsIntro = 'Plantilla:Comentarios_intro'
tab_view_comment_on_article = 'opinion';
//--Start doing stuff
//Fix existing tabs
function global_fix_comment_tabs() {
var base_article = wgPageName;
//should always be true
if (base_article.indexOf(talknamespace) != -1) {
base_article.replace(talknamespace, "");
base_article = encodeURI(base_article);
// try something. killing this line var base_article = base_article.replace("%3A", ":").replace("%2F", "/").replace("%C3%A1", "á").replace("%C3%A9", "é").replace("%C3%AD", "í").replace("%C3%BA", "ú").replace("%C3%B3", "ó");
var article_tab = document.getElementById('ca-nstab-main');
var article_tab_link = article_tab.firstChild.getAttribute('href');
var base_number = base_article.lastIndexOf(commentSubpage);
//if the title does not not (note double not = positive) have /comment ( commentSubpage) on the end
if (base_number != -1) {
//get rid of talk (7)
base_article = base_article.substring(talknamespace.length,base_number);
//escape spaces
article_tab_link = base_article.replace(" ", "_");
article_tab.firstChild.setAttribute('href', '/wiki/' + article_tab_link);
//Fixme: Why am I removing the class? probably should not do that.
article_tab.removeAttribute("class");
//fix talk tab
document.getElementById('ca-talk').firstChild.setAttribute('href', "/wiki/" + talknamespace + article_tab_link);
//since where here, show that we're here
document.getElementById('ca-view-comment').setAttribute('class', 'selected');
}
}
}
// Appends a new tab.
function global_append_tab(url, name, id)
{
var na = document.createElement('a');
na.setAttribute('href', url);
var txt = document.createTextNode(name);
na.appendChild(txt);
var li = document.createElement('li');
if(id) li.id = id;
li.appendChild(na);
// Grab the element we want to append the tab and append the tab to it.
var hist = document.getElementById('ca-edit');
var c1 = document.getElementById('column-one');
var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
tabs.insertBefore(li, hist);
//perhaps this should be done through css, so in other skins, weirdeness doesn't happen
document.getElementById('ca-talk').style.marginRight = ".3em";
document.getElementById('ca-view-comment').style.marginRight = "1.6em";
}
function global_add_article_tabs(article)
{
var appendComments = '';
if (wgPageName.indexOf(commentSubpage) == -1) {
appendComments = commentSubpage;
}
if (article !== talknamespace + MainPage)
{
global_append_tab('/wiki/' + article + appendComments, tab_view_comment_on_article, 'ca-view-comment');
}
}
function global_do_onload()
{
// extract the namespace
// var title = global_get_tidy_title();
var title = wgPageName;
// Namespace numbers are (see [[m:Help:Variables]]):
// -1: Special
// 0: Article (main)
// 1: talk
// 2: User
// 3: User_talk
// 6: Image
// 7: Image_talk
// 14: Category
switch(wgNamespaceNumber)
{
//case -1:
// global_add_special_tabs(title);
// break;
case 0:
global_add_article_tabs(talknamespace + title);
break;
case 1:
global_add_article_tabs(title);
break;
//case 2:
//case 3:
// global_add_user_tabs(title);
// break;
//case 6:
//case 7:
// global_add_image_tabs(title);
// break;
//case 14:
// global_add_category_tabs(title);
// break;
default:
// nothing
}
global_fix_comment_tabs();
// checking if pages exist
function reddenTabs() {
var title = wgTitle;
if (wgNamespaceNumber == 1 || wgNamespaceNumber == 0) { // main and talk namespace only
if (title != MainPage) { //don't check for main page
if (wgPageName.lastIndexOf(commentSubpage) == -1) { // not viewing comments page
checkCommentaryPageExist(talknamespace + title + commentSubpage);
} else {
var newtitle = title.replace(commentSubpage, "");
checkCommentaryPageExist(talknamespace + newtitle);
}
}
}
}
reddenTabs();
}
// The following two functions run a background check of api.php to see
// if the particular page exists, so a non-existing comment page can be red,
// and an existing comment page will look like a normal tab.
//Takes arguments for talk ns name, and Comment subpage name so I can define them all in one spot
function checkCommentaryPageExist(pageName) {
var x;
x = sajax_init_object();
// do nothing if we can't check
if (!x) {
return;
}
x.open("GET", "http://es.wikinews.org/w/api.php?action=query&format=xml&titles=" + pageName, true);
x.setRequestHeader("Pragma", "cache=yes");
x.setRequestHeader("Cache-Control", "no-transform");
x.onreadystatechange = function() {
if (x.readyState == 4) {
if (x.status == 200) {
var xmldoc = x.responseXML;
var xpage = xmldoc.getElementsByTagName('page');
if (xpage.item(0).hasAttribute('missing')) { // is missing
if (pageName.indexOf("/Comentarios") == -1) {
document.getElementById('ca-talk').className = 'new';
document.getElementById('ca-talk').firstChild.setAttribute('href',
'http://es.wikinews.org/w/index.php?title=' + pageName + '&action=edit');
} else {
document.getElementById('ca-view-comment').className = 'new';
document.getElementById('ca-view-comment').firstChild.setAttribute('href',
'http://es.wikinews.org/w/index.php?title=' + pageName +
'&action=edit&preload=' + commentsPreload +
'&editintro=' + commentsIntro);
}
}
}
}
};
x.send(null);
}
addOnloadHook( global_do_onload );
}
// END: MediaWiki interface button definition for comments. this was modified
// by Bawolff for en.wikinews comments from [[commons:Mediawiki:extra-tabs.js]]. Translated (up to
// now by Jurock).
// ========================================================================
// </source>