Module:Pornbasedata: Difference between revisions
Content deleted Content added
PeaceDeadC (talk | contribs) Created page with "-- settings, may differ from project to project local fileDefaultSize = '267x400px'; local outputReferences = true; -- sources that shall be omitted if any preffered sources..." |
PeaceDeadC (talk | contribs) No edit summary |
||
Line 1:
local fileDefaultSize = '267x400px';
local outputReferences = true;
local deprecatedSources = {
Q255 = true,
Q256 = true,
Q257 = true,
};
local preferredSources = {
Q258 = true,
Q259 = true,
};
local moduleSources = require( 'Module:Sources' )
local WDS = require( 'Module:PornBaseDataSelectors' );
local contentLanguageCode = mw.getContentLanguage():getCode();
Line 97 ⟶ 93:
end) (str);
local oh,om = ( function(str)
if str:sub(-1)=="Z" then return 0,0 end;
local pattern = "([-+])(%d%d):?(%d?%d?)$";
local sign, oh, om = mw.ustring.match( str, pattern);
Line 154 ⟶ 149:
end
local function toBoolean( valueToParse, defaultValue )
if ( valueToParse ~= nil ) then
Line 170 ⟶ 159:
end
local function getEntityFromId( id )
local entity;
Line 190 ⟶ 172:
end
local function throwError( key )
error( getConfig( 'errors', key ) );
end
local function getEntityIdFromValue( value )
local prefix = ''
Line 218 ⟶ 188:
end
local function getUserFunction( options, prefix, defaultFunction )
if options[ prefix .. '-module' ] or options[ prefix .. '-function' ] then
if not options[ prefix .. '-module' ] or not options[ prefix .. '-function' ] then
throwError( 'unknown-' .. prefix .. '-module' );
end
local formatter = require( 'Module:' .. options[ prefix .. '-module' ] );
if formatter == nil then
Line 242 ⟶ 207:
end
local function selectClaims( context, options, propertySelector )
if ( not context ) then error( 'context not specified' ); end;
Line 265 ⟶ 229:
end
local function getPropertyInBoundaries( context, entityId, boundaries, propertyIds, selectors )
if (type(entityId) ~= 'string') then error('type of entityId argument expected string, but was ' .. type(entityId)); end
Line 311 ⟶ 269:
end
function p.getTimeBoundariesFromQualifier( frame, context, statement, qualifierId )
local left = nil;
local right = nil;
Line 334 ⟶ 288:
end
function p.getTimeBoundariesFromQualifiers( frame, context, statement, qualifierIds )
if not qualifierIds then
Line 353 ⟶ 304:
local CONTENT_LANGUAGE_CODE = mw.language.getContentLanguage():getCode();
local getLabelWithLang_DEFAULT_PROPERTIES = { "
local getLabelWithLang_DEFAULT_SELECTORS = {
'
'
'
'P79[language:' .. CONTENT_LANGUAGE_CODE .. ']'
};
function getLabelWithLang( context, options, entityId, boundaries, propertyIds, selectors )
if (type(entityId) ~= 'string') then error('type of entityId argument expected string, but was ' .. type(entityId)); end
Line 374 ⟶ 320:
local langCode = CONTENT_LANGUAGE_CODE;
local label = nil;
if ( options.text and options.text ~= '' ) then
Line 384 ⟶ 329:
end
local results = getPropertyInBoundaries( context, entityId, boundaries, propertyIds, selectors );
Line 411 ⟶ 355:
end
local function formatProperty( options )
local entity = getEntityFromId( options.entityId )
if not entity then
return
end
if (entity.claims == nil) then
return ''
end
options.frame = g_frame;
options.entity = entity;
Line 443 ⟶ 376:
end
local context = {
entity = options.entity,
Line 456 ⟶ 388:
options.entity = entity;
newOptions.entity = entity;
newOptions.frame = options.frame;
return newOptions;
Line 486 ⟶ 418:
end
function formatPropertyDefault(
local formattedClaims = {}
if (formattedStatement and formattedStatement ~= '') then
formattedStatement = '<span class="wikidata-claim" data-wikidata-property-id="' .. string.upper(options.property) .. '" data-wikidata-claim-id="' .. claim.id .. '">' .. formattedStatement .. '</span>'
table.insert(formattedClaims, formattedStatement)
end
local processedClaims = {}
local totalClaims = #formattedClaims
for index, claim in ipairs(formattedClaims) do
local processedClaim = claim
if index < totalClaims then
processedClaim = string.gsub(processedClaim, " model%]", "]")
end
table.insert(processedClaims, processedClaim)
local out = mw.text.listToText(processedClaims, options.separator, options.conjunction)
if out ~= '' then
if options.before then
out = options.before .. out
end
if options.after then
out = out .. options.after
end
end
return out
end
function formatStatement( context, options, statement )
if ( not statement ) then
Line 563 ⟶ 495:
end
function formatStatementDefault( context, options, statement )
if (not context) then error('context is not specified') end;
Line 608 ⟶ 532:
end
function formatSnak( context, options, snak, circumstances )
circumstances = circumstances or {};
Line 658 ⟶ 575:
end
function formatGlobeCoordinate( value, options )
if options['subvalue'] == 'latitude' then
return value['latitude']
elseif options['subvalue'] == 'longitude' then
return value['longitude']
elseif options['nocoord'] and options['nocoord'] ~= '' then
return ''
else
coord_mod = require( "Module:Coordinates" );
Line 700 ⟶ 605:
end
function formatCommonsMedia( value, options )
local image = value;
Line 720 ⟶ 619:
if not string.find( value, '[%[%]%{%}]' ) and not string.find( value, 'imagemap' ) then
image = '[[File:' .. value .. '|frameless';
if options[ 'border' ] and options[ 'border' ] ~= '' then
Line 730 ⟶ 627:
if size and size ~= '' then
if not string.match( size, 'px$' )
and not string.match( size, 'пкс$' )
then
size = size .. 'px'
Line 764 ⟶ 661:
end
function formatMath( value, options )
return options.frame:extensionTag{ name = 'math', content = value };
end
local function formatExternalId( value, options )
local formatter = options.formatter;
Line 830 ⟶ 714:
end
local function formatQuantity( value, options )
local amount = string.gsub( value['amount'], '^%+', '' );
local lang = mw.language.getContentLanguage();
Line 843 ⟶ 720:
local function formatNum( number, sigfig )
sigfig = sigfig or 12
local mult = 10^sigfig;
number = math.floor( number * mult + 0.5 ) / mult;
Line 852 ⟶ 729:
if value.upperBound then
local diff = tonumber( value.upperBound ) - tonumber( amount )
if diff > 0 then
local integer, dot, decimals, expstr = value.upperBound:match( '^+?-?(%d*)(%.?)(%d*)(.*)' )
local prec
Line 862 ⟶ 738:
end
bound = formatNum( diff, prec )
if string.match( bound, 'E%-(%d+)' ) then
digits = tonumber( string.match( bound, 'E%-(%d+)' ) ) - 2
bound = formatNum( diff * 10 ^ digits, prec )
Line 887 ⟶ 763:
conversionToSIunit = string.gsub( unitEntity.claims.P2370[1].mainsnak.datavalue.value.amount, '^%+', '' );
if math.floor( math.log10( conversionToSIunit )) ~= math.log10( conversionToSIunit ) then
outValue = tonumber( amount ) * conversionToSIunit
if ( outValue > 0 ) then
local integer, dot, decimals, expstr = amount:match( '^(%d*)(%.?)(%d*)(.*)' )
local prec
Line 928 ⟶ 802:
local DATATYPE_CACHE = {}
local function getPropertyDatatype( propertyId )
if not propertyId or not string.match( propertyId, '^P%d+$' ) then
Line 982 ⟶ 850:
local function getDefaultValueFunction( datavalue, datatype )
if datavalue.type == 'wikibase-entityid' then
return function( context, options, value ) return formatEntityId( context, options, getEntityIdFromValue( value ) ) end;
elseif datavalue.type == 'string' then
if datatype and datatype == 'commonsMedia' then
return function( context, options, value )
if options.caption and options.caption ~= '' then
Line 1,024 ⟶ 888:
end;
elseif datatype and datatype == 'external-id' then
return function( context, options, value )
return formatExternalId( value, options )
end
elseif datatype and datatype == 'math' then
return function( context, options, value )
return formatMath( value, options )
end
elseif datatype and datatype == 'url' then
return function( context, options, value )
local moduleUrl = require( 'Module:URL' )
Line 1,046 ⟶ 907:
return function( context, options, value ) return value end;
elseif datavalue.type == 'monolingualtext' then
return function( context, options, value )
if ( options.monolingualLangTemplate == 'lang' ) then
Line 1,060 ⟶ 920:
end;
elseif datavalue.type == 'globecoordinate' then
return function( context, options, value ) return formatGlobeCoordinate( value, options ) end;
elseif datavalue.type == 'quantity' then
Line 1,070 ⟶ 929:
end;
else
throwError( 'unknown-datavalue-type' )
end
end
function formatDatavalue( context, options, datavalue, datatype )
if ( not context ) then error( 'context not specified' ); end;
Line 1,088 ⟶ 939:
if ( not datavalue.value ) then error( 'datavalue.value is missng' ); end;
context.formatValueDefault = getDefaultValueFunction( datavalue, datatype );
local functionToCall = getUserFunction( options, 'value', context.formatValueDefault );
Line 1,097 ⟶ 946:
local DEFAULT_BOUNDARIES = { os.time() * 1000, os.time() * 1000};
function formatEntityId(context, options, entityId)
local boundaries = nil
if options.qualifiers then
boundaries = p.getTimeBoundariesFromQualifiers(frame, context, { qualifiers = options.qualifiers })
end
if not boundaries then
boundaries = DEFAULT_BOUNDARIES
end
local label, labelLanguageCode = getLabelWithLang(context, options, entityId, boundaries)
local category = p.extractCategory(context, options, { id = entityId })
local link = mw.wikibase.sitelink(entityId)
if link then
if mw.ustring.match(link, '^' .. mw.site.namespaces[14].name .. ':') then
link = ':' .. link
end
if label and not options.rawArticle then
local a = link == label and ('[[' .. link .. ']]') or '[[' .. link .. '|' .. label .. ']]'
if contentLanguageCode ~= labelLanguageCode then
return a .. category
else
return a .. category
end
else
return '[[' .. link .. ']]' .. category
end
end
if label then
if title and not title.exists and options.frame then
local moduleRedLink = require('Module:Pornbasedata/redLink')
local rawLabel = mw.wikibase.label(entityId) or label
local redLink = moduleRedLink.formatRedLinkWithInfobox(rawLabel, label, entityId)
return redLink .. category
end
local sup = ''
if not options.format or options.format ~= 'text' and entityId ~= 'Q267' and entityId ~= 'Q5' then
sup = ''
end
return '<span class="iw" data-title="' .. label .. '">' .. label .. sup .. '</span>' .. category
end
return '[[:d:' .. entityId .. '|' .. entityId .. ']]<span style="border-bottom: 1px dotted; cursor: help; white-space: nowrap" title="В PBD нет русской подписи к элементу. Вы можете помочь, указав русский вариант подписи.">?</span>' .. getCategoryByCode('links-to-entities-with-missing-label') .. category
end
function p.extractCategory( context, options, value )
if ( not options.category ) then
Line 1,195 ⟶ 1,023:
return '';
end
function p.formatStatements( frame )
return p.formatProperty( frame );
end
function getPropertyParams( propertyId, datatype, params )
local config = getConfig();
local propertyParams = {};
if params then
for key, value in pairs( params ) do
Line 1,225 ⟶ 1,041:
end
if config[ 'properties' ] and config[ 'properties' ][ propertyId ] then
for key, value in pairs( config[ 'properties' ][ propertyId ] ) do
Line 1,234 ⟶ 1,049:
end
if propertyParams[ 'preset' ] and config[ 'presets' ] and
config[ 'presets' ][ propertyParams[ 'preset' ] ]
Line 1,250 ⟶ 1,064:
end
if datatype and config[ 'datatypes' ] and config[ 'datatypes' ][ datatype ] then
for key, value in pairs( config[ 'datatypes' ][ datatype ] ) do
Line 1,259 ⟶ 1,072:
end
if config[ 'global' ] then
for key, value in pairs( config[ 'global' ] ) do
Line 1,274 ⟶ 1,086:
local args = frame.args
if not args.property then
throwError( 'property-param-not-provided' )
Line 1,291 ⟶ 1,102:
local datatype = args.datatype;
p_frame = frame
while p_frame do
Line 1,307 ⟶ 1,117:
args.references = toBoolean( args.references, true );
if args.value and args.value ~= '' then
if args.value == '-' then
return ''
Line 1,315 ⟶ 1,123:
local value = args.value
if args.plain then
return value
end
local wrapperExtraArgs = ''
if args['value-module'] and args['value-function'] and not string.find( value, '[%[%]%{%}]' ) then
Line 1,340 ⟶ 1,146:
end
if string.match( propertyId, '^P%d+$' ) then
value = mw.text.trim( value )
if ( propertyId ~= 'P166'
and string.match( value, '<t[dr][ >]' )
Line 1,351 ⟶ 1,155:
value = value .. getCategoryByCode( 'value-contains-table' )
else
if ( string.match( value, '\n' )
or string.match( value, '<t[dhr][ >]' )
Line 1,366 ⟶ 1,169:
end
if not args.nocat then
local pageTitle = mw.title.getCurrentTitle();
Line 1,377 ⟶ 1,179:
end
if ( args.plain ) then
local callArgs = { propertyId };
if args.entityId then
Line 1,386 ⟶ 1,188:
g_frame = frame
return formatProperty( args )
end
function formatRefs( context, options, statement )
if ( not context ) then error( 'context not specified' ); end;
Line 1,418 ⟶ 1,209:
for _, reference in pairs( statement.references ) do
if ( reference.snaks
and reference.snaks.
and reference.snaks.
and reference.snaks.
and reference.snaks.
local entityId = reference.snaks.
if ( preferredSources[entityId] ) then
hasPreferred = true;
Line 1,433 ⟶ 1,224:
if ( hasPreferred ) then
if ( reference.snaks
and reference.snaks.
and reference.snaks.
and reference.snaks.
and reference.snaks.
local entityId = reference.snaks.
if ( deprecatedSources[entityId] ) then
display = false;
| |||