MediaWiki:Gadget-friendlytalkback.js

Vikisöz, özgür söz dizini

Not: Yayımladıktan sonra değişiklikleri görmek için tarayıcınızın önbelleğini temizlemeniz gerekebilir.

  • Firefox / Safari: Shift tuşuna basılıyken Yeniden Yükle'ye tıklayın ya da Ctrl-F5 ya da Ctrl-R tıklayın (Mac için ⌘-R).
  • Google Chrome: Ctrl-Shift-R'ye basın. (Mac için ⌘-Shift-R)
  • Internet Explorer / Edge: Ctrl basılıyken Yenile'ye tıklayın ya da Ctrl-F5 yapın.
  • Opera: Ctrl-F5 tıklayın.
//<nowiki>


(function($){


/*
 ****************************************
 *** friendlytalkback.js: Hızlı mesaj modülü
 ****************************************
 * Mode of invocation:     Tab ("TB")
 * Active on:              Existing user talk pages
 * Config directives in:   FriendlyConfig
 */

Twinkle.talkback = function() {

	if ( !mw.config.get('wgRelevantUserName') ) {
		return;
	}

	Twinkle.addPortletLink( Twinkle.talkback.callback, "Hızlı Mesaj", "friendly-talkback", "Hızlı mesaj gönder." );
};

Twinkle.talkback.callback = function( ) {
	if( mw.config.get('wgRelevantUserName') === mw.config.get("wgUserName") && !confirm("Kendi kendine mesaj göndermen normal değil.") ){
		return;
	}

	var Window = new Morebits.simpleWindow( 600, 350 );
	Window.setTitle("Hızlı Mesaj");
	Window.setScriptName("Twinkle");
	Window.addFooterLink( "{{HızlıMesaj}} hakkında", "Şablon:HızlıMesaj" );
	Window.addFooterLink( "Twinkle yardım", "Vikisöz tartışma:Twinkle" );

	var form = new Morebits.quickForm( callback_evaluate );

	form.append({ type: "radio", name: "tbtarget",
				list: [
					{
						label: "Hızlı mesaj: mesaj sayfam",
						value: "mytalk",
						checked: "true"
					},
					{
						label: "Hızlı mesaj: başka kullanıcının mesaj sayfası",
						value: "usertalk"
					},
					{
						label: "Hızlı mesaj: diğer sayfa",
						value: "other"
					},
					{
						label: "\"Lütfen bakın\"",
						value: "see"
					},
					{
						label: "\"Epostanız Var\"",
						value: "mail"
					}
				],
				event: callback_change_target
			});

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

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

	var result = form.render();
	Window.setContent( result );
	Window.display();

	// 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: mw.config.get('wgPageName'),
		elquery: 'userjs.invalid/noTalkback',
		ellimit: '1'
	};
	var wpapi = new Morebits.wiki.api("Fetching talkback opt-out status", query, Twinkle.talkback.callback.optoutStatus);
	wpapi.post();
};

Twinkle.talkback.optout = null;

Twinkle.talkback.callback.optoutStatus = function(apiobj) {
	var xml = apiobj.getXML();
	var $el = $(xml).find('el');

	if ($el.length) {
		Twinkle.talkback.optout = mw.config.get('wgRelevantUserName') + " hızlı mesaj almamayı tercih ediyor";
		var url = $el.text();
		if (url.indexOf("reason=") > -1) {
			Twinkle.talkback.optout += ": " + decodeURIComponent(url.substring(url.indexOf("reason=") + 7)) + ".";
		} else {
			Twinkle.talkback.optout += ".";
		}
	} else {
		Twinkle.talkback.optout = false;
	}

	var $status = $("#twinkle-talkback-optout-message");
	if ($status.length && Twinkle.talkback.optout) {
		$status.text(Twinkle.talkback.optout);
	}
};

var prev_page = "";
var prev_section = "";
var prev_message = "";

var callback_change_target = 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: "Hızlı mesaj bilgileri",
			name: "work_area"
		});

	switch( value ) {
		case "mytalk":
			/* falls through */
		default:
			work_area.append({
				type: "div",
				label: "",
				style: "color: red",
				id: "twinkle-talkback-optout-message"
			});
			work_area.append({
					type:"input",
					name:"section",
					label:"Bağlantılı bölüm (isteğe bağlı)",
					tooltip:"Mesaj sayfanızdaki ilgili bölüm başlığı. Hiçbir bölümün bağlanmaması için boş bırakın.",
					value: prev_section
				});
			break;
		case "usertalk":
			work_area.append({
				type: "div",
				label: "",
				style: "color: red",
				id: "twinkle-talkback-optout-message"
			});
			work_area.append({
					type:"input",
					name:"page",
					label:"Kullanıcı",
					tooltip:"Mesaj sayfasında mesaj bıraktığınız kullanıcının, kullanıcı adı.",
					value: prev_page
				});

			work_area.append({
					type:"input",
					name:"section",
					label:"Bağlantılı bölüm (isteğe bağlı)",
					tooltip:"Sayfada mesaj bıraktığınız bölüm başlığı. Hiçbir bölümün bağlanmaması için boş bırakın.",
					value: prev_section
				});
			break;
		case "notice":
			var noticeboard = work_area.append({
					type: "select",
					name: "noticeboard",
					label: "Bildirim panosu:",
					event: function(e) {
						if (e.target.value === "afchd") {
							Morebits.quickForm.overrideElementLabel(e.target.form.section, "Taslağın başlığı (ön ek hariç): ");
							Morebits.quickForm.setElementTooltipVisibility(e.target.form.section, false);
						} else {
							Morebits.quickForm.resetElementLabel(e.target.form.section);
							Morebits.quickForm.setElementTooltipVisibility(e.target.form.section, true);
						}
					}
				});
			noticeboard.append({
					type: "option",
					label: "VS:HDP (Hizmetli duyuru panosu)",
					value: "an"
				});
			noticeboard.append({
					type: "option",
					label: "VP:YDP/3GK (Üç geri dönüş kuralı ihlal panosu)",
					value: "an3"
				});
			// let's keep AN and its cousins at the top
			noticeboard.append({
					type: "option",
					label: "VS:DM (Danışma masası)",
					value: "hd"
				});
			work_area.append({
					type:"input",
					name:"section",
					label:"Bağlantılı konu",
					tooltip:"Bildirim panosu sayfasındaki ilgili mesajın başlığı.",
					value: prev_section
				});
			break;
		case "other":
			work_area.append({
				type: "div",
				label: "",
				style: "color: red",
				id: "twinkle-talkback-optout-message"
			});
			work_area.append({
					type:"input",
					name:"page",
					label:"Tam sayfa adı",
					tooltip:"Mesajınızı bıraktığınız sayfanın tam adı. Örneğin: 'Vikisöz tartışma:Twinkle'.",
					value: prev_page
				});

			work_area.append({
					type:"input",
					name:"section",
					label:"Bağlantılı bölüm (isteğe bağlı)",
					tooltip:"Sayfada mesaj bıraktığınız bölüm başlığı. Hiçbir bölümün bağlanmaması için boş bırakın.",
					value: prev_section
				});
			break;
		case "mail":
			work_area.append({
					type:"input",
					name:"section",
					label:"Eposta konusu (isteğe bağlı)",
					tooltip:"Gönderdiğiniz e-postanın konusu."
				});
			break;
		case "see":
			work_area.append({
					type:"input",
					name:"page",
					label:"Tam sayfa adı",
					tooltip:"Mesajınızı bıraktığınız sayfanın tam adı. Örneğin: 'Vikisöz tartışma:Twinkle'.",
					value: prev_page
				});
			work_area.append({
					type:"input",
					name:"section",
					label:"Bağlantılı bölüm (isteğe bağlı)",
					tooltip:"Tartışmanın yapıldığı bölüm başlığı. Örneğin: 'Birleştirme teklifi'.",
					value: prev_section
				});
			break;
	}

	if (value !== "notice") {
		work_area.append({ type:"textarea", label:"Ek mesaj (isteğe bağlı):", name:"message", tooltip:"Eklenecek şablonunun altına bırakmak istediğiniz ek bir mesaj. İmzanız mesajın sonuna eklenir." });
	}

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

	if (Twinkle.talkback.optout) {
		$("#twinkle-talkback-optout-message").text(Twinkle.talkback.optout);
	}
};

var callback_evaluate = function( e ) {

	var tbtarget = e.target.getChecked( "tbtarget" )[0];
	var page = null;
	var section = e.target.section.value;
	var fullUserTalkPageName = mw.config.get("wgFormattedNamespaces")[ mw.config.get("wgNamespaceIds").user_talk ] + ":" + mw.config.get('wgRelevantUserName');

	if( tbtarget === "usertalk" || tbtarget === "other" || tbtarget === "see" ) {
		page = e.target.page.value;

		if( tbtarget === "usertalk" ) {
			if( !page ) {
				alert("Konuşma sayfasına mesaj bıraktığınız kullanıcının, kullanıcı adını belirtmelisiniz.");
				return;
			}
		} else {
			if( !page ) {
				alert("Mesajınız bir kullanıcı mesaj sayfasında olmadığı için tam sayfa adını belirtmelisiniz.");
				return;
			}
		}
	} else if (tbtarget === "notice") {
		page = e.target.noticeboard.value;
	}

	var message;
	if (e.target.message) {
		message = e.target.message.value;
	}

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

	Morebits.wiki.actionCompleted.redirect = fullUserTalkPageName;
	Morebits.wiki.actionCompleted.notice = "Hızlı mesaj tamamlandı; mesaj sayfası birkaç saniye içinde yeniden yüklenecek";

	var talkpage = new Morebits.wiki.page(fullUserTalkPageName, "Hızlı mesaj ekleniyor");
	var tbPageName = (tbtarget === "mytalk") ? mw.config.get("wgUserName") : page;

	var text;
	if ( tbtarget === "notice" ) {
		switch (page) {
			case "afchd":
				text = "\n\n{{subst:AFCHD/u|" + section + "}} ~~~~";
				talkpage.setEditSummary( "You have replies at the [[Wikipedia:AFCHD|Articles for Creation Help Desk]]" + Twinkle.getPref("summaryAd") );
				break;
			case "an":
				text = "\n\n== " + Twinkle.getFriendlyPref("adminNoticeHeading") + " ==\n";
				text += "{{subst:ANI-notice|thread=" + section + "|noticeboard=Wikipedia:Administrators' noticeboard}} ~~~~";
				talkpage.setEditSummary( "Notice of discussion at [[Wikipedia:Administrators' noticeboard]]" + Twinkle.getPref("summaryAd") );
				break;
			case "an3":
				text = "\n\n{{subst:An3-notice|" + section + "}} ~~~~";
				talkpage.setEditSummary( "Notice of discussion at [[Wikipedia:Administrators' noticeboard/Edit warring]]" + Twinkle.getPref("summaryAd") );
				break;
			case "ani":
				text = "\n\n== " + Twinkle.getFriendlyPref("adminNoticeHeading") + " ==\n";
				text += "{{subst:ANI-notice|thread=" + section + "|noticeboard=Wikipedia:Administrators' noticeboard/Incidents}} ~~~~";
				talkpage.setEditSummary( "Notice of discussion at [[Wikipedia:Administrators' noticeboard/Incidents]]" + Twinkle.getPref("summaryAd") );
				break;
			case "coin":
				text = "\n\n{{subst:Coin-notice|thread=" + section + "}} ~~~~";
				talkpage.setEditSummary( "Notice of discussion at [[Wikipedia:Conflict of interest noticeboard]]" + Twinkle.getPref("summaryAd") );
				break;
			case "drn":
				text = "\n\n{{subst:DRN-notice|thread=" + section + "}} ~~~~";
				talkpage.setEditSummary( "Notice of discussion at [[Wikipedia:Dispute resolution noticeboard]]" + Twinkle.getPref("summaryAd") );
				break;
			case "hd":
				text = "\n\n== Your question at the Help desk ==\n";
				text += "{{helpdeskreply|1=" + section + "|ts=~~~~~}}";
				talkpage.setEditSummary( "You have replies at the [[Wikipedia:Help desk|Wikipedia help desk]]" + Twinkle.getPref("summaryAd") );
				break;
			case "otrs":
				text = "\n\n{{OTRSreply|1=" + section + "|2=~~~~}}";
				talkpage.setEditSummary( "You have replies at the [[Wikipedia:OTRS noticeboard|OTRS noticeboard]]" + Twinkle.getPref("summaryAd") );
				break;
			case "th":
				text = "\n\n== Teahouse talkback: you've got messages! ==\n{{WP:Teahouse/Teahouse talkback|WP:Teahouse/Questions|" + section + "|ts=~~~~}}";
				talkpage.setEditSummary( "You have replies at the [[Wikipedia:Teahouse/Questions|Teahouse question board]]" + Twinkle.getPref("summaryAd") );
				break;
			default:
				throw "Twinkle.talkback, function callback_evaluate: default case reached";
		}

	} else if ( tbtarget === "mail" ) {
		text = "\n\n==" + Twinkle.getFriendlyPref("mailHeading") + "==\n{{E-postanız var|subject=";
		text += section + "|ts=~~~~~}}";

		if( message ) {
			text += "\n" + message.trim() + "  ~~~~";
		} else if( Twinkle.getFriendlyPref("insertTalkbackSignature") ) {
			text += "\n~~~~";
		}

		talkpage.setEditSummary("Bildirim: Epostanız var" + Twinkle.getPref("summaryAd"));

	} else if ( tbtarget === "see" ) {
		text = "\n\n{{subst:Lütfen bakın|location=" + tbPageName;
		if (section) {
			text += "#" + section;
		}
		text += "|more=" + message.trim() + "}}";
		talkpage.setEditSummary("Lütfen [[:" + tbPageName +
			(section ? ("#" + section) : "") + "]] sayfasındaki tartışmayı kontrol edin" + Twinkle.getPref("summaryAd"));

	} else {  // tbtarget one of mytalk, usertalk, other
		// clean talkback heading: strip section header markers that were erroneously suggested in the documentation
		text = "\n\n==" + Twinkle.getFriendlyPref("talkbackHeading").replace( /^\s*=+\s*(.*?)\s*=+$\s*/, "$1" ) + "==\n{{HızlıMesaj|";
		text += tbPageName;

		if( section ) {
			text += "|" + section;
		}

		text += "|ts=~~~~~}}";

		if( message ) {
			text += "\n" + message.trim() + " ~~~~";
		} else if( Twinkle.getFriendlyPref("insertTalkbackSignature") ) {
			text += "\n~~~~";
		}

		var editSummary = "Hızlı mesaj ([[:";
		if (tbtarget !== "other" && !/^\s*user talk:/i.test(tbPageName)) {
			editSummary += "Kullanıcı mesaj:";
		}
		editSummary += tbPageName + (section ? ("#" + section) : "") + "]])";
		talkpage.setEditSummary(editSummary + Twinkle.getPref("summaryAd"));
	}

	talkpage.setAppendText( text );
	talkpage.setCreateOption("recreate");
	talkpage.setMinorEdit(Twinkle.getFriendlyPref("markTalkbackAsMinor"));
	talkpage.setFollowRedirect( true );
	talkpage.append();
};

})(jQuery);


//</nowiki>