Modul:Article

Moduldokumentasjon

Denne modulen brukes i Mal:Stubb for å vaske vekk wikitekst som ellers gir unødig stor tekst, slik at artikler kan legges i spesifikke kategorier utfra deres størrelse.

local scrubs
scrubs = {
	["scrub-tags"] = function(text)
		return mw.ustring.gsub(text, '%b<>', '' )
	end,
	["scrub-templates"] = function(text)
		return mw.ustring.gsub(text, '%b{}', '' )
	end,
	["scrub-extlinks"] = function(text)
		return mw.ustring.gsub(text, '%[[htps]*:?//%w[^%s]+%s*([^%]]*)%]', '%1' )
	end,
	["scrub-magics"] = function(text)
		return mw.ustring.gsub(text, '__[_%w]+__', '' )
	end,
	["scrub-links"] = function(text)
		local text = mw.ustring.gsub(text, '%[%[[^|%]]+%|([^%]]+)%]%]', '%1' )
		text = mw.ustring.gsub(text, '%[%[([^|%]]+)%]%]', '%1' )
		return text
	end,
	["scrub-sections"] = function(text)
		return mw.ustring.gsub(text, '==+[^=\n]+==+', '' )
	end,
	["scrub-all"] = function(text)
		text = scrubs["scrub-tags"](text)
		text = scrubs["scrub-templates"](text)
		text = scrubs["scrub-links"](text)
		text = scrubs["scrub-extlinks"](text)
		text = scrubs["scrub-magics"](text)
		text = scrubs["scrub-sections"](text)
		return text
	end
}

local tests
tests = {
	["length"] = function(text)
		return mw.ustring.len( text )
	end,
	["extlinks"] = function(text)
		local count = 0
		for line in string.gmatch(text, '%[[htps]*:?//%w[^%s]+%s*([^%]]*)%]') do
			count = 1 + count
		end
		return count
	end,
	["links"] = function(text)
		mw.log('enter links')
		local count = 0
		for line in string.gmatch(text, '%[%[[^|%]]+%|[^%]]+%]%]') do
			count = 1 + count
		end
		for line in string.gmatch(text, '%[%[[^|%]]+%]%]') do
			count = 1 + count
		end
		return count
	end,
	["lines"] = function(text)
		local count = 0
		for line in string.gmatch(text, '([^\n]+)') do
			if mw.ustring.find( line, '%w', init, plain ) then
				count = 1 + count
			end
		end
		return count
	end,
	["words"] = function(text)
		local count = 0
		for line in string.gmatch(text, '([^%s]+)') do
			if mw.ustring.find( line, '%a', init, plain ) then
				count = 1 + count
			end
		end
		return count
	end,
	-- anslag
	["characters"] = function(text)
		local _,count = mw.ustring.gsub(text, '%s', '')
		return mw.ustring.len( text ) - count
	end
}

local p = {}
p.tests=tests
p.scrubs = scrubs

function p._stats(content, args)
	for k,v in ipairs(args) do
		local num = tonumber(k)
		if num and num ~= 1 then
			if scrubs[v] then
				content = scrubs[v](content)
			end
		end
	end
	local acc = 0
	for k,v in pairs(args) do
		local num = tonumber(k)
		if not num and k then
			if tests[k] then
				acc = acc + tonumber(v) * tests[k](content)
			end
		end
	end
	return acc
end

function p.stats(frame)
	return p._stats(mw.title.getCurrentTitle():getContent(), (frame or mw.getCurrentFrame()).args)
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.