コンテンツにスキップ

モジュール:サンドボックス/Semi-Brace/file

モジュールの解説[作成]
require("strict")
local p = {}
--[[
name (string): page's title. File:Example.png --> Example.png
-- messages (table<0 | 1 | 2, string>): output message.
-- returns
-- 0: no warning.
-- 1: detected possibly unacceptable title.
-- 2: detected definitely unacceptable title.
-- This method is based both MediaWiki:Titleblacklist and 
--]]
function p.check(name)
	local MS = require("Module:String")
	local ends_with = function(source, pattern)
		return MS.endswith { args = { source = source, pattern = pattern } } == "yes" -- boolean via "yes" | ""
	end
	local m = function(pattern)
		-- ( s, pattern, start, match_index, plain_flag, nomatch )
		return MS._match(name, pattern, nil, nil, nil, nil)
	end
	local rep = string.rep
	local isJPG = ends_with(mw.ustring.ucase(name), "JPG")
	local hitDC = isJPG and m("^Test[%d%s]+")
        or m("^DCP[%d%s]+")
        or m("^DSC[%d%s]+")
        or m("^MVC?[%d%s]+")
        or m("^P[%dA-F][%d%s]+")
        or m("^I?MG[P_]?[%d%s]+")
        or m("^1%d+-%d+(_IMG)?")
        or m("^IM[%d%s]+")
        or m("^EX[%d%s]+")
        or m("^DC[%d%s]+[SML]")
        or m("^PIC[T_]?[%d%s]")
        or m("^PANA[%d%s]+")
        or m("^DUW[%d%s]+")
        or m("^CIMG[%d%s]+")
        or m("^JD[%d%s]+")
        or m("^SDC[%d%s]+")
        or m("^DVC[%d%s]+")
        or m("^SANY[%d%s]+")
        or m("^SAM[%d%s]+")
	if hitDC or (
        m("^CIMG.*")
        or m("^DSC_.*")
        or m("^DSCF.*")
        or m("^DSCN.*")
        or m("^DUW.*")
        or m("^GEDC.*")
        or m("^IMG.*")
        or m("^JD.*")
        or m("^MGP.*")
        or m("^PICT.*")
        or m("^Imagegen.*")
        or m("^FOTO.*")
        or m("^DSC.*")
        or m("^SANY.*")
        or m("^SAM.*")
	) then
		return 2
	elseif (m("%d*[a-fA-F]+%d+[a-fA-F]*%d+[a-fA-F]+%d+") and m(rep("[a-fA-F%d]", 10) .. "[a-fA-F%d]*")) then
		return 1
	else
		return 0
	end
end

function p.main(frame)
	local ret = {
		[2] = "警告: このファイル名はコモンズでは受け入れられていません。",
		[1] = "ヒント: このファイル名はコモンズでは受け入れられていない可能性があります。",
		[0] = "",
	}
	local ret2 = ret[p.check(mw.title.getCurrentTitle())]
	return ret2
end

return p