Documentation icon دستاویز [تخلیق]
local p = {}

function p.count_ref(frame)
	 -- {{#invoke:Sandbox/Mr. Ibrahem|count_ref|Yemen}}
	local title = frame.args[1]
	local _;
	local page_title_object = mw.title.new(title);
	local text = page_title_object:getContent();
	local count;
	_, count = mw.ustring.gsub (text, '<ref[^>/]*>', '%1');
	--mw.log(_)
	return count;
end
function p.tab(frame)
	local title = frame.args[1]
	local _,ref;
	local page_title_object = mw.title.new(title);
	local text = page_title_object:getContent();
	text = mw.ustring.gsub(text , "%{%|", "<table>")
	text = mw.ustring.gsub(text , "%|%}", "</table>")
	local pattern = '(<table[^>]*>.-</table>)'
	local tstart, tend = text:find (pattern , 1 , false );
	 --mw.ustring.find( source_str, pattern, start_pos, plain )
	local total = 0;
	while tstart do			
		ref = text:sub(tstart, tend)
		total = total + #ref;
		tstart = tend;
		tstart, tend = text:find (pattern, tstart , false );
	end
	return total;
end

function p.ref_len(frame)
	local title = frame.args[1]
	local _,ref;
	local page_title_object = mw.title.new(title);
	local text = page_title_object:getContent();
	local pattern = '(<ref[^>]*>[^<>]+</ref>)'
	local tstart, tend = text:find (pattern , 1 , false );
	 --mw.ustring.find( source_str, pattern, start_pos, plain )
	local total = 0;
	while tstart do			
		--mw.log(mw.ustring.sub(text, tstart, tend))
		ref = text:sub(tstart, tend)
		mw.log(  ref  )
		total = total + #ref;
		tstart = tend;
		tstart, tend = text:find (pattern, tstart , false );
	end
	return total;
end

function p.count2(frame)
	local page_title_object = mw.title.new('الانتخابات البرلمانية اللبنانية 2005')
	local text = page_title_object:getContent();	
	text = mw.ustring.gsub( text, "%a", " " )
	local words = mw.text.split( text , " ")
	mw.log(#words)
	tt = frame:extensionTag("source", mw.dumpObject(words),{ lang= 'lua'})
	return tt
end

function p.aoooooooooo( datavalue, datatype, options )
	local language = mw.language.fetchLanguageName(datavalue.value.language, 'ur')
	
	if options.langpref and options.langpref ~= '' 
	then
		langpref = options.langpref
		if datavalue.value.language == langpref
			then valu = mw.text.tag('span', {title = language}, datavalue.value.text)
		end
	elseif options.withoutlang and options.withoutlang ~= '' 
			then
				withoutlang = options.withoutlang
			if datavalue.value.language == withoutlang
				then valu = ''
			end
	else 
		valu  = mw.text.tag('span', {title = language}, datavalue.value.text)
	end
	if valu and valu ~= '' then 
		if options.showlang and options.showlang ~= '' then
			lange = '('.. language..')'
			valu = valu  ..' '..lange
		end
	end
	return valu
end

function p.test(frame)
    	local str = frame.args[1]
    	if str and str ~= '' then
	if string.find(str, "[د|ج|ح|خ|ه|ع|غ|ف|ق|ث|ص|ض|ش|س|ي|ب|ل|ا|ت|ن|م|ك|ط|ذ|ئ|ء|ؤ|ر|لا|ى|ة|و|ز|ظ|أ|إ|آ|ـ]") then
	     return '' else return '[[category:قالب معلومات صاحب منصب بمدخلات انجليزية]]'
	end
end	
end

return p