![]() | صُنّفت هذه الوحدة على أنها محمية. تصل الوحدة لهذه المرحلة عندما تستخدم في صفحات كثيرة جدًا. فيجب أن تحمى بسبب أن عمليات التخريب أو الأخطاء تطال الكثير من الصفحات. كما هناك تعديلات غير مجدية تتم على هذه الوحدات تسبب تعب للخادم، إذا كنت ترى أن تعدل هذه الوحدة طبق تعديلك على الملعب أولا وبعد اختباره استدعِ أحدًا لديه صلاحية التعديل لتطبيقه . |
![]() | الوحدة تُستخدم في ما يقارب 50٬000 صفحة وقد تُلاحظ التغييرات على نطاق واسع، اختبرها في وحدة /ملعب أو /مختبر، أو في ملعب. فكر في مناقشة التغييرات على صفحة النقاش قبل تنفيذها. |
هذه الوحدة لديها ثلاث وظائف لاستخراج البيانات من تصنيف:قوالب بيانات بلد (التي تستخدم لمعظم قوالب الأعلام).
جدول gettable
Extracts all parameters from a data template and returns them as a Lua table. This function is only usable from other Lua modules; invoke it using require('Module:CountryData').gettable(parameters)
.
The first parameter is the frame
of the invoking module; the second is the country or other entity to get the data of. The optional third parameter is a table of parameters to pass into the data template; this may, for example, include |age=
or |mw=
, which are used in the values of some sports alias parameters. E.g.,
local data = require('Module:CountryData').gettable(frame,"France",{age="20",mw="men's"})
The function returns an empty table if a data template does not exist or does not conform to the standard structure.
الأسماء المستعارة {{getalias}}
إذا ما استخدمت من wikicode، هذه الدالة تقوم بإرجاع قيمة حقل واحد في قالب البيانات. المعلمة الأولى هي اسم البلد؛ والثاني هو اسم الحقل. على سبيل المثال:
{{#invoke:CountryData|getalias|France|flag alias}}
ينتج : Flag of France.svg.
المعلمات الأخرى هي:
|variant=
لإرجاع قيمة معلمة variant، مع تراجع لقيمة الحقل الرئيسي إذا كان البديل غير موجود.|def=
قيمة افتراضية في حالة عدم وجود ناتج أو عدم وجود القالب.
الافتراضي "nil" حرفياً.
القالب gettemplate
هذه الوظيفة تقوم بعرض محتويات القالب:
{{Pre|{{بيانات بلد فرنسا}}}} {{Pre|{{#invoke:CountryData|gettemplate|France}}}}
يعطي:
{{ {{{1}}} | alias = فرنسا | flag alias = Flag of France.svg | flag alias-1790 = Flag of France (1790–1794).svg | flag alias-1794 = Flag of France (1794–1815, 1830–1958).svg | flag alias-1814 = Flag of the Kingdom of France (1814-1830).svg | flag alias-1830 = Flag of France (1794–1815, 1830–1958).svg | flag alias-1848 = Drapeau france 1848.svg | flag alias-1848a = Drapeau france 1848.svg | flag alias-1848b = Flag of France (1794–1815, 1830–1958).svg | flag alias-1974 = Flag of France (lighter variant).svg | flag alias-naval = Civil and Naval Ensign of France.svg | flag alias-naval-1790 = Flag of French-Navy-Revolution.svg | flag alias-1976 = Flag of France (Pantone).svg | link alias-army = القوات البرية الفرنسية | link alias-naval = البحرية الفرنسية | size = | name = | altlink = | variant = }}
{{ {{{1}}} | altlink = | flag alias-naval-1790 = Flag of French-Navy-Revolution.svg | flag alias-1848 = Drapeau france 1848.svg | flag alias = Flag of France.svg | variant = | flag alias-1814 = Flag of the Kingdom of France (1814-1830).svg | flag alias-1830 = Flag of France (1794–1815, 1830–1958).svg | alias = فرنسا | flag alias-1794 = Flag of France (1794–1815, 1830–1958).svg | flag alias-naval = Civil and Naval Ensign of France.svg | flag alias-1848b = Flag of France (1794–1815, 1830–1958).svg | size = | flag alias-1974 = Flag of France (lighter variant).svg | name = | link alias-naval = البحرية الفرنسية | flag alias-1790 = Flag of France (1790–1794).svg | link alias-army = القوات البرية الفرنسية | flag alias-1976 = Flag of France (Pantone).svg | flag alias-1848a = Drapeau france 1848.svg }}
ملاحظة: في جميع جداول لوا، لا يتم حفظ ترتيب المداخل، لذلك يتم خلطها.
local p = {}
function getcontents(frame,country,params)
local find= require('Module:تحويلات بلدان').red
con = find(country)
return frame:expandTemplate({title="بيانات بلد "..con;args=params})
end
function p.gettable(frame,country,params)
--Returns the parameters of a country data template as a Lua table
--If not a valid data template, return empty table
local bool, s = pcall(getcontents,frame,country,params or {})
if bool and string.find(s,"^%{%{ *%{%{%{1")
then
--Replace parameter delimiters with arbitrary control characters
--to avoid clashes if param values contain equals/pipe signs
s = string.gsub(s,"|([^|=]-)=","\1\1%1\2")
s = string.gsub(s,"}}%s*$","\1")
--Loop over string and add params to table
local part = {}
for par in string.gmatch(s,"\1[^\1\2]-\2[^\1\2]-\1") do
local k = string.match(par,"\1%s*(.-)%s*\2")
local v = string.match(par,"\2%s*(.-)%s*\1")
if v and not (v=="" and string.find(k,"^flag alias")) then
part[k] = v
end
end
return part
else
return {}
end
end
function p.getalias(frame)
--Returns a single parameter value from a data template
local part = p.gettable(frame,frame.args[1])
if frame.args.variant
then return tostring(part[frame.args[2].."-"..frame.args.variant]
or part[frame.args[2]] or frame.args.def)
else return tostring(part[frame.args[2]] or frame.args.def)
end
end
function p.gettemplate(frame)
--For testing, recreates the country data from the created Lua table
--Get data table
local data = p.gettable(frame,frame.args[1])
--Concatenate fields into a template-like string
local out = "{{ {{{1}}}"
for k,v in pairs(data) do
out = out.."\n| "..k.." = "..v
end
return out.."\n}}"
end
return p