// <nowiki>
// implicit dependencies : ext.gadget.Editor,ext.gadget.LegacyScriptsNewNode,mediawiki.cookie,ext.gadget.LanguageUtils,mediawiki.util
/* jshint maxerr:1048576, strict:true, undef:true, latedef:true, esversion:5, sub:true */
/* global mw, newNode, importScript, importScriptURI, $, AdderWrapper */
/**
* Storage of "string" preferences.
*/
function CookiePreferences(context) {
//Repeated calls with the same context should get the same preferences object.
if (arguments.callee)
return arguments.callee;
else
arguments.callee = this;
var storage = {};
var defaults = {};
/**
* Change the value of a preference and store into a cookie.
*/
this.set = function (name, value) {
if (value === null || storage === value)
return;
storage = value;
updateCookie();
};
/**
* Get the value of a preference from the cookie or default
*
* If the preference isn't set, return the second argument or undefined.
*/
this.get = function (name, def) {
return storage || defaults || def;
};
/**
* let the default for get(name) be value for this session
*/
this.setDefault = function (name, value) {
defaults = value;
};
// Save storage into the cookie.
function updateCookie() {
var value = "";
for (var name in storage) {
value += '&' + encodeURIComponent(name) + "=" + encodeURIComponent(storage);
}
mw.cookie.set('preferences' + context, value, {
expires: 30
});
}
// Load storage from the cookie.
// NOTE: If you wish to update the cookie format, both loading and storing
// must continue to work for 30 days.
function updateStorage() {
var value = mw.cookie.set('preferences' + context, value, {
expires: 30
}) || '';
var pairs = value.split('&');
for (var i = 1; i < pairs.length; i++) {
var val = pairs.split('=');
if (storage] === val)
continue;
storage] = val;
}
}
//__init__
updateStorage();
}
var util = {
getVanillaIndexOf: function (str, text, pos) {
if (!pos)
pos = 0;
var cpos = 0,
tpos = 0,
wpos = 0,
spos = 0;
do {
cpos = text.indexOf('<!--', pos);
tpos = text.indexOf('{{', pos);
wpos = text.indexOf('<nowiki>', pos);
spos = text.indexOf(str, pos);
pos = Math.min(
cpos == -1 ? Infinity : cpos,
tpos == -1 ? Infinity : tpos,
wpos == -1 ? Infinity : wpos,
spos == -1 ? Infinity : spos
);
if (pos == spos)
return pos == Infinity ? -1 : pos;
else if (pos == cpos)
pos = text.indexOf('-->', pos) + 3;
else if (pos == wpos)
pos = text.indexOf('<\/nowiki>', pos) + 9;
else if (pos == tpos) //FIXME
pos = text.indexOf('}}', pos) + 2;
} while (pos < Infinity);
return -1;
},
validateNoWikisyntax: function (field, nonempty) {
return function (txt, error) {
if (//.test(txt))
return error("Please don't use wiki markup ({}#) in the " + field + ".");
if (nonempty && !txt)
return error("Please specify a " + field + ".");
return txt;
};
},
// pos is a position in the line containing the gloss
getWikitextGloss: function (txt, pos) {
var g_start = txt.lastIndexOf('\n{{Üst', pos) + 1;
var g_end = txt.indexOf('\n', pos);
var g_line = txt.substr(g_start, g_end - g_start);
g_line = g_line.replace("{{Üst}}", "{{Üst|Çeviriler|tip=çeviriler}}");
return g_line.replace(/\{\{Üst\|(.*)\}\}/, "$1");
},
// get of position of wikitext for trans_table containing node in text
getTransTable: function (text, node, recursive) {
var gloss = util.getTransGloss(node);
var pos = 0;
var transect = ;
while (pos > -1) {
pos = util.getVanillaIndexOf('{{Üst', text, pos + 1); // }}
if (pos > -1 && util.matchGloss(util.getWikitextGloss(text, pos), gloss)) {
transect.push(pos);
}
}
if (transect.length > 1) {
var poss = transect;
transect = ;
for (var i = 0; i < poss.length; i++) {
pos = poss;
if (util.matchGloss(gloss, util.getWikitextGloss(text, pos))) {
transect.push(pos);
}
}
if (transect.length > 1 && !recursive)
transect = util.tieBreakTransTable(text, transect, node);
}
if (transect.length == 1) {
pos = transect;
pos = util.getVanillaIndexOf("\n", text, pos) + 1;
var endpos = text.indexOf('{{Alt}}', pos);
if (endpos > -1 && pos > 0)
return ;
}
return false;
},
// try to narrow down the correct poss if multiple matching trans tables
tieBreakTransTable: function (text, poss, node) {
if (node.nodeName == 'DIV') {
while (node && !(node.classList && node.classList.contains('NavFrame')))
node = node.parentNode;
var nodes = node.getElementsByTagName('table');
if (!nodes.length)
return poss;
node = nodes;
} else {
while (node && node.nodeName != 'TABLE')
node = node.parentNode;
}
var before_count = 0;
var after_count = 0;
var is_found = false;
$("table.çeviriler").each(function () {
var gloss = util.getTransGloss(this);
if (gloss == "Kontrol edilecek çeviriler")
return;
if (this == node) {
is_found = true;
return;
}
var pos = util.getTransTable(text, this, true);
if (pos) {
for (var j = 0; j < poss.length; j++) {
if (poss == pos)
return util.tieBreakTransTable(poss.splice(j, 1), node);
}
} else {
var matched = 0;
for (var j = 0; j < poss.length; j++) {
if (util.matchGloss(util.getWikitextGloss(text, poss), gloss) &&
util.matchGloss(gloss, util.getWikitextGloss(text, poss))) {
matched++;
}
}
if (matched == poss.length) {
if (is_found)
after_count++;
else
before_count++;
}
}
});
if (before_count + 1 + after_count == poss.length)
return ];
else
return poss;
},
matchGloss: function (line, gloss) {
if (gloss.match(/^ *$/))
return !!(line.match(/\{\{Üst\| *\}\}/) || line.match(/^ *$/));
var words = gloss.split(/\W+/);
var pos = 0;
for (var i = 0; i < words.length; i++) {
pos = line.indexOf(words, pos);
if (pos == -1)
return false;
}
return pos > -1;
},
//User:Karelklic
getTransGlossText: function (node) {
var ret = '';
for (var child = node.firstChild; child !== null; child = child.nextSibling) {
if (child.nodeType == 3)
ret += child.nodeValue;
else if (/^$/.test(child.nodeName) || (child.classList && child.classList.contains('wt-edit-recurse')))
ret += util.getTransGlossText(child);
else if (ret.match(/\w$/)) //Prevent new words from being created across node boundaries
ret += " ";
}
// all characters except a-zA-Z0-9 are changed to spaces
return ret.replace(/\W/g, ' ');
},
getTransGloss: function (ul) {
var node = ul;
while (node && !(node.classList && node.classList.contains('NavFrame')))
node = node.parentNode;
if (!node) return '';
for (var child = node.firstChild; child !== null; child = child.nextSibling) {
if (child.classList && child.classList.contains('NavHead'))
return util.getTransGlossText(child);
}
return '';
},
isTrreq: function (li) {
var span = li.getElementsByTagName('span');
return (span && span.classList.contains("trreq"));
},
genderList: {
"t": "tekil", "i": "ikil", "ç": "çoğul",
"e": "eril", "e-i": "eril ikil", "e-ç": "eril çoğul",
"d": "dişil", "d-i": "dişil ikil", "d-ç": "dişil çoğul",
"g": "genel", "g-i": "genel ikil", "g-ç": "genel çoğul",
"n": "nötr", "n-i": "nötr ikil", "n-ç": "nötr çoğul",
"impf": "imperfective", "pf": "perfective"
}
};
// An adder for translations on en.wikt
function TranslationAdders(editor) {
function TranslationLabeller(insertDiv) {
var original_span;
var adder_form;
var initial_value;
var edit_button;
var editing = false;
var adderInterface = {
'fields': {
'gloss': function (txt, error) {
return util.validateNoWikisyntax('gloss', true)(txt, error);
}
},
'createForm': function () {
var thisId = "a" + String(Math.random()).replace(".", "");
return adder_form = newNode('form', {
style: 'display: inline',
width: 'auto',
click: kill_event
},
newNode('label', {
'for': thisId
}, "Anlam: "),
newNode('input', {
type: 'text',
name: 'gloss',
value: initial_value,
style: 'width: 50%',
title: 'İlgili anlamın bir özetini girin',
id: thisId
}),
newNode('input', {
type: 'submit',
name: 'preview',
value: 'Önizle'
}),
newNode('a', {
href: 'https://dictious.com/tr/Yardım:Anlamlar'
}, 'Yardım?!')
);
},
'onsubmit': function (values, render) {
render(values.gloss, function (new_html) {
if (editing)
toggle_editing(false);
var old_html = original_span.innerHTML;
editor.addEdit({
'undo': function () {
original_span.innerHTML = old_html;
if (!editing) toggle_editing();
},
'redo': function () {
original_span.innerHTML = new_html;
if (editing) toggle_editing();
},
'edit': function (text) {
return perform_edit(text, values.gloss);
},
'summary': 'çanlam:"' + (values.gloss.length > 50 ? values.gloss.substr(0, 50) + '...' : values.gloss + '"')
}, original_span);
});
}
};
// The actual modification to the wikitext
function perform_edit(wikitext, gloss) {
var pos = util.getTransTable(wikitext, insertDiv) - 4;
var g_start = wikitext.lastIndexOf('\n{{Üst', pos) + 1;
var g_end = wikitext.indexOf('}}\n', pos) + 2;
if (g_start === 0 || wikitext.substr(g_start, g_end - g_start).indexOf("\n") > -1) {
editor.error("Çeviri tablosu bulunamadı.");
return wikitext;
} else {
return wikitext.substr(0, g_start) + '{{Üst|' + gloss + '|tip=çeviriler}}' + wikitext.substr(g_end);
}
}
// Don't open and close box when interacting with form.
function kill_event(e) {
e.stopPropagation();
}
// What to do when the +/- button is clicked.
function toggle_editing() {
if (editing) {
adder_form.style.display = "none";
original_span.style.display = "inline";
editing = false;
return;
}
editing = true;
edit_button.text("Yükleniyor...");
editor.withCurrentText(function (currentText) {
var pos = util.getTransTable(currentText, insertDiv);
edit_button.text('±');
if (!pos)
return editor.error("Çeviri tablosu bulunamadı");
var gloss_line = currentText.substr(currentText.lastIndexOf('\n', pos - 2) + 1);
gloss_line = gloss_line.substr(0, gloss_line.indexOf('\n'));
initial_value = gloss_line.replace(/^\{\{Üst(\|(.*)|)\|tip=çeviriler\}\}\s*$/, "$2");
if (initial_value.indexOf("\n") > 0)
return editor.error("İç hata: birden fazla satıra span ekleniyor");
if (!original_span) {
original_span = newNode('span', {
'class': 'wt-edit-recurse'
});
for (var i = 0; i < insertDiv.childNodes.length; i++) {
var child = insertDiv.childNodes;
if (child != edit_button && child.className !== 'NavToggle') {
original_span.appendChild(insertDiv.removeChild(child));
i--;
}
}
insertDiv.appendChild(original_span);
new AdderWrapper(editor, adderInterface, insertDiv, original_span);
}
original_span.style.display = "none";
adder_form.style.display = "inline";
adder_form.getElementsByTagName('input').focus();
});
}
edit_button = $('<a href="#">±</a>')
//.addClass("translation-gloss-edit-button")
.attr("title", "Edit table heading").css("padding", "2px").css("margin-left", "-5px")
.on("click", function (e) {
if (e && e.preventDefault)
e.preventDefault();
kill_event(e);
toggle_editing();
return false;
});
$(insertDiv).prepend(edit_button); //XXX: this places anchor before NavToggle which may not be a good idea
}
function TranslationAdder(insertUl) {
// Hippietrail
var langmetadata = new LangMetadata();
this.fields = {
lang: function (txt, error) {
if (txt == 'tr')
return error("Lütfen yabancı bir dil seçin. (en, fr, es, aaa)");
if (txt == 'nds')
return error("Lütfen Aşağı Almanca için nds-de veya Aşağı Saxon dili için de nds-nl kullanın");
if (/^{2,3}(-{1,7})?$/.test(txt))
return txt;
return error("Lütfen bir dil kodu kullanın. (en, fr, es, aaa)");
},
word: function (txt, error) {
if (txt == '{{ç}}')
return '{{ç}}';
if (txt == '{{ç}}')
return txt;
if (txt.indexOf(',') == -1 || forceComma) {
forceComma = false;
if (langmetadata.expectedCase(thiz.elements.lang.value, mw.config.get('wgTitle'), txt) || forceCase) {
forceCase = false;
return util.validateNoWikisyntax('translation', true)(txt, error);
}
if (prefs.get('case-knowledge', 'none') == 'none') {
return error(newNode('span',
"Çeviriler genelde büyük harfle başlamaz. Eğer büyük harfle başladığından eminseniz, ",
newNode('span', {
style: "color: blue; text-decoration: underline; cursor: pointer;",
click: function () {
forceCase = true;
inputForm.onsubmit();
prefs.set('case-knowledge', 'guru');
}
}, "buraya tıklayarak ekleyin.")));
} else {
var msg = newNode('span',
newNode('span', {
style: "color: blue; text-decoration: underline; cursor: pointer;",
click: function () {
prefs.set('case-knowledge', 'none');
try {
msg.parentNode.removeChild(msg);
} catch (e) {
}
editor.undo();
}
}, "Lütfen geri ala tıklayın"), " eğer bu çevirinin büyük harfle baladığına emin değilseniz.");
error(msg);
return txt;
}
}
if (prefs.get('comma-knowledge', 'none') == 'none') {
return error(newNode('span',
"Bir seferde tek çeviri ekleyebilirsiniz. Eğer bu virgül içeren bir çeviriyse, ",
newNode('span', {
style: "color: blue; text-decoration: underline; cursor: pointer;",
click: function () {
forceComma = true;
inputForm.onsubmit();
prefs.set('comma-knowledge', 'guru');
}
}, "buraya tıklayarak ekleyin.")));
} else {
var msg = newNode('span',
newNode('span', {
style: "color: blue; text-decoration: underline; cursor: pointer;",
click: function () {
prefs.set('comma-knowledge', 'none');
try {
msg.parentNode.removeChild(msg);
} catch (e) {
}
editor.undo();
}
}, "Lütfen geri ala tıklayın"), " eğer tek seferde birden fazla çeviri eklemeye çalışıyorduysanız, şu anda bu desteklenmemekte.");
error(msg);
return txt;
}
},
qual: util.validateNoWikisyntax('qualifier'),
tr: util.validateNoWikisyntax('transcription'),
rawPageName: util.validateNoWikisyntax('raw page name'),
sc: function (txt, error) {
if (txt && !/^((?:?-)?|polytonic|Latinx)$/.test(txt))
return error(newNode('span', "Lütfen ", newNode('a', {
href: 'https://dictious.com/tr/Vikisözlük:Alfabeler'
}, "geçerli bir alfane kodu girin"), "(örn. fa-Arab, Deva, polytonic)"));
var scripts = (new AlfabeAraclari()).GetScriptsByLangCode(thiz.elements.lang.value);
if (txt && scripts.length > 0 && scripts.indexOf(txt) == -1) {
var plural = scripts.length > 1;
return error(newNode('span',
"Lütfen geçerli bir alfabe kodu girin. "
+ (plural ? "Mevcut alfabe kodu" : "Bu dilde kullanılan")
+ " alfabe" + (plural ? "ler" : "") + " "
+ scripts.join(", ")));
}
if (!txt)
txt = prefs.get('script-' + thiz.elements.lang.value, langmetadata.guessScript(thiz.elements.lang.value) || '');
if (txt == 'Latn')
txt = '';
return txt;
},
nested: util.validateNoWikisyntax('nested'),
"t": 'checkbox',
"i": 'checkbox',
"ç": 'checkbox',
"e": 'checkbox',
"e-i": 'checkbox',
"e-ç": 'checkbox',
"d": 'checkbox',
"d-i": 'checkbox',
"d-ç": 'checkbox',
"g": 'checkbox',
"g-i": 'checkbox',
"g-ç": 'checkbox',
"n": 'checkbox',
"n-i": 'checkbox',
"n-ç": 'checkbox',
"impf": 'checkbox',
"pf": 'checkbox',
nclass1: util.validateNoWikisyntax('ad sınıfı'),
nclass2: util.validateNoWikisyntax('çoğul sınıfı')
};
this.createForm = function () {
function createGenderNode(name, text) {
var inp = document.createElement("input");
inp.type = "checkbox";
inp.name = name;
var lbl = document.createElement("label");
lbl.appendChild(inp);
lbl.appendChild(document.createTextNode(text));
return lbl;
}
var genderControls = {};
for (var g in util.genderList) genderControls = createGenderNode(g, util.genderList);
var controls = {
lang: newNode('input', {
size: 4,
type: 'text',
name: 'lang',
value: prefs.get('curlang', ''),
title: 'İki veya üç harfli ISO 639 dil kodu'
}),
transliteration: newNode('span', newNode('a', {
href: 'https://dictious.com/tr/Vikisözlük:Alfabe çevirisi'
}, "Alfabe çevirisi"), ": ",
newNode('input', {
name: "tr",
title: "Sözcüğün Latin alfabesine çevrilmiş hali"
}), " (örn. 字母 sözcüğü için zìmǔ)"),
qualifier: newNode('p', "Belirtici: ", newNode('input', {
name: 'qual',
title: "Sözcük için nitelik bildirici"
}), " (örn. motamot, resmi, argo)"),
display: newNode('p', "Asıl sayfa adı: ", newNode('input', {
name: 'rawPageName',
title: "Bağlantı verilecek sayfa, eğer çeviri bir sözcüğün yazılışı değilse"
}), " (örn. 疲れた sözcüğü için 疲れる)"),
script: newNode('p', newNode('a', {
href: 'https://dictious.com/tr/Vikisözlük:Alfabeler'
}, "Alfabe kodu"), ": ",
newNode('input', {
name: 'sc',
size: 6,
title: "Bu sözcüğe uygulanacak olan alfabe kodu"
}), "(örn. Kiril alfabesi için Cyrl, Latin için Latn)", newNode('br')),
nested: newNode('p', "Alt alfabe: ", newNode('input', {
name: 'nested',
title: "Dilin birçok alfabesinden birini belirleme"
}), " (örn. Sırp-Hırvatça/Kiril)"),
// Genders
genders: genderControls,
// Noun class
nclass: newNode('p',
"Ad sınıfı: ", newNode('input', {
type: 'text',
size: 4,
name: 'nclass1',
title: "Sözcüğün tekil haldeki ad sınıfı."
}),
" Çoğul sınıfı: ", newNode('input', {
type: 'text',
size: 4,
name: 'nclass2',
title: "Eğer varsa, sözcüğün çoğul haldeki ad sınıfı."
}))
};
function createGenderDiv(genderz) {
var $div = $("<div>");
for (var i = 1; i < arguments.length; i++) $div.append(genderz]);
return $div;
}
var $mdiv = createGenderDiv(controls.genders, "e", "e-i", "e-ç");
var $fdiv = createGenderDiv(controls.genders, "d", "d-i", "d-ç");
var $cdiv = createGenderDiv(controls.genders, "g", "g-i", "g-ç");
var $ndiv = createGenderDiv(controls.genders, "n", "n-i", "n-ç");
var $sdpdiv = createGenderDiv(controls.genders, "t", "i", "ç");
var $pfdiv = createGenderDiv(controls.genders, "impf", "pf");
controls.gender = $("<p>").append($mdiv).append($fdiv).append($cdiv).append($ndiv).append($sdpdiv).append($pfdiv);
langInput = controls.lang;
var showButton = newNode('span', {
'click': function () {
if (!advancedMode) {
advancedMode = true;
showButton.innerHTML = " Daha az";
} else {
advancedMode = false;
showButton.innerHTML = " Daha fazla";
}
updateScriptGuess.call(langInput, true);
},
'style': "color: #0000FF;cursor: pointer;"
}, advancedMode ? " Daha az" : " Daha fazla");
function autoTransliterate() {
var rawPageName = langmetadata.computeRawPageName(thiz.elements.lang.value, thiz.elements.word.value);
if (rawPageName && rawPageName !== thiz.elements.word.value)
thiz.elements.rawPageName.value = rawPageName;
}
function updateScriptGuess(preserve) {
preserve = (preserve === true);
//show all arguments
function show() {
for (var i = 0; i < arguments.length; i++) {
if (arguments.nodeName == 'P')
arguments.style.display = "block";
else
arguments.style.display = "inline";
}
}
//hide all arguments
function hide() {
for (var i = 0; i < arguments.length; i++)
arguments.style.display = "none";
}
//if the first argument is false hide the remaining arguments, otherwise show them.
function toggle(condition) {
if (condition) //eww...
show.apply(this, .splice.call(arguments, 1, arguments.length - 1));
else
hide.apply(this, .splice.call(arguments, 1, arguments.length - 1));
}
if (!preserve)
langInput.value = langmetadata.cleanLangCode(langInput.value);
var guess = prefs.get('script-' + langInput.value, langmetadata.guessScript(langInput.value || ''));
if (!preserve) {
if (guess)
thiz.elements.sc.value = guess;
else
thiz.elements.sc.value = '';
thiz.elements.nested.value = langmetadata.getNested(langInput.value || '');
autoTransliterate();
}
var lang = langInput.value;
if (!advancedMode) {
var g = langmetadata.getGenders(lang);
if (!lang) {
hide(controls.gender);
}
else if (g === undefined) {
hide(controls.gender);
}
else {
for (var genderName in util.genderList) {
toggle(g.indexOf(genderName) != -1, controls.genders);
}
}
toggle(g, controls.gender);
toggle(langmetadata.hasNounClasses(lang), controls.nclass);
var hasAutomaticTransliteration = new window.LanguageUtils().HasAutomaticTransliteration(lang);
toggle(guess && guess != 'Latn' && !hasAutomaticTransliteration, controls.transliteration);
toggle(langmetadata.needsRawPageName(lang), controls.display);
hide(controls.qualifier, controls.nested); //only in more
//should be hidden if the language has only one script
toggle(langmetadata.getScripts(lang).length != 1, controls.script);
} else {
show(
controls.gender,
controls.genders, controls.genders, controls.genders,
controls.genders, controls.genders, controls.genders,
controls.genders, controls.genders, controls.genders,
controls.genders, controls.genders, controls.genders,
controls.genders, controls.genders, controls.genders,
controls.genders, controls.genders,
controls.nclass, controls.transliteration, controls.qualifier, controls.display,
controls.script, controls.nested);
}
}
//autocomplete language names
function langAutoFill(e) {
e = (e || event).keyCode;
if ((e >= 33 && e <= 40) || e == 8 || e == 46 || e == 27 || e == 16) {
return;
}
var t = this,
langPrefix = t.value;
if (langPrefix.substr(0, 1) != langPrefix.substr(0, 1).toUpperCase()) {
return;
}
new mw.Api().get({
"action": "expandtemplates",
"format": "json",
"text": "{{#invoke:diller/javascript-arayüzü|GetirDilOnekineGoreTekDil|" + langPrefix + "}}",
"prop": "wikitext"
}).done(function (r) {
if (r.expandtemplates && r.expandtemplates.wikitext !== "") {
var langcode = r.expandtemplates.wikitext.split(":");
var langname = r.expandtemplates.wikitext.split(":");
var oldLength = t.value.length;
t.value = langname;
$(t).data("langcode", langcode);
if (t.setSelectionRange) {
t.setSelectionRange(oldLength, langname.length);
} else if (t.createTextRange) {
var z = t.createTextRange();
z.moveEnd('character', 0 - z.move('character', ) + t.value.length);
z.select();
}
} else {
$(t).removeData("langcode");
}
});
}
langInput.onkeyup = langAutoFill;
langInput.onblur = function () {
if ($(this).data("langcode"))
$(this).val($(this).data("langcode"));
updateScriptGuess.call(langInput);
};
window.setTimeout(function () {
updateScriptGuess.call(langInput);
}, 0);
inputForm = newNode('form',
newNode('p', newNode('a', {
href: "https://dictious.com/tr/MediaWiki tartışma:Gadget-CeviriEkleyici.js#Kullanım"
}, "Çeviri ekle"), ' ',
langInput, newNode('b', ': '), newNode('input', {
'name': 'word',
size: 20,
keyup: autoTransliterate,
change: autoTransliterate
}),
newNode('input', {
'type': 'submit',
'value': 'Çeviriyi önizle'
}), showButton
),
controls.gender,
controls.nclass,
controls.transliteration,
controls.display,
controls.qualifier,
controls.script,
controls.nested
);
return inputForm;
};
this.onsubmit = function (values, render) {
var wikitext;
function callRender() {
render(wikitext, function (html) {
registerEdits(values, wikitext, html);
});
}
if (values.word.indexOf('{{ç') === 0) {
wikitext = '{{subst:#invoke:diller/şablonlar|getirKodaGore|' + values.lang + '|getirAsilAd}}: {{ç|' + values.lang + '}}';
callRender();
} else {
langmetadata.retrieveRawPageName(values.lang, values.word, values.rawPageName, function (rawPageName, needsRawPageName) {
if (needsRawPageName) {
values.rawPageName = rawPageName;
values.wordMinus = '';
} else {
values.rawPageName = '';
values.wordMinus = rawPageName;
}
wikitext = '{{subst:#invoke:diller/şablonlar|getirKodaGore|' + values.lang + '|getirAsilAd}}: ' +
'{{ç|' + values.lang + '|' + (values.rawPageName || values.word) +
(values.nclass1 ? '|c' + values.nclass1 : '') +
(values.nclass2 ? '|c' + values.nclass2 : '');
// Add gender codes
wikitext +=
(values ? '' : '') + (values ? '|i' : '') + (values ? '|ç' : '') +
(values ? '|e' : '') + (values ? '|e-i' : '') + (values ? '|e-ç' : '') +
(values ? '|d' : '') + (values ? '|d-i' : '') + (values ? '|d-ç' : '') +
(values ? '|g' : '') + (values ? '|g-i' : '') + (values ? '|g-ç' : '') +
(values ? '|n' : '') + (values ? '|n-i' : '') + (values ? '|n-ç' : '') +
(values ? '|impf' : '') + (values ? '|pf' : '');
wikitext +=
(values.tr ? '|tr=' + values.tr : '') +
(values.rawPageName ? '|alt=' + values.word : '') +
/* (values.sc ? '|sc=' + values.sc : '') + */
'}}' +
(values.qual ? ' {{şerh|' + values.qual + '}}' : '');
langmetadata.hasWiktionaryWithEntry(values.lang, values.rawPageName || values.wordMinus, function (result) {
if (result)
wikitext = wikitext.replace(/\{t\|/, '{ç|');
callRender();
});
});
}
};
var thiz = this;
var prefs = new CookiePreferences('EditorJs');
var langInput;
var inputForm;
var advancedMode = prefs.get('more-display', 'none') != 'none';
var forceComma = false;
var forceCase = false;
//Reset elements to default values.
function resetElements() {
if (prefs.get('more-display', 'none') != advancedMode ? 'block' : 'none')
prefs.set('more-display', advancedMode ? 'block' : 'none'); //named for compatibility
thiz.elements.word.value = thiz.elements.nclass1.value = thiz.elements.nclass2.value = thiz.elements.tr.value = thiz.elements.rawPageName.value = thiz.elements.qual.value = '';
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
thiz.elements.checked = false;
prefs.set('curlang', thiz.elements.lang.value);
if ((thiz.elements.sc.value || 'Latn') != (prefs.get('script-' + thiz.elements.lang.value, langmetadata.guessScript(thiz.elements.lang.value) || 'Latn'))) {
prefs.set('script-' + thiz.elements.lang.value, thiz.elements.sc.value);
// Uncaught TypeError: Object #<HTMLInputElement> has no method 'update'
thiz.elements.lang.update();
}
}
// This is onsubmit after the wikitext has been rendered to give content
function registerEdits(values, wikitext, content) {
var li = newNode('li', {
'class': 'trans-' + values.lang
});
li.innerHTML = content;
var lang = getLangName(li);
var summary = 'ç' + values.lang + ':]';
var insertBefore = null;
var nextLanguage = null;
var nestedHeading, nestedLang;
var nestedLang;
if (values.nested.indexOf('/') > -1) {
nestedLang = values.nested.replace(/.*\//, '');
nestedHeading = values.nested.replace(/\/.*/, '');
if (nestedHeading === '')
nestedHeading = lang;
content = content.replace(/.*: /, nestedLang + ": ");
wikitext = wikitext.replace("subst:", "").replace(/.*: /, nestedLang + ": ");
} else {
nestedHeading = values.nested;
nestedLang = lang;
}
var nestedWikitext = "\n* " + nestedHeading + ":\n*: " + wikitext;
function addEdit(edit, span) {
editor.addEdit({
'undo': function () {
edit.undo();
if (thiz.elements.word.value === "" &&
thiz.elements.nclass1.value === "" &&
thiz.elements.nclass2.value === "" &&
thiz.elements.tr.value === "" &&
thiz.elements.rawPageName.value === "" &&
thiz.elements.qual.value === "") {
var fields = ;
for (var i = 0; i < fields.length; i++) {
thiz.elements].value = values];
}
for (var genderName in util.genderList) {
thiz.elements.checked = values;
}
}
},
'redo': function () {
edit.redo();
var fields = ;
for (var i = 0; i < fields.length; i++) {
if (thiz.elements].value != values])
return;
}
resetElements();
},
'edit': edit.edit,
'summary': summary
}, span);
}
if (lang) {
//Get all li's in this table row.
var lss = $(insertUl).parent().parent().find('li').get();
var dds = $(insertUl).parent().parent().find('dd').get();
var lis = lss.concat(dds);
for (var j = 0; j < lis.length; j++) {
if (lis.getElementsByTagName('form').length > 0)
continue;
var ln = getLangName(lis);
if (ln == lang) {
if (values.word == '{{ç}}') {
addEdit({
'redo': function () {
},
'undo': function () {
},
'edit': function () {
return editor.error("Can not add a translation request for a language with translations");
}
});
return resetElements();
}
var span = newNode('span');
var parent = lis;
if (util.isTrreq(parent)) {
span.innerHTML = content.substr(content.indexOf(':') + 1);
var trspan = parent.getElementsByTagName('span');
addEdit({
'redo': function () {
parent.removeChild(trspan);
parent.appendChild(span);
},
'undo': function () {
parent.removeChild(span);
parent.appendChild(trspan);
},
'edit': getEditFunction(values, wikitext, ln, values.lang, true, function (text, ipos) {
//Converting a Translation request into a translation
var lineend = text.indexOf('\n', ipos);
return text.substr(0, ipos) + wikitext + text.substr(lineend);
})
}, span);
return resetElements();
} else {
if (parent.getElementsByTagName('ul').length + parent.getElementsByTagName('dl').length == 0) {
span.innerHTML = ", " + content.substr(content.indexOf(':') + 1);
addEdit({
'redo': function () {
parent.appendChild(span)
},
'undo': function () {
parent.removeChild(span)
},
'edit': getEditFunction(values, wikitext, ln, values.lang, false, function (text, ipos) {
//We are adding the wikitext to a list of translations that already exists.
var lineend = text.indexOf('\n', ipos);
var wt = wikitext.replace('subst:#invoke:', '');
wt = wt.substr(wt.indexOf(':') + 1);
return text.substr(0, lineend) + "," + wt + text.substr(lineend);
})
}, span);
return resetElements();
} else {
var node = parent.firstChild;
var hastrans = false;
while (node) {
if (node.nodeType == 1) {
var nn = node.nodeName;
if (nn == 'UL' || nn == 'DL') {
// If we want to use the dialectical nesting for orthographical nesting
// then we need to skip this (otherwise perfect) match.
if (!hastrans && nestedHeading == ln) {
node = node.nextSibling;
continue;
}
span.innerHTML = (hastrans ? ", " : " ") + content.substr(content.indexOf(':') + 1);
addEdit({
'redo': function () {
parent.insertBefore(span, node)
},
'undo': function () {
parent.removeChild(span)
},
'edit': getEditFunction(values, wikitext, ln, values.lang, false, function (text, ipos) {
//Adding the translation to a language that has nested translations under it
var lineend = text.indexOf('\n', ipos);
var wt = wikitext.replace('subst:#invoke:', '');
wt = wt.substr(wt.indexOf(':') + 1);
return text.substr(0, lineend) + (hastrans ? "," : "") + wt + text.substr(lineend);
})
}, span);
return resetElements();
} else {
hastrans = true;
}
}
node = node.nextSibling;
}
}
}
} else if (ln && ln.localeCompare(lang, 'tr') > 0 && (!nextLanguage || ln.localeCompare(nextLanguage, 'tr') < 0) && lis.parentNode.parentNode.nodeName != 'LI') {
nextLanguage = ln;
var parent = lis;
insertBefore = [{
'redo': function () {
parent.parentNode.insertBefore(li, parent);
},
'undo': function () {
parent.parentNode.removeChild(li)
},
'edit': getEditFunction(values, wikitext, ln, getLangCode(parent), util.isTrreq(parent), function (text, ipos) {
//Adding a new language's translation before another language's translation
var lineend = text.lastIndexOf('\n', ipos);
return text.substr(0, lineend) + "\n* " + wikitext + text.substr(lineend);
})
}, li];
}
}
}
if (values.nested) {
nextLanguage = null;
insertBefore = null;
li.innerHTML = nestedHeading + ":" + "<dl><dd class=\"trans-" + values.lang + "\">" + content + "</dd></dl>";
var lis = insertUl.parentNode.parentNode.getElementsByTagName('li');
for (var j = 0; j < lis.length; j++) {
//Ignore the editor form
if (lis.getElementsByTagName('form').length > 0)
continue;
//Don't look at nested translations
if (lis.parentNode.parentNode.nodeName != 'TD')
continue;
var ln = getLangName(lis);
if (ln == nestedHeading) {
var sublis = lis.getElementsByTagName('li');
if (!sublis.length)
sublis = lis.getElementsByTagName('dd');
if (sublis.length == 0) {
var parent = lis;
var dd = newNode('dd', {
'class': 'trans-' + values.lang
});
var dl = newNode('dl', dd);
dd.innerHTML = content;
addEdit({
'redo': function () {
parent.appendChild(dl);
},
'undo': function () {
parent.removeChild(dl);
},
'edit': getEditFunction(values, wikitext, nestedHeading, getLangCode(parent), util.isTrreq(parent), function (text, ipos) {
//Adding a new dl to an existing translation line
var lineend = text.indexOf('\n', ipos);
return text.substr(0, lineend) + "\n*: " + wikitext + text.substr(lineend);
})
}, dd);
return resetElements();
} else {
var dd = newNode(sublis.nodeName, {
'class': 'trans-' + values.lang
});
var linestart = dd.nodeName == 'DD' ? '\n*: ' : '\n** ';
dd.innerHTML = content;
for (var k = 0; k < sublis.length; k++) {
var subln = getLangName(sublis);
var parent = sublis;
if (subln == nestedLang) {
var span = newNode('span');
span.innerHTML = ", " + content.substr(content.indexOf(':') + 1);
addEdit({
'redo': function () {
parent.appendChild(span)
},
'undo': function () {
parent.removeChild(span)
},
'edit': getEditFunction(values, wikitext, nestedLang, values.lang, false, function (text, ipos) {
// Adding the wikitext to a list of translations that already exists.
var lineend = text.indexOf('\n', ipos);
var wt = wikitext.replace('subst:#invoke:', '');
wt = wt.substr(wt.indexOf(':') + 1);
return text.substr(0, lineend) + "," + wt + text.substr(lineend);
})
}, span);
return resetElements();
} else if (langmetadata.nestsBefore(nestedLang, subln)) {
addEdit({
'redo': function () {
parent.parentNode.insertBefore(dd, parent);
},
'undo': function () {
parent.parentNode.removeChild(dd);
},
'edit': getEditFunction(values, wikitext, subln, getLangCode(parent), util.isTrreq(parent),
function (text, ipos) {
// Adding a nested translation in-order
var lineend = text.lastIndexOf('\n', ipos);
return text.substr(0, lineend) + linestart + wikitext + text.substr(lineend);
})
}, dd);
return resetElements();
}
}
addEdit({
'redo': function () {
parent.parentNode.appendChild(dd);
},
'undo': function () {
parent.parentNode.removeChild(dd);
},
'edit': getEditFunction(values, wikitext, subln, getLangCode(parent), util.isTrreq(parent),
function (text, ipos) {
// Adding a nested translation at the end of its group
var lineend = text.indexOf('\n', ipos);
return text.substr(0, lineend) + linestart + wikitext + text.substr(lineend);
})
}, dd);
return resetElements();
}
} else if (ln && ln.localeCompare(nestedHeading, 'tr') > 0 && (!nextLanguage || ln.localeCompare(nextLanguage, 'tr') < 0)) {
nextLanguage = ln;
var parent = lis;
insertBefore = [{
'redo': function () {
parent.parentNode.insertBefore(li, parent);
},
'undo': function () {
parent.parentNode.removeChild(li)
},
'edit': getEditFunction(values, wikitext, ln, getLangCode(parent), util.isTrreq(parent), function (text, ipos) {
//Adding a new nested translation section.
var lineend = text.lastIndexOf('\n', ipos);
return text.substr(0, lineend) + nestedWikitext + text.substr(lineend);
})
}, li];
}
}
wikitext = nestedHeading + ":\n*: " + wikitext;
}
li.className = "trans-" + values.lang;
if (insertBefore) {
addEdit(insertBefore, insertBefore);
} else {
//Append the translations to the end (no better way found)
addEdit({
'redo': function () {
insertUl.appendChild(li);
},
'undo': function () {
insertUl.removeChild(li)
},
'edit': getEditFunction(values, wikitext)
}, li);
}
return resetElements();
}
//Get the wikitext modification for the current form submission.
function getEditFunction(values, wikitext, findLanguage, findLangCode, trreq, callback) {
return function (text) {
var p = util.getTransTable(text, insertUl);
if (!p)
return editor.error("Could not find translation table for '" + values.lang + ":" + values.word + "'. Glosses should be unique");
var stapos = p;
var endpos = p;
var trreqLegacy = false;
if (findLanguage) {
var ipos = 0;
if (trreq) {
ipos = text.substr(stapos).search(RegExp(mw.util.escapeRegExp(findLanguage) + ":\\s*\\{\\{t-needed(?:\\|" + findLangCode + "}})?")) + stapos;
if (ipos < stapos || ipos > endpos)
ipos = text.indexOf('{{ç|' + findLanguage + '}}', stapos);
if (ipos < stapos || ipos > endpos)
ipos = text.indexOf('{{ç|' + findLangCode + '}}', stapos);
}
// If we have a nested trreq, then we still need to look for the non-trreq form of the heading language
if (!trreq || ipos < stapos || ipos > endpos) {
var escapedLang = mw.util.escapeRegExp(findLanguage);
//if the translation should not be nested it should not go before any nested language
var regexByShouldFindSubLanguage = values.nested != "" ? "?" : "";
var possibleRegexes = [
RegExp("\\*" + regexByShouldFindSubLanguage + " ?\\\\]:"),
RegExp("\\*" + regexByShouldFindSubLanguage + " ?" + escapedLang + ":"),
RegExp("\\*" + regexByShouldFindSubLanguage + " ?\\{\\{ttbc\\|" + escapedLang + "}}:")
];
ipos = text.substr(stapos).search(possibleRegexes) + stapos;
if (ipos < stapos || ipos > endpos)
ipos = text.substr(stapos).search(possibleRegexes) + stapos;
if (ipos < stapos || ipos > endpos)
ipos = text.substr(stapos).search(possibleRegexes) + stapos;
if (ipos < stapos || ipos > endpos)
ipos = text.indexOf('{{subst:#invoke:diller/şablonlar|getirKodaGore|' + findLangCode + '|getirAsilAd}}:', stapos);
}
if (ipos >= stapos && ipos < endpos) {
return callback(text, ipos, trreq);
} else {
return editor.error("Could not find translation entry for '" + values.lang + ":" + values.word + "'. Please reformat");
}
}
return text.substr(0, endpos) + "* " + wikitext + "\n" + text.substr(endpos);
};
}
// For an <li> in well-formed translation sections, return the language name.
function getLangName(li) {
var guess = li.textContent || li.innerText;
if (guess)
guess = guess.substr(0, guess.indexOf(':'));
if (guess == 'Template') {
return false;
}
return guess.replace(/^*/, '');
}
// Try to get the language code from an <li> containing { {t t+ or t- // }}
function getLangCode(li) {
if (li.className.indexOf('trans-') === 0)
return li.className.substr(6);
var spans = li.getElementsByTagName('span');
for (var i = 0; i < spans.length; i++) {
if (spans.lang) {
return spans.lang;
}
if (spans.dataset && spans.dataset.lang) {
return spans.dataset.lang;
}
}
return false;
}
}
function createTranslationAdderRow(li) {
var $ul = $("<ul>").append(li);
return $("<tr>")
.append($("<td>").css("text-align", "left").append($ul));
}
$('table.çeviriler').each(function () {
if (util.getTransGloss(this) != 'Kontrol edilecek çeviriler') {
var uls = $(this).find("td > ul").get();
if (uls.length == 0) {
this.getElementsByTagName('td').appendChild(newNode('ul'));
uls = this.getElementsByTagName('ul');
}
if (uls.length == 1) {
var td = this.getElementsByTagName('td');
if (td) {
td.appendChild(newNode('ul'));
uls = this.getElementsByTagName('ul');
}
}
if (uls) {
var li = document.createElement('li');
var ul = uls;
$(this).append(createTranslationAdderRow(li));
new AdderWrapper(editor, new TranslationAdder(ul), li);
if (true) {// XXX: why not? (new CookiePreferences('EditorJs')).get('labeller') == 'true') {
var div = $(this).parent().parent().find('div.NavHead');
if (div) {
new TranslationLabeller(div)
}
}
}
}
});
}
$.when( mw.loader.using( ), $.ready ).then( function () {
// Check if we are on a sensible page
var isOnPrintable = mw.util.getParamValue("printable") !== null;
var isDiff = mw.util.getParamValue("diff") !== null || mw.util.getParamValue("oldid") !== null;
if (mw.config.get('wgAction') != 'view' || isOnPrintable || isDiff)
return;
var editor = new Editor();
TranslationAdders(editor);
/*
// Check that we have not been disabled
var prefs = new CookiePreferences('EditorJs');
if (prefs.get('enabled', 'true') == 'true') {
if (!window.loadedEditor) {
prefs.setDefault('labeller', mw.config.get('wgUserName') ? 'true' : 'false');
window.loadedEditor = true;
}
}
// The enable-disable button on WT:EDIT
var node = document.getElementById('editor-js-disable-button');
if (node) {
node.innerHTML = "";
var toggle = newNode('span', {
click: function() {
if (prefs.get('enabled', 'true') == 'true') {
toggle.innerHTML = "Enable";
prefs.set('enabled', 'false');
} else {
toggle.innerHTML = "Disable";
prefs.set('enabled', 'true');
}
}
}, (prefs.get('enabled', 'true') == 'true' ? 'Disable' : 'Enable'))
node.appendChild(toggle);
}
var node = document.getElementById("editor-js-labeller-button");
if (node) {
node.innerHTML = "";
var toggle2 = newNode('span', {
click: function() {
if (prefs.get('labeller') == 'true') {
toggle2.innerHTML = "Enable";
prefs.set('labeller', 'false');
} else {
toggle2.innerHTML = "Disable";
prefs.set('labeller', 'true');
}
}
}, (prefs.get('labeller') == 'true' ? 'Disable' : 'Enable'))
node.appendChild(toggle2);
}*/
});
//</nowiki>