You can edit almost every page by Creating an account and confirming your email.

Module:Iucn: Difference between revisions

From EverybodyWiki Bios & Wiki
WikiMasterBot2 (talk | contribs)
Add new revision
 
WikiMasterBot2 (talk | contribs)
m Add new revision
 
Line 1: Line 1:
local p = {}
local p = {}


local data = { -- these data entries will ultimately go in data subpage or series of data subpages
local data = { -- these data entries will ultimately go in data subpage or series of data subpages **NOT USED**
iucn = {  
iucn = {
['_template'] = "cite journal", -- use cite journal  
['_template'] = "cite journal", -- use cite journal
        ['_exclude'] = "amended, url" ,  -- do not pass these to {{cite journal}}
['_exclude'] = "amended, url" ,  -- do not pass these to {{cite journal}}
                                        --_alias-map: associate {{IUCN}}-specific parameter names with cs1|2-standard parameter names  
--_alias-map: associate {{IUCN}}-specific parameter names with cs1|2-standard parameter names
    ['_alias-map'] =  "assessors : authors, vassessors : vauthors, assessor# : last#, assessor#-link : author#-link,assessor-link# : author-link#, assessorlink# : authorlink#, assessor#-mask : author#-mask, assessor-mask# : author-mask#, assessormask# : authormask#, display-assessors : display-authors, displayassessors : displayauthors, last-assessor-amp : last-author-amp, lastassessoramp : lastauthoramp, assessment_year : year, taxon : title, downloaded : access-date"
['_alias-map'] =  "assessors : authors, vassessors : vauthors, assessor# : last#, assessor#-link : author#-link,assessor-link# : author-link#, assessorlink# : authorlink#, assessor#-mask : author#-mask, assessor-mask# : author-mask#, assessormask# : authormask#, display-assessors : display-authors, displayassessors : displayauthors, last-assessor-amp : last-author-amp, lastassessoramp : lastauthoramp, assessment_year : year, taxon : title, downloaded : access-date"
}
}
}
}


function getArgs (frame, args)
local function getArgs (frame, args)
local parents = mw.getCurrentFrame():getParent()
local parents = mw.getCurrentFrame():getParent()
 
for k,v in pairs(parents.args) do
for k,v in pairs(parents.args) do
--check content
--check content
Line 32: Line 32:
--local parents = mw.getCurrentFrame():getParent()
--local parents = mw.getCurrentFrame():getParent()


local templateArgs = {}  
local templateArgs = {}
    getArgs (frame, templateArgs)
getArgs (frame, templateArgs)
 
--we only want to make changes if there is old-style url, i.e. one containing "/details/"
--we only want to make changes if there is old-style url, i.e. one containing "/details/"
local url = templateArgs['url'] or ""
local url = templateArgs['url'] or ""
local old = string.find( url, "details" , 1, true)
local old = string.find( url, "details" , 1, true)
if old then
if old then
        local page = templateArgs['page']
local page = templateArgs['page'] or ""
    local speciesID = string.match( page, "T(%d+)A" )  
local speciesID = string.match( page, "T(%d+)A" )
    local speciesAssessment = string.match( page, "A(%d+)" )
local speciesAssessment = string.match( page, "A(%d+)" )
    if speciesID  and speciesAssessment then -- set new style url
if speciesID  and speciesAssessment then -- set new style url
      templateArgs['url'] = "https://www.iucnredlist.org/species/" .. speciesID .. '/' .. speciesAssessment  
templateArgs['url'] = "https://www.iucnredlist.org/species/" .. speciesID .. '/' .. speciesAssessment
        end
end
end
end
if templateArgs['amended'] then templateArgs['trans-title']=templateArgs['amended'] end -- use translated title parameter to add amended text, e.g. "amended version of 2016 assessment", which will be added in square brackets after title
if templateArgs['amended'] then templateArgs['trans-title']=templateArgs['amended'] end -- use translated title parameter to add amended text, e.g. "amended version of 2016 assessment", which will be added in square brackets after title
Line 50: Line 50:
return frame:expandTemplate{ title = 'cite journal', args = templateArgs }
return frame:expandTemplate{ title = 'cite journal', args = templateArgs }
--return frame:expandTemplate{ title = 'cite journal', args = parents.args }
--return frame:expandTemplate{ title = 'cite journal', args = parents.args }
end
end
-- version using template wrapper for cite journal
-- version using template wrapper for cite journal
function p.cite2(frame)
function p.cite2(frame)


    -- now use wrapper template
-- now use wrapper template
   
 
    --[[this doesn't work
--[[this doesn't work
     frame.args['_alias-map'] =  "assessors : authors, vassessors : vauthors, assessor# : last#, assessor#-link : author#-link,assessor-link# : author-link#, assessorlink# : authorlink#, assessor#-mask : author#-mask, assessor-mask# : author-mask#, assessormask# : authormask#, display-assessors : display-authors, displayassessors : displayauthors, last-assessor-amp : last-author-amp, lastassessoramp : lastauthoramp, assessment_year : year, taxon : title, downloaded : access-date"
     frame.args['_alias-map'] =  "assessors : authors, vassessors : vauthors, assessor# : last#, assessor#-link : author#-link,assessor-link# : author-link#, assessorlink# : authorlink#, assessor#-mask : author#-mask, assessor-mask# : author-mask#, assessormask# : authormask#, display-assessors : display-authors, displayassessors : displayauthors, last-assessor-amp : last-author-amp, lastassessoramp : lastauthoramp, assessment_year : year, taxon : title, downloaded : access-date"
     frame.args['_template'] = "cite journal"
     frame.args['_template'] = "cite journal"
     but the following does ]]
     but the following does ]]
 
 
    local wrapperArgs ={}
local wrapperArgs ={}
    wrapperArgs['_template'] = "cite journal"
wrapperArgs['_template'] = "cite journal"
    --|_exclude=id, version, new, IUCN_Year, iucn_year, criteria-version <!-- do not pass these to {{cite journal}} -->
--|_exclude=id, version, new, IUCN_Year, iucn_year, criteria-version <!-- do not pass these to {{cite journal}} -->
    wrapperArgs['_exclude'] = "amended, url" -- exclude url (from parent) as we wanted updated version
wrapperArgs['_exclude'] = "amended, url" -- exclude url (from parent) as we wanted updated version
    --|_alias-map= <!-- associate {{IUCN}}-specific parameter names with cs1|2-standard parameter names -->
--|_alias-map= <!-- associate {{IUCN}}-specific parameter names with cs1|2-standard parameter names -->
    wrapperArgs['_alias-map'] =  "assessors : authors, vassessors : vauthors, assessor# : last#, assessor#-link : author#-link,assessor-link# : author-link#, assessorlink# : authorlink#, assessor#-mask : author#-mask, assessor-mask# : author-mask#, assessormask# : authormask#, display-assessors : display-authors, displayassessors : displayauthors, last-assessor-amp : last-author-amp, lastassessoramp : lastauthoramp, assessment_year : year, taxon : title, downloaded : access-date"
wrapperArgs['_alias-map'] =  "assessors : authors, vassessors : vauthors, assessor# : last#, assessor#-link : author#-link,assessor-link# : author-link#, assessorlink# : authorlink#, assessor#-mask : author#-mask, assessor-mask# : author-mask#, assessormask# : authormask#, display-assessors : display-authors, displayassessors : displayauthors, last-assessor-amp : last-author-amp, lastassessoramp : lastauthoramp, assessment_year : year, taxon : title, downloaded : access-date"




local templateArgs = {}  -- need a copy to alter and pass to citation template
local templateArgs = {}  -- need a copy to alter and pass to citation template
    getArgs (frame, templateArgs)
getArgs (frame, templateArgs)
 
--we only want to make changes if there is old-style url, i.e. one containing "/details/"
--we only want to make changes if there is old-style url, i.e. one containing "/details/"
local url = templateArgs['url'] or ""
local url = templateArgs['url'] or ""
Line 78: Line 78:


if replace  then
if replace  then
        local page = templateArgs['page'] or ""
local page = templateArgs['page'] or ""
    local speciesID = string.match( page, "T(%d+)A" )  
local speciesID = string.match( page, "T(%d+)A" )
    local speciesAssessment = string.match( page, "A(%d+)" )
local speciesAssessment = string.match( page, "A(%d+)" )
    if speciesID  and speciesAssessment then -- set new style url
if speciesID  and speciesAssessment then -- set new style url
      wrapperArgs['url'] = "https://www.iucnredlist.org/species/" .. speciesID .. '/' .. speciesAssessment  
wrapperArgs['url'] = "https://www.iucnredlist.org/species/" .. speciesID .. '/' .. speciesAssessment
        end
end
else
else
wrapperArgs['url']=templateArgs['url']  
wrapperArgs['url']=templateArgs['url']
end
end
if url == "" and templateArgs['id'] then -- use oldstyle url
if url == "" and templateArgs['id'] then -- use oldstyle url
wrapperArgs['url'] = "http://oldredlist.iucnredlist.org/details/" .. templateArgs['id']  
wrapperArgs['url'] = "http://oldredlist.iucnredlist.org/details/" .. templateArgs['id']
wrapperArgs['journal'] = '[[IUCN Red List of Threatened Species]]'
wrapperArgs['journal'] = '[[IUCN Red List of Threatened Species]]'
wrapperArgs['volume'] = 'Version ' .. templateArgs['version']
wrapperArgs['volume'] = 'Version ' .. templateArgs['version']
end
end
if templateArgs['amended'] then wrapperArgs['trans-title']=templateArgs['amended'] end -- use translated title parameter to add amended text, e.g. "amended version of 2016 assessment", which will be added in square brackets after title
if templateArgs['amended'] then wrapperArgs['trans-title']=templateArgs['amended'] end -- use translated title parameter to add amended text, e.g. "amended version of 2016 assessment", which will be added in square brackets after title
    --wrapperArgs['trans-title'] = templateArgs['trans-title']
--wrapperArgs['trans-title'] = templateArgs['trans-title']
 
frame.args=wrapperArgs --set the wrapper arguments


 
local wrapper = require("Module:Template wrapper/sandbox")
   
 
   
--local xframe = frame --mw.clone(frame)  --mw.getCurrentFrame()
    frame.args=wrapperArgs --set the wrapper arguments
--frame.args.metatable['_template'] = "cite journal"
 
    local wrapper = require("Module:Template wrapper/sandbox")
 
    --local xframe = frame --mw.clone(frame)  --mw.getCurrentFrame()
    --frame.args.metatable['_template'] = "cite journal"
--local parents = xframe:getParent() --mw.getCurrentFrame():getParent()
--local parents = xframe:getParent() --mw.getCurrentFrame():getParent()
    --parents.args['_template'] = "cite journal"
--parents.args['_template'] = "cite journal"


  --mw.logObject(frame)
--mw.logObject(frame)
  --return  mw.dumpObject(wrapperArgs)
--return  mw.dumpObject(wrapperArgs)
  return wrapper.wrap(frame)
return wrapper.wrap(frame)


end
end
--[[ function to replace iucn templates
--[[ function to replace iucn templates
     test template: Template:IUCN/sandbox/lua
     test template: Template:IUCN/sandbox/lua
Line 117: Line 114:
--]]
--]]
function p.main(frame)
function p.main(frame)
 
local templateArgs = {}  -- need a copy to alter and pass to citation template
local templateArgs = {}  -- need a copy to alter and pass to citation template
    getArgs (frame, templateArgs)
getArgs (frame, templateArgs)
   
 
-- local parents = mw.getCurrentFrame():getParent()
-- local parents = mw.getCurrentFrame():getParent()
local reference = ""
local reference = ""
local taxon =templateArgs['taxon']
local taxon =templateArgs['taxon']
 
reference = '{{cite journal |title=' .. taxon  
reference = '{{cite journal |title=' .. taxon
local maxAssessors = 20
local maxAssessors = 20
local assessorNumber =0
local assessorNumber =0
 
-- if 'assessor' instead of 'assessor1'
-- if 'assessor' instead of 'assessor1'
if templateArgs['assessor'] then templateArgs['assessor1'] = templateArgs['assessor'] end  
if templateArgs['assessor'] then templateArgs['assessor1'] = templateArgs['assessor'] end
if templateArgs['assessor-link'] then templateArgs['assessor-link1'] = templateArgs['assessor-link'] end  
if templateArgs['assessor-link'] then templateArgs['assessor-link1'] = templateArgs['assessor-link'] end
 
while assessorNumber < maxAssessors do -- use the last number determined in the preprocessing
while assessorNumber < maxAssessors do -- use the last number determined in the preprocessing


assessorNumber  = assessorNumber  + 1 -- so we start with 1
assessorNumber  = assessorNumber  + 1 -- so we start with 1
local assessorName = templateArgs['assessor'..tostring(assessorNumber)] or ""
local assessorName = templateArgs['assessor'..tostring(assessorNumber)] or ""
if assessorName ~= "" then
if assessorName ~= "" then
reference = reference .. ' |author' .. assessorNumber .. '=' .. assessorName
reference = reference .. ' |author' .. assessorNumber .. '=' .. assessorName
    end
end
local assessorLink = templateArgs['assessor-link'..tostring(assessorNumber)]
local assessorLink = templateArgs['assessor-link'..tostring(assessorNumber)]
                    or templateArgs['assessor'..tostring(assessorNumber)..'link']  
or templateArgs['assessor'..tostring(assessorNumber)..'link']
                    or templateArgs['assessorlink'..tostring(assessorNumber)]or ""
or templateArgs['assessorlink'..tostring(assessorNumber)]or ""
if assessorLink ~= "" then
if assessorLink ~= "" then
reference = reference .. ' |authorlink' .. assessorNumber .. '=' .. assessorLink
reference = reference .. ' |authorlink' .. assessorNumber .. '=' .. assessorLink
    end      
end
end
local year = templateArgs['year']
local id = templateArgs['id']
local assessment = templateArgs['assessment'] or ""
local version = templateArgs['version']
local doi = templateArgs['doi'] or ""
local accessdate = templateArgs['accessdate'] or ""
 
reference = reference ..
' |year=' .. year
" |version=''Version "..  version .. "''" ..
' |journal=[[The IUCN Red List of Threatened Species]]' ..
' |accessdate='.. accessdate ..
' |doi='.. doi
 
if assessment ~= "" then
reference = reference .. '|url=https://www.iucnredlist.org/species/'.. id .. '/' .. assessment
else  -- if there is no assessment number, use oldredlist.iucnredlist.org version
-- an alternative might be to use archive.org in case this cite is dropped
reference = reference .. '|url=http://oldredlist.iucnredlist.org/details/'.. id .. '/0'
end


    end
reference = reference .. ' |publisher=[[International Union for Conservation of Nature]]}}'
    local year = templateArgs['year']
    local id = templateArgs['id']
    local assessment = templateArgs['assessment'] or ""
    local version = templateArgs['version']
    local doi = templateArgs['doi'] or ""
    local accessdate = templateArgs['accessdate'] or ""
   
   
   
   
    reference = reference .. ' |year='.. year
    reference = reference .. " |version=''Version "..  version .. "''"
    reference = reference .. ' |journal=[[The IUCN Red List of Threatened Species]]'
    reference = reference .. ' |accessdate='.. accessdate
    reference = reference .. ' |doi='.. doi


    if assessment ~= "" then
return frame:preprocess(reference)
      reference = reference .. '|url=https://www.iucnredlist.org/species/'.. id .. '/' .. assessment
--return reference
    else  -- if there is no assessment number, use oldredlist.iucnredlist.org version
        -- an alternative might be to use archive.org in case this cite is dropped
      reference = reference .. '|url=http://oldredlist.iucnredlist.org/details/'.. id .. '/0'
    end
   
    reference = reference .. ' |publisher=[[International Union for Conservation of Nature]]}}'
   
    return frame:preprocess(reference)
    --return reference
end
end


return p
return p

Latest revision as of 11:28, 20 April 2019

Documentation for this module may be created at Module:Iucn/doc

local p = {}

local data = { -- these data entries will ultimately go in data subpage or series of data subpages **NOT USED**
	iucn = {
		['_template'] = "cite journal", -- use cite journal
		['_exclude'] = "amended, url" ,  -- do not pass these to {{cite journal}}
				--_alias-map: associate {{IUCN}}-specific parameter names with cs1|2-standard parameter names
		['_alias-map'] =  "assessors : authors, vassessors : vauthors, assessor# : last#, assessor#-link : author#-link,assessor-link# : author-link#, assessorlink# : authorlink#, assessor#-mask : author#-mask, assessor-mask# : author-mask#, assessormask# : authormask#, display-assessors : display-authors, displayassessors : displayauthors, last-assessor-amp : last-author-amp, lastassessoramp : lastauthoramp, assessment_year : year, taxon : title, downloaded : access-date"
	}
}

local function getArgs (frame, args)
	local parents = mw.getCurrentFrame():getParent()

	for k,v in pairs(parents.args) do
		--check content
		if v and v ~= "" then
			args[k]=v --parents.args[k]
		end
	end
end
--[[ function p.cite() - function wrapping {{cite journal}}
     takes cite journal parameters but updates old style url using electronic page number
     page should be in format e.T13922A45199653
     the url uses                13922/45199653
     so we need to extract the number between T and A and the number after A
     the target url is https://www.iucnredlist.org/species/13922/45199653
     usage: {{#invoke:iucn|cite}}
     template: {{Template:Cite iucn}}
--]]
function p.cite(frame)
	--local parents = mw.getCurrentFrame():getParent()

	local templateArgs = {}
	getArgs (frame, templateArgs)

	--we only want to make changes if there is old-style url, i.e. one containing "/details/"
	local url = templateArgs['url'] or ""
	local old = string.find( url, "details" , 1, true)
	if old then
		local page = templateArgs['page'] or ""
		local speciesID = string.match( page, "T(%d+)A" )
		local speciesAssessment = string.match( page, "A(%d+)" )
		if speciesID  and speciesAssessment then -- set new style url
			templateArgs['url'] = "https://www.iucnredlist.org/species/" .. speciesID .. '/' .. speciesAssessment
		end
	end
	if templateArgs['amended'] then templateArgs['trans-title']=templateArgs['amended'] end -- use translated title parameter to add amended text, e.g. "amended version of 2016 assessment", which will be added in square brackets after title

	return frame:expandTemplate{ title = 'cite journal', args = templateArgs }
	--return frame:expandTemplate{ title = 'cite journal', args = parents.args }
end
-- version using template wrapper for cite journal
function p.cite2(frame)

	-- now use wrapper template

	--[[this doesn't work
    frame.args['_alias-map'] =  "assessors : authors, vassessors : vauthors, assessor# : last#, assessor#-link : author#-link,assessor-link# : author-link#, assessorlink# : authorlink#, assessor#-mask : author#-mask, assessor-mask# : author-mask#, assessormask# : authormask#, display-assessors : display-authors, displayassessors : displayauthors, last-assessor-amp : last-author-amp, lastassessoramp : lastauthoramp, assessment_year : year, taxon : title, downloaded : access-date"
    frame.args['_template'] = "cite journal"
    but the following does ]]

	local wrapperArgs ={}
	wrapperArgs['_template'] = "cite journal"
	--|_exclude=id, version, new, IUCN_Year, iucn_year, criteria-version <!-- do not pass these to {{cite journal}} -->
	wrapperArgs['_exclude'] = "amended, url" -- exclude url (from parent) as we wanted updated version
	--|_alias-map= <!-- associate {{IUCN}}-specific parameter names with cs1|2-standard parameter names -->
	wrapperArgs['_alias-map'] =  "assessors : authors, vassessors : vauthors, assessor# : last#, assessor#-link : author#-link,assessor-link# : author-link#, assessorlink# : authorlink#, assessor#-mask : author#-mask, assessor-mask# : author-mask#, assessormask# : authormask#, display-assessors : display-authors, displayassessors : displayauthors, last-assessor-amp : last-author-amp, lastassessoramp : lastauthoramp, assessment_year : year, taxon : title, downloaded : access-date"


	local templateArgs = {}   -- need a copy to alter and pass to citation template
	getArgs (frame, templateArgs)

	--we only want to make changes if there is old-style url, i.e. one containing "/details/"
	local url = templateArgs['url'] or ""
	local replace = string.find( url, "details" , 1, true)    -- replace url if contains "details"
	if url == "" and templateArgs['page'] then replace = true end -- if no url and page number available,

	if replace  then
		local page = templateArgs['page'] or ""
		local speciesID = string.match( page, "T(%d+)A" )
		local speciesAssessment = string.match( page, "A(%d+)" )
		if speciesID  and speciesAssessment then -- set new style url
			wrapperArgs['url'] = "https://www.iucnredlist.org/species/" .. speciesID .. '/' .. speciesAssessment
		end
	else
		wrapperArgs['url']=templateArgs['url']
	end
	if url == "" and templateArgs['id'] then -- use oldstyle url
		wrapperArgs['url'] = "http://oldredlist.iucnredlist.org/details/" .. templateArgs['id']
		wrapperArgs['journal'] = '[[IUCN Red List of Threatened Species]]'
		wrapperArgs['volume'] = 'Version ' .. templateArgs['version']
	end
	if templateArgs['amended'] then wrapperArgs['trans-title']=templateArgs['amended'] end -- use translated title parameter to add amended text, e.g. "amended version of 2016 assessment", which will be added in square brackets after title
	--wrapperArgs['trans-title'] = templateArgs['trans-title']

	frame.args=wrapperArgs --set the wrapper arguments

	local wrapper = require("Module:Template wrapper/sandbox")

	--local xframe = frame --mw.clone(frame)  --mw.getCurrentFrame()
	--frame.args.metatable['_template'] = "cite journal"
	--local parents = xframe:getParent() --mw.getCurrentFrame():getParent()
	--parents.args['_template'] = "cite journal"

	--mw.logObject(frame)
	--return  mw.dumpObject(wrapperArgs)
	return wrapper.wrap(frame)

end
--[[ function to replace iucn templates
     test template: Template:IUCN/sandbox/lua
     usage: {{#invoke:iucn|main}}
--]]
function p.main(frame)

	local templateArgs = {}   -- need a copy to alter and pass to citation template
	getArgs (frame, templateArgs)

--	local parents = mw.getCurrentFrame():getParent()
	local reference = ""
	local taxon =templateArgs['taxon']

	reference = '{{cite journal |title=' .. taxon
	local maxAssessors = 20
	local assessorNumber =0

	-- if 'assessor' instead of 'assessor1'
	if templateArgs['assessor'] then templateArgs['assessor1'] = templateArgs['assessor'] end
	if templateArgs['assessor-link'] then templateArgs['assessor-link1'] = templateArgs['assessor-link'] end

	while assessorNumber < maxAssessors do -- use the last number determined in the preprocessing

		assessorNumber  = assessorNumber  + 1 -- so we start with 1
		local assessorName = templateArgs['assessor'..tostring(assessorNumber)] or ""
		if assessorName ~= "" then
			reference = reference .. ' |author' .. assessorNumber .. '=' .. assessorName
		end
		local assessorLink = templateArgs['assessor-link'..tostring(assessorNumber)]
				or templateArgs['assessor'..tostring(assessorNumber)..'link']
				or templateArgs['assessorlink'..tostring(assessorNumber)]or ""
		if assessorLink ~= "" then
			reference = reference .. ' |authorlink' .. assessorNumber .. '=' .. assessorLink
		end
	end
	local year = templateArgs['year']
	local id = templateArgs['id']
	local assessment = templateArgs['assessment'] or ""
	local version = templateArgs['version']
	local doi = templateArgs['doi'] or ""
	local accessdate = templateArgs['accessdate'] or ""

	reference = reference ..
		' |year=' .. year
		" |version=''Version "..  version .. "''" ..
		' |journal=[[The IUCN Red List of Threatened Species]]' ..
		' |accessdate='.. accessdate ..
		' |doi='.. doi

	if assessment ~= "" then
		reference = reference .. '|url=https://www.iucnredlist.org/species/'.. id .. '/' .. assessment
	else  -- if there is no assessment number, use oldredlist.iucnredlist.org version
		-- an alternative might be to use archive.org in case this cite is dropped
		reference = reference .. '|url=http://oldredlist.iucnredlist.org/details/'.. id .. '/0'
	end

	reference = reference .. ' |publisher=[[International Union for Conservation of Nature]]}}'

	return frame:preprocess(reference)
	--return reference
end

return p

This module "Iucn" is from Wikipedia if otherwise notified