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

function trim(s)
		--Removes leading zeroes from value
		if s:sub(1,1)=="P" then return s:sub(2)
		else return s
		end
	end
local function category(propertyid,q,nocate)
	main = '[[زمرہ:صفحات مع ویکی ڈیٹا|'.. trim(propertyid) ..']]'
	if nocate and nocate  ~= ''  
		then -- to hide the category
	 		return ''
	 	elseif q and q  ~= ''  
		then 
	 		return q..''..main 
	end
	d = mw.text.trim(propertyid)
	s = list(d)
	if s then
		return '[[زمرہ:'.. s ..']]'..main  -- linktext(s)
	end
end

local function icons(u,id,noicon,icon2)
	if noicon and noicon  ~= ''  
		then -- to hide the icon
	 		return ''
	end
	local label = ""--mw.wikibase.label(u) --{{#invoke:Wikibase|label| u }}
	--if label ==nil or not label  then label ='' else end

	local temp =  label .. ' ('.. u ..')'
	local ico =  'Arbcom_ru_editing.svg|13px'
		if icon2 and icon2 ~='' then 
			ico = 'Wikidata-logo.svg|20px' 
			size = '20px' 
			end
	local so = 'ویکی ڈیٹا پر ' .. temp ..' کی خاصیت میں تبدیلی کریں'
	local im =' [[File:'.. ico .. '|baseline|link=d:'.. (id or '') .. '#'.. u ..'|'.. so .. ']]'
	local noprint=  '<span class="noprint">'.. im ..'</span>'
	local sup=  '<sup>'.. noprint ..'</sup>'
	if u then
		return noprint
	end
end

local function xt(e)
		return  'صفحات مع خاصیت '.. e
end

local function wd(e)
		return e .. ' ویکی ڈیٹا سے ماخوذ'
end

function list(s)
	local I = trim(s)
	return xt(s)
end

function p.pageId(frame)
	return mw.wikibase.getEntityIdForCurrentPage()
end

function p.makecategory1(options)  --Main function
	page_title_object = mw.title.getCurrentTitle()
	ns = page_title_object.namespace	
	title = page_title_object.text
	-- ############################
	prop = options['property']
	prop2 = options['justthisqual']
	noicon = options['noicon'] -- options to hide the icon.
	nocate = options['nocate']  -- options to hide the category.
	q = options['category']
	iid = options['entityId'] or options['id']
	icon2 = options['icon2']
	-- ############################
	if iid == '' or not iid then
             id = p.pageId()
             else id = iid 
      end
	-- ############################
	if prop  == '' or not prop then
		return nil -- don't do anything if no options property.
	end
	-- ############################
	propertyid = mw.ustring.gsub(prop:upper(), " ", "")

	icon = icons(propertyid,id,noicon,icon2)   -- function to display the icon.
	cate = category(propertyid,q,nocate) -- function to display the category.
	-- ############################
	if prop2 and prop2 ~= "" then 
		cate = cate .. category( mw.ustring.gsub(prop2:upper(), " ", "") , q , nocate) 
	end
	-- ############################
	last = cate ..''.. icon
	--mw.log("Module:Wikidata/تتبع:" .. title)
	if title == "ويكي بيانات/ملعب ويكي بيانات" then
		last = icon
	end	
	if ns == 2 then -- to hide category in user pages
		 last = icon
	end
	return last
end

function p.makecategory(frame)  --Main function
	local final = p.makecategory1(frame.args)
	return final
end

function p.make1(prop,id)  --Main function
	if id == '' or not id then
             id = p.pageId()
             else id = iid 
      end
	if prop  == '' or not prop then
		return nil -- don't do anything if no args property.
	end
	propertyid = mw.ustring.gsub(prop:upper(), " ", "")

	icon = icons(propertyid,id,noicon)   -- function to display the icon.
	cate = category(propertyid,q,nocate) -- function to display the category.
	
	last = cate ..''.. icon
		return last
end


function p.SS(frame) --testing function
	s = mw.ustring.gsub(frame.args['property']:upper(), " ", "")
	s = list(s)
	s = mw.text.trim(s)
	if s  == '' or not s then
		return  nil
	end
	q = frame.args['category']
	if q  == '' or not q then
		return category(s)
        else return q
	end
	
end

return p