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 03:34, 21 January 2020 (doi function). 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})
	n.doi1 = n.doi or n.doi1													-- assume that |doi= is an alias of |doi1=; TODO: add redundant parameter err msg?
	local i = 1;																-- an indexer variable
	local doi = n['doi'	.. i]													-- get initial value from |doi= or |doi1=

	local search = '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'
	local suffix = '%5C%2F%20*%2F'

	while doi do																-- loop through n.doi1, n.doi2, ...; must be sequential; stops at first gap
		text = text..string.format("\n** <code>{{doi|[%s%s%s %s]}}</code>", search, doi:gsub ('10%.', '\/10\\.'), suffix, doi)
		i = i + 1																-- bump the indexer for next parameter
		doi = n['doi'..i]														-- get next |doin= parameter value
	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

function p.selected (frame)
	local n = mArguments.getArgs(frame, {parentOnly = true})
	n.doi1 = n.doi or n.doi1													-- assume that |doi= is an alias of |doi1=; TODO: add redundant parameter err msg?
	local i = 1;																-- an indexer variable
	local doi = n['doi'	.. i]													-- get initial value from |doi= or |doi1=

	local search = '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'
	local suffix = '%5C%2F%20*%2F'

	while doi do																-- loop through n.doi1, n.doi2, ...; must be sequential; stops at first gap
		text = text..string.format("\n** <code>{{doi|[%s%s%s %s]}}</code>", search, doi:gsub ('10%.', '\/10\\.'), suffix, doi)
		i = i + 1																-- bump the indexer for next parameter
		doi = n['doi'..i]														-- get next |doin= parameter value
	end

	return text
end
	
return p