Qeyd: Dəyişiklikləri yayımladıqdan sonra etdiyiniz dəyişikliklərin görünməsi üçün brauzerinizin keşinin təmizlənməsi lazım ola bilər.

  • Firefox / Safari: Reload düyməsinə basılı tutarkən Shift düyməsinə basın, və ya Ctrl+F5 və ya Ctrl+R (Mac üçün ⌘-R )
  • Google Chrome: Ctrl-Shift-R (Mac üçün ⌘-Shift-R)
  • Edge: Ctrl düyməsini basılı tutarkən Refresh düyməsinə basın, və ya sadəcə Ctrl+F5.
// See the docs at https://meta.wikimedia.org/wiki/User:Jack_who_built_the_house/Code_Prettifier
// <nowiki>
(function () {

var pageIsProbablyTemplate = [2, 10].includes(mw.config.get('wgNamespaceNumber'));

function alignTemplateParameters(settings) {
	settings = settings || {};
	var askOptions = settings.askOptions;
	var hardMode = settings.hardMode;
	var templateExpanderMode = settings.templateExpanderMode;
	var codeStylerMode = settings.codeStylerMode;

	var txt = '';
	var hidden = [];
	var $textbox = $('#wpTextbox1');
	var $CodeMirrorVscrollbar = $('.CodeMirror-vscrollbar');
	var winScroll = document.documentElement.scrollTop;
	var i;
	var selectionMode = false;
	
	if (typeof cpMaxWidth === 'undefined') window.cpMaxWidth = 30;
	if (typeof cpPreserveBasicSpacing === 'undefined') window.cpPreserveBasicSpacing = true;
	if (typeof cpPreserveParameterSpacing === 'undefined') window.cpPreserveParameterSpacing = true;
	if (typeof cpStandardExternalLeftSpacing === 'undefined') window.cpStandardExternalLeftSpacing = 0;
	if (typeof cpStandardInternalLeftSpacing === 'undefined') window.cpStandardInternalLeftSpacing = 1;
	if (typeof cpParserFunctionExternalLeftSpacing === 'undefined') window.cpParserFunctionExternalLeftSpacing = 0;
	if (typeof cpParserFunctionInternalLeftSpacing === 'undefined') window.cpParserFunctionInternalLeftSpacing = 1;
	if (typeof cpAutoSummary === 'undefined') window.cpAutoSummary = true;
	
	if (cpParserFunctionExternalLeftSpacing > 1) cpParserFunctionExternalLeftSpacing = 1;
	if (cpParserFunctionInternalLeftSpacing > 1) cpParserFunctionInternalLeftSpacing = 1;
	if (cpStandardExternalLeftSpacing > 1) cpStandardExternalLeftSpacing = 1;
	if (cpStandardInternalLeftSpacing > 1) cpStandardInternalLeftSpacing = 1;
	
	function isMultiline(s) {
		return s.includes('\n');
	}

	function r(r1, r2) {
		txt = txt.replace(r1, r2);
	}

	function hide(re) {
		r(re, function (s) {
			return '\x01' + (isMultiline(s) ? '_' : '') + hidden.push(s) + '\x02';
		});
	}
	
	function hideTag(tag) {
		hide(new RegExp('<' + tag + '( [^>]+)?>[\\s\\S]+?<\\/' + tag + '>', 'gi'));
	}
	
	function prettifyTemplates() {
		function prettifyTemplate() {
			function localR(r1, r2) {
				newTpl = newTpl.replace(r1, r2);
			}

			function localHide(re) {
				localR(re, function (s) {
					return '\x03' + localHidden.push(s) + '\x04';
				});
			}
			
			function localUnhide() {
				while (newTpl.match(/\x03\d+\x04/)) {
					newTpl = newTpl.replace(/\x03(\d+)\x04/g, function (s, num) {
						return localHidden[num - 1];
					});
				}
			}
			
			function isNamed(param) {
				return param.includes('=');
			}
			
			function removeEndingNewlines(s) {
				return s.replace(/\n+([ \t]*)$/, '');
			}
			
			function generateSpaces(num) {
				return ' '.repeat(Math.max(0, num));
			}
			
			function lcFirst(s) {
				if (!s) return s;
				return s[0].toLowerCase() + s.substr(1);
			}

			function calculateOneValueDominance(arr) {
				var spread = arr.reduce((obj, item) => {
					obj[item] = (obj[item] || 0) + 1;
					return obj;
				}, {});
				var topValueCount = Object.entries(spread)
					.map(([, value]) => value)
					.sort((a, b) => b - a)[0];
				return topValueCount / arr.length;
			}
			
			
			var newTpl = tpl;
			var multiline = isMultiline(newTpl);
			newTpl = newTpl.replace(/^\{\{\s+(?!\x01)/, '{{');

			// For example, {{fullurl:...|action=edit}}
			if (!newTpl.match(/\{\{[a-zA-Z][^\|]*:/)) {
				newTpl = newTpl.replace(/^([^\|]+?)\s+\}\}$/, '$1}}');
			}
			
			if (!multiline && !cpCodeStyler && !cpTemplateExpander) return newTpl;
			
			var re, m, m2, tplName, start;
			var isParserFunction = false;
			
			var anythingBeforeTplName = '(\\x01\\d+\\x02|(?:<includeonly>)?(?:safe)?subst:(?:<\\/includeonly>|<(?:includeonly|noinclude) ?\\/>))?';
			re = new RegExp('^\\{\\{' + anythingBeforeTplName + '(#\\w*)?:[ \\t]*(?=(\\n?))');
			m = newTpl.match(re);
			tplName = m && m[2];
			if (tplName) {
				isParserFunction = true;
				if (codeStylerMode && tplName !== '#invoke') {
					newTpl = newTpl.replace(re, '{{' + (m[1] || '') + tplName + ':' + (m[3] ? '' : ' '));
				}
			} else {
				if (!multiline && !cpTemplateExpander) {
					return newTpl;
				}
				m = newTpl.match(/^\{\{([^|}\n]+)/);
				tplName = m && m[1].trim();
			}
			
			var localHidden = [];
			var params;
			if (isParserFunction && cpCodeStyler && codeStylerMode) {
				localHide(/\[\[[^\]]+\]\]/g);  // [[Вики-ссылки]]
				
				params = newTpl.split('|');
				params[0] = params[0].replace(/^\{\{/, '');
				params[params.length - 1] = params[params.length - 1].replace(/\}\}$/, '');
				
				// Unsafe to space out parameters when there are unnamed ones.
				var safeToSpace = false;
				var unnamedCount = 0;
				if (tplName === '#invoke' && codeStylerMode === 'newlines') {
					safeToSpace = true;
					for (i = 2; i < params.length; i++) {
						if (!isNamed(params[i])) {
							safeToSpace = false;
							break;
						}
					}
				}

				// Make #if, #ifexpr, #ifeq, #ifexist, #iferror multiline only if both arguments are non-empty, or if
				// it contains nested templates / parser functions
				var makeIfMultiline = codeStylerMode === 'newlines' &&
					(tplName.substr(0, 3) === '#if' &&
						params[1] !== undefined &&
						(isMultiline(params[1]) ||
							tplName === '#ifeq' ||
							(params[2] !== undefined &&
								isMultiline(params[2])
							) ||
							((params[1].trim() !== '' &&
								params[2] !== undefined &&
								params[2].trim() !== ''
							) ||
								params[1].includes('\x01_') ||
								(params[2] !== undefined &&
									params[2].includes('\x01_')
								)
							)
						)
					);
				
				var isMultipleAlternativesSwitch = false;
				var isOneOfSwitchAlternatives;

				// FIXME: this should be refactored, of course. Above, apparently, safeToSpace must be able
				// to become true not only when `codeStylerMode === 'newlines'`.
				if (params.length > 1) {
					for (i = 1; i < params.length; i++) {
						// FIXME: bizarre, yes, that previous parameter is analyzed, but that's connected to the
						// logic below.
						if (tplName === '#switch' && i - 1 !== 0 && !params[i - 1].includes('=')) {
							isMultipleAlternativesSwitch = true;
							isOneOfSwitchAlternatives = true;
						} else {
							isOneOfSwitchAlternatives = false;
						}
						if (tplName === '#switch' ||
							(tplName === '#invoke' &&
								(safeToSpace ||
									params[i].match(/\n[ \t]*$/) &&
									params[i - 1].match(/\n[ \t]*$/)
								)
							)
						) {
							params[i] = params[i].replace(/([ \t]*)=[ \t]*/, function (s, m1) {
								var sp;
								if (tplName === '#invoke' &&
									codeStylerMode === 'newlines' &&
									!isMultipleAlternativesSwitch
								) {
									sp = generateSpaces(i);
								} else if (m1.length < 1 ||
									codeStylerMode === 'newlines-collapse' ||
									!(params[i].match(/\n[ \t]*$/) &&
										params[i - 1].match(/\n[ \t]*$/)
									) ||
									isMultipleAlternativesSwitch
								) {
									sp = ' ';
								} else {
									sp = m1;
								}
								return sp + '= ';
							});
						} else if (tplName === '#invoke') {
							params[i] = params[i]
								.replace(/[ \t]+=/, ' =')
								.replace(/=[ \t]+/, '= ');
						}
						if (codeStylerMode === 'newlines-collapse' && !(tplName === '#invoke' && !multiline)) {
							params[i - 1] = params[i - 1].replace(/\s*$/, ' ');
							// {{#if: smth |\nsmth\n}}
							params[i] = params[i].replace(/^[ \t]*(?=(\n)?)/, function (s, m1) {
								return m1 ? '' : ' ';
							});
							if (i === params.length - 1) {
								params[i] = params[i].replace(/\s*$/, ' ');
							}
						} else if (!isMultiline(params[i - 1]) ||
							params[i - 1].match(/\S[ \t]*$/) ||
							(tplName === '#switch' && isOneOfSwitchAlternatives)
						) {
							if (codeStylerMode === 'newlines' &&
								((tplName.substr(0, 3) === '#if' && makeIfMultiline) ||
									(tplName === '#switch' && !isOneOfSwitchAlternatives) ||
									(tplName === '#invoke' && safeToSpace && i !== 1)
								)
							) {
								params[i - 1] = params[i - 1].replace(/[ \t]*$/, '\n');
								multiline = true;
							} else if (tplName === '#switch' && isOneOfSwitchAlternatives) {
								params[i - 1] = ' ' + params[i - 1].trim() + ' ';
							} else {
								if (!(tplName === '#invoke' && !safeToSpace)) {
									params[i - 1] = params[i - 1].replace(/[ \t]*$/, ' ');
								} else if (isNamed(params[i - 1]) || i - 1 <= 1) {
									params[i - 1] = params[i - 1].replace(/[ \t]+$/, ' ');
								}
							}
							if (!(tplName === '#invoke' && !safeToSpace)) {
								// {{#if: smth |\nsmth\n}}
								params[i] = params[i].replace(/^[ \t]*(?=(\n)?)/, function (s, m1) {
									return m1 ? '' : ' ';
								});
							} else if (isNamed(params[i]) || i === 1) {
								params[i] = params[i].replace(/^[ \t]+/, ' ');
							}
							if (i === params.length - 1) {
								if (!(tplName === '#invoke' && !safeToSpace)) {
									params[i] = params[i].replace(/(\S)[ \t]*$/, '$1 ');
								} else if (isNamed(params[i])) {
									params[i] = params[i].replace(/(\S)[ \t]+$/, '$1 ');
								}
							}
						}
					}
				} else {
					params[0] = params[0].replace(/\s*$/, ' ');
				}
				if (tplName === '#expr' || tplName === '#ifexpr') {
					params[0] = params[0]
						// Don't touch cases like `+30 * -7`
						.replace(/: /, ':')
						.replace(/[ \t]*(\+|-|\*|\/|\^|<>|!=|>=|<=|>|<|=)[ \t]*/g, ' $1 ')
						.replace(/([+\-*/^=<>:])[ \t]*(\+|-) /g, '$1 $2')
						.replace(/:[ \t]*/, ': ');
				}
				newTpl = '{{' + params.join('|') + '}}';
				
				if (params.length > 1) {
					if (tplName !== '#invoke') {
						newTpl = newTpl.replace(/\|[ \t]\}\}/, '}}');
					}
					if (tplName === '#invoke' && (safeToSpace || codeStylerMode === 'newlines-collapse')) {
						newTpl = newTpl.replace(
							new RegExp('^\\{\\{' + anythingBeforeTplName + '#invoke:[ \\t]*'),
							'{{$1#invoke: '
						);
					} else {
						newTpl = newTpl.replace(
							new RegExp('^\\{\\{' + anythingBeforeTplName + '#invoke:[ \\t]+'),
							'{{$1#invoke: '
						);
					}
					if (tplName !== '#switch') {
						newTpl = newTpl.replace(/\|  ?\|/g, '||');
					}
				}
				
				localUnhide();
				//console.log(newTpl);
				if (!multiline) {
					return newTpl;
				}
			}
			
			if (!isParserFunction && cpTemplateExpander && templateExpanderMode) {
				localHide(/\[\[[^\]]+\]\]/g);  // [[Вики-ссылки]]
				
				params = newTpl.split('|');
				params[0] = params[0].replace(/^\{\{/, '');
				params[params.length - 1] = params[params.length - 1].replace(/\}\}$/, '');
				
				var namedCount = 0;
				var unnamedCount = 0;
				var hasCollapsed = false;
				var isFullyCollapsible = true;
				for (i = 1; i < params.length; i++) {
					if (isNamed(params[i])) {
						namedCount++;
						if (!isMultiline(params[i - 1])) {
							hasCollapsed = true;
						}
					} else {
						unnamedCount++;
					}
					if ((isNamed(params[i]) &&
							isMultiline(params[i].trim())
						) ||
						(!isNamed(params[i]) &&
							isMultiline(params[i]) &&
							params[i + 1] &&
							!isNamed(params[i + 1]) &&
							isMultiline(params[i + 1])
						)
					) {
						// Is it OK to collapse the template into a one-liner
						isFullyCollapsible = false;
					}
				}
				
				if (namedCount > 1 && !(templateExpanderMode === 'expand' && !hasCollapsed)) {
					if (templateExpanderMode === 'expand') {
						for (i = 0; i < params.length; i++) {
							if (i === 0) {
								params[i] = params[i].replace(/\s*$/, '');
							}
							if ((params[i + 1] &&
									isNamed(params[i + 1])
								) ||
								(i === 0 &&
									(params[i + 1] &&
										params[i + 2] &&
										!isNamed(params[i + 1]) &&
										!isNamed(params[i + 2]) &&
										isMultiline(params[i + 1])
									)
								) ||
								(i !== 0 &&
									(isNamed(params[i]) ||
										lcFirst(tplName) === 'публикация'
									)
								)
							) {
								if (isNamed(params[i]) || lcFirst(tplName) === 'публикация') {
									params[i] = params[i].replace(/\s*$/, '');
								} else {
									params[i] = removeEndingNewlines(params[i]);
								}
								params[i] = params[i] + '\n' + generateSpaces(stack.length * 2 + selectionSpacing) +
									' ';
								if (unnamedCount <= 1 && params[i + 1] && isNamed(params[i + 1])) {
									params[i + 1] = ' ' + params[i + 1].trim();
								}
								if (i !== 0) {
									// For subsequent alignment
									params[i] = params[i].replace('=', generateSpaces(i) + '=');
								}
							}
						}
						hasCollapsed = false;
					} else if (templateExpanderMode === 'collapse') {
						for (i = 0; i < params.length; i++) {
							if (i === 0 ||
								isNamed(params[i]) ||
								(params[i + 1] &&
									(isNamed(params[i + 1]) ||
										!isMultiline(params[i + 1])
									)
								) ||
								(i === params.length - 1 &&
									isFullyCollapsible
								)
							) {
								if (i === 0 || isNamed(params[i])) {
									if (isFullyCollapsible ||
										(i !== params.length - 1 &&
											!(params[i + 1] &&
												!isNamed(params[i + 1]) &&
												isMultiline(params[i + 1]) &&
												params[i + 2] &&
												!isNamed(params[i + 2]) &&
												isMultiline(params[i + 2])
											)
										)
									) {
										params[i] = params[i].trim();
									} else {
										params[i] = params[i]
											.replace(/^\s*/, '')
											.replace(/\s*?(\n*)$/, '$1');
									}
								} else if (i !== 0 && !isNamed(params[i]) && isMultiline(params[i]) &&
									(isFullyCollapsible ||
										params[i + 1] &&
										(isNamed(params[i + 1]) ||
											!isMultiline(params[i + 1])
										) &&
										(i === 1 ||
											isNamed(params[i - 1]) ||
											!isMultiline(params[i - 1])
										)
									)
								) {
									// Sometimes unnamed parameters are stretched out into a stack
									params[i] = removeEndingNewlines(params[i]);
								}
							}
							if (i !== 0) {
								params[i] = params[i].replace(/[ \t]*=[ \t]*/, '=');
							}
							if (!pageIsProbablyTemplate &&
								(!unnamedCount &&
									isNamed(params[Math.max(1, i)]) ||
									(lcFirst(tplName) === 'публикация')
								)  // && i !== params.length - 1
							) {
								params[i] = params[i].replace(/ *$/, ' ');
							}
						}
						hasCollapsed = true;
					}
					
					newTpl = '{{' + params.join('|') + '}}';
				}
				
				localUnhide();
				//console.log(newTpl);
				if (hasCollapsed) {
					return newTpl;
				}
			}
			
			m = newTpl.match(/^(\{\{[\s\S]*?\n\s*)(\||\}\})/);
			if (!m) return newTpl;
			
			start = m[1];
			if (!templateExpanderMode) {
				start = start.trim();
			} else {
				start = removeEndingNewlines(start);
			}
			
			var indentSpaces = ' '.repeat(basicLevel);
			if (!refTagBefore) {
				// Insert a number of spaces depending on the level of nesting
				if (isParserFunction) {
					indentSpaces += generateSpaces(stack.length);  // Character "|"
					indentSpaces += generateSpaces(stack.length * cpParserFunctionExternalLeftSpacing);
					indentSpaces += generateSpaces(stack.length * cpParserFunctionInternalLeftSpacing);
				} else {
					indentSpaces += generateSpaces(stack.length * 2);
				}
				indentSpaces += generateSpaces(selectionSpacing);
			}
			
			var noEndingBrackets = false;
			if (!newTpl.includes('}}', newTpl.length - 2)) {
				newTpl += '}}';
				noEndingBrackets = true;
			}
			
			if (tplName === '#switch') {
				// For correct alignment of `=` in `| a | b | c = value`
				re = /\n([ \t]*)\|([ \t]*)(?:([^=\n]+?)([ \t]*)=([ \t]*))?([\s\S]*?)(?=(\n[ \t]*\||\}\}))/g;
			} else {
				re = /\n([ \t]*)\|([ \t]*)(?:([^=|\n]+?)([ \t]*)=([ \t]*))?([\s\S]*?)(?=(\n[ \t]*\||\}\}))/g;
			}
			params = [];
			var longestParameterLength = 0;
			var standardWidth = 0;
			var length;
			var basicExternalLeftSpacing;
			var basicInternalLeftSpacing;
			var oneSpaceCount = 0;
			var zeroSpacesCount = 0;
			var paramLeftLengths = [];
			var namedParametersCount = 0;
			i = 0;
			while ((m = re.exec(newTpl))) {
				i++;
				if (i === 1) {
					basicExternalLeftSpacing = isParserFunction
						? generateSpaces(indentSpaces.length + cpParserFunctionExternalLeftSpacing)
						: m[1];
					basicInternalLeftSpacing = isParserFunction
						? generateSpaces(cpParserFunctionInternalLeftSpacing)
						: m[2];
				}
				if (thisPreserveBasicSpacing) {
					/*
						This code ensures that:
							1) the outer left padding will not be multiplied in nested templates,
							2) there will be no lines with a smaller outer left padding than the first line,
							3) there will be no outer left padding of more than one space out of the blue.
					*/
					if (i === 1) {
						m[1] = '';
					} else {
						// Cases when the parameters are spaced out relative to the base level by editors on
						// purpose. But all parser function arguments have the same indentation.
						if (isParserFunction || !thisPreserveParameterSpacing) {
							m[1] = '';
						} else if (thisPreserveParameterSpacing) {
							m[1] = generateSpaces(m[1].length - basicExternalLeftSpacing.length);
						}
					}
					if (basicExternalLeftSpacing.length > indentSpaces.length) {
						m[1] += ' ';
					}
				} else {
					if (isParserFunction) {
						m[1] = '';
						// FIXME: bizarre that the standard padding of parser functions is formed via
						// `basicExternalLeftSpacing` and not directly via
						// `cpParserFunctionExternalLeftSpacing` (also above).
						if (basicExternalLeftSpacing.length > indentSpaces.length) {
							m[1] += ' ';
						}
					} else if (thisPreserveParameterSpacing) {
						m[1] = generateSpaces(
							cpStandardExternalLeftSpacing + m[1].length - basicExternalLeftSpacing.length
						);
					} else {
						m[1] = generateSpaces(cpStandardExternalLeftSpacing);
					}
				}
				
				if (thisPreserveBasicSpacing) {
					// The same for the inner left padding
					if (i === 1) {
						m[2] = '';
					} else {
						if (isParserFunction || !thisPreserveParameterSpacing) {
							m[2] = '';
						} else if (thisPreserveParameterSpacing) {
							m[2] = generateSpaces(m[2].length - basicInternalLeftSpacing.length);
						}
					}
					if (basicInternalLeftSpacing.length > 0) {
						m[2] += ' ';
					}
				} else {
					if (thisPreserveParameterSpacing) {
						m[2] = generateSpaces(
							cpStandardInternalLeftSpacing + m[2].length - basicInternalLeftSpacing.length
						);
					} else {
						m[2] = generateSpaces(cpStandardInternalLeftSpacing);
					}
				}
				
				if (!hardMode || codeStylerMode || templateExpanderMode) {
					paramLeftLengths.push((m[1] + m[2] + m[3] + m[4]).length);
					if (m[4] === ' ') {
						oneSpaceCount++;
					}
					if (m[4] === '' && m[5] === '') {
						zeroSpacesCount++;
					}
				}
				
				if (m[3] !== undefined) {
					length = m[1].length + m[2].length + m[3].length;
					if (length > longestParameterLength) {
						longestParameterLength = length;
					}
					
					if (!hardMode || codeStylerMode || templateExpanderMode) {
						namedParametersCount++;
					}
				}
				
				if (m[3] === undefined && m[6].match(/^[ \t]*\n/)) {
					m[6] = m[6].replace(/^\n\s*\x01/, '\x01');
				}
				
				m[6] = m[6]
					.replace(/\n\s*\n\s*$/, '\n')  // 3+ newlines in total
					.replace(/^[ \t]+$/, '');  // Empty parameter (but can't trim if there are newlines there)
				
				if (m[3] !== undefined) {
					m[6] = m[6]
						// Trailing spaces in all terminating (space-only) lines
						.replace(/[ \t]*(\n?)[ \t]*$/, '$1')
						// A trailing space in parameters `lat_*`, `lon_*`, etc.
						.replace(/(\|.*=)(\n?)$/, '$1 $2');
				}
				
				params.push([m[1], m[2], m[3], m[6]]);
			}
			if (!params[0]) {
				return newTpl;
			}
			
			standardWidth = Math.min(thisMaxWidth, longestParameterLength);
			if (!hardMode || codeStylerMode || templateExpanderMode) {
				if (namedParametersCount !== 0 && calculateOneValueDominance(paramLeftLengths) <= 0.75) {
					if (oneSpaceCount / namedParametersCount > 0.75) {
						standardWidth = 0;
					}
					if (zeroSpacesCount / namedParametersCount > 0.75) {
						standardWidth = -1;
					}
				}
			}

			newTpl = '';
			if (isMultiline(trailingSpaceBefore)) {
				m = trailingSpaceBefore.match(/ *$/);
				var trailingNormalSpacesLength = m ? m[0].length : 0;
				if (trailingNormalSpacesLength < indentSpaces.length) {
					newTpl += generateSpaces(indentSpaces.length - trailingNormalSpacesLength);
				} else {
					newLeft -= trailingNormalSpacesLength - indentSpaces.length;
				}				
			}
			newTpl += start + '\n';
			//console.log(params);
			
			if (params.length !== 1 && params[params.length - 1][2] && params[params.length - 1][3]) {
				params[params.length - 1][3] = params[params.length - 1][3]
					.replace(/\s*$/, '')

					// Again a trailing space in parameters `lat_*`, `lon_*`, etc.
					.replace(/(\|.*=)(\n?)$/, '$1 $2');
			} else if (isParserFunction) {
				params[params.length - 1][3] = params[params.length - 1][3].replace(/\s*$/, '');
			} else {
				params[params.length - 1][3] = removeEndingNewlines(params[params.length - 1][3]);
			}
			
			var line;

			// Not all numbered params are listed: only those that are part of the main block where
			// ordered elements are located. For example, `image1` and `image2` are not listed because
			// they appear separately from the main block; they are not related to `label1` and `label2`.
			var NUMBERED_PARAMS = [
				// Infobox
				'header', 'başlıq',
				'label', 'nişan',
				'data', 'mətn',
				'class', 'sinif',
				'rowclass',
				'rowstyle',
				'rowcellstyle',
				'başlıqlar sinfi',
				'nişan sinfi',
				'mətnin sinfi',
				'başlıqlar stili',
				'nişanlar stili',
				'mətn stili',
				'vikiverilənlər',

				// Infobox3cols
				'dataa', 'datab', 'datac', 'mətn_a', 'mətn_b', 'mətn_c',
				'datastylea', 'datastyleb', 'datastylec', 'стиль_текста_а', 'стиль_текста_б', 'стиль_текста_в',
				'classa', 'classb', 'classc',
				'стиль_колонки_а', 'стиль_колонки_б', 'стиль_колонки_в',

				// Navbox
				'group', 'qrup', 'blok',
				'list', 'siyahı',
				'listclass', 'siyahıların sinfi', 'siyahı sinfi',
				'groupstyle', 'qrupların stili', 'qrupun stili',
				'liststyle', 'siyahının stili',
				'abbr', 'blokun adı',
				'col', 'колонка',
				'colheader', 'заголовок_колонки', 'заголовок колонки',
				'colfooter', 'низ_колонки', 'низ колонки',		
				'colwidth', 'ширина_колонки', 'ширина колонки',
				'colstyle', 'стиль_колонки', 'стиль колонки',
				'colheaderstyle', 'стиль_заголовка_колонки', 'стиль заголовка колонки',
				'colfooterstyle', 'стиль_низа_колонки', 'стиль низа колонки',
				'colheadercolspan', 'отступ_заголовка_колонки', 'отступ заголовка колонки',
				'colfootercolspan', 'отступ_низа_колонки', 'отступ низа колонки',

				// Sidebar
				'headingclass',
				'headingclass',
				'contentclass',
				'contentstyle',
			];
			var paramName, numberMatches, number, numberedParamCurrent, numberedParamCounter, paramNameCount,
				paramGroupDuplicatesCount, isDuplicate;
			var paramNamesMet = [];
			var paramGroupDuplicateNumbersMet = [];
			for (i = 0; i < params.length; i++) {
				if (params[i][2]) {
					paramName = params[i][2];
					if (!NUMBERED_PARAMS.includes(paramName) &&
						NUMBERED_PARAMS.includes(paramName.replace(/\d+/, ''))
					) {
						numberMatches = paramName.match(/\d+/);
						number = Number(numberMatches[0]);
						
						isDuplicate = paramNamesMet.includes(paramName);
						if (isDuplicate) {
							paramNameCount = paramNamesMet.filter(function (value) {
								return value === paramName;
							}).length;
							paramGroupDuplicatesCount = paramGroupDuplicateNumbersMet.filter(function (value) {
								return value === number;
							}).length;
						}
						
						if (numberedParamCurrent === undefined) {
							numberedParamCounter = 1;
						} else if (
							// `numberedParamCurrent` has the previous number.
							number !== numberedParamCurrent ||

							// This condition makes it possible to adequately parse numerous duplicates of
							// parameter names. It identifies cases where a certain parameter is repeated more
							// times than there are already groups for that number in order to increase the
							// counter by 1.
							(isDuplicate && paramNameCount > paramGroupDuplicatesCount)
						) {
							numberedParamCounter++;
							if (isDuplicate) {
								paramGroupDuplicateNumbersMet.push(number);
							}
						}
						
						numberedParamCurrent = number;
						paramNamesMet.push(paramName);
						
						paramName = paramName.replace(/\d+/, numberedParamCounter);
						params[i][2] = paramName;
					}
				}
				
				line = indentSpaces + params[i][0] + '|' + params[i][1] + (params[i][2] || '');
				if (params[i][2]) {
					if (!params[i][2].match(/^(lat|lon)_/) || !params[i][3].includes('|')) {
						line += generateSpaces(
							standardWidth - (params[i][2].length + params[i][0].length + params[i][1].length)
						);
					}
					if (standardWidth !== -1) {
						line += ' ';
					}
					line += '=';
					if (standardWidth !== -1 && (!params[i][3].match(/^\n(?!<!--)/) || params[i][3].trim() === '')) {
						line += ' ';
					}
				}
				line += params[i][3] + '\n';
				newTpl += line;
			}
			if (!noEndingBrackets) {
				newTpl += indentSpaces + '}}';
			}
			
			return newTpl;
		}
		
		var initialTxt = txt;
		
		
		var thisMaxWidth, thisPreserveBasicSpacing, thisPreserveParameterSpacing;
		var selectionSpacing = 0;
		var basicLevel = 0;
		if (askOptions) {
			if (!templateExpanderMode && !codeStylerMode) {
				if (selectionMode) {
					selectionSpacing = parseInt(prompt('Basic spacing of parameter values:', '0'));
					if (isNaN(selectionSpacing)) {
						selectionSpacing = 0;
					}
				}
				
				thisMaxWidth = parseInt(prompt('The maximum allowed standard width of the column consisting of parameter names, in characters. (The default value for this setting can be specified in your common.js in the cpMaxWidth variable.)', cpMaxWidth));
				if (isNaN(thisMaxWidth)) {
					thisMaxWidth = cpMaxWidth;
				}
				
				thisPreserveBasicSpacing = confirm('Keep the spacing around the "|" character at the beginning of the line? (The default value for this setting [true/false, now ' + cpPreserveBasicSpacing + '] can be specified in your common.js in the cpPreserveBasicSpacing variable.)');
				thisPreserveParameterSpacing = confirm('Keep the spacing around the "|" character at the beginning of the line at the individual parameters relative to the basic level (the parameters of some templates are visually grouped this way)? (The default value for this setting [true/false, now ' + cpPreserveParameterSpacing + '] can be specified in your common.js in the cpPreserveParameterSpacing variable.)');
			} else {
				thisMaxWidth = cpMaxWidth;
				thisPreserveBasicSpacing = cpPreserveBasicSpacing;
				thisPreserveParameterSpacing = cpPreserveParameterSpacing;
			}
			basicLevel = parseInt(prompt('Basic spacing of lines', '0'));
			if (isNaN(basicLevel) || basicLevel < 0) {
				basicLevel = 0;
			}
		} else {
			thisMaxWidth = cpMaxWidth;
			thisPreserveBasicSpacing = cpPreserveBasicSpacing;
			thisPreserveParameterSpacing = cpPreserveParameterSpacing;
		}
		
		// Template blanks
		if (!pageIsProbablyTemplate) {
			hideTag('pre');
		}
		hideTag('nowiki');
		hideTag('source');
		hideTag('syntaxhighlight');
		hideTag('templatedata');

		hideTag('code');
		hideTag('kbd');
		hideTag('tt');

		hideTag('graph');
		hideTag('hiero');
		hideTag('math');
		hideTag('timeline');
		hideTag('chem');
		hideTag('score');
		hideTag('categorytree');
		hide(/<!--[\s\S]*?-->/g);
		
		if (cpCodeStyler && codeStylerMode) {
			r(/^;(?=[^ ])/mg, '; ');
			
			r(/(\sstyle=)([\'"])([^<>\2]+?)\2([^<>]*?)/g, function (s, m1, m2, m3, m4) {
				if (/\{\{ *#/.test(s)) {
 					return s;
				}
				m3 = m3
					.replace(/;+/g, ';')
					.replace(/; */g, '; ')
					.replace(/ *$/, '')
					.replace(/([^;}])$/, '$1;')
					.replace(/#[0-9A-F]{6}/, function (m) {
						return m.toLowerCase();
					})
					.replace(/#[0-9A-F]{3}/, function (m) {
						return m.toLowerCase();
					});
				return m1 + '"' + m3 + '"' + m4;
			});
		}
		
		var tpl;
		var left;
		var right;
		var trailingSpaceBefore;
		var refTagBefore;
		var leftM;
		var lastStackBrackets;
		var stackElem;
		var newLeft;
		var stack = [];

		// Take into account `{{{{{|subst:}}}template}}`, `{{{!}}` (expanding to `{|`). Sacrifice the
		// fact that `{{{!}}}` will be parsed as `{ + {{!}} + }`.
		var leftRe = /\{\{(?:\{(?!\{|!)|(?!\{!))/g;
		
		var bracketsLength = 0;
		
		while (true) {
			lastStackBrackets = stack.length && stack[stack.length - 1][1] === 3 ? '}}}' : '}}';
			right = txt.indexOf(lastStackBrackets, leftRe.lastIndex);
			
			leftM = leftRe.exec(txt);
			if (leftM) {
				bracketsLength = leftM[0].length;
				left = leftM.index;
			} else {
				left = -1;
			}
			
			if (left === -1 && right === -1 && !stack.length) {
				break;
			}
			if (left !== -1 && (left < right || right === -1)) {
				stack.push([left, bracketsLength]);
			} else {
				stackElem = stack.pop();
				if (stackElem) {
					left = stackElem[0];
					bracketsLength = stackElem[1];
				} else {
					if (right === -1) {
						continue;
					} else {
						left = 0;
						bracketsLength = 2;
					}
				}
				if (right === -1) {
					right = txt.length;
				}
				right += bracketsLength;
				tpl = txt.substring(left, right);
				trailingSpaceBefore = '';
				if (isMultiline(tpl) || templateExpanderMode) {
					var m = txt.substring(0, left).match(/(\S)\s*$/);
					if (m && m[1] === '=') {
						trailingSpaceBefore = m[0].substr(1);
					}
					refTagBefore = txt.substring(0, left).match(/\n<ref( [\w ]+?=[^<>]+?| *\/?)>\s*$/);
				}
				newLeft = left;
				var index;
				var isParserFunction = false;
				var isMultilineTemplate = isMultiline(tpl);
				if (bracketsLength === 2) {
					isParserFunction = /^\{\{\s*#/.test(tpl);
					index = hidden.push(prettifyTemplate());
				} else {
					index = hidden.push(
						tpl.replace(/^\{\{\{\s*([^}|]*?)\s*(?:\|\s*([^}]*?)\s*)?\}\}\}$/, function (s, m1, m2) {
							return '{{{' + m1 + (m2 === undefined ? '' : '|' + m2) + '}}}';
						})
					);
				}
				// Add "_" to the indexes of templates that should be taken into account when determining the
				// makeIfMultiline variable value.
				txt = txt.substring(0, newLeft) + '\x01' + (isParserFunction || isMultilineTemplate ? '_' : '') +
					index + '\x02' + txt.substr(right);
				leftRe.lastIndex = right - tpl.length;
			}
		}
		//console.log(hidden);
		
		while (txt.match(/\x01_?\d+\x02/)) {
			txt = txt.replace(/\x01_?(\d+)\x02/g, function (s, num) {
				return hidden[num - 1];
			});
		}
		
		if (cpAutoSummary && txt !== initialTxt) {
			var summaryValue = $('#wpSummary').val();
			if (!/prettify code/.test(summaryValue)) {
				var commaOrNot = (/[^,; \/]$/.test(summaryValue) ? ', ' : '');
				var metaPrefixOrNot = location.hostname === 'meta.wikimedia.org' ? '' : 'meta:';
				$('#wpSummary').val(summaryValue + commaOrNot + '[[' + metaPrefixOrNot + 'User:JWBTH/CP|Skript]] istifadə edərək kodun səliqəyə salınması');
			}
		}
	}

	function processAllText() {
		if (templateExpanderMode && !selectionMode) {
			var expandOrCollapseText = templateExpanderMode === 'expand' ? 'expand' : 'collapse';
			if (!confirm('Are you sure you want to ' + expandOrCollapseText + ' all templates on the page? To ' + expandOrCollapseText + ' a single template or a group of templates, select only them.')) return;
		}
		txt = $textbox.textSelection('getContents').replace(/^\s+/, '');
		prettifyTemplates();

		// 2017 wikitext editor adds an empty line to the end with every text replacement. Remove
		// the following block when [[phab:T198010]] is fixed.
		if (window.ve && ve.init && ve.init.target && ve.init.target.active) {
			r(/[\n\r]+$/, '');
		}

		$textbox.textSelection('setContents', txt);
		if (caretPosition) {
			$textbox.textSelection('setSelection', {
				start: caretPosition[0] > txt.length ? txt.length : caretPosition[0]
			});
		}
	}
	
	
	$textbox.focus();

	var caretPosition = $textbox.textSelection('getCaretPosition', { startAndEnd: true });
	if (caretPosition) {
		var textScroll = ($CodeMirrorVscrollbar.length ? $CodeMirrorVscrollbar : $textbox).scrollTop();
		if (caretPosition[0] === caretPosition[1]) {
			processAllText();
		} else {
			txt = $textbox.textSelection('getSelection');
			prettifyTemplates();
			$textbox
				.textSelection('replaceSelection', txt)
				.textSelection('setSelection', {
					start: caretPosition[0],
					end: caretPosition[0] + txt.length
				});
		}
		($CodeMirrorVscrollbar.length ? $CodeMirrorVscrollbar : $textbox).scrollTop(textScroll);
	// If something went wrong
	} else if (confirm('The script will process ALL text on this page. Proceed?')) {
		processAllText();
	}

	// scroll back, for 2017 wikitext editor, IE, Opera
	document.documentElement.scrollTop = winScroll;
}

$.when(
	mw.loader.getScript('https://az.wikipedia.org/w/index.php?title=MediaWiki:Gadget-registerTool.js&action=raw&ctype=text/javascript'),
	mw.loader.using(['jquery.textSelection'])
).done(function () {
	if (typeof cpTemplateExpander === 'undefined') window.cpTemplateExpander = true;
	if (typeof cpCodeStyler === 'undefined') window.cpCodeStyler = true;
	
	registerTool({
		name: 'cpAlignTemplateParameters',
		position: 150,
		title: 'Şablon parametrlərini səliqəyə sal',
		label: 'Şablon parametrlərini səliqəyə sal. Sadəcə spesifik şablon üçün həmin hissəni seçin. Parametrləri dizaynla uyğunlaşdırılmamış şablonların parametrlərini eyniləşdirmək üçün Ctrl ilə klikləyin. Parametrləri çağırmaq üçün Alt ilə klikləyin',
		callback: function () {},
		classic: {
			icon: '//upload.wikimedia.org/wikipedia/commons/5/59/AlignTemplateParameters.js_icon.png',
			addCallback: function () {
				 $('.tool-button[rel="cpAlignTemplateParameters"], .tool[rel="cpAlignTemplateParameters"] a')
					.off('click')
					.on('click', function (e) {
						alignTemplateParameters({
							askOptions: e.altKey,
							hardMode: e.ctrlKey || e.metaKey,
						});
						e.preventDefault();
					});
			},
		},
		visual: {
			icon: '//upload.wikimedia.org/wikipedia/commons/thumb/1/14/AlignTemplateParameters.js_VE_icon.svg/20px-AlignTemplateParameters.js_VE_icon.svg.png',
			modes: ['source'],
			callback: alignTemplateParameters,
		},
	});
	
	if (cpTemplateExpander) {
		if (typeof cpSwapExpandCollapseTemplates === 'undefined') window.cpSwapExpandCollapseTemplates = false;
		
		registerTool({
			name: 'cpTemplateExpander',
			position: 151,
			label: !cpSwapExpandCollapseTemplates
				? 'Şablon parametrlərini alt-alta göstər. Yalnız zəruri hallarda istifadə edin. Yığmaq üçün "Shift+click"'
				: 'Şablon parametrlərini bir sətirdə göstər. Yalnız zəruri hallarda istifadə edin. Genişləndirmək üçün "Shift+click"',
			icon: '//upload.wikimedia.org/wikipedia/commons/8/8b/AlignTemplateParameters.js_templateExpander.png',
			callback: function () {},
			classic: {
				addCallback: function () {
					$('.tool-button[rel="cpTemplateExpander"], .tool[rel="cpTemplateExpander"] a')
						.off('click')
						.on('click', function (e) {
							alignTemplateParameters({
								askOptions: e.altKey,
								templateExpanderMode: e.shiftKey === cpSwapExpandCollapseTemplates ? 'expand' : 'collapse',
							});
							e.preventDefault();
						});
				},
			},
		});
	}
	
	if (cpCodeStyler) {
		registerTool({
			name: 'cpCodeStyler',
			position: 152,
			label: 'Şablon kodlarındakı parametrləri səliqəyə sal. "Ctrl+click" vasitəsilə onları bir neçə sətirə keçirmək mümkündür. Yığmaq üçün Ctrl+Shift+click',
			icon: '//upload.wikimedia.org/wikipedia/commons/6/68/AlignTemplateParameters.js_codeStyler.png',
			callback: function () {},
			classic: {
				addCallback: function () {
					$('.tool-button[rel="cpCodeStyler"], .tool[rel="cpCodeStyler"] a')
						.off('click')
						.on('click', function (e) {
							alignTemplateParameters({
								askOptions: e.altKey,
								codeStylerMode: (e.ctrlKey || e.metaKey) ? (e.shiftKey ? 'newlines-collapse' : 'newlines') : 'spaces',
							});
							e.preventDefault();
						});
				},
			},
		});
	}
});

}());
// </nowiki>
Mənbə — ""

Informasiya Melumat Axtar

Anarim.Az

Sayt Rehberliyi ile Elaqe

Saytdan Istifade Qaydalari

Anarim.Az 2004-2023