匿名
未登录
中文(中国大陆)
登录
深色模式
「荏苒之境」
搜索
查看“︁模块:FeaturedPage”︁的源代码
来自「荏苒之境」
命名空间
模块
讨论
更多
更多
页面操作
阅读
查看源代码
历史
清除缓存
←
模块:FeaturedPage
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local translation = require("Module:Template translation") local utils_str = require("Module:Utils/String") local featured_page = {} local API_EXTRACT_TEMPALTE = "http://localhost/api.php?action=query&prop=extracts&exintro&exchars=256&redirects=1&format=json&titles=" local API_IMAGES_TEMPLATE = "http://localhost/api.php?action=query&prop=pageimages&pithumbsize=512&redirects=1&format=json&titles=" local function get_random_title(namespace, title_match) while true do local title_text = mw.site.randomPages(1, namespace, title_match)[1] if title_text == nil then return end title_text = title_match == nil and string.match(title_text, "([^/]+)") or title_text return title_text end end local function get_page_summary(title) local d, e = mw.ext.externaldata.getExternalData { url = API_EXTRACT_TEMPALTE..title, format = "json" } if e then error("发起请求失败") end local page = d[1]["__json"]["query"]["pages"][1] return page["extract"], page["title"] end local function get_page_image(title) local d, e = mw.ext.externaldata.getExternalData { url = API_IMAGES_TEMPLATE..title, format = "json" } if e then error("发起请求失败") end return d[1]["__json"]["query"]["pages"][1]["pageimage"] end local function get_featured_page(language, messages) local checked_titles = {} local title_match = (language ~= nil and language ~= "zh-cn") and "%/"..language or nil while true do local title for i = 1, 10 do title = get_random_title(0, title_match) if title == nil then break elseif not checked_titles[title] then checked_titles[title] = true if string.find(title, "首页") ~= 1 then break end end title = nil end if title == nil then return messages.no_article_text end local extract, real_title = get_page_summary(title) checked_titles[real_title] = true if extract ~= nil and extract ~= "" and not string.find(extract, "^%<p%>%<span.-%>%</span%>[\n\r%s]*%</p%>$") then extract = utils_str.replace( extract, real_title, "[["..real_title.."]]", 1) local pageimage = get_page_image(title) if pageimage then extract = "[[File:"..pageimage.."|200px|right]]"..extract end if string.find(extract, "…$") then extract = string.sub(extract, 1, #extract - 7).."…" else extract = string.sub(extract, 1, #extract - 4) end return extract.."[["..real_title.."|"..messages.link_text.."]]</p>" end end end featured_page.get_random_title = get_random_title featured_page.get_page_summary = get_page_summary featured_page.get_page_image = get_page_image featured_page.get_featured_page = get_featured_page featured_page.show = function(frame) local language = translation.getFrameLanguage(frame) return get_featured_page(language, frame.args) end return featured_page
该页面使用的模板:
模块:FeaturedPage/doc
(
查看源代码
)
返回
模块:FeaturedPage
。
导航
导航
最近更改
随机页面
特殊页面
模板列表
wiki工具
wiki工具
Cargo数据
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志