MediaWiki:Gadget-friendlytalkback.js

Vikipedi, özgür ansiklopedi

Not: Sayfayı kaydettikten sonra değişiklikleri görebilmek için tarayıcınızın önbelleğinizi temizlemeniz gerekir. Google Chrome, Firefox, Microsoft Edge ve Safari: ⇧ Shift tuşuna basılı tutun ve Yeniden Yükle araç çubuğu düğmesine tıklayın. Ayrıntılar ve diğer tarayıcılara yönelik yönergeler için Vikipedi:Önbelleğinizi atlayın sayfasını inceleyin.

// <nowiki>


(function($) {


/*
 ****************************************
 *** friendlytalkback.js: Hızlı mesaj modülü
 ****************************************
 * Çağırma modu:                Sekme ("Not")
 * Etkin olduğu yerler:         Kullanıcıyla ilgili her türlü sayfa (kullanıcı sayfası, katkılar vb.) IP aralıkları hariç
 * Yapılandırma yönergeleri:    FriendlyConfig
 */

Twinkle.talkback = function() {

	if (!mw.config.exists('wgRelevantUserName') || Morebits.ip.isRange(mw.config.get('wgRelevantUserName'))) {
		return;
	}

	Twinkle.addPortletLink(Twinkle.talkback.callback, 'Not', 'friendly-talkback', 'Not bırak');
};

Twinkle.talkback.callback = function() {
	if (mw.config.get('wgRelevantUserName') === mw.config.get('wgUserName') && !confirm("Kendinize not bırakmak istediğinizden emin misiniz?")) {
		return;
	}

	var Window = new Morebits.simpleWindow(600, 350);
	Window.setTitle('Not Bırakma');
	Window.setScriptName('Twinkle');
	Window.addFooterLink('Not tercihleri', 'VP:TW/T#talkback');
	Window.addFooterLink('Twinkle yardımı', 'VP:TW#talkback');
	//Window.addFooterLink('Give feedback', 'WT:TW');
	
	var form = new Morebits.quickForm(Twinkle.talkback.evaluate);

	form.append({ type: 'radio', name: 'tbtarget',
		list: [
			{
				label: 'Talkback', //Çevrilmeli
				value: 'talkback',
				checked: 'true'
			},
			{
				label: 'Lütfen bkz',
				value: 'see'
			},
			{
				label: 'Pano bildirimi',
				value: 'notice'
			},
			{
				label: 'E-postanız var',
				value: 'mail'
			}
		],
		event: Twinkle.talkback.changeTarget
	});

	form.append({
		type: 'field',
		label: 'Work area',
		name: 'work_area'
	});

	var previewlink = document.createElement('a');
	$(previewlink).click(function() {
		Twinkle.talkback.callbacks.preview(result);  // |result| is defined below
	});
	previewlink.style.cursor = 'pointer';
	previewlink.textContent = 'Önizleme';
	form.append({ type: 'div', id: 'talkbackpreview', label: [ previewlink ] });
	form.append({ type: 'div', id: 'friendlytalkback-previewbox', style: 'display: none' });

	form.append({ type: 'submit' });

	var result = form.render();
	Window.setContent(result);
	Window.display();
	result.previewer = new Morebits.wiki.preview($(result).find('div#friendlytalkback-previewbox').last()[0]);

	// We must init the
	var evt = document.createEvent('Event');
	evt.initEvent('change', true, true);
	result.tbtarget[0].dispatchEvent(evt);

	// Check whether the user has opted out from talkback
	var query = {
		action: 'query',
		prop: 'extlinks',
		titles: 'Kullanıcı mesaj:' + mw.config.get('wgRelevantUserName'),
		elquery: 'userjs.invalid/noTalkback',
		ellimit: '1',
		format: 'json'
	};
	var wpapi = new Morebits.wiki.api('Not bırakma kullanım durumu alınıyor', query, Twinkle.talkback.callback.optoutStatus);
	wpapi.post();
};

Twinkle.talkback.optout = '';

Twinkle.talkback.callback.optoutStatus = function(apiobj) {
	var el = apiobj.getResponse().query.pages[0].extlinks;
	if (el && el.length) {
		Twinkle.talkback.optout = mw.config.get('wgRelevantUserName') + ' not bırakılmamasını tercih ediyor';
		var url = el[0].url;
		var reason = mw.util.getParamValue('reason', url);
		Twinkle.talkback.optout += reason ? ': ' + reason : '.';
	}
	$('#twinkle-talkback-optout-message').text(Twinkle.talkback.optout);
};

var prev_page = '';
var prev_section = '';
var prev_message = '';

Twinkle.talkback.changeTarget = function(e) {
	var value = e.target.values;
	var root = e.target.form;

	var old_area = Morebits.quickForm.getElements(root, 'work_area')[0];

	if (root.section) {
		prev_section = root.section.value;
	}
	if (root.message) {
		prev_message = root.message.value;
	}
	if (root.page) {
		prev_page = root.page.value;
	}

	var work_area = new Morebits.quickForm.element({
		type: 'field',
		label: 'Not bırakma bilgileri',
		name: 'work_area'
	});

	root.previewer.closePreview();

	switch (value) {
		case 'talkback':
			/* falls through */
		default:
			work_area.append({
				type: 'div',
				label: '',
				style: 'color: red',
				id: 'twinkle-talkback-optout-message'
			});

			work_area.append({
				type: 'input',
				name: 'page',
				label: 'Tartışmanın sayfa adı',
				tooltip: "Tartışmanın yapıldığı sayfanın adı. Örneğin: 'Kullanıcı mesaj:Jimbo Wales' veya Vikipedi tartışma:Twinkle '. Tüm konuşmalar, Vikipedi ad alanı ve Şablon ad alanı ile sınırlıdır.",
				value: prev_page || 'Kullanıcı mesaj:' + mw.config.get('wgUserName')
			});
			work_area.append({
				type: 'input',
				name: 'section',
				label: 'Bölüm bağlantısı (isteğe bağlı)',
				tooltip: 'Mesajı bıraktığınız tartışma veya mesaj sayfasının bölüm başlığı. Bölüm bağlantısı olmasını istemiyorsanız boş bırakın.',
				value: prev_section
			});
			break;

		case 'notice':
			var noticeboard = work_area.append({
				type: 'select',
				name: 'noticeboard',
				label: 'Pano:',
				event: function(e) {
					if (e.target.value === 'afchd') {
						Morebits.quickForm.overrideElementLabel(root.section, 'Title of draft (excluding the prefix): ');
						Morebits.quickForm.setElementTooltipVisibility(root.section, false);
					} else {
						Morebits.quickForm.resetElementLabel(root.section);
						Morebits.quickForm.setElementTooltipVisibility(root.section, true);
					}
				}
			});

			$.each(Twinkle.talkback.noticeboards, function(value, data) {
				noticeboard.append({
					type: 'option',
					label: data.label,
					value: value,
					selected: !!data.defaultSelected
				});
			});

			work_area.append({
				type: 'input',
				name: 'section',
				label: 'Bölüm başlığı',
				tooltip: 'Pano sayfasındaki ilgili konunun bölüm başlığı.',
				value: prev_section
			});
			break;

		case 'mail':
			work_area.append({
				type: 'input',
				name: 'section',
				label: 'E-postanın konusu (isteğe bağlı)',
				tooltip: 'Gönderdiğiniz e-postanın konu satırı.'
			});
			break;
	}

	if (value !== 'notice') {
		work_area.append({ type: 'textarea', label: 'Ek mesaj (isteğe bağlı):', name: 'message', tooltip: 'Not bırakma şablonunun altına eklemek istediğiniz bir mesaj. Bu mesajı bırakırsanız imzanız otomatik olarak sona eklenecektir.' });
	}

	work_area = work_area.render();
	root.replaceChild(work_area, old_area);
	if (root.message) {
		root.message.value = prev_message;
	}

	$('#twinkle-talkback-optout-message').text(Twinkle.talkback.optout);
};

Twinkle.talkback.noticeboards = {
	adp: {
		label: "VP:ADP (Arayüz yöneticisi panosu)",
		text: '{{yk:Pano bildirimi|pano=Vikipedi:Arayüz yöneticisi duyuru panosu|bölüm=$SECTION}} ~~~~',
		editSummary: '[[Vikipedi:Arayüz yöneticisi duyuru panosu]]\'ndaki bir tartışmanın bildirimi]]'
	},
	bdp: {
		label: "VP:BDP (Bürokrat panosu)",
		text: '{{yk:Pano bildirimi|pano=Vikipedi:Bürokrat duyuru panosu|bölüm=$SECTION}} ~~~~',
		editSummary: '[[Vikipedi:Bürokrat duyuru panosu]]\'ndaki bir tartışmanın bildirimi]]'
	},
	hdp: {
		label: "VP:HDP (Hizmetli panosu)",
		text: '{{yk:Pano bildirimi|Vikipedi:Hizmetli duyuru panosu|bölüm=$SECTION}} ~~~~',
		editSummary: '[[Vikipedi:Hizmetli duyuru panosu]]\'ndaki bir tartışmanın bildirimi]]',
		defaultSelected: true
	},
	// an3: {
	// 	label: "WP:AN3 (Administrators' noticeboard/Edit warring)",
	// 	text: '{{subst:An3-notice|$SECTION}} ~~~~',
	// 	editSummary: "Notice of discussion at [[Wikipedia:Administrators' noticeboard/Edit warring]]"
	// },
	// ani: {
	// 	label: "WP:ANI (Administrators' noticeboard/Incidents)",
	// 	text: "== Notice of Administrators' noticeboard/Incidents discussion ==\n" +
	// 	'{{subst:ANI-notice|thread=$SECTION}} ~~~~',
	// 	editSummary: 'Notice of discussion at [[Wikipedia:Administrators\' noticeboard/Incidents]]'
	// },
	// let's keep AN and its cousins at the top
	// afchd: {
	// 	label: 'WP:AFCHD (Articles for creation/Help desk)',
	// 	text: '{{subst:AFCHD/u|$SECTION}} ~~~~',
	// 	editSummary: 'You have replies at the [[Wikipedia:AFCHD|Articles for Creation Help Desk]]'
	// },
	// blpn: {
	// 	label: 'WP:BLPN (Biographies of living persons noticeboard)',
	// 	text: '{{subst:BLPN-notice|thread=$SECTION}} ~~~~',
	// 	editSummary: 'Notice of discussion at [[Wikipedia:Biographies of living persons/Noticeboard]]'
	// },
	// coin: {
	// 	label: 'WP:COIN (Conflict of interest noticeboard)',
	// 	text: '{{subst:Coin-notice|thread=$SECTION}} ~~~~',
	// 	editSummary: 'Notice of discussion at [[Wikipedia:Conflict of interest/Noticeboard]]'
	// },
	// drn: {
	// 	label: 'WP:DRN (Dispute resolution noticeboard)',
	// 	text: '{{yk:DRN-notice|thread=$SECTION}} ~~~~',
	// 	editSummary: 'Notice of discussion at [[Wikipedia:Dispute resolution noticeboard]]'
	// },
	comp: {
		label: 'VP:Ş (Anlaşmazlık çözümü panosu)',
		text: '{{yk:Pano bildirimi|pano=Vikipedi:Şikâyet|başlık=$SECTION}} ~~~~',
		editSummary: '[[Vikipedi:Şikâyet|Anlaşmazlık çözüm panosunda]] tartışma bildirimi'
	},
	compadm: {
		label: 'VP:Ş/H (Görevi kötüye kullanım panosu)',
		text: '{{yk:Pano bildirimi|pano=Vikipedi:Şikâyet/Hizmetli|başlık=$SECTION}} ~~~~',
		editSummary: '[[Vikipedi:Şikâyet/Hizmetli|Görevi kötüye kullanım panosunda]] tartışma bildirimi'
	},
	effp: {
		label: 'VP:DS/H (Değişiklik süzgeci hata raporu)',
		text: '{{yk:DSH bildirimi|1=$SECTION|2=~~~~}}',
		editSummary: '[[Vikipedi:Değişiklik süzgeci/Hatalar|Değişiklik süzgeci hata raporunuz]] yanıtlandı'
	},
	// eln: {
	// 	label: 'WP:ELN (External links noticeboard)',
	// 	text: '{{subst:ELN-notice|thread=$SECTION}} ~~~~',
	// 	editSummary: 'Notice of discussion at [[Wikipedia:External links/Noticeboard]]'
	// },
	// ftn: {
	// 	label: 'WP:FTN (Fringe theories noticeboard)',
	// 	text: '{{subst:Ftn-notice|thread=$SECTION}} ~~~~',
	// 	editSummary: 'Notice of discussion at [[Wikipedia:Fringe theories/Noticeboard]]'
	// },
	hd: {
		label: 'VP:DM (Danışma masası)',
		text: '== Danışma masasındaki sorunuz ==\n' + '{{DM bildirimi|1=$SECTION|damga=~~~~~}}',
		editSummary: '[[Vikipedi:Danışma masası|Danışma masası]] sorunuz yanıtlandı'
	}
	// norn: {
	//  label: 'WP:NORN (No original research noticeboard)',
	// 	text: '{{subst:Norn-notice|thread=$SECTION}} ~~~~',
	// 	editSummary: 'Notice of discussion at [[Wikipedia:No original research/Noticeboard]]'
	// },
	// npovn: {
	// 	label: 'WP:NPOVN (Neutral point of view noticeboard)',
	// 	text: '{{subst:NPOVN-notice|thread=$SECTION}} ~~~~',
	// 	editSummary: 'Notice of discussion at [[Wikipedia:Neutral point of view/Noticeboard]]'
	// },
	// rsn: {
	// 	label: 'WP:RSN (Reliable sources noticeboard)',
	// 	text: '{{subst:RSN-notice|thread=$SECTION}} ~~~~',
	// 	editSummary: 'Notice of discussion at [[Wikipedia:Reliable sources/Noticeboard]]'
	// },
	// th: {
	// 	label: 'WP:THQ (Teahouse question forum)',
	// 	text: "== Teahouse talkback: you've got messages! ==\n{{WP:Teahouse/Teahouse talkback|WP:Teahouse/Questions|$SECTION|ts=~~~~}}",
	// 	editSummary: 'You have replies at the [[Wikipedia:Teahouse/Questions|Teahouse question board]]'
	// },
	// vrt: {
	//  label: 'WP:VRTN (VRT noticeboard)',
	//  text: '{{subst:VRTreply|1=$SECTION}}\n~~~~',
	//  editSummary: 'You have replies at the [[Wikipedia:VRT noticeboard|VRT noticeboard]]'
	// }
};

Twinkle.talkback.evaluate = function(e) {
	var input = Morebits.quickForm.getInputData(e.target);

	var fullUserTalkPageName = new mw.Title(mw.config.get('wgRelevantUserName'), 3).toText();
	var talkpage = new Morebits.wiki.page(fullUserTalkPageName, 'Not bırakılıyor');

	Morebits.simpleWindow.setButtonsEnabled(false);
	Morebits.status.init(e.target);

	Morebits.wiki.actionCompleted.redirect = fullUserTalkPageName;
	Morebits.wiki.actionCompleted.notice = 'Not bırakma işlemi tamamlandı. Sayfa birkaç saniye içinde yeniden yüklenecek.';

	// Not used for notice or mail
	input.page = input.page || mw.config.get('wgUserName');

	switch (input.tbtarget) {
		case 'notice':
			talkpage.setEditSummary(Twinkle.talkback.noticeboards[input.noticeboard].editSummary);
			break;
		case 'mail':
			talkpage.setEditSummary("Bildirim: E-postanız var");
			break;
		case 'see':
			input.page = Twinkle.talkback.callbacks.normalizeTalkbackPage(input.page);
			talkpage.setEditSummary('[[:' + input.page +
			(input.section ? '#' + input.section : '') + ']] adlı sayfadaki tartışmaya bakınız');
			break;
		default:  // talkback
			input.page = Twinkle.talkback.callbacks.normalizeTalkbackPage(input.page);
			talkpage.setEditSummary('Talkback ([[:' + input.page +
			(input.section ? '#' + input.section : '') + ']])');
			break;
	}

	talkpage.setAppendText('\n\n' + Twinkle.talkback.callbacks.getNoticeWikitext(input));
	talkpage.setChangeTags(Twinkle.changeTags);
	talkpage.setCreateOption('recreate');
	talkpage.setMinorEdit(Twinkle.getPref('markTalkbackAsMinor'));
	talkpage.setFollowRedirect(true);
	talkpage.append();
};

Twinkle.talkback.callbacks = {
	// Not used for notice or mail, default to user page
	normalizeTalkbackPage: function(page) {
		page = page || mw.config.get('wgUserName');

		// Assume no prefix is a username, convert to user talk space
		var normal = mw.Title.newFromText(page, 3);
		// Normalize erroneous or likely mis-entered items
		if (normal) {
			// Only allow talks and WPspace, as well as Template-space for DYK
			if (normal.namespace !== 4 && normal.namespace !== 10) {
				normal = normal.getTalkPage();
			}
			page = normal.getPrefixedText();
		}
		return page;
	},

	preview: function(form) {
		var input = Morebits.quickForm.getInputData(form);

	if (input.tbtarget === 'talkback' || input.tbtarget === 'see') {
			input.page = Twinkle.talkback.callbacks.normalizeTalkbackPage(input.page);
		}

		var noticetext = Twinkle.talkback.callbacks.getNoticeWikitext(input);
		form.previewer.beginRender(noticetext, 'User talk:' + mw.config.get('wgRelevantUserName')); // Force wikitext/correct username
	},

	getNoticeWikitext: function(input) {
		var text;

		switch (input.tbtarget) {
			case 'notice':
				text = Morebits.string.safeReplace(Twinkle.talkback.noticeboards[input.noticeboard].text, '$SECTION', input.section);
				break;
			case 'mail':
				text = '==' + Twinkle.getPref('mailHeading') + '==\n' +
					"{{You've got mail|subject=" + input.section + '|ts=~~~~~}}';

				if (input.message) {
					text += '\n' + input.message + '  ~~~~';
				} else if (Twinkle.getPref('insertTalkbackSignature')) {
					text += '\n~~~~';
				}
				break;
			case 'see':
				var heading = Twinkle.getPref('talkbackHeading');
				text = '{{subst:Please see|location=' + input.page + (input.section ? '#' + input.section : '') +
				'|more=' + input.message + '|heading=' + heading + '}}';
				break;
			default:  // talkback
				text = '==' + Twinkle.getPref('talkbackHeading') + '==\n' +
					'{{talkback|' + input.page + (input.section ? '|' + input.section : '') + '|ts=~~~~~}}';

				if (input.message) {
					text += '\n' + input.message + ' ~~~~';
				} else if (Twinkle.getPref('insertTalkbackSignature')) {
					text += '\n~~~~';
				}
		}
		return text;
	}
};
Twinkle.addInitCallback(Twinkle.talkback, 'talkback');
})(jQuery);


// </nowiki>