Jump to content
Toggle menu
  • 3 articles
  • 75 files
  • 7 users
  • 37.9K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Information: Difference between revisions

From Neodyland Wiki
←Created page with '--[[ __ __ _ _ ___ __ _ _ | \/ | ___ __| |_ _| | ___ _|_ _|_ __ / _| ___ _...'
 
No edit summary
Line 14: Line 14:
* User:Jarekt - original version  
* User:Jarekt - original version  
]]
]]
local ISOdate = require('Module:ISOdate')                      
local ISOdate = require('Module:ISOdate')  
 
-- ====================================================================
-- This function is responsible for producing HTML of a single row of the template
-- At this stage all the fields are already filed. There is either one or two fields
-- INPUTS:
-- * param - structures containing fields:
--    - tag      - I18n tag used for localization of the field name. Usually name of page in MediaWiki namespace which was imported from translatewiki.org.
--                Alternative is to pass already translated field name.
--    - field    - field content
--    - id      - ID tag added to HTML's <td> cell. if IDs of 2 fields ar the same than we ignore the second one
--    - wrapper  - some fields need a <span class=...> wrapper around the field content
-- ====================================================================
local function Build_html_row(param, args)
local field = args[param.field]
if field=='' then field=nul; end
if not (field or args.demo) then
return nil
end
if not param.id then -- "other fields" parameter
return field
end
local tag = param.tag or 'bad'
tag = mw.message.new( tag ):inLanguage(args.lang):plain() -- label message in args.lang language
cell1 = string.format('<td id="%s" class="fileinfo-paramfield" lang="%s">%s</td>\n', param.id, args.lang, tag)
local cell2 = string.format('<td>\n'.. param.wrapper ..'</td>', field or '')
return string.format('<tr valign="top">\n%s%s\n</tr>\n\n', cell1, cell2)
end


-- ====================================================================
-- ====================================================================
Line 50: Line 23:
-- get text direction
-- get text direction
local dir
local dir = 'ltr'
if mw.language.new( args.lang ):isRTL() then
if mw.language.new( args.lang ):isRTL() then
dir = 'rtl'
dir = 'rtl'
else
dir = 'ltr'
end  
end  
-- files with no source will be flagged
if (not args.source and not args.source_) and args.strict and (args.namespace==6) then
args.nosource = mw.getCurrentFrame():expandTemplate{ title = 'Source missing' }
end
-- Permissions tag
-- Permissions tag
Line 70: Line 36:
-- add other fields
-- add other fields
local params = {
local params = {
{field='author'         , id='fileinfotpl_aut'   , tag='wm-license-information-author',         wrapper='<div class="fn value">\n%s</div>'},
{field='description'   , id='fileinfotpl_desc' , tag='wm-license-information-description',    alt='Description missing', wrapper='<div class="description">\n%s</div>'},
{field='other_fields_1'},
{field='other_fields_1'},
{field='date'          , id='fileinfotpl_date'  , tag='wm-license-information-date',           wrapper='%s'},
{field='date'          , id='fileinfotpl_date'  , tag='wm-license-information-date',                                     wrapper='%s'},
{field='source'        , id='fileinfotpl_src'  , tag='wm-license-information-source',        wrapper='%s'}, -- source
{field='source'        , id='fileinfotpl_src'  , tag='wm-license-information-source',        alt='Source missing',      wrapper='%s'}, -- source
{field='nosource'       , id='fileinfotpl_nosrc' , tag='wm-license-information-source',        wrapper='%s'},
{field='author'         , id='fileinfotpl_aut'   , tag='wm-license-information-author',        alt='Author missing',      wrapper='<div class="fn value">\n%s</div>'},
{field='permission'    , id='fileinfotpl_perm'  , tag=permission_tag,                         wrapper='%s'},
{field='permission'    , id='fileinfotpl_perm'  , tag=permission_tag,                                                     wrapper='%s'},
{field='other_versions' , id='fileinfotpl_ver'  , tag='wm-license-information-other-versions', wrapper='%s'},  
{field='other_versions' , id='fileinfotpl_ver'  , tag='wm-license-information-other-versions',                           wrapper='%s'},  
{field='other_fields'}
{field='other_fields'}
}
}
local results = {}
local results = {}
for i=1,#params do
for _, param in ipairs(params) do
table.insert(results, Build_html_row(params[i], args))
local field, tag, cell1, cell2, id
field = args[param.field]
if #field<2 then field=nul; end
 
if param.id then -- skip "other fields" parameter
if field then  -- add "id" to first <td> cell only if the field is present
id = string.format('id="%s" ', param.id)
elseif param.alt then -- Some field have "Missing" message if field is not provided
field = mw.getCurrentFrame():expandTemplate{ title = param.alt }
end
if field or args.demo then  -- skip the row if still no field
tag = param.tag
if string.sub(tag,1,10) == 'wm-license' then
tag = mw.message.new( tag ):inLanguage(args.lang):plain() -- label message in args.lang language
end
cell1 = string.format('<td %sclass="fileinfo-paramfield" lang="%s">%s</td>\n', id or '', args.lang, tag)
cell2 = string.format('<td>\n'.. param.wrapper ..'</td>', field or '')
field = string.format('<tr valign="top">\n%s%s\n</tr>\n\n', cell1, cell2)
end
end
table.insert(results, field)
end
end


-- add table and outer layers
-- add table and outer layers
local style = string.format('class="fileinfotpl-type-artwork toccolours vevent mw-content-%s" dir="%s" style="width: 100%%" cellpadding="4"', dir, dir)
local style = string.format('class="fileinfotpl-type-information toccolours vevent mw-content-%s" style="width: 100%%; direction: %s" cellpadding="4"', dir, dir)
results = string.format('<table %s>\n%s\n</table>\n', style, table.concat(results))
results = string.format('<table %s>\n%s\n</table>\n', style, table.concat(results))
results = string.format('<div class="hproduct commons-file-information-table">\n%s\n</div>\n', results)
results = string.format('<div class="hproduct commons-file-information-table">\n%s\n</div>\n', results)
Line 102: Line 88:
-- ====================================================
-- ====================================================
-- === automatic tagging of pages in all namespaces ===  
-- === add tag templates used for tracking          ===  
-- ====================================================
-- ====================================================
if args.date then
if args.date then
    -- add an empty template which can be used as a tag in PetScan
  -- add an empty template which can be used as a tag in PetScan
local d    = os.date('!*t')                  -- current date table
local d    = os.date('!*t')                  -- current date table
local current_year  = tonumber(d.year)        -- current year
local current_year  = tonumber(d.year)        -- current year
Line 114: Line 100:
end  
end  
mw.getCurrentFrame():expandTemplate{ title = 'Infobox template tag' } -- add the template tag
mw.getCurrentFrame():expandTemplate{ title = 'Infobox template tag' } -- add the template tag
return Build_html(args)
return Build_html(args)
end
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.