模組:Is article
呢個模組用到Lua語言: |
Module:Is article is used to determine if a given page is an article, a redirect, a disambiguation page, does not exist or a bad title.
Usage
編輯Return values
編輯Result | Return value |
---|---|
Article | article |
Redirect | redirect |
Disambiguation page | dab |
Page does not exist | empty |
bad title | badtitle |
Parameter list
編輯Parameter | Explanation |
---|---|
1
|
Positional or numbered parameter; The page name title. |
上面嘅解係穿透包含咗自模組:Is article/doc。 (改 | 史) 編者可以響呢個模組嘅沙盤 (開 | 鏡)同埋試例 (開)版度試驗佢。 呢個模組嘅細版。 |
local p = {}
local disambiguationTemplates = {
"[Dd]isambiguation",
"[Dd]isambig",
"[Dd]isamb",
"[Dd]ab",
"[Ss]urname",
"[Tt]emplate disambiguation",
}
function p.main(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
local page = mw.title.new(args[1], 0)
if not page then
return "badtitle"
end
if not page.exists then
return "empty"
end
if page.isRedirect then
return "redirect"
end
local content = page:getContent()
if content then
content = string.gsub(content, "noinclude", "<!-- noinclude -->")
for _, name in ipairs(disambiguationTemplates) do
if content:match("{{%s?" .. name .. "%s?}}") and not content:match("{{{%s?" .. name .. "%s?}}}") then -- to disable false positives in parameter names {{{disamb}}}
return "dab"
end
end
end
return "article"
end
return p