Saltu al enhavo

Modulo:mpeekruangnama

El Vikivortaro
 MODULO
Memtesto ne disponeblas.

--[===[

MODULE "MPEEKRUANGNAMA" (peek ruang nama)

"eo.wiktionary.org/wiki/Modulo:mpeekruangnama" <!--2019-Jun-19-->
"id.wiktionary.org/wiki/Modul:mpeekruangnama"

Purpose: peeks amount of pages in given namespace
         (using "mw.site.stats.pagesInNamespace")

Utilo: ellegas kvanton da pagxoj en donita nomspaco
       (per "mw.site.stats.pagesInNamespace")

Manfaat: membaca jumlah halaman dalam ruang nama yang dimasukkan
         (melalui "mw.site.stats.pagesInNamespace")

Used by templates / Uzata far sxablonoj:
- no templates, but page "Helpo:Nomspaco" (EO) or "Wiktionary:Ruang nama" (ID)

Required submodules / Bezonataj submoduloj:
- none / neniuj

Incoming: - 1 anonymous obligatory parameter:
            - index of namespace (0...2000)

Returned: - string containing the number, at worst "=" if an error occurs

]===]

local peekruangnama = {}

------------------------------------------------------------------------

---- ORDINARY LOCAL LOW LEVEL FUNCTIONS ----

------------------------------------------------------------------------

-- Local function LFBUNCH

-- Add digit bunching to raw decimal number string

local function lfbunch (strnomorin)
  local strnomorut = ""
  local numlenn = 0
  local numindeex = 0 -- ZERO-based counts up
  local numcaar = 0 -- char of string
  numlenn = string.len(strnomorin)
  while (true) do
    if (numindeex==numlenn) then
      break
    end--if
    numcaar = string.byte(strnomorin,(numlenn-numindeex),(numlenn-numindeex))
    if (((numindeex%3)==0) and (numindeex~=0)) then
      strnomorut = "'" .. strnomorut -- prefix by apo
    end--if
    strnomorut = string.char(numcaar) .. strnomorut -- prefix by digit
    numindeex = numindeex + 1
  end--while
  return strnomorut
end--function lfbunch

------------------------------------------------------------------------

---- MAIN EXPORTED FUNCTION ----

------------------------------------------------------------------------

function peekruangnama.ek (arxframent)

  -- general unknown type "var"

  local vartmp = 0     -- variable without type multipurpose

  -- special type "args" AKA "arx"

  local arxourown = 0  -- metaized "args" from our own "frame" (NOT caller's)

  -- general "str"

  local strret    = ""  -- output string
  local strtmp    = ""

  -- general "num"

  local numtemp   = 0  -- length of parameter and amount of pages
  local numindx   = 0  -- index of namespace

  -- general "boo"

  local booerr    = false  -- fatal error flag

  ---- SEIZE 1 OBLIGATORY ARGUMENT SUBMITTED TO US ----

  arxourown = arxframent.args -- "args" from our own "frame"

  if ((arxourown[1]==nil) or (arxourown[2])) then
    booerr = true -- need 1 obligatory param, 2 are not appreciated
  else
    strtmp = arxourown[1] -- 0...2000
    numtemp = string.len(strtmp)
    if ((numtemp==0) or (numtemp>4)) then
      booerr = true
    else
      numindx = tonumber(strtmp)
      if ((numindx<0) or (numindx>2000)) then
        booerr = true
      end--if
    end--if
  end--if

  ---- CARRY OUT THE HARD WORK ----

  if (booerr==false) then
    vartmp = mw.site.stats.pagesInNamespace(numindx)
    if (vartmp) then
      numtemp = tonumber(vartmp)
      if ((numtemp<0) or (numtemp>200000000)) then -- need 0...200M
        booerr = true
      end--if
    else
      booerr = true
    end--if
  end--if

  if (booerr) then
    strret = "=" -- damn (hardcoded error string)
  else
    strret = lfbunch(tostring(numtemp))
  end--if

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

  return strret

end--function

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

return peekruangnama