MODULO
Memtesto disponeblas sur la dokumentaĵa subpaĝo.
Ĉi tiu modulo estas multfoje bindita.
Se vi konas la eblajn sekvojn, tiam vi povas zorgeme ekredakti.
Se vi ne kuraĝas redakti tiam vi povas proponi la deziratan ŝanĝon en la diskutejo.

Utilo

Ellegas paĝonomon simile kiel {{PAGENAME}} sed kun la foje grava diferenco ke apo ' ne estas kodigita al '. Krom tio eblas kodigi la paĝonomon je certaj manieroj kaj samaj kiel kaj aldonaj al parsila funcio {{urlencode...}}, kaj havigi transpasan parametron kiu anstataŭigas la paĝonomon kaj eniras la kodigon. Uzata far:

sed ne {{ref-Cambridge}}.



--[===[

MODULE "PAGENAMKOD"

"eo.wiktionary.org/wiki/Modulo:pagenamkod" <!--2022-Feb-26-->

Purpose: seizes pagename and encodes it

Utilo: ellegas pagxonomon kaj kodigas gxin

Used by templates / Uzata far sxablonoj / Digunakan oleh templat:
- ref-DDO ref-Dictionary ref-Macmillan ref-onelook ref-Tato (EO)

Required submodules / Bezonataj submoduloj / Submodul yang diperlukan:
- none

Incoming: * 2 optional named parameters
            * "ctl=" encoding method (1...7)
              * "ADASH"  dash/minus for space and apo
              * "DASH"   dash/minus for space only
              * "DBDASH" double dash
              * "QUERY"  plus
              * "WIKI"   underscore
              * prefix "!" to also percent-encode complete string after
                replace, otherwise only replace troubled chars, use "!"
                instead of "PATH"
              invalid string ignored, no change or coding then
            * "ovr=" override string to replace the pagename

Returned: * one string

]===]

local pnk = {}

---- CONSTANTS [O] ----

  local contabtransspc = { ["ADASH"]="-",["DASH"]="-",["DBDASH"]="--",["QUERY"]="+",["WIKI"]="_" }
  local contabtransapo = { ["ADASH"]="-"                                                         }

---- MATH FUNCTIONS [A] ----

local function mathdiv (xdividend, xdivisor)
  local resultdiv = 0
  resultdiv = math.floor (xdividend / xdivisor)
  return resultdiv
end--function mathdiv

local function mathmod (xdividendo, xdivisoro)
  local resultmod = 0
  resultmod = xdividendo % xdivisoro
  return resultmod
end--function mathmod

---- NUMBER CONVERSION FUNCTIONS [N] ----

local function lfuint8tohex (numinclow)
  local strheksulo = ''
  local numhajhaj = 0
  numhajhaj = mathdiv (numinclow,16)
  numinclow = mathmod (numinclow,16)
  if (numhajhaj>9) then
    numhajhaj = numhajhaj + 7 -- now 0...9 or 17...22
  end--if
  if (numinclow>9) then
    numinclow = numinclow + 7 -- now 0...9 or 17...22
  end--if
  strheksulo = string.char (numhajhaj+48) .. string.char (numinclow+48)
  return strheksulo
end--function lfuint8tohex

---- LOW LEVEL STRING FUNCTIONS [G] ----

local function lftestnum (numkaad)
  local boodigit = false
  boodigit = ((numkaad>=48) and (numkaad<=57))
  return boodigit
end--function lftestnum

local function lftestuc (numkode)
  local booupperc = false
  booupperc = ((numkode>=65) and (numkode<=90))
  return booupperc
end--function lftestuc

local function lftestlc (numcode)
  local boolowerc = false
  boolowerc = ((numcode>=97) and (numcode<=122))
  return boolowerc
end--function lftestlc

local function lfis62safe (numcxair)
  local booguud = false
  booguud = lftestnum (numcxair) or lftestuc (numcxair) or lftestlc (numcxair)
  return booguud
end--function lfis62safe

---- HIGH LEVEL STRING FUNCTIONS [I] ----

-- Local function LFIPERCENTEN

-- Depends on functions :
-- [G] lftestnum lftestuc lftestlc lfis62safe
-- [N] lfuint8tohex
-- [A] mathdiv mathmod

local function lfipercenten (strenigacxeno)
  local strelirope = ''
  local numinlenin = 0
  local numtiamp = 0
  local numcharbychar = 0
  numinlenin = string.len (strenigacxeno)
  numtiamp = 0 -- ZERO-based
  while (true) do
    if (numtiamp>=numinlenin) then
      break -- done
    end--if
    numcharbychar = string.byte(strenigacxeno,(numtiamp+1),(numtiamp+1))
    if (lfis62safe(numcharbychar)) then
      strelirope = strelirope .. string.char(numcharbychar) -- keep
    else
      strelirope = strelirope .. '%' .. lfuint8tohex(numcharbychar) -- encode
    end--if
    numtiamp = numtiamp + 1
  end--while
  return strelirope
end--function lfipercenten

---- VARIABLES [R] ----

function pnk.ek (arxframent)

  -- general unknown type

  local vartmp = 0 -- variable without type multipurpose

  -- special type "args" AKA "arx"

  local arxourown = 0 -- metaized "args" from our own "frame"

  -- general str

  local strpagenam = ''
  local strctlpara = ''
  local strreplspc = ''
  local strreplapo = ''
  local strreplace = ''
  local strret     = ''

  -- general num boo

  local numlen    = 0
  local numtamp   = 0
  local numoct    = 0
  local booexc    = false

---- MAIN [Z] ----

  ---- GET THE ARX AND 2 NAMED ----

  arxourown = arxframent.args -- "args" from our own "frame"
  if (type(arxourown)~="table") then
    arxourown = {} -- guard against indexing error
  end--if

  strctlpara = arxourown["ctl"] or '' -- quard again
  numlen = string.len (strctlpara)
  if (numlen>7) then -- 1...7 OK (let empty string pass here)
    strctlpara = ''
  end--if

  strpagenam = arxourown["ovr"] or '' -- quard again
  numlen = string.len (strpagenam)
  if (numlen>200) then -- 1...200 OK (let empty string pass here)
    strpagenam = ''
  end--if

  ---- SEIZE THE PAGENAME FROM MW AND CHECK IT ----

  if (strpagenam=='') then
    vartmp = mw.title.getCurrentTitle().text -- without namespace prefix
    if (type(vartmp)=="string") then
      numtamp = string.len(vartmp)
      if (numtamp<=200) then
        strpagenam = vartmp -- pagename (let empty string pass here)
      end--if
    end--if
  end--if

  if (strpagenam=='') then
    strpagenam = "!!ERROR!!" -- empty is NOT legal
  end--if

  ---- CHECK EXCLAM ----

  numlen = string.len (strctlpara)
  if (numlen~=0) then
    booexc = (string.byte(strctlpara,1,1)==33) -- exclam "!"
    if (booexc) then
      strctlpara = string.sub (strctlpara,2,numlen) -- risk leave behind empty
    end--if
  end--if

  strreplspc = contabtransspc [strctlpara] or " " -- replacement for space
  strreplapo = contabtransapo [strctlpara] or "'" -- replacement for apo

  ---- PERFORM THE HUGE WORK ----

  numlen = string.len (strpagenam)
  numtamp = 0 -- ZERO-based
  while (true) do
    if (numtamp>=numlen) then
      break -- done
    end--if
    numoct = string.byte(strpagenam,(numtamp+1),(numtamp+1))
    strreplace = string.char(numoct) -- pre-assume keep char
    if (numoct==32) then
      strreplace = strreplspc -- replace space
    end--if
    if (numoct==39) then
      strreplace = strreplapo -- replace apo
    end--if
    strret = strret .. strreplace -- can be more than one char
    numtamp = numtamp + 1
  end--while
  if (booexc) then
    strret = lfipercenten (strret) -- percent-encode
  end--if

  ---- RETURN THE JUNK STRING ----

  return strret

end--function

  ---- RETURN THE JUNK LUA TABLE ----

return pnk