(function($) {

/*
 and adds an ad box to the top of user subpages belonging to the
 currently logged-in user which end in '.js'

 I, User:This, that and the other, originally wrote this. If the code is misbehaving, or you have any
 questions, don't hesitate to ask me. (This doesn't at all imply WP:OWNership - it's just meant to
 point you in the right direction.) -- TTO

Twinkle.config = {};

Twinkle.config.watchlistEnums = { yes: '주시문서 목록에 추가', no: "주시문서 목록에 추가하지 않음", 'default': '사이트의 환경 설정에 따름' };

Twinkle.config.commonSets = {
	csdCriteria: {
		db: 'Custom rationale ',
		g1: 'G1', g2: 'G2', g3: 'G3', g4: 'G4', g5: 'G5', g6: 'G6', g7: 'G7', g8: 'G8', g10: 'G10', g11: 'G11', g12: 'G12', g13: 'G13', g14: 'G14',
		a1: 'A1', a2: 'A2', a3: 'A3', a5: 'A5', a7: 'A7', a9: 'A9', a10: 'A10', a11: 'A11',
		u1: 'U1', u2: 'U2', u3: 'U3', u5: 'U5',
		f1: 'F1', f2: 'F2', f3: 'F3', f7: 'F7', f8: 'F8', f9: 'F9', f10: 'F10',
		c1: 'C1',
		t3: 'T3',
		r2: 'R2', r3: 'R3', r4: 'R4',
		p1: 'P1', p2: 'P2'
	csdCriteriaDisplayOrder: [
		'db',
		'g1', 'g2', 'g3', 'g4', 'g5', 'g6', 'g7', 'g8', 'g10', 'g11', 'g12', 'g13', 'g14',
		'a1', 'a2', 'a3', 'a5', 'a7', 'a9', 'a10', 'a11',
		'u1', 'u2', 'u3', 'u5',
		'f1', 'f2', 'f3', 'f7', 'f8', 'f9', 'f10',
		'c1',
		't3',
		'r2', 'r3', 'r4',
		'p1', 'p2'
	],
	csdCriteriaNotification: {
		db: 'Custom rationale ',
		g1: 'G1', g2: 'G2', g3: 'G3', g4: 'G4', g6: 'G6 ("copy-paste move" only)',
		g10: 'G10', g11: 'G11', g12: 'G12', g13: 'G13', g14: 'G14',
		a1: 'A1', a2: 'A2', a3: 'A3', a5: 'A5', a7: 'A7', a9: 'A9', a10: 'A10', a11: 'A11',
		u3: 'U3', u5: 'U5',
		f1: 'F1', f2: 'F2', f3: 'F3', f7: 'F7', f9: 'F9', f10: 'F10',
		c1: 'C1',
		t3: 'T3',
		r2: 'R2', r3: 'R3', r4: 'R4',
		p1: 'P1', p2: 'P2'
	csdCriteriaNotificationDisplayOrder: [
		'db',
		'g1', 'g2', 'g3', 'g4', 'g6', 'g10', 'g11', 'g12', 'g13', 'g14',
		'a1', 'a2', 'a3', 'a5', 'a7', 'a9', 'a10', 'a11',
		'u3', 'u5',
		'f1', 'f2', 'f3', 'f7', 'f9', 'f10',
		'c1',
		't3',
		'r2', 'r3', 'r4',
		'p1', 'p2'
	],
	csdAndDICriteria: {
		db: 'Custom rationale ',
		g1: 'G1', g2: 'G2', g3: 'G3', g4: 'G4', g5: 'G5', g6: 'G6', g7: 'G7', g8: 'G8', g10: 'G10', g11: 'G11', g12: 'G12', g13: 'G13', g14: 'G14',
		a1: 'A1', a2: 'A2', a3: 'A3', a5: 'A5', a7: 'A7', a9: 'A9', a10: 'A10', a11: 'A11',
		u1: 'U1', u2: 'U2', u3: 'U3', u5: 'U5',
		f1: 'F1', f2: 'F2', f3: 'F3', f4: 'F4', f5: 'F5', f6: 'F6', f7: 'F7', f8: 'F8', f9: 'F9', f10: 'F10', f11: 'F11',
		c1: 'C1',
		t3: 'T3',
		r2: 'R2', r3: 'R3', r4: 'R4',
		p1: 'P1', p2: 'P2'
	csdAndDICriteriaDisplayOrder: [
		'db',
		'g1', 'g2', 'g3', 'g4', 'g5', 'g6', 'g7', 'g8', 'g10', 'g11', 'g12', 'g13', 'g14',
		'a1', 'a2', 'a3', 'a5', 'a7', 'a9', 'a10', 'a11',
		'u1', 'u2', 'u3', 'u5',
		'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11',
		'c1',
		't3',
		'r2', 'r3', 'r4',
		'p1', 'p2'
	],
	namespacesNoSpecial: {
		'0': '일반',
		'1': '토론',
		'2': '사용자',
		'3': '사용자토론',
		'4': '위키백과',
		'5': '위키백과토론',
		'6': '파일',
		'7': '파일토론',
		'8': '미디어위키',
		'9': '미디어위키토론',
		'10': '틀',
		'11': '틀토론',
		'12': '도움말',
		'13': '도움말토론',
		'14': '분류',
		'15': '분류토론',
		'100': '포털',
		'101': '포털토론',
		'108': '책',
		'109': '책토론',
		'118': '초안',
		'119': '초안토론',
		'710': 'TimedText',
		'711': 'TimedText talk',
		'828': '모듈',
		'829': '모듈토론'

/**

Twinkle.config.sections = [
		title: '일반',
		preferences: [
			// TwinkleConfig.summaryAd (string)
			// Text to be appended to the edit summary of edits made using Twinkle
				name: 'summaryAd',
				label: "\"Ad\" to be appended to Twinkle's edit summaries",
				helptip: '시작할 때는 한칸을 띄우고, 최대한 짧게 넣습니다.',
				type: 'string'

			// TwinkleConfig.deletionSummaryAd (string)
			// Text to be appended to the edit summary of deletions made using Twinkle
				name: 'deletionSummaryAd',
				label: 'Summary ad to use for deletion summaries',
				helptip: 'Normally the same as the edit summary ad above.',
				adminOnly: true,
				type: 'string'

			// TwinkleConfig.protectionSummaryAd (string)
			// Text to be appended to the edit summary of page protections made using Twinkle
				name: 'protectionSummaryAd',
				label: 'Summary ad to use for page protections',
				helptip: 'Normally the same as the edit summary ad above.',
				adminOnly: true,
				type: 'string'

			// TwinkleConfig.userTalkPageMode may take arguments:
			// 'window': open a new window, remember the opened window
			// 'tab': opens in a new tab, if possible.
			// 'blank': force open in a new window, even if such a window exists
				name: 'userTalkPageMode',
				label: '사용자 토론 문서를 열 때',
				type: 'enum',
				enumValues: { window: '창에서 다른 사용자 토론을 치환', tab: '새 탭에서', blank: '완전히 새 창에서' }

			// TwinkleConfig.dialogLargeFont (boolean)
				name: 'dialogLargeFont',
				label: '트윙클 대화 상자에서 더 큰 텍스트 사용',
				type: 'boolean'

			// Twinkle.config.disabledModules (array)
				name: 'disabledModules',
				label: '선택된 트윙클 모듈 끄기',
				helptip: 'Anything you select here will NOT be available for use, so act with care. Uncheck to reactivate.',
				type: 'set',
				setValues: { arv: 'ARV', warn: 'Warn', welcome: 'Welcome', shared: 'Shared IP', talkback: 'Talkback', speedy: 'CSD', prod: 'PROD', xfd: 'XfD', image: 'Image (DI)', protect: 'Protect (RPP)', tag: 'Tag', diff: 'Diff', unlink: 'Unlink', 'fluff': 'Revert and rollback' }

			// Twinkle.config.disabledSysopModules (array)
				name: 'disabledSysopModules',
				label: '선택된 관리자 전용 모듈 끄기',
				helptip: 'Anything you select here will NOT be available for use, so act with care. Uncheck to reactivate.',
				adminOnly: true,
				type: 'set',
				setValues: { block: 'Block', deprod: 'DePROD', batchdelete: 'D-batch', batchprotect: 'P-batch', batchundelete: 'Und-batch' }
		]

		title: 'ARV',
		preferences: [
				name: 'spiWatchReport',
				label: '다중 계정 보고서 문서를 주시문서 목록에 추가',
				type: 'enum',
				enumValues: Twinkle.config.watchlistEnums
		]

		title: '사용자 차단',
		adminOnly: true,
		preferences: [
			// TwinkleConfig.defaultToPartialBlocks (boolean)
			// Whether to default partial blocks on or off
				name: 'defaultToPartialBlocks',
				label: 'Select partial blocks by default when opening the block menu',
				type: 'boolean'

			// TwinkleConfig.blankTalkpageOnIndefBlock (boolean)
			// if true, blank the talk page when issuing an indef block notice (per WP:UWUL#Indefinitely blocked users)
				name: 'blankTalkpageOnIndefBlock',
				label: 'Blank the talk page when indefinitely blocking users',
				helptip: 'See  for more information.',
				type: 'boolean'
		]

		title: '그림 삭제 (DI)',
		preferences: [
			// TwinkleConfig.notifyUserOnDeli (boolean)
			// If the user should be notified after placing a file deletion tag
				name: 'notifyUserOnDeli',
				label: 'Check the "notify initial uploader" box by default',
				type: 'boolean'

			// TwinkleConfig.deliWatchPage (string)
			// The watchlist setting of the page tagged for deletion. Either "yes", "no", or "default". Default is "default" (Duh).
				name: 'deliWatchPage',
				label: 'Add image page to watchlist when tagging',
				type: 'enum',
				enumValues: Twinkle.config.watchlistEnums

			// TwinkleConfig.deliWatchUser (string)
			// The watchlist setting of the user talk page if a notification is placed. Either "yes", "no", or "default". Default is "default" (Duh).
				name: 'deliWatchUser',
				label: 'Add user talk page of initial uploader to watchlist when notifying',
				type: 'enum',
				enumValues: Twinkle.config.watchlistEnums
		]

		title: 'Proposed deletion (PROD)',
		preferences: [
			// TwinkleConfig.watchProdPages (boolean)
			// If, when applying prod template to page, to watch the page
				name: 'watchProdPages',
				label: 'Add article to watchlist when tagging',
				type: 'boolean'

			// TwinkleConfig.markProdPagesAsPatrolled (boolean)
			// If, when applying prod template to page, to mark the page as curated/patrolled (if the page was reached from NewPages)
				name: 'markProdPagesAsPatrolled',
				label: 'Mark page as patrolled/reviewed when tagging (if possible)',
				helptip: 'This should probably not be checked as doing so is against best practice consensus',
				type: 'boolean'

			// TwinkleConfig.prodReasonDefault (string)
			// The prefilled PROD reason.
				name: 'prodReasonDefault',
				label: 'Prefilled PROD reason',
				type: 'string'

				name: 'logProdPages',
				label: '삭제 제안을 할 때 기록을 사용자 하위 문서에 작성하기',
				helptip: 'Since non-admins do not have access to their deleted contributions, the userspace log offers a good way to keep track of all pages you tag for PROD using Twinkle.',
				type: 'boolean'
				name: 'prodLogPageName',
				label: 'Keep the PROD userspace log at this user subpage',
				helptip: 'Enter a subpage name in this box. You will find your PROD log at User:. Only works if you turn on the PROD userspace log.',
				type: 'string'
		]

		title: '되돌리기', // twinklefluff module
		preferences: [
			// TwinkleConfig.autoMenuAfterRollback (bool)
			// Option to automatically open the warning menu if the user talk page is opened post-reversion
				name: 'autoMenuAfterRollback',
				label: '트윙클의 되돌리기를 사용한 후 자동으로 사용자 토론 문서',
				helptip: 'Only operates if the relevant box is checked below.',
				type: 'boolean'

			// TwinkleConfig.openTalkPage (array)
			// What types of actions that should result in opening of talk page
				name: 'openTalkPage',
				label: '아래 기능을 사용했을 때만 사용자 토론 문서 열기',
				type: 'set',
				setValues: { agf: '일괄 되돌리기 (선의의 편집)', norm: '일괄 되돌리기', vand: '"문서 훼손"', torev: '"이 판으로 복구하기"' }

			// TwinkleConfig.openTalkPageOnAutoRevert (bool)
			// Defines if talk page should be opened when calling revert from contribs or recent changes pages. If set to true, openTalkPage defines then if talk page will be opened.
				name: 'openTalkPageOnAutoRevert',
				label: '일괄 되돌리기 기능을 사용한 후 사용자의 토론 문서 열기',
				helptip: '사용자 경고를 한번에 하는 데 도움이 됩니다.',
				type: 'boolean'

			// TwinkleConfig.rollbackInPlace (bool)
			//
				name: 'rollbackInPlace',
				label: "최근 바뀜과 기여에서 사용한 경우 페이지를 새로 고치지 않기",
				helptip: "보통은 되돌리기 버튼을 누른 후 확인을 위해 페이지를 새로 고치지만, 옆 창에 뜨는 팝업으로 대체할 수 있습니다.",
				type: 'boolean'

			// TwinkleConfig.markRevertedPagesAsMinor (array)
			// What types of actions that should result in marking edit as minor
				name: 'markRevertedPagesAsMinor',
				label: '다음 기능을 사용했을 때만 사소한 편집으로 표시하기',
				type: 'set',
				setValues: { agf: '일괄 되돌리기 (선의의 편집)', norm: '일괄 되돌리기', vand: '"문서 훼손"', torev: '"이 판으로 복구하기"' }

			// TwinkleConfig.watchRevertedPages (array)
			// What types of actions that should result in forced addition to watchlist
				name: 'watchRevertedPages',
				label: '다음 기능을 사용하였을 때만 주시문서 목록에 추가하기',
				type: 'set',
				setValues: { agf: '일괄 되돌리기 (선의의 편집)', norm: '일괄 되돌리기', vand: '"문서 훼손"', torev: '"이 판으로 복구하기"' }

			// TwinkleConfig.offerReasonOnNormalRevert (boolean)
			// If to offer a prompt for extra summary reason for normal reverts, default to true
				name: 'offerReasonOnNormalRevert',
				label: '"일괄 되돌리기" 버튼을 누를 때 편집 요약 입력 창 열기',
				helptip: '[문서 훼손] 버튼이 아닌, [일괄 되돌리기] 버튼을 나타냅니다.',
				type: 'boolean'

				name: 'confirmOnFluff',
				label: '되돌리기 전에 확인 거치기',
				helptip: '잘못 클릭하는 경우가 많은 사용자들에게 도움이 됩니다.',
				type: 'boolean'

			// TwinkleConfig.showRollbackLinks (array)
			// Where Twinkle should show rollback links:
			// diff, others, mine, contribs, history, recent
			// Note from TTO: |contribs| seems to be equal to |others| + |mine|, i.e. redundant, so I left it out heres
				name: 'showRollbackLinks',
				label: '아래 문서에서 되돌리기 링크 보이기',
				type: 'set',
				setValues: { diff: '차이 보기 페이지', others: '다른 사용자의 기여 페이지', mine: '내 기여 페이지', recent: '최근 바뀜, 주시문서 목록, 링크 최근 바뀜', history: '역사 보기 페이지' }
		]

		title: '공유 IP 태그',
		preferences: [
				name: 'markSharedIPAsMinor',
				label: 'Mark shared IP tagging as a minor edit',
				type: 'boolean'
		]

		title: '빠른 삭제 (CSD)',
		preferences: [
				name: 'speedySelectionStyle',
				label: 'When to go ahead and tag/delete the page',
				type: 'enum',
				enumValues: { 'buttonClick': 'When I click "Submit"', 'radioClick': 'As soon as I click an option' }

			// TwinkleConfig.watchSpeedyPages (array)
			// Whether to add speedy tagged or deleted pages to watchlist
				name: 'watchSpeedyPages',
				label: 'Add page to watchlist when using these criteria',
				type: 'set',
				setValues: Twinkle.config.commonSets.csdCriteria,
				setDisplayOrder: Twinkle.config.commonSets.csdCriteriaDisplayOrder

			// TwinkleConfig.markSpeedyPagesAsPatrolled (boolean)
			// If, when applying speedy template to page, to mark the page as triaged/patrolled (if the page was reached from NewPages)
				name: 'markSpeedyPagesAsPatrolled',
				label: 'Mark page as patrolled/reviewed when tagging (if possible)',
				helptip: 'This should probably not be checked as doing so is against best practice consensus',
				type: 'boolean'

			// TwinkleConfig.welcomeUserOnSpeedyDeletionNotification (array of strings)
			// On what types of speedy deletion notifications shall the user be welcomed
			// with a "firstarticle" notice if their talk page has not yet been created.
				name: 'welcomeUserOnSpeedyDeletionNotification',
				label: 'Welcome page creator when notifying with these criteria',
				helptip: 'The welcome is issued only if the user is notified about the deletion, and only if their talk page does not already exist. The template used is .',
				type: 'set',
				setValues: Twinkle.config.commonSets.csdCriteriaNotification,
				setDisplayOrder: Twinkle.config.commonSets.csdCriteriaNotificationDisplayOrder

			// TwinkleConfig.notifyUserOnSpeedyDeletionNomination (array)
			// What types of actions should result in the author of the page being notified of nomination
				name: 'notifyUserOnSpeedyDeletionNomination',
				label: 'Notify page creator when tagging with these criteria',
				helptip: 'Even if you choose to notify from the CSD screen, the notification will only take place for those criteria selected here.',
				type: 'set',
				setValues: Twinkle.config.commonSets.csdCriteriaNotification,
				setDisplayOrder: Twinkle.config.commonSets.csdCriteriaNotificationDisplayOrder

			// TwinkleConfig.warnUserOnSpeedyDelete (array)
			// What types of actions should result in the author of the page being notified of speedy deletion (admin only)
				name: 'warnUserOnSpeedyDelete',
				label: 'Notify page creator when deleting under these criteria',
				helptip: 'Even if you choose to notify from the CSD screen, the notification will only take place for those criteria selected here.',
				adminOnly: true,
				type: 'set',
				setValues: Twinkle.config.commonSets.csdCriteriaNotification,
				setDisplayOrder: Twinkle.config.commonSets.csdCriteriaNotificationDisplayOrder

			// TwinkleConfig.promptForSpeedyDeletionSummary (array of strings)
				name: 'promptForSpeedyDeletionSummary',
				label: 'Allow editing of deletion summary when deleting under these criteria',
				adminOnly: true,
				type: 'set',
				setValues: Twinkle.config.commonSets.csdAndDICriteria,
				setDisplayOrder: Twinkle.config.commonSets.csdAndDICriteriaDisplayOrder

			// TwinkleConfig.deleteTalkPageOnDelete (boolean)
			// If talk page if exists should also be deleted (CSD G8) when spedying a page (admin only)
				name: 'deleteTalkPageOnDelete',
				label: 'Check the "also delete talk page" box by default',
				adminOnly: true,
				type: 'boolean'

				name: 'deleteRedirectsOnDelete',
				label: 'Check the "also delete redirects" box by default',
				adminOnly: true,
				type: 'boolean'

			// TwinkleConfig.deleteSysopDefaultToDelete (boolean)
			// Make the CSD screen default to "delete" instead of "tag" (admin only)
				name: 'deleteSysopDefaultToDelete',
				label: 'Default to outright deletion instead of speedy tagging',
				helptip: 'If there is a CSD tag already present, Twinkle will always default to "delete" mode',
				adminOnly: true,
				type: 'boolean'

			// TwinkleConfig.speedyWindowWidth (integer)
			// Defines the width of the Twinkle SD window in pixels
				name: 'speedyWindowWidth',
				label: 'Width of speedy deletion window (pixels)',
				type: 'integer'

			// TwinkleConfig.speedyWindowWidth (integer)
			// Defines the width of the Twinkle SD window in pixels
				name: 'speedyWindowHeight',
				label: 'Height of speedy deletion window (pixels)',
				helptip: 'If you have a big monitor, you might like to increase this.',
				type: 'integer'

				name: 'logSpeedyNominations',
				label: 'Keep a log in userspace of all CSD nominations',
				helptip: 'Since non-admins do not have access to their deleted contributions, the userspace log offers a good way to keep track of all pages you nominate for CSD using Twinkle. Files tagged using DI are also added to this log.',
				type: 'boolean'
				name: 'speedyLogPageName',
				label: 'Keep the CSD userspace log at this user subpage',
				helptip: 'Enter a subpage name in this box. You will find your 빠른 삭제 기록 at User:. Only works if you turn on the CSD userspace log.',
				type: 'string'
				name: 'noLogOnSpeedyNomination',
				label: 'Do not create a userspace log entry when tagging with these criteria',
				type: 'set',
				setValues: Twinkle.config.commonSets.csdAndDICriteria,
				setDisplayOrder: Twinkle.config.commonSets.csdAndDICriteriaDisplayOrder
		]

		title: '태그',
		preferences: [
				name: 'watchTaggedPages',
				label: 'Add page to watchlist when tagging',
				type: 'boolean'
				name: 'watchMergeDiscussions',
				label: 'Add talk pages to watchlist when starting merge discussions',
				type: 'boolean'
				name: 'markTaggedPagesAsMinor',
				label: 'Mark addition of tags as a minor edit',
				type: 'boolean'
				name: 'markTaggedPagesAsPatrolled',
				label: 'Check the "mark page as patrolled/reviewed" box by default',
				type: 'boolean'
				name: 'groupByDefault',
				label: 'Check the "group into " box by default',
				type: 'boolean'
				name: 'tagArticleSortOrder',
				label: 'Default view order for article tags',
				type: 'enum',
				enumValues: { 'cat': 'By categories', 'alpha': 'In alphabetical order' }
				name: 'customTagList',
				label: 'Custom article/draft maintenance tags to display',
				helptip: "These appear as additional options at the bottom of the list of tags. For example, you could add new maintenance tags which have not yet been added to Twinkle's defaults.",
				type: 'customList',
				customListValueTitle: '중괄호를 제외한 틀 이름',
				customListLabelTitle: 'Text to show in Tag dialog'
				name: 'customFileTagList',
				label: 'Custom file maintenance tags to display',
				helptip: 'Additional tags that you wish to add for files.',
				type: 'customList',
				customListValueTitle: '중괄호를 제외한 틀 이름',
				customListLabelTitle: 'Text to show in Tag dialog'
				name: 'customRedirectTagList',
				label: 'Custom redirect category tags to display',
				helptip: 'Additional tags that you wish to add for redirects.',
				type: 'customList',
				customListValueTitle: '중괄호를 제외한 틀 이름',
				customListLabelTitle: 'Text to show in Tag dialog'
		]

		title: '토론 알림',
		preferences: [
				name: 'markTalkbackAsMinor',
				label: 'Mark talkbacks as minor edits',
				type: 'boolean'
				name: 'insertTalkbackSignature',
				label: 'Insert signature within talkbacks',
				type: 'boolean'
				name: 'talkbackHeading',
				label: 'Section heading to use for talkbacks',
				type: 'string'
				name: 'adminNoticeHeading',
				label: "Section heading to use for administrators' noticeboard notices",
				helptip: 'Only relevant for AN and ANI.',
				type: 'string'
				name: 'mailHeading',
				label: "Section heading to use for \"you've got mail\" notices",
				type: 'string'
		]

		title: '링크 제거',
		preferences: [
			// TwinkleConfig.unlinkNamespaces (array)
			// In what namespaces unlink should happen, default in 0 (article), 10 (template), 100 (portal), and 118 (draft)
				name: 'unlinkNamespaces',
				label: 'Remove links from pages in these namespaces',
				helptip: 'Avoid selecting any talk namespaces, as Twinkle might end up unlinking on talk archives (a big no-no).',
				type: 'set',
				setValues: Twinkle.config.commonSets.namespacesNoSpecial
		]

		title: '사용자에게 경고',
		preferences: [
			// TwinkleConfig.defaultWarningGroup (int)
			// Which level warning should be the default selected group, default is 1
				name: 'defaultWarningGroup',
				label: '기본 경고 단계',
				type: 'enum',
				enumValues: {
					'1': 'Level 1',
					'2': 'Level 2',
					'3': 'Level 3',
					'4': 'Level 4',
					'5': 'Level 4im',
					'6': 'Single-issue notices',
					'7': 'Single-issue warnings',
					// 8 was used for block templates before #260
					'9': 'Custom warnings',
					'10': 'All warning templates',
					'11': 'Auto-select level (1-4)'

			// TwinkleConfig.combinedSingletMenus (boolean)
			// if true, show one menu with both single-issue notices and warnings instead of two separately
				name: 'combinedSingletMenus',
				label: 'Replace the two separate single-issue menus into one combined menu',
				helptip: 'Selecting either single-issue notices or single-issue warnings as your default will make this your default if enabled.',
				type: 'boolean'

			// TwinkleConfig.showSharedIPNotice may take arguments:
			// true: to show shared ip notice if an IP address
			// false: to not print the notice
				name: 'showSharedIPNotice',
				label: 'IP 사용자일 경우 추가 안내 틀을 추가합니다.',
				helptip: 'Notice used is ',
				type: 'boolean'

			// TwinkleConfig.watchWarnings (boolean)
			// if true, watch the page which has been dispatched an warning or notice, if false, default applies
				name: 'watchWarnings',
				label: '사용자에게 알린 후 사용자 토론 문서를 주시문서 목록에 추가',
				type: 'boolean'

			// TwinkleConfig.oldSelect (boolean)
			// if true, use the native select menu rather the select2-based one
				name: 'oldSelect',
				label: 'Use the non-searchable classic select menu',
				type: 'boolean'

				name: 'customWarningList',
				label: 'Custom warning templates to display',
				helptip: 'You can add individual templates or user subpages. Custom warnings appear in the "Custom warnings" category within the warning dialog box.',
				type: 'customList',
				customListValueTitle: '중괄호를 제외한 틀 이름',
				customListLabelTitle: '경고 틀 목록에 사용할 이름 (편집 요약에도 사용)'
		]

		title: '사용자 환영',
		preferences: [
				name: 'topWelcomes',
				label: 'Place welcomes above existing content on user talk pages',
				type: 'boolean'
				name: 'watchWelcomes',
				label: 'Add user talk pages to watchlist when welcoming',
				helptip: 'Doing so adds to the personal element of welcoming a user - you will be able to see how they are coping as a newbie, and possibly help them.',
				type: 'boolean'
				name: 'insertUsername',
				label: 'Add your username to the template (where applicable)',
				helptip: "Some welcome templates have an opening sentence like \"Hi, I'm &lt;username&gt;. Welcome\" etc. If you turn off this option, these templates will not display your username in that way.",
				type: 'boolean'
				name: 'quickWelcomeMode',
				label: 'Clicking the "welcome" link on a 차이 보기 페이지 will',
				helptip: 'If you choose to welcome automatically, the template you specify below will be used.',
				type: 'enum',
				enumValues: { auto: 'welcome automatically', norm: 'prompt you to select a template' }
				name: 'quickWelcomeTemplate',
				label: 'Template to use when welcoming automatically',
				helptip: 'Enter the name of a welcome template, without the curly brackets. A link to the given article will be added.',
				type: 'string'
				name: 'customWelcomeList',
				label: '커스텀 환영 틀',
				helptip: "당신은 기본 환영 틀 이욍 다른 틀이나 사용자 하위 문서를 사용할 수 있습니다.",
				type: 'customList',
				customListValueTitle: '중괄호를 제외한 틀 이름',
				customListLabelTitle: '환영 틀 목록에 표시할 텍스트'
				name: 'customWelcomeSignature',
				label: 'Automatically sign custom welcome templates',
				helptip: 'If your custom welcome templates contain a built-in signature within the template, turn off this option.',
				type: 'boolean'
		]

		title: 'XFD (삭제 토론)',
		preferences: [
				name: 'logXfdNominations',
				label: 'Keep a log in userspace of all pages you nominate for a deletion discussion (XfD)',
				helptip: 'The userspace log offers a good way to keep track of all pages you nominate for XfD using Twinkle.',
				type: 'boolean'
				name: 'xfdLogPageName',
				label: 'Keep the deletion discussion userspace log at this user subpage',
				helptip: 'Enter a subpage name in this box. You will find your XfD log at User:. Only works if you turn on the XfD userspace log.',
				type: 'string'
				name: 'noLogOnXfdNomination',
				label: 'Do not create a userspace log entry when nominating at this venue',
				type: 'set',
				setValues: { afd: 'AfD', tfd: 'TfD', ffd: 'FfD', cfd: 'CfD', cfds: 'CfD/S', mfd: 'MfD', rfd: 'RfD', rm: 'RM' }

			// TwinkleConfig.xfdWatchPage (string)
			// The watchlist setting of the page being nominated for XfD. Either "yes" (add to watchlist), "no" (don't
			// add to watchlist), or "default" (use setting from preferences). Default is "default" (duh).
				name: 'xfdWatchPage',
				label: 'Add the nominated page to watchlist',
				type: 'enum',
				enumValues: Twinkle.config.watchlistEnums

			// TwinkleConfig.xfdWatchDiscussion (string)
			// The watchlist setting of the newly created XfD page (for those processes that create discussion pages for each nomination),
			// or the list page for the other processes.
			// Either "yes" (add to watchlist), "no" (don't add to watchlist), or "default" (use setting from preferences). Default is "default" (duh).
				name: 'xfdWatchDiscussion',
				label: 'Add the deletion discussion page to watchlist',
				helptip: 'This refers to the discussion subpage (for AfD and MfD) or the daily log page ',
				type: 'enum',
				enumValues: Twinkle.config.watchlistEnums

			// TwinkleConfig.xfdWatchList (string)
			// The watchlist setting of the XfD list page, *if* the discussion is on a separate page. Either "yes" (add to watchlist), "no" (don't
			// add to watchlist), or "default" (use setting from preferences). Default is "no" .
				name: 'xfdWatchList',
				label: 'Add the daily log/list page to the watchlist (where applicable)',
				helptip: 'This only applies for AfD and MfD, where the discussions are transcluded onto a daily log page (for AfD) or the main MfD page (for MfD).',
				type: 'enum',
				enumValues: Twinkle.config.watchlistEnums

			// TwinkleConfig.xfdWatchUser (string)
			// The watchlist setting of the user talk page if they receive a notification. Either "yes" (add to watchlist), "no" (don't
			// add to watchlist), or "default" (use setting from preferences). Default is "default" (duh).
				name: 'xfdWatchUser',
				label: 'Add user talk page of initial contributor to watchlist (when notifying)',
				type: 'enum',
				enumValues: Twinkle.config.watchlistEnums

			// TwinkleConfig.xfdWatchRelated (string)
			// The watchlist setting of the target of a redirect being nominated for RfD. Either "yes" (add to watchlist), "no" (don't
			// add to watchlist), or "default" (use setting from preferences). Default is "default" (duh).
				name: 'xfdWatchRelated',
				label: "Add the redirect's target page to watchlist (when notifying)",
				helptip: 'This only applies for RfD, when leaving a notification on the talk page of the target of the redirect',
				type: 'enum',
				enumValues: Twinkle.config.watchlistEnums

				name: 'markXfdPagesAsPatrolled',
				label: 'Mark page as patrolled/reviewed when nominating for AFD (if possible)',
				type: 'boolean'
		]

		title: 'Hidden',
		hidden: true,
		preferences: [
			// twinkle.js: portlet setup
				name: 'portletArea',
				type: 'string'
				name: 'portletId',
				type: 'string'
				name: 'portletName',
				type: 'string'
				name: 'portletType',
				type: 'string'
				name: 'portletNext',
				type: 'string'
			// twinklefluff.js: defines how many revision to query maximum, maximum possible is 50, default is 50
				name: 'revertMaxRevisions',
				type: 'integer'
			// twinklewarn.js: When using the autolevel select option, how many days makes a prior warning stale
			// Huggle is three days (Special:Diff/918980316 and Special:Diff/919417999) while ClueBotNG is two:
			// https://github.com/DamianZaremba/cluebotng/blob/4958e25d6874cba01c75f11debd2e511fd5a2ce5/bot/action_functions.php#L62
				name: 'autolevelStaleDays',
				type: 'integer'
			// How many pages should be queried by deprod and batchdelete/protect/undelete
				name: 'batchMax',
				type: 'integer',
				adminOnly: true
			// How many pages should be processed at a time by deprod and batchdelete/protect/undelete
				name: 'batchChunks',
				type: 'integer',
				adminOnly: true
		]

]; // end of Twinkle.config.sections

Twinkle.config.init = function twinkleconfigInit {

	// create the config page at Wikipedia:Twinkle/Preferences
	if ((mw.config.get('wgNamespaceNumber') === mw.config.get('wgNamespaceIds').project && mw.config.get('wgTitle') === '도구/트윙클/환경 설정') &&
			mw.config.get('wgAction') === 'view') {

		if (!document.getElementById('twinkle-config')) {
			return; // maybe the page is misconfigured, or something - but any attempt to modify it will be pointless

		// set style (the url CSS function doesn't seem to work from wikicode - ?!)
		document.getElementById('twinkle-config-titlebar').style.backgroundImage = 'url';

		var contentdiv = document.getElementById('twinkle-config-content');
		contentdiv.textContent = ''; // clear children

		// let user know about possible conflict with skin js/common.js file
		// 
		if (window.TwinkleConfig || window.FriendlyConfig) {
			var contentnotice = document.createElement('p');
			contentnotice.innerHTML = '' +
				'' +
				'' +
				'To do this, you can <a href="' + mw.util.getUrl('User:' + mw.config.get('wgUserName') + '/' + mw.config.get('skin') +
				'.js', { action: 'edit' }) + '" target="_blank"> or <a href="' +
				mw.util.getUrl('User:' + mw.config.get('wgUserName') + '/common.js', { action: 'edit'}) + '" target="_blank">';
			contentdiv.appendChild(contentnotice);

		// start a table of contents
		var toctable = document.createElement('div');
		toctable.className = 'toc';
		toctable.style.marginLeft = '0.4em';
		// create TOC title
		var toctitle = document.createElement('div');
		toctitle.id = 'toctitle';
		var toch2 = document.createElement('h2');
		toch2.textContent = '목차 ';
		toctitle.appendChild(toch2);
		// add TOC show/hide link
		var toctoggle = document.createElement('span');
		toctoggle.className = 'toctoggle';
		toctoggle.appendChild(document.createTextNode('['));
		var toctogglelink = document.createElement('a');
		toctogglelink.className = 'internal';
		toctogglelink.setAttribute;
		toctogglelink.textContent = '숨기기';
		toctoggle.appendChild(toctogglelink);
		toctoggle.appendChild(document.createTextNode(']'));
		toctitle.appendChild(toctoggle);
		toctable.appendChild(toctitle);
		// create item container: this is what we add stuff to
		var tocul = document.createElement('ul');
		toctogglelink.addEventListener('click', function twinkleconfigTocToggle {
			var $tocul = $(tocul);
			$tocul.toggle;
			if ($tocul.find(':visible').length) {
				toctogglelink.textContent = '숨기기';
				toctogglelink.textContent = '보이기';
		toctable.appendChild(tocul);
		contentdiv.appendChild(toctable);

		var tocnumber = 1;

		var contentform = document.createElement('form');
		contentform.setAttribute('action', 'javascript:void(0)'); // was #tw-save - changed to void(0) to work around Chrome issue
		contentform.addEventListener;
		contentdiv.appendChild(contentform);

		var container = document.createElement('table');
		container.style.width = '100%';
		contentform.appendChild(container);

		$(Twinkle.config.sections).each(function {
			if (section.hidden || (section.adminOnly && !Morebits.userIsSysop)) {
				return true; // i.e. "continue" in this context

			// add to TOC
			var tocli = document.createElement('li');
			tocli.className = 'toclevel-1';
			var toca = document.createElement('a');
			toca.setAttribute;
			toca.appendChild(document.createTextNode(section.title));
			tocli.appendChild(toca);
			tocul.appendChild(tocli);

			var row = document.createElement('tr');
			var cell = document.createElement('td');
			cell.setAttribute;
			var heading = document.createElement('h4');
			heading.style.borderBottom = '1px solid gray';
			heading.style.marginTop = '0.2em';
			heading.id = 'twinkle-config-section-' + (tocnumber++).toString;
			heading.appendChild(document.createTextNode(section.title));
			cell.appendChild(heading);
			row.appendChild(cell);
			container.appendChild(row);

			var rowcount = 1; // for row banding

			// add each of the preferences to the form
			$(section.preferences).each(function {
				if (pref.adminOnly && !Morebits.userIsSysop) {
					return true; // i.e. "continue" in this context

				row = document.createElement('tr');
				row.style.marginBottom = '0.2em';
				// create odd row banding
				if (rowcount++ % 2 === 0) {
					row.style.backgroundColor = 'rgba';
				cell = document.createElement('td');

				var label, input;
				switch (pref.type) {

					case 'boolean': // create a checkbox
						cell.setAttribute;

						label = document.createElement('label');
						input = document.createElement('input');
						input.setAttribute;
						input.setAttribute;
						input.setAttribute;
						if (Twinkle.getPref(pref.name) === true) {
							input.setAttribute;
						label.appendChild(input);
						label.appendChild(document.createTextNode(' ' + pref.label));
						cell.appendChild(label);
						break;

					case 'string': // create an input box
					case 'integer':
						// add label to first column
						cell.style.textAlign = 'right';
						cell.style.paddingRight = '0.5em';
						label = document.createElement('label');
						label.setAttribute;
						label.appendChild(document.createTextNode(pref.label + ':'));
						cell.appendChild(label);
						row.appendChild(cell);

						// add input box to second column
						cell = document.createElement('td');
						cell.style.paddingRight = '1em';
						input = document.createElement('input');
						input.setAttribute;
						input.setAttribute;
						input.setAttribute;
						if (pref.type === 'integer') {
							input.setAttribute;
							input.setAttribute;
							input.setAttribute; // integers only
						if (Twinkle.getPref(pref.name)) {
							input.setAttribute('value', Twinkle.getPref(pref.name));
						cell.appendChild(input);
						break;

					case 'enum': // create a combo box
						// add label to first column
						// note: duplicates the code above, under string/integer
						cell.style.textAlign = 'right';
						cell.style.paddingRight = '0.5em';
						label = document.createElement('label');
						label.setAttribute;
						label.appendChild(document.createTextNode(pref.label + ':'));
						cell.appendChild(label);
						row.appendChild(cell);

						// add input box to second column
						cell = document.createElement('td');
						cell.style.paddingRight = '1em';
						input = document.createElement('select');
						input.setAttribute;
						input.setAttribute;
						$.each(pref.enumValues, function {
							var option = document.createElement('option');
							option.setAttribute;
							if (Twinkle.getPref(pref.name) === enumvalue) {
								option.setAttribute;
							option.appendChild(document.createTextNode(enumdisplay));
							input.appendChild(option);
						cell.appendChild(input);
						break;

					case 'set': // create a set of check boxes
						// add label first of all
						cell.setAttribute;
						label = document.createElement('label'); // not really necessary to use a label element here, but we do it for consistency of styling
						label.appendChild(document.createTextNode(pref.label + ':'));
						cell.appendChild(label);

						var checkdiv = document.createElement('div');
						checkdiv.style.paddingLeft = '1em';
						var worker = function {
							var checklabel = document.createElement('label');
							checklabel.style.marginRight = '0.7em';
							checklabel.style.display = 'inline-block';
							var check = document.createElement('input');
							check.setAttribute;
							check.setAttribute;
							check.setAttribute;
							if (Twinkle.getPref(pref.name) && Twinkle.getPref(pref.name).indexOf(itemkey) !== -1) {
								check.setAttribute;
							// cater for legacy integer array values for unlinkNamespaces (this can be removed a few years down the track...)
							if (pref.name === 'unlinkNamespaces') {
								if (Twinkle.getPref(pref.name) && Twinkle.getPref(pref.name).indexOf(parseInt) !== -1) {
									check.setAttribute;
							checklabel.appendChild(check);
							checklabel.appendChild(document.createTextNode(itemvalue));
							checkdiv.appendChild(checklabel);
						if (pref.setDisplayOrder) {
							// add check boxes according to the given display order
							$.each(pref.setDisplayOrder, function {
								worker;
							// add check boxes according to the order it gets fed to us (probably strict alphabetical)
							$.each;
						cell.appendChild(checkdiv);
						break;

					case 'customList':
						// add label to first column
						cell.style.textAlign = 'right';
						cell.style.paddingRight = '0.5em';
						label = document.createElement('label');
						label.setAttribute;
						label.appendChild(document.createTextNode(pref.label + ':'));
						cell.appendChild(label);
						row.appendChild(cell);

						// add button to second column
						cell = document.createElement('td');
						cell.style.paddingRight = '1em';
						var button = document.createElement('button');
						button.setAttribute;
						button.setAttribute;
						button.setAttribute;
						button.addEventListener;
						// use jQuery data on the button to store the current config value
						$(button).data({
							value: Twinkle.getPref(pref.name),
							pref: pref
						button.appendChild(document.createTextNode('Edit items'));
						cell.appendChild(button);
						break;

					default:
						alert('twinkleconfig: unknown data type for preference ' + pref.name);
						break;
				row.appendChild(cell);

				// add help tip
				cell = document.createElement('td');
				cell.style.fontSize = '90%';

				cell.style.color = 'gray';
				if (pref.helptip) {
					// convert mentions of templates in the helptip to clickable links
					cell.innerHTML = pref.helptip.replace;
				// add reset link 
				if (pref.type !== 'customList') {
					var resetlink = document.createElement('a');
					resetlink.setAttribute;
					resetlink.setAttribute;
					resetlink.addEventListener;
					resetlink.style.cssFloat = 'right';
					resetlink.style.margin = '0 0.6em';
					resetlink.appendChild(document.createTextNode('초기화'));
					cell.appendChild(resetlink);
				row.appendChild(cell);

				container.appendChild(row);
				return true;
			return true;

		var footerbox = document.createElement('div');
		footerbox.setAttribute;
		footerbox.style.backgroundColor = '#BCCADF';
		footerbox.style.padding = '0.5em';
		var button = document.createElement('button');
		button.setAttribute;
		button.setAttribute;
		button.appendChild(document.createTextNode('변경된 내용 저장'));
		footerbox.appendChild(button);
		var footerspan = document.createElement('span');
		footerspan.className = 'plainlinks';
		footerspan.style.marginLeft = '2.4em';
		footerspan.style.fontSize = '90%';
		var footera = document.createElement('a');
		footera.setAttribute;
		footera.setAttribute;
		footera.addEventListener;
		footera.appendChild(document.createTextNode('기본값 복원'));
		footerspan.appendChild(footera);
		footerbox.appendChild(footerspan);
		contentform.appendChild(footerbox);

		// since all the section headers exist now, we can try going to the requested anchor
		if (location.hash) {
			window.location.hash = location.hash;

			mw.config.get('wgTitle').indexOf(mw.config.get('wgUserName')) === 0 &&
			mw.config.get('wgPageName').slice(-3) === '.js') {

		var box = document.createElement('div');
		// Styled in twinkle.css
		box.setAttribute;

		var link,
			scriptPageName = mw.config.get('wgPageName').slice(mw.config.get('wgPageName').lastIndexOf('/') + 1,
				mw.config.get('wgPageName').lastIndexOf('.js'));

		if (scriptPageName === 'twinkleoptions') {
			// place "why not try the preference panel" notice
			box.setAttribute;

			if (mw.config.get('wgArticleId') > 0) { // page exists
				box.appendChild(document.createTextNode('This page contains your Twinkle preferences. You can change them using the '));
				box.appendChild(document.createTextNode('You can customize Twinkle to suit your preferences by using the '));
			link = document.createElement('a');
			link.setAttribute('href', mw.util.getUrl(mw.config.get('wgFormattedNamespaces')[mw.config.get('wgNamespaceIds').project] + ':Twinkle/Preferences'));
			link.appendChild(document.createTextNode('Twinkle preferences panel'));
			box.appendChild(link);
			box.appendChild(document.createTextNode);
			$(box).insertAfter($('#contentSub'));

			// place "Looking for Twinkle options?" notice
			box.setAttribute;

			box.appendChild(document.createTextNode);
			link = document.createElement('a');
			link.setAttribute('href', mw.util.getUrl(mw.config.get('wgFormattedNamespaces')[mw.config.get('wgNamespaceIds').project] + ':도구/트윙클/환경 설정'));
			link.appendChild(document.createTextNode('트윙클 환경 설정 패널'));
			box.appendChild(link);;
			box.appendChild(document.createTextNode('을 이용할 수 있습니다.'));
			$(box).insertAfter($('#contentSub'));

// custom list-related stuff

Twinkle.config.listDialog = {};

Twinkle.config.listDialog.addRow = function twinkleconfigListDialogAddRow {
	var contenttr = document.createElement('tr');
	// "remove" button
	var contenttd = document.createElement('td');
	var removeButton = document.createElement('button');
	removeButton.setAttribute;
	removeButton.addEventListener('click', function {
		$(contenttr).remove;
	removeButton.textContent = '제거';
	contenttd.appendChild(removeButton);
	contenttr.appendChild(contenttd);

	// value input box
	contenttd = document.createElement('td');
	var input = document.createElement('input');
	input.setAttribute;
	input.className = 'twinkle-config-customlist-value';
	input.style.width = '97%';
	if (value) {
		input.setAttribute;
	contenttd.appendChild(input);
	contenttr.appendChild(contenttd);

	// label input box
	contenttd = document.createElement('td');
	input = document.createElement('input');
	input.setAttribute;
	input.className = 'twinkle-config-customlist-label';
	input.style.width = '98%';
	if (label) {
		input.setAttribute;
	contenttd.appendChild(input);
	contenttr.appendChild(contenttd);

	dlgtable.appendChild(contenttr);

Twinkle.config.listDialog.display = function twinkleconfigListDialogDisplay(e) {
	var $prefbutton = $(e.target);
	var curvalue = $prefbutton.data('value');
	var curpref = $prefbutton.data('pref');

	var dialog = new Morebits.simpleWindow;
	dialog.setTitle(curpref.label);
	dialog.setScriptName('Twinkle preferences');

	var dialogcontent = document.createElement('div');
	var dlgtable = document.createElement('table');
	dlgtable.className = 'wikitable';
	dlgtable.style.margin = '1.4em 1em';
	dlgtable.style.width = 'auto';

	var dlgtbody = document.createElement('tbody');

	// header row
	var dlgtr = document.createElement('tr');
	// top-left cell
	var dlgth = document.createElement('th');
	dlgth.style.width = '5%';
	dlgtr.appendChild(dlgth);
	// value column header
	dlgth = document.createElement('th');
	dlgth.style.width = '35%';
	dlgth.textContent = curpref.customListValueTitle ? curpref.customListValueTitle : 'Value';
	dlgtr.appendChild(dlgth);
	// label column header
	dlgth = document.createElement('th');
	dlgth.style.width = '60%';
	dlgth.textContent = curpref.customListLabelTitle ? curpref.customListLabelTitle : 'Label';
	dlgtr.appendChild(dlgth);
	dlgtbody.appendChild(dlgtr);

	// content rows
	var gotRow = false;
	$.each(curvalue, function {
		gotRow = true;
		Twinkle.config.listDialog.addRow;
	// if there are no values present, add a blank row to start the user off
	if (!gotRow) {
		Twinkle.config.listDialog.addRow(dlgtbody);

	// final "add" button
	var dlgtfoot = document.createElement('tfoot');
	dlgtr = document.createElement('tr');
	var dlgtd = document.createElement('td');
	dlgtd.setAttribute;
	var addButton = document.createElement('button');
	addButton.style.minWidth = '8em';
	addButton.setAttribute;
	addButton.addEventListener('click', function {
		Twinkle.config.listDialog.addRow(dlgtbody);
	addButton.textContent = '추가';
	dlgtd.appendChild(addButton);
	dlgtr.appendChild(dlgtd);
	dlgtfoot.appendChild(dlgtr);

	dlgtable.appendChild(dlgtbody);
	dlgtable.appendChild(dlgtfoot);
	dialogcontent.appendChild(dlgtable);

	// buttonpane buttons: [Save changes] [Reset] [Cancel]
	var button = document.createElement('button');
	button.setAttribute; // so Morebits.simpleWindow puts the button in the button pane
	button.addEventListener('click', function {
		Twinkle.config.listDialog.save;
		dialog.close;
	button.textContent = '변경사항 저장';
	dialogcontent.appendChild(button);
	button = document.createElement('button');
	button.setAttribute; // so Morebits.simpleWindow puts the button in the button pane
	button.addEventListener('click', function {
		Twinkle.config.listDialog.reset;
	button.textContent = '초기화';
	dialogcontent.appendChild(button);
	button = document.createElement('button');
	button.setAttribute; // so Morebits.simpleWindow puts the button in the button pane
	button.addEventListener('click', function {
		dialog.close; // the event parameter on this function seems to be broken
	button.textContent = '취소';
	dialogcontent.appendChild(button);

	dialog.setContent(dialogcontent);
	dialog.display;

// Resets the data value, re-populates based on the new (default) value, then saves the
// old data value again (less surprising behaviour)
Twinkle.config.listDialog.reset = function twinkleconfigListDialogReset {
	// reset value on button
	var $button = $(button);
	var curpref = $button.data('pref');
	var oldvalue = $button.data('value');
	Twinkle.config.resetPref(curpref);

	// reset form
	var $tbody = $(tbody);
	$tbody.find('tr').slice(1).remove; // all rows except the first (header) row
	// add the new values
	var curvalue = $button.data('value');
	$.each(curvalue, function {
		Twinkle.config.listDialog.addRow;

	// save the old value
	$button.data;

Twinkle.config.listDialog.save = function twinkleconfigListDialogSave {
	var result = [];
	var current = {};
	$(tbody).find('input[type="text"]').each(function {
		if ($(input).hasClass('twinkle-config-customlist-value')) {
			current = { value: input.value };
			current.label = input.value;
			// exclude totally empty rows
			if (current.value || current.label) {
				result.push(current);
	$(button).data;

// reset/restore defaults

Twinkle.config.resetPrefLink = function twinkleconfigResetPrefLink(e) {
	var wantedpref = e.target.id.substring(21); // "twinkle-config-reset-" prefix is stripped

	// search tactics
	$(Twinkle.config.sections).each(function {
		if (section.hidden || (section.adminOnly && !Morebits.userIsSysop)) {
			return true; // continue: skip impossibilities

		var foundit = false;

		$(section.preferences).each(function {
			if (pref.name !== wantedpref) {
				return true; // continue
			Twinkle.config.resetPref(pref);
			foundit = true;
			return false; // break

		if (foundit) {
			return false; // break
	return false; // stop link from scrolling page

Twinkle.config.resetPref = function twinkleconfigResetPref(pref) {
	switch (pref.type) {

		case 'boolean':
			document.getElementById(pref.name).checked = Twinkle.defaultConfig[pref.name];
			break;

		case 'string':
		case 'integer':
		case 'enum':
			document.getElementById(pref.name).value = Twinkle.defaultConfig[pref.name];
			break;

		case 'set':
			$.each(pref.setValues, function(itemkey) {
				if (document.getElementById(pref.name + '_' + itemkey)) {
					document.getElementById(pref.name + '_' + itemkey).checked = Twinkle.defaultConfig[pref.name].indexOf(itemkey) !== -1;
			break;

		case 'customList':
			$(document.getElementById(pref.name)).data;
			break;

		default:
			alert('twinkleconfig: unknown data type for preference ' + pref.name);
			break;

Twinkle.config.resetAllPrefs = function twinkleconfigResetAllPrefs {
	// no confirmation message - the user can just refresh/close the page to abort
	$(Twinkle.config.sections).each(function {
		if (section.hidden || (section.adminOnly && !Morebits.userIsSysop)) {
			return true; // continue: skip impossibilities
		$(section.preferences).each(function {
			if (!pref.adminOnly || Morebits.userIsSysop) {
				Twinkle.config.resetPref(pref);
		return true;
	return false; // stop link from scrolling page

Twinkle.config.save = function twinkleconfigSave(e) {
	Morebits.status.init(document.getElementById('twinkle-config-content'));

	var userjs = mw.config.get('wgFormattedNamespaces')[mw.config.get('wgNamespaceIds').user] + ':' + mw.config.get('wgUserName') + '/twinkleoptions.js';
	var wikipedia_page = new Morebits.wiki.page;
	wikipedia_page.setCallbackParameters(e.target);
	wikipedia_page.load(Twinkle.config.writePrefs);

	return false;

Twinkle.config.writePrefs = function twinkleconfigWritePrefs(pageobj) {
	var form = pageobj.getCallbackParameters;

	// this is the object which gets serialized into JSON; only
	// preferences that this script knows about are kept
	var newConfig = {optionsVersion: 2};

	// a comparison function is needed later on
	// it is just enough for our purposes 
	// and it is not very robust: e.g. compare === true, and
	// compare === false, but it's good enough for our purposes here
	var compare = function {
		if (Array.isArray(a)) {
			if (a.length !== b.length) {
				return false;
			var asort = a.sort, bsort = b.sort;
			for (var i = 0; asort[i]; ++i) {
				// comparison of the two properties of custom lists
				if ((typeof asort[i] === 'object') && (asort[i].label !== bsort[i].label ||
					asort[i].value !== bsort[i].value)) {
					return false;
					return false;
			return true;
		return a === b;

	$(Twinkle.config.sections).each(function {
		if (section.adminOnly && !Morebits.userIsSysop) {
			return; // i.e. "continue" in this context

		// reach each of the preferences from the form
		$(section.preferences).each(function {
			var userValue; // = undefined

			// only read form values for those prefs that have them
			if (!pref.adminOnly || Morebits.userIsSysop) {
				if (!section.hidden) {
					switch (pref.type) {
						case 'boolean': // read from the checkbox
							userValue = form[pref.name].checked;
							break;

						case 'string': // read from the input box or combo box
						case 'enum':
							userValue = form[pref.name].value;
							break;

						case 'integer': // read from the input box
							userValue = parseInt;
							if (isNaN(userValue)) {
								Morebits.status.warn('Saving', 'The value you specified for ' + pref.name + ' (' + pref.value + ') was invalid. The save will continue, but the invalid data value will be skipped.');
								userValue = null;
							break;

						case 'set': // read from the set of check boxes
							userValue = [];
							if (pref.setDisplayOrder) {
							// read only those keys specified in the display order
								$.each(pref.setDisplayOrder, function {
									if (form[pref.name + '_' + item].checked) {
										userValue.push(item);
							// read all the keys in the list of values
								$.each(pref.setValues, function(itemkey) {
									if (form[pref.name + '_' + itemkey].checked) {
										userValue.push(itemkey);
							break;

						case 'customList': // read from the jQuery data stored on the button object
							userValue = $(form[pref.name]).data('value');
							break;

						default:
							alert('twinkleconfig: unknown data type for preference ' + pref.name);
							break;
					// Retain the hidden preferences that may have customised by the user from twinkleoptions.js
					// undefined if not set
					userValue = Twinkle.prefs[pref.name];

			// only save those preferences that are *different* from the default
			if (userValue !== undefined && !compare) {
				newConfig[pref.name] = userValue;

	var text =
		'// twinkleoptions.js: 개인 트윙클 환경 설정 파일\n' +
		'//\n' +
		'// 참고: 이 설정을 바꾸는 편리한 방법은\n' +
		'// ' + Morebits.pageNameNorm + '을 이용하는 것입니다.\n' +
		'//\n' +
		'// 이 문서는 자동으로 생성 및 수정됩니다.\n' +
		'// 트윙클 환경 설정 패널에서 "저장"을 누르면\n' +
		'// 이전에 있던 내용이 덮어씌워지게 됩니다.\n' +
		'// 이 문서를 직접 수정하고자 하는 경우\n' +
		'// 올바른 자바스크립트 문법을 사용해 주세요.\n' +
		'// \n' +
		'// twinkleoptions.js 끝\n';

	pageobj.setPageText(text);
	pageobj.setEditSummary('트윙클 환경 설정 저장: :' + Morebits.pageNameNorm + '에 의해 자동으로 편집됨 (TW)');
	pageobj.setCreateOption('recreate');
	pageobj.save(Twinkle.config.saveSuccess);

Twinkle.config.saveSuccess = function twinkleconfigSaveSuccess(pageobj) {
	pageobj.getStatusElement.info('successful');

	var noticebox = document.createElement('div');
	noticebox.className = 'successbox';
	noticebox.style.fontSize = '100%';
	noticebox.style.marginTop = '2em';
	noticebox.innerHTML = '';
	Morebits.status.root.appendChild(noticebox);
	var noticeclear = document.createElement('br');
	noticeclear.style.clear = 'both';
	Morebits.status.root.appendChild(noticeclear);

Twinkle.addInitCallback(Twinkle.config.init);