Module:WeeklyEvent: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
Mcint (talk | contribs)
m span use again
Mcint (talk | contribs)
simplified
Tag: Reverted
Line 5: Line 5:
end
end


local function exists(t)
function p.links(frame)
   local title = mw.title.new(t)
   local args    = frame:getParent().args
   return title and title.exists
  local prefix  = args.prefix  or 'Meeting Notes'
end
   local joiner  = args.joiner  or ' '
  local weekday = args.weekday or 'Tuesday'


function p.links(frame)
  -- show segment iff arg PROVIDED (nil => omit); blank string allowed
  local args = frame:getParent().args
   local t_prev   = args.text_prev
   local prefix   = args.prefix  or 'Meeting Notes'
   local t_this  = args.text_this
  local joiner  = args.joiner  or ' '
   local t_next  = args.text_next
  local weekday  = args.weekday  or 'Tuesday'
   local t_this  = args.text_this or 'This week'
  local t_prev  = args.text_prev or 'Last week'
   local t_next  = args.text_next or 'Next week'
   local preload  = args.preload
   local preload  = args.preload
  local t_create = args.create_text -- show create link iff provided (and preload nonempty)


  local prevdate = d('Y m d', 'last ' .. weekday)
   local thisdate = d('Y m d', 'this ' .. weekday)
   local thisdate = d('Y m d', 'this ' .. weekday)
  local prevdate = d('Y m d', 'last ' .. weekday)
   local nextdate = d('Y m d', 'next ' .. weekday)
   local nextdate = d('Y m d', 'next ' .. weekday)


  local prevTitle = table.concat({prefix, prevdate}, joiner)
   local thisTitle = table.concat({prefix, thisdate}, joiner)
   local thisTitle = table.concat({prefix, thisdate}, joiner)
  local prevTitle = table.concat({prefix, prevdate}, joiner)
   local nextTitle = table.concat({prefix, nextdate}, joiner)
   local nextTitle = table.concat({prefix, nextdate}, joiner)


   local latestTitle, latestText
   local parts = {}
  if exists(thisTitle) then
    latestTitle, latestText = thisTitle, t_this
  elseif exists(prevTitle) then
    latestTitle, latestText = prevTitle, t_prev
  end
 
  -- build inline wikitext
  local out = ''


   if latestTitle then
   local function add_link(title, label)
     out = out .. string.format('[[%s|%s]]', latestTitle, latestText)
     table.insert(parts, string.format('[[%s|%s]]', title, label or ''))
  else
    out = out .. "''no recent page''"
   end
   end


   out = out .. ' · ' ..
   if t_prev ~= nil then add_link(prevTitle, t_prev) end
        string.format('[[%s|%s]]', nextTitle, t_next)
  if t_this ~= nil then add_link(thisTitle, t_this) end
  if t_next ~= nil then add_link(nextTitle, t_next) end


   if preload then
   if preload and preload ~= '' and t_create ~= nil then
     local url = mw.uri.canonicalUrl(nextTitle, { action='edit', preload=preload })
     local url = mw.uri.canonicalUrl(nextTitle, { action='edit', preload=preload })
     out = out .. ' · ' ..
     table.insert(parts, string.format('[%s %s]', tostring(url), t_create))
          string.format('[%s create next]', tostring(url))
   end
   end


   --[[
   local out = mw.text.trim(table.concat(parts, ' · '))
  return frame:preprocess(out)
  ]]
  -- no leading/trailing whitespace
 
  out = mw.text.trim(out)


  -- force inline rendering; content is parsed as wikitext inside a <span>
   return frame:extensionTag{
   return frame:extensionTag{
     name = 'span',
     name = 'span',
     content = out,
     content = out,
     args = { class = 'weekly-event-inline' } -- optional
     args = { class = 'weekly-event-inline' }
   }
   }
end
end


return p
return p

Revision as of 18:16, 23 February 2026

docs

mw:Extension:Scribunto

mw:Module:Arguments

https://dev.fandom.com/wiki/Lua_reference_manual/Scribunto_libraries

https://en.wikipedia.org/wiki/Wikipedia:Comparable_Lua_functions_to_wikitext


local p = {}

local function d(fmt, rel)
  return mw.getContentLanguage():formatDate(fmt, rel)
end

function p.links(frame)
  local args    = frame:getParent().args
  local prefix  = args.prefix  or 'Meeting Notes'
  local joiner  = args.joiner  or ' '
  local weekday = args.weekday or 'Tuesday'

  -- show segment iff arg PROVIDED (nil => omit); blank string allowed
  local t_prev   = args.text_prev
  local t_this   = args.text_this
  local t_next   = args.text_next
  local preload  = args.preload
  local t_create = args.create_text -- show create link iff provided (and preload nonempty)

  local prevdate = d('Y m d', 'last ' .. weekday)
  local thisdate = d('Y m d', 'this ' .. weekday)
  local nextdate = d('Y m d', 'next ' .. weekday)

  local prevTitle = table.concat({prefix, prevdate}, joiner)
  local thisTitle = table.concat({prefix, thisdate}, joiner)
  local nextTitle = table.concat({prefix, nextdate}, joiner)

  local parts = {}

  local function add_link(title, label)
    table.insert(parts, string.format('[[%s|%s]]', title, label or ''))
  end

  if t_prev ~= nil then add_link(prevTitle, t_prev) end
  if t_this ~= nil then add_link(thisTitle, t_this) end
  if t_next ~= nil then add_link(nextTitle, t_next) end

  if preload and preload ~= '' and t_create ~= nil then
    local url = mw.uri.canonicalUrl(nextTitle, { action='edit', preload=preload })
    table.insert(parts, string.format('[%s %s]', tostring(url), t_create))
  end

  local out = mw.text.trim(table.concat(parts, ' · '))

  return frame:extensionTag{
    name = 'span',
    content = out,
    args = { class = 'weekly-event-inline' }
  }
end

return p