模块:Dictionary-Entry.lua:修订间差异
来自「荏苒之境」
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
local csv = require("Module:Csv.lua") | |||
local dict_views = require("Module:Dictionary-Views.lua") | |||
local DICT_TABLE = dict_views.TABLE | |||
local html = mw.html | local html = mw.html | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local entry = {} | local entry = {} | ||
第12行: | 第13行: | ||
local spelling = args.spelling | local spelling = args.spelling | ||
local r = cargo.query(DICT_TABLE, "Definition, | local r = cargo.query(DICT_TABLE, "Definition,Extra,_pageName", { | ||
where = string.format( | where = string.format( | ||
[[Language="%s" AND Spelling="%s"]], | [[Language="%s" AND Spelling="__META__" OR Spelling="%s"]], | ||
language, spelling, tonumber(args.priority)) | language, spelling, tonumber(args.priority)) | ||
}) | }) | ||
if r == nil then | local headers | ||
local word | |||
if r[1].Spelling == "__META__" then | |||
headers = r[1] | |||
word = r[2] | |||
else | |||
headers = r[2] | |||
word = r[1] | |||
end | |||
if word == nil then | |||
return "词典条目不存在:"..spelling | return "词典条目不存在:"..spelling | ||
end | end | ||
local view = html.create('div') | local view = html.create('div') | ||
:tag('p'):wikitext( | :tag('p'):wikitext(word.Definition):done() | ||
:tag('p'):wikitext("来源:[[".. | :tag('p'):wikitext("来源:[["..word._pageName.."]]"):done() | ||
local headers_extra = csv.parse_row(headers.Extra) | |||
local word_extra = csv.parse_row(word.Extra) | |||
for i = 1, #word_extra do | |||
local header = headers_extra[i] or "<i>未知标题/i>" | |||
view:tag('h2'):wikitext(header):done() | |||
:tag('p'):wikitext(word_extra[i]):done() | |||
view:tag('h2'):wikitext( | |||
:tag('p'):wikitext( | |||
end | end | ||
2025年8月4日 (一) 17:11的版本
此模块的文档可以在模块:Dictionary-Entry.lua/doc创建
local csv = require("Module:Csv.lua")
local dict_views = require("Module:Dictionary-Views.lua")
local DICT_TABLE = dict_views.TABLE
local html = mw.html
local cargo = mw.ext.cargo
local entry = {}
entry.show = function(frame)
local args = frame.args
local language = args.language
local spelling = args.spelling
local r = cargo.query(DICT_TABLE, "Definition,Extra,_pageName", {
where = string.format(
[[Language="%s" AND Spelling="__META__" OR Spelling="%s"]],
language, spelling, tonumber(args.priority))
})
local headers
local word
if r[1].Spelling == "__META__" then
headers = r[1]
word = r[2]
else
headers = r[2]
word = r[1]
end
if word == nil then
return "词典条目不存在:"..spelling
end
local view = html.create('div')
:tag('p'):wikitext(word.Definition):done()
:tag('p'):wikitext("来源:[["..word._pageName.."]]"):done()
local headers_extra = csv.parse_row(headers.Extra)
local word_extra = csv.parse_row(word.Extra)
for i = 1, #word_extra do
local header = headers_extra[i] or "<i>未知标题/i>"
view:tag('h2'):wikitext(header):done()
:tag('p'):wikitext(word_extra[i]):done()
end
return view
end
return entry