Module:Extract:修订间差异
武外梗百科 爱国好学自强图新的百科全书
更多操作
创建页面,内容为“local p = {} function p.extractLead(page, sentences) sentences = tonumber(sentences) or 2 local title = mw.title.new(page) if not title or not title.exists then return "" end local api = mw.ext.Api local result = api:get({ action = "query", prop = "extracts", exsentences = sentences, explaintext = true, titles = page }) local pages = result.query and result.query.pages if not…” |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
function p.extractLead(page | function p.extractLead(frame) | ||
sentences = tonumber( | -- 参数 | ||
local page = frame.args[1] | |||
local sentences = tonumber(frame.args[2]) or 2 | |||
if not page or page == "" then | |||
return "" | |||
end | |||
local title = mw.title.new(page) | local title = mw.title.new(page) | ||
if not title or not title.exists then | if not title or not title.exists then | ||
| 第17行: | 第24行: | ||
}) | }) | ||
if not result or not result.query or not result.query.pages then | |||
return "" | return "" | ||
end | end | ||
for _, v in pairs(pages) do | for _, v in pairs(result.query.pages) do | ||
return v.extract or "" | return v.extract or "" | ||
end | end | ||