وحدة:بطاقة/مساعدة
المظهر

-- Credits:
-- Developer : وهراني @arwiki (وحدة:بطاقة/مساعدة)
-- Version: 20240504
local helpMod = {}
local function _removeSpaces(param)
if(type(param) =='string') then return param:gsub('%s+','_') end
if(type(param) ~='table') then return param end
local hash = {}
local res = {}
for _,v in ipairs(param) do
v = v:gsub('%s+','_')
if (not hash[v]) then
res[#res+1] = v -- you could print here instead of saving to result table if you wanted
hash[v] = true
end
end
return res
end
local function _getModInfo(moduledata)
local rows = {}
for i, j in pairs( moduledata.parts ) do
if (j.type and j.type~='table')
then
table.insert(rows,j)
elseif (j.type and j.type=='table' and type(j.rows)=='table')
then
for _,jj in pairs( j.rows ) do
if (jj.type and jj.type=='multi' and type(jj.rows)=='table')
then
for _,jjj in pairs( jj.rows ) do
table.insert(rows,jjj)
end
else
table.insert(rows,jj)
end
end
end
end
--mw.logObject(rows)
local info = {}
for i, j in pairs( rows ) do
if (j.type and j.type=='map') then
elseif (j.type and j.type=='subtitle') then
table.insert(info,{
prop = (type(j.wikidata)=='table' and j.wikidata.property) or j.property,
param = (type(j.value) ~= 'function' and j.value),
type= j.type,
metadata= j.metadata
})
elseif (j.type and (j.type=='navbox' or j.type=='succession'))
then
table.insert(info,{param = j.nextparameter, type= j.type,
prop = (j.nextwikidata and j.nextwikidata.property) or j.nextproperty
})
table.insert(info,{param = j.previousparameter, type= j.type,
prop = (j.previouswikidata and j.previouswikidata.property) or j.previousproperty
})
elseif (j.type and j.type=='images') --j.imageparameters)
then
table.insert(info,{
param = j.imageparameters,
type= j.type,
prop = (j.wikidata and j.wikidata.property) or j.property,
metadata= j.metadata
})
if (j.captionparameter) then
table.insert(info,{param = j.captionparameter, type= j.type})
end
elseif (j.type and j.type=='title') then
table.insert(info,{
param = {'اسم','الاسم','title','name'},
type= j.type,
metadata= j.metadata
})
else
table.insert(info,{
prop = (type(j.wikidata)=='table' and j.wikidata.property) or j.property,
param = (type(j.value) ~= 'function' and j.value),
label = j.label,
defaultlabel = j.defaultlabel,
type= j.type,
metadata= j.metadata
})
end
end
--mw.logObject(info)
return info
end
function helpMod.printSyntax()
localdata = require( 'وحدة:بطاقة/بيانات')
--mw.logObject(localdata)
localdata.modulename = localdata["__modulename__"] or localdata.modulename or localdata["وحدة"]
if( type(localdata.modulename) == 'nil') then return nil end
local moduledata = require('وحدة:بطاقة/قالب/' .. localdata.modulename )
local templatename = localdata['قالب'] or localdata["__templatename__"]
if type(templatename) == 'string' then
templatename = mw.ustring.gsub(templatename,'template:','')
templatename = mw.ustring.gsub(templatename,'قالب:','')
else templatename = nil
end
local info = _getModInfo(moduledata)
--mw.logObject(moduledata) mw.logObject(info)
local out={}
table.insert(out,"{{"..(templatename or localdata.modulename or localdata['__modulename__']))
for _,i in ipairs(info) do
if(type(i.label) =='table') then
table.insert(out," | ".. (i.label[1]):gsub(' ','_') .. "\t=" )
end
if((type(i.param) =='table' and i.param[1]) or i.param ) then
table.insert(out," | "..((type(i.param) =='table' and i.param[1]) or i.param or '***'):gsub(' ','_').."\t=" )
end
end
table.insert(out,"}}")
return
"<!-- لتوليد آلي استعمل : {{نسخ:بطاقة/إدراج/صيغة|وحدة="
.. localdata.modulename .."|قالب=".. templatename .."}} -->\n"
..mw.getCurrentFrame():extensionTag{
name = "syntaxhighlight",
content = table.concat(out,"\n"),
args = { lang = "wikitext" , style='direction:rtl'}
}
end
function helpMod.printTemplateParameters()
localdata = require( 'وحدة:بطاقة/بيانات')
mw.logObject(localdata)
--if true then return nil end
localdata.modulename = localdata.modulename or localdata["وحدة"]
if( type(localdata.modulename) == 'nil') then return nil end
local moduledata = require('وحدة:بطاقة/قالب/' .. localdata.modulename )
local templatename = localdata.templatename or localdata["قالب"]
if type(templatename) == 'string' then
templatename = mw.ustring.gsub(templatename,'template:','')
templatename = mw.ustring.gsub(templatename,'قالب:','')
else templatename = nil
end
local info = _getModInfo(moduledata)
-- mw.logObject(localdata) mw.logObject(moduledata)
-- mw.logObject(info)
local wikiout ={}
table.insert(wikiout,
"<!-- لتوليد آلي استعمل : {{نسخ:بطاقة/إدراج/مدخلات|وحدة="..
localdata.modulename .."|قالب="..
(templatename or '') .."}} -->")
table.insert(wikiout,"{| class=\"wikitable\"")
table.insert(wikiout,"|-")
table.insert(wikiout,
'! عنوان السطر'
..'!! الوسيط '
..'!! تسميات أخرى'
..'!! الخاصية'
..'!! أكثر ..'
)
local lparam
local llabel
local lprop
for _,i in ipairs(info) do
table.insert(wikiout,"|- valign=\"top\"")
lprop = {}
i.metadata = i.metadata or {}
if(type(i.prop) == 'table') then i.prop= table.concat(i.prop,' - ') end
for p in string.gmatch(i.prop or '', 'P%d+') do
table.insert(lprop,p)
end
llabel = (type(i.label) =='table' and 'حسب المدخلات :'..table.concat(i.label,'<br />'))
or (type(i.label) =='string' and i.label) or ''
llabel = llabel
.. ((type(i.defaultlabel) =='string' and '<br />قيمة افتراضية :' .. i.defaultlabel) or '')
lparam = _removeSpaces( i.param or i.imageparameters or i.captionparameter )
table.insert(wikiout,mw.ustring.format( "| %s \n| %s \n| %s \n| %s \n| %s"
, llabel or ''
, (type(lparam) =='table' and lparam[1]) or lparam or ''
, (type(lparam) =='table' and table.concat( lparam, '<br />', 2 )) or ''
, (type(lprop)== 'table' and table.concat(lprop, '<br />')) or ''
, i.metadata.description or ''
))
end
table.insert(wikiout,'|}')
return table.concat(wikiout,"\n")
end
function helpMod.printTemplateData()
localdata = require( 'وحدة:بطاقة/بيانات')
localdata.modulename = localdata.modulename or localdata['__modulename__'] or localdata["وحدة"]
if( type(localdata.modulename) == 'nil') then return nil end
local moduledata = require('وحدة:بطاقة/قالب/' .. localdata.modulename )
local templatename = localdata.templatename
if type(templatename) == 'string' then
templatename = mw.ustring.gsub(templatename,'template:','')
templatename = mw.ustring.gsub(templatename,'قالب:','')
else templatename = nil
end
local info = _getModInfo(moduledata)
-- mw.logObject(localdata) mw.logObject(moduledata)
--mw.logObject(info)
local params ={}
for _,i in ipairs(info) do
local param1 ={}
local paramName
i.metadata = i.metadata or {}
local label1
label = (type(i.label) =='string' and i.label) or
(type(i.defaultlabel) =='string' and i.defaultlabel) or nil
--param1.label = label1
lparam = _removeSpaces(i.param or i.imageparameters or i.captionparameter)
local aliases1 = {}
if type(lparam) =='table' then
paramName = lparam[1]
for j,v in ipairs(lparam) do
if j > 1 then table.insert(aliases1,v) end
end
elseif type(lparam) =='string' then
paramName = lparam
end
if #aliases1 > 0 then param1.aliases = aliases1 end
if (type(i.metadata.description) == 'string'
and i.metadata.description ~='')
then
param1.description = i.metadata.description
end
if type(i.metadata.option) == 'string' then
if(string.match(i.metadata.option,'required'))
then param1.required = true
end
if(string.match(i.metadata.option,'suggested'))
then param1.suggested = true
end
end
param1.example = i.metadata.example
if(type(i.metadata.suggestedvalues) == 'table' and #(i.metadata.suggestedvalues)>0) then
param1.suggestedvalues = i.metadata.suggestedvalues
end
if(type(i.metadata.type) == 'string' and i.metadata.type ~='') then
param1.type = i.metadata.type
else
param1.type = 'string'
end
if paramName then params[paramName] = param1 end
--mw.logObject(params)
end
local res = {
["format"] = "block"
,['params'] = params
}
if moduledata.description then res.description = moduledata.description end
res = mw.text.jsonEncode( res, mw.text.JSON_PRETTY )
res = string.gsub(res,"%[%]","{}")
return res
end
helpMod.templatedata = helpMod.printTemplateData
function helpMod.printIconsTable()
local src
src =mw.title.makeTitle("قالب",
"بطاقة/icones.css"):getContent();
local xlines=mw.html.create('table')
:addClass('wikitable mw-collapsible mw-collapsed')
:attr({style="border-color:#000; font-size:85%; padding:0; width:100%;"})
:done()
local td1 = mw.html.create('th')
:wikitext("خلفية فاتحة" )
:done()
local td11 = mw.html.create('th')
:wikitext("خلفية فاتحة<br />وأيقونة على اليسار" )
:done()
local td2 = mw.html.create('th')
:wikitext("خلفية داكنة" )
:done()
local row = mw.html.create('tr')
:node(td1)
:node(td11)
:node(td2)
:done()
xlines:node(row)
for v in string.gmatch( src, "%.entete%.([%w-_]+)" ) do
local td1 = mw.html.create('td')
:wikitext(( v ) )
:attr({class="entete "..v})
:attr({style="background-color:#DFEDFF; height:45px; text-align:center; font-size:150%; font-weight:bolder;"})
:done()
local td11 = mw.html.create('td')
:wikitext(( v ) )
:attr({class="entete "..v})
:attr({style="background-color:#F0B020; height:45px; text-align:center; font-size:150%; font-weight:bolder;background-position: left;"})
:done()
local td2 = mw.html.create('td')
:wikitext(( v ) )
:attr({class="entete "..v})
:attr({style="color:#fff;background-color:#808080; height:45px; text-align:center; font-size:150%; font-weight:bolder;"})
:done()
local row = mw.html.create('tr')
:node(td1)
:node(td11)
:node(td2)
:done()
xlines:node(row)
end
local output
output = mw.getCurrentFrame():extensionTag('templatestyles', '', { src = "بطاقة/icones.css"})
..tostring(xlines)
return output
end
helpMod['صيغة'] = helpMod.printSyntax
helpMod['مدخلات'] = helpMod.printTemplateParameters
helpMod['بيانات القالب'] = helpMod.printTemplateData
helpMod['syntax'] = helpMod.printSyntax
helpMod['parameters'] = helpMod.printTemplateParameters
helpMod['templatedata'] = helpMod.printTemplateData
return helpMod