模块:FeaturedPage:修订间差异
来自「荏苒之境」
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
第1行: | 第1行: | ||
local featured_page = {} | local featured_page = {} | ||
local function get_random_title(namespace, root_page_only) | |||
root_page_only = root_page_only or true | |||
while true do | while true do | ||
local title_text = mw.site.randomPages(1, | local title_text = mw.site.randomPages(1, namespace)[1] | ||
if not string.match(title_text, ":") then | if not string.match(title_text, ":") then | ||
title_text = root_page_only | |||
string.match(title_text, "([^/]+)")) | and string.match(title_text, "([^/]+)") or title_text | ||
return title | local title = mw.title.new(title_text) | ||
if not title.isRedirect then | |||
return title | |||
end | |||
end | end | ||
end | end | ||
end | |||
featured_page.get_random_title = get_random_title | |||
featured_page.show = function(frame) | |||
return get_random_title(0) | |||
end | end | ||
return featured_page | return featured_page |
2025年8月20日 (三) 16:10的版本
此模块的文档可以在模块:FeaturedPage/doc创建
local featured_page = {}
local function get_random_title(namespace, root_page_only)
root_page_only = root_page_only or true
while true do
local title_text = mw.site.randomPages(1, namespace)[1]
if not string.match(title_text, ":") then
title_text = root_page_only
and string.match(title_text, "([^/]+)") or title_text
local title = mw.title.new(title_text)
if not title.isRedirect then
return title
end
end
end
end
featured_page.get_random_title = get_random_title
featured_page.show = function(frame)
return get_random_title(0)
end
return featured_page