Модуль:Wikidata/Countries

Для документации этого модуля может быть создана страница Модуль:Wikidata/Countries/doc

local moduleDates = require( "Module:Dates" );local p = {}local function calculateEndDateTimestamp( context, options, statement )if (not context) then error('context not specified') end;if (not options) then error('options not specified') end;if (not options.entity) then error('options.entity missing') end;if (not statement) then error('statement not specified') end;if ( statement.qualifiers and statement.qualifiers.P582 ) thenfor i, qualifier in ipairs(statement.qualifiers.P582 ) dolocal parsedTime = context.parseTimeFromSnak( qualifier );if ( parsedTime ) thenreturn parsedTime;endendend-- check death day... do we have it at all?for h, propertyId in pairs( { "P570", "P577", "P571" } ) dolocal dateClaims = context.selectClaims( options, propertyId );if ( dateClaims ) thenfor i, statement in ipairs( dateClaims ) dolocal parsedTime = context.parseTimeFromSnak( statement.mainsnak );if ( parsedTime ) thenreturn parsedTime;endendendend-- TODO: check other "end" properties-- no death dayreturn os.time();endfunction getFlag( context, entityId, actualDate )local flags = mw.loadData('Module:Wikidata:Dictionary/Flags');local countryFlags = flags[ entityId ];local goodFlag = nil;if ( countryFlags ) thenlocal ordered_dates = {}for flagBeginDate in pairs(countryFlags) dotable.insert(ordered_dates, flagBeginDate)endtable.sort(ordered_dates)for i = 1, #ordered_dates dolocal flagBeginDate, flag = ordered_dates[i], countryFlags[ ordered_dates[i] ];if ( actualDate >= flagBeginDate ) thengoodFlag = flag;endendendif ( goodFlag ) thenreturn '[[File:' .. goodFlag .. '|20x15px|border]]';endreturn nil;endfunction p.formatCountryClaimWithFlag( context, options, statement )if (not context) then error('context not specified') end;if (not options) then error('options not specified') end;if (not options.entity) then error('options.entity is missing') end;if (not statement) then error('statement not specified') end;local flag = nil;if ( statement.mainsnak and statement.mainsnak.datavalue and statement.mainsnak.datavalue.value and statement.mainsnak.datavalue.value["numeric-id"] ) thenlocal endDateTimestamp = calculateEndDateTimestamp( context, options, statement ) * 1000;flag = getFlag( context, 'Q' .. statement.mainsnak.datavalue.value["numeric-id"], endDateTimestamp );endif ( flag ) thenreturn flag .. '&nbsp;<span class="country-name">' .. context.formatStatementDefault( context, options, statement ) .. '</span>';endreturn '<span class="country-name">' .. context.formatStatementDefault( context, options, statement ) .. '</span>';endreturn p;