وحدة:Check

من ويكيبيديا، الموسوعة الحرة
اذهب إلى التنقل اذهب إلى البحث

استعمال[عدل]

local str = {}

function str.check( frame )
	--frame = frame:getParent()
	local new_args = frame.args or frame:getParent().args
	local pagetext = new_args['pagetext'] or ""
	--mw.log("pagetext" .. pagetext)
	local talktext = new_args['talktext'] or ""
	
	local plain = false
	if pagetext == '' then return "" end   
	
	function findd(number)
		local search_talk = new_args["search_talk" .. number]  or "" 
		local search_page = new_args["search_page" .. number]  or "" 
		local cat = new_args["cat" .. number] or ""
		if search_talk == '' or search_page == "" then return "" end	  
		local findportal = mw.ustring.find( pagetext , search_page , 1, plain )
		
		mw.log(search_page)
		mw.log(findportal)
		
		if findportal ~= 0 and findportal ~= nil then
			local findtalk = mw.ustring.find( talktext , search_talk , 1, plain )
				if findtalk == 0 or findtalk == nil then
					return '[[تصنيف:' .. cat .. ']]'
				end
		end
		
		return ''
	end
	
	local Table = {}
	table.insert(Table , findd ( 1 ) ) 
	table.insert(Table , findd ( 2 ) ) 
	table.insert(Table , findd ( 3 ) ) 
	table.insert(Table , findd ( 4 ) ) 
	table.insert(Table , findd ( 5 ) ) 
	table.insert(Table , findd ( 6 ) ) 
	table.insert(Table , findd ( 7 ) ) 
	table.insert(Table , findd ( 8 ) ) 
	table.insert(Table , findd ( 9 ) ) 
	table.insert(Table , findd ( 10 ) ) 
	table.insert(Table , findd ( 11 ) ) 
	table.insert(Table , findd ( 12 ) ) 
	table.insert(Table , findd ( 13 ) ) 
	table.insert(Table , findd ( 14 ) ) 
	table.insert(Table , findd ( 15 ) ) 
	table.insert(Table , findd ( 16 ) ) 
	table.insert(Table , findd ( 17 ) ) 
	table.insert(Table , findd ( 18 ) ) 
	table.insert(Table , findd ( 19 ) ) 
	table.insert(Table , findd ( 20 ) ) 
	return mw.text.listToText( Table , "", "" )
end	  

function str.check2( frame )
	--frame = frame:getParent()
	local Portals = frame:getParent().args
	local Find_args = frame.args
	
	Portals_table = {}
	for x,y in pairs(Portals) do
		Portals_table[y] = true
		--mw.log(y)
	end
	--local talktext = Find_args['talktext'] or ""
	local currtitle = mw.title.getCurrentTitle()
	local talktext = ''
	local page = mw.title.new( currtitle.baseText or '', 'talk' )
	
	if currtitle.namespace ~= 0 then									-- only main page
		return '' 
	end
	if page.exists then
		talktext = page:getContent()											-- get talk text
	end
	
	local plain = false
	function findd(number)
		local search_talk = Find_args["search_talk" .. number]  or "" 
		local search_page = Find_args["search_page" .. number]  or "" 
		local cat = Find_args["cat" .. number] or ""
		local findportal = Portals_table[search_page]
		if cat == '' then return "" end											-- no tracking category
		if search_talk == '' then return  '[[تصنيف:' .. cat .. ']]' end			 -- no talk text
		if findportal == true then
			local findtalk = mw.ustring.find( talktext , search_talk , 1, plain )
				if findtalk == 0 or findtalk == nil then
					mw.log("Module:Check add track cat [[تصنيف:" .. cat .. "]]")
					return '[[تصنيف:' .. cat .. ']]'
				end
		end
		return ''
	end
	
	local Table = {}
	table.insert(Table , findd ( 1 ) ) 
	table.insert(Table , findd ( 2 ) ) 
	table.insert(Table , findd ( 3 ) ) 
	table.insert(Table , findd ( 4 ) ) 
	table.insert(Table , findd ( 5 ) ) 
	table.insert(Table , findd ( 6 ) ) 
	table.insert(Table , findd ( 7 ) ) 
	table.insert(Table , findd ( 8 ) ) 
	table.insert(Table , findd ( 9 ) ) 
	table.insert(Table , findd ( 10 ) ) 
	table.insert(Table , findd ( 11 ) ) 
	table.insert(Table , findd ( 12 ) ) 
	table.insert(Table , findd ( 13 ) ) 
	table.insert(Table , findd ( 14 ) ) 
	table.insert(Table , findd ( 15 ) ) 
	table.insert(Table , findd ( 16 ) ) 
	table.insert(Table , findd ( 17 ) ) 
	table.insert(Table , findd ( 18 ) ) 
	table.insert(Table , findd ( 19 ) ) 
	table.insert(Table , findd ( 20 ) ) 
	return mw.text.listToText( Table , "", "" )
end	  
return str