Va ô cuntinutu

Mòdulu:basi

Da Wikizziunariu, lu dizziunariu a cuntinutu lìbbiru.

La ducumintazzioni di stu mòdulu si pò criari nta Mòdulu:basi/doc

local p = {}
local lucali = mw.language.new('scn')
local currentTitle = mw.title.getCurrentTitle()

-- Namespaces

p.NS_MEDIA = {
  id = -2,
  canonical_name = 'Media',
  local_name = 'Media',
}
p.NS_SPECIAL = {
  id = -1,
  canonical_name = 'Special',
  local_name = 'Spiciali',
}
p.NS_MAIN = {
  id = 0,
  canonical_name = '',
  local_name = '',
}
p.NS_TALK = {
  id = 1,
  canonical_name = 'Talk',
  local_name = 'Discussioni',
}
p.NS_USER = {
  id = 2,
  canonical_name = 'User',
  local_name = 'Utenti',
}
p.NS_USER_TALK = {
  id = 3,
  canonical_name = 'User talk',
  local_name = 'Discussioni utenti',
}
p.NS_PROJECT = {
  id = 4,
  canonical_name = 'Project',
  local_name = 'Wikizziunariu',
}
p.NS_PROJECT_TALK = {
  id = 5,
  canonical_name = 'Project talk',
  local_name = 'Discussioni Wikizziunariu',
}
p.NS_FILE = {
  id = 6,
  canonical_name = 'File',
  local_name = 'File',
}
p.NS_FILE_TALK = {
  id = 7,
  canonical_name = 'File talk',
  local_name = 'Discussioni file',
}
p.NS_MEDIAWIKI = {
  id = 8,
  canonical_name = 'MediaWiki',
  local_name = 'MediaWiki',
}
p.NS_MEDIAWIKI_TALK = {
  id = 9,
  canonical_name = 'MediaWiki talk',
  local_name = 'Discussioni MediaWiki',
}
p.NS_TEMPLATE = {
  id = 10,
  canonical_name = 'Template',
  local_name = 'Template',
}
p.NS_TEMPLATE_TALK = {
  id = 11,
  canonical_name = 'Template talk',
  local_name = 'Discussioni template',
}
p.NS_HELP = {
  id = 12,
  canonical_name = 'Help',
  local_name = 'Aiutu',
}
p.NS_HELP_TALK = {
  id = 13,
  canonical_name = 'Help talk',
  local_name = 'Discussioni aiutu',
}
p.NS_CATEGORY = {
  id = 14,
  canonical_name = 'Category',
  local_name = 'Catigurìa',
}
p.NS_CATEGORY_TALK = {
  id = 15,
  canonical_name = 'Category talk',
  local_name = 'Discussioni catigurìa',
}

-- p.NS_ANNEXE = {
-- id = 100,
--  canonical_name = 'Annexe',
-- local_name = 'Annexe',
-- }
-- p.NS_DISCUSSION_ANNEXE = {
--   id = 101,
--   canonical_name = 'Discussion Annexe',
--   local_name = 'Discussion Annexe',
-- }
-- p.NS_TRANSWIKI = {
--   id = 102,
--   canonical_name = 'Transwiki',
--   local_name = 'Transwiki',
-- }
-- p.NS_DISCUSSION_TRANSWIKI = {
--   id = 103,
--   canonical_name = 'Discussion Transwiki',
--   local_name = 'Discussion Transwiki',
-- }
p.NS_PORTAIL = {
  id = 104,
  canonical_name = 'Portail',
  local_name = 'Purtali',
}
p.NS_DISCUSSION_PORTAIL = {
  id = 105,
  canonical_name = 'Discussion Portail',
  local_name = 'Discussioni purtali',
}
-- p.NS_THESAURUS = {
--   id = 106,
--   canonical_name = 'Thésaurus',
--   local_name = 'Thésaurus',
-- }
-- p.NS_DISCUSSION_THESAURUS = {
--   id = 107,
--   canonical_name = 'Discussion Thésaurus',
--   local_name = 'Discussion Thésaurus',
-- }
 p.NS_PROJET = {
   id = 108,
   canonical_name = 'Projet',
   local_name = 'Pruggettu',
 }
p.NS_DISCUSSION_PROJET = {
  id = 109,
  canonical_name = 'Discussion Projet',
  local_name = 'Discussioni pruggettu',
}
-- p.NS_RECONSTRUCTION = {
--   id = 110,
--   canonical_name = 'Reconstruction',
--   local_name = 'Reconstruction',
-- }
-- p.NS_DISCUSSION_RECONSTRUCTION = {
--   id = 111,
--   canonical_name = 'Discussion Reconstruction',
--   local_name = 'Discussion Reconstruction',
-- }
-- p.NS_TUTORIEL = {
--   id = 112,
--   canonical_name = 'Tutoriel',
--   local_name = 'Tutoriel',
-- }
-- p.NS_DISCUSSION_TUTORIEL = {
--   id = 113,
--   canonical_name = 'Discussion Tutoriel',
--   local_name = 'Discussion Tutoriel',
-- }
-- p.NS_RIME = {
--   id = 114,
--   canonical_name = 'Rime',
--   local_name = 'Rime',
-- }
-- p.NS_DISCUSSION_RIME = {
--   id = 115,
--   canonical_name = 'Discussion Rime',
--  local_name = 'Discussion Rime',
-- }
-- p.NS_CONJUGAISON = {
--   id = 116,
--   canonical_name = 'Conjugaison',
--   local_name = 'Conjugaison',
-- }
-- p.NS_DISCUSSION_CONJUGAISON = {
--   id = 117,
--   canonical_name = 'Discussion Conjugaison',
--   local_name = 'Discussion Conjugaison',
-- }
-- p.NS_RACINE = {
--   id = 118,
--   canonical_name = 'Racine',
--   local_name = 'Racine',
-- }
-- p.NS_DISCUSSION_RACINE = {
--   id = 119,
--   canonical_name = 'Discussion Racine',
--   local_name = 'Discussion Racine',
-- }

p.NS_MODULE = {
  id = 828,
  canonical_name = 'Module',
  local_name = 'Mòdulu',
}
p.NS_MODULE_TALK = {
  id = 829,
  canonical_name = 'Module talk',
  local_name = 'Discussioni mòdulu',
}

p.NS_TRANSLATIONS = {
  id = 1198,
  canonical_name = 'Translations',
  local_name = 'Translations',
}
p.NS_TRANSLATIONS_TALK = {
  id = 1199,
  canonical_name = 'Translations talk',
  local_name = 'Translations talk',
}

p.NS_GADGET = {
  id = 2300,
  canonical_name = 'Gadget',
  local_name = 'Accissoriu',
}
p.NS_GADGET_TALK = {
  id = 2301,
  canonical_name = 'Gadget talk',
  local_name = 'Discussioni accissoriu',
}
p.NS_GADGET_DEFINITION = {
  id = 2302,
  canonical_name = 'Gadget definition',
  local_name = 'Difinizzioni accissoriu',
}
p.NS_GADGET_DEFINITION_TALK = {
  id = 2303,
  canonical_name = 'Gadget definition talk',
  local_name = 'Discussioni difinizzioni accissoriu',
}

-- p.NS_TOPIC = {
--   id = 2600,
--   canonical_name = 'Topic',
--    local_name = 'Sujet',
-- }

function p.is_elidable(word)
  return mw.ustring.match(p.lcfirst(word), "^h?[aáàâäeéèêëiíìîïoóòôöuúùûüǘǜ]") ~= nil
end

function p.is_locution(word)
  if word == nil then
    return nil
  end
  return mw.ustring.find(word, ". .") ~= nil
end

function p.paggina_esisti(title)
  return title ~= nil and mw.title.new(title).exists
end

function p.ucfirst(text)
  if text == nil then
    return nil
  end
  return (mw.ustring.gsub(text, "^([’ǂǃǀǁ]*.)", p.uc))
end

function p.lcfirst(text)
  if text == nil then
    return nil
  end
  return lucali:lcfirst(text)
end


function p.uc(text)
  if text == nil then
    return nil
  end
  return lucali:uc(text)
end

function p.lc(text)
  if text == nil then
    return nil
  end
  return lucali:lc(text)
end

function p.paggina_di_cuntinutu()
  local ns = currentTitle.namespace
  return ns == p.NS_MAIN.id
  -- or ns == p.NS_ANNEXE.id or ns == p.NS_THESAURUS.id or ns == p.NS_RECONSTRUCTION.id or ns == p.NS_RIME.id or ns == p.NS_CONJUGAISON.id or ns == p.NS_RACINE.id
end

function p.paggina_principali()
  return currentTitle:inNamespace(p.NS_MAIN.id)
end

function p.fa_catiguria(name, sortingKey, asLink)
  local cat = asLink and ':Catigurìa:' or 'Catigurìa:'

  if name ~= nil then
    if sortingKey ~= nil and sortingKey ~= '' then
      return '[[' .. cat .. name .. '|' .. sortingKey .. ']]'
    else
      return '[[' .. cat .. name .. ']]'
    end
  else
    return ''
  end
end

function p.fa_catiguria_cuntinutu(name, sortingKey, asLink)
  if p.paggina_di_cuntinutu() then
    return p.fa_catiguria(name, sortingKey, asLink) or ''
  else
    return ''
  end
end

function p.fa_catiguria_principali(name, sortingKey, asLink)
  if p.paggina_principali() then
    return p.fa_catiguria(name, sortingKey, asLink) or ''
  else
    return ''
  end
end

function p.tabbella_ntistazzioni(columnTitles)
  return '{| class="wikitable sortable"\n|-\n!' .. table.concat(columnTitles, ' !! ')
end

function p.tabbella_linia(elements)
  return '|-\n|' .. table.concat(elements, ' || ')
end

function p.tabbella_fini()
  return '|}\n'
end

function p.esp(text)
  return mw.ustring.format('<sup style="font-size:83%%;line-height:1">%s</sup>', text)
end

function p.tag_lingua(text, code)
  return mw.ustring.format('<bdi lang="%s" xml:lang="%s" class="lang-%s">%s</bdi>', code, code, code, text)
end

function p.trim_paramitri(args)
  if args == nil then
    return nil
  end

  local trim_args = {}
  for k, v in pairs(args) do
    trim_args[k] = mw.text.trim(v)
  end

  return trim_args
end

function p.link_template(word, langCode, anchor, text, keepLangAnchor)
  if langCode and langCode == "" then
    langCode = nil
  end
  if text and text == "" then
    text = nil
  end
  if anchor and anchor == "" then
    anchor = nil
  end
  local m_unicode = require("Mòdulu:dati Unicode")
  local m_langs = require("Mòdulu:lingui")
  text = m_unicode.setWritingDirection(text or word)

  local langCodeForlink = m_langs.specialCodes[langCode] or langCode

  local link

  if word == currentTitle.prefixedText and not anchor then
    if keepLangAnchor and langCodeForlink then
      link = mw.ustring.format("[[%s#%s|%s]]", word, langCodeForlink, text)
    else
      link = mw.ustring.format("[[%s|%s]]", word, text)
    end
  else
    if langCodeForlink then
      if anchor and anchor ~= "" then
        anchor = langCodeForlink .. "-" .. anchor
      else
        anchor = langCodeForlink
      end
    end
    if anchor then
      link = mw.ustring.format("[[%s#%s|%s]]", word, anchor, text)
    else
      link = mw.ustring.format("[[%s|%s]]", word, text)
    end
  end

  if langCode then
    return p.tag_lingua(link, langCode)
  end
  return link
end

function p.derniereOccurrence(subject, s)
  local dernier = 0

  while subject:sub(dernier + 1, subject:len()):find(s) ~= nil do
    dernier = dernier + subject:sub(dernier + 1, subject:len()):find(s)
  end

  return dernier
end

return p