local export = {}
-- it is either here, or in [[Module:ugly hacks]], and it is not in ugly hacks.
function export.CONTENTMODEL()
return mw.title.getCurrentTitle().contentModel
end
local skins = {
["common" ] = "";
["vector" ] = "Vector";
["monobook" ] = "Monobook";
["cologneblue"] = "Cologne Blue";
["modern" ] = "Modern";
}
-- this is to automatically categorize data modules and prevent cluttering [[Cat:Uncategorized modules]]
local data_modules_regex_cats = {
["^มอดูล:data tables/data..?.?.?$"] = "Reference module sharded data tables",
["^มอดูล:Quotations/...?.?.?.?.?.?$"] = "Quotation data modules",
["^มอดูล:zh/data/.+[a-zA-z0-9]$"] = "มอดูลข้อมูลภาษาจีน", -- capture submodules of zh/data that do not end with a hanzi in the title
["^มอดูล:zh/data/dial%-pron/"] = "Chinese dialectal pronunciation data modules",
["^มอดูล:zh/data/dial%-syn/"] = "Chinese dialectal synonyms data modules",
["^มอดูล:zh/data/glyph%-data/"] = "Chinese historical character forms data modules",
["^มอดูล:zh/data/ltc%-pron/"] = "มอดูลข้อมูลการออกเสียงภาษาจีนยุคกลาง",
["^มอดูล:zh/data/och%-pron%-BS/"] = "มอดูลข้อมูลการออกเสียงภาษาจีนเก่า (Baxter-Sagart)",
["^มอดูล:zh/data/och%-pron%-ZS/"] = "มอดูลข้อมูลการออกเสียงภาษาจีนเก่า (Zhengzhang)",
["^มอดูล:Unicode data"] = "มอดูลข้อมูลยูนิโคด",
["^มอดูล:number list/data/"] = "Number data modules",
["^มอดูล:es%-conj/data/"] = "Spanish data modules"
}
function export.show(frame)
local params = {
["hr"] = {},
["for"] = {},
["from"] = {},
["notsubpage"] = { type = "boolean", default = false },
["nodoc"] = { type = "boolean", default = false },
}
local args = require("Module:parameters").process(frame.args, params)
local output = { '\n<div class="documentation" style="display:block; clear:both">\n' }
local cats = {}
if (not args.hr) or (args.hr == "above") then
output[#output + 1] = "----\n"
end
local title = ((args['for'] ~= "") and args['for']) and mw.title.new(args['for']) or mw.title.getCurrentTitle()
local doc_title = mw.title.new((args['from'] ~= "") and args['from'] or (title.fullText .. '/documentation'))
local pagetype = "หน้า" .. mw.getContentLanguage():lcfirst(title.nsText)
local preload
local user_name, skin_name
if title.contentModel == "javascript" then
pagetype = "สคริปต์"
preload = 'แม่แบบ:documentation/preloadTemplate' -- XXX
if title.nsText == 'ผู้ใช้' then
user_name = title.rootText
end
elseif title.contentModel == "css" then
pagetype = "สไตล์ชีต"
preload = 'แม่แบบ:documentation/preloadTemplate' -- XXX
if title.nsText == 'ผู้ใช้' then
user_name = title.rootText
end
elseif title.contentModel == "Scribunto" then
pagetype = "มอดูล"
user_name = title.rootText:match("^ผู้ใช้:(.+)")
if user_name then
preload = 'แม่แบบ:documentation/preloadModuleSandbox'
else
preload = 'แม่แบบ:documentation/preloadModule'
end
elseif title.nsText == "แม่แบบ" then
pagetype = "แม่แบบ"
preload = 'แม่แบบ:documentation/preloadTemplate'
elseif title.nsText == "วิกิพจนานุกรม" then
pagetype = "หน้าโครงการ"
preload = 'แม่แบบ:documentation/preloadTemplate' -- XXX
end
local old_title
if doc_title.isRedirect then
old_title = doc_title
doc_title = mw.title.new(string.match(doc_title:getContent(), "^#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]]-)%]%]") or string.match(doc_title:getContent(), "^#เปลี่ยนทาง%s*:?%s*%[%[([^%[%]]-)%]%]"))
end
local fallback_docs
output[#output + 1] = "<dl class=\"plainlinks\" style=\"font-size: smaller;\">"
if doc_title.exists then
output[#output + 1] =
"<dd><i style=\"font-size: larger;\">[[วิธีใช้:การทำเอกสารการใช้งานแม่แบบและมอดูล|เอกสารการใช้งาน]]ต่อไปนี้ตั้งอยู่ที่ [[" .. doc_title.fullText .. "]] " ..
"<sup>[[" .. doc_title:fullUrl { action = 'edit' } .. " แก้ไข]]</sup> </i></dd>"
else
if title.contentModel == "Scribunto" then
local automatic_cat = "มอดูลที่ไม่จัดหมวดหมู่"
if user_name then
fallback_docs = 'documentation/fallback/user module'
automatic_cat = "มอดูลกระบะทรายของผู้ใช้"
else
local categorized = false
for r, cat in pairs(data_modules_regex_cats) do
if mw.ustring.match(title.fullText, r) then
automatic_cat = cat;
break
end
end
end
cats[#cats + 1] = automatic_cat
if automatic_cat == "มอดูลที่ไม่จัดหมวดหมู่" and not fallback_docs then --meaning module is not in user's sandbox or on of many datamodule boring series
cats[#cats + 1] = "แม่แบบและมอดูลที่ต้องการเอกสารการใช้งาน"
end
elseif title.nsText == "แม่แบบ" then
--cats[#cats + 1] = "แม่แบบที่ไม่จัดหมวดหมู่"
if not ( fallback_docs or args.nodoc ) then
cats[#cats + 1] = "แม่แบบและมอดูลที่ต้องการเอกสารการใช้งาน"
end
elseif (title.contentModel == "css") or (title.contentModel == "javascript") then
if user_name then
skin_name = skins[title.text:sub(#title.rootText + 1):match("^/([a-z]+)%.[jc]ss?$")]
if skin_name then
fallback_docs = 'documentation/fallback/user ' .. title.contentModel
end
end
end
if not args.nodoc then
output[#output + 1] =
"<dd><i style=\"font-size: larger;\">" .. pagetype .. "นี้ขาด[[วิธีใช้:การทำเอกสารการใช้งานแม่แบบและมอดูล|หน้าย่อยแสดงเอกสารการใช้งาน]] " ..
(fallback_docs and "คุณสามารถ" or "กรุณา") ..
"[" .. doc_title:fullUrl { action = 'edit', preload = preload } .. " สร้างขึ้น]</i></dd>\n"
end
end
if title.fullText:match("^มีเดียวิกิ:Gadget%-") then
local is_gadget = false
local gadget_list = mw.title.new("มีเดียวิกิ:Gadgets-definition"):getContent()
for line in mw.text.gsplit(gadget_list, "\n") do
local gadget, opts, items = line:match("^%*%s*([A-Za-z][A-Za-z0-9_%-]*)%[(.-)%]|(.+)$")
if not gadget then
gadget, items = line:match("^%*%s*([A-Za-z][A-Za-z0-9_%-]*)|(.+)$")
end
if gadget then
items = mw.text.split(items, "|")
for i, item in ipairs(items) do
if title.fullText == ("มีเดียวิกิ:Gadget-" .. item) then
is_gadget = true
output[#output + 1] = "<dd> ''สคริปต์นี้เป็นส่วนหนึ่งของอุปกรณ์เสริม <code>"
output[#output + 1] = gadget
output[#output + 1] = "</code> (["
output[#output + 1] = tostring(mw.uri.fullUrl('มีเดียวิกิ:Gadgets-definition', 'action=edit'))
output[#output + 1] = " แก้ไขการนิยาม])'' <dl>"
output[#output + 1] = "<dd> ''คำอธิบาย (["
output[#output + 1] = tostring(mw.uri.fullUrl('มีเดียวิกิ:Gadget-' .. gadget, 'action=edit'))
output[#output + 1] = " แก้ไข])'': "
output[#output + 1] = mw.message.new('Gadget-' .. gadget):plain()
output[#output + 1] = " </dd>"
table.remove(items, i)
if #items > 0 then
for j, item in ipairs(items) do
items[j] = '[[มีเดียวิกิ:Gadget-' .. item .. '|' .. item .. ']]'
end
output[#output + 1] = "<dd> ''ส่วนอื่น ๆ'': "
output[#output + 1] = mw.text.listToText(items)
output[#output + 1] = "</dd>"
end
output[#output + 1] = "</dl></dd>"
break
end
end
end
end
if not is_gadget then
output[#output + 1] = "<dd> ''สคริปต์นี้ไม่ได้เป็นส่วนหนึ่งของ ["
output[#output + 1] = tostring(mw.uri.fullUrl('พิเศษ:Gadgets', 'uselang=en'))
output[#output + 1] = ' อุปกรณ์เสริม] (['
output[#output + 1] = tostring(mw.uri.fullUrl('มีเดียวิกิ:Gadgets-definition', 'action=edit'))
output[#output + 1] = ' แก้ไขการนิยาม])</dd>'
--else
-- cats[#cats + 1] = "อุปกรณ์เสริมวิกิพจนานุกรม"
end
end
if old_title then
output[#output + 1] = "<dd> ''เปลี่ยนทางจาก'' ["
output[#output + 1] = old_title:fullUrl { redirect = 'no' }
output[#output + 1] = " "
output[#output + 1] = old_title.fullText
output[#output + 1] = "] (["
output[#output + 1] = old_title:fullUrl { action = 'edit' }
output[#output + 1] = " แก้ไข])</dd>\n"
end
local links = {}
if title.isSubpage and not args.notsubpage then
links[#links + 1] = "[[:" .. title.nsText .. ":" .. title.rootText .. "|หน้าราก]]"
links[#links + 1] = "[[พิเศษ:PrefixIndex/" .. title.nsText .. ":" .. title.rootText .. "/|หน้าย่อยของหน้าราก]]"
else
links[#links + 1] = "[[พิเศษ:PrefixIndex/" .. title.fullText .. "/|รายชื่อหน้าย่อย]]"
end
if (title.contentModel == "javascript") or (title.contentModel == "css") then
links[#links + 1] = "[[พิเศษ:WhatLinksHere/" .. title.fullText .. "|หน้าอื่นที่โยงมา]]"
if user_name then
links[#links + 1] = "[[พิเศษ:MyPage" .. title.text:sub(#title.rootText + 1) .. "|ของคุณเอง]]"
end
else
links[#links + 1] =
'[' .. tostring(mw.uri.fullUrl('พิเศษ:WhatLinksHere/' .. title.fullText, 'hidelinks=1&hideredirs=1')) ..
' การรวมมา]'
if title.contentModel ~= "Scribunto" then
links[#links + 1] =
'[' .. tostring(mw.uri.fullUrl('พิเศษ:WhatLinksHere/' .. title.fullText, 'hidelinks=1&hidetrans=1')) ..
' หน้าเปลี่ยนทาง]'
end
end
if title.contentModel == "Scribunto" then
if title.isSubpage and (title.subpageText == "testcases") then
links[#links + 1] = "[[:" .. title.nsText .. ":" .. title.baseText .. "|มอดูลทดสอบ]]"
else
links[#links + 1] = "[[" .. title.fullText .. "/testcases|มอดูลทดสอบ]]"
end
if user_name then
links[#links + 1] = "[[ผู้ใช้:" .. user_name .. "|หน้าผู้ใช้]]"
links[#links + 1] = "[[คุยกับผู้ใช้:" .. user_name .. "|หน้าคุยกับผู้ใช้]]"
links[#links + 1] = "[[พิเศษ:PrefixIndex/ผู้ใช้:" .. user_name .. "/|เนมสเปซผู้ใช้]]"
end
end
if #links > 0 then
output[#output + 1] =
"<dd> ''ลิงก์ที่เป็นประโยชน์'': " .. table.concat(links, " • ") .. "</dd>"
end
output[#output + 1] = "</dl>\n"
if doc_title.exists then
output[#output + 1] = frame:expandTemplate { title = doc_title.fullText }
elseif fallback_docs then
output[#output + 1] = frame:expandTemplate {
title = fallback_docs;
args = {
['user'] = user_name;
['page'] = title.fullText;
['skin name'] = skin_name;
}
}
end
if args.hr == "below" then
output[#output + 1] = '\n<hr style="clear: both;" />'
else
output[#output + 1] = '\n<br style="clear: both;" />'
end
for _, cat in ipairs(cats) do
output[#output + 1] = "[[หมวดหมู่:" .. cat .. "]]"
end
output[#output + 1] = "</div>\n"
return table.concat(output)
end
function export.translitModuleLangList(frame)
local output = {}
local pagename, subpage
if frame.args[1] then
pagename = frame.args[1]
else
local title = mw.title.getCurrentTitle()
subpage = title.subpageText
pagename = title.text
if subpage ~= pagename then
pagename = title.rootText
end
end
local translitModule = pagename
local languageObjects = require("Module:languages/byTranslitModule")(translitModule)
local codeInPagename = mw.ustring.match(pagename, "^(.-)%-translit")
if not codeInPagename then
return ""
end
local langs = {}
local codeInPagenameInList = false
local category = ""
if #languageObjects ~= 0 and subpage ~= "documentation" then
local agreement = #languageObjects == 1 and "" or "s"
category = "[[หมวดหมู่:Transliteration modules used by " .. #languageObjects .. " language" .. agreement .. "]]"
end
for i, lang in pairs(languageObjects) do
if lang:getCode() == codeInPagename then
table.remove(languageObjects, i)
codeInPagenameInList = true
end
end
if #languageObjects == 0 then
return category or ""
elseif #languageObjects > 2 then
for i, lang in pairs(languageObjects) do
table.insert(langs, "[[:หมวดหมู่:" .. lang:getCategoryName() .. "|" .. lang:getCanonicalName() .. "]] (<code>" .. lang:getCode() .. "</code>)")
if languageObjects[i + 2] then
table.insert(langs, ", ")
elseif languageObjects[i + 1] then
table.insert(langs, '<span class="serial-comma">,</span> and ')
end
end
else
for i, lang in pairs(languageObjects) do
table.insert(langs, "[[:หมวดหมู่:" .. lang:getCategoryName() .. "|" .. lang:getCanonicalName() .. "]] (<code>" .. lang:getCode() .. "</code>)")
if languageObjects[i + 1] then
table.insert(langs, " และ ")
end
end
end
langs = table.concat(langs)
return "It is " .. ( codeInPagenameInList and "also" or "" ) ..
" used to transliterate " .. langs .. "." .. category
end
return export