Stapx Steve(讨论 | 贡献) 小无编辑摘要 |
Stapx Steve(讨论 | 贡献) 小无编辑摘要 |
||
| (未显示同一用户的6个中间版本) | |||
| 第96行: | 第96行: | ||
html = html.."</ul>" | html = html.."</ul>" | ||
return html | return html | ||
end | |||
function p.getdomain() | |||
return "https://" .. mw.uri.fullUrl( "主页").host | |||
end | end | ||
| 第115行: | 第118行: | ||
function p.nowPage() | function p.nowPage() | ||
return mw.title.getCurrentTitle() | return mw.title.getCurrentTitle() | ||
end | |||
function p.nowPageR() | |||
local title = tostring(mw.title.getCurrentTitle()) | |||
title = (string.gsub(title, ":", "-")) | |||
title = (string.gsub(title, " ", "-")) | |||
return title | |||
end | end | ||
return p | return p | ||
2022年1月29日 (六) 12:44的最新版本
这是个基础模块,曾经用了个很新手的名字:Hello Lua,但这也确实是我首次使用 Lua 这门语言 ——
下面是这个基础模块的功能列表和详细用法。
实战函数[编辑]
这些函数已经完善并且可以正常使用。
| 函数名 | 简介 | 参数 | 返回值 | 备注 |
|---|---|---|---|---|
| getURL() | 获取当前界面的 URL | - | 对应的无主域名编码 URL | - |
| strCat(string, string) | 连接两个字符串 | 两个字符串参数 | 连接完成的一个字符串 | - |
| getStat(string) | 获取站点统计信息 | 统计的类型,参见 mw.site.stats | 统计数值 | - |
| gethitokoto() | 获取一言 | 是否显示from(一言出处),默认false | 一言字符串 | - |
| drawSector(int) | 生成一个二值扇形图 | 主值数值(度数) | 扇形图的完整 HTML | 请确保输入合法 |
getURL()[编辑]
获取当前界面的 URL。
{{#invoke:Basic|getURL}}
/%E6%A8%A1%E5%9D%97:Basic
srtCat()[编辑]
连接两个字符串。
{{#invoke:Basic|strCat|This is the text| and add text}}
This is the text and add text
getStat()[编辑]
获取站点统计信息
{{#invoke:Basic|getStat|articles}}
DHW PCS WIKI 目前总文章数:49
gethitokoto()[编辑]
获取一言( https://hitokoto.cn )
{{#invoke:Basic|gethitokoto|true}}
停下脚步才注意到 世界被染得雪白。 —— 雪降り、メリクリ
drawSector()[编辑]
生成一个二值扇形图
{{#invoke:Basic|drawSector|70}}
计划函数[编辑]
这些函数正在制作中,暂时无法使用但是已经存在计划。
学习函数[编辑]
这些函数没有使用意义,仅仅是我用来学习 Lua 和 Mediawiki 的。
| 函数名 | 简介 | 参数 | 返回值 | 备注 |
|---|---|---|---|---|
| hello() | 输出 Hello, Lua! | - | - | - |
| inPut(frame) | 输出获取到的第一个参数 | 随意参数 | - | - |
| nowPage() | 获取当前界面标题 | - | - | - |
Hello, Lua!
inPut1
模块:Basic
--Basic By Stapx Steve
--本模块包含一些基础的功能
local p = {} --p代表一个包(package)
-- 以下是实战函数
------------------------------------------------------------
function p.getURL()
local urlobj = mw.uri.localUrl( mw.title.getCurrentTitle().fullText )
return urlobj.path
end
function p.strCat(strs)
return strs.args[1] .. strs.args[2]
end
function p.getStat( type )
local info = mw.site.stats
if( type.args[1] == "pages" )
then
return info.pages
elseif( type.args[1] == "articles" )
then
return info.articles
elseif( type.args[1] == "files" )
then
return info.files
elseif( type.args[1] == "edits" )
then
return info.edits
elseif( type.args[1] == "users" )
then
return info.users
elseif( type.args[1] == "activeUsers" )
then
return info.activeUsers
elseif( type.args[1] == "admins" )
then
return info.admins
else
return "err - 类型不存在"
end
end
function p.gethitokoto(sets)
local yy = mw.ext.externaldata.getWebData {
url = "https://v1.hitokoto.cn"
, data = "hit=$.hitokoto, from=$.from"
, format = "json"
, 'use jsonpath'
}
if(sets.args[1] == "true")
then
return yy.hit .. ' —— ' .. yy.from
else
return yy.hit
end
end
function p.drawSector( set )
local s11,s12,s21,s22,bac1,bac2
local seta = tonumber(set.args[1])
if(seta < 180)
then
bac1 = "#4188F1"
bac2 = "#ffffff"
if(seta < 90)
then
s11 = 360 - seta
s12 = -90 + seta
s21 = 90
s22 = -90
else
s11 = 270
s12 = 0
s21 = 180 + (180 - seta)
s22 = 0 - (180 - seta)
end
else
bac1 = "#ffffff"
bac2 = "#4188F1"
local set = 360 - seta
if(set < 90)
then
s11 = 0
s12 = - (90 - set)
s21 = 90
s22 = -90
else
s11 = 0
s12 = 0
s21 = 90
s22 = - (90 - (set - 90))
end
end
local html = "<ul style=\"position: relative;margin: 0px;padding: 0;box-shadow:0px 0px 10px -1px #C9C9C9;width: 11em;height: 11em;border-radius: 50%;list-style: none;overflow: hidden;background-color: "..bac2..";\">"
html = html.."<li style=\"overflow: hidden;position: absolute;top: 0;right: 0;width: 50%;height: 50%;transform-origin: 0% 100%;transform: rotate("..s11.."deg) skewY("..s12.."deg);background: "..bac1..";\"> </li>"
html = html.."<li style=\"overflow: hidden;position: absolute;top: 0;right: 0;width: 50%;height: 50%;transform-origin: 0% 100%;transform: rotate("..s21.."deg) skewY("..s22.."deg);background: "..bac1..";\"> </li>"
html = html.."</ul>"
return html
end
function p.getdomain()
return "https://" .. mw.uri.fullUrl( "主页").host
end
-- 以下是计划函数
-----------------------------------------------------------
-- 以下是辅助函数
-----------------------------------------------------------
-- 以下是学习函数
-----------------------------------------------------------
function p.hello()
return "Hello, Lua!"
end
function p.inPut( frame )
local args = frame.args
return args[1]
end
function p.nowPage()
return mw.title.getCurrentTitle()
end
function p.nowPageR()
local title = tostring(mw.title.getCurrentTitle())
title = (string.gsub(title, ":", "-"))
title = (string.gsub(title, " ", "-"))
return title
end
return p