Module:Favilink: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
No edit summary
(split main favilink to its own main function that cannot be individually called, added modulefavilink that allows direct calling that does not require frame usage)
Line 4: Line 4:
local colorparse = require'Module:ColorParse'
local colorparse = require'Module:ColorParse'
local util = require'Module:Favilink Utility'
local util = require'Module:Favilink Utility'
local util_args = require('Module:Args Utility')


function p.favilink(frame, searchtype)
function p.favilink(frame, searchtype)
local displayname_tooltip_override = false


--[Getting query results...]
--[Getting query results...]
Line 26: Line 26:
end
end


local result = util.favilink(name, searchtype)
return main(name, searchtype, modifier)
 
end
 
function p.modulefavilink(name, searchtype, modifier)
  searchtype = searchtype or 'PlainName'
  modifier = modifier or ''
  if name ~= nil and name ~= '' then
    return main(name, searchtype, modifier)
  else 
    error "There is no argument specified! [[Category:pages with favilink errors]]"
  end
end
 
function main(name, searchtype, modifier)
local displayname_tooltip_override = false
  local result = util.favilink(name, searchtype)


if result ~= nil then
if result ~= nil then
Line 82: Line 98:


return tostring(qudimage)
return tostring(qudimage)
end
end



Revision as of 20:33, 7 January 2020

Template-info.png Documentation

!!Currently only for use for objects in the tables: ItemsTable, Food, Corpses, Characters, Locations. All possible items can be found here: Special:CargoTables/GeneralData.

Usage

Used similar to regular wikipage linking syntax. First argument takes name of the object and will pull the image from that item. This must be called using Template:Favilink.

{{favilink|Stopsvalinn}}

Lua error at line 47: attempt to index field '?' (a nil value).

Optional Parameters

You can use the following values as the second argument:

plural pluralizes the item name while preserving the color formatting.
{{favilink |antimatter cell|plural}}

Lua error at line 47: attempt to index field '?' (a nil value).

possessive makes the item name possessive while preserving the color formatting.
{{favilink | Q Girl | possessive}}

Lua error at line 47: attempt to index field '?' (a nil value).

displayname-tooltip-override makes the hover tooltip equal to the display name for items whose display name doesn't match their page name, such as cybernetics credit wedge 1¢. This is probably only needed in special locations where part of the favilink can get truncated, such as in the Character infobox's Inventory list.
{{favilink | cybernetics credit wedge 1¢ | displayname-tooltip-override}}
Lua error at line 47: attempt to index field '?' (a nil value).

Compare to tooltip when this parameter is not specified:

Lua error at line 47: attempt to index field '?' (a nil value).
prefix:<prefix> Prepends a prefix to the name, which can include qud text color styles.
{{favilink | mental aggregator | prefix:&ylant&Ye&Wr&Yn&yed}}

Lua error at line 47: attempt to index field '?' (a nil value).

suffix:<suffix> Postpends a suffix to the name, which can include qud text color styles.
{{favilink | plasma grenade | suffix:mk II}}

Lua error at line 47: attempt to index field '?' (a nil value).

<any other value> completely overrides the name shown in the favilink to whatever argument specified.
{{favilink|torch|A &Rreally&y spicy meatball}}

Lua error at line 47: attempt to index field '?' (a nil value).


local p = {}
local cargo= mw.ext.cargo
local htmlparse = require'Module:HTMLParse'
local colorparse = require'Module:ColorParse'
local util = require'Module:Favilink Utility'
local util_args = require('Module:Args Utility')

function p.favilink(frame, searchtype)

--[Getting query results...]

local name
local modifier

frame=mw.getCurrentFrame()

searchtype = searchtype or 'PlainName'
 
if frame.args ~= nil and frame.args ~= '' then
  if frame.args[1] ~= nil and frame.args[1] ~= '' then
  name = mw.text.trim(frame:preprocess(frame.args[1]))
  modifier = mw.text.trim(frame:preprocess(frame.args[2]))
  else
     error "There is no argument specified! [[Category:pages with favilink errors]]"
  end
end

return main(name, searchtype, modifier)

end

function p.modulefavilink(name, searchtype, modifier)
  searchtype = searchtype or 'PlainName'
  modifier = modifier or ''
  if name ~= nil and name ~= '' then
     return main(name, searchtype, modifier)
  else  
     error "There is no argument specified! [[Category:pages with favilink errors]]"
  end
end

function main(name, searchtype, modifier)
local displayname_tooltip_override = false
  local result = util.favilink(name, searchtype)

if result ~= nil then
  name = result[1]['PlainName']
else
  return '[[' .. name.. ']][[Category:pages with favilink errors]]'
end

local pagelink = result[1]['Page'] or name
local displayname = result[1]['DisplayName'] or name
local image = (result[1]['Image'] ~= '' and result[1]['Image']~=nil) and result[1]['Image'] or 'None'
local displaychar = result[1]['DisplayChar'] or '•'

--[Setting display name modifiers...]
local display

if modifier == 'plural' then
  local displayresult = htmlparse.pluralize( {args= {html = displayname} })
  display=displayresult

elseif modifier == 'possessive' then
  local displayresult = htmlparse.make_possessive({ args = {html = displayname} })
  display=displayresult

elseif modifier == '' then
  display = displayname

elseif modifier == 'displayname-tooltip-override' then
  display = displayname
  displayname_tooltip_override = true
else
  display= colorparse.parse('&y'..modifier)
end

local img
if (mw.title.new('File:' .. image).exists == true) then
  img = '[[File:' .. image .. '|16px|link='..pagelink..']]'
else 
  img = displaychar
end


local spandisplay = displayname_tooltip_override == true and '<span title="'..name..'">'..display..'</span>' or display

local qudimage = mw.html.create('span')
qudimage
        :addClass('qud-image')
        :node(mw.html.create('span') 
             :addClass('qud-image-link-image-container')
             :wikitext(img))
        :node(mw.html.create('span')
             :addClass('qud-image-link')
             :css('color','#b1c9c3')
             :wikitext('[['..pagelink..'|' .. spandisplay .. ']]'))

return tostring(qudimage)
end

function p.idfavilink(frame)
  return p.favilink(frame,'ObjectID')
end

function p.pagenamefavilink(frame)
  return p.favilink(frame,'_pageName')
end

return p