Difference between revisions of "Module:Is article"

From blackwiki
Jump to navigation Jump to search
blackwiki>Gonnym
m (6 revisions imported)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
 +
 +
local disambiguationTemplates = {
 +
"[Dd]isambiguation",
 +
"[Dd]isambig",
 +
"[Dd]isamb",
 +
"[Dd]ab",
 +
"[Ss]urname"
 +
}
  
 
function p.main(frame)
 
function p.main(frame)
Line 6: Line 14:
 
title = args[1]
 
title = args[1]
 
page = mw.title.new(title, 0)
 
page = mw.title.new(title, 0)
 +
 +
if (not page) then
 +
return "badtitle"
 +
end
  
 
if (not page.exists) then
 
if (not page.exists) then
Line 16: Line 28:
  
 
local content = page:getContent()
 
local content = page:getContent()
if content and content:match('{{%s*[Dd]isambig%a*%s*}}') or content:match('{{%s*[Dd]ab%s*}}') then
+
if (content) then
return "dab"
+
for i, name in ipairs(disambiguationTemplates) do
 +
if (content:match('{{%s*' .. name .. '.*}}')) then
 +
return "dab"
 +
end
 +
end
 
end
 
end
  

Latest revision as of 05:44, 27 September 2020

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

Results and 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.



local p = {}

local disambiguationTemplates = {
	"[Dd]isambiguation",
	"[Dd]isambig",
	"[Dd]isamb",
	"[Dd]ab",
	"[Ss]urname"
	}

function p.main(frame)
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)
	title = args[1]
	page = mw.title.new(title, 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
		for i, name in ipairs(disambiguationTemplates) do
			if (content:match('{{%s*' .. name .. '.*}}')) then
				return "dab"
			end
		end
	end

	return "article"
end

return p