MediaWiki:Group-sysop.js

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

mw.loader.using('ext.gadget.site-lib').then(function() {

	// 保護選項校正
	if (mw.config.get('wgAction') === 'protect') {
		$(function() {
			var pform = document.getElementById('mw-Protect-Form'),
			timeoptions;
			if (typeof ProtectionForm === 'undefined') {
				return;
			}

			timeoptions = pform['wpProtectExpirySelection-edit'].options;
			if (timeoptions[0].value !== 'existing') {
				timeoptions[timeoptions.length - 1].selected = true;
				ProtectionForm.updateExpiryList(pform['wpProtectExpirySelection-edit']);
			}

			timeoptions = pform['wpProtectExpirySelection-move'].options;
			if (timeoptions[0].value !== 'existing') {
				timeoptions[timeoptions.length - 1].selected = true;
				ProtectionForm.updateExpiryList(pform['wpProtectExpirySelection-move']);
			}
		});
	}

	// 擷取選單文字按鈕
	$(function() {
		var addGetMenuTextButton = function(id, $srcMenu, $targetText, tiptext, afterSelIdx) {
			if ($srcMenu.length === 0 || $targetText.length === 0) {
				return null;
			}

			var $btnAdd = $('<input type="button">', {
				id: id,
				name: id
			}).attr('value', ((!tiptext) ? '(+)' : tiptext));

			$btnAdd.get(0).srcMenu = $srcMenu.get(0);
			$btnAdd.get(0).targetText = $targetText.get(0);
			$btnAdd.get(0).afterSelIdx = (!afterSelIdx || isNaN(afterSelIdx)) ? 0 : afterSelIdx;

			$btnAdd.on('click', function() {
				this.targetText.value += this.srcMenu.options[this.srcMenu.selectedIndex].value;
				this.srcMenu.selectedIndex = this.afterSelIdx;
			}).insertAfter($srcMenu);

			return $btnAdd;
		};

		if (mw.config.get('wgAction').match(/(?:un)?protect/i)) { // 保護理由
			addGetMenuTextButton('wpProtectReasonSelectionAdd', $("form[id='mw-Protect-Form'] select#wpProtectReasonSelection"), $("form[id='mw-Protect-Form'] input[id='mwProtect-reason']"), '加到附加的理由', 0);
		} else if ((String(mw.config.get('wgCanonicalSpecialPageName'))).match(/block(?:ip)?/i)) { // 封禁理由
			mw.loader.using('mediawiki.special.block').then(function() {
				var reasonInput = OO.ui.infuse($('#mw-input-wpReason')),
				button = new OO.ui.ButtonInputWidget({
					label: wgULS('加到附带原因', '加到附帶原因')
				}).on('click', function() {
					var reason = reasonInput.dropdowninput.getValue();
					if (reason !== 'other') {
						reasonInput.textinput.setValue(
							reason + ':' +
							reasonInput.textinput.getValue());
						reasonInput.dropdowninput.setValue('other');
					}
				});
				reasonInput.dropdowninput.$element.after(button.$element);
			});
		}
	});
});