Модуль:Sources: Версиязда гьоркьор батӀалъиял

Контент гилдана Контент жубана
Категория
модуль, обновление данных
Мухъ 1:
local p = {};
local u = require('Module:Sources-utils')
 
local i18nDefaultLanguage = 'ru';
 
local i18nEtAlDefault = ' et al.';
local i18nEtAl = {
ru = ' и др.',
}
 
local i18nDefaultLanguage = 'Q7737';
local i18nEditors = {
Q150fr = '', -- French
Q1321de = 'Hrsg.: ', -- Spanish
Q1860es = '', -- English
en = '',
Q7737 = 'под ред. ', -- Russian
Q188it = 'Hrsg.: ', -- German
ru = 'под ред. ',
}
 
local i18nVolume = {
Q150fr = 'Vol.', -- French
Q1321es = 'Vol.', -- Spanish
Q1860en = 'Vol.', -- English
Q7737it = 'ТVol.', -- Russian
ru = 'Т.',
}
 
local i18nPage = {
local i18nIssue = {
Q150 = 'P.', -- French
Q188 en = 'SIss.', -- German
Q1321 ru = 'Pвып.', -- Spanish
Q1860 = 'P.', -- English
Q7737 = 'С.', -- Russian
}
 
local i18nPages = {
local monthg = {'января', 'февраля', 'марта', 'апреля', 'мая', 'июня',
fr = 'P.',
'июля', 'августа', "сентября", "октября", "ноября", "декабря"};
de = 'S.',
es = 'P.',
en = 'P.',
it = 'P.',
ru = 'С.',
}
 
local PREFIX_CITEREFi18nNumberOfPages = "CITEREF_";{
en = 'p.',
ru = 'с.',
}
 
local i18nTirage = {
function p.deepcopy(orig)
en = 'ed. size: %d',
local orig_type = type(orig)
ru = '%d экз.',
local copy
}
if orig_type == 'table' then
 
copy = {}
 
for orig_key, orig_value in pairs(orig) do
local monthg = {'январалъ', 'февралалъ', 'марталъ', 'апрелалъ', 'майалъ', 'июналъ', 'июлалъ', 'августалъ', 'сентябралъ', 'октябралъ', 'ноябралъ', 'декабралъ'};
copy[orig_key] = p.deepcopy( orig_value );
 
end
local PREFIX_CITEREF = "CITEREF_";
else -- number, string, boolean, etc
copy = orig
end
return copy
end
 
local options_commas = { separator = ', ', conjunction = ', ', format = function( src ) return src end, nolinks = false, preferids = false };
local options_commas_short = { separator = ', ', conjunction = ', ', format = function( src ) return src end, nolinks = false, preferids = false, short = true };
local options_commas_nolinks = { separator = ', ', conjunction = ', ', format = function( src ) return src end, nolinks = true, preferids = false };
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 options_commas_it_nolinks = { separator = ', ', conjunction = ', ', format = function( src ) return "''" .. src .. "''" end, nolinks = true , preferids = false };
local options_citetypes = { separator = ' ', conjunction = ' ', format = function( src ) return 'citetype_' .. src end, nolinks = true , preferids = true };
 
local options_commas_authors = { separator = ', ', conjunction = ', ', format = personNameToAuthorName, nolinks = false, preferids = false };
function renderSource( src )
local options_commas_responsible = { separator = ', ', conjunction = ', ', format = personNameToResponsibleName, nolinks = false, preferids = false };
mw.logObject( src );
 
local options_arxiv = { separator = '; ', conjunction = '; ', format = function( id ) return '[http://arxiv.org/abs/' .. id .. ' arXiv:' .. id .. ']' end, nolinks = true, preferids = false };
local options_doi = { separator = '; ', conjunction = '; ', format = function( doi ) return '[http://dx.doi.org/' .. doi .. ' doi:' .. doi .. ']' end, nolinks = true, preferids = false };
local options_issn = { separator = '; ', conjunction = '; ', format = function( issn ) return '[https://www.worldcat.org/issn/' .. issn .. ' ' .. issn .. ']' end, nolinks = true, preferids = false };
 
function renderSource( context, src )
options_commas_authors.format = personNameToAuthorName;
options_commas_responsible.format = personNameToResponsibleName;
 
context.lang = getLangCode( getSingle( src.lang ) ) or i18nDefaultLanguage;
 
preprocessPlaces( src, context.lang );
 
if ( src.code and not src.url ) then
src.url = mw.wikibase.sitelink( src.code ) or ( 'd:' .. src.code )
src.url = ':' .. src.url;
end
src.lang = getSingle( src.lang ) or i18nDefaultLanguage;
src.title = src.title or getSingle( src.url ) or '\'\'(unspecified title)\'\''
 
if ( not src.yearsourceId and not src.dateurl ) then
local dateentity = getSinglegetEntity( context, src.datesourceId );
if ( entity.sitelinks and entity.sitelinks[ context.lang .. 'wikisource'] ) then
src.year = mw.ustring.sub( date, 9, 12 );
src.url = ':' .. context.lang .. ':s:' .. entity.sitelinks[ context.lang .. 'wikisource' ].title;
end
end
 
if ( not src.year and src.dateOfPublication ) then
local result = '';
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 result;
if ( src.author ) then
result = resultgetPeopleAsWikitext( .. toString(context, src.author, options_commas_itoptions_commas_authors );
end
if ( string.lennot isEmpty( result ) ~= 0 ) 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 ) );
local url = getSingle( src.url );
else
if ( string.sub( url, 1, 1 ) == ':' ) then
result = result .. '[[' .. url .. '|' .. toString( context, src.part, options_commas_nolinksoptions_commas ) .. ']]';
else
result = result .. '[' .. url .. ' ' .. toString( src.part, options_commas_nolinks ) .. ']';
end
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 ) );
local url = getSingle( src.url );
else
if ( string.sub( url, 1, 1 ) == ':' ) then
result = result .. '[[' .. url .. '|' .. toString( context, src.title, options_commas_nolinksoptions_commas ) .. ']]';
else
result = result .. '[' .. url .. ' ' .. toString( src.title, options_commas_nolinks ) .. ']';
end
end
end
 
if ( src.subtitle ) then
result = result .. ": " .. toString( context, src.subtitle, options_commas );
end
 
if ( src.originaltitle ) then
result = result .. ' = ' .. toString( context, src.originaltitle, options_commas );
end
 
if ( src.publication ) then
resultif =( resulttype( src.publication.title or '') //~= 'string' ) then error('type of src.publication.title toStringis not string but ' .. type( src.publication,.title options_commas_it) ) 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">';
 
if ( src.editor ) then
local prefix = i18nEditors[ srccontext.lang ] or i18nEditors[ i18nDefaultLanguage ];
result = result .. ' / ' .. prefix .. toStringgetPeopleAsWikitext( context, src.editor, options_commasoptions_commas_responsible );
end
 
if ( src.edition ) then
result = result .. ' — ' .. toString( context, src.edition, options_commas );
end
 
Мухъ 109 ⟶ 154 :
result = result .. ' — ';
if ( src.place ) then
result = result .. toString( context, src.place, options_commasoptions_commas_short );
if ( src.publisher or src.year ) then
result = result .. ': ';
Мухъ 115 ⟶ 160 :
end
if ( src.publisher ) then
result = result .. toString( context, src.publisher, options_commasoptions_commas_short );
if ( src.year ) then
result = result .. ', ';
Мухъ 121 ⟶ 166 :
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 .. ' — ';
local letter = i18nVolume[ src.lang ] or i18nVolume[ i18nDefaultLanguage ];
if ( src.volume ) then
result = result .. ' — ' .. letter .. '&nbsp;' .. toString(src.volume, options_commas ) .. '.';
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 ];
local strPages = toString( context, src.pages, options_commas );
strPages = mw.ustring.gsub( strPages, '[-—]', '–' );
result = result .. ' — ' .. letter .. '&nbsp;' .. strPages .. '.';
end
 
if ( src.issuenumberOfPages ) then
local letter = i18nNumberOfPages[ context.lang ] or i18nNumberOfPages[ i18nDefaultLanguage ];
result = result .. ' — №&nbsp;' .. toString(src.issue, options_commas ) .. '.';
result = result .. ' — ' .. toString( context, src.numberOfPages, options_commas ) .. '&nbsp;' .. letter;
end
 
if ( src.pagebookSeries ) then
result = result .. ' — (' .. toString( context, src.bookSeries, options_commas )
local letter = i18nPage[ src.lang ] or i18nPage[ i18nDefaultLanguage ];
 
result = result .. ' — ' .. letter .. '&nbsp;' .. toString(src.page, 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
 
if ( src.isbn13tirage ) then
local tirageTemplate = i18nTirage[ context.lang ] or i18nTirage[ i18nDefaultLanguage ];
result = result .. ' — ISBN ' .. toString( src.isbn13, options_commas );
result = result .. ' — ' .. toString( context, src.tirage, { separator = '; ', conjunction = ';', format = function( data ) return mw.ustring.format(tirageTemplate, data) end } );
elseif ( src.isbn10 ) then
end
result = result .. ' — ISBN ' .. toString( src.isbn10, options_commas );
 
if ( src.isbn ) then
result = result .. ' — ISBN ' .. toString( context, src.isbn, options_commas );
end
 
if ( src.issn ) then
result = result .. ' — ISSN ' .. toString( context, src.issn, options_commasoptions_issn );
end
 
if ( src.doi ) then
result = result .. ' — [http://dx.doi.org/' .. mw.uri.encodetoString( src.doi ) .. ' DOI&nbsp;' ..context, src.doi, ..options_doi ']');
end
 
if ( src.entityIdarxiv ) then
result = result .. ' — ' .. toString( context, src.arxiv, options_arxiv );
if ( src.type and src.entityId ) then
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.entityIdsourceId ) .. '">' .. result .. '</span>'
else
result = '<span class="wikidata_cite citetype_unknown" data-entity-id="' .. getSingle( src.entityIdsourceId ) .. '">' .. result .. '</span>'
end
end
Мухъ 169 ⟶ 260 :
result = result .. " <small>Проверено " .. 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};
Мухъ 174 ⟶ 274 :
 
function renderShortReference( src )
context = {
src.lang = getSingle( src.lang ) or i18nDefaultLanguage;
cache = {},
lang = getSingle( src.lang ) or i18nDefaultLanguage;
};
src.title = src.title or '\'\'(unspecified title)\'\''
 
local result = '[[#' .. PREFIX_CITEREF .. src.code .. '|';
if ( src.author ) then
result = result .. toString( context, src.author, options_commas_it_nolinksoptions_authors_nolinks );
else
result = result .. toString( context, src.title, options_commas_it_nolinks );
end
result = result .. ']]'
 
if ( src.year ) then
result = result .. ', ' .. toString( context, src.year, options_commas );
end
 
if ( src.volume ) then
local letter = i18nVolume[ srccontext.lang ] or i18nVolume[ i18nDefaultLanguage ];
result = result .. ' — ' .. letter .. '&nbsp;' .. toString( context, src.volume, options_commas ) .. '.';
end
 
if ( src.issue ) then
local letter = i18nIssue[ context.lang ] or i18nIssue[ i18nDefaultLanguage ];
result = result .. ' — №&nbsp;' .. toString(src.issue, options_commas ) .. '.';
result = result .. ' — ' .. letter .. '&nbsp;' .. toString( context, src.issue, options_commas ) .. '.';
end
if ( src.pagepages ) then
local letter = i18nPagei18nPages[ srccontext.lang ] or i18nPagei18nPages[ i18nDefaultLanguage ];
result = result .. ' — ' .. letter .. '&nbsp;' .. toString( context, src.pagepages, options_commas ) .. '.';
end
end
 
function getSinglegetPeopleAsWikitext( context, value, options )
if ( not value ) then
return;
end
if ( type( value ) == 'string' ) then
return value;
elseif ( type( value ) == 'table' ) then
if ( value.id ) then
return value.id;
end
 
for i, tableValue in pairs( value ) do
return getSingle( tableValue );
end
end
 
return '(unknown)';
end
 
function toString( value, options )
if ( type( value ) == 'string' ) then
return options.format( value );
Мухъ 230 ⟶ 316 :
-- this is link
if ( options.preferids ) then
return options.format( value.id );
else
if ( options.nolinks ) then
return options.formatgetPersonNameAsLabel( context, value.labelid, or mw.wikibasevalue.label(, value.id ) or '\'\'(untranslated title)\'\''options );
else
return options.formatgetPersonNameAsWikitext( renderLink(context, value.id, value.label, )options );
end
end
Мухъ 242 ⟶ 328 :
local resultList = {};
for i, tableValue in pairs( value ) do
table.insert(local resultList,nextWikitext toString= getPeopleAsWikitext( context, tableValue, options ) );
if ( not isEmpty( nextWikitext ) ) then
table.insert( resultList, nextWikitext );
if ( #resultList == 4 ) then
-- even 4 is too much, but we preserve 4th to mark that "it's more than 3"
break;
end
end
end
 
local resultWikitext = '';
return mw.text.listToText( resultList, options.separator, options.conjunction);
for i, wikitext in pairs( resultList ) do
else
if ( i == 4 ) then
return options.format( '(unknown type)' );
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( '(unknown type)' );
end
 
function renderLinkgetPersonNameAsWikitext( context, entityId, textcustomLabel, options )
local personName = getPersonNameAsLabel( context, entityId, customLabel, options);
if ( not entityId ) then
if ( personName == nil ) then
error("entityId is not specified");
return nil;
end
 
local actualText = text or mw.wikibase.label( entityId ) or '\'\'(untranslated)\'\'';
local link = mw.wikibase.sitelinkgetElementLink( context, entityId, ) or ( ':d:' .. entityIdnil );
return '[[' ..wrapInUrl( link, .. '|' .. actualText ..personName ']]');
end
 
function getPersonNameAsLabel( context, entityId, providedLabel, options )
-- Expand special types of references when additional data could be found in OTHER entity properties
-- would custom label provided we don't need to check entity at all
function expandSpecials( currentEntity, reference, data )
if ( not isEmpty( providedLabel ) ) then
if ( reference.snaks.P248
mw.log( 'Custom label provided for ' .. entityId );
and reference.snaks.P248[1]
return options.format( providedLabel );
and reference.snaks.P248[1].datavalue
end
and reference.snaks.P248[1].datavalue.value["numeric-id"]) then
local sourceId = "Q" .. reference.snaks.P248[1].datavalue.value["numeric-id"];
 
local entity = getEntity( context, entityId );
-- Gemeinsame Normdatei -- specified by P227
if ( not entity ) then return '\'\'(entity ' .. entityId .. ' is missing)\'\'' end;
if ( sourceId == 'Q36578' ) then
appendMainSnaks( currentEntity, 'P227', data, 'title', { format = function( gnd ) return 'Record #' .. gnd; end } );
appendMainSnaks( currentEntity, 'P227', data, 'url', { format = function( gnd ) return 'http://d-nb.info/gnd/' .. gnd .. '/'; end } );
end
-- BNF -- specified by P268
if ( sourceId == 'Q15222191' ) then
appendMainSnaks( currentEntity, 'P268', data, 'title', { format = function( id ) return 'Record #' .. id; end } );
appendMainSnaks( currentEntity, 'P268', data, 'url', { format = function( id ) return 'http://catalogue.bnf.fr/ark:/12148/cb' .. id; end } );
expandSpecialsQualifiers( currentEntity, 'P268', data );
end
 
local personName = nil;
-- Find a Grave -- specified by P535
-- support only labels so far
if ( sourceId == 'Q63056' ) then
if ( entity.labels[ context.lang ] ) then
appendMainSnaks( currentEntity, 'P535', data, 'url', { format = function( id ) return 'http://www.findagrave.com/cgi-bin/fg.cgi?page=gr&GRid=' .. id; end } );
personName = entity.labels[ context.lang ].value;
expandSpecialsQualifiers( currentEntity, 'P535', data );
mw.log('Got person name of ' .. entityId .. ' from label: «' .. personName .. '»' )
end
end
 
if ( not isInstanceOf( entity, 'Q5' ) ) then
-- Gran Enciclopèdia Catalana -- specified by P1296
mw.log( 'Entity ' .. entityId .. ' is not a person' );
if ( sourceId == 'Q2664168' ) then
return personName;
appendMainSnaks( currentEntity, 'P1296', data, 'url', { format = function( id ) return 'http://www.enciclopedia.cat/enciclop%C3%A8dies/gran-enciclop%C3%A8dia-catalana/EC-GEC-' .. id .. '.xml'; end } );
end
expandSpecialsQualifiers( currentEntity, 'P1296', data );
end
 
if ( isEmpty( personName ) ) then
-- Encyclopædia Britannica online -- specified by P1417
return '\'\'(not translated to ' .. context.lang .. ')\'\'';
if ( sourceId == 'Q5375741' ) then
else
appendMainSnaks( currentEntity, 'P1417', data, 'url', { format = function( id ) return 'http://global.britannica.com/' .. id; end } );
return options.format( personName );
expandSpecialsQualifiers( currentEntity, 'P1417', data );
end
end
 
function personNameToAuthorName( fullName )
-- Electronic Jewish Encyclopedia (Elektronnaja Evrejskaja Entsiklopedia) -- specified by P1438
if ( sourceIdnot == 'Q1967250'fullName ) then return fullName; end
appendMainSnaks( currentEntity, 'P1438', data, 'url', { format = function( id ) return 'http://www.eleven.co.il/article/' .. id; end } );
expandSpecialsQualifiers( currentEntity, 'P1438', data );
end
 
local f, i, o = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)\,%s(%a[%a\-]*)%s(%a[%a\-]*)%s*$' );
-- sports-reference.com -- specified by P1447
if ( sourceId == 'Q18002875'f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Fa, I. O.» match' );
appendMainSnaks( currentEntity, 'P1447', data, 'url', { format = function( id ) return 'http://www.sports-reference.com/olympics/athletes/' .. id .. '.html'; end } );
return f .. '&nbsp;'
expandSpecialsQualifiers( currentEntity, 'P1447', data );
.. mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;'
end
.. 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*$' );
-- do we have appropriate record in P1343 ?
if ( f1 ) then
local claims = findClaimsByValue( currentEntity, 'P1343', sourceId );
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Fa Fa, I» match' );
if ( claims and #claims ~= 0 ) then
return f1 .. '&nbsp;' .. f2 .. '&nbsp;'
appendQualifiers( claims, 'P958', data, 'part', {} );
appendQualifiers.. mw.ustring.sub( claimsi, 'P854'1, data,1 ) .. 'url.', {} );
appendQualifiers( claims, 'P357', data, 'title', {} );
appendQualifiers( claims, 'P478', data, 'volume', {} );
end
end
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a)\.%s(%a)\.%s(%a[%a\-]+)%s*$');
function expandSpecialsQualifiers( entity, propertyId, result )
if ( entity.claims and entity.claims[propertyId]f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «I. O. Fa» match' );
local claims = entity.claims[propertyId];
return f .. '&nbsp;' .. i .. '.&nbsp;' .. o .. '.';
appendQualifiers( claims, 'P958', result, 'part', {} );
appendQualifiers( claims, 'P854', result, 'url', {} );
appendQualifiers( claims, 'P357', result, 'title', {} );
appendQualifiers( claims, 'P478', result, 'volume', {} );
end
end
 
local i1, i2, i3, f = mw.ustring.match( fullName, '^%s*(%a)\.%s(%a)\.%s(%a)\.%s(%a[%a\-]+)%s*$');
function findClaimsByValue( entity, propertyId, value )
if ( f ) then
local result = {};
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «I. O. ?. Fa» match' );
if ( entity and entity.claims and entity.claims[propertyId] ) then
return f .. '&nbsp;' .. i1 .. '.&nbsp;' .. i2 .. '.&nbsp;' .. i3 .. '.';
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
 
-- Joel J. P. C. Rodrigues
function appendMainSnaks( entity, propertyId, result, property, options )
local i1, i2, i3, i4, f = mw.ustring.match( fullName, '^%s*(%a)[%a\-]+%s(%a)\.%s(%a)\.%s(%a)\.%s(%a[%a\-]+)%s*$');
if ( entity.claims and entity.claims[propertyId] ) then
if ( f ) then
for i, claim in pairs( entity.claims[propertyId] ) do
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «I. O. ?. Fa» match' );
if ( claim.mainsnak and claim.mainsnak.datavalue ) then
return f .. '&nbsp;' .. i1 .. '.&nbsp;' .. i2 .. '.&nbsp;' .. i3 .. '.&nbsp;' .. i4 .. '.';
appendImpl( claim.mainsnak.datavalue, result, property, options );
end
end
end
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)%s(%a)\.%s(%a[%a\-]*)%s*$');
function appendSnaks( allSnaks, snakPropertyId, result, property, options )
if ( allSnaks and allSnaks[ snakPropertyId ]f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Im O. Fa» match' );
for k, snak in pairs( allSnaks[ snakPropertyId ] ) do
return f .. '&nbsp;' .. mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;' .. o .. '.';
if ( snak and snak.datavalue ) then
appendImpl( snak.datavalue, result, property, options );
end
end
end
end
 
local i1, i2, i3, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)%s(%a)\.%s(%a)\.%s(%a[%a\-]*)%s*$');
function appendQualifiers( claims, qualifierPropertyId, result, property, options )
if ( f ) then
for i, claim in pairs( claims ) do
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Im I. I. Fa» match' );
if ( claim.qualifiers and claim.qualifiers[ qualifierPropertyId ] ) then
return f .. '&nbsp;' .. mw.ustring.sub( i1, 1, 1 ) .. '.&nbsp;' .. i2 .. '.&nbsp;' .. i3 .. '.';
for k, qualifier in pairs( claim.qualifiers[ qualifierPropertyId ] ) do
if ( qualifier and qualifier.datavalue ) then
appendImpl( qualifier.datavalue, result, property, options );
end
end
end
end
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)%s(%a[%a\-]*)%s(%a[%a\-]*)%s*$');
function appendImpl( datavalue, result, property, options )
if ( datavalue.type == 'string'f ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «Im Ot Fa» match' );
local value = datavalue.value;
return f .. '&nbsp;' .. mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;' .. mw.ustring.sub( o, 1, 1 ) .. '.';
if ( options.format ) then
end
value = options.format( value );
end
if ( not result[property] ) then
result[property] = {};
elseif ( type( result[property] ) == 'string' or ( type( result[property] ) == 'table' and type( result[property].id ) == 'string' ) ) then
result[property] = { result[property] };
end
table.insert( result[property], value);
elseif ( datavalue.type == 'wikibase-entityid' ) then
local value = datavalue.value;
if ( not result[property] ) then
result[property] = {};
elseif ( type( result[property] ) == 'string' or ( type( result[property] ) == 'table' and type( result[property].id ) == 'string' ) ) then
result[property] = { result[property] };
end
table.insert( result[property], { id = 'Q' .. value["numeric-id"] });
elseif datavalue.type == 'time' then
local value = datavalue.value;
if ( options.format ) then
value = options.format( value );
end
if ( not result[property] ) then
result[property] = {};
elseif ( type( result[property] ) == 'string' or ( type( result[property] ) == 'table' and type( result[property].id ) == 'string' ) ) then
result[property] = { result[property] };
end
table.insert( result[property], tostring( value.time ));
end
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]+)%s(%a[%a\-]+)%s+оглы%s+(%a[%a\-]+)%s*$');
function expandPublication( data )
if ( f ) then
local publication = data.publication;
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 i1, i2, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]+)%s(%a[%a\-]+)%s+de%s+(%a[%a\-]+)%s*$');
-- use only first one
if ( f ) then
if ( type( publication ) == 'table' and publication[1] and publication[1].id ) then
mw.log( 'personNameToAuthorName: «' .. fullName .. '»: have «I1 I2 de Fa» match' );
data.publication = publication[1];
return f .. '&nbsp;' .. mw.ustring.sub( i1, 1, 1 ) .. '.&nbsp;' .. mw.ustring.sub( i2, 1, 1 ) .. '.';
publication = data.publication;
end
 
local i, f = mw.ustring.match( fullName, '^%s*(%a[%a\-\']+)%s(%a[%a\-\']+)%s*$');
if ( publication and publication.id ) then
if ( f ) then
populateSourceData( data, publication.id );
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
 
function loadSafepersonNameToResponsibleName( entityIdfullName )
if ( entityIdnot == nilfullName ) then return fullName; end
 
error('entityId to load is not specified');
local f, i, o = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)\,%s(%a[%a\-]*)%s(%a[%a\-]*)%s*$' );
if ( f ) then
mw.log( 'personNameToResponsibleName: «' .. fullName .. '»: have «Fa, I. O.» match' );
return mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;' .. mw.ustring.sub( o, 1, 1 ) .. '.&nbsp;' .. f;
end
 
local status, result = pcall( function() return mw.loadData( 'Module:Source/' .. entityId ) end );
local f1, f2, i = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)%s(%a[%a\-]*)\,%s(%a[%a\-]*)%s*$' );
if ( status == true ) then
if ( f1 ) then
return true, result;
mw.log( 'personNameToResponsibleName: «' .. fullName .. '»: have «Fa Fa, I» match' );
return mw.ustring.sub( i, 1, 1 ) .. '&nbsp;' .. f1 .. '&nbsp;' .. f2;
end
return false, nil;
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a)\.%s(%a)\.%s(%a[%a\-]+)%s*$');
function populateSourceData( data, sourceId )
if ( f ) then
local loaded, sourceData = loadSafe( sourceId );
mw.log( 'v: «' .. fullName .. '»: have «I. O. Fa» match' );
if ( loaded and sourceData ) then
return i .. '.&nbsp;' .. o .. '.&nbsp;' .. f;
populateSourceDataImpl( data, sourceData );
end
end
 
local i1, i2, i3, f = mw.ustring.match( fullName, '^%s*(%a)\.%s(%a)\.%s(%a)\.%s(%a[%a\-]+)%s*$');
function populateSourceDataImpl( data, sourceData )
if ( f ) then
for key, value in pairs( sourceData ) do
mw.log( 'personNameToResponsibleName: «' .. fullName .. '»: have «I. O. ?. Fa» match' );
if ( not data[key] and key ~= 'title' ) then
return i1 .. '.&nbsp;' .. i2 .. '.&nbsp;' .. i3 .. '.&nbsp;' .. f;
data[key] = value;
end
end
 
-- Joel J. P. C. Rodrigues
-- if we already have title, than it would be the current one, otherwise move it to publication
local i1, i2, i3, i4, f = mw.ustring.match( fullName, '^%s*(%a)[%a\-]+%s(%a)\.%s(%a)\.%s(%a)\.%s(%a[%a\-]+)%s*$');
if ( sourceData.title ) then
if ( not data.titlef ) then
mw.log( 'personNameToResponsibleName: «' .. fullName .. '»: have «I. O. ?. Fa» match' );
data.title = sourceData.title;
return i1 .. '.&nbsp;' .. i2 .. '.&nbsp;' .. i3 .. '.&nbsp;' .. i4 .. '.&nbsp;' .. f;
else
if ( not data.publication ) then
data.publication = sourceData.title;
end
end
end
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)%s(%a)\.%s(%a[%a\-]*)%s*$');
function updateWithRef( reference, src )
if ( f ) then
-- specified
mw.log( 'personNameToResponsibleName: «' .. fullName .. '»: have «Im O. Fa» match' );
if ( reference.snaks.O662 ) then
return mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;' .. o .. '.&nbsp;' .. f;
local cid = reference.snaks.P662[1].datavalue.value;
src.code = src.code .. '-cid:' .. cid;
src.title = 'Compound Summary for: CID ' .. cid;
src.url = 'http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=' .. cid;
src.publication = { id = 'Q278487', label = 'PubChem' };
end
 
local i, o, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]*)%s(%a[%a\-]*)%s(%a[%a\-]*)%s*$');
appendSnaks( reference.snaks, 'P50', src, 'author', {} );
if ( f ) then
appendSnaks( reference.snaks, 'P364', src, 'lang', {} );
mw.log( 'personNameToResponsibleName: «' .. fullName .. '»: have «Im Ot Fa» match' );
appendSnaks( reference.snaks, 'P958', src, 'part', {} ); -- part
return mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;' .. mw.ustring.sub( o, 1, 1 ) .. '.&nbsp;' .. f;
appendSnaks( reference.snaks, 'P357', src, 'title', {} ); -- title
end
appendSnaks( reference.snaks, 'P854', src, 'url', {} );
 
appendSnaks( reference.snaks, 'P1433', src, 'publication', {} );
local i, o, f = mw.ustring.match( fullName, '^%s*(%a[%a\-]+)%s(%a[%a\-]+)%s+оглы%s+(%a[%a\-]+)%s*$');
appendSnaks( reference.snaks, 'P123', src, 'publisher', {} );
if ( f ) then
appendSnaks( reference.snaks, 'P304', src, 'page', {} );
mw.log( 'personNameToResponsibleName: «' .. fullName .. '»: have «Im Ot оглы Fa» match' );
appendSnaks( reference.snaks, 'P478', src, 'volume', {} );
return mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;' .. mw.ustring.sub( o, 1, 1 ) .. '.&nbsp;' .. f;
appendSnaks( reference.snaks, 'P577', src, 'date', {} );
end
appendSnaks( reference.snaks, 'P813', src, 'accessdate', {} );
 
return src;
local i, f = mw.ustring.match( fullName, '^%s*(%a[%a\-\']+)%s(%a[%a\-\']+)%s*$');
if ( f ) then
mw.log( 'personNameToResponsibleName: «' .. fullName .. '»: have «Im Fa» match' );
return mw.ustring.sub( i, 1, 1 ) .. '.&nbsp;' .. f;
end
 
mw.log( 'Unmatched any pattern: «' .. fullName .. '»' );
return fullName;
end
 
function p.renderSource( frame )
p.currentFrame = frame;
 
local arg = frame.args[1];
local refAnchor = frame.args['ref'];
return p.renderSourceImpl( arg );
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
 
function p.renderSourceImpl( entityId, args )
local valueargs = args or {};
 
value["numeric-id"] = string.sub( entityId , 2);
local snaksnaks = { datavalue = { value =value } };
snaks.P248 = { toWikibaseEntityIdSnak( 'P248', entityId ) };
local properties = {};
copyArgsToSnaks( args, snaks );
properties[1] = snak;
 
return renderReferenceImpl( {}, { snaks = { P248 = properties } } ).text;
local rendered = renderReferenceImpl( mw.wikibase.getEntity(), { snaks = snaks }, args.refAnchor, args.refAnchorYear );
if ( rendered ) then return rendered.text end;
end
 
function p.renderReference( frame, currentEntity, reference )
p.currentFrame = frame;
 
-- template call
if ( frame and not currentEntity and not reference ) then
local valueargs = {}frame.args;
value["numeric-id"]if = string.sub( #frame.args[1] ,== 0 2); then
args = frame:getParent().args;
local snak = { datavalue = { value =value } };
end
local properties = {};
 
properties[1] = snak;
local snaks = {};
 
currentEntity = mw.wikibase.getEntityObject();
if ( args[1] ) then
reference = { snaks = { P248 = properties } };
snaks.P248 = { toWikibaseEntityIdSnak( "P248", args[1] ) };
end
copyArgsToSnaks( args, snaks );
 
currentEntity = mw.wikibase.getEntity();
reference = { snaks = snaks };
end
 
Мухъ 526 ⟶ 588 :
 
local result;
local code = rendered.code or mw.text.encode( rendered.text );
result = frame:extensionTag( 'ref', rendered.text, {name = code} ) .. '[[КатегорияCategory:Википедия:Статьи с источниками из Викиданных]]';
 
if ( not rendered.found ) then
result = result .. '[[Категория:Википедия:Статьи с неоформленными источниками из Викиданных]]';
end
 
return result;
end
 
function renderReferenceImpl( currentEntity, reference, refAnchor, refAnchorYear )
if ( not reference.snaks ) then
return nil;
end
 
-- контекст, содержит также кеш элементов
local context = {
cache = {},
}
 
-- данные в простом формате, согласованном с модулями формирования библиографического описания
local data = {};
 
local entityId, found, sourceData;
-- забрать данные из reference
if ( reference.snaks.P248 ) then
populateDataFromClaims( context, nil, reference.snaks, data )
entityId = "Q" .. reference.snaks.P248[1].datavalue.value["numeric-id"];
 
found, sourceData = loadSafe( entityId );
-- update ref name with ref-specific properties
data.code = entityId;
if ( data.entityIdcode =) entityId;then
if ( data.part ) then data.code = data.code .. '-' .. getSingle( data.part ) end
else
if ( data.pages ) then data.code = data.code .. '-' .. getSingle( data.pages ) end
found = true;
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
 
updateWithRefexpandSpecials( context, currentEntity, reference, data );
 
expandSpecials( currentEntity, reference, data );
local sourceEntity = nil;
if ( entityId ) then
if ( found and sourceDatadata.sourceId ) then
sourceEntity = getEntity( context, data.sourceId );
populateSourceDataImpl( data, sourceData );
if ( sourceEntity ) then
else
populateSourceDataImpl( context, sourceEntity, data );
if ( data.title ) then
data.publication = data.publication or { id = entityId, label = mw.wikibase.label( entityId ) };
else
data.title = { id = entityId, label = mw.wikibase.label( entityId ) };
end
end
end
 
expandPublication( data );
if ( data.publication ) then
expandPublication( context, sourceEntity, data );
end
 
expandBookSeries( context, data );
 
if ( next( data ) == nil ) then
return nil;
end
 
local rendered;
if ( p.short ) then
local toStore = p.deepcopy( data );
if (not p.list ) then
p.list = {};
end
p.list[toStore.code] = toStore;
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
end
return nil;
end
 
if ( mw.ustring.len( rendered.text ) == 0refAnchor ) then
local anchorValue = 'CITEREF' .. refAnchor .. ( coalesce( refAnchorYear, data.year ) or '' );
return nil;
rendered.text = '<span class="citation" id="' .. mw.uri.anchorEncode( anchorValue ) .. '">' .. rendered.text .. '</span>';
end
end
 
rendered.found = found;
return rendered;
end