مودول:ب.ص.م/أدوات/مبنى

من ويكيپيديا

local p = {}
local localdata = require( 'وحدة:ب.ص.م/بيانات' )
local item = localdata.item
local wd = require "Module:Wikidata/fr"
local general = require "وحدة:ب.ص.م/أدوات"
local linguistic = require "Module:Linguistique"
local address = require "وحدة:ب.ص.م/بيانات/عنوان"

local function keyDate(event)
	return wd.keyDate(event, item, {conjtype = 'comma', showqualifiers = {'P518'}, link = '-'})
end

local function inclexcl(statement, params) -- formatte les qualificatifs "P518" / "P1011" (à mettre plutôt dans un sous module de Module:Wikidata, comme pour les dates ?
	local str = wd.formatSnak(statement.mainsnak, params)
	if not statement.qualifiers then
		return str
	end
	local incl = wd.getFormattedQualifiers(statement, "P518")
	local excl = wd.getFormattedQualifiers(statement, "P1011")

	if incl then
		str = str .. linguistic.inparentheses(incl .. " y compris") -- pas la formulation la plus élégante mais elle évite les problèmes d'accord grammaticaux
	end
	if excl then
		str = str .. linguistic.inparentheses("sans " .. excl) -- pas la formulation la plus élégante mais elle évite les problèmes d'accord grammaticaux
	end
	return str
end

function p.creatorQuery(prop) 
	return {
		property = prop,
		entity = localdata.item,
		showqualifiers = {'P518'},
		showdate = true,
		qualiflink = '-',
		statementformat = function(statement)
			
			local str
			-- On commence par les qualificatifs (attibué à, atelier etc.)
			local possiblequalifiers = {
				P1773 = "attribué $to $creator", 
				P1774 = "atelier $of $creator",
				P1775 = "suiveur $of $creator",
				P1776 = "cercle $of $creator",
				P1777 = "حسب $creator", -- TODO : d'après LE Maître X
				P1778 = "faux d'après $creator",
				P1779 = "$creator (?)",
				P1780 = "مدرسة $of",
				P1877 = "حسب عمل $of",
			}
	
			if statement.qualifiers then
				for qualif, text in pairs(possiblequalifiers) do
					local creator = wd.getFormattedQualifiers(statement, {qualif})
					if creator then
						str = text
						str = mw.ustring.gsub(str, '$to $creator', "à ".. creator)
						str = mw.ustring.gsub(str, '$of $creator', linguistic.of(creator))
						str = mw.ustring.gsub(str, '$creator', creator)
						break
					end
				end
			end
						
			-- Sinon, la voie normale
			if not str then
				str = wd.formatStatement(statement, {speciallabels = {Q4233718 = "anonyme"}}) -- speciallabels pour éviter le lien par défaut
			end
			return str
		end
	}
end

--Titrest
function p.title()
	--	local class = en-tête par défaut à définir ici ?
	return general.title()
end

--Image
function p.mainimage(cat, defaultimage)
	if not cat then 
		cat = 'Article à illustrer Bâtiment divers'
	end
	return general.mainimage(cat, defaultimage)
end

function p.country()
	return -- déprécié	
end

function p.historicalregion()
	return {
		type = 'row', -- pour les régions historiques, non adminstratives
		value = 'منطقة',
		label = localdata['اسم المنطقة'] or 'المنطقة',
	}
end

function p.adminloc(divstr) -- affiche l'adresse complète (rue, divisions administratives pertinentes, pays) dans un champ unique

	-- pas de paramètre global pour la ligne streetstr et la ligne divstr, dépend de l'historique du modèle utilisé
	local country = localdata["بلد"]
	local streetstr =  localdata['العنوان'] or localdata['عنوان']
	local val = address.fullAddress(localdata['item'], country, nil, streetstr, divstr)
	return 
		{
		type = 'row',
		label = 'العنوان',
		value = function() return val end
		}
end

function p.adminlocation() -- Fonction assez compliquée du fait des différences entre infobox. Simlifiable si on harmonise les infobox
	-- infobox à prendre en compte : bâtiment, gratte-ciel, gare, château
	
	if not (localdata['subdivision1'] or localdata['subdivision_name1'] or localdata['العنوان'] or localdata['عنوان']) then
		return p.adminloc()
	end
	return {
		type = 'multi', 
		rows = {
			general.country(),
			p.historicalregion(),
			{
				type = 'row', 
				value = {'subdivision_name1', 'subdivision1', 'اسم المنطقة 1'},
				label = localdata['subdivision_type1'] or localdata['نوع المنطقة 1'] or 'المنطقة 1'
			},
			{
				type = 'row', 
				value = {'subdivision_name2', 'subdivision2', 'اسم المنطقة 2'},
				label = localdata['subdivision_type2'] or localdata['نوع المنطقة 2'] or 'المنطقة 2'
			},
			{
				type = 'row', 
				value = {'subdivision_name3', 'subdivision3', 'اسم المنطقة 3'},
				label = localdata['subdivision_type3'] or localdata['نوع المنطقة 3'] or 'المنطقة 3'
			},
			{
				type = 'row',
				value = {'العنوان','عنوان'},
				label = 'العنوان',
				wikidata = require('وحدة:ب.ص.م/بيانات/عنوان').wikidataAddress(localdata.item),
			},
		}
	}
end

function p.onshoreof()
	return {
		type = 'row',
		label = 'على ضفاف',
		value = {'baigné par', 'على ضفاف'},
		wikidata = {property = 'P206', defaultlinkquery = {property = 'P361'}},
	}
end

function p.watershed()
	return {
		type = 'row',
		label = 'Bassin versant',
		value = 'bassin versant',
		wikidata = {property = 'P4614', defaultlinkquery = {property = {'P4614', 'P138'}}},
	}
end

function p.protectedarea()
	return {
		type = 'row',
		label = 'منطقة محمية',
		plurallabel = 'مناطق محمية',
		value = {'منطقة محمية', 'مناطق محمية'},
		property = 'P3018',
	}
end

function p.island()
	return {
		type = 'row',
		label = 'جزيرة',
		plurallabel = 'جزر',
		value = 'جزيرة',
		property = 'P5130',
	}
end

function p.mountainrange()
	return {
		type = 'row',
		label = 'السلسلة الجبلية',
		plurallabel = 'السلاسل الجبلية',
		value = {'جبل', 'سلسلة جبلية'},
		wikidata = {property = 'P4552', defaultlinkquery = {property = 'P4552'}},
	}
end

function p.elevation()
	return {
		type = 'row',
		label = 'الإرتفاع',
		value = 'الإرتفاع',
		wikidata = {property = 'P2044', targetunit = 'متر', conjtype = ' ou ', rounding = '0', numval = '2'},
	}
end

function p.coordinates(args)
	return general.coordinates(args)
end

function p.website(localparam) 
	return general.website(localparam)
end

function p.construction()
	return {
		type = 'multi', 
		rows = {

			-- début construction, fin construction (legacy infobox Stade, Infobox Château),
			{
				type = 'row',
				value = {'بداية التشييد', 'بداية', 'حجر_الأساس','broke_ground','broke ground'},
				label = 'التشييد', 
			},
			{
				type = 'row',
				value = {'نهاية التشييد', 'نهاية'}, 
				label = 'نهاية التشييد', 
			},

			-- construction (nom de paramètre "date de construction" à déprécier)
			{
				type = 'row',
				value = {'تشييد', 'التشييد', 'التشييد'}, 
				label = 'التشييد', 
				wikidata = keyDate{'Q385378', 'P571'}
			},
		}
	}

end

function p.reconstruction()
	return {
		type = 'multi', 
		rows = {

			-- début reconstruction, fin reconstruction (legacy infobox Stade, Infobox Château),
			{
				type = 'row',
				value = {'بداية إعادة التشييد', 'بداية'}, 
				label = 'بداية إعادة التشييد', 
			},
			{
				type = 'row',
				value = {'نهاية إعادة التشييد', 'نهاية'}, 
				label = 'نهاية إعادة التشييد', 
			},

			-- reconstruction (nom de paramètre "date de reconstruction" à déprécier)
			{
				type = 'row',
				value = {'إعادة التشييد', 'تاريخ إعادة التشييد'}, 
				label = 'إعادة التشييد', 
				wikidata = keyDate{'Q1370468'}
			},
		}
	}

end

function p.opening()  --ouverture / consécration / date de mise en service (!= date de construction)
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row', 
				value =  {"تاريخ الافتتاح", "تاريخ_الافتتاح", "mise en service",'opened'}, 
				label = 'الافتتاح', 
				wikidata = keyDate{'P1619', 'Q15051339'} -- P1619 = ouverture officielle, pas ouverture de facto
			},
			{
				type = 'row', 
				value = 'الافتتاح', 
				label = 'الافتتاح',
				blockers = 'الافتتاح', 
				wikidata = keyDate{'Q1417098'}
			},

			{
				type = 'row', 
				value = 'consécration', 
				label = 'Consécration',
				blockers = 'inauguration',
				wikidata = keyDate{ 'Q125375'}
			},
			{
				type = 'row', 
				value = 'première lumière', 
				label = '[[Première lumière]]',
				blockers = 'Ouverture',
				wikidata = keyDate{'Q1306940'} -- P1619 = ouverture officielle, pas ouverture de facto
			},
		}
	}
end


function p.renovation()
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				value = 'ترميم',
				label = 'الترميم',			
				wikidata = keyDate{'Q217102'},
				blockers = 'تجديد',
			},
			{
				type = 'row',
				value = 'تجديد',
				label = 'التجديد',			
				wikidata = keyDate{'Q2144402'},
				blockers = 'ترميم',
			},
			{
				type = 'row',
				value = {'توسعة', 'التوسعة'},
				label = 'التوسعة',		
				wikidata = keyDate{'Q18621193'},
				blockers = 'restauration',
			},
			{
				type = 'row',
				value = 'أشغال أخرى',
				label = 'أشغال أخرى',		
		},
	}
}
end

function p.demolition()
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				value = {'هدم', 'تاريخ الهدم'},
				label = 'الهدم',
				wikidata = keyDate('Q331483')
				},
				{
				type = 'row',
				value = {'تدمير'},
				label = 'التدمير',
				wikidata = keyDate('Q17781833')
			}
		}
	}
end

function p.closure()
	return {
		type = 'row',
		value = {'الإقفال', 'تاريخ_الإقفال'},
		label = 'الإقفال',
		wikidata = keyDate{'Q14954904', 'P3999', 'P576'} -- P576: date de dissolution, plutôt réservé aux organisations
	}
end

function p.usage()
	return {
		type = 'row',
		label = 'الاستعمال',
		value = 'الاستعمال', 
		wikidata = {
			property = 'P366',
			link = '-',
			speciallabels = {Q182060 = 'مكاتب'}, -- bureaux semble toujours pouvoir se mettre au pluriel quand c'est en P366 d'un bâtiment
		}	
	}
end

function p.operator()
	return {
		type = 'row',
		label = 'الإدارة',
		wikidata = {property = 'P137', showdate= true},
		value = {'إدارة', 'مسير','المشغل','operator','الإدارة'}
	}
end

function p.transport()
	return {
		type = 'multi', 
		rows = {
			{type = 'row', label = 'الموقف', value = 'موقف'},
			{type = 'row', label = 'محطة', value = 'محطة'},
			{type = 'row', label = 'الميترو', value = 'ميترو'},
			{type = 'row', label = 'ترمواي', value = {'قطار', 'ترمواي'}},
			{type = 'row', label = 'حافلة', value = {'باص', 'حافلة'}},
		},
	}
end

function p.part_of() -- le complexe immobilier auquel appartient un bâtiment
	return {
		type = 'row',
		label = 'جزء من',
		value = 'جزء من',
		wikidata = {
			property = 'P361',
			condition = function(claim)
				local v = wd.getMainId(claim)
				return wd.isInstance("Q1497364", v, 1)
			end,
		}
	}
end

function p.archistyle()
	return {
		type = 'row',
		label = 'النمط المعماري',
		plurallabel = 'الأنماط المعمارية',
		value = {'نمط معماري', 'نمط','طراز'},
		wikidata = {
			property = {'P149', 'P135'},
			labelformat = function(id)
			local label = mw.wikibase.label(id)
			return label
			end
		}
	}
end

function p.creator() -- toute sorte de créateurs, pourraient peut-être être partagé avec infobox oeuvre d'art
	local wdarchitect, wdengineer = p.creatorQuery("P84"), p.creatorQuery("P631")
	if wdarchitect and wdengineer then -- ne pas afficher les deux si c'est la même valeur
		if (wd.formatStatements{property = "P84", displayformat = "raw", entity= localdata.item} == wd.formatStatements{property = "P631", displayformat = "raw", entity = localdata.item}) then
			wdengineer = nil
		end
	end
	return {
		type = 'multi',
		rows = { 
			-- architect
			{
				type = "row",
				label =  "المهندس المعماري",
				plurallabel = "المهندسون المعماريون",
				value = {'معماري','المهندس المعماري','المهندس_المعماري','architect'},
				wikidata = wdarchitect,
			},
			-- ingénieur
			{
				type = "row",
				label = "المهندس الإنشائي",
				plurallabel = "المهندسون الإنشائيون",
				value = {'مهندس','المهندس_الإنشائي'},
				wikidata =  wdengineer,
			},
			-- créateur (quand les autres noms ne conviennent pas)
			{	type = "row",
				label = "المصمم",
				plurallabel = "المصممون",
				value = "مصمم",
				-- ne pas utiliser Wikidata si le paramètre "architecte" est renseigné (risques de doublon)
				wikidata =  p.creatorQuery("P170"),
				blockers = {'مهندس'},
			},
		}
	}
end


function p.owner()
	return {
		type = 'multi', 
		rows = {
			{
				type = 'row',
				label = 'المالك الأول',
				plurallabel = 'الملاك الأوائل',
				value = 'المالك الأول',
			},
			{
				type = 'row',
				label = 'المالك الحالي',
				plurallabel = 'الملاك الحاليون',
				value = 'المالك الحالي',
			},
			{
				type = 'row',
				label = 'المالك',
				plurallabel = 'الملاك',
				value = {'المالك','owner','المالك'},
				wikidata = function() return require('وحدة:ب.ص.م/بيانات/مالك').formatFromItem(localdata.item, {sorttype = 'chronological', showdate = true, conjtype = 'comma', precision = 'year'}) end,
			}
		}
	}
end

function p.shape()
	return {
		type = 'row',
		label = 'الشكل',
		value = {'شكل', 'هيئة'},
		property = 'P1419',
	}
end

function p.dimensions()
	return {
	type = 'multi', 
		rows = {
	{
		type = 'row',
		label = 'ارتفاع الهوائي' ,
		value = 'ارتفاع الهوائي',
		wikidata = {property = 'P2048', targetunit = 'م', qualifier = 'P518', qualifiervalue = {'Q131214','Q852590'}}
	},
	{
		type = 'row',
		label = 'ارتفاع السقف',
		value = 'ارتفاع السقف',
		wikidata = {property = 'P2048', targetunit = 'م', qualifier = 'P518', qualifiervalue = 'Q83180'}
	},
	{
		type = 'row',
		label = 'الطوابق',
		value = 'الطوابق' 
	},
--- Hauteur générique : exclut les valeurs Wikidata affichées dans une des lignes précedentes + affiche le qualificatif P518
	{
		type = 'row',
		label = 'الارتفاع',
		value = 'ارتفاع',
		wikidata =  {property = 'P2048', targetunit = 'م', excludequalifier = {'P518', 'P794'}, excludequalifiervalue = {'Q24192182', 'Q131214','Q852590', 'Q83180'}, statementformat = function(statement) return inclexcl(statement, {targetunit = 'متر', rounding = '1'}) end}
	},
	{
		type = 'row',
		label = 'العمق',
		value = 'عمق',
		wikidata =  {property = 'P2610', targetunit = 'متر', numval = '2', statementformat = function(statement) return inclexcl(statement, {targetunit = 'متر', rounding = '1'}) end},
	},
	{
		type = 'row',
		label = 'الطول',
		value = 'طول',
		wikidata = {property = 'P2043', targetunit = 'متر', numval = '2', statementformat = function(statement) return inclexcl(statement, {targetunit = 'متر', rounding = '1'}) end},
	},
	{
		type = 'row',
		label = 'العرض',
		value = 'عرض',
		wikidata = {property = 'P2049', targetunit = 'متر', numval = 2, statementformat = function(statement) return inclexcl(statement, {targetunit = 'متر', rounding = '1'}) end},
	},
	{
		type = 'row',
		label = 'الباع',
		value = 'باع',
		wikidata = {property = 'P2050', targetunit = 'متر', conjtype = 'or', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'القطر',
		value = 'قطر',
		wikidata = {property = 'P2386', targetunit = 'متر', conjtype = 'or', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'المحيط',
		value = {'محيط', 'المحيط'},
		wikidata = {property = 'P2547', targetunit = 'متر', conjtype = 'or', rounding = '1', numval = '2'},
	},
	-- Hauteur (avec plusieurs différentes affichées pour les gratte-ciel, voir les bases Emporis ou skyscrapercenter
	{
		type = 'row',
		label = 'الإرتفاع الهندسي',
		value = 'الإرتفاع',
		wikidata =  {property = 'P2048', targetunit = 'm', qualifier = {'P794'}, {'P518', 'P794'}, qualifiervalue = {'Q24192182'}}
	},
	{
		type = 'row',
		label = 'المساحة',
		value = {'المساحة', 'مساحة'},
		wikidata = {property = 'P2046', targetunit = 'متر مربع', conjtype = 'or', rounding = '1', numval = '2'},
	},
	{
		type = 'row',
		label = 'الحجم',
		value = 'حجم',
		wikidata = {property = 'P2234', targetunit = 'متر مكعب', conjtype = 'or', rounding = '1', numval = '2'},
	}
	}
}
end

function p.floors()
	return {
	type = 'multi', 
		rows = {
	{
		type = 'row',
		label = 'الطوابق',
		value = {'الطوابق', 'طوابق','عدد الطوابق','عدد_الطوابق','floor_count'},
		property = 'P1101',
	},
	{
		type = 'row',
		label = 'الطوابق الأرضية',
		value = {'الطوابق الأرضية', 'طوابق أرضية','عدد الطوابق الأرضية'},
		property = 'P1139',
	}
	}
}
end

function p.destroyedby()
	return {
		type = 'row',
		label = 'هدمه',
		value = {'هدمه'}, 
		property = 'P770',
	}
end

function p.material()
	return {
		type = 'row',
		label = 'مادة البناء',
		plurallabel = 'مواد البناء',
		value = 'مادة البناء', 
		wikidata = require('وحدة:ب.ص.م/بيانات/مادة').formatFromItem(localdata.item),
	}
end

function p.colour()
	return {
		type = 'row',
		label = 'اللون',
		plurallabel = 'الألوان',
		value = {'لون', 'ألوان'},
		property = 'P462',
	}
end

function p.inscription()
	return {
		type = 'row',
		label = 'لافتة',
		value = {'لافتة', 'يافطة'},
		wikidata = {property = 'P1684', numval = '1'},
	}
end

function p.equipment()
	return {
		type = 'row',
		label = 'التجهيز',
		plurallabel = 'التجهيزات',
		value = {'تجهيز', 'التجهيز'},
		property = 'P912',
	}
end

function p.replaces()
	return {
		type = 'row',
		label = 'عوض',
		value = 'عوض',
		property = 'P1398',
	}
end

function p.replacedby()
	return {
		type = 'row',
		label = 'حل مكانه',
		value = 'حل مكانه',
		property = 'P167',
	}
end

function p.visitors()
	return {
		type = 'row',
		label = 'عدد الزوار سنويا',
		value = {'الزوار', 'عدد الزوار سنويا','زوار'},
		wikidata = {property = 'P1174', showdate = 'true', numval = 1, sorttype = "inverted"},
	}
end

function p.protection()
	return {
		type = 'row',
		label = 'Statut patrimonial',
		value = {'classement', 'protection'},
		--wikidata = require('Module:Classement').formattedList(localdata.item)
	}
end

function p.unesco() -- pour remplacer [[Modèle:Infobox Patrimoine Mondial]] à ajouter : paramètres extension, patrimoine en péril, retrait, gestion des monuments faisant partie d'un ensemble
	local id = localdata['رقم']
	if (id == '-') then
		return nil
	end
	if id then
		id = '[http://whc.unesco.org/ar/list/' .. id .. ' ' .. id .. ']'

	else
		id = wd.formatAndCat{entity = item, property = 'P757',  urlpattern = 'http://whc.unesco.org/ar/list/$1'}

	end
	if (not id) then
		return nil
	end
	return 
	{type = 'table', title = '[[File:World Heritage Emblem.svg|15px|alt=Logo du patrimoine mondial|link=موقع تراث عالمي]] تراث عالمي', rows = {
		{type = 'row', label = 'Désignation', value = 'nom unesco'},
		{type = 'row', label = "النوع", value = 'النوع', wikidata = {property = 'P1435', targetvalue = {'Q16617071', 'Q52683527', 'Q52683530'}}},
		{type = 'row', label = "السنة", value = 'السنة', wikidata = {property = 'P1435', targetvalue = {'Q9259', 'Q16617071', 'Q52683527', 'Q52683530'}, showonlyqualifier = {'P580'}}},
		{
		type = 'row',
		label = "رقم التعريف",
		value = function() return id end,
		},
		{	
		type = 'row',
		label = "المعايير",
		singularlabel = "المعيار",
		value = function(localdata)
			if localdata['المعايير'] then
					return '[http://whc.unesco.org/ar/criteres/' .. localdata['المعايير'] .. ']'
			end
			end, 
		wikidata = function(item)
			local str, numclaims = wd.formatStatements{entity = item, property = 'P2614', link = '-', conjtype = ' ', returnnumberofvalues = true}
			if str then
				return wd.formatAndCat{value = '[http://whc.unesco.org/ar/criteres/$1 ' .. str .. ']', entity = item, property = 'P2614'}, numclaims
			end
			end
		},
		{type = 'row', label = 'Surface', value = 'surface unesco'},
		{type = 'row', label = 'Zone tampon', value = 'surface zone tampon unesco'},
	}
}
end

function p.geoloc(params)
	return general.geoloc(params)
end

return p