Moduł:ISBN

 Dokumentacja modułu[zobacz] [edytuj] [historia] [odśwież]

Moduł techniczny do obsługi numerów ISBN.

Funkcja do generowania linku do strony Specjalna:Książki.

Opis parametrów

edytuj
PoleDo czego służy?Jak wypełnić?
1Numer ISBNNp. 83-8678-825-9 lub 978-83-62467-88-4.

Przykład

edytuj

Funkcja do generowania automatycznej dokumentacji w modułach deklarujących formalnie nieprawidłowe numery ISBN.

Błędy

edytuj

Błędy należy zgłaszać na stronie Wikipedia:Kawiarenka/Kwestie techniczne.

Zobacz też

edytuj


local resources = {classLink = "isbn",classIncorrect = "isbn-incorrect",classSeparator = "isbn-do-sprawdzenia",classJustified = "isbn-usprawiedliwiony",classPretty = "isbn-ulepszony",specialBooksPrefix = "Specjalna:Książki/",findLinkPrefix = "Moduł:ISBN/",isbnPrefix = "ISBN&#160;",categoryIncorrectNumber = "[[Kategoria:Artykuły z nieprawidłowymi numerami ISBN]]",categoryInvalidNumber = "[[Kategoria:Artykuły z błędnymi numerami ISBN]]",errorSyntax = "nieprawidłowa składnia",errorFormal = "numer jest poprawny, możliwe, że ten sam numer jest przypisany do kilku różnych tytułów",errorCheck10 = "nieprawidłowa cyfra kontrolna w numerze ISBN-10",errorCheck13 = "nieprawidłowa cyfra kontrolna w numerze ISBN-13",errorPretend13 = "numer ISBN-13 zawiera niewłaściwe cyfry na kluczowych pozycjach",defaultPrefix13 = "978-",}local function deduceSeparators(number, prefix)local function deduce(region, regionLen)for _, v in ipairs(region) dolocal minimum, maximum = string.match(v, "^(%d-)%-(%d-)$")if minimum and maximum and #minimum==#maximum and (minimum <= maximum) thenlocal width = #minimumlocal minimum = tonumber(minimum)local maximum = tonumber(maximum)local publisher = tonumber(string.sub(number, regionLen+1, regionLen+width))if (minimum <= publisher) and (publisher <= maximum) thenreturn string.sub(number, 1, regionLen).."-"..string.sub(number, regionLen+1, regionLen+width).."-"..string.sub(number, regionLen+width+1)endendendendlocal publishers = mw.loadData( "Moduł:ISBN/wydawcy" )local regionLen = 1while regionLen <= 5 dolocal region = publishers[(prefix or resources.defaultPrefix13)..string.sub(number, 1, regionLen)]if region thenlocal pretty = deduce(region, regionLen)if pretty thenreturn prettyendendregionLen = regionLen + 1endif prefix and (prefix ~= defaultPrefix13) thenregionLen = 1while regionLen <= 5 doregion = publishers["978-"..string.sub(number, 1, regionLen)]if region thenlocal pretty = deduce(region, regionLen)if pretty thenreturn prettyendendregionLen = regionLen + 1endendendlocal function analyze(isbn)local result = {}result.isbn = isbnif string.match(isbn, "^[0-9][0-9%-]+[0-9]%-?[0-9Xx]$") and not string.match(isbn, "%-%-") then-- numer ma odowiednie cyfry z opcjonalnymi separatoramilocal clean, n = string.gsub(isbn, "%-", "")result.code, result.n = string.upper(clean), nresult.justified = mw.title.new(resources.findLinkPrefix..clean).existsendif result.code and string.match(result.code, "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9X]$") then-- ISBN-10local b10, b9, b8, b7, b6, b5, b4, b3, b2, b1 = string.byte(result.code, 1, 10)result.expectedSum = (11 - ((10*(b10-48)+9*(b9-48)+8*(b8-48)+7*(b7-48)+6*(b6-48)+5*(b5-48)+4*(b4-48)+3*(b3-48)+2*(b2-48)) % 11)) % 11result.receivedSum = b1 == 88 and 10 or (b1 - 48)result.kind = 10result.error = result.expectedSum ~= result.receivedSum and resources.errorCheck10 or nilresult.separatorWarn = (result.n~=0) and ((result.n~=3) or not string.match(isbn, "[0-9]%-[0-9Xx]$"))result.prefix = falseresult.number = string.sub(result.code, 1, 9)result.checksum = "-"..string.sub(result.code, 10, 10)elseif result.code and (string.match(result.code, "^978[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$") or string.match(result.code, "^979[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$")) then-- ISBN-13local b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13 = string.byte(result.code, 1, 13)result.expectedSum = (10 - (((b1-48)+3*(b2-48)+(b3-48)+3*(b4-48)+(b5-48)+3*(b6-48)+(b7-48)+3*(b8-48)+(b9-48)+3*(b10-48)+(b11-48)+3*(b12-48)) % 10)) % 10result.receivedSum = b13 - 48result.kind = 13result.error = result.expectedSum ~= result.receivedSum and resources.errorCheck13 or nilresult.separatorWarn = (result.n~=0) and ((result.n~=4) or not string.match(isbn, "^97[89]%-[0-9][0-9%-]-[0-9]%-[0-9]$"))result.prefix = string.sub(result.code, 1, 3).."-"result.number = string.sub(result.code, 4, 12)result.checksum = "-"..string.sub(result.code, 13, 13)elseif result.code and string.match(result.code, "^9[78][78][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9X]$") then-- ten numer udaje, że jest ISBN-13result.error = resources.errorPretend13else-- to nie jest numer ISBN, ma nieprawidłową liczbę cyfr lub nieprawidłowe znakiresult.error = resources.errorSyntaxendif result.justified and not result.error thenresult.error = resources.errorFormalendif not result.error and (result.n == 0) and (result.prefix ~= nil) and result.checksum and result.number thenlocal prettyNumber = deduceSeparators(result.number, result.prefix)if prettyNumber thenresult.org = result.isbnresult.isbn = (result.prefix or "")..prettyNumber..result.checksumendendreturn resultendlocal function printISBN(builder, info, prefix)local ns = mw.title.getCurrentTitle().namespaceif info.error and not info.justified and not mw.site.namespaces[ns].isTalk and (ns >= 0) and (ns <= 102) thenmw.addWarning(mw.text.nowiki("{{ISBN|"..info.isbn.."}} "..info.error))endif not info.code thenbuilder:wikitext(prefix):tag("span"):addClass(resources.classIncorrect):attr("title", mw.getContentLanguage():ucfirst(info.error)):wikitext(mw.text.nowiki(info.isbn), ns == 0 and resources.categoryIncorrectNumber or "")returnendbuilder:wikitext("[[", resources.specialBooksPrefix, info.code, "|", prefix):tag("span"):addClass(resources.classLink):addClass(info.justified and resources.classJustified or nil):addClass((not info.justified and info.error) and resources.classIncorrect or nil):addClass(info.separatorWarn and resources.classSeparator or nil):addClass(info.org and resources.classPretty or nil):attr("title", info.error and mw.getContentLanguage():ucfirst(info.error) or nil):wikitext(string.upper(info.isbn)):done():wikitext("]]"):wikitext((not info.justified and info.error and (ns == 0)) and resources.categoryIncorrectNumber or ""):wikitext((info.justified and (ns == 0)) and resources.categoryInvalidNumber or "")endreturn {link = function(builder, isbn)if isbn thenlocal info = analyze(isbn)printISBN(builder, info, resources.isbnPrefix)return tostring(builder)endlocal isbn = builder[1] or builder.args[1] or builder:getParent().args[1]if isbn thenisbn = mw.text.trim(isbn)if #isbn >= 0 thenlocal info = analyze(isbn)local builder = mw.html.create()printISBN(builder, info, resources.isbnPrefix)return tostring(builder)endendend,opis = function(frame)local isbn = type(frame) == "string" and frame or (frame[1] or frame.args[1] or frame:getParent().args[1] or mw.title.getCurrentTitle().subpageText)local info = analyze(isbn)local result = mw.html.create():tag("tt"):wikitext("{{[[Szablon:ISBN|ISBN]]|", mw.text.nowiki(isbn), "}}"):done():wikitext(" → ")printISBN(result, info, resources.isbnPrefix)if info.error thenresult:wikitext("\n* ", mw.getContentLanguage():ucfirst(info.error), ".")endif info.justified thenlocal status, data = pcall(mw.loadData, "Moduł:ISBN/"..info.code)if status then_ = mw.title.new("Module:ISBN/nietrywialne moduły generujące dokumentację").idresult:wikitext("\n----")for i, v in ipairs(data) dolocal text = falseif (type(v) == "table") and (type(v.title) == "string") and (type(v.args) == "table") thentext = mw.getCurrentFrame():expandTemplate(v)elseif type(v) == "string" thentext = mw.getCurrentFrame():preprocess(v)endif text and #text > 0 thenresult:wikitext("\n# ", text)endendif data.kategoria and type(data.kategoria) == "string" and (#data.kategoria > 0) thenresult:wikitext("\n[[Kategoria:", data.kategoria, "]]")endendendreturn tostring(result)end,}