Difference between revisions of "Module:Check card number/sandbox"
Dinoguy1000 (talk | contribs) (`page` is a title object, not a string containing a pagename) |
Dinoguy1000 (talk | contribs) (that doesn't work either I guess) |
||
(7 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
local targets = {} | local targets = {} | ||
if isRedirect then | if isRedirect then | ||
− | table.insert( targets, | + | local target = page.redirectTarget |
+ | if target then | ||
+ | table.insert( targets, target.prefixedText ) | ||
+ | end | ||
else | else | ||
local pageSrc = page:getContent() | local pageSrc = page:getContent() | ||
− | if pageSrc:find( ' | + | if pageSrc:find( '[Dd]isambig' ) then |
− | for target in | + | for target in mw.text.gsplit( pageSrc, '%[%[' ) do |
− | table.insert( targets, | + | table.insert( targets, target:match( '^([^%]|]-)%]%]' ) or target:match( '^([^%]|]-)|[^%]]-%]%]' ) ) |
end | end | ||
else | else | ||
Line 22: | Line 25: | ||
local searchStr = ( '%s%s;' ):format ('%s', page.prefixedText:gsub( '%-', '%%-' ) ) | local searchStr = ( '%s%s;' ):format ('%s', page.prefixedText:gsub( '%-', '%%-' ) ) | ||
− | for target in targets do | + | for _, target in ipairs( targets ) do |
local success, targetTitle = pcall( mw.title.new, target ) | local success, targetTitle = pcall( mw.title.new, target ) | ||
− | if | + | if success and targetTitle then |
− | + | local targetSrc = targetTitle:getContent() | |
− | + | if not targetSrc:find( searchStr ) then | |
− | + | return isRedirect and '[[Category:Potentially invalid card number redirects]]' or '[[Category:Card number disambiguation pages to be checked]]' | |
− | + | end | |
− | |||
− | |||
end | end | ||
end | end |
Latest revision as of 17:14, 26 July 2023
This is the module sandbox page for Module:Check card number (diff). |
Rudimentary Card Number validity check for Template:R from card number.
-- super rudimentary check for potentially invalid card numbers
local p = {}
function p.check()
local page = mw.title.getCurrentTitle()
local isRedirect = page.isRedirect
local targets = {}
if isRedirect then
local target = page.redirectTarget
if target then
table.insert( targets, target.prefixedText )
end
else
local pageSrc = page:getContent()
if pageSrc:find( '[Dd]isambig' ) then
for target in mw.text.gsplit( pageSrc, '%[%[' ) do
table.insert( targets, target:match( '^([^%]|]-)%]%]' ) or target:match( '^([^%]|]-)|[^%]]-%]%]' ) )
end
else
-- some page that isn't a redirect or a dabpage, just return without doing anything
return
end
end
local searchStr = ( '%s%s;' ):format ('%s', page.prefixedText:gsub( '%-', '%%-' ) )
for _, target in ipairs( targets ) do
local success, targetTitle = pcall( mw.title.new, target )
if success and targetTitle then
local targetSrc = targetTitle:getContent()
if not targetSrc:find( searchStr ) then
return isRedirect and '[[Category:Potentially invalid card number redirects]]' or '[[Category:Card number disambiguation pages to be checked]]'
end
end
end
return
end
return p