Wiki - KEONHACAI COPA

Thành viên:NgocAnMaster/Request-page-protection-form.js

/**
 * Phiên bản tiếng Việt của [[:en:MediaWiki:Request-page-protection-form.js]],
 * dành cho [[Wikipedia:Yêu cầu khóa hay mở khóa trang]]
 * 
 * Dịch thuật viên: [[Thành viên:NgocAnMaster]]
 * 
 * Invoked via [[mw:Snippets/Load JS and CSS by URL]] for
 * [[Wikipedia:Requests_for_page_protection]]
 * 
 * Authors: [[User:Enterprisey]], [[User:SD0001]]
 */

/**
 * Fetch JSON page with 1-day caching
 */
function fetchJsonData(page) {
	return $.getJSON("/w/api.php?action=query&format=json&formatversion=2" + 
		"&titles=" + encodeURIComponent(page) + "&prop=revisions&rvprop=content" + 
		"&uselang=content&maxage=86400&smaxage=86400" // parameters to force caching
	).then(function(apiResponse) {
		return JSON.parse(apiResponse.query.pages[0].revisions[0].content);
	});
}

$.when(fetchJsonData("Wikipedia:Yêu cầu khóa hay mở khóa trang/Forms-configuration.json"), $.ready, mw.loader.using(['mediawiki.api', 'mediawiki.widgets', 'mediawiki.util'])).then(function(config) {
    if ((mw.config.get("wgPageName") !== "Wikipedia:Yêu_cầu_khóa_hay_mở_khóa_trang/Nâng_mức_khóa/Biểu_mẫu") &&
            (mw.config.get("wgPageName") !== "Wikipedia:Yêu_cầu_khóa_hay_mở_khóa_trang/Hạ_mức_khóa/Biểu_mẫu") &&
            (mw.config.get("wgPageName") !== "Wikipedia:Yêu_cầu_khóa_hay_mở_khóa_trang/Sửa_đổi/Biểu_mẫu")) {
        return;
    }
    var api = new mw.Api();
    var previewApi = new mw.Api();

    // either 'Increase', 'Decrease', or 'Edit'
    var subpage = (mw.config.get("wgPageName").indexOf('Nâng_mức_khóa') >= 0) ? 'Nâng_mức_khóa' : ((mw.config.get(
        "wgPageName").indexOf('Hạ_mức_khóa') >= 0) ? 'Hạ_mức_khóa' : 'Sửa_đổi');
	var requestsPageTitle = 'Wikipedia:Yêu_cầu_khóa_hay_mở_khóa_trang';
    config = config[subpage];

    var titleInput = new mw.widgets.TitleInputWidget({
        'showMissing': false,
        'required': true,
        'value': mw.util.getParamValue('prefillPage') || '',
    });
    var reasonInput = new OO.ui.MultilineTextInputWidget({
        'placeholder': config.reasonInputPlaceholder,
        'required': 'true'
    });
	var reasonPreview = new OO.ui.LabelWidget();
    var submitButton = new OO.ui.ButtonWidget({
        'label': 'Đăng yêu cầu',
        'flags': ['progressive', 'primary'],
        'accesskey': 's'
    });
    var fieldset = new OO.ui.FieldsetLayout();
    fieldset.addItems([
        new OO.ui.FieldLayout(titleInput, {
            'label': 'Tên trang:',
            align: 'top'
        }),
        new OO.ui.FieldLayout(reasonInput, {
            'label': config.reasonInputLabel,
            align: 'top'
        }),
        new OO.ui.FieldLayout(reasonPreview, {
            'label': 'Xem trước:',
            align: 'top'
        }),
        new OO.ui.FieldLayout(submitButton)
    ]);
    $("#mw-content-text").empty().append(fieldset.$element);

    function makeRequestText() {
	    var reason = reasonInput.getValue() + (
			(reasonInput.getValue().indexOf('~~' + '~~') >= 0)
			? ''
			: (' ~~' + '~~'));
        return config.template.replace(/\$title/g, titleInput.getValue()).replace(/\$reason/g, reason)
    }
    function updateForm() {
        var hasTitle = titleInput.getValue().trim().length > 0;
        var hasReason = reasonInput.getValue().trim().length > 0;
        
        var formEnabled = hasTitle && hasReason;
        submitButton.setDisabled(!formEnabled);
        var reasonOrRequest = (subpage === 'Sửa_đổi') ? 'yêu cầu' : 'lý do';
        if (!hasTitle && !hasReason) submitButton.setLabel('Lựa chọn trang và nhập ' + reasonOrRequest);
        else if (!hasTitle) submitButton.setLabel('Lựa chọn trang');
        else if (!hasReason) submitButton.setLabel('Nhập ' + reasonOrRequest);
        else submitButton.setLabel('Đăng yêu cầu');
        
        if (formEnabled) {
			previewApi.abort();
			previewApi.parse(makeRequestText(), { 
				pst: true, 
				title: requestsPageTitle 
			}).then(function(text) {
				text = text.replace(/<script/g, '&lt;script');
				reasonPreview.$element.html(text);
			});
        }
    }
    titleInput.on('change', updateForm);
    reasonInput.on('change', updateForm);

    submitButton.on('click', function() {
        updateForm();
        if (submitButton.isDisabled()) {
            return;
        }

        submitButton.setDisabled(true);
        submitButton.setLabel('Đang đăng...');
        api.edit(requestsPageTitle, function() {
            return {
                appendtext: '\n\n' + makeRequestText(),
                summary: config.summary.replace(/\$title/g, titleInput.getValue())
            };
        }).then(function() {
            window.location.href = mw.util.getUrl(requestsPageTitle);
        });
    });
});
Wiki - Keonhacai copa chuyên cung cấp kiến thức thể thao, keonhacai tỷ lệ kèo, bóng đá, khoa học, kiến thức hằng ngày được chúng tôi cập nhật mỗi ngày mà bạn có thể tìm kiếm tại đây có nguồn bài viết: https://vi.wikipedia.org/wiki/Th%C3%A0nh_vi%C3%AAn:NgocAnMaster/Request-page-protection-form.js