吃什么可以增加免疫力| 山药和什么不能一起吃| 人为什么有五根手指| 吃完香蕉不能吃什么| 一惊一乍是什么意思| 灵芝对身体有什么好处| 胸腔疼痛是什么原因| 女人身体发热预示什么| 嗓子不舒服吃什么消炎药| 胎儿缺氧孕妇会有什么反应| 肋骨骨折挂什么科| fizz是什么意思| 美容行业五行属什么| 月经提前是什么原因引起的| 额头上长痘痘是什么原因引起的| 火腿是什么动物的腿| 拉倒吧是什么意思| 鹌鹑蛋不能和什么一起吃| 八月一日是什么节日| 下鼻甲肥大是什么意思| 突然抽搐失去意识是什么原因| 85年是什么命| 卤素灯是什么灯| 鱼白是什么东西| 眉毛尾部有痣代表什么| 南瓜和窝瓜有什么区别| 从父是什么意思| 白蛋白偏高是什么原因| 骨质疏松吃什么药好| 单病种是什么意思| 胃不好吃什么水果好| 法尔如是是什么意思| 安乃近又叫什么名| 碳酸氢铵是什么| 吃益生菌有什么好处| 回不到我们的从前是什么歌| 升学宴选什么日子好| 女人吃鹿茸有什么好处| 孩子睡觉出汗多是什么原因| 木命人五行缺什么| 1d是什么意思| 珍珠鸟是什么鸟| 消炎药吃多了有什么副作用| 大腿出汗是什么原因| 穆字五行属什么| 小美女是什么意思| 为什么高铁没有e座| 胃酸过多吃什么食物好| 山东人喜欢吃什么| 狗狗中毒了用什么办法可以解毒| 实时更新是什么意思| 白细胞低有什么危险| 佝偻病是什么意思| 肠梗阻什么症状| naoh是什么| 日加西念什么| 月经不来又没怀孕是什么原因| 小孩抽多动症吃什么药最好| 今晚吃什么家常菜| 雷同是什么意思| 副乳是什么原因造成的| 北京的市花是什么| 目不暇接的意思是什么| 土人参长什么样| 什么叫糙米| 鸡的守护神是什么菩萨| 什么菜好吃| 钠低是什么原因| 痉挛吃什么药效果好| 初一不能做什么| 鼻血止不住是什么原因| 91是什么意思| 淋巴结肿大是什么样子的| 中图分类号是什么| 煽是什么意思| 梦见被狗追是什么意思| 哥斯拉是什么| 李子什么时候成熟| 望惠存是什么意思| 梅菜在北方叫什么菜| 肝囊性灶是什么意思| rich什么意思| 看病人买什么水果| 中枢是什么意思| 思钱想厚什么意思| 阿尔卑斯是什么意思| 白蛋白偏低是什么意思| 阴道里面痒是什么原因| 路由器管理员密码是什么| 痛风吃什么水果最好| 咳嗽吐白痰吃什么药| 肝血不足吃什么| 三马念什么| 补气血喝什么| 宫外孕破裂有什么症状| 得五行属什么| 骨碎补有什么功效| 类风湿关节炎吃什么好| 乳腺属于什么科室| 秋天有什么| 青定读什么| 剥苔舌是什么原因| 前胸后背长痘痘是什么原因| 囊性病变是什么意思| 血糖高吃什么水果降糖| 猪心炖什么适合孩子| 毛片是什么意思| 走南闯北是什么生肖| 脚气挂什么科室| 皮秒是什么| 失眠看什么科| 你好是什么意思| 小圆细胞阳性什么意思| 舌头溃疡是什么原因造成的| 取经是什么意思| 肥皂是什么做的| 很轴是什么意思| 表现优异是什么意思| butterfly什么意思| 权威是什么意思| 有偿服务是什么意思| 名垂千古是什么意思| 衣原体感染吃什么药| 肌酐低什么原因| 人中长痘痘是什么原因| 白猫是什么品种| quake是什么意思| 新生儿一直哭闹是什么原因| 女人梦见掉头发是什么征兆| 梦见自己出轨是什么意思| 介词后面跟什么| 蒙脱石散什么时候吃| 鞘是什么意思| 鲁迅为什么弃医从文| 后知后觉什么意思| 众星捧月是什么意思| 番薯是什么时候传入中国的| 喉咙干痒吃什么药| 什么招牌| 技压群雄的意思是什么| im是什么| apple什么意思| 咀嚼食用是什么意思| 吃薄荷叶有什么好处和坏处| 螚什么意思| 歧途什么意思| 6.20什么星座| gigi 是什么意思| 子宫增厚是什么原因| 陈赫是什么星座的| 单侧流鼻血是什么原因| 脾胃不好吃什么| 什么是吸附性义齿| 叙字五行属什么| 今天是个什么日子| 一什么云彩| 立夏吃什么食物| 兔儿爷是什么意思| 什么样的包皮需要做手术| 白斑是什么| 个子矮吃什么才能长高| 正事是什么意思| 梦到棺材什么意思| 06属什么生肖| 阴虱长什么样子图片| 常乐我净是什么意思| 肠道紊乱吃什么药| 冰粉籽是什么植物| 2021年是属什么年| 吃什么升血小板快| 痔疮坐浴用什么药效果好| 颅脑平扫是检查什么| 梦见穿袜子是什么意思| 地奥司明片治疗什么病| 眼球突出是什么原因| 艾滋病的症状是什么| 脾脏大是什么原因| 抵押什么意思| 胃子老是胀气是什么原因| 什么人容易得圆锥角膜| 女人排卵期是什么时候| 淋巴细胞偏高说明什么问题| 胆囊壁厚是什么意思| 犯太岁是什么意思啊| 狮子座什么性格| 养胃早餐吃什么好| 三聚氰胺是什么| 北京大学校长什么级别| 查肾结石挂什么科| 珏字五行属什么| c1开什么车| 做一半就软了是什么原因| r级电影是什么意思| 尿道感染应该吃什么药| ph值偏高是什么意思| 1997年属什么生肖年| 老鸨是什么| 2是什么生肖| 狗不能吃什么东西| 什么是直男| 子不问卜自惹祸殃什么意思| 蜈蚣是什么生肖| 黄色分泌物是什么原因| 胎动在肚脐周围是什么胎位| 甲功五项查的是什么| 复刻什么意思| vinegar是什么意思| mA是什么| 10月15号是什么星座| 吃完榴莲后不能吃什么| 婴儿打嗝是什么原因| 心率快吃什么药| 肠胃不好可以吃什么水果| 三点水加个真念什么| 牛黄安宫丸治什么病| 子宫内膜薄有什么影响| 乳铁蛋白对宝宝有什么好处| 前列腺钙化吃什么药| 一个六一个允念什么| 吃什么增强性功能| 客家人为什么叫客家人| 卵巢早衰是什么意思| 掮客是什么意思| 蜱虫咬人后有什么症状图片| 锅包肉用什么淀粉| 阿罗裤是什么意思| 女人嘴唇发紫是什么病| 女生喜欢什么姿势| 五月十三日是什么星座| 什么光会给人带来痛苦| ea7是什么品牌| 定心丸什么意思| 测血糖挂什么科| 足字旁的有什么字| 为什么不愿意工作| 呕吐是什么原因引起的| 总是放屁是什么原因引起的| 加字五行属什么| 不孕不育有什么症状| 眼睛怕光是什么原因| 甲状腺结节吃什么散结| 陈皮的作用是什么| 杭州灵隐寺求什么最灵| 抗凝血是什么意思| 便黑色大便是什么情况| 六月十一是什么星座| 玉米什么时候种| 手抖吃什么药马上控制| 什么叫软文| 修身养性下一句是什么| 胃寒胃凉吃什么药| 吃羊肉不能吃什么| 夏至喝什么汤| 东北方是什么方位| 及什么意思| 五灵脂是什么东西| 总是流鼻血是什么原因| 五月一日是什么星座| 医生为什么会建议竖切| 子宫内膜9mm意味着什么| 鲤鱼最爱吃什么食物| 人参有什么功效| 自由行是什么意思| 石斛什么人不适合吃| 百度Перейти к содержанию

【在习近平新时代中国特色社会主义思想指引下——新时代 新气象 新作为】鲁家村产业振兴的启示

С?рибар энциклопеди Википедийы ?рм?г.
百度 ”“我们的赛季开始好了许多。

Для документации этого модуля может быть создана страница Модуль:Wikidata/Places/doc

local categorizeByPlace = true;

local WDS = require( 'Module:WikidataSelectors' );
local Flags = require( 'Module:Wikidata/Flags' );
local p = {
	config = {
		hideSameLabels = false,
		hidePartOfLabels = false,
		hideUnitsForCapitals = true,
		reverseOrder = false,
		catLoopInGeoChains = '[[Категория:Википедия:Страницы с зацикливающимися геоцепочками]]',
		catWikibaseError = '[[Категория:Википедия:Страницы с ошибками скриптов, использующих Викиданные]]'
	}
};

local function min( prev, next )
	if prev == nil then
		return next;
	elseif prev > next then
		return next;
	else
		return prev;
	end
end

local function max( prev, next )
	if prev == nil then
		return next;
	elseif prev < next then
		return next;
	else
		return prev;
	end
end

local function getTimeBoundariesFromProperty( context, propertyId )
	local dateClaims = WDS.filter( context.entity.claims, propertyId );
	if not dateClaims or #dateClaims == 0 then
		return nil;
	end

	-- only support exact date so far, but need improvment
	local left = nil;
	local right = nil;
	for _, claim in pairs( dateClaims ) do
		if not claim.mainsnak then return nil; end
		local boundaries = context.parseTimeBoundariesFromSnak( claim.mainsnak );
		if not boundaries then return nil; end
		left = min( left, boundaries[ 1 ] );
		right = max( right, boundaries[ 2 ] );
	end

	if not left or not right then return nil; end

	return { left, right };
end

local function getTimeBoundariesFromProperties( context, propertyIds )
	for _, propertyId in ipairs( propertyIds ) do
		local result = getTimeBoundariesFromProperty( context, propertyId );
		if result then
			return result;
		end
	end

	return nil;
end

local function getTimeBoundariesFromQualifiers( context, statement, qualifierId )
	-- only support exact date so far, but need improvment
	local left = nil;
	local right = nil;
	if statement.qualifiers and statement.qualifiers[qualifierId] then
		for _, qualifier in pairs( statement.qualifiers[qualifierId] ) do
			local boundaries = context.parseTimeBoundariesFromSnak( qualifier );
			if not boundaries then return nil; end
			left = min( left, boundaries[1] );
			right = max( right, boundaries[2] );
		end
	end

	if not left or not right then
		return nil;
	end

	return { left, right };
end

local function getParentsInBoundariesSnakImpl( context, entityId, boundaries, propertyIds, selectors )
	local results = {};

	if not propertyIds or #propertyIds == 0 then
		return results;
	end
	
	for _, propertyId in ipairs( propertyIds ) do
		if (not string.match( propertyId, '^P%d+$' )) then error('Incorrect propertyId: ' + propertyId); end
		local selector;
		if (selectors ~= nil) then
			selector = selectors[propertyId] or propertyId;
		else
			selector = propertyId;
		end

		local entityClaims = {};
		entityClaims[propertyId] = mw.wikibase.getAllStatements( entityId, propertyId );

		local filteredClaims = WDS.filter( entityClaims, selector .. '[rank:preferred, rank:normal]' );
		if filteredClaims then
			for _, claim in pairs( filteredClaims ) do
				if not boundaries or not propertyIds or #propertyIds == 0 then
					table.insert( results, claim.mainsnak );
				else
					local startBoundaries = getTimeBoundariesFromQualifiers( context, claim, 'P580' );
					local endBoundaries = getTimeBoundariesFromQualifiers( context, claim, 'P582' );
		
					if ( startBoundaries == nil or startBoundaries[2] <= boundaries[1] ) and
						( endBoundaries == nil or endBoundaries[1] >= boundaries[2] )
					then
						table.insert( results, claim.mainsnak );
					end 
				end
			end
		end

		if #results > 0 then
			break;
		end
	end

	return results;
end

local function getParentsInBoundariesSnak( context, entityId, boundaries )
	if not entityId then error('entityId must be specified'); end
	if type(entityId) ~= 'string' then error('entityId must be string'); end
	if not boundaries then error('boundaries must be specified'); end
	if type(boundaries) ~= 'table' then error('boundaries must be table'); end

	local results = getParentsInBoundariesSnakImpl( context, entityId, boundaries, {'P131'} ) -- located in
	if not results or #results == 0 then
		results = getParentsInBoundariesSnakImpl( context, entityId, boundaries, {'P17'} ) -- country
	end

	for r, result in pairs( results ) do
		if result.snaktype ~= 'value' then
			return nil;
		end
		local resultId = result.datavalue.value.id;
		if resultId == entityId then
			return nil;
		end
	end
	return results;
end

local unions = { 
	Q1140229 = true, -- political union
	Q3623811 = true, -- Экономический союз
	Q4120211 = true -- региональная организация
}

local countries = {
	Q6256 = true, -- страна
	Q7275 = true, -- государство
	Q3024240 = true, -- историческое государство
	Q3624078 = true -- суверенное государство
}

local function isSkipTopLevel( entity )
	local isCountry = false;
	local isUnion = false;
	if entity and
		entity.claims and
		entity.claims.P31
	then
		for c, claim in pairs( entity.claims.P31 ) do
			if claim and
				claim.mainsnak and
				claim.mainsnak.datavalue and
				claim.mainsnak.datavalue.value and
				claim.mainsnak.datavalue.value.id
			then
				local typeId = claim.mainsnak.datavalue.value.id;
				isCountry = isCountry or countries[ typeId ];
				isUnion = isUnion or unions[ typeId ];
			end
		end
	end
	return isUnion and not isCountry;
end

local function isPartOfNext( prevLabel, nextLabel )
	return ( mw.ustring.len( prevLabel ) > mw.ustring.len( nextLabel ) )
		and ( mw.ustring.sub( prevLabel, mw.ustring.len( prevLabel ) - mw.ustring.len( nextLabel ) + 1 ) == nextLabel );
end

--Property:P19, Property:P20, Property:P119
function p.formatPlaceWithQualifiers( context, options, statement )
	local property = mw.ustring.upper( options.property );

	local actualDateBoundariesProperties = nil;
	if property == 'P19' then actualDateBoundariesProperties = {'P569','P570'}; end
	if property == 'P20' then actualDateBoundariesProperties = {'P570','P569'}; end
	if property == 'P119' then actualDateBoundariesProperties = {'P570','P569'}; end
	if property == 'P159' then actualDateBoundariesProperties = {'P576'}; end

	local boundaries = nil;
	if actualDateBoundariesProperties ~= nil then
		boundaries = getTimeBoundariesFromProperties( context, actualDateBoundariesProperties );
		if (boundaries == nil) and (property == 'P159') then
			boundaries = {os.time() * 1000, os.time() * 1000};
		end
	end

	local entriesToLookupCategory = {};

	local circumstances = context.getSourcingCircumstances( statement );
	local result = '';
	local baseResult = context.formatSnak( options, statement.mainsnak, circumstances );
	if not baseResult then
		return nil;
	end
	
	insertFromSnak( statement.mainsnak, entriesToLookupCategory )

	local hasAdditionalQualifiers = false;
	if statement.qualifiers then
		--parent divisions
		if statement.qualifiers.P131 then
			for i, qualifier in ipairs( statement.qualifiers.P131 ) do
				if qualifier.datavalue then
					local parentOptions = context.cloneOptions( options );
					local qualifierEntityId = qualifier.datavalue.value.id;
					parentOptions['text'] = getLabel( context, qualifierEntityId, boundaries );
					local link = context.formatSnak( parentOptions, qualifier );
	
					if p.config.reverseOrder then
						result = link .. ', ' .. result;
					else
						result = result .. ', ' .. link;
					end
					insertFromSnak( qualifier, entriesToLookupCategory )
					hasAdditionalQualifiers = true;
				end
			end
		end

		--country
		if statement.qualifiers.P17 then
			for i, qualifier in ipairs( statement.qualifiers.P17 ) do
				if qualifier.datavalue then
					local parentOptions = context.cloneOptions( options );
					local qualifierEntityId = qualifier.datavalue.value.id;
					parentOptions[ 'text' ] = getLabel( context, qualifierEntityId, boundaries );
					local link = context.formatSnak( parentOptions, qualifier );
	
					if p.config.reverseOrder then
						result = link .. ', ' .. result;
					else
						result = result .. ', ' .. link;
					end
					insertFromSnak( qualifier, entriesToLookupCategory )
					hasAdditionalQualifiers = true;
				end
			end
		end
	end

	if statement.mainsnak and
		statement.mainsnak.datavalue and
		statement.mainsnak.datavalue.value and
		statement.mainsnak.datavalue.value.id
	then
		local entityId = statement.mainsnak.datavalue.value.id;
		local parentSnaks = { statement.mainsnak };
		local parentEntityIds = { entityId };

		if actualDateBoundariesProperties ~= nil then
			local filterCapitalOf = {
				[ entityId ] = getParentsInBoundariesSnakImpl( context, entityId, boundaries, {'P1376'} )
			};
			if boundaries then
				local entityOptions = context.cloneOptions( options );
				entityOptions['text'] = getLabel( context, entityId, boundaries );
				baseResult = context.formatSnak( entityOptions, statement.mainsnak, circumstances );

				local parentId = entityId;
				while parentId ~= nil do
					-- get parent
					local newParentSnaks = getParentsInBoundariesSnak( context, parentId, boundaries );
					if not newParentSnaks or #newParentSnaks == 0 then
						parentId = nil;
					elseif #newParentSnaks == 1 then
						local parentSnak = newParentSnaks[ 1 ];
						parentId = parentSnak.datavalue.value.id;
						
						local hasLoop = false
						for _, parentEntityId in pairs(parentEntityIds) do
							if parentEntityId == parentId then
								hasLoop = true
							end
						end
						
						if hasLoop then
							if p.config and p.config.catLoopInGeoChains then
								result = result .. p.config.catLoopInGeoChains;
							end
							break -- while parentId ~= nil do
						end
								
						table.insert( parentSnaks, parentSnak );
						table.insert( parentEntityIds, parentId );
						filterCapitalOf[ parentId ] = getParentsInBoundariesSnakImpl( context, parentId, boundaries, { 'P1376' } );
					else
						parentId = nil;
						if p.config and p.config.catAmbiguousGeoChains then
							result = result .. p.config.catAmbiguousGeoChains;
						end
					end
				end

				if not hasAdditionalQualifiers then
					for i = 2, #parentSnaks, 1 do
						local parentSnak = parentSnaks[ i ];
						insertFromSnak( parentSnak, entriesToLookupCategory )
					end
				end

				-- do not output similar countries like "Denmark, the Kingdom of Denmark"
				local simularCountries = {
					['Q41304'] = 'Q1206012', -- Weimar Republic / German Reich
					['Q7318'] = 'Q1206012', -- Weimar Republic / Nazi Germany
					['Q35'] = 'Q756617', -- Denmark / Danish Realm
					['Q55'] = 'Q29999', -- Netherlands / Kingdom of the Netherlands
					['Q32081'] = 'Q865', -- Taiwan Province / Taiwan
				}
				if (#parentSnaks > 1) then
					for smallerCountryId, largerCountryId in pairs( simularCountries ) do
						if parentSnaks[ #parentSnaks ].datavalue.value.id == largerCountryId
							and parentSnaks[ #parentSnaks - 1 ].datavalue.value.id == smallerCountryId
						then
							table.remove( parentSnaks, #parentSnaks );
							table.remove( parentEntityIds, #parentEntityIds );
						end
					end
				end

				-- optimization for capital regions
				if (#parentSnaks > 3) then
					if parentSnaks[ #parentSnaks - 2 ].datavalue.value.id == 'Q23939248' --Greater London, Greater London
						and parentSnaks[ #parentSnaks - 3 ].datavalue.value.id == 'Q23306'
					then
						table.remove( parentSnaks, #parentSnaks - 2 );
						table.remove( parentEntityIds, #parentEntityIds - 2 );
					end
				end
				if (#parentSnaks > 2) then
					if parentSnaks[ #parentSnaks - 1 ].datavalue.value.id == 'Q240' --Brussels-Capital, Brussels
						and parentSnaks[ #parentSnaks - 2 ].datavalue.value.id == 'Q90870'
					then
						table.remove( parentSnaks, #parentSnaks - 2 );
						table.remove( parentEntityIds, #parentEntityIds - 2 );
					end
				end

				-- do not output (maternity) hospitals, houses and streets but do it for manor and English country houses
				local unignoredTypes = {
					'Q879050', -- manor house
					'Q1343246', -- English country house
				}
				local ignoredTypes = {
					'Q3947', -- house
					'Q16917', -- hospital
					'Q34442', -- road
					'Q79007', -- street
					'Q174782', -- square
					'Q958822', -- maternity hospital
					'Q2087181', -- historic house museum
				}
				if (#parentSnaks > 1) then
					local p31 = mw.wikibase.getAllStatements( parentEntityIds[ 1 ], 'P31' );
					local doignore = true;
					for _, iOf in ipairs( p31 ) do
						for _, unignoredTypeId in ipairs( unignoredTypes ) do
							if ( iOf.mainsnak.datavalue.value.id == unignoredTypeId ) then
								doignore = false;
								unignoredTypes = {};
								ignoredTypes = {};
								break;
							end
						end
					end
					
					if (doignore) then
						for _, iOf in ipairs( p31 ) do
							for _, ignoredTypeId in ipairs( ignoredTypes ) do
								if ( iOf.mainsnak.datavalue.value.id == ignoredTypeId ) then
									baseResult = '';
									unignoredTypes = {};
									ignoredTypes = {};
									break;
								end
							end
						end
					end
				end

				do
					local capofstate = false;
					local i = #parentSnaks;
					while i > 1 do
						local prevEntityId = parentEntityIds[ i - 1 ];
						-- TODO: use English labels, if there is no current language labels
						local prevLabel = getLabel( context, prevEntityId, boundaries ) or '';
						local nextEntityId = parentEntityIds[ i ];
						local nextLabel = getLabel( context, nextEntityId, boundaries ) or '';
						if p.config and p.config.hideSameLabels == true and prevLabel == nextLabel then
							-- do not output same label twice (NY, NY, USA)
							table.remove( parentSnaks, i );
							table.remove( parentEntityIds, i );
						elseif p.config and p.config.hidePartOfLabels == true and isPartOfNext( prevLabel, ' ' .. nextLabel ) then
							-- do not output same label if it's part of previos
							table.remove( parentSnaks, i - 1 );
							table.remove( parentEntityIds, i - 1 );
						elseif p.config and p.config.hideUnitsForCapitals == true then
							-- do not ouput items whose capital is the first item
							local capitalId = nil;
							for _capitalId, capitalSnaks in pairs( filterCapitalOf ) do
								if #capitalSnaks > 0 then
									for __, capitalSnak in pairs( capitalSnaks ) do
										if	capitalSnak.datavalue and 
											parentSnaks[ i ].datavalue.value.id == capitalSnak.datavalue.value.id then
											capitalId = _capitalId;
											if (i == #parentSnaks) then
												capofstate = true;
											end
											break;
										end
									end
								end
							end
							if capitalId ~= nil then
								if i == #parentSnaks then
									i = i - 1;
								end
								-- always ouput constituent countries like England or Russian SFSR
								if (i == (#parentSnaks-1)) and (capofstate == false) then
									local p31 = mw.wikibase.getAllStatements(parentEntityIds[ i ], 'P31');
										for _, iOf in pairs (p31) do
											if (iOf.mainsnak.datavalue.value['numeric-id'] == 236036) or (iOf.mainsnak.datavalue.value['numeric-id'] == 3336843) or (iOf.mainsnak.datavalue.value['numeric-id'] == 12959600) or (iOf.mainsnak.datavalue.value['numeric-id'] == 56219758) or (iOf.mainsnak.datavalue.value['numeric-id'] == 15304003) or (iOf.mainsnak.datavalue.value['numeric-id'] == 66724388) then
												i = i - 1;
										end
									end
								end
								while i > 1 and parentEntityIds[ i ] ~= capitalId do
									table.remove( parentSnaks, i );
									table.remove( parentEntityIds, i );
									i = i - 1;
								end
							end
						end
						i = i - 1;
					end
				end

				if isSkipTopLevel( parentEntityIds[ #parentEntityIds ] ) then
					table.remove( parentSnaks, #parentEntityIds );
					table.remove( parentEntityIds, #parentEntityIds );
				end

				if not hasAdditionalQualifiers then
					for i = 2, #parentSnaks, 1 do
						local parentSnak = parentSnaks[ i ];

						local parentOptions = context.cloneOptions( options );
						parentOptions['text'] = getLabel( context, parentEntityIds[ i ], boundaries );

						local comma;
						if ((baseResult == '') and (i == 2)) then
							comma = '';
						else
							comma = ', ';
						end

						if p.config.reverseOrder then
							result = context.formatSnak( parentOptions, parentSnak ) .. comma .. result;
						else
							result = result .. comma .. context.formatSnak( parentOptions, parentSnak );
						end
					end
				end
			end
		end
	end

	if options[ 'thisLocationOnly' ] then
		result = baseResult;
	elseif p.config.reverseOrder then
		result = result .. baseResult;
	else
		result = baseResult .. result;
	end
	if options.references then
		result = result .. context.formatRefs( options, statement );
	end

	if categorizeByPlace then
		if property == 'P19' then result = result .. getCategory( 'P1464', entriesToLookupCategory ); end
		if property == 'P20' then result = result .. getCategory( 'P1465', entriesToLookupCategory ); end
		if property == 'P119' then result = result .. getCategory( 'P1791', entriesToLookupCategory ); end
	end

	return result;
end

-- append entity id from snak to result
function insertFromSnak( snak, result )
	if not categorizeByPlace then
		return;
	end
	if snak and
		snak.datavalue and
		snak.datavalue.type == 'wikibase-entityid' and
		snak.datavalue.value and
		snak.datavalue.value[ 'entity-type' ] == 'item'
	then
		table.insert( result, snak.datavalue.value.id );
	end
end

function getCategory( propertyId, entriesToLookupCategoryFor )
	if mw.title.getCurrentTitle().namespace == 0 then
		for _, placeId in pairs( entriesToLookupCategoryFor ) do
			local claims = mw.wikibase.getBestStatements(placeId, propertyId);
	
			if claims then
				for _, claim in pairs( claims ) do
					if claim.mainsnak and
						claim.mainsnak and
						claim.mainsnak.datavalue and
						claim.mainsnak.datavalue.type == 'wikibase-entityid'
					then
						local catEntityId = claim.mainsnak.datavalue.value.id;
						local catSitelink = mw.wikibase.getSitelink(catEntityId);
						if (catSitelink) then
							return '[[' .. catSitelink .. ']]';
						end
					end
				end
			end
		end
	end
	return '';
end


local historicNamesProperties = { 'P1813', 'P1448', 'P1705' };

local langCode = mw.language.getContentLanguage():getCode();
local historicNamesPropertySelectors = {
		P1813 = 'P1813[language:' .. langCode .. '][!P3831,P3831:Q105690470]',
		P1448 = 'P1448[language:' .. langCode .. '][!P3831,P3831:Q105690470]',
		P1705 = 'P1705[language:' .. langCode .. '][!P3831,P3831:Q105690470]'
};

-- get current of historic name of place
function getLabel( context, entityId, boundaries )
	if not entityId then
		return nil;
	end
	if (type(entityId) ~= 'string') then error('incorrect type of entityId argument'); end;

    local label = nil;

	-- name from properties
	local results = getParentsInBoundariesSnakImpl( context, entityId, boundaries,
		historicNamesProperties, historicNamesPropertySelectors);

	for r, result in pairs( results ) do
		if result.datavalue and
			result.datavalue.value and
			result.datavalue.value.text
		then
			label = result.datavalue.value.text;
			break;
		end
	end

    -- name from label
    if label == nil then
		label = mw.wikibase.getLabel( entityId );
    end

    return label;
end

p.getLabel = getLabel;

local function calculateEndDateTimestamp( context, options, statement )
	if not context then error( 'context not specified' ) end;
	if not options then error( 'options not specified' ) end;
	if not options.entity then error( 'options.entity missing' ) end;
	if not statement then error( 'statement not specified' ) end;

	if statement.qualifiers and statement.qualifiers.P582 then
		for i, qualifier in ipairs( statement.qualifiers.P582 ) do
			local parsedTime = context.parseTimeFromSnak( qualifier );
			if parsedTime then
				return parsedTime;
			end
		end
	end

	-- check death day... do we have it at all?
	for h, propertyId in pairs( { "P570", "P577", "P576" } ) do
		local dateClaims = context.selectClaims( options, propertyId );
		if dateClaims then
			for i, statement in ipairs( dateClaims ) do
				local parsedTime = context.parseTimeFromSnak( statement.mainsnak );
				if parsedTime then
					return parsedTime;
				end
			end
		end
	end

	-- TODO: check other "end" properties

	-- no death day
	return os.time() * 1000;
end

local function deleteTwinAncestors( countryEntityId, propertyId, entityId ) --do not display countries which have twin ancestors
	local badTwins
	if ( countryEntityId == 'Q174193' ) then				--Great Britain and Ireland
		badTwins = {'Q145'}									--Great Brirani & NI
    elseif ( countryEntityId == 'Q161885' ) then			--Great Britain
		badTwins = {'Q174193'}								--Great Britain and Ireland
	elseif ( countryEntityId == 'Q43287' ) then				--German Impire
		badTwins = {'Q41304', 'Q7318', 'Q2415901', 'Q183'}	--Weimar Republic or Nazi Germany or Allied-occupied Germany or Germany
	elseif ( countryEntityId == 'Q41304' ) then				--Weimar Republic
		badTwins = {'Q7318', 'Q2415901', 'Q183'}			--Nazi Germany or Allied-occupied Germany or Germany
	elseif ( countryEntityId == 'Q7318' ) then				--Nazi Germany
		badTwins = {'Q2415901', 'Q183'}						--Allied-occupied Germany or Germany
    elseif ( countryEntityId == 'Q2415901' ) then			--Allied-occupied Germany
		badTwins = {'Q183'}									--Germany
	elseif ( countryEntityId == 'Q696908' ) then			--Kingdom of Poland
		badTwins = {'Q207272', 'Q211274', 'Q36'}			--Second Polish Republic or Polish People's Republic or Poland
	elseif ( countryEntityId == 'Q207272' ) then			--Second Polish Republic
		badTwins = {'Q211274', 'Q36'}						--Polish People's Republic or Poland
	elseif ( countryEntityId == 'Q211274' ) then			--Polish People's Republic
		badTwins = {'Q36'}									--Poland
	elseif ( countryEntityId == 'Q203493' ) then			--Kingdom of Romania
		badTwins = {'Q842794', 'Q218'}						--Socialist Republic of Romania or Romania
	elseif ( countryEntityId == 'Q842794' ) then			--Socialist Republic of Romania
		badTwins = {'Q218'}									--Romania
	elseif ( countryEntityId == 'Q838261' ) then			--FR of Yugoslavia
		badTwins = {'Q37024'}								--Serbia & Montenegro
	else
		return true;
	end

	local listforcheck
	if propertyId == 'P1532' then
		listforcheck = mw.wikibase.getAllStatements( entityId, propertyId );
	else
		listforcheck = mw.wikibase.getBestStatements( entityId, propertyId );
	end

	for _, claim in pairs( listforcheck ) do
		if ( claim and claim.mainsnak
			and claim.mainsnak.datavalue
			and claim.mainsnak.datavalue.value
			and claim.mainsnak.datavalue.value.id ) then
			local actualId = claim.mainsnak.datavalue.value.id;
			for index, value in ipairs(badTwins) do
				if ( value == actualId ) then
            		return false;
        		end
			end
		end
	end
	return true; 
end

function p.formatCountryClaimWithFlag( context, options, statement )
	if not context then error('context not specified') end;
	if not options then error('options not specified') end;
	if not options.entity then error('options.entity is missing') end;
	if not statement then error('statement not specified') end;

	if not statement.mainsnak or
		not statement.mainsnak.datavalue or
		not statement.mainsnak.datavalue.value or
		not statement.mainsnak.datavalue.value.id
	then
		local result = context.formatStatementDefault( context, options, statement );
		if not result then
			return '';
		end
		return '<span class="country-name">' .. result .. '</span>';
	end
	
	local countryEntityId = statement.mainsnak.datavalue.value.id;
	local endDateTimestamp = calculateEndDateTimestamp( context, options, statement );
	local boundaries = getTimeBoundariesFromProperties( context, {'P570', 'P577', 'P571'} );

	if deleteTwinAncestors( countryEntityId, string.upper(options.property), options.entity.id ) then

		local countryOptions = context.cloneOptions( options );
		if not countryOptions['text'] or countryOptions['text'] == '' then
			countryOptions['text'] = getLabel( context, countryEntityId, boundaries );
		end

		local flag = Flags.getFlag( context, countryEntityId, endDateTimestamp );	
		if flag then
			return flag .. '&nbsp;<span class="country-name">' ..
				context.formatStatementDefault( context, countryOptions, statement ) ..
				'</span>';
		end

		return '<span class="country-name">' ..
			context.formatStatementDefault( context, countryOptions, statement ) ..
			'</span>';
	else
		return nil;
	end
end

return p;
半夜腿抽筋是什么原因 血糖高吃什么蔬菜 什么是水痘 湿温病是什么症状 吃布洛芬有什么副作用
结婚证需要什么资料 心悸吃什么中成药 鉴黄师是什么职业 阴茎不硬吃什么 肚脐眼周围疼是什么原因
什么绿 胪是什么意思 对方忙线中什么意思 1957年属什么 乳腺化疗期间吃什么
老玻璃是什么意思 笙是什么意思 背部毛孔粗大是什么原因 女人小腹坠痛是什么原因 角膜炎是什么症状
礼仪是什么hcv9jop5ns1r.cn 身高用什么单位hcv9jop2ns6r.cn 主动脉钙化什么意思hcv9jop0ns9r.cn 雨字头的字有什么hcv8jop8ns6r.cn 强高是什么意思hcv7jop4ns6r.cn
热毛巾敷眼睛有什么好处hcv9jop7ns1r.cn 蛋白尿吃什么食物好hcv8jop6ns2r.cn 鸡奸什么意思hcv9jop0ns3r.cn 为什么叫梅雨季节hcv8jop1ns9r.cn 山东济南有什么好玩的地方clwhiglsz.com
地图鱼吃什么hcv8jop8ns6r.cn 肚子经常胀气是什么原因hcv9jop6ns6r.cn 预科班是什么意思hcv8jop1ns5r.cn 血脂高看什么科hcv8jop4ns1r.cn 尿道刺痛吃什么药hcv9jop3ns9r.cn
什么米减肥效果好hcv8jop0ns9r.cn 小腿肿是什么原因hcv9jop3ns0r.cn 1988年出生是什么命hcv8jop4ns7r.cn 1976年是什么命hcv8jop0ns3r.cn 隐翅虫咬了用什么药膏hcv8jop9ns6r.cn
百度