"use strict";
/*globals mw, jQuery */
// {{documentation}}
var conf = mw.config.get([
'wgPageName',
'wgUserLanguage',
'wgNamespaceNumber',
'wgNamespaceIds',
'wgTitle',
'wgCanonicalNamespace'
]);
var msg = {
'main-title': "İçerik sayfasını göster [⌃⌥c]",
'talk-title': "İçerik ile ilgili tartışma [⌃⌥t]",
'citations-title': "İçerik ile ilgili alıntılar",
'template-title': "Şablon sayfasını görüntüle",
'module-title': "Modül sayfasını görüntüle",
'documentation-title': "Belgeleme sayfasını görüntüle",
'main-access': "c",
'talk-access': "t",
'main-id': "ca-nstab-main",
'talk-id': "ca-talk",
'citations-id': "ca-nstab-alıntılar",
'template-id': "ca-nstab-template",
'module-id': "ca-nstab-module",
'template': "Şablon",
'module': "Modül"
};
function addTab(name, page, rel, type, exists) {
return "<li id='"+msg[type+"-id"]+"' class='"+(exists == 0 ? "new" : "")+" vector-tab-noicon mw-list-item'>" +
"<a href='/wiki/" + (name === "Madde" ? "" : name + ":") + page +
(type === "documentation" ? "/belge" : "") + "' " +
(rel === "" ? "" : "rel='" + rel + "' ") +
"title='" + (exists === 1 ? msg[type+"-title"] : msg[type+"-title"].replace(" [", " (sayfa mevcut değil) [")) +
"' "+ (msg[type+"-access"] ? "accesskey='"+ msg[type+"-access"] + "'" : "") +">" +
(type === "documentation" ? "Belgeleme" : ((name == "Şablon tartışma" || name == "Modül tartışma") ? "Tartışma" : name)) +
"</a></li>";
}
function createAllTabs(type) {
var check1 = $("#p-associated-pages");
var check2 = $("#p-namespaces");
var element = check1.length ? check1 : (check2.length ? check2 : $("#p-cactions"));
var pages = [ conf.wgTitle, "Tartışma:"+conf.wgTitle, "Alıntılar:"+conf.wgTitle,
msg[type] + ":"+conf.wgTitle.replace("/belge", ""), msg[type]+":"+conf.wgTitle+"/belge",
msg[type] + " tartışma:"+conf.wgTitle.replace("/belge", "")];
new mw.Api().get( {
action: "query",
titles: pages,
} ).then( function( ret ) {
var exists = {};
$.each( ret.query.pages, function() {
if ( this.pageid ) {
exists[this.title] = "1";
} else {
exists[this.title] = "0";
}
} );
var found = element.find(".vector-menu-content-list");
if (type === "main") {
found.append(addTab("Alıntılar", conf.wgTitle, "", "citations", exists[pages[2]]));
} else if (type == "citations") {
found.children().last().remove();
found.prepend(addTab("Madde", conf.wgTitle, "", "main", exists[pages[0]]) +
addTab("Tartışma", conf.wgTitle, "discussion", "talk", exists[pages[1]]));
} else if (type === "template" || type == "module") {
if (conf.wgTitle.endsWith("/belge")) {
found.children().last().remove();
found.prepend(addTab(msg[type], conf.wgTitle.replace("/belge", ""), "", type, exists[pages[3]]) +
addTab(msg[type]+" tartışma", conf.wgTitle.replace("/belge", ""), "", "talk", exists[pages[5]]));
found.children().last().find("span").text("Belgeleme");
} else {
found.append(addTab(msg[type], conf.wgTitle, "", "documentation", exists[pages[4]]));
}
}
}, function( error ) {});
}
$( document ).ready( function ( $, mw ) {
if ((conf.wgNamespaceNumber === 0) || (conf.wgNamespaceNumber === conf.wgNamespaceIds.talk)) {
createAllTabs("main");
} else if (conf.wgNamespaceNumber === conf.wgNamespaceIds['alıntılar']) {
createAllTabs("citations");
} else if (conf.wgNamespaceNumber === conf.wgNamespaceIds.module ||
conf.wgNamespaceNumber === conf.wgNamespaceIds.module_talk) {
createAllTabs("module");
} else if (conf.wgNamespaceNumber === conf.wgNamespaceIds.template ||
conf.wgNamespaceNumber === conf.wgNamespaceIds.template_talk) {
createAllTabs("template");
}
});