From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.

importScript("User:Ebraminio/ArticleTranslator.js");

mw.loader.load("//fa.wikipedia.org/?title=MediaWiki:Tofawiki.js&action=raw&ctype=text/javascript");



// <nowiki> // DO NOT REMOVE THIS LINE EVER

/*jslint browser: true, white: true*/

/*global mediaWiki, jQuery*/

/*!

 * @author User:Ebraminio, User:Yamaha5

 */

(function ($, mw) {

	'use strict';



	function createPage(title, text, summary, callback) {

		return new mw.Api().post({

			action: 'edit',

			title: title,

			text: text,

			summary: summary,

			createonly: '',

			minor: '',

			bot: '',

			token: mw.user.tokens.get('csrfToken')

		}).then(function (data) {

			if (data.error && data.error.info) {

			} else {

				callback();

			}

			return data;

		}, function (data) {

			return data;

		});

	}



	function faWikiName(title) {

		return $.ajax({

			url: '//en.wikipedia.org/w/api.php',

			data: {

				action: 'query',

				prop: 'langlinks',

				titles: title,

				redirects: 1,

				format: 'json',

				lllimit: 500

			},

			dataType: 'jsonp'

		}).then(function (data) {

			try {

				return $.grep($.map(data.query.pages, function (x) { return x; })[0].langlinks, function (x) {

					return x.lang === 'fa';

				})[0]['*'];

			} catch (ignore) { }

		});

	}



	function catParents(title) {

		return $.ajax({

			url: '//en.wikipedia.org/w/api.php',

			data: {

				action: 'query',

				prop: 'categories',

				titles: title,

				clshow: '!hidden',

				cllimit: 500,

				format: 'json'

			},

			dataType: 'jsonp'

		}).then(function (data) {

			try {

				return $.map($.map(data.query.pages, function (x) { return x; })[0].categories, function (x) {

					return x.title;

				});

			} catch (ignore) { }

		});

	}



	function getWikidataEntity(entitle) {

		return new mw.Api({ ajax: { url: '//www.wikidata.org/w/api.php' } }).get({

			action: 'wbgetentities',

			format: 'json',

			sites: 'enwiki',

			titles: entitle,

			normalize: 'true',

			origin: window.location.protocol + '//' + window.location.hostname

		}).then(function (x) { return $.map(x.entities, function (x) { return x; })[0]; });

	}



	function commonsCatFromEntity(entity) {

		try { return entity.claims.P3730].mainsnak.datavalue.value; } catch (ignore) { }

	}



	function startCat(falink, enlink) {

		enlink = enlink.replace(/\_/g, ' ');

		return faWikiName(enlink).then(function (x) {

			if (x) {

				return;

			}

			return catParents(enlink).then(function (x) {

				if (!x) {

					return;

				}

				return $.when.apply(null, $.map(x, function (y) {

					return faWikiName(y);

				})).then(function () {

					var catText = $.map(arguments, function (x) {

							return '[[' + x + ']]';

						})

						.join('\n') + '\n[['+'en:' + enlink + ']]';

					catText = catText.replace(/\[\[undefined\]\]/g, '');

					catText = catText.replace(/\n\n/g, '\n');

					catText = catText.trim();

					return createPage(

						falink,

						catText,

						'ایجاد ردهٔ همسنگ [[:en:' + enlink + ']] با ابزار رده\u200cساز',

						function () {

							mw.notify('ساخت ' + falink + ' با موفقیت انجام شد.');

						}

					);

				});

			});

		});

	}



	function loadPage(title) {

		return new mw.Api().get({

			action: 'query',

			prop: 'revisions',

			titles: title,

			rvprop: 'content',

			format: 'json'

		}).then(function (data) {

			return $.map(data.query.pages, function (value) { return value; })[0].revisions0]['*'];

		});

	}

 

	/**

	 * Save a page

	 */

	function savePage(title, text, summary) {

		return new mw.Api().post({

			action: 'edit',

			title: title,

			text: text,

			summary: summary,

			nocreate: '',

			minor: '',

			token: mw.user.tokens.get('csrfToken')

		}).then(function (data) {

			if (data.error && data.error.info) {

				mw.notify(data.error.info);

			}

		}, function (data) {

			mw.notify(data);

		});

	}



	function init(e) {

		e.preventDefault();

		$('<div>' +

			'<textarea style="width: 100%; background-color: white;" placeholder="رده۱@Cateogry1" id="catmakerinput" rows="7"></textarea>' +

			'</div>'

			).dialog({

			modal: true,

			width: 700,

			buttons: [{

				id: 'catmaker-button-import',

				text: 'ساخت رده',

				click: function () {

					var formInput = $('#catmakerinput').val();

					formInput = formInput.replace('*', '').replace('#', '').replace('---', '@')

					if (formInput === '') { mw.notify('لطفاً فرم درخواست را به درستی پر کنید'); return; }

					var requests = formInput.trim().split('\n');

					$.when.apply(null, $.map(requests, function (x) {

						var req = x.split('@');

						return startCat('رده:' + req0].trim(), 'Category:' + req1].trim());

					})).then(function () {

						mw.notify('ساخت رده\u200cها به پایان رسید، لطفاً بررسی کنید.');

						window.location = mw.util.getUrl('Special:Contributions/' + mw.config.get('wgUserName'));

					});

				}

			}]

		});

	}



	$(function () {

		mw.util.addCSS('#t-catmaker { font-weight: bold; }');

		$(mw.util.addPortletLink('p-tb', '#', 'رده\u200cساز', 't-catmaker', 'ساخت رده به صورت خودکار')).click(init);

	});

}(jQuery, mediaWiki));
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.

importScript("User:Ebraminio/ArticleTranslator.js");

mw.loader.load("//fa.wikipedia.org/?title=MediaWiki:Tofawiki.js&action=raw&ctype=text/javascript");



// <nowiki> // DO NOT REMOVE THIS LINE EVER

/*jslint browser: true, white: true*/

/*global mediaWiki, jQuery*/

/*!

 * @author User:Ebraminio, User:Yamaha5

 */

(function ($, mw) {

	'use strict';



	function createPage(title, text, summary, callback) {

		return new mw.Api().post({

			action: 'edit',

			title: title,

			text: text,

			summary: summary,

			createonly: '',

			minor: '',

			bot: '',

			token: mw.user.tokens.get('csrfToken')

		}).then(function (data) {

			if (data.error && data.error.info) {

			} else {

				callback();

			}

			return data;

		}, function (data) {

			return data;

		});

	}



	function faWikiName(title) {

		return $.ajax({

			url: '//en.wikipedia.org/w/api.php',

			data: {

				action: 'query',

				prop: 'langlinks',

				titles: title,

				redirects: 1,

				format: 'json',

				lllimit: 500

			},

			dataType: 'jsonp'

		}).then(function (data) {

			try {

				return $.grep($.map(data.query.pages, function (x) { return x; })[0].langlinks, function (x) {

					return x.lang === 'fa';

				})[0]['*'];

			} catch (ignore) { }

		});

	}



	function catParents(title) {

		return $.ajax({

			url: '//en.wikipedia.org/w/api.php',

			data: {

				action: 'query',

				prop: 'categories',

				titles: title,

				clshow: '!hidden',

				cllimit: 500,

				format: 'json'

			},

			dataType: 'jsonp'

		}).then(function (data) {

			try {

				return $.map($.map(data.query.pages, function (x) { return x; })[0].categories, function (x) {

					return x.title;

				});

			} catch (ignore) { }

		});

	}



	function getWikidataEntity(entitle) {

		return new mw.Api({ ajax: { url: '//www.wikidata.org/w/api.php' } }).get({

			action: 'wbgetentities',

			format: 'json',

			sites: 'enwiki',

			titles: entitle,

			normalize: 'true',

			origin: window.location.protocol + '//' + window.location.hostname

		}).then(function (x) { return $.map(x.entities, function (x) { return x; })[0]; });

	}



	function commonsCatFromEntity(entity) {

		try { return entity.claims.P3730].mainsnak.datavalue.value; } catch (ignore) { }

	}



	function startCat(falink, enlink) {

		enlink = enlink.replace(/\_/g, ' ');

		return faWikiName(enlink).then(function (x) {

			if (x) {

				return;

			}

			return catParents(enlink).then(function (x) {

				if (!x) {

					return;

				}

				return $.when.apply(null, $.map(x, function (y) {

					return faWikiName(y);

				})).then(function () {

					var catText = $.map(arguments, function (x) {

							return '[[' + x + ']]';

						})

						.join('\n') + '\n[['+'en:' + enlink + ']]';

					catText = catText.replace(/\[\[undefined\]\]/g, '');

					catText = catText.replace(/\n\n/g, '\n');

					catText = catText.trim();

					return createPage(

						falink,

						catText,

						'ایجاد ردهٔ همسنگ [[:en:' + enlink + ']] با ابزار رده\u200cساز',

						function () {

							mw.notify('ساخت ' + falink + ' با موفقیت انجام شد.');

						}

					);

				});

			});

		});

	}



	function loadPage(title) {

		return new mw.Api().get({

			action: 'query',

			prop: 'revisions',

			titles: title,

			rvprop: 'content',

			format: 'json'

		}).then(function (data) {

			return $.map(data.query.pages, function (value) { return value; })[0].revisions0]['*'];

		});

	}

 

	/**

	 * Save a page

	 */

	function savePage(title, text, summary) {

		return new mw.Api().post({

			action: 'edit',

			title: title,

			text: text,

			summary: summary,

			nocreate: '',

			minor: '',

			token: mw.user.tokens.get('csrfToken')

		}).then(function (data) {

			if (data.error && data.error.info) {

				mw.notify(data.error.info);

			}

		}, function (data) {

			mw.notify(data);

		});

	}



	function init(e) {

		e.preventDefault();

		$('<div>' +

			'<textarea style="width: 100%; background-color: white;" placeholder="رده۱@Cateogry1" id="catmakerinput" rows="7"></textarea>' +

			'</div>'

			).dialog({

			modal: true,

			width: 700,

			buttons: [{

				id: 'catmaker-button-import',

				text: 'ساخت رده',

				click: function () {

					var formInput = $('#catmakerinput').val();

					formInput = formInput.replace('*', '').replace('#', '').replace('---', '@')

					if (formInput === '') { mw.notify('لطفاً فرم درخواست را به درستی پر کنید'); return; }

					var requests = formInput.trim().split('\n');

					$.when.apply(null, $.map(requests, function (x) {

						var req = x.split('@');

						return startCat('رده:' + req0].trim(), 'Category:' + req1].trim());

					})).then(function () {

						mw.notify('ساخت رده\u200cها به پایان رسید، لطفاً بررسی کنید.');

						window.location = mw.util.getUrl('Special:Contributions/' + mw.config.get('wgUserName'));

					});

				}

			}]

		});

	}



	$(function () {

		mw.util.addCSS('#t-catmaker { font-weight: bold; }');

		$(mw.util.addPortletLink('p-tb', '#', 'رده\u200cساز', 't-catmaker', 'ساخت رده به صورت خودکار')).click(init);

	});

}(jQuery, mediaWiki));

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook