打开/关闭搜索
搜索
打开/关闭菜单
1K
5.2K
4
8.2K
星砂岛百科
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
上传文件
打开/关闭外观设置菜单
通知
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
本站正在进行早期测试,目前仍存在许多内容的缺失。
查看“︁模块:CharacterCommon”︁的源代码
来自星砂岛百科
查看
阅读
查看源代码
查看历史
associated-pages
模块
讨论
更多操作
←
模块:CharacterCommon
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:已验证邮箱用户
您没有权限编辑
模块
命名空间内的页面。
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
local common = require('Module:Common') local p = {} local character_mapping_cache local DEFAULT_MAPPING_PAGES = { '数据:Character/character_mapping.json', '数据:Character/character mapping.json', } function p.defaultMapping() return { name_to_id = {}, id_to_name = {}, aliases = {}, overrides = { name_to_id = {}, aliases = {}, }, } end local function normalize_pages(pages) if type(pages) == 'string' then return { pages } end if type(pages) ~= 'table' then return {} end return pages end local function find_mapped_key(data, mapping, normalized) if type(data) ~= 'table' or type(mapping) ~= 'table' then return '' end local function resolve_candidate(candidate) local mapped_key = p.normalizeKey(candidate) if mapped_key ~= '' and data[mapped_key] then return mapped_key end return '' end for _, candidate in ipairs({ mapping.overrides and mapping.overrides.name_to_id and mapping.overrides.name_to_id[normalized] or false, mapping.overrides and mapping.overrides.aliases and mapping.overrides.aliases[normalized] or false, mapping.name_to_id and mapping.name_to_id[normalized] or false, mapping.aliases and mapping.aliases[normalized] or false, }) do local mapped_key = resolve_candidate(candidate) if mapped_key ~= '' then return mapped_key end end return '' end function p.trim(value) return common.trim(value) end function p.normalizeKey(value) return common.normalizeKey(value) end function p.stripNamespace(value) local resolved = common.trim(value) local namespace_stripped = mw.ustring.match(resolved, '^[^:]+:(.+)$') if common.trim(namespace_stripped) ~= '' then return common.trim(namespace_stripped) end return resolved end function p.resolveLookupKey(value, options) local resolved = common.trim(value) if resolved == '' then resolved = common.getCurrentTitleText() end if not options or options.strip_namespace ~= false then resolved = p.stripNamespace(resolved) end return resolved end function p.loadFirstJsonPage(pages) for _, title in ipairs(normalize_pages(pages)) do local data = common.loadJsonData(title) if type(data) == 'table' then return data end end return nil end function p.loadCharacterMapping() if character_mapping_cache then return character_mapping_cache end character_mapping_cache = p.loadFirstJsonPage(DEFAULT_MAPPING_PAGES) or p.defaultMapping() return character_mapping_cache end function p.loadDomainData(data_pages, mapping_pages) local data = p.loadFirstJsonPage(data_pages) or {} local mapping if mapping_pages == false then mapping = p.defaultMapping() elseif mapping_pages == nil then mapping = p.loadCharacterMapping() else mapping = p.loadFirstJsonPage(mapping_pages) or p.defaultMapping() end return data, mapping end function p.findRecordWithKey(data, mapping, key, options) local resolved = p.resolveLookupKey(key, options) local normalized = p.normalizeKey(resolved) if normalized ~= '' and type(data) == 'table' and data[normalized] then return data[normalized], normalized, normalized end local mapped_key = find_mapped_key(data, mapping or p.loadCharacterMapping(), normalized) if mapped_key ~= '' then return data[mapped_key], mapped_key, normalized end return nil, '', normalized end function p.findRecord(data, mapping, key, options) local record = p.findRecordWithKey(data, mapping, key, options) return record end function p.tableHasEntries(value) if type(value) ~= 'table' then return false end for _ in pairs(value) do return true end return false end function p.orderedNumericValues(value) if type(value) ~= 'table' then return {} end local ordered_pairs = {} for key, item in pairs(value) do local numeric_key = tonumber(key) if numeric_key ~= nil then ordered_pairs[#ordered_pairs + 1] = { key = numeric_key, value = item, } end end table.sort(ordered_pairs, function(left, right) return left.key < right.key end) local out = {} for _, pair in ipairs(ordered_pairs) do out[#out + 1] = pair.value end return out end return p
该页面嵌入的页面:
模块:CharacterCommon/doc
(
查看源代码
)
返回
模块:CharacterCommon
。
查看“︁模块:CharacterCommon”︁的源代码
来自星砂岛百科