Modul:Sources/peskovnik: Razlika med redakcijama

Izbrisana vsebina Dodana vsebina
mBrez povzetka urejanja
mBrez povzetka urejanja
Vrstica 1:
local p = {};
 
local langs = require('Module:Languages')
local utils = require('Module:Sources-utils')
 
local i18nDefaultLanguage = 'ru'
 
local i18nEtAlDefault = ' et al.'
local i18nEtAl = {
ru = ' и др.',
}
 
local i18nDefaultLanguage = 'sl';
local i18nEditors = {
fr = '',
Vrstica 9 ⟶ 18:
it = '',
ru = 'под ред. ',
sl = 'izdajatelj: ',
}
 
local i18nVolume = {
de = 'Vol.',
fr = 'Vol.',
es = 'Vol.',
Vrstica 17 ⟶ 27:
it = 'Vol.',
ru = 'Т.',
sl = 'Vol.',
}
local i18nEtAlDefault = ' et al.';
local i18nEtAl = {
ru = ' idr.',
sl = ' et al.',
}
 
local i18nIssue = {
en = 'Iss.',
ru = 'вып.',
sl = '',
}
 
local i18nPages = {
fr = 'P.',
Vrstica 36 ⟶ 41:
it = 'P.',
ru = 'С.',
sl = 'str.',
}
 
Vrstica 42 ⟶ 46:
en = 'p.',
ru = 'с.',
sl = 'p.',
}
 
local NORMATIVE_DOCUMENTSi18nTirage = {
en = 'ed. size: %d',
Q20754888 = 'Закон Российской Федерации',
ru = '%d экз.',
Q20754884 = 'Закон РСФСР',
Q20873831 = 'Распоряжение Президента Российской Федерации',
Q20873834 = 'Указ исполняющего обязанности Президента Российской Федерации',
Q2061228 = 'Указ Президента Российской Федерации',
}
 
 
local monthg = {'januar', 'februar', 'marec', 'april', 'maj', 'junij', 'julij', 'avgust', "september", "oktober", "november", "december"};
local monthg = {'января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', "сентября", "октября", "ноября", "декабря"}
 
local PREFIX_CITEREF = "CITEREF_";
 
-- Returns formatted pair {Family name(s), First name(s)}
local options_arxiv = { separator = '; ', conjunction = '; ', format = function( id ) return '[http://arxiv.org/abs/' .. id .. ' arXiv:' .. id .. ']' end, nolinks = true, preferids = false };
local function tokenizeName( fullName )
local options_doi = { separator = '; ', conjunction = '; ', format = function( doi ) return '[http://dx.doi.org/' .. doi .. ' doi:' .. doi .. ']' end, nolinks = true, preferids = false };
local start = '^%s*' -- matches beginning of the string + arbitrary number of spaces
local options_issn = { separator = '; ', conjunction = '; ', format = function( issn ) return '[https://www.worldcat.org/issn/' .. issn .. ' ' .. issn .. ']' end, nolinks = true, preferids = false };
local finish = '%s*$' -- matches end of the string + arbitrary number of spaces
 
local comma = '\,%s+' -- matches comma + single or more spacing character
local options_commas = { separator = ', ', conjunction = ', ', format = function( src ) return src end, nolinks = false, preferids = false };
local space = '%s+' -- matches single or more spacing character
local options_commas_short = { separator = ', ', conjunction = ', ', format = function( src ) return src end, nolinks = false, preferids = false, short = true };
local name = '(%a[%a\-\']*)\.?' -- matches single name, have to start with letter, can contain apostrophe and hyphen, may end with dot
local options_commas_nolinks = { separator = ', ', conjunction = ', ', format = function( src ) return src end, nolinks = true, preferids = false };
local surname = '(%a[%a\-\']*)' -- same as name, but can't end with dot
local options_commas_it = { separator = ', ', conjunction = ', ', format = function( src ) return "''" .. src .. "''" end, nolinks = false, preferids = false };
local options_commas_it_short = { separator = ', ', conjunction = ', ', format = function( src ) return "''" .. src .. "''" end, nolinks = false, preferids = false, short = true };
local f, i = mw.ustring.match(fullName, start .. surname .. comma .. name .. finish)
local options_commas_it_nolinks = { separator = ', ', conjunction = ', ', format = function( src ) return "''" .. src .. "''" end, nolinks = true , preferids = false };
if f then
local options_citetypes = { separator = ' ', conjunction = ' ', format = function( src ) return 'citetype_' .. src end, nolinks = true , preferids = true };
mw.log('tokenizeName: «' .. fullName .. '»: have «Fa, Im» match')
 
return {f, mw.ustring.sub( i, 1, 1 ) .. '.'}
function assertNotNull( argName, arg )
if ( (not arg) or (arg == nil) ) then
error( argName .. ' ni določen' )
end
end
 
function coalesce( arg1, arg2, arg3, arg4 )
if ( not isEmpty( arg1 ) ) then return arg1 end
if ( not isEmpty( arg2 ) ) then return arg2 end
if ( not isEmpty( arg3 ) ) then return arg3 end
if ( not isEmpty( arg4 ) ) then return arg4 end
return nil;
end
 
function isEmpty( str )
return ( not str ) or ( str == nil ) or ( #str == 0 );
end
 
function isInstanceOf( entity, typeEntityId )
if ( not entity or not entity.claims or not entity.claims.P31 ) then
return false;
end
 
for _, claim in pairs( entity.claims.P31 ) do
if ( claim and claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value and claim.mainsnak.datavalue.value["numeric-id"] ) then
local actualTypeId = 'Q' .. claim.mainsnak.datavalue.value["numeric-id"];
if ( actualTypeId == typeEntityId ) then
return true;
end
end
end
 
return false;
end
 
function getEntity( context, entityId )
assertNotNull( 'context', context );
assertNotNull( 'entityId', entityId );
 
local cached = context.cache[ entityId ];
if ( cached ) then return cached; end;
 
local result = mw.wikibase.getEntity( entityId );
if ( result ) then
context.cache[ entityId ] = result;
end
 
return result;
end
 
function toStringSnak( propertyId, strValue )
assertNotNull('propertyId', strValue)
assertNotNull('strValue', strValue)
 
local snak = { snaktype = "value", property = propertyId, datatype = 'string'};
snak["datavalue"] = { value = strValue, type = 'string' };
return snak;
end
 
function toUrlSnak( propertyId, strValue )
assertNotNull('propertyId', strValue)
assertNotNull('strValue', strValue)
 
local snak = { snaktype = "value", property = propertyId, datatype = 'string'};
snak["datavalue"] = { value = strValue, type = 'url' };
return snak;
end
 
function toWikibaseEntityIdSnak( propertyId, entityId )
assertNotNull('propertyId', entityId)
assertNotNull('entityId', entityId)
if ( mw.ustring.sub( entityId, 1, 1 ) ~= 'Q' ) then error( 'Incorrect entity ID: «' .. entityId .. '»' ); end;
 
local value = {};
value["entity-type"] = 'item';
value["numeric-id"] = mw.ustring.sub( entityId , 2);
 
local snak = { snaktype = "value", property = propertyId, datatype = 'wikibase-item'};
snak["datavalue"] = { value = value, type = 'wikibase-entityid' };
return snak;
end
 
function renderSource( context, src )
context.lang = getLangCode( getSingle( src.lang ) ) or i18nDefaultLanguage;
 
preprocessPlaces( src, context.lang );
 
src.title = src.title or getSingle( src.url ) or '\'\'(neimenovan naslov)\'\''
 
if ( src.sourceId and not src.url ) then
local entity = getEntity( context, src.sourceId );
if ( entity.sitelinks and entity.sitelinks[ context.lang .. 'wikisource'] ) then
src.url = ':' .. context.lang .. ':s:' .. entity.sitelinks[ context.lang .. 'wikisource' ].title;
end
end
 
if ( not src.year and src.dateOfPublication ) then
local date = getSingle( src.dateOfPublication );
src.year = mw.ustring.sub( date, 2, 5 );
end
 
if ( not src.year and src.dateOfCreation ) then
local date = getSingle( src.dateOfCreation );
src.year = mw.ustring.sub( date, 2, 5 );
end
local f, i, o = mw.ustring.match(fullName, start .. surname .. comma .. name .. space .. name .. finish)
local result;
if ( src.author )f then
mw.log( 'tokenizeName: «' .. fullName .. '»: have «Fa, Im Ot» match')
result = getPeopleAsAuthorWikitext( context, src.author, options_commas );
return {f, mw.ustring.sub( i, 1, 1 ) .. '. '
.. mw.ustring.sub( o, 1, 1 ) .. '.'}
end
if ( not isEmpty( result )) then
result = '<i class="wef_low_priority_links">' .. result .. '</i> ';
else
result = '';
end
if ( src.part ) then
if ( src.url ) then
result = result .. wrapInUrl( src.url, toString( context, src.part, options_commas_nolinks ) );
else
result = result .. toString( context, src.part, options_commas );
end
result = result .. ' // ' .. toString( context, src.title, options_commas );
else
-- title only
if ( src.url ) then
result = result .. wrapInUrl( src.url, toString( context, src.title, options_commas_nolinks ) );
else
result = result .. toString( context, src.title, options_commas );
end
end
 
local f1, f2, i = mw.ustring.match(fullName, start .. surname .. space .. surname .. comma .. name .. finish)
if ( src.subtitle ) then
if f1 then
result = result .. ": " .. toString( context, src.subtitle, options_commas );
mw.log('tokenizeName: «' .. fullName .. '»: have «Fa Fa, Im» match')
return {f1 .. '&nbsp;' .. f2, mw.ustring.sub( i, 1, 1 ) .. '.'}
end
 
if ( src.originaltitle ) then
result = result .. ' = ' .. toString( context, src.originaltitle, options_commas );
end
 
if ( src.publication ) then
if ( type( src.publication.title or '') ~= 'string' ) then error('type of src.publication.title is not string but ' .. type( src.publication.title ) ) end;
 
result = result .. ' // ' .. toString( context, src.publication, options_commas_it_short );
if ( src.publication.subtitle ) then
result = result .. ': ' .. toString( context, src.publication.subtitle, options_commas_it_short );
end
end
 
result = result .. '<span class="wef_low_priority_links">';
local i, o, f = mw.ustring.match(fullName, start .. name .. space .. name .. space .. 'оглы' .. space .. surname .. finish)
if ( src.editor ) then
if f then
local prefix = i18nEditors[ context.lang ] or i18nEditors[ i18nDefaultLanguage ];
mw.log('tokenizeName: «' .. fullName .. '»: have «Im Ot оглы Fa» match')
result = result .. ' / ' .. prefix .. toString( context, src.editor, options_commas );
return {f, mw.ustring.sub(i, 1, 1) .. '.&nbsp;' .. mw.ustring.sub(o, 1, 1) .. '.'}
end
 
local i1, i2, f = mw.ustring.match(fullName, start .. name .. space .. name .. space .. 'de' .. space .. surname .. finish)
if ( src.edition ) then
if f then
result = result .. ' — ' .. toString( context, src.edition, options_commas );
mw.log('tokenizeName: «' .. fullName .. '»: have «Im Im de Fa» match')
return {f, mw.ustring.sub( i1, 1, 1 ) .. '.&nbsp;' .. mw.ustring.sub( i2, 1, 1 ) .. '.'}
end
-- Try matching k names + surname
if ( src.place or src.publisher or src.year ) then
for k = 1, 4 do
result = result .. ' — ';
pattern = start .. string.rep(name .. space, k) .. surname .. finish
if ( src.place ) then
matched = {mw.ustring.match(fullName, pattern)}
result = result .. toString( context, src.place, options_commas_short );
if (#matched src.publisher~= or src.year )0 then
mw.log('tokenizeName: «' .. fullName .. '»: have «Im (x' .. k .. ') Fa» match')
result = result .. ': ';
for i = 1, k do
matched[i] = mw.ustring.sub(matched[i], 1, 1)
end
return {matched[k + 1], table.concat(matched, '.&nbsp;', 1, k) .. '.'}
end
if ( src.publisher ) then
result = result .. toString( context, src.publisher, options_commas_short );
if ( src.year ) then
result = result .. ', ';
end
end
if ( src.year ) then
result = result .. toString( context, src.year, options_commas );
end
result = result .. '.';
end
if ( src.volume or src.issue ) then
result = result .. ' — ';
if ( src.volume ) then
local letter = i18nVolume[ context.lang ] or i18nVolume[ i18nDefaultLanguage ];
result = result .. letter .. '&nbsp;' .. toString( context, src.volume, options_commas );
if ( src.issue ) then
local letter = i18nIssue[ context.lang ] or i18nIssue[ i18nDefaultLanguage ];
result = result .. ', ' .. letter .. '&nbsp;' .. toString( context, src.issue, options_commas ) .. '.';
else
result = result .. '.';
end
else
local letter = i18nIssue[ context.lang ] or i18nIssue[ i18nDefaultLanguage ];
result = result .. letter .. '&nbsp;' .. toString( context, src.issue, options_commas ) .. '.';
end
end
 
if ( src.pages ) then
local letter = i18nPages[ context.lang ] or i18nPages[ i18nDefaultLanguage ];
result = result .. ' — ' .. letter .. '&nbsp;' .. toString( context, src.pages, options_commas ) .. '.';
end
 
if ( src.numberOfPages ) then
local letter = i18nNumberOfPages[ context.lang ] or i18nNumberOfPages[ i18nDefaultLanguage ];
result = result .. ' — ' .. toString( context, src.numberOfPages, options_commas ) .. '&nbsp;' .. letter;
end
if ( src.bookSeries ) then
result = result .. ' — (' .. toString( context, src.bookSeries, options_commas )
 
if ( src.bookSeriesVolume or src.bookSeriesIssue ) then
result = result .. '; ';
if ( src.bookSeriesVolume ) then
local letter = i18nVolume[ context.lang ] or i18nVolume[ i18nDefaultLanguage ];
result = result .. letter .. '&nbsp;' .. toString( context, src.bookSeriesVolume, options_commas );
if ( src.bookSeriesIssue ) then
local letter = i18nIssue[ context.lang ] or i18nIssue[ i18nDefaultLanguage ];
result = result .. ', ' .. letter .. '&nbsp;' .. toString( context, src.bookSeriesIssue, options_commas );
else
result = result;
end
else
local letter = i18nIssue[ context.lang ] or i18nIssue[ i18nDefaultLanguage ];
result = result .. letter .. '&nbsp;' .. toString( context, src.bookSeriesIssue, options_commas );
end
end
 
result = result .. ')';
end
mw.log('Unmatched any pattern: «' .. fullName .. '»')
if ( src.isbn ) then
return {fullName}
result = result .. ' — ISBN ' .. toString( context, src.isbn, options_commas );
end
 
local function personNameToAuthorName( fullName )
if ( src.issn ) then
if not fullName then return fullName end
result = result .. ' — ISSN ' .. toString( context, src.issn, options_issn );
local tokenized = tokenizeName(fullName)
if #tokenized == 1 then
return tokenized[1]
else
return tokenized[1] .. '&nbsp;' .. tokenized[2]
end
 
if ( src.doi ) then
result = result .. ' — ' .. toString( context, src.doi, options_doi );
end
 
if ( src.arxiv ) then
result = result .. ' — ' .. toString( context, src.arxiv, options_arxiv );
end
 
if ( src.sourceId ) then
if ( src.type and src.sourceId ) then
-- wrap into span to target from JS
result = '<span class="wikidata_cite ' .. toString( context, src.type, options_citetypes ) .. '" data-entity-id="' .. getSingle( src.sourceId ) .. '">' .. result .. '</span>'
else
result = '<span class="wikidata_cite citetype_unknown" data-entity-id="' .. getSingle( src.sourceId ) .. '">' .. result .. '</span>'
end
end
 
if ( src.accessdate ) then
local date = getSingle( src.accessdate );
local pattern = "(%-?%d+)%-(%d+)%-(%d+)T";
local y, m, d = mw.ustring.match( date , pattern );
y,m,d = tonumber(y),tonumber(m),tonumber(d);
result = result .. " <small>Pridobljeno dne " .. tostring(d) .. " " .. monthg[m] .. " " .. tostring(y) .. ".</small>";
end
 
result = result .. '</span>';
-- append invisible links to all elements used by source for tracking purposes
local result = result .. '<div style="display:none">';
for key, entity in pairs( context.cache ) do
result = result .. '<a href="https://wikidata.org' .. mw.uri.localUrl('Track:' .. key).path .. '"></a>';
end
result = result ..'</div>'
 
return {text = result, code = src.code};
end
 
local function wrapInUrlpersonNameToResponsibleName( urls, textfullName )
if not fullName then return fullName end
local url = getSingle( urls );
local tokenized = tokenizeName(fullName)
if ( string.sub( url, 1, 1 ) == ':' ) then
if #tokenized == 1 then
return '[[' .. url .. '|' .. text .. ']]';
return tokenized[1]
else
return 'tokenized[' .. url2] .. ' &nbsp;' .. text .. 'tokenized[1]';
end
end
 
function renderShortReference( src )
context = {
cache = {},
lang = getSingle( src.lang ) or i18nDefaultLanguage;
};
src.title = src.title or '\'\'(neimenovan naslov)\'\''
 
local options_commas = { separator = ', ', conjunction = ', ', format = function( src ) return src end, nolinks = false, preferids = false };
local result = '[[#' .. PREFIX_CITEREF .. src.code .. '|';
local options_commas_short = { separator = ', ', conjunction = ', ', format = function( src ) return src end, nolinks = false, preferids = false, short = true };
if ( src.author ) then
local options_commas_nolinks = { separator = ', ', conjunction = ', ', format = function( src ) return src end, nolinks = true, preferids = false };
result = result .. toString( context, src.author, options_authors_nolinks );
local options_commas_it = { separator = ', ', conjunction = ', ', format = function( src ) return "''" .. src .. "''" end, nolinks = false, preferids = false };
else
local options_commas_it_short = { separator = ', ', conjunction = ', ', format = function( src ) return "''" .. src .. "''" end, nolinks = false, preferids = false, short = true };
result = result .. toString( context, src.title, options_commas_it_nolinks );
local options_commas_it_nolinks = { separator = ', ', conjunction = ', ', format = function( src ) return "''" .. src .. "''" end, nolinks = true , preferids = false };
end
local options_citetypes = { separator = ' ', conjunction = ' ', format = function( src ) return 'citetype_' .. src end, nolinks = true , preferids = true };
result = result .. ']]'
 
local options_commas_authors = { separator = ', ', conjunction = ', ', format = personNameToAuthorName, nolinks = false, preferids = false };
if ( src.year ) then
local options_commas_responsible = { separator = ', ', conjunction = ', ', format = personNameToResponsibleName, nolinks = false, preferids = false };
result = result .. ', ' .. toString( context, src.year, options_commas );
end
 
local options_arxiv = { separator = '; ', conjunction = '; ', format = function( id ) return '[http://arxiv.org/abs/' .. id .. ' arXiv:' .. id .. ']' end, nolinks = true, preferids = false };
if ( src.volume ) then
local options_doi = { separator = '; ', conjunction = '; ', format = function( doi ) return '[http://dx.doi.org/' .. doi .. ' doi:' .. doi .. ']' end, nolinks = true, preferids = false };
local letter = i18nVolume[ context.lang ] or i18nVolume[ i18nDefaultLanguage ];
local options_issn = { separator = '; ', conjunction = '; ', format = function( issn ) return '[https://www.worldcat.org/issn/' .. issn .. ' ' .. issn .. ']' end, nolinks = true, preferids = false };
result = result .. ' — ' .. letter .. '&nbsp;' .. toString( context, src.volume, options_commas ) .. '.';
local options_pmid = { separator = '; ', conjunction = '; ', format = function( pmid ) return '[https://www.ncbi.nlm.nih.gov/pubmed/?term=' .. pmid .. ' PMID:' .. pmid .. ']' end, nolinks = true, preferids = false };
end
 
local function getPersonNameAsLabel( context, entityId, providedLabel, options )
if ( src.issue ) then
-- would custom label provided we don't need to check entity at all
local letter = i18nIssue[ context.lang ] or i18nIssue[ i18nDefaultLanguage ];
if ( not utils.isEmpty( providedLabel ) ) then
result = result .. ' — ' .. letter .. '&nbsp;' .. toString( context, src.issue, options_commas ) .. '.';
mw.log( 'Custom label provided for ' .. entityId );
return options.format( providedLabel );
end
if ( src.pages ) then
local letter = i18nPages[ context.lang ] or i18nPages[ i18nDefaultLanguage ];
result = result .. ' — ' .. letter .. '&nbsp;' .. toString( context, src.pages, options_commas ) .. '.';
end
end
 
local entity = utils.getEntity( context, entityId );
function getSingle( value )
if ( not valueentity ) then return '\'\'(entity ' .. entityId .. ' is missing)\'\'' end;
 
return;
local personName = nil;
-- support only labels so far
if ( entity.labels[ context.lang ] ) then
personName = entity.labels[ context.lang ].value;
mw.log('Got person name of ' .. entityId .. ' from label: «' .. personName .. '»' )
end
if ( type( value ) == 'string' ) then
return value;
elseif ( type( value ) == 'table' ) then
if ( value.id ) then
return value.id;
end
 
if ( not utils.isInstanceOf( entity, 'Q5' ) ) then
for i, tableValue in pairs( value ) do
mw.log( 'Entity ' .. entityId .. ' is not a person' );
return getSingle( tableValue );
return personName;
end
end
 
if ( utils.isEmpty( personName ) ) then
return '(neznano)';
return '\'\'(not translated to ' .. context.lang .. ')\'\'';
end
 
function toString( context, value, options )
if ( type( value ) == 'string' ) then
return options.format( value );
elseif ( type( value ) == 'table' ) then
if ( value.id ) then
-- this is link
if ( type( value.label or '' ) ~= 'string' ) then mw.logObject( value ); error('label of table value is not string but ' .. type( value.label ) ) end
 
if ( options.preferids ) then
return options.format( value.id );
else
if ( options.nolinks ) then
return options.format( value.label or mw.wikibase.label( value.id ) or '\'\'(nepreveden naslov)\'\'' );
else
return options.format( renderLink( context, value.id, value.label, options ) );
end
end
end
 
local resultList = {};
for i, tableValue in pairs( value ) do
table.insert( resultList, toString( context, tableValue, options ) );
end
 
return mw.text.listToText( resultList, options.separator, options.conjunction);
else
return options.format( '(neznan tip)'personName );
end
 
return '';
end
 
local function renderLinkgetPersonNameAsWikitext( context, entityId, customTitlecustomLabel, options )
local personName = getPersonNameAsLabel( context, entityId, customLabel, options);
if ( not entityId ) then error("entityId is not specified") end
if ( personName == nil ) then
if ( type( entityId ) ~= 'string' ) then error('entityId is not string, but ' .. type( entityId ) ) end
return nil;
if ( type( customTitle or '' ) ~= 'string' ) then error('customTitle is not string, but ' .. type( customTitle ) ) end
 
local title = customTitle;
 
if ( isEmpty( title ) ) then
local entity = getEntity( context, entityId );
 
-- ISO 4
if ( isEmpty( title ) ) then
if ( entity.claims and entity.claims.P1160 ) then
for _, claim in pairs( entity.claims.P1160 ) do
if ( claim
and claim.mainsnak
and claim.mainsnak.datavalue
and claim.mainsnak.datavalue.value
and claim.mainsnak.datavalue.value.language == context.lang ) then
title = claim.mainsnak.datavalue.value.text;
mw.log('Got title of ' .. entityId .. ' from ISO 4 claim: «' .. title .. '»' )
break;
end
end
end
end
 
-- official name P1448
-- short name P1813
if ( isEmpty( title ) and options.short ) then
if ( entity.claims and entity.claims.P1813 ) then
for _, claim in pairs( entity.claims.P1813 ) do
if ( claim
and claim.mainsnak
and claim.mainsnak.datavalue
and claim.mainsnak.datavalue.value
and claim.mainsnak.datavalue.value.language == context.lang ) then
title = claim.mainsnak.datavalue.value.text;
mw.log('Got title of ' .. entityId .. ' from short name claim: «' .. title .. '»' )
break;
end
end
end
end
-- person name P1559
-- labels
if ( isEmpty( title ) and entity.labels[ context.lang ] ) then
title = entity.labels[ context.lang ].value;
mw.log('Naslov pridobljen ' .. entityId .. ' iz oznake: «' .. title .. '»' )
end
end
 
local link = utils.getElementLink( context, entityId, nil );
local actualText = title or '\'\'(neprevedeno)\'\'';
return utils.wrapInUrl( link, personName );
local link = getElementLink( context, entityId, entity);
return wrapInUrl( link, actualText );
end
 
local function getElementLinkgetPeopleAsWikitext( context, entityIdvalue, entityoptions )
if type( value ) == 'string' then
-- fast sitelink lookup, not an expensive operation
return options.format( value )
local link = mw.wikibase.sitelink( entityId )
ifelseif type( linkvalue ) then return== ':table' .. link endthen
if value.id then
 
if ( not entity and entityId ) then
entity = getEntity( context, entityId )
end
 
if ( entity ) then
-- link to entity in source context language
local projectToCheck = context.lang .. 'wiki';
if ( entity.sitelinks and entity.sitelinks[ projectToCheck ] ) then
return ':' .. context.lang .. ':' .. entity.sitelinks[ projectToCheck ].title;
end
end
 
if ( entityId ) then return ':d:' .. entityId end;
-- if ( entityId ) then return 'https://tools.wmflabs.org/reasonator/?q=' .. entityId .. '&lang=sl' end;
return nil;
end
 
function getPeopleAsAuthorWikitext( context, value, options )
if ( type( value ) == 'string' ) then
return personNameToAuthorName( value );
elseif ( type( value ) == 'table' ) then
if ( value.id ) then
-- this is link
if ( options.preferids ) then
return value.id;
else
if ( options.nolinks ) then
return getPersonNameAsAuthorLabelgetPersonNameAsLabel( context, value.id, value.label, options );
else
return getPersonNameAsAuthorWikitextgetPersonNameAsWikitext( context, value.id, value.label, options );
end
end
end
 
local maxAuthors = 10 -- need some restrictions, as some publications have enormous amount of authors (e.g. 115 authors of Q68951544)
local resultList = {};
local resultList = {}
for i, tableValue in pairs( value ) do
local nextWikitext = getPeopleAsAuthorWikitextgetPeopleAsWikitext( context, tableValue, options );
if ( not utils.isEmpty( nextWikitext ) ) then
table.insert( resultList, nextWikitext );
if ( #resultList == 4maxAuthors + )1 then
-- evenkeep 4one is too much, but we preserve 4thmore to markindicate that "it'sthere moreare thantoo 3"many
break;
end
end
end
 
local resultWikitext = '';
for i, wikitext in pairs( resultList ) do
if ( i == 4maxAuthors + )1 then
resultWikitext = resultWikitext .. ( i18nEtAl[ context.lang ] or i18nEtAlDefault );
break;
end
if ( i ~= 1 ) then
resultWikitext = resultWikitext .. ', ';
end
resultWikitext = resultWikitext .. wikitext;
end
 
return resultWikitext;
end
 
return options.format( '(neznanunknown tiptype)' );
end
 
local function getPersonNameAsAuthorWikitextgenerateAuthorLinks( context, entityId, customLabel, options src)
local result = ''
local personNameAsAuthor = getPersonNameAsAuthorLabel( context, entityId, customLabel, options);
if ( personNameAsAuthor == nil )src.author then
result = getPeopleAsWikitext( context, src.author, options_commas_authors )
return nil;
result = '<i class="wef_low_priority_links">' .. result .. '</i> '
end
return result
 
local link = getElementLink( context, entityId, nil );
return wrapInUrl( link, personNameAsAuthor );
end
 
local function getPersonNameAsAuthorLabelappendProperty(result, context, entityIdsrc, providedLabelconjunctor, optionsproperty, url)
if src[property] then
-- would custom label provided we don't need to check entity at all
if (url notand isEmpty( providedLabel ) )src[url] then
result = result .. conjunctor .. utils.wrapInUrl( src[url], utils.toString( context, src[property], options_commas_nolinks ) )
mw.log( 'Custom label provided for ' .. entityId );
else
return personNameToAuthorName( providedLabel );
result = result .. conjunctor .. utils.toString( context, src[property], options_commas )
end
end
return result
end
 
local entityfunction = getEntityappendTitle(result, context, entityId src);
if src.part then
if ( not entity ) then return '\'\'(entity ' .. entityId .. ' is missing)\'\'' end;
result = appendProperty(result, context, src, '', 'part', 'url')
if ( not isInstanceOf( entity, 'Q5' ) ) then
result = appendProperty(result, context, src, ' // ', 'title')
mw.log( 'Entity ' .. entityId .. ' is not a person' );
else -- title only
return nil;
result = appendProperty(result, context, src, '', 'title', 'url')
end
end
return result
end
 
local function appendLanguage(result, context, src)
local personName = nil;
if context.lang ~= i18nDefaultLanguage then
-- support only labels so far
result = result .. langs.list_ref(p.currentFrame:newChild{ args = {context.lang} })
if ( entity.labels[ context.lang ] ) then
personName = entity.labels[ context.lang ].value;
mw.log('Got person name of ' .. entityId .. ' from label: «' .. personName .. '»' )
end
return result
end
 
local function appendSubtitle(result, context, src)
if ( isEmpty( personName ) ) then
return appendProperty(result, context, src, ': ', 'subtitle')
return '\'\'(ni prevedeno v ' .. context.lang .. ')\'\'';
else
return personNameToAuthorName( personName );
end
end
 
local function personNameToAuthorNameappendOriginalTitle(result, fullNamecontext, src)
return appendProperty(result, context, src, ' = ', 'originaltitle')
if ( not fullName ) then return fullName; end
 
local f, i, o = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)\,%s(%a[%a\-]*)%s(%a[%a\-]*)%s*$' );
if ( f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Fa, I. O.» match' );
return f .. '&nbsp;'
.. mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;'
.. mw.ustring.sub( o, 1, 1 ) .. '.';
end
 
local f1, f2, i = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)%s(%a[%a\-]*)\,%s(%a[%a\-]*)%s*$' );
if ( f1 ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Fa Fa, I» match' );
return f1 .. '&nbsp;' .. f2 .. '&nbsp;'
.. mw.ustring.sub( i, 1, 1 ) .. '.';
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a)\.%s(%a)\.%s(%a[%a\-]+)%s*$');
if ( f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «I. O. Fa» match' );
return f .. '&nbsp;' .. i .. '.&nbsp;' .. o .. '.';
end
 
local i1, i2, i3, f = mw.ustring.match( fullName, '^%s*(%a)\.%s(%a)\.%s(%a)\.%s(%a[%a\-]+)%s*$');
if ( f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «I. O. ?. Fa» match' );
return f .. '&nbsp;' .. i1 .. '.&nbsp;' .. i2 .. '.&nbsp;' .. i3 .. '.';
end
 
-- Joel J. P. C. Rodrigues
local i1, i2, i3, i4, f = mw.ustring.match( fullName, '^%s*(%a)[%a\-]+%s(%a)\.%s(%a)\.%s(%a)\.%s(%a[%a\-]+)%s*$');
if ( f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «I. O. ?. Fa» match' );
return f .. '&nbsp;' .. i1 .. '.&nbsp;' .. i2 .. '.&nbsp;' .. i3 .. '.&nbsp;' .. i4 .. '.';
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)%s(%a)\.%s(%a[%a\-]*)%s*$');
if ( f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Im O. Fa» match' );
return f .. '&nbsp;' .. mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;' .. o .. '.';
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)%s(%a[%a\-]*)%s(%a[%a\-]*)%s*$');
if ( f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Im Ot Fa» match' );
return f .. '&nbsp;' .. mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;' .. mw.ustring.sub( o, 1, 1 ) .. '.';
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]+)%s(%a[%a\-]+)%s+оглы%s+(%a[%a\-]+)%s*$');
if ( f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Im Ot оглы Fa» match' );
return f .. '&nbsp;' .. mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;' .. mw.ustring.sub( o, 1, 1 ) .. '.';
end
 
local i, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]+)%s(%a[%a\-]+)%s*$');
if ( f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Im Fa» match' );
return f .. '&nbsp;' .. mw.ustring.sub( i, 1, 1 ) .. '.';
end
 
mw.log( 'Unmatched any pattern: «' .. fullName .. '»' );
return fullName;
end
 
local function appendPublication(result, context, src)
-- Expand special types of references when additional data could be found in OTHER entity properties
if src.publication then
function expandSpecials( currentEntity, reference, data )
if type( src.publication.title or '') ~= 'string' then
if ( reference.snaks.P248
error('type of src.publication.title is not string but ' .. type( src.publication.title ) )
and reference.snaks.P248[1]
and reference.snaks.P248[1].datavalue
and reference.snaks.P248[1].datavalue.value["numeric-id"]) then
local sourceId = "Q" .. reference.snaks.P248[1].datavalue.value["numeric-id"];
data.sourceId = sourceId;
 
-- Gemeinsame Normdatei -- specified by P227
if ( sourceId == 'Q36578' ) then
appendSnaks( currentEntity.claims, 'P227', data, 'part', { format = function( gnd ) return 'Record #' .. gnd; end } );
appendSnaks( currentEntity.claims, 'P227', data, 'url', { format = function( gnd ) return 'http://d-nb.info/gnd/' .. gnd .. '/'; end } );
data.year = '2012—2016'
expandSpecialsQualifiers( currentEntity, 'P227', data );
end
 
result = result .. ' // ' .. utils.toString( context, src.publication, options_commas_it_short )
-- BNF -- specified by P268
if ( sourceId == 'Q15222191' )src.publication.subtitle then
result = result .. ': ' .. utils.toString( context, src.publication.subtitle, options_commas_it_short )
appendSnaks( currentEntity.claims, 'P268', data, 'part', { format = function( id ) return 'Record #' .. id; end } );
appendSnaks( currentEntity.claims, 'P268', data, 'url', { format = function( id ) return 'http://catalogue.bnf.fr/ark:/12148/cb' .. id; end } );
expandSpecialsQualifiers( currentEntity, 'P268', data );
end
 
-- Union List of Artist Names -- specified by P245
if ( sourceId == 'Q2494649' ) then
appendSnaks( currentEntity.claims, 'P245', data, 'url', { format = function( id ) return 'http://www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid=' .. id end } );
expandSpecialsQualifiers( currentEntity, 'P245', data );
end
 
-- imdb.com -- specified by P345
if ( sourceId == 'Q37312' ) then
appendSnaks( currentEntity.claims, 'P345', data, 'part', { format = function( id ) return 'Person Profile' end } );
appendSnaks( currentEntity.claims, 'P345', data, 'url', { format = function( id ) return 'http://www.imdb.com/name/' .. id .. '/' end } );
expandSpecialsQualifiers( currentEntity, 'P345', data );
end
 
-- wtatennis.com -- specified by P597
if ( sourceId == 'Q14580067' ) then
appendSnaks( currentEntity.claims, 'P597', data, 'part', { format = function( id ) return 'Player Profile' end } );
appendSnaks( currentEntity.claims, 'P597', data, 'url', { format = function( id ) return 'http://www.wtatennis.com/players/player/' .. id end } );
expandSpecialsQualifiers( currentEntity, 'P597', data );
end
 
-- Find a Grave -- specified by P535
if ( sourceId == 'Q63056' ) then
appendSnaks( currentEntity.claims, 'P535', data, 'url', { format = function( id ) return 'http://www.findagrave.com/cgi-bin/fg.cgi?page=gr&GRid=' .. id; end } );
expandSpecialsQualifiers( currentEntity, 'P535', data );
end
 
-- Gran Enciclopèdia Catalana -- specified by P1296
if ( sourceId == 'Q2664168' ) then
appendSnaks( currentEntity.claims, 'P1296', data, 'url', { format = function( id ) return 'http://www.enciclopedia.cat/enciclop%C3%A8dies/gran-enciclop%C3%A8dia-catalana/EC-GEC-' .. id .. '.xml'; end } );
expandSpecialsQualifiers( currentEntity, 'P1296', data );
end
 
-- Encyclopædia Britannica online -- specified by P1417
if ( sourceId == 'Q5375741' ) then
appendSnaks( currentEntity.claims, 'P1417', data, 'url', { format = function( id ) return 'http://global.britannica.com/' .. id; end } );
expandSpecialsQualifiers( currentEntity, 'P1417', data );
end
 
-- do we have appropriate record in P1433 ?
local claims = findClaimsByValue( currentEntity, 'P1343', sourceId );
if ( claims and #claims ~= 0 ) then
for _, claim in pairs( claims ) do
populateDataFromClaims( sourceId, claim.qualifiers, data );
end
end
 
-- Electronic Jewish Encyclopedia (Elektronnaja Evrejskaja Entsiklopedia) -- specified by P1438
if ( sourceId == 'Q1967250' ) then
appendSnaks( currentEntity.claims, 'P1438', data, 'url', { format = function( id ) return 'http://www.eleven.co.il/article/' .. id; end } );
expandSpecialsQualifiers( currentEntity, 'P1438', data );
end
 
-- sports-reference.com -- specified by P1447
if ( sourceId == 'Q18002875' ) then
appendSnaks( currentEntity.claims, 'P1447', data, 'url', { format = function( id ) return 'http://www.sports-reference.com/olympics/athletes/' .. id .. '.html'; end } );
expandSpecialsQualifiers( currentEntity, 'P1447', data );
end
 
-- Dizionario Biografico degli Italiani -- specified by P1986
if ( sourceId == 'Q1128537' ) then
if ( not data.lang ) then data.lang = { id = 'Q652' } end;
appendSnaks( currentEntity.claims, 'P1986', data, 'url', { format = function( id ) return 'http://www.treccani.it/enciclopedia/' .. id .. '_%28Dizionario_Biografico%29/' end } );
expandSpecialsQualifiers( currentEntity, 'P1986', data );
end
end
return result
end
 
local function expandSpecialsQualifiersappendEditor( entityresult, propertyIdcontext, data src)
if src.editor then
if ( entity.claims ~= nil and entity.claims[propertyId] ~= nil ) then
local prefix = i18nEditors[ context.lang ] or i18nEditors[ i18nDefaultLanguage ]
for _, claim in pairs( entity.claims[propertyId] ) do
result = result .. ' / ' .. prefix .. getPeopleAsWikitext( context, src.editor, options_commas_responsible )
populateDataFromClaims( nil, claim.qualifiers, data );
end
end
return result
end
 
local function findClaimsByValueappendEdition( entityresult, propertyIdcontext, value src)
return appendProperty(result, context, src, ' — ', 'edition')
local result = {};
if ( entity and entity.claims and entity.claims[propertyId] ) then
for i, claim in pairs( entity.claims[propertyId] ) do
if ( claim.mainsnak and claim.mainsnak.datavalue ) then
local datavalue = claim.mainsnak.datavalue;
if ( datavalue.type == "string" and datavalue.value == value
or datavalue.type == "wikibase-entityid" and datavalue.value["entity-type"] == "item" and tostring( datavalue.value["numeric-id"] ) == mw.ustring.sub( value, 2 ) ) then
table.insert( result, claim );
end
end
end
end
return result;
end
 
local function appendSnaksappendPublicationData( allSnaks, snakPropertyId, result, propertycontext, options src)
if src.place or src.publisher or src.year then
-- do not populate twice
if result (= result[property] ).. then' return result end;'
if src.place then
if ( not allSnaks ) then return result; end;
result = result .. utils.toString( context, src.place, options_commas_short )
if src.publisher or src.year then
local selectedSnakes = allSnaks[ snakPropertyId ];
result = result .. ': '
if ( not selectedSnakes ) then return result; end;
end
 
local hasPreferred = false;
for k, snak in pairs( selectedSnakes ) do
if ( snak and snak.mainsnak and snak.mainsnak.datavalue and snak.rank == 'preferred' ) then
--it's a preferred claim
appendImpl( snak.mainsnak.datavalue, snak.qualifiers, result, property, options );
hasPreferred = true;
end
if src.publisher then
end
result = result .. utils.toString( context, src.publisher, options_commas_short )
if ( hasPreferred ) then return result; end;
if src.year then
 
result = result .. ', '
for k, snak in pairs( selectedSnakes ) do
if ( snak and snak.mainsnak and snak.mainsnak.datavalue and snak.rank ~= 'deprecated' ) then
--it's a claim
appendImpl( snak.mainsnak.datavalue, snak.qualifiers, result, property, options );
elseif ( snak and snak.datavalue ) then
-- it's a snak
appendImpl( snak.datavalue, nil, result, property, options );
end
end
end
 
function appendQualifiers( claims, qualifierPropertyId, result, resultProperty, options )
-- do not populate twice
if ( not claims ) then return result end;
if ( result[resultProperty] ) then return result end;
 
for i, claim in pairs( claims ) do
if ( claim.qualifiers and claim.qualifiers[ qualifierPropertyId ] ) then
for k, qualifier in pairs( claim.qualifiers[ qualifierPropertyId ] ) do
if ( qualifier and qualifier.datavalue ) then
appendImpl( qualifier.datavalue, nil, result, resultProperty, options );
end
end
end
if src.year then
result = result .. utils.toString( context, src.year, options_commas )
end
result = result .. '.';
end
return result
end
 
local function appendImplappendVolumeAndIssue( datavalue, qualifiers, result, propertycontext, options src)
if ( datavaluesrc.typevolume ==or 'string' )src.issue then
result = result .. ' — '
local statedAs = getSingleStringQualifierValue(qualifiers, 'P1932');
local letter_vol = i18nVolume[ context.lang ] or i18nVolume[ i18nDefaultLanguage ]
local value;
local letter_iss = i18nIssue[ context.lang ] or i18nIssue[ i18nDefaultLanguage ]
if ( statedAs ) then
if src.volume then
value = statedAs;
result = appendProperty(result, context, src, letter_vol .. '&nbsp;', 'volume')
result = appendProperty(result, context, src, ', ' .. letter_iss .. '&nbsp;', 'issue')
else
result = appendProperty(result, context, src, letter_iss .. '&nbsp;', 'issue')
value = datavalue.value;
if ( options.format ) then
value = options.format( value );
end
end
appendImpl_toTable(result = result, property.. );'.'
end
table.insert( result[property], value);
return result
elseif ( datavalue.type == 'monolingualtext' ) then
local value = datavalue.value.text;
if ( options.format ) then
value = options.format( value );
end
appendImpl_toTable( result, property );
table.insert( result[property], value);
elseif ( datavalue.type == 'quantity' ) then
local value = datavalue.value.amount;
if ( mw.ustring.sub( value , 1, 1 ) == '+' ) then
value = mw.ustring.sub( value , 2 );
end
if ( options.format ) then
value = options.format( value );
end
appendImpl_toTable( result, property );
table.insert( result[property], value);
elseif ( datavalue.type == 'wikibase-entityid' ) then
local value = datavalue.value;
appendImpl_toTable( result, property );
local toInsert = {
id = 'Q' .. value["numeric-id"],
label = getSingleStringQualifierValue(qualifiers, 'P1932') -- stated as
};
table.insert( result[property], toInsert );
elseif datavalue.type == 'time' then
local value = datavalue.value;
if ( options.format ) then
value = options.format( value );
end
appendImpl_toTable( result, property );
table.insert( result[property], tostring( value.time ));
end
end
 
local function appendImpl_toTableappendPages(result, resultPropertycontext, src)
if ( not result[resultProperty] )src.pages then
local letter = i18nPages[ context.lang ] or i18nPages[ i18nDefaultLanguage ]
result[resultProperty] = {};
local strPages = utils.toString( context, src.pages, options_commas )
elseif ( type( result[resultProperty] ) == 'string' or ( type( result[resultProperty] ) == 'table' and type( result[resultProperty].id ) == 'string' ) ) then
strPages = mw.ustring.gsub( strPages, '[-—]', '—' );
result[resultProperty] = { result[resultProperty] };
result = result .. ' — ' .. letter .. '&nbsp;' .. strPages .. '.'
end
return result
end
 
local function appendNumberOfPages(result, context, src)
function getSingleStringQualifierValue( allQualifiers, qualifierPropertyId )
if ( not allQualifiers )src.numberOfPages then return end
local letter = i18nNumberOfPages[ context.lang ] or i18nNumberOfPages[ i18nDefaultLanguage ]
if ( not allQualifiers[qualifierPropertyId] ) then return end
result = appendProperty(result, context, src, ' — ', 'numberOfPages') .. '&nbsp;' .. letter
 
for k, qualifier in pairs( allQualifiers[qualifierPropertyId] ) do
if ( qualifier and qualifier.datatype == 'string'
and qualifier.datavalue and qualifier.datavalue.type == 'string' and not isEmpty( qualifier.datavalue.value ) ) then
return qualifier.datavalue.value;
end
end
return result
 
return;
end
 
local function expandPublicationappendBookSeries(result, context, sourceEntity, data src)
if src.bookSeries then
local publication = data.publication;
result = appendProperty(result, context, src, ' — (', 'bookSeries')
 
if src.bookSeriesVolume or src.bookSeriesIssue then
-- use only first one
result = result .. '; '
if ( type( publication ) == 'table' and publication[1] and publication[1].id ) then
local letter_vol = i18nVolume[ context.lang ] or i18nVolume[ i18nDefaultLanguage ]
data.publication = publication[1];
local letter_iss = i18nIssue[ context.lang ] or i18nIssue[ i18nDefaultLanguage ]
publication = data.publication;
if ( src.bookSeriesVolume ) then
end
result = appendProperty(result, context, src, letter_vol .. '&nbsp;', 'bookSeriesVolume')
 
result = appendProperty(result, context, src, ', ' .. letter_iss .. '&nbsp;', 'bookSeriesIssue')
if ( not publication ) then return end;
else
if ( not publication.id ) then return end;
result = appendProperty(result, context, src, letter_iss .. '&nbsp;', 'bookSeriesIssue')
 
if ( sourceEntity ) then
-- do we have appropriate record in P1433 ?
local claims = findClaimsByValue( sourceEntity, 'P1433', publication.id );
if ( claims and #claims ~= 0 ) then
for _, claim in pairs( claims ) do
populateDataFromClaims( sourceEntity, claim.qualifiers, data );
break;
end
end
result = result .. ')'
end
return result
end
 
local function appendTirage(result, context, src)
local titleWerePresent = not (not data.title);
if src.tirage then
local pubEntity = getEntity( context, publication.id );
local tirageTemplate = i18nTirage[ context.lang ] or i18nTirage[ i18nDefaultLanguage ]
populateSourceDataImpl( pubEntity, data );
result = result .. ' — ' .. utils.toString( context, src.tirage, { separator = '; ', conjunction = '; ', format = function( data ) return mw.ustring.format(tirageTemplate, data) end } )
if ( titleWerePresent and isEmpty( data.publication.label ) ) then
appendSnaks( pubEntity.claims, 'P1160', data, 'publication-title', {} ); -- obsolete
data.publication.label = getSingle( data['publication-title'] );
end
if ( titleWerePresent and isEmpty( data.publication.label ) ) then
appendSnaks( pubEntity.claims, 'P357', data, 'publication-title', {} ); -- obsolete
appendSnaks( pubEntity.claims, 'P1476', data, 'publication-title', {} );
appendSnaks( pubEntity.claims, 'P1680', data, 'publication-subtitle', {} );
data.publication.label = getSingle( data['publication-title'] );
data.publication.subtitle = getSingle( data['publication-subtitle'] );
end
return result
end
 
local function appendIdentifiers(result, context, src)
if ( pubEntity.claims and pubEntity.claims.P361 ) then
if src.isbn then result = result .. ' — ISBN ' .. utils.toString( context, src.isbn, options_commas ) end
for c, claim in pairs( pubEntity.claims.P361 ) do
if src.issn then result = result .. ' — ISSN ' .. utils.toString( context, src.issn, options_issn ) end
if ( claim and claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value and claim.mainsnak.datavalue.value["numeric-id"] ) then
if src.doi then result = result .. ' — ' .. utils.toString( context, src.doi, options_doi ) end
local possibleBookSeriesEntityId = 'Q' .. claim.mainsnak.datavalue.value["numeric-id"];
if src.pmid then result = result .. ' — ' .. utils.toString( context, src.pmid, options_pmid ) end
local possibleBookSeriesEntity = getEntity( context, possibleBookSeriesEntityId );
if src.arxiv then result = result .. ' — ' .. utils.toString( context, src.arxiv, options_arxiv ) end
if ( isInstanceOf( possibleBookSeriesEntity, 'Q277759' ) ) then
return result
appendImpl_toTable( data, 'bookSeries' );
end
table.insert( data.bookSeries, { id = possibleBookSeriesEntityId } );
 
local function appendSourceId(result, context, src)
appendQualifiers( { claim }, 'P478', data, 'bookSeriesVolume', {} );
if src.sourceId then
appendQualifiers( { claim }, 'P433', data, 'bookSeriesIssue', {} );
local citetype = src.type and utils.toString(context, src.type, options_citetypes) or 'citetype_unknown'
end
result = '<span class="wikidata_cite ' .. citetype .. '" data-entity-id="' .. utils.getSingle(src.sourceId) .. '">' .. result .. '</span>'
end
end
end
return result
 
expandBookSeries( context, data );
end
 
local function expandBookSeriesappendAccessDate(result, context, data src)
if src.accessdate then
local bookSeries = data.bookSeries;
local date = utils.getSingle(src.accessdate)
if ( not bookSeries ) then return end;
local pattern = "(%-?%d+)%-(%d+)%-(%d+)T";
 
local y, m, d = mw.ustring.match(date, pattern)
-- use only first one
y, m, d = tonumber(y), tonumber(m), tonumber(d)
if ( type( bookSeries ) == 'table' and bookSeries[1] and bookSeries[1].id ) then
result = result .. " <small>Проверено " .. tostring(d) .. " " .. monthg[m] .. " " .. tostring(y) .. ".</small>"
data.bookSeries = bookSeries[1];
bookSeries = data.bookSeries;
end
return result
 
if ( not bookSeries ) then return end;
if ( not bookSeries.id ) then return end;
 
local bookSeriesEntity = getEntity( context, bookSeries.id );
appendSnaks( bookSeriesEntity.claims, 'P123', data, 'publisher', {} );
appendSnaks( bookSeriesEntity.claims, 'P291', data, 'place', {} );
appendSnaks( bookSeriesEntity.claims, 'P236', data, 'issn', {} );
end
 
local function populateSourceDataImplpopulateUrl( entitycontext, plainData src)
if src.sourceId and not src.url then
populateDataFromClaims( entity.id, entity.claims, plainData );
local entity = utils.getEntity(context, src.sourceId)
 
if entity.sitelinks and entity.sitelinks[context.lang .. 'wikisource'] then
local normativeTitle = getNormativeTitle( entity )
src.url = ':' .. context.lang .. ':s:' .. entity.sitelinks[context.lang .. 'wikisource'].title
if ( normativeTitle ) then
local y, m, d = mw.ustring.match( getSingle( plainData.dateOfCreation ) , "(%-?%d+)%-(%d+)%-(%d+)T" );
y,m,d = tonumber(y),tonumber(m),tonumber(d);
local title = toString( { lang='sl' }, plainData.title, options_commas_nolinks );
plainData.title = { normativeTitle .. " od&nbsp;" .. tostring(d) .. "&nbsp;" .. monthg[m] .. " " .. tostring(y) .. "&nbsp;г. №&nbsp;" .. getSingle( plainData.docNumber ) .. ' «' .. title .. '»' }
end
 
if ( not plainData.title ) then
if ( entity.labels and entity.labels.sl and entity.labels.sl.value ) then
plainData.title = { entity.labels.sl.value };
end
end
 
return plainData;
end
 
local function populateYear(src)
function populateDataFromClaims( entityId, claims, data )
if not src.year and src.dateOfPublication then
appendSnaks( claims, 'P50', data, 'author', {} );
local date = utils.getSingle(src.dateOfPublication)
appendSnaks( claims, 'P2093', data, 'author', {} );
src.year = mw.ustring.sub(date, 2, 5)
appendSnaks( claims, 'P407', data, 'lang', {} );
end
appendSnaks( claims, 'P364', data, 'lang', {} );
if not src.year and src.dateOfCreation then
appendSnaks( claims, 'P958', data, 'part', {} );
local date = utils.getSingle(src.dateOfCreation)
if ( not data.title ) then
src.year = mw.ustring.sub(date, 2, 5)
if ( not isEmpty( entityId ) ) then
local optionsAsLinks = { format = function( text ) return { id = entityId, label = text } end };
appendSnaks( claims, 'P357', data, 'title', optionsAsLinks ); -- obsolete
appendSnaks( claims, 'P1476', data, 'title', optionsAsLinks );
else
appendSnaks( claims, 'P357', data, 'title', {} ); -- obsolete
appendSnaks( claims, 'P1476', data, 'title', {} );
end
appendSnaks( claims, 'P1680', data, 'subtitle', {} );
end
appendSnaks( claims, 'P953', data, 'url', {} );
appendSnaks( claims, 'P1065', data, 'url', {} );
appendSnaks( claims, 'P854', data, 'url', {} );
-- temp disable, use only for current entity, see Q22338048 for example of incorrect work
-- appendSnaks( claims, 'P856', data, 'url', {} );
appendSnaks( claims, 'P1433', data, 'publication', {} );
appendSnaks( claims, 'P393', data, 'edition', {} );
appendSnaks( claims, 'P123', data, 'publisher', {} );
appendSnaks( claims, 'P291', data, 'place', {} );
appendSnaks( claims, 'P304', data, 'pages', {} );
appendSnaks( claims, 'P1104', data, 'numberOfPages', {} );
appendSnaks( claims, 'P478', data, 'volume', {} );
appendSnaks( claims, 'P433', data, 'issue', {} );
appendSnaks( claims, 'P571', data, 'dateOfCreation', {} );
appendSnaks( claims, 'P577', data, 'dateOfPublication', {} );
appendSnaks( claims, 'P212', data, 'isbn', {} ); -- ISBN-13
appendSnaks( claims, 'P957', data, 'isbn', {} ); -- ISBN-10
appendSnaks( claims, 'P236', data, 'issn', {} );
 
-- web
-- appendSnaks( claims, 'P813', data, 'accessdate', {} );
 
-- docs
appendSnaks( claims, 'P1545', data, 'docNumber', {} );
 
-- other
appendSnaks( claims, 'P31', data, 'type', {} );
 
appendSnaks( claims, 'P818', data, 'arxiv', {} );
appendSnaks( claims, 'P356', data, 'doi', {} );
-- JSTOR
appendSnaks( claims, 'P888', data, 'url', { format = function( id ) return 'http://www.jstor.org/stable/' .. id end } );
 
return src;
end
 
local function p.renderSourcepopulateTitle( frame src)
src.title = src.title or utils.getSingle(src.url) or '\'\'(unspecified title)\'\''
p.currentFrame = frame;
 
local arg = frame.args[1];
local refAnchor = frame.args['ref'];
local refAnchorYear = frame.args['ref-year'];
local args = {};
args.refAnchor = frame.args['ref'];
args.refAnchorYear = frame.args['ref-year'];
args.part = frame.args['part'];
args.pages = frame.args['pages'];
 
return p.renderSourceImpl( mw.text.trim( arg ), args );
end
 
local function copyArgsToSnaksrenderSource( argscontext, snaks src)
options_commas_authors.format = personNameToAuthorName
if ( not isEmpty( args.part ) ) then snaks.P958 = { toStringSnak( 'P958', tostring( args.part ) ) } end
options_commas_responsible.format = personNameToResponsibleName
if ( not isEmpty( args.pages ) ) then snaks.P304 = { toStringSnak( 'P304', tostring( args.pages ) ) } end
if ( not isEmpty( args.issue ) ) then snaks.P433 = { toStringSnak( 'P433', tostring( args.issue ) ) } end
if ( not isEmpty( args.volume ) ) then snaks.P478 = { toStringSnak( 'P478', tostring( args.volume ) ) } end
if ( not isEmpty( args.url ) ) then snaks.P953 = { toUrlSnak( 'P953', tostring( args.url ) ) } end
end
 
context.lang = utils.getLangCode(utils.getSingle(src.lang)) or i18nDefaultLanguage
function p.renderSourceImpl( entityId, args )
args = args or {};
 
utils.preprocessPlaces(src, context.lang)
local snaks = {};
snaks.P248 = { toWikibaseEntityIdSnak( 'P248', entityId ) };
copyArgsToSnaks( args, snaks );
 
populateUrl(context, src)
local rendered = renderReferenceImpl( mw.wikibase.getEntity(), { snaks = snaks }, args.refAnchor, args.refAnchorYear );
populateTitle(src)
if ( rendered ) then return rendered.text end;
populateYear(src)
end
 
local result = generateAuthorLinks(context, src)
function p.renderReference( frame, currentEntity, reference )
result = appendTitle(result, context, src)
p.currentFrame = frame;
result = appendLanguage(result, context, src)
 
result = appendSubtitle(result, context, src)
-- template call
result = appendOriginalTitle(result, context, src)
if ( frame and not currentEntity and not reference ) then
result = appendPublication(result, context, src)
local args = frame.args;
if ( #frame.args == 0 ) then
result = result .. '<span class="wef_low_priority_links">'
args = frame:getParent().args;
result = appendEditor(result, context, src) -- Might take current editor instead of actual. Use with caution
end
result = appendEdition(result, context, src)
 
result = appendPublicationData(result, context, src)
local snaks = {};
result = appendVolumeAndIssue(result, context, src)
 
result = appendPages(result, context, src)
if ( args[1] ) then
result = appendNumberOfPages(result, context, src)
snaks.P248 = { toWikibaseEntityIdSnak( "P248", args[1] ) };
result = appendBookSeries(result, context, src)
end
result = appendTirage(result, context, src)
copyArgsToSnaks( args, snaks );
result = appendIdentifiers(result, context, src)
 
result = appendSourceId(result, context, src)
currentEntity = mw.wikibase.getEntity();
result = appendAccessDate(result, context, src)
reference = { snaks = snaks };
result = result .. '</span>'
end
 
local rendered = renderReferenceImpl( currentEntity, reference );
 
if ( not rendered ) then
return '';
end
 
local result;
local code = rendered.code or mw.text.encode( rendered.text );
result = frame:extensionTag( 'ref', rendered.text, {name = code} ) .. '[[Kategorija:Članki z viri iz Wikipodatkov]]';
 
return result;
end
 
local function renderReferenceImpl( currentEntity, reference, refAnchor, refAnchorYear )
if ( not reference.snaks ) then
return nil;
end
 
-- контекст, содержит также кеш элементов
local context = {
cache = {},
}
 
-- данные в простом формате, согласованном с модулями формирования библиографического описания
local data = {};
 
-- забрать данные из reference
utils.populateDataFromClaims(context, nil, reference.snaks, data )
 
utils.expandSpecials(context, currentEntity, reference, data)
-- update ref name with ref-specific properties
if ( data.code ) then
if ( data.part ) then data.code = data.code .. '-' .. getSingle( data.part ) end
if ( data.pages ) then data.code = data.code .. '-' .. getSingle( data.pages ) end
if ( data.volume ) then data.code = data.code .. '-' .. getSingle( data.volume ) end
if ( data.issue ) then data.code = data.code .. '-' .. getSingle( data.issue ) end
if ( data.url ) then data.code = data.code .. '-' .. getSingle( data.url ) end
end
 
expandSpecials( currentEntity, reference, data );
 
local sourceEntity = nil;
if ( data.sourceId ) then
sourceEntity = utils.getEntity( context, data.sourceId );
if ( sourceEntity ) then
utils.populateSourceDataImpl(context, sourceEntity, data );
end
end
 
if ( data.publication ) then
utils.expandPublication( context, sourceEntity, data );
end
 
utils.expandBookSeries(context, data)
if ( next( data ) == nil ) then
return nil;
end
 
if next(data) == nil then
local rendered;
return nil
if ( p.short ) then
rendered = renderShortReference( data );
if ( mw.ustring.len( rendered.text ) == 0 ) then
return nil;
end
 
else
rendered = renderSource( context, data );
if ( mw.ustring.len( rendered.text ) == 0 ) then
return nil;
end
 
if ( refAnchor ) then
local anchorValue = 'CITEREF' .. refAnchor .. ( coalesce( refAnchorYear, data.year ) or '' );
rendered.text = '<span class="citation" id="' .. mw.uri.anchorEncode( anchorValue ) .. '">' .. rendered.text .. '</span>';
end
end
 
returnlocal rendered; = renderSource(context, data)
if mw.ustring.len(rendered) == 0 then
end
return nil
 
function getNormativeTitle( entity )
if ( not entity or not entity.claims or not entity.claims.P31 ) then
return;
end
 
if refAnchor then
for _, claim in pairs( entity.claims.P31 ) do
local anchorValue = 'CITEREF' .. refAnchor .. (utils.coalesce(refAnchorYear, data.year) or '')
if ( claim and claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.value and claim.mainsnak.datavalue.value["numeric-id"] ) then
rendered = '<span class="citation" id="' .. mw.uri.anchorEncode(anchorValue) .. '">' .. rendered .. '</span>'
local classId = 'Q' .. claim.mainsnak.datavalue.value["numeric-id"];
local title = NORMATIVE_DOCUMENTS[ classId ];
if ( title ) then
return title;
end
end
end
 
return; rendered
end
 
local function artificialSnaks(args)
local LANG_CACHE = {
local snaks = {}
Q150 = 'fr',
if args[1] then
Q188 = 'de',
entityId = mw.text.trim(args[1])
Q1321 = 'es',
snaks.P248 = {utils.toWikibaseEntityIdSnak("P248", entityId)}
Q1860 = 'en',
snaks.P805 = {utils.toWikibaseEntityIdSnak("P805", entityId)}
Q652 = 'it',
Q7737 = 'ru',
Q9063 = 'sl',
}
 
function getLangCode( langEntityId )
if ( not langEntityId ) then
return;
end
utils.copyArgsToSnaks(args, snaks)
 
return mw.wikibase.getEntity(), {snaks = snaks}
-- small optimization
local cached = LANG_CACHE[ langEntityId ];
if ( cached ) then return cached; end
 
local langEntity = mw.wikibase.getEntity( langEntityId );
if ( not langEntity ) then
mw.log( '[getLangCode] Missing entity ' .. langEntityId );
else
if ( langEntity.claims and langEntity.claims.P424 ) then
for _, claim in pairs( langEntity.claims.P424 ) do
if ( claim
and claim.mainsnak
and claim.mainsnak.datavalue
and claim.mainsnak.datavalue.value ) then
return '' .. claim.mainsnak.datavalue.value;
end
end
end
end
 
return;
end
 
function preprocessPlacesp.renderReference( dataframe, langcurrentEntity, reference)
p.currentFrame = frame
if ( not data.place ) then
return;
end;
 
-- template call
local newPlaces = {};
if frame and not currentEntity and not reference then
for index, place in pairs( data.place ) do
currentEntity, reference = artificialSnaks(frame.args)
if ( place.id ) then
local newPlaceStr = getPlaceName(lang, place.id)
if ( newPlaceStr ) then
newPlaces[index] = newPlaceStr;
else
newPlaces[index] = place;
end
else
newPlaces[index] = place;
end
end
data.place = newPlaces;
end
 
local rendered = renderReferenceImpl(currentEntity, reference)
function getPlaceName( lang, placeId )
if not rendered then
-- ГОСТ Р 7.0.12—2011
return ''
if ( (lang == 'sl' ) or (lang == 'ru' ) ) then
if ( placeId == 'Q649' ) then return toTextWithTip('Moskva', 'Moskva'); end
if ( placeId == 'Q656' ) then return toTextWithTip('Sankt Peterburg.', 'Sankt Peterburg'); end
if ( placeId == 'Q891' ) then return toTextWithTip('Nižni Novgorod', 'Nižni Novgorod'); end
if ( placeId == 'Q908' ) then return toTextWithTip('Rostov na Donu', 'Rostov na Donu'); end
end
-- Про выбор алгоритма хеширования см. [[Модуль:Hash]]. Знак подчёркивания в начале позволяет
return nil;
-- исключить ошибку, когда имя сноски — чисто числовое значение, каковыми иногда бывают хеши.
return frame:extensionTag('ref', rendered, {name = '_' .. mw.hash.hashValue('fnv164', rendered)}) .. '[[Category:Википедия:Статьи с источниками из Викиданных]]'
end
 
function toTextWithTipp.renderSource( text, tip frame)
p.currentFrame = frame
return '<span title="' .. tip .. '" style="border-bottom: 1px dotted; cursor: help; white-space: nowrap">' .. text .. '</span>';
currentEntity, reference = artificialSnaks(frame.args)
return renderReferenceImpl(currentEntity, reference, frame.args['ref'], frame.args['ref-year'])
end