Zum Inhalt springen
Das Halloween-Event (Süßes oder Saures) findet vom 24.10.2025 bis 07.11.2025 statt.

Modul:Link: Unterschied zwischen den Versionen

Aus Firestone Idle RPG Wiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 6: Zeile 6:
local DEFAULT_LIMIT = 220
local DEFAULT_LIMIT = 220


local function trim(s)
local function trim(s) return type(s)=='string' and (s:gsub('^%s+',''):gsub('%s+$','')) or '' end
  if type(s) ~= 'string' then return '' end
  return (s:gsub('^%s+',''):gsub('%s+$',''))
end
 
local function normalize_key(s)
local function normalize_key(s)
   s = trim(s or '')
   s = US.lower(trim(s or '')):gsub('_',' '):gsub('%s+',' ')
  s = US.lower(s)
  s = s:gsub('_',' '):gsub('%s+',' ')
   return s
   return s
end
end


-- Links zu neutralem Text machen (für Hover)
local function strip_links(txt)
local function strip_links(txt)
   txt = txt or ''
   txt = txt or ''
   txt = txt:gsub('%[%[([^%]|%]]-)|([^\]]-)%]%]', '%2')             -- [[Ziel|Text]] -> Text
   txt = txt:gsub('%[%[([^%]|%]]-)|([^\]]-)%]%]', '%2')
   txt = txt:gsub('%[%[([^%]]-)%]%]', function(inner) return inner:gsub('_',' ') end) -- [[Ziel]] -> Ziel
   txt = txt:gsub('%[%[([^%]]-)%]%]', function(inner) return inner:gsub('_',' ') end)
   txt = txt:gsub('%[(https?://[^%s%]]+)%s+([^\]]-)%]', '%2')       -- [url Label] -> Label
   txt = txt:gsub('%[(https?://[^%s%]]+)%s+([^\]]-)%]', '%2')
   txt = txt:gsub('%[(https?://[^%]]+)%]', '%1')                     -- [url] -> url
   txt = txt:gsub('%[(https?://[^%]]+)%]', '%1')
   return txt
   return txt
end
end
Zeile 39: Zeile 32:


local function htmlize_plain(txt)
local function htmlize_plain(txt)
   txt = tostring(txt or '')
   txt = mw.text.encode(tostring(txt or ''))
  txt = mw.text.encode(txt) -- HTML-sicher
   return txt:gsub('\n','<br/>')
   txt = txt:gsub('\n','<br/>')
  return txt
end
end


local function make_link(target, display)
local function make_link(target, display)
   target  = trim(target)
   target  = trim(target)
   display = display and trim(display) or ''
   display = trim(display or '')
   if display ~= '' then return '[[' .. target .. '|' .. display .. ']]' end
   return display ~= '' and ('[['..target..'|'..display..']]') or ('[['..target..']]')
  return '[[' .. target .. ']]'
end
end


-- === HOVER ===
local function render_hover(link_wt, info, limit)
local function render_hover(link_wikitext, info, limit)
   if not info or (not info.title and not info.desc and not info.icon) then
   if not info or (not info.title and not info.desc and not info.icon) then
     return link_wikitext
     return link_wt
   end
   end
  local wrap  = mw.html.create('span'):addClass('fs-tt')
  wrap:wikitext(link_wt)


   local wrap  = mw.html.create('span'):addClass('kr-tt')
   local content = mw.html.create('span'):addClass('tt-content')
  wrap:wikitext(link_wikitext)
   local box    = mw.html.create('span'):addClass('tt-box')
 
  local content = mw.html.create('span'):addClass('kr-tt__content')
   local box    = mw.html.create('span'):addClass('kr-tt__box')


   if info.icon and info.icon ~= '' then
   if info.icon and info.icon ~= '' then
     box:wikitext('[[File:' .. info.icon .. '|28x28px|link=|class=kr-tt__icon]]')
     box:wikitext('[[File:'..info.icon..'|28x28px|link=|class=tt-icon]]')
   else
   else
     box:wikitext('<span class="kr-tt__icon kr-tt__icon--empty"></span>')
     box:wikitext('<span class="tt-icon tt-icon--empty"></span>')
   end
   end


Zeile 73: Zeile 61:
   local desc  = info.desc  or ''
   local desc  = info.desc  or ''


   desc = strip_links(desc)
   desc = shorten(strip_links(desc), limit)
  desc = shorten(desc, limit)


   local text = mw.html.create('span'):addClass('kr-tt__text')
   local text = mw.html.create('span'):addClass('tt-text')
   text:tag('span'):addClass('kr-tt__title'):wikitext(htmlize_plain(title))
   text:tag('span'):addClass('tt-title'):wikitext(htmlize_plain(title))
   text:tag('span'):addClass('kr-tt__sep')   -- << Trenner hinzufügen
   text:tag('span'):addClass('tt-sep')
   text:tag('span'):addClass('kr-tt__desc'):wikitext(htmlize_plain(desc))
   text:tag('span'):addClass('tt-desc'):wikitext(htmlize_plain(desc))


   box:node(text)
   box:node(text)
Zeile 87: Zeile 74:
end
end


-- === VIEW ===
local function render_view(info)
local function render_view(info)
   local title = info and info.title or ''
   local title = info and info.title or ''
Zeile 93: Zeile 79:
   local icon  = info and info.icon  or ''
   local icon  = info and info.icon  or ''


   local tbl = mw.html.create('table'):addClass('kr-tt-view')
   local tbl = mw.html.create('table'):addClass('fs-tt-view')
   local trh = tbl:tag('tr')
   local trh = tbl:tag('tr')
   trh:tag('th'):attr('colspan','2'):wikitext(title ~= '' and title or '&nbsp;')
   trh:tag('th'):attr('colspan','2'):wikitext(title ~= '' and title or '&nbsp;')


   local tr = tbl:tag('tr')
   local tr = tbl:tag('tr')
   local tdIcon = tr:tag('td'):addClass('kr-tt-view__icon')
   local tdIcon = tr:tag('td'):addClass('fs-tt-view__icon')
   if icon ~= '' then
   if icon ~= '' then
     tdIcon:wikitext('[[File:' .. icon .. '|64x64px|class=kr-tt-view__iconimg|link=]]')
     tdIcon:wikitext('[[File:'..icon..'|64x64px|class=fs-tt-view__iconimg|link=]]')
   else
   else
     tdIcon:wikitext('&nbsp;')
     tdIcon:wikitext('&nbsp;')
   end
   end
   tr:tag('td'):addClass('kr-tt-view__desc'):wikitext(desc or '')
   tr:tag('td'):addClass('fs-tt-view__desc'):wikitext(desc or '')
 
   return tostring(tbl)
   return tostring(tbl)
end
end
Zeile 116: Zeile 101:
   if target == '' then return '' end
   if target == '' then return '' end


   local p2 = args[2] and trim(args[2]) or ''
   local p2 = trim(args[2] or '')
   local mode_view = (US.lower(p2) == 'view')
   local mode_view = (US.lower(p2) == 'view')


   -- Key bestimmen (ggf. überschreibbar via |key=)
   -- Key: Anzeigename (Param 2) > Ziel (Param 1); überschreibbar via |key=
   local key = trim(args.key or (mode_view and target or (p2 ~= '' and p2 or target)))
   local key = trim(args.key or (mode_view and target or (p2 ~= '' and p2 or target)))
   local key_norm = normalize_key(key)
   local info = data[normalize_key(key)] or data[normalize_key(key):gsub(' ','_')]


  local info = data[key_norm] or data[key_norm:gsub(' ','_')] or nil
   local limit = tonumber(args.limit or '') or DEFAULT_LIMIT
   local limit = tonumber(args.limit or '') or DEFAULT_LIMIT


Zeile 129: Zeile 113:
     return render_view(info or {})
     return render_view(info or {})
   else
   else
     local link_wt = make_link(target, (p2 ~= '' and p2 or nil))
     return render_hover(make_link(target, (p2 ~= '' and p2 or nil)), info or {}, limit)
    return render_hover(link_wt, info or {}, limit)
   end
   end
end
end


return p
return p

Version vom 23. Oktober 2025, 23:56 Uhr

Erzeugt interne Links mit Hover-Tooltip (Icon, Titel, Kurzbeschreibung) aus Modul:LinkData. Optional kann eine „Detailansicht“ (Wikitable) ausgegeben werden.

Grundsyntax

Tooltip-Link
{{Link|Ziel}}
Tooltip-Link mit eigenem Anzeigenamen
{{Link|Ziel|Anzeigename}}
Detailansicht (Tabelle) statt Link
{{Link|Ziel|view}}

Parameter

Param Name Typ/Standard Beschreibung
1 Ziel Pflicht Seitentitel oder „Titel#Abschnitt“. Wird als Linkziel verwendet.
2 Anzeigename / view / Kurz-Suffix optional
  • leer → Anzeigename = title aus LinkData
  • view → gibt die Tabelle aus
  • +… → Kurz-Suffix für Plural etc. (siehe unten)
s s (Suffix) optional Hängt Text an den Anzeigenamen aus LinkData an (z. B. s=e → „Biere“).
key key optional Erzwingt den Datensatz-Schlüssel für LinkData (falls Ziel und title nicht übereinstimmen).
limit limit Zahl (220) Maximale Länge der Tooltip-Beschreibung; bei Überschreitung wird abgeschnitten (…).

Verhalten

Anzeigename

  • Standardmäßig wird als Anzeigename der deutsche Titel aus Modul:LinkData verwendet (Feld title).
  • Eigener Anzeigename (2. Parameter) überschreibt den Titel.
  • Groß-/Kleinschreibung bleibt genau wie im Wikitext/LinkData.

Plural / LinkTrail

MediaWikis LinkTrail funktioniert nur bei direkt geschriebenen Links, nicht bei Vorlagen. Dafür gibt es zwei Wege:

  1. Suffix-Kurzform im 2. Parameter:
{{Link|Bier|+e}}+e
{{Link|Bier|+en}}+en
  1. Expliziter Suffix über s=:
{{Link|Bier|s=e}}Bier

Hinweise:

  • Sobald ein eigener Anzeigename gesetzt ist, wird s= ignoriert.
  • Bei „unpiped“ Links (also wirklich Biere) greift LinkTrail – das ist mit Vorlagen technisch nicht möglich. Nutze daher s= / +….

Anker/Abschnitte

  • Bei Zielen mit # (z. B. Währungen#Bier) wird immer ein gepipter Link erzeugt (kein LinkTrail / ToolTip möglich).
  • Die Detailansicht (view) setzt die Tabellen-ID anhand des Titels (Leerzeichen → Unterstrich).

Tooltip

  • Holt title / icon / desc aus Modul:LinkData.
  • Links in der Beschreibung werden im Hover-Tooltip zu normalem Text neutralisiert.
  • Zeilenumbrüche werden unterstützt; lange Texte werden nach limit Zeichen abgeschnitten.

Fallbacks

  • Gibt es keinen Datensatz in LinkData, wird ein normaler Link ohne Tooltip ausgegeben.

Beispiele

Standard
{{Link|Bier}}Bier
Eigener Anzeigename
{{Link|Währungen#Bier|Bier}}Bier
Plural via Suffix (Kurzform)
{{Link|Bier|+e}}+e
Plural via s=
{{Link|Bier|s=en}}Bier
Detailansicht (Wikitable)
{{Link|Bier|view}}
 
 
Limit anpassen
{{Link|Bier|limit=50}}Bier
Abweichender Datensatz (engl. key)
{{Link|Währungen|key=Beer}}WährungenBier0Bier schaltet sich auf Charakterlevel 15 frei. Biere droppen mit einer Rate von 1 Bier pro 28,8 Sekunden auf dem Schlachtfeld (entspricht 3000 Bier pro Tag). Zusätzlich ist Bier als mögliche Belohnung aus T…0

-- Modul:ToolTip
local p = {}

local data = mw.loadData('Modul:LinkData')
local US = mw.ustring
local DEFAULT_LIMIT = 220

local function trim(s) return type(s)=='string' and (s:gsub('^%s+',''):gsub('%s+$','')) or '' end
local function normalize_key(s)
  s = US.lower(trim(s or '')):gsub('_',' '):gsub('%s+',' ')
  return s
end

local function strip_links(txt)
  txt = txt or ''
  txt = txt:gsub('%[%[([^%]|%]]-)|([^\]]-)%]%]', '%2')
  txt = txt:gsub('%[%[([^%]]-)%]%]', function(inner) return inner:gsub('_',' ') end)
  txt = txt:gsub('%[(https?://[^%s%]]+)%s+([^\]]-)%]', '%2')
  txt = txt:gsub('%[(https?://[^%]]+)%]', '%1')
  return txt
end

local function shorten(txt, limit)
  limit = tonumber(limit) or DEFAULT_LIMIT
  local len = US.len(txt or '')
  if len <= limit then return txt end
  local cut = US.sub(txt, 1, limit)
  local lastSpace = cut:match('^.*()%s')
  if lastSpace and lastSpace > 15 then cut = US.sub(cut, 1, lastSpace - 1) end
  return cut .. '…'
end

local function htmlize_plain(txt)
  txt = mw.text.encode(tostring(txt or ''))
  return txt:gsub('\n','<br/>')
end

local function make_link(target, display)
  target  = trim(target)
  display = trim(display or '')
  return display ~= '' and ('[['..target..'|'..display..']]') or ('[['..target..']]')
end

local function render_hover(link_wt, info, limit)
  if not info or (not info.title and not info.desc and not info.icon) then
    return link_wt
  end
  local wrap   = mw.html.create('span'):addClass('fs-tt')
  wrap:wikitext(link_wt)

  local content = mw.html.create('span'):addClass('tt-content')
  local box     = mw.html.create('span'):addClass('tt-box')

  if info.icon and info.icon ~= '' then
    box:wikitext('[[File:'..info.icon..'|28x28px|link=|class=tt-icon]]')
  else
    box:wikitext('<span class="tt-icon tt-icon--empty"></span>')
  end

  local title = info.title or ''
  local desc  = info.desc  or ''

  desc = shorten(strip_links(desc), limit)

  local text = mw.html.create('span'):addClass('tt-text')
  text:tag('span'):addClass('tt-title'):wikitext(htmlize_plain(title))
  text:tag('span'):addClass('tt-sep')
  text:tag('span'):addClass('tt-desc'):wikitext(htmlize_plain(desc))

  box:node(text)
  content:node(box)
  wrap:node(content)
  return tostring(wrap)
end

local function render_view(info)
  local title = info and info.title or ''
  local desc  = info and info.desc  or ''
  local icon  = info and info.icon  or ''

  local tbl = mw.html.create('table'):addClass('fs-tt-view')
  local trh = tbl:tag('tr')
  trh:tag('th'):attr('colspan','2'):wikitext(title ~= '' and title or '&nbsp;')

  local tr = tbl:tag('tr')
  local tdIcon = tr:tag('td'):addClass('fs-tt-view__icon')
  if icon ~= '' then
    tdIcon:wikitext('[[File:'..icon..'|64x64px|class=fs-tt-view__iconimg|link=]]')
  else
    tdIcon:wikitext('&nbsp;')
  end
  tr:tag('td'):addClass('fs-tt-view__desc'):wikitext(desc or '')
  return tostring(tbl)
end

function p.main(frame)
  local parent = frame:getParent()
  local args = parent and parent.args or frame.args

  local target = trim(args[1] or '')
  if target == '' then return '' end

  local p2 = trim(args[2] or '')
  local mode_view = (US.lower(p2) == 'view')

  -- Key: Anzeigename (Param 2) > Ziel (Param 1); überschreibbar via |key=
  local key = trim(args.key or (mode_view and target or (p2 ~= '' and p2 or target)))
  local info = data[normalize_key(key)] or data[normalize_key(key):gsub(' ','_')]

  local limit = tonumber(args.limit or '') or DEFAULT_LIMIT

  if mode_view then
    return render_view(info or {})
  else
    return render_hover(make_link(target, (p2 ~= '' and p2 or nil)), info or {}, limit)
  end
end

return p