Sivun "Moduuli:Universal infocard" versielöin eroloi

Syväindö on otettu iäre Syväindö on ližätty
Kawtaj (pagin | kohendukset)
pEi ole yhtehveduo kohendukses
Kawtaj (pagin | kohendukset)
p update from ruwki
 
Rivi 21:
infobox = '',
error = '',
title = 'font-sizebackground:125%#eaecf0; font-weight:bold; background:#eaecf0',
original = 'font-style:oblique;',
label = 'width:9em; background:#eaecf0',
text = '',
media = '',
split = 'vertical-align:middle; text-align:center;',
footer = 'background:#eaecf0;',
};
local classes = {
title = 'infobox-above',
media = 'infobox-image',
footer = 'infobox-below'
};
if config and config.styles then
Rivi 36 ⟶ 41:
 
function getTemplate( propertyId )
if config and config.templates and config.templates[ propertyId ] then
ifreturn config.templates[ propertyId ] then;
return config.templates[ propertyId ];
end
 
if config.templates.default then
return config.templates.default;
end
end
 
if propertyId == 'title' then
return '{{PAGENAME}}';
end
 
if propertyId == 'map' then
return getMap;
end
 
if config and config.templates and config.templates.default then
return config.templates.default;
end
 
Rivi 60 ⟶ 67:
if not title then
return '';
elseif string.matchtype( title, ) == '^#function' ) then
args.frame = frame;
return frame:callParserFunction{ name = title, args = args };
return title( args )
elseif string.match( title, '^{' ) then
elseif type( title ) == 'string' then
return frame:preprocess( title );
if string.match( title, '^#' ) then
else
return frame:expandTemplatecallParserFunction{ titlename = title, args = args };
elseif string.match( title, '^{' ) then
return frame:preprocess( title );
else
return frame:expandTemplate{ title = title, args = args };
end
elseif type( title ) == 'table' then
local realTitle = title[ 1 ];
table.remove( title, 1 )
return expandTemplate( frame, realTitle, title )
end
end
Rivi 97 ⟶ 113:
end
 
function getLine( value, style, class )
local result = '';
if ( value and string.len( value ) ~= 0 ) then
result = result .. '<tr><td colspan="2" style="text-align:center;' .. ( style or '' ) .. '" class="'.. ( class or '' ) .. '">';
result = result .. value;
result = result .. '</td></tr>\n';
Rivi 122 ⟶ 138:
end
return result;
end
 
function getMap( args )
local entityId = args.entityId or mw.wikibase.getEntityIdForCurrentPage();
local statements = mw.wikibase.getBestStatements( entityId, 'P625' );
if not statements or
not statements[ 1 ] or
not statements[ 1 ].mainsnak or
statements[ 1 ].mainsnak.snaktype ~= 'value' or
statements[ 1 ].mainsnak.datavalue.value.globe ~= 'http://www.wikidata.org/entity/Q2'
then
return '';
end
 
local coord = statements[ 1 ].mainsnak.datavalue.value;
local title = expandTemplate( args.frame, getTemplate( 'title' ), { from = entityId } );
 
mw.logObject( coord, 'coord' );
mw.logObject( title, 'title' );
 
 
local mapContent = [[ {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
]] .. coord['longitude'] .. [[,
]] .. coord['latitude'] .. [[
]
},
"properties": {
"title": "]] .. title .. [[",
"marker-symbol": "star",
"marker-color": "#3366cc"
}
}, {
"type": "ExternalData",
"service": "geoline",
"ids": "]] .. entityId .. [[",
"properties": {
"stroke": "#FF9999"
}
}, {
"type": "ExternalData",
"service": "geoshape",
"ids": "]] .. entityId .. [[",
"properties": {
"fill": "#FF0000",
"fill-opacity": 0.1,
"stroke": "#FF9999"
}
} ]];
 
return args.frame:extensionTag{
name = 'mapframe',
content = '[' .. mapContent .. ']',
args = {
'frameless',
align = 'center',
latitude = coord['latitude'],
longitude = coord['longitude'],
zoom = 11,
width = 300,
height = 250,
}
};
end
 
function renderValue( frame, propertyId, args )
local tplArgs = { propertyId, from = entityId, nocat = frame.args['nocat'] };
 
if args then
Rivi 220 ⟶ 303:
 
local result = '<table class="infobox" cellspacing="2"';
if config and config.i18n and config.i18n.dataName then
result = result .. ' data-name="' .. config.i18n.dataName .. '"';
end
if config and config.styles and config.styles.infobox then
result = result .. ' style="' .. config.styles.infobox .. '"';
Rivi 276 ⟶ 362:
label = expandTemplate( frame, titleTemplate, { from = entityId } );
end
result = result .. getLine( label, styles.title, classes.title );
 
---- Original name.
Rivi 321 ⟶ 407:
local orderedProperties = mw.wikibase.orderProperties( propertyIds )
local shownProperties = 0
for i, propertyId in ipairs( orderedProperties ) do
local propertyClaims = claims[ propertyId ];
Rivi 334 ⟶ 421:
local label = propertyLabel( propertyId );
if propertyClaims[ 1 ].mainsnak.datatype == 'commonsMedia' then
result = result .. getLine( renderValue( frame, propertyId, { alt = label } ), styles.media, classes.media );
else
result = result .. getValue( label, renderValue( frame, propertyId ) );
end
skipPropertyIds[ propertyId ] = true
shownProperties = shownProperties + 1
end
end
 
-- Footer.
 
---- Map.
if claims.P625 ~= nil then
result = result .. getLine( renderValue( frame, 'map' ), styles.text );
if claims.P17 ~= nil then
-- TODO: Don't use templates specific to Russian Wikipedia by default,
-- but give an option to specify it through the settings.
result = result .. getLine( expandTemplate(
frame,
'wikidata-coords',
{
'EK/Kartal sijaičendat',
['русское название'] = expandTemplate( frame, getTemplate( 'title' ), { from = entityId } ),
['mua'] = renderValue( frame, 'P17', { plain = 'true', from = entityId } ),
from = entityId,
}
), styles.footer );
end
end
 
---- Commons.
if claims.P373 ~= nil then
result = result .. getLine( expandTemplate( frame, getTemplate( 'P373' ), { from = entityId } ), styles.footer, classes.footer );
end
 
result = result .. '</table>';
 
---- Coords.
if claims.P625 ~= nil then
result = result .. renderValue( frame, 'P625', { display = 'title', from = entityId } );
end
-- Tracking category.
if config and config.categories and config.categories['few-properties-shown'] then
if shownProperties < 4 then
result = result .. '[[Category:' .. config.categories['few-properties-shown'] .. '|' .. shownProperties .. ']]'
end
end
 
return result;
end