Bước tới nội dung

Thành viên:NhacNy2412/SubpageMover.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.
/*** Subpage Mover ***/// Easily move the subpages of a page with a single click// Documention at [[User:BrandonXLF/SubpageMover]]// By [[User:BrandonXLF]]$(function() {	function moveSubpages() {		var allowed = false;		$.each(mw.config.get('wgUserGroups'), function(i, v) {			if (v == 'eliminator') {				allowed = true;				var from = $('input[name=wpOldTitle]').val(),					to_ns = mw.config.get('wgFormattedNamespaces')[$('select[name=wpNewTitleNs]').val()].replace(' ', '_'),					to_page = $('input[name=wpNewTitleMain]').val(),					to = (to_ns === '' ? to_page : to_ns + ':' + to_page),					reason = $('input[name=wpReason]').val(),					talk = $('input[name=wpMovetalk]').prop('checked') ? 'yes' : void 0,					watch = $('input[name=wpWatch]').prop('checked') ? 'watch' : void 0;				$.get(mw.config.get('wgScriptPath') + '/api.php', {					action: 'query',					list: 'prefixsearch',					pssearch: from + '/',					pslimit: '500',					format: 'json'				}).done(function(apiQuery) {					$('#moveSubpages-log').remove();					var log = $('<span>')						.appendTo($('#movepage'))						.append('<br /><hr />')						.attr('id', 'moveSubpages-log');					function movePage(from, to, noerror) {						$.post(mw.config.get('wgScriptPath') + '/api.php', {							action: 'move',							from: from,							to: to,							reason: reason,							movetalk: talk,							watchlist: watch,							token: mw.user.tokens.get('csrfToken'),							format: 'json'						}).done(function(response) {							if (response.move) {								if (response.move['talkmove-errors']) {									var talkpage = from.match(':') ? from.replace(':', ' th%E1%BA%A3o_lu%E1%BA%ADn:') : 'Th%E1%BA%A3o_lu%E1%BA%ADn:' + from;									log.append($('<p>').text('Không thể di chuyển ' + talkpage).css('color', 'red'));								} else if (response.move.talkfrom) {									log.append(										'<p>Di chuyển thành công ' +										response.move.talkfrom +										' đến ' +										response.move.talkto +										'.</p>'									).css('color', 'green');								}							}							if (response.error) {								log.append($('<p>').text('Không thể di chuyển ' + from).css('color', 'red'));								log.append($('<p>').append('&bull; Nguyên nhân: ' + response.error.info + '</li>').css('color', 'red'));							} else {								log.append('<p>Di chuyển thành công ' + response.move.from + ' đến ' + response.move.to + '.</p>').css('color', 'green');								noerror();							}						});					}					movePage(from, to, function() {						apiQuery.query.prefixsearch.forEach(function(info) {							if (info.title === from) return;							movePage(info.title, info.title.replace(from, to));						});					});				});			}		});		if (!allowed) {			mw.notify('You must be at least eliminator.', {title: 'Cannot move page and subpages', type: 'error'});		}	}		if (mw.config.get('wgCanonicalSpecialPageName') == 'Movepage') {		new OO.ui.ButtonWidget({			label: 'Di chuyển trang và trang con',			flags: ['primary', 'progressive']		}).$element			.on('click', moveSubpages)			.appendTo($('button[name=wpMove]').parent().parent());	}});