无编辑摘要
无编辑摘要
第91行: 第91行:
end
end
end
end
local html = "<ul style=\"position: relative;margin: 1em auto;padding: 0;box-shadow:0px 0px 10px -1px #C9C9C9;width: 12em;height: 12em;border-radius: 50%;list-style: none;overflow: hidden;background-color: "..bac2..";\">"
local html = "<ul style=\"position: relative;padding: 0;box-shadow:0px 0px 10px -1px #C9C9C9;width: 12em;height: 12em;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("..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.."<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>"

2020年8月28日 (五) 03:05的版本

Icon-product.png
底层模块
它提供了支柱功能,请讨论后修改。


这是个基础模块,曾经用了个很新手的名字: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;padding: 0;box-shadow:0px 0px 10px -1px #C9C9C9;width: 12em;height: 12em;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.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

return p