Jump to content

Module:JCW

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Headbomb (talk | contribs) at 14:11, 21 November 2019 (**). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local mArguments = require('Module:Arguments')
local TableTools = require('Module:TableTools')

function p.selected (frame)
	local n = mArguments.getArgs(frame, {parentOnly = true})
	doi = n.doi
	doi1 = n.doi1
	doi2 = n.doi2
	doi3 = n.doi3
	note = n.note
	source = n.source or 'Unknown'
	if mw.title.getCurrentTitle().fullText == 'User:JL-Bot/Publishers.cfg' or 'User:JL-Bot/Maintenance.cfg' then
		source = nil
	end
	--local abbrev = {BLJ = '[https://beallslist.weebly.com/standalone-journals.html BLJ]', BLJU='[https://beallslist.weebly.com/standalone-journals.html BLJU]', BLP='[https://beallslist.weebly.com/ BLP]', BLPU='[https://beallslist.weebly.com/ BLPU]', SPJJ = '[https://predatoryjournals.com/journals/ SPJJ]', SPJP = '[https://predatoryjournals.com/publishers/ SPJP]', DOAJ='[https://blog.doaj.org/2014/08/28/some-journals-say-they-are-in-doaj-when-they-are-not/ Lying about DOAJ]', QW ='[https://www.quackwatch.org/04ConsumerEducation/nonrecperiodicals.html QW]',	DEPS ='[[WP:DEPS|DEPS]]', URF ='[[#Unreliable fields|URF]]'}
	local abbrev = {Bohannon = 'Bohannon', BLJ = 'BLJ', BLJU= 'BLJU', BLP = 'BLP', BLPU = 'BLPU', SPJJ ='SPJJ', SPJP ='SPJP', DOAJ = 'DOAJ', QW='QW', DEPS ='DEPS', URF = 'URF', Unknown = 'Unknown'}
	local source = abbrev[source] or source
	local sourcenote = ''
	if note and source then
		sourcenote = string.format(' (%s) [%s]', source, note)
	end
	if source and not note then
		sourcenote = string.format(' (%s)', source)
	end
	if note and not source then
		sourcenote = string.format(' [%s]', note)
	end
	text = string.format ('* [[:%s]]%s', n[1] or '', sourcenote or '')
	n[1] = nil --make next loop only target arguments >=2
	for i, j in ipairs(TableTools.compressSparseArray(n)) do
		text = text..string.format("\n** [[:%s]]", j)
	end
	if doi then
		text = text..string.format("\n** <code>%s</code> ([[Digital object identifier#Prefix|doi prefix]], [https://en.wikipedia.org/w/index.php?sort=relevance&title=Special%%3ASearch&profile=advanced&fulltext=1&advancedSearch-current={}&ns0=1&ns118=1&search=insource%%3A%%2Fdoi+*(%%3D%%7C%%5C%%7C%%7C%%3A)+*%s%%2F])", doi, doi)	
		text = mw.ustring.gsub(text, "%*10%.", "\*10\\.")
	end
	if doi1 then
		text = text..string.format("\n** <code>%s</code> ([[Digital object identifier#Prefix|doi prefix]])", doi1)
	end
	if doi2 then
		text = text..string.format("\n** <code>%s</code> ([[Digital object identifier#Prefix|doi prefix]])", doi2)
	end
	if doi3 then
		text = text..string.format("\n** <code>%s</code> ([[Digital object identifier#Prefix|doi prefix]])", doi3)
	end
	return text
end

function p.exclude (frame)
	local n = mArguments.getArgs(frame, {parentOnly = true})
	local length = TableTools.length(n)
	local text = string.format ('*[[:%s]]', n[1] or '')
	n[1] = nil
	for i, j in ipairs(TableTools.compressSparseArray(n)) do
		if length > 1 then
			text = text..string.format(" ≠ [[:%s]]", j)
		end
	end
	return text
end

function p.pattern (frame)
	local n = mArguments.getArgs(frame, {parentOnly = true})
	local length = TableTools.length(n)
	local text = string.format ('*[[%s]]', n[1] or '')
	n[1] = nil --make next loop only target arguments >=2
	for i, j in ipairs(TableTools.compressSparseArray(n)) do
		 text = text..string.format("\n** <code>%s</code>", j)
		 text = mw.ustring.gsub(text, "%.%*", "<b><font style=color:#006400;>.*</font></b>")
		 text = mw.ustring.gsub(text, "!", "<b><font style=color:#8B0000;>!</font></b>")
		 text = mw.ustring.gsub(text, "'", "&rsquo;")
	end
	return text
end

return p