Importer, Bürokraten, Moderatoren (CommentStreams), Strukturierte-Diskussionen-Bots, Oberflächenadministratoren, Push-Abonnementverwalter, Oversighter, Administratoren, Kampagnenbearbeiter (Hochladeassistent)
855
Bearbeitungen
(range format) |
K (51 Versionen von wikivoyage:Modul:Citation/utilities importiert) |
||
| (17 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt) | |||
| Zeile 3: | Zeile 3: | ||
suite = 'Citation', | suite = 'Citation', | ||
sub = 'utilities', | sub = 'utilities', | ||
serial = ' | serial = '2022-10-21' | ||
} | } | ||
| Zeile 12: | Zeile 12: | ||
-- module import | -- module import | ||
require( ' | -- require( 'strict' ) | ||
local ci = require( 'Module:Citation/i18n' ) | local ci = require( 'Module:Citation/i18n' ) | ||
| Zeile 182: | Zeile 182: | ||
end | end | ||
-- remove adjoining punctuation marks | -- remove adjoining punctuation marks etc. | ||
function cu.finalCleanup( s ) | function cu.finalCleanup( s ) | ||
s = | s = s:gsub( '%.+%.', '.' ):gsub( '%s%s+', ' ' ):gsub( '([,;:])(%s%.+)', '.' ) | ||
for _, replacement in ipairs( ci.replacements ) do | |||
s = mw.ustring.gsub( s, replacement.s, replacement.r ) | |||
end | |||
s = s:gsub( '#b#', '.' ) -- restore bibcode | |||
return s | |||
end | end | ||
function cu.makeLink( url, text ) | function cu.makeLink( url, text ) | ||
return mw.ustring.format( '[%s %s]', url, text ) | return mw.ustring.format( '[%s %s]', url, text ) | ||
end | end | ||
| Zeile 278: | Zeile 273: | ||
return '' | return '' | ||
end | end | ||
end | |||
function cu.templateStyles( frame ) | |||
return frame:extensionTag( 'templatestyles', '', { src = ci.styleSrc } ); | |||
end | |||
-- Check digit estimation for countries at, ch, de, and fi | |||
-- See: https://github.com/bohnelang/URN-Pruefziffer | |||
-- Description of the algorithm: http://www.pruefziffernberechnung.de/U/URN.shtml | |||
function cu.getNbnCheckDigit( urn ) | |||
-- two-digits codes for ascii characters starting from - == '-' | |||
local code='3947450102030405060708094117############1814191516212223242542262713282931123233113435363738########43' | |||
local sum = 0 | |||
local pos = 1 | |||
local digit1, digit2, x | |||
urn = urn:upper():sub( 1, -2 ) -- remove last character | |||
for i = 1, urn:len() do | |||
x = 2 * ( urn:byte( i ) - 45 ); -- - == '-' | |||
digit1 = tonumber( code:sub( x + 1, x + 1 ) ); | |||
digit2 = tonumber( code:sub( x + 2, x + 2 ) ); | |||
if digit1 == 0 then | |||
sum = sum + digit2 * pos | |||
pos = pos + 1 | |||
else | |||
sum = sum + digit1 * pos + digit2 * ( pos + 1 ) | |||
pos = pos + 2 | |||
end | |||
end | |||
return tostring( math.floor( sum / digit2 ) % 10 ); | |||
end | |||
function cu.check_UrnNbn( urn ) | |||
urn = urn:gsub( '/fragment/.+$', '' ) -- remove fragment | |||
return urn:sub( -1 ) == cu.getNbnCheckDigit( urn ) | |||
end | end | ||
return cu | return cu | ||