本站页面(多半)转载自
萌娘百科
的同名页面,依CC BY-NC-SA 3.0引入,贡献者可以在历史页查询。
因各种原因页面内容可能和源页面有所出入,
非本站特有页面内容请以萌娘百科为准
。此外,因萌百的api限制,本站部分页面和图片同步自
另一个镜像站
。
置顶公告:
【置顶】关于临时开启评论区所有功能的公告(2022.10.22)
|
【置顶】关于本站Widget恢复使用的公告
你好~!欢迎来到萌娘百科镜像站!
如需查看或编辑,请联系本站管理员注册账号。
本镜像站和其他萌娘百科的镜像站
无关
,请注意分别。
查看“Module:IconLink”的源代码
←
Module:IconLink
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
-- 请在[[模块:IconLink/data]]添加站点数据 local data = require('Module:IconLink/data') local sites, domains, idPatterns = data.sites, data.domains, data.idPatterns -- 短点方便些 local match = string.match local format = string.format -- 从模块参数分析站点 -- 返回:site表 | nil local function getSiteFromUrl(url) local domainParts = mw.text.split(mw.uri.new(url).host, '%.') local curPart = domains for i = #domainParts, 1, -1 do curPart = curPart[domainParts[i]] if not curPart then return nil end if type(curPart) == 'string' then return sites[curPart] end end return nil end -- 根据[[模块:IconLink/data]]的sites表,对指定site和id生成URL local function makeUrl(site, id) local urlType = type(site.url) if urlType == 'table' then for _, v in ipairs(site.url) do if (not v[1]) or match(id, v[1]) then return format(v[2], id) end end return false end if urlType == 'function' then return site.url(id) end if urlType == 'string' then return format(site.url, id) end error('模块:IconLink/data中,sites表' .. site.name .. '的url填写有误。') end -- 生成最终链接 local function makeIconLink(site, url, title, size) -- 错误 -- * 无url,无site: 未正确填写参数 -- * 无url,有site: 未填写URL/ID或填写了不受支持的URL/ID -- * 有url,无site: 未匹配到支持的网站,不显示网站图标,但不报错 if not url then if site then error('URL/ID填写有误') else error('分析参数失败') end end if site then if title then -- [[File:icon]] [url title] return format('[[File:%s|%s|link=|%s]] [%s %s]', site.icon.file, size or site.icon.size or 'x20px', site.name, url, title ) end -- [[File:icon|url]] return format('[[File:%s|%s|link=%s|%s]]', site.icon.file, size or site.icon.size or 'x20px', url, site.name ) end -- [url title] if title then return '['..url..' '..title..']' end -- [url] return '['..url..']' end local p = {} function p.main(args) local url = args.link local site = (args.site and sites[args.site:lower()]) or (url and getSiteFromUrl(url)) local title = args.title for _, arg in ipairs(args) do arg = mw.text.trim(arg) if not url then -- 默认有url的时候就知晓site和id -- 若参数是url if match(arg, '^[Hh][Tt][Tt][Pp][Ss]?://') then url = arg -- 从url获取网站 if not site then site = getSiteFromUrl(url) end -- 若参数是site或id elseif not site then -- 未知site,尝试从该参数获取site site = sites[mw.ustring.lower(arg)] if not site then for idPattern, siteById in pairs(idPatterns) do -- 遍历idPatterns if match(arg, idPattern) then site = siteById url = makeUrl(site, arg) break end end end if not site then break end -- 连站点都获取不到,还搞啥,润! -- site已知晓,该参数是id,从中获取url else url = makeUrl(site, arg) end elseif not title then -- url(site、id)已知晓,只缺title title = arg end end return makeIconLink(site, url, title, args.size) end function p.fromParent(frame) return p.main(frame:getParent().args) end function p.wrapper(frame) local parent = frame:getParent() parent.args.site = frame.args.site return p._main(parent.args) end return p
本页使用的模板:
Template:Documentation
(
查看源代码
)(仅允许管理员和巡查姬)
Template:Documentation/docname
(
查看源代码
)
Module:IconLink/doc
(
查看源代码
)
返回
Module:IconLink
。
导航菜单
个人工具
登录
命名空间
模块
讨论
English
已展开
已折叠
查看
阅读
查看源代码
查看历史
更多
已展开
已折叠
搜索
导航
首页
随机页面
最近更改
最新文件
萌娘原味图裤
讨论版
帮助
帮助
沙盒
Wiki入门
萌百编辑教程
编辑规范
萌娘百科政策
创建新条目
请求创建条目
常见问题集
分类索引
作品
人物
组织
概念用语
设定
软件
活动
工具
链入页面
相关更改
特殊页面
页面信息