وحدة:بطاقة/ملعب
المظهر
| هذه صفحة ملعب الوحدة لصفحة وحدة:بطاقة (فرق). |
| صُنّفت هذه الوحدة على أنها في المرحلة النهائية. في هذه المرحلة تكون الوحدة وصلت لنقطة يمكن أن تستخدم في أي صفحة أو أي نطاق. كما أنها تؤدي الهدف الذي بنيت من أجله ولا توجد أي أخطاء بها. يمكن أن يشار إلى هذه الوحدة في صفحات المساعدة أو أي صفحات إرشادية على ويكيبيديا، كما يمكن أن توضع كأمثلة للجدد ليتعلموا منها. |
وحدة فرعية جديدة
[عدل]لاستحداث وحدة فرعية جديدة لقالب بطاقة جديد، عوض <اسم_الوحدة_الفرعية> بالاسم المناسب :
لماذا هذا الأسلوب ؟
[عدل]هذه الوحدة تعمل على جعل عملية استحداث قوالب البطاقات (أو قوالب معلومات أو Infobox) أسهل/أبسط ما يمكن من خلال تعريفات بسيطة في وحدات فرعية.
- المميزات
- استحداث القوالب يندرج ضمن عملية البرمجة واستعمال وحدات فرعية بلغة لوا (Lua) يضبط المكتوب لضمان غياب الأخطاء.
- عملية ترتيب البيانات المعروضة بسيطة ولا تستدعي تغيير الأرقام (مثلما هو الحال مع module:Infobox).
- توفر مكتبات لجلب البيانات الأكثر استعمالا لاقتصاد الوقت والكود.
- الجمع في مكان واحد للمبرمج/المطور لتوفير التعليمات والشروح.
- توفر أدوات مساعدة لتحيين صفحة الشرح بصورة آنية وآلية أو نصف آلية (مثل : الصيغة وبيانات القالب ..) بعد تحيين الوحدة أو أحد المكتبات المساعدة.
الاستخدام
[عدل]هذه الوحدة تستعمل لعرض قالب معلومات (Infobox) أو بطاقة بالاعتماد على وحدة فرعية تحتوي على بيانات حول مضمون هذا القالب. تسمح هذه الوحدة بإجراء استجوابات بصورة مبسطة لويكي بيانات لجلب ما توفر من البيانات.
استحداث قالب معلومة (أو بطاقة) يمر بخطوتين :
- إنشاء وحدة فرعية بعنوان من الشاكلة : وحدة:بطاقة/قالب/اسم_قالب
- مثال : وحدة:بطاقة/قالب/لعبة
- إنشاء قالب يستعمل لاحقا في المقالات. محتوى هذا القالب سيكون :
{{#استدعاء:بطاقة|تركيب|وحدة=اسم_الوحدة_الفرعية}}- مثال :
{{#استدعاء:بطاقة|تركيب|وحدة=لعبة}}
- مثال :
محتوى الوحدة الفرعية
[عدل]- محتوى فارغ
return {
maincolor = '#DDDDDD' -- اللون المستعمل لعنوان البطاقة
,parts = {} -- محتويات البطاقة
}
- محتوى نموذجي
local generic = require( 'وحدة:بطاقة/أدوات' )
return {
-- اللون المستعمل لعنوان البطاقة
maincolor = '#DDDDDD',
-- محتويات البطاقة
parts = {
generic.title(),
{type = 'subtitle', value = {'الاسم_الأصلي'}},
generic.logo(),
generic.mainimage(),
{type = 'table', title = 'معلومات عامة', rows = {
{type = 'row',
label = 'الصانع',
value ={'صانع','manufacturer'},
wikidata = {property='P176'}
},
{type = 'row',
label = 'أسماء أخرى',
value ={'أسماء_أخرى','aka'},
},
{type = 'row',
label = '[[شركة أم]]',
value ={'شركة_أم','parent_company'},
},
}},
}
}
- محتوى متقدم يجمع التعليمات بالشروح
return {
-- شرح مختصر عن وظيفة البطاقة
description = "بطاقة تعريفية عن ...",
-- اللون المستعمل لعنوان البطاقة
maincolor = '#DDDDDD',
-- محتويات البطاقة
parts = {
generic.title(),
{type = 'subtitle', value = {'الاسم_الأصلي'}},
generic.logo(),
generic.mainimage(),
{type = 'table', title = 'معلومات عامة', rows = {
{type = 'row',
label = 'الصانع',
value ={'صانع','manufacturer'},
wikidata = {property='P176'},
metadata = {
description = "تسمية صانع المنتج",
option = "required", -- تظهر عند التحرير المرئي على أنها معلومة ضرورية يجب توفيرها
type = "string",
}
},
{type = 'row',
label = 'أسماء أخرى',
value ={'أسماء_أخرى','aka'},
metadata = {
description = "أسماء أخرى متداولة",
option = "suggested",
type = "string",
}
},
{type = 'row',
label = 'تاريخ التأسيس',
value ={'تأسيس','founded'},
metadata = {
description = "تاريخ التأسيس الشركة",
option = "suggested",
-- تظهر عند التحرير المرئي على أنها معلومة تمثل تاريخا لذا وجب كتابة بنسق التواريخ.
type = "date"
}
},
}},
}
}
توثيق المعطيات (metadata)
[عدل]metadata = {
description = "", -- شرح مختصر
option = "", -- أهمية المعلومة : required / suggested / deprecated
type = "", -- نوع المعلومة : number/boolean/date/url/wiki-file-name/line/content
example = "", -- مثال عن نص يساعد في ملء صحيح للخانة
suggestedvalues = {}, -- قائمة لقيم مقترحة مساعدة.
autovalue = ""; -- قيمة مولدة آليا مثل :{{subst:CURRENTYEAR}}
default = "" -- قيمة ثابتة
}
الأيقونات المتوفرة
[عدل]| خلفية فاتحة | خلفية فاتحة وأيقونة على اليسار | خلفية داكنة |
|---|---|---|
| aerostat | aerostat | aerostat |
| aikido | aikido | aikido |
| alpinisme | alpinisme | alpinisme |
| arbitre | arbitre | arbitre |
| arc | arc | arc |
| archives2 | archives2 | archives2 |
| arduino | arduino | arduino |
| electro | electro | electro |
| artiste | artiste | artiste |
| artsmartiauxjap | artsmartiauxjap | artsmartiauxjap |
| association | association | association |
| athletisme | athletisme | athletisme |
| audio | audio | audio |
| auteur | auteur | auteur |
| autogire | autogire | autogire |
| automobile | automobile | automobile |
| avion | avion | avion |
| aviron | aviron | aviron |
| badminton | badminton | badminton |
| baseball | baseball | baseball |
| basket-ball | basket-ball | basket-ball |
| bd | bd | bd |
| biathlon | biathlon | biathlon |
| biere | biere | biere |
| book | book | book |
| universite | universite | universite |
| boxe | boxe | boxe |
| calendrier | calendrier | calendrier |
| camera | camera | camera |
| canada | canada | canada |
| cardinal | cardinal | cardinal |
| catch | catch | catch |
| chateau | chateau | chateau |
| chimie | chimie | chimie |
| cinema | cinema | cinema |
| commonwealth | commonwealth | commonwealth |
| communication | communication | communication |
| cyclisme | cyclisme | cyclisme |
| deportation | deportation | deportation |
| diplomatie | diplomatie | diplomatie |
| disney | disney | disney |
| droit | droit | droit |
| drone-civil | drone-civil | drone-civil |
| echecs | echecs | echecs |
| egypte-antique | egypte-antique | egypte-antique |
| entreprise | entreprise | entreprise |
| entreprise-blanc | entreprise-blanc | entreprise-blanc |
| equitation | equitation | equitation |
| escalade | escalade | escalade |
| escrime | escrime | escrime |
| espagne | espagne | espagne |
| eveque | eveque | eveque |
| factory | factory | factory |
| floorball | floorball | floorball |
| fondeur | fondeur | fondeur |
| football | football | football |
| footballblack | footballblack | footballblack |
| footUS | footUS | footUS |
| futsal | futsal | futsal |
| golf | golf | golf |
| grappe | grappe | grappe |
| gymnastique | gymnastique | gymnastique |
| handball | handball | handball |
| handballblack | handballblack | handballblack |
| helicoptere | helicoptere | helicoptere |
| hockey | hockey | hockey |
| hockey-sur-gazon | hockey-sur-gazon | hockey-sur-gazon |
| hospitaliers | hospitaliers | hospitaliers |
| humain | humain | humain |
| informatique | informatique | informatique |
| internet | internet | internet |
| israel-judaisme | israel-judaisme | israel-judaisme |
| jeu | jeu | jeu |
| jeu-role | jeu-role | jeu-role |
| jeuvideo | jeuvideo | jeuvideo |
| jeuvideov3 | jeuvideov3 | jeuvideov3 |
| judo | judo | judo |
| karate | karate | karate |
| kayak | kayak | kayak |
| kickboxing | kickboxing | kickboxing |
| lutte | lutte | lutte |
| macintosh | macintosh | macintosh |
| malte | malte | malte |
| map | map | map |
| medecine | medecine | medecine |
| mets | mets | mets |
| militaire | militaire | militaire |
| money | money | money |
| money_coin | money_coin | money_coin |
| montreal-metro | montreal-metro | montreal-metro |
| metro | metro | metro |
| montreal-train | montreal-train | montreal-train |
| moteur-avion | moteur-avion | moteur-avion |
| mosque | mosque | mosque |
| musee | musee | musee |
| museum | museum | museum |
| papyrus | papyrus | papyrus |
| musique | musique | musique |
| music | music | music |
| natation | natation | natation |
| nations-unies | nations-unies | nations-unies |
| omnisports | omnisports | omnisports |
| palace | palace | palace |
| paralympique | paralympique | paralympique |
| persofiction | persofiction | persofiction |
| petrole | petrole | petrole |
| planeur | planeur | planeur |
| plateforme | plateforme | plateforme |
| poker | poker | poker |
| presse | presse | presse |
| pretendant | pretendant | pretendant |
| projet | projet | projet |
| project | project | project |
| psychologie | psychologie | psychologie |
| quebec | quebec | quebec |
| recherche | recherche | recherche |
| rinkhockey | rinkhockey | rinkhockey |
| rome-antique | rome-antique | rome-antique |
| route | route | route |
| rugby | rugby | rugby |
| rugbyblack | rugbyblack | rugbyblack |
| satellite | satellite | satellite |
| sautski | sautski | sautski |
| science-fiction | science-fiction | science-fiction |
| serie-video | serie-video | serie-video |
| ski-alpin | ski-alpin | ski-alpin |
| snooker | snooker | snooker |
| software | software | software |
| sport | sport | sport |
| sport-automobile | sport-automobile | sport-automobile |
| squash | squash | squash |
| stadium | stadium | stadium |
| starwars | starwars | starwars |
| surf | surf | surf |
| taekwondo | taekwondo | taekwondo |
| television | television | television |
| templiers | templiers | templiers |
| tennis | tennis | tennis |
| tennis-de-table | tennis-de-table | tennis-de-table |
| tennis-de-tableblack | tennis-de-tableblack | tennis-de-tableblack |
| timbre | timbre | timbre |
| train | train | train |
| triathlon | triathlon | triathlon |
| ultimate | ultimate | ultimate |
| union-europeenne | union-europeenne | union-europeenne |
| video | video | video |
| voile | voile | voile |
| volleyball | volleyball | volleyball |
| water-polo | water-polo | water-polo |
-- Credits:
-- Original from fr:Module:Infobox
-- forked by وهراني @arwiki
-- Version: 20250126
local p = {}
local wikiLang = 'ar' -- اللغة
local localdata = require( 'وحدة:بطاقة/بيانات') -- بيانات مضمنة في القالب
local wdexpandQuery = require("وحدة:بطاقة/ويكي.بيانات").expandQuery
local builder = require('وحدة:بطاقة/تركيب')
local page = { -- بيانات حول الصفحة التي ستعرض عليها البطاقة
name = mw.title.getCurrentTitle().prefixedText,
namespace = mw.title.getCurrentTitle().namespace
}
local colors = {
maincolor = 'var(--background-color-interactive-subtle, #f8f9fa)',
secondcolor = 'var(--background-color-disabled-subtle, #E1E1E1)',
thirdcolor = 'var(--color-emphasized, #000000)'
}
--local maincolor, secondcolor, thirdcolor = '#E1E1E1', '#E1E1E1', '#000000'
-- نتائج ثانوية
local maintenance = '' -- نص مضاف للنتيجة يستعمل لإدراج التصنيفات عادة
local externaltext = '' -- نص مضاف عام يستعمل لعرض إضافات مثل القوالب خارج قالب المعلومات
-- وحدات مستعملة
local i18n = {
['see doc'] = 'حول القالب',
['edit'] = 'تعديل',
['edit code'] = 'تعديل مصدري',
['edit item'] = 'تعديل ويكي بيانات',
['tracking cat'] = "صفحات بها بيانات ويكي بيانات",
['invalid block type'] = "لبنة بيانات غير صحيحة في القالب",
['default cat'] = "صيانة بطاقات",
['pages_using_bitaqa_with_no_params_cat'] = 'صفحات_تستخدم_وحدة_بطاقة/بلا_مدخلات',
['pages_using_bitaqa_cat'] = 'صفحات_تستخدم_وحدة_بطاقة',
['pages_with_empty_bitaqa_cat'] = 'صفحات_تستخدم_وحدة_بطاقة/بقالب_فارغ',
['pages_using_bitaqa_with_errors_cat'] = 'صفحات_تستخدم_وحدة_بطاقة/بها_أخطاء',
['pages_using_infobox_cat'] = 'مقالات تستعمل قوالب معلومات',
}
local function addWikidataCat(prop)
if type(prop) == 'table' then prop = prop[1] end
if page.namespace == 0 then
maintenance = maintenance .. '[[تصنيف:صفحات_تستخدم_خاصية_' .. prop .. ']]'
end
end
local function addMaintenanceCat(cat, sortkey)
if page.namespace == 0 and cat then
maintenance = maintenance
.. '[[تصنيف:' .. cat .. '|' .. (sortkey or page.name) .. ']]'
end
return ''
end
local getValue = localdata.getValue
local function expandQuery(query)
local function expand1Query(query,wikimod)
local noerr,data, nb
noerr,data, nb = pcall(wdexpandQuery,localdata.item ,wikimod,query)
if noerr
then return data, nb
else
addMaintenanceCat(i18n['pages_using_bitaqa_with_errors_cat'])
mw.log("WD Query Error : "..mw.dumpObject(data))
mw.log(debug.traceback('>>ERROR :>>'))
return '<span class="error">' .. (data) .. '</span>' ,1
end
end
local v, valnum -- نتيجة ، عدد النتائج للضبط الصرفي للعنوان
if(type(query) ~= 'table') then return nil end
-- الوحدات المستعملة
local wikimod = query.wikimod or localdata.wikimod or 'Wikidata.Ca' --'Wikidata2' --'Wikidata/fr'
if type(query["wikidata" .. 2]) ~= 'nil' then
local answers = {}
local maxNbAns
v,valnum = expand1Query(query["wikidata"]
or query["wikidata" .. 1],wikimod)
maxNbAns = valnum or 0
table.insert(answers,v)
local i = 2
while type(query["wikidata" .. i]) ~= 'nil' do
v,valnum =expand1Query(query["wikidata" .. i],wikimod)
maxNbAns = math.max(maxNbAns,valnum or 0)
table.insert(answers,v)
i = i+1
end
if #answers>0 then
return table.concat(answers, query.sep or "\n<br />"),maxNbAns
else return nil
end
else
return expand1Query(query,wikimod)
end
end
local function getWikidataValue(params, wikidataparam)
if(type(params) ~='table') then params={} end
if not localdata.item then
return nil
end
if params.blockers then -- blockers are local parameters that disable the wikidata query
local blockers = params.blockers
if (type(blockers) == 'string') then
blockers = {blockers}
end
for i, blocker in ipairs(blockers) do
if getValue(blocker) then return nil end
end
end
local v, valnum -- قيم النتائج وعددها (لعرض مناسب في حالة الجمع)
if not wikidataparam then wikidataparam = 'wikidata' end
if params[wikidataparam] then
if type(params[wikidataparam]) == 'function' then
v, valnum = params[wikidataparam](localdata.item)
elseif type(params[wikidataparam]) == 'table' then
v, valnum = expandQuery(params[wikidataparam])
else
v, valnum = params[wikidataparam]
end
end
local i = 2
while not v and type(params["wikidata" .. i]) ~= 'nil' do
wikidataparam = "wikidata" .. i
i = i + 1
if params[wikidataparam] then
if type(params[wikidataparam]) == 'function' then
v, valnum = params[wikidataparam](localdata.item)
elseif type(params[wikidataparam]) == 'table' then
v, valnum = expandQuery(params[wikidataparam])
else
v, valnum = params[wikidataparam]
end
end
end
if not v or valnum==0 then return nil end
return v, valnum
end
function p.separator(params)
if(type(params) ~='table') then params={} end
local style = params['separator style'] or {}
local class = params['separator class'] or ''
style.height = style.height or '2px'
style['background-color'] = style['background-color'] or colors.maincolor
return builder.separator({style = style, class = class})
end
--[=[
تحضير لبنة العنوان في البطاقة
]=]
function p.buildtitle(params)
if(type(params) ~='table') then params={} end
local text = getValue(params.value, params)
or params.textdefaultvalue
or getWikidataValue(params)
or mw.title.getCurrentTitle().text
local subtext = getValue(params.subtitle)
or getWikidataValue(params, 'wikidatasubtitle')
or params.subtitledefaultvalue
-- overwrites with those provided in the module
local style = {}
style['background-color'] = colors.maincolor
style['color'] = colors.thirdcolor
if params.style then
for i, j in pairs(params.style) do
style[i] = j
end
end
return builder.title({
title = text, subtitle = subtext,
style=style, class = params.class or '',
icon = params.icon
})
end
p.buildTitle = p.buildtitle
local function getwdImage(Q, property)
property = property
local QID
if type(Q) == 'table' and Q.id and Q.id ~= '-'
then QID = Q.id
else return
end
local wdata
if (type(property) == 'string')
then wdata = mw.wikibase.getBestStatements(QID, property)
elseif(type(property) == 'table')
then for _,prop in ipairs(property) do
wdata = mw.wikibase.getBestStatements(QID,prop)
if(wdata) then break end
end
else return
end
local first
for _, image in pairs(wdata) do
if image.mainsnak.snaktype == 'value' then
if not first then
first = image.mainsnak.datavalue.value
end
local q = image.qualifiers
if q and q.P2096 then
for _, caption in pairs(q.P2096) do -- P2096 is 'caption'
if caption.snaktype == 'value'
and caption.datavalue.value.language == wikiLang then
return
image.mainsnak.datavalue.value, caption.datavalue.value.text
end
end
end
end
end
return first,nil
end
local function getImageFromWD(Q, pwd)
local images,caption
if type(pwd.property) == 'table' then
pwd.property = mw.text.listToText(pwd.property, '**', '**')
end
if type(pwd) == 'table' then
for p in string.gmatch(pwd.property, 'P%d+') do
images,caption = getwdImage(Q, p)
if images then
addWikidataCat(p)
return images,caption
end
end
end
if type(pwd) == 'function' then
images = pwd()
if type(images) == 'string' then
return images
end
end
end
function p.buildgallery(params)
if(type(params) ~='table') then params={} end
if(type(params.images) ~= 'table') then return nil end
local images = {}
for _, im in ipairs(params.images) do
local imv = getValue(im.imageparameters)
if type(imv)=='string' then
table.insert(images, {
img = imv ,
cap = (getValue(im.captionparameter) or im.defaultcaption or '')
})
else
local caption
if type(im.property) == 'string' then
im.wikidata = {['property'] = im.property}
end
if type(im.wikidata) == 'table' then
imv,caption = getImageFromWD(localdata.item, im.wikidata)
if type(imv)=='string' then
table.insert(images, {
img = imv ,
cap = (caption or im.defaultcaption or '')
})
end
end
end
end
if #images >= 0 then
local arg = {
total_width = params.total_width or '260',
align = params.align or 'center',
footer = params.footer,
image_gap = params.image_gap or 5,
footer_align = params.footer_align or 'center',
caption_align = 'center',
border = 'infobox'
}
local i=1
for _, im in ipairs(images) do
arg["image"..i] = im.img
arg["caption"..i] = im.cap
i = i + 1
end
local renderMultipleImages = require("Module:Multiple image").renderMultipleImages
local noerr,data = pcall(renderMultipleImages,arg)
if noerr == true
then return
'<div style="width: 100%;clear: both">'
.. data ..
'</div>'
else
addMaintenanceCat(i18n["pages_using_bitaqa_with_errors_cat"])
mw.log("Error from [[Module:Multiple image]] : "..mw.dumpObject(data))
mw.log(debug.traceback('>>ERROR :>>'))
return nil
end
end
return nil
end
function p.buildimages(params)
if(type(params) ~='table') then params={} end
local class = params.class or ''
local style = params.style or {}
local image
local upright, link, caption, alt, size -- size is deprecated
if type(params.imageparameters) == 'string' then
params.imageparameters = {params.imageparameters}
end
image = getValue(params.imageparameters)
-- Images from Wikidata
if type(image) ~= 'string' and localdata.item then
if params.property then
params.wikidata = { property = params.property}
end
if params.wikidata then
image,caption = getImageFromWD(localdata.item, params.wikidata)
end
end
-- استعمال صور افتراضبة في حال عرفت
if type(image) ~= 'string' then
if params.maintenancecat then
addMaintenanceCat(params.maintenancecat, params.sortkey)
end
if params.defaultimages then
image = params.defaultimages
upright = params.defaultimageupright
caption = params.defaultimagecaption
link = params.defaultimagelink
alt = params.defaultimagealt
if not alt and ( image == 'DefautAr.svg' or image == 'Defaut 2.svg' ) then
alt = 'نحتاج صورة تكون من الأفضل حرة'
end
end
end
if type(image) ~= 'string' or image == '-' then
return nil
end
upright = upright or getValue(params.uprightparameter) or params.defaultupright or "1"
link = link or getValue(params.linkparameter) or params.defaultlink
caption = caption or getValue(params.captionparameter) or params.defaultcaption
alt = alt or getValue( params.altparameter) or params.defaultalt
size = size or getValue(params.sizeparameter) or params.defaultsize
if size then
local numsize = size:gsub('px', '')
numsize = size:gsub('بك', '')
numsize = mw.ustring.gsub(numsize, 'x.*', '')
numsize = tonumber(numsize)
if type(numsize) ~= 'number' or numsize > 280 then
addMaintenanceCat("مقالات تسيء استعمال حجم الصورة")
end
if tonumber(size) then
size = size .. 'px'
end
size = '|' .. size
else
size = ''
end
if tonumber(upright) then
upright = tostring(tonumber(upright) )
end
-- تحضير عرض الصورة
local imagesString = ''
if(string.find(image, '<table',1,true) ~= nil or string.find(image, '<div',1,true) ~= nil) then
imagesString = imagesString .. image
else
image = string.match(image, '[^:]*:([^|%]]*)') or image
imagesString = imagesString .. '[[ملف:' .. image .. size .. '|frameless'
if alt then imagesString = imagesString .. '|alt=' .. alt end
if link then imagesString = imagesString .. '|link=' .. link end
if upright then imagesString = imagesString .. '|upright=' .. upright end
imagesString = imagesString .. ']]'
end
return builder.image({class= class, style=style, imagetext = imagesString, caption=caption})
end
p.buildImages = p.buildimages
function p.buildtext(params)
if(type(params) ~='table') then params={} end
local class = params.class or ''
local style = params.style or {}
local text = getValue(params.value, params)
or getWikidataValue(params)
or params.defaultvalue
if text == '-' then return end
if not text then
addMaintenanceCat(params.maintenancecat, params.sortkey)
return nil
end
return builder.text({class= class, style=style, text = text })
end
p.buildText = p.buildtext
function p.buildrow(params)
if(type(params) ~='table') then params={} end
local class = params.class or ''
local style = params.style or {}
local valueClass = params.valueClass or ''
local valueStyle = params.valueStyle or {}
local value, number = getValue(params.value, params)
if (not value) then
value, number = getWikidataValue(params, 'wikidata')
end
if (not value) and (params.property) then
value, number = expandQuery{ property = params.property }
end
if not value then
value = params.defaultvalue
end
if value == '-' then
return nil
end
if not value then
if params.maintenancecat then
local maintenancecat = getValue(params.maintenancecat, params)
addMaintenanceCat(maintenancecat, params.sortkey)
end
return nil
end
if not number then
number = 0 -- == غير معرف
end
local label = params.label
if type(label) == 'table' then label= getValue(params.label, params) end
if number > 1 and (params.plurallabel) then
label = params.plurallabel
elseif number == 1 and (params.singularlabel) then
label = params.singularlabel
end
if type(label) == 'function' then
label = label(localdata, localdata.item)
end
if not label and type(params.defaultlabel) == 'string' then
label = params.defaultlabel
end
if number > 4 then --- إخفاء النتيجة في حال تجاوز عددها 4
-- params.hidden = true
end
local bparams = {
class = class ,
style = style,
valueClass = valueClass,
valueStyle = valueStyle,
value = value ,
label = label,
hidden = params.hidden
}
return builder.row(bparams)
end
p.buildRow = p.buildrow
function p.buildnavbox(params)
if(type(params) ~='table') then params={} end
-- تعريف الستايل
local class = "overflow nav " .. (params.class or '')
local style = params.style or {}
if params.separated then -- خيار إضافة فاصل مسبق
class = class .. ' bordered'
style['border-top'] = '1px solid' .. colors.maincolor
end
-- ترتيب البيانات
params.previousval = params.previousval or params.previousparameter
params.nextval = params.nextval or params.nextparameter
if params.previousproperty then
params.previouswikidata = {property = params.previousproperty, conjtype='<br />'}
end
if params.nextproperty then
params.nextwikidata = {property = params.nextproperty, conjtype='<br />'}
end
local previousval = getValue(params.previousval, params)
or getWikidataValue(params, 'previouswikidata')
local nextval = getValue(params.nextval, params)
or getWikidataValue(params, 'nextwikidata')
return builder.navbar({
class = class, style = style,
previousval = previousval,
nextval = nextval
})
end
p.buildNavbox = p.buildnavbox
function p.buildsuccession(params)
if(type(params) ~='table') then params={} end
if not params.value then return nil end
local style = {}
local arrowLeft
local arrowRight
-- ترتيب البيانات
params.previousval = params.previousval or params.previousparameter
params.nextval = params.nextval or params.nextparameter
if params.previousproperty then
params.previouswikidata = {property = params.previousproperty}
end
if params.nextproperty then
params.nextwikidata = {property = params.nextproperty}
end
local previousval = params.value['before']
or getValue(params.previousval, params)
or getWikidataValue(params, 'previouswikidata')
local nextval = params.value['after']
or getValue(params.nextval, params)
or getWikidataValue(params, 'nextwikidata')
local centerval = params.value['center']
return builder.navbar({
class = class, style = style,
previousval = previousval,
nextval = nextval,
centerval = centerval
})
end
p.buildSuccession = p.buildsuccession
function p.buildrow1col(params)
if(type(params) ~='table') then params={} end
local value, number = getValue(params.value, params)
if (not value) then
value, number = getWikidataValue(params, 'wikidata')
end
if (not value) and (params.property) then
value, number = expandQuery{ property = params.property }
end
if not value then
value = params.defaultvalue
end
if value == '-' or type(value)== 'nil' then
return nil
end
local class = params.class or ""
local style = params.style or {}
local bparams = {
class = class ,
style = style,
valueClass = valueClass,
valueStyle = valueStyle,
value = value ,
label = label,
hidden = params.hidden
}
return builder.row(bparams)
end
p.buildRow1Col = p.buildrow1col
function p.buildsubtitle(params)
if(type(params) ~='table') then params={} end
local class = params.class or ''
local style = params.style or {}
local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue
if text == '-' then
return
end
if not text then
addMaintenanceCat(params.maintenancecat, params.sortkey)
return nil
end
return builder.subtitle({class= class, style=style, text = text })
end
p.buildSubTitle = p.buildsubtitle
function p.buildtable(params)
if(type(params) ~='table') then params={} end
local tab = builder.table(params)
local rows = params.rows
-- expand parameters so that we have a list of tables
local i = 1
while (i <= #rows) do
local l = rows[i]
if type(l) == 'function' then
l = l(localdata, localdata.item)
end
if (type(l) == 'table') and (l.type == 'multi') then
table.remove(rows, i)
for j, row in ipairs(l.rows) do
table.insert(rows, i + j - 1, row)
end
elseif type(l) == 'nil' then
table.remove(rows, i)
elseif type(l) ~= 'table' then
return error('أسطر قالب البطاقة ("rows") على شكل جداول (table), وليست ' .. type(l))
else
i = i + 1
end
end
-- CREATE ROW
local expandedrows = {}
for k, row in ipairs(rows) do
local v = p.buildblock(row, true)
if v then
table.insert(expandedrows, v)
end
end
if (#expandedrows == 0) then
return nil
end
rows = expandedrows
-- ADD TITLE
local title
if params.title or params.singulartitle or params.pluraltitle then
local text
if #rows > 1 and params.pluraltitle then
text = params.pluraltitle
elseif #rows == 1 and params.singulartitle then
text = params.singulartitle
else
text = params.title
end
local style = params.titlestyle or {}
title = builder.caption({class= class, style=style, text = text })
end
if title then
tab:node(title)
end
for i, j in pairs (rows) do
tab:node(j)
end
if params.separator then
local separator = p.separator(params)
tab:node(separator)
end
tab:allDone()
return tab
end
p.buildTable = p.buildtable
function p.buildinvalidblock(args)
addMaintenanceCat(defaultcat)
local text = ''
if type(args) ~= 'table' then
text = "لبنات قالب بطاقة يجب أن تكتب على شكل جداول (table)"
else
text = i18n["invalid block type"] .. ' : ' .. (args.type or '??')
end
return text
end
p.buildInvalidBlock = p.buildinvalidblock
function p.buildmap(params)
if(type(params) ~='table') then params={} end
local latitude = getValue({'latitude','دائرة العرض','دائرة عرض'})
local longitude = getValue({'longitude','خط الطول','خط طول'})
local itemid
if localdata.item and localdata.item.id then itemid = localdata.item.id end
if(not params.ids and not longitude and not itemid ) then return nil end
if itemid and not (
#(mw.wikibase.getBestStatements(itemid, 'P625'))~=0
or params.ids or longitude
) then return nil end
local width = tonumber(params.width) or 260
if width > 260 then
--addMaintenanceCat("خطأ في بطاقة/صورة بأبعاد كبيرة")
width = 260
end
local newparams = {
['marker-symbol'] = params.marker or 'marker',
['marker-color'] = params.markercolor or '#FF0000',
['marker-size'] = params.markersize,
frameless='yes',
['width']=width,
['height']=width,
['latitude']= latitude,
['longitude']= longitude,
['align']='center',
type='mapframe',
geotype= params.geotype,
item = itemid,
ids = params.ids,
zoom= params.zoom or params.default_zoom or 9,
lang= wikiLang or 'ar',
title = mw.title.getCurrentTitle().text,
debug = params.debug --or 1
}
if params.params and type(params.params) == 'table' then -- بيانات اضافية
for i, j in pairs(params.params) do
if(not newparams[i]) then newparams[i] = j end
end
end
local f_tag = require('Module:Map')._tag
local noerr,data = pcall(f_tag,newparams)
if noerr == true
then return builder.image({class= class, style=style, imagetext = data, caption='خريطة تفاعلية'})
else
addMaintenanceCat(i18n["pages_using_bitaqa_with_errors_cat"])
mw.log("Error from [[Module:Map]] : "..mw.dumpObject(data))
mw.log(debug.traceback('>>ERROR :>>'))
return nil
end
end
p.buildMap = p.buildmap
function p.buildexternaltext(params)
if(type(params) ~='table') then params={} end
local value = getValue(params.value)
if value and (type(value) == 'string') then
externaltext = externaltext .. value
end
end
p.buildExternalText = p.buildexternaltext
function p.buildfooter(params)
if(type(params) ~='table') then params={} end
local class = (params.class or '')
local style = params.style or {}
local backlinkstr = '['
.. tostring( mw.uri.fullUrl( page.name, 'veaction=edit§ion=0' ) )
.. ' ' .. i18n['edit'] .. ']'.. ' - ['
.. tostring( mw.uri.fullUrl( page.name, 'action=edit§ion=0' ) )
.. ' ' .. i18n['edit code'] .. ']'
local itemlinkstr
if localdata.item and localdata.item.id then
itemlinkstr = '[[d:' .. localdata.item.id .. '|' .. i18n['edit item'] .. ']]'
end
local editstr = backlinkstr
if itemlinkstr then
editstr = editstr .. ' - ' .. itemlinkstr
end
local editlinkspan = mw.html.create('span')
:css({['text-align'] = "right", ['font-size'] = "80%",['background'] = "inherit"})
:addClass('plainlinks')
:wikitext(editstr)
:done()
local doclinkstr = '[[ملف:Test_Template_Info-Icon_-_Version_(2).svg|30x15px|link='
.. localdata["__templatename__"] .. '|' .. i18n['see doc'] .. ']]'
local doclinkspan = mw.html.create('span')
:css({['text-align'] = "left",['float'] = "left"})
:wikitext(doclinkstr)
:done()
return builder.footer({
class = class, style = style,
content = tostring(editlinkspan) .. tostring(doclinkspan)
})
end
p.buildFooter = p.buildfooter
function p.buildblock(block, inner)
if type(block) == 'function' then
block = block( localdata )
end
if(inner) then block.inner = true end
local blocktypes = { -- list of functions for block buildings
['invalid'] = p.buildinvalidblock,
['external text'] = p.buildexternaltext,
['footer'] = p.buildfooter,
['images'] = p.buildimages,
['gallery'] = p.buildgallery,
['map']= p.buildmap,
['navbox'] = p.buildnavbox,
['table'] = p.buildtable,
['mixed'] = p.buildrow,
['row'] = p.buildrow,
['row1col'] = p.buildrow1col,
['succession'] = p.buildsuccession,
['text'] = p.buildtext,
['title'] = p.buildtitle,
['subtitle'] = p.buildsubtitle,
}
if type(block) ~= 'table'
or (not block.type)
or (not blocktypes[block.type]) then
return blocktypes['invalid'](block)
end
return blocktypes[block.type](block)
end
p.buildBlock = p.buildblock
local function _modbuild()
local function _table_size(tab)
local tab_size = 0
for k, v in pairs( tab ) do tab_size = tab_size + 1 end
return tab_size
end
if _table_size(localdata) <= 5 and page.namespace == 0 then
addMaintenanceCat(i18n["pages_using_bitaqa_with_no_params_cat"])
end
-- assign rank to the infobox, "secondary" means special formatting like no displaytitle for coordinates
local infoboxrank = 'main' -- main infobox of the page, with coordinates displayed in title etc.
if page.namespace ~= 0 then
infoboxrank = 'secondary'
else
addMaintenanceCat(i18n["pages_using_bitaqa_cat"])
addMaintenanceCat(i18n["pages_using_infobox_cat"])
end
-- if infobox is linked to another item: rank = secondary
if localdata.item and localdata.item.id then
local itemlink = mw.wikibase.sitelink(localdata.item.id)
local pagetitle = mw.title.getCurrentTitle().text
if (itemlink or '') ~= pagetitle then
infoboxrank = 'secondary'
end
end
localdata.infoboxrank = infoboxrank
-- load infobox module page
local moduledata = require('وحدة:بطاقة/قالب/' .. localdata["__modulename__"] )
moduledata.name = localdata["__modulename__"]
localdata.wikimod = moduledata.wikimod or moduledata.wikidatamod or moduledata.wdmod
-- defines main color
colors.maincolor = getValue({'infobox_color','لون_البطاقة'}) or moduledata.maincolor or colors.maincolor
colors.secondcolor = moduledata.secondcolor or colors.secondcolor
colors.thirdcolor = getValue({'text_color','لون_النص'}) or moduledata.thirdcolor or colors.thirdcolor
if colors.maincolor:match( '^%x%x%x%x%x%x$' ) or colors.maincolor:match( '^%x%x%x$' ) then
colors.maincolor = '#' .. colors.maincolor
end
if colors.thirdcolor:match ('نعم') or colors.thirdcolor:match( 'true' ) then
colors.thirdcolor = '#000'
end
if colors.thirdcolor:match ('لا') or colors.thirdcolor:match( 'false' ) then
colors.thirdcolor = '#fff'
end
-- build infobox
-- النتيجة النهائية
local infobox = builder.header({style= moduledata.style, class = moduledata.class })
local nbblock = 0
for i, j in pairs( moduledata.parts ) do
-- accepted only in table
if(not(j =='mixed' or j == 'multi' or j == 'row' or j == 'row1col'))
then
local mdp= p.buildblock(j)
infobox:node(mdp)
if(mdp) then nbblock = nbblock + 1 end
end
end
if nbblock < 2 and page.namespace == 0 then
addMaintenanceCat(i18n["pages_with_empty_bitaqa_cat"])
end
infobox :node(p.buildfooter(moduledata.footer))
:done()
local templatestyles
templatestyles = builder.style() ..
mw.getCurrentFrame():extensionTag( 'templatestyles', '', { src = "بطاقة/icones.css"}
)
return templatestyles .. tostring(infobox) .. externaltext .. maintenance
end
function p.build()
local noerr,data, nb
noerr,data = pcall(_modbuild)
if noerr
then return data
else
mw.log("Bitaqa Error : "..mw.dumpObject(data))
mw.log(debug.traceback('>>ERROR :>>'))
addMaintenanceCat(i18n['pages_using_bitaqa_with_errors_cat'])
return '<span class="error">' .. (data) .. '</span>'
end
end
p['تركيب'] = p.build
return p