모듈:Political party
| 이 루아 모듈은 많은 문서에서 사용 중인 루아 모듈입니다. 이 루아 모듈을 수정하면 많은 문서에 영향을 줄 수 있습니다. 기여할 모든 내용은 /연습장이나 /시험장에서 사전 점검을 거쳐야 합니다. 이 루아 모듈을 수정하기 전에, 먼저 토론 문서에 의견을 구하시는 것이 좋습니다. |
| 이 모듈은 다음의 모듈에 의존합니다. |
사용법
[편집]{{#invoke:Political party|fetch|<party>|<value>}}
매개변수
[편집]모듈 업데이트하기
[편집]이 모듈에 포함된 정당들은 이름의 첫 글자에 따라 알파벳순 목록으로 나뉘어 저장된다 (예를 들어, "노동당 (영국)"은 /L 아래에 있다). /1 하위 페이지는 라틴 음소문자 A부터 Z로 시작하지 않는 모든 정당(숫자 및 발음 구별 부호가 포함된 문자 포함)을 위한 것이다.
각 데이터 하위 모듈 내에는 local alternate와 local full이라는 두 개의 지역 그룹이 있다.
대체 정당 이름
[편집]alternate 그룹은 정당의 대체 이름을 위한 것이다. 다음은 노동당 (영국)의 대체 이름 예시이다.
local alternate = {
....
["Labour and Co-operative"] = "Labour Party (UK)",
["Labour Co-operative"] = "Labour Party (UK)",
...
}
대괄호 안의 첫 번째 항목은 대체 이름이고, 따옴표로 묶인 두 번째 항목은 아래에 설명된 full 그룹에서 찾을 수 있는 이름이다. 정당의 대체 이름은 해당 글자에 해당하는 하위 페이지에 저장되어야 한다. "Alabama Democratic Party"는 "Democratic Party (US)"(/D에 저장됨)의 대체 이름이지만 /A에 목록화되어 있다.
테이블 값
[편집]local full = {
....
["Labour Party (UK)"] = {abbrev = "Lab", color = "#E4003B", shortname = "Labour",},
...
}
각 정당에 대해 세 가지 값이 저장된다:
- 약칭 (
abbrev). - 정당의 색상 (
color). 이는 16진수 색상 코드나 기본 색상 이름일 수 있으며, 정당에 연결된 색상이 없는 경우 "default"로 지정한다. - 정당의 짧은 이름 (
shortname).
이 매개변수에 추가된 값은 정당의 기본 이름과 달리 이 모듈 내의 다른 정당과 중복되어도 상관없다.
정당에 대해 특정 이름 값이 저장되어 있지 않은 경우, 모듈은 입력값을 그대로 반환하기 전에 다른 "짧은" 이름 변체를 반환하려고 시도한다. 따라서 abbrev는 저장되어 있지만 shortname이 저장되어 있지 않은 경우, 어떤 값을 요청하든 abbrev 값을 반환한다.
추가 또는 변경 요청
[편집]모듈을 직접 편집할 수 없는 경우 편집 요청을 해야 한다. 요청은 토론 페이지의 새 섹션에서 이루어져야 한다. 다음 줄을 복사하고 해당 정당과 관련된 필드만 채워 넣는다. 정당 이름은 필수이며 최소한 하나 이상의 다른 정보가 필요하다. 각 값에 관한 정보는 위를 참조하라.
["party"] = {abbrev = "", color = "", shortname = "",},
오류 메시지
[편집]| 오류 메시지 | 해결 방법 |
|---|---|
| Lua error: bad argument #1 to 'sub' (string expected, got table). | "local full" 섹션에 들어가야 할 항목이 "local alternate" 섹션에 배치되었다. 해당 항목을 "local full" 섹션으로 이동하라. |
| Lua error in package.lua at line 80: module 'Module:Political party/' not found. | 대체 목록(alternate list)에 빈 값으로 정당이 추가되었다. |
| Value not in template. Please request that it be added. (문서 검색) | 해당 정당이 "local full" 섹션에 색상 없이 등록되어 있다. (이는 "local full"에 중복된 항목이 있을 때 발생할 수 있으며, 이 경우 항목을 병합해야 한다.) |
| (오류 메시지는 없지만 정당 색상이 흰색/공백으로 나옴) | 관련된 Module:Political party/ 알파벳 데이터 페이지의 "local full" 섹션 항목에 정당 색상을 추가하라(아래 링크 참조). |
| parameter 1 should be a party name (문서 검색) | 틀이 모듈에 누락된 매개변수를 전달하려고 시도 중이다. 틀에서 매개변수 존재 여부를 테스트하여 이 문제를 해결하라. |
| parameter 2 should be the output type (문서 검색) |
데이터 페이지
[편집]- Political party/1
- Political party/A
- Political party/B
- Political party/C
- Political party/D
- Political party/E
- Political party/F
- Political party/G
- Political party/H
- Political party/I
- Political party/J
- Political party/K
- Political party/L
- Political party/M
- Political party/N
- Political party/O
- Political party/P
- Political party/Q
- Political party/R
- Political party/S
- Political party/T
- Political party/U
- Political party/V
- Political party/W
- Political party/X
- Political party/Y
- Political party/Z
local p = {}
local default_color = '#F8F9FA'
local categories = {
party_not_in_list = '[[Category:Pages using Political party with unknown party]]',
shortname_not_in_list = '[[Category:Pages using Political party with missing shortname]]',
color_not_in_list = '[[Category:Pages using Political party with missing color]]',
}
local function create_error(error_message)
return string.format('<strong class="error">%s</strong>', error_message)
end
local function getFirstLetter(party)
local index = mw.ustring.sub(party, 1, 1)
-- Set index for non-A-Z starts
if string.match(index, '%A') then
return '1'
end
return string.upper(index)
end
local function stripToNil(text)
-- If text is a string, return its trimmed content, or nil if empty.
-- Otherwise return text (which may, for example, be nil).
if type(text) == 'string' then
text = text:match('(%S.-)%s*$')
local delink = require('Module:Delink')._delink
text = delink({text, wikilinks = "target"})
end
return text
end
-- Example of having all the data - color and names - in one table. Requires one page to be edited instead of two when adding a new party.
function p._fetch(args)
if not args[1] then
return create_error("parameter 1 should be a party name.")
end
if not args[2] then
return create_error("parameter 2 should be the output type.")
end
local party = stripToNil(args[1])
local out_type = stripToNil(args[2])
if out_type == 'colour' then
out_type = 'color'
end
local index = getFirstLetter(party)
-- Load data from submodule
local data = mw.loadData('Module:Political party/' .. index)
local data_all = data.full
local party_alt = data.alternate[party]
local party_info
if party_alt then
if data_all[party_alt] then
party_info = data_all[party_alt]
else
index = getFirstLetter(party_alt)
data = mw.loadData('Module:Political party/' .. index)
party_info = data.full[party_alt]
end
else
party_info = data_all[party]
end
-- Check if database value exists
-- * Not even in database - return given error or input
-- * No color - return error
-- * No shortname/abbrev - return first non-blank of abbrev->shortname->input
if not party_info then
if out_type == 'color' then
return args.error or default_color
else
return args.error or party
end
end
local return_value = party_info[out_type]
if return_value == "" then
if out_type == 'color' then
return args.error or create_error("Value not in template. Please request that it be added.")
elseif out_type == 'abbrev' then
if party_info.shortname ~= "" then
return party_info.shortname
else
party = party:gsub('%([^)]*%)', '')
return party
end
elseif out_type == 'shortname' then
if party_info.abbrev ~= "" then
return party_info.abbrev
else
party = party:gsub('%([^)]*%)', '')
return party
end
else
return party
end
end
if out_type == 'color' then
if string.find(return_value, '#') then
return_value = string.gsub(return_value, '#', '#')
elseif string.lower(return_value) == 'default' then
return default_color
end
end
return return_value
end
function p.fetch(frame)
-- Initialise and populate variables
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
return p._fetch(args)
end
return p