MediaWiki:Common.js/edit.js

Bách khoa toàn thư mở Wikipedia
Chú ý: Sau khi lưu thay đổi trang, bạn phải xóa bộ nhớ đệm của trình duyệt để nhìn thấy các thay đổi. Google Chrome, Firefox, Internet ExplorerSafari: Giữ phím ⇧ Shift và nhấn nút Reload/Tải lại trên thanh công cụ của trình duyệt. Để biết chi tiết và hướng dẫn cho các trình duyệt khác, xem Trợ giúp:Xóa bộ nhớ đệm.
/*global mw, importScriptURI, importScript */
/*jshint strict: false, browser: true, jquery: true */

/** Buộc IP phải nhấn vào "Xem trước" trước khi có thể "Lưu trang" ********************************
* English : Force IP to preview before saving changes.
* Copyright Marc Mongenet, 2006
* Plyd 05/2007: add "after preview" in the button to prevent misunderstanding from beginners
*/
function forcePreview() {
  if (mw.config.get('wgUserName') != null || mw.config.get('wgAction') != "edit") return;
  saveButton = document.getElementById("wpSave");
  if (!saveButton) return;
  saveButton.disabled = true;
  saveButton.value = "Lưu trang (sau khi xem trước)";
  saveButton.style.fontWeight = "normal";
  var preview = document.getElementById("wpPreview");
  if(preview) preview.style.fontWeight = "bold";
}
 
mw.hook("wikipage.content").add(forcePreview);

/**
 * Tùy chọn bổ sung cho thanh công cụ khi sửa trang
 *  
 *  Mô tả: Thêm một số nút tùy chọn vào thanh công cụ sửa đổi cũ.
 *  
 *  Người bảo trì: [[:en:User:MarkS]], [[:en:User:Voice of All]], [[:en:User:R. Koot]], [[Thành viên:Vinhtantran]]
 */
 
mw.loader.using( 'mediawiki.toolbar', function () {
    var buttons, i, len;
 
	buttons = [
	{
		'imageId': 'button-redirect',
		'imageFile': '//upload.wikimedia.org/wikipedia/en/c/c8/Button_redirect.png',
		'speedTip': 'Đổi hướng',
		'tagOpen': '#đổi [[',
		'tagClose': ']]',
		'sampleText': 'Tên trang để đổi hướng đến'
	},
	{
		'imageId': 'button-strike',
		'imageFile': '//upload.wikimedia.org/wikipedia/en/c/c9/Button_strike.png',
		'speedTip': 'Gạch ngang',
		'tagOpen': '<s>',
		'tagClose': '</s>',
		'sampleText': 'Nội dung gạch ngang'
	},
	{
		'imageId': 'button-enter',
		'imageFile': '//upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png',
		'speedTip': 'Ngắt dòng',
		'tagOpen': '<br/>',
		'tagClose': '',
		'sampleText': ''
	},
	{
		'imageId': 'button-subscript',
		'imageFile': '//upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png',
		'speedTip': 'Viết xuống dưới',
		'tagOpen': '<sub>',
		'tagClose': '</sub>',
		'sampleText': 'Chữ được viết xuống dưới'
	},
	{
		'imageId': 'button-superscript',
		'imageFile': '//upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png',
		'speedTip': 'Viết lên trên',
		'tagOpen': '<sup>',
		'tagClose': '</sup>',
		'sampleText': 'Chữ được viết lên trên'
	},
	{
		'imageId': 'button-small',
		'imageFile': '//upload.wikimedia.org/wikipedia/en/5/58/Button_small.png',
		'speedTip': 'Chữ nhỏ',
		'tagOpen': '<small>',
		'tagClose': '</small>',
		'sampleText': 'Văn bản nhỏ'
	},
	{
		'imageId': 'button-hide-comment',
		'imageFile': '//upload.wikimedia.org/wikipedia/en/3/34/Button_hide_comment.png',
		'speedTip': 'Chèn chú thích ẩn',
		'tagOpen': '<!-- ',
		'tagClose': ' -->',
		'sampleText': 'Chú thích'
	},
	{
		'imageId': 'button-gallery',
		'imageFile': '//upload.wikimedia.org/wikipedia/en/1/12/Button_gallery.png',
		'speedTip': 'Chèn nhóm tập tin',
		'tagOpen': '\n<gallery>\n',
		'tagClose': '\n</gallery>',
		'sampleText': 'Tập tin:Ví dụ.jpg|Chú thích 1\nTập tin:Ví dụ.jpg|Chú thích 2'
	},
	{
		'imageId': 'button-blockquote',
		'imageFile': '//upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png',
		'speedTip': 'Chèn đoạn văn trích dẫn',
		'tagOpen': '<blockquote>\n',
		'tagClose': '\n</blockquote>',
		'sampleText': 'Đoạn trích dẫn'
	},
	{
		'imageId': 'button-insert-table',
		'imageFile': '//upload.wikimedia.org/wikipedia/en/6/60/Button_insert_table.png',
		'speedTip': 'Chèn bảng',
		'tagOpen': '{| class="wikitable"\n|',
		'tagClose': '\n|}',
		'sampleText': '-\n! đầu 1\n! đầu 2\n! đầu 3\n|-\n| hàng 1, ô 1\n| hàng 1, ô 2\n| hàng 1, ô 3\n|-\n| hàng 2, ô 1\n| hàng 2, ô 2\n| hàng 2, ô 3'
	},
	{
		'imageId': 'button-insert-reflink',
		'imageFile': '//upload.wikimedia.org/wikipedia/commons/7/79/Button_reflink.png',
		'speedTip': 'Chèn một nguồn tham khảo',
		'tagOpen': '<ref>',
		'tagClose': '</ref>',
		'sampleText': 'Thêm văn bản chú thích ở đây'
	},
    {
		'imageId': 'button-insert-reflist',
		'imageFile': '//upload.wikimedia.org/wikipedia/commons/6/64/Buttonrefvs8.png',
		'speedTip': 'Chèn đề mục Tham khảo',
		'tagOpen': '== Tham khảo ==\n{{tham khảo}}',
		'tagClose': '',
		'sampleText': ''
	}
	];
 
	for ( i = 0, len = buttons.length; i < len; i++ ) {
		mw.toolbar.addButton( buttons[i] );
	}
 
});

/**
 * Thêm bảng ký tự tiếng Việt có dấu sẵn dành cho bộ sửa đổi của Sáng kiến Khả dụng Wikipedia.
 */
function addVietCharPage() {
	// Thêm bảng ký tự "Việt".
	$("#wpTextbox1").wikiEditor("addToToolbar", {
		section: "characters",
		pages: {
			vietnamese: {
				layout: "characters",
				label: "Việt",
				characters: "ÀàÁáẢảÃãẠạÂâẦầẤấẨẩẪẫẬậĂăẰằẮắẲẳẴẵẶặĐđ₫ÈèÉéẺẻẼẽẸẹÊêỀềẾếỂểỄễỆệÌìÍíỈỉĨĩỊịÒòÓóỎỏÕõỌọÔôỒồỐốỔổỖỗỘộƠơỜờỚớỞởỠỡỢợÙùÚúỦủŨũỤụƯưỪừỨứỬửỮữỰựỲỳÝýỶỷỸỹỴỵ".split("")
			}
		}
	});
	
	// Đẩy khoản "Việt" lên trên danh sách phần.
	var latnItem = $("#editform div.section-characters > div.index > div[rel='latin']");
	var vietItem = $("#editform div.section-characters > div.index > div[rel='vietnamese']");
	latnItem.before(vietItem);
}
 
/**
 * Cài bảng ký tự tiếng Việt vào bộ sửa đổi của Sáng kiến Khả dụng Wikipedia để cho nó hiện trong danh sách bảng ký tự khi nào mở ngăn kéo "Ký tự đặc biệt".
 */
function bindVietCharPage() {
    if (!mw.user.options.get("usebetatoolbar")) return;
    
	// Ngay sau khi xây dựng phần ký tự, thêm bảng tiếng Việt.
	$("#wpTextbox1").on("wikiEditor-toolbar-buildSection-characters", function (section) {
		// Bộ sửa đổi không có cách để gắn hàm sau khi xây dựng phần, nên phải thực hiện không đồng bộ.
		setTimeout(addVietCharPage, 0);
	});
}
mw.hook("wikipage.content").add(bindVietCharPage);

/**
 * Dịch mã cho ra của nút Đổi hướng. Xem [[MediaZilla:24114]].
 */
function bindLocalizedRedirect() {
    $("#wpTextbox1").on("wikiEditor-toolbar-buildSection-advanced", function(event, section) {
        section.groups.insert.tools.redirect.action.options.pre = "#đổi [[";
    });
}
mw.hook("wikipage.content").add(bindLocalizedRedirect);