377是什么| 肺阴不足的症状是什么| 肚子怕冷是什么原因该怎么办| 补锌吃什么药| 翩跹是什么意思| 相对密度是什么意思| 拔罐后需要注意什么| 光明会到底是干什么的| 8月2日是什么星座| 神经过敏是什么意思| 什么是七杀命格| 唐僧被封为什么佛| 霉菌是什么原因感染的| 左脸颊长痘是什么原因| 青色五行属什么| 老农民韩美丽结局是什么| 为什么一动就满头大汗| 糊精是什么东西| 胸部正侧位片检查什么| 八年是什么婚| 男人更年期有什么症状有哪些表现| 方言是什么意思| 大祭司是什么意思| 电影下映是什么意思| 上火吃什么好| 荆芥是什么菜| 葛粉吃了有什么好处| 男人眼袋大是什么原因造成的| 夏天像什么| 机场地勤是干什么的| 觅食是什么意思| 南方有什么生肖| 当局是什么意思| 中指戴戒指代表什么| 来大姨妈拉肚子是什么原因| 活动性肺结核是什么意思| 什么地发现| 神经纤维由什么组成| 送老师什么花好| 一条条什么| psv医学是什么意思| 双向转诊是什么意思| 露从今夜白下一句是什么| 拔智齿后吃什么| 欧代是什么| 婴儿补钙什么牌子的好| 脖子疼吃什么药| 汉语什么意思| 女性喝什么利尿最快| 为什么会精神衰弱| 五谷指的是什么| 什么居什么业| 人最重要的是什么| 早上的太阳叫什么| 成服是什么意思| 少尉军衔是什么级别| 凤凰指什么生肖| amh是什么检查项目| lcp是什么意思| 四肢肌力5级什么意思| 一个兹一个子念什么| 基友是什么关系| 嗓子痒控制不住咳嗽是什么原因| 职称有什么用| 1980年五行属什么| 胃酸过多什么原因| 211属于什么大学| 负离子是什么| 超负荷是什么意思| 五指姑娘是什么意思| 7月31号是什么星座| 射进去什么感觉| 山梨酸钾是什么东西| 心脏早搏是什么原因| HPV高危亚型52阳性什么意思| 扁桃体发炎咳嗽吃什么药效果好| 嗫嚅是什么意思| 520是什么节日| 绿茶什么意思| 大便秘结是什么意思| 什么是目标| 梦见吃葡萄是什么意思| 6月25日是什么星座| pm2.5是什么| 瘘管是什么病| 腹腔气体多是什么原因| 承五行属性是什么| 人生得意须尽欢什么意思| 子宫萎缩是什么原因| 观音成道日是什么意思| 薄荷音是什么意思| 心烦意乱吃什么药| 发票抬头是什么意思| 白癜风有什么危害| 泰勒为什么叫霉霉| 风热感冒和风寒感冒有什么区别| peace是什么牌子| 六亲缘浅是什么意思| 孩子咳嗽有痰吃什么药| 锋芒毕露什么意思| 镪水池是什么| 息影是什么意思| 乙肝有什么明显的症状| 逍遥丸配什么治失眠| 着数是什么意思| 知了吃什么东西| 51岁属什么| 1月1号什么星座| tr是什么意思| 吃什么拉什么完全不能消化怎么办| 水光针是什么| 肝素是什么| 经常吃莲子有什么好处| 脑白质疏松是什么意思| 员工体检费计入什么科目| 八月三日是什么星座| 直肠指检能检查出什么| winbond是什么品牌| 锲而不舍是什么生肖| 屁多屁臭是什么原因| 蚧壳虫用什么药最有效| 贱痣是什么意思| 中医师承是什么意思| 什么时候恢复高考| 吃猪皮有什么好处和坏处| 什么是处男| 学兽医需要什么学历| 适得其反什么意思| 8023是什么意思| 大排畸是什么检查| 镜花水月什么意思| 心神不定是什么生肖| 成是什么生肖| 全身燥热是什么原因引起的| 乌龟下蛋预示着什么| 苹果是什么季节成熟的| 普洱茶是属于什么茶| 肾阳虚吃什么药好| 太阳穴胀痛是什么原因| 国字脸适合什么发型| 奔波是什么意思| 人生意义是什么| 智力是什么意思| 优是什么意思| 减肥什么方法有效| 苕皮是什么做的| 什么人容易得帕金森病| 什么是丛林法则| 有什么神话故事| 基友是什么关系| 小暑节气吃什么| 来月经小腹痛是什么原因| 痉挛是什么意思啊| 八九年属什么| 胰腺在人体起什么作用| 经常喝藕粉有什么好处| 11月15日什么星座| 测血糖挂号挂什么科| dvf是什么档次的牌子| 指甲很薄很软是为什么| 白酒都有什么香型| 甲状腺吃什么盐| 容易饿是什么原因| 什么什么团结| 为什么会突然耳鸣| 神经内科主要看什么| 纳肛是什么意思| cps是什么意思| 鼓刹和碟刹有什么区别| 石字旁有什么字| 宝典是什么意思| 梦见两只狗是什么征兆| 飞机下降时耳朵疼是什么原因| 右眼跳代表什么| 送表的寓意是什么| 小孩有口臭是什么原因引起的| 霉菌孢子是什么意思| 农历六月六是什么日子| 什么馅的馄饨好吃| 减肥期间晚上可以吃什么| 脉沉细是什么意思| 私联是什么意思| 感染性腹泻吃什么药| 做梦放鞭炮什么意思| 四个火读什么| 直肠ca是什么意思| 逼长什么样| 秦始皇是什么民族| 牙疼是什么火引起的| 沙棘不能和什么一起吃| 感冒咳嗽吃什么药好| 糖尿病人适合吃什么水果| 牙痛吃什么药最好| 奥美拉唑与雷贝拉唑有什么区别| 口腔溃疡能吃什么| 豺狼虎豹为什么豺第一| 97年属什么生肖| 窦房结内游走性心律是什么意思| 今晚吃什么家常菜| 均一性红细胞什么意思| 八字桃花是什么意思| 三十六计第一计是什么| 小太阳是什么牌子| 什么水果热量低| 喉咙里老是有痰是什么原因| 小便多吃什么药好| hi是什么| 什么枕头好| 合肥古代叫什么| 喝最烈的酒下一句是什么| 西游记是什么时候写的| 不一般是什么意思| 珍母口服液有什么作用| 宝批龙什么意思| 榴莲补什么| nos是什么单位| 王久是什么字| 母亲节送母亲什么礼物| 什么能美白皮肤而且效果快| 左耳朵嗡嗡响是什么原因引起的| 走马灯什么意思| 治疗湿疹吃什么药| 端午节是什么星座| 血压低压高是什么原因造成的| 早早孕试纸什么时候测最准| 拉黑色的屎是什么原因| 丝瓜为什么会苦| 100聚酯纤维是什么面料| 突兀什么| 女性尿特别黄是什么原因| 女人什么时候性欲最强| 继往开来是什么意思| 玉帝叫什么名字| 类风湿不能吃什么食物| 尿酸盐结晶是什么意思| 来月经为什么会拉肚子| 绿豆汤放什么糖最好| 中耳炎吃什么药好| 中国国鸟是什么鸟| brown什么意思| 肝结节是什么病严重吗| 囊变是什么意思| 日食是什么现象| 什么是孝| ol是什么| 骨折和骨裂有什么区别| 一月二十五号是什么星座| 尿潜血挂什么科| 什么中药治肝病最好| 凝血四项能查出什么病| 精液带血是什么原因| 同房是什么意思| 昆仑雪菊有什么作用| 治痛风吃什么药| 眼睛出血是什么原因| 滑肠是什么意思| 五行代表什么意思| 公鸡为什么打鸣| 陪嫁一般陪些什么东西| 小便出血是什么原因| 胚发育成什么| 洛阳白马寺求什么最灵| 什么是共产主义社会| 黄喉是牛的什么部位| 百度Ётамс сёрматфть няфтьфонц потмос (содержаниянцты)

泾河新城:比学先进科学植树 加快加密见缝增绿

Википедиесь лопаста
百度 并对奕泽的生产准备工作高度认可,也对这款诠释了丰田发展新思维的产品更加充满自信。

Для документации этого модуля может быть создана страница Модуль: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,
		catAmbiguousGeoChains = '[[Категория:Википедия:Страницы с неоднозначными геоцепочками]]',
		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;
复方氨酚烷胺片是什么药 姑姑的老公叫什么 潜血弱阳性是什么意思 无名指长痣代表什么 舌裂吃什么药
天天喝绿茶有什么好处和坏处 早餐吃什么减肥 梦见自己和别人吵架是什么意思 女性脱发严重是什么原因引起的 心理学属于什么学科
身上长瘊子是什么原因 七夕节什么时候 生物学是什么 查处是什么意思 为什么每次同房后都会尿路感染
狗是什么意思 心脏供血不足是什么原因引起的 耳鸣是什么原因造成的 宝宝喜欢趴着睡觉是什么原因 宫颈纳氏囊肿是什么
腹泻拉稀水吃什么药hcv8jop5ns4r.cn 姝五行属什么beikeqingting.com 潮起潮落是什么意思hcv9jop6ns9r.cn 右胸痛什么原因hcv8jop6ns8r.cn 为什么有的人晒不黑hcv8jop1ns5r.cn
嘴唇红润是表示什么hcv9jop5ns8r.cn 锦纶是什么材料hcv7jop6ns2r.cn 手起皮是什么原因hcv8jop2ns5r.cn 月和什么有关hcv8jop1ns8r.cn 小拇指和无名指发麻是什么原因hcv7jop5ns0r.cn
老农民韩美丽结局是什么hcv9jop0ns6r.cn 三叉戟是什么车gangsutong.com 其他垃圾有什么cl108k.com 壮阳是什么意思sanhestory.com alike是什么意思huizhijixie.com
小孩子手脚脱皮是什么原因hcv8jop5ns9r.cn buds是什么意思hcv9jop8ns3r.cn 什么运动使人脸部年轻hcv8jop9ns9r.cn 吃什么减脂肪最快最有效的方法cj623037.com 端游什么意思hcv9jop4ns7r.cn
百度