Module:Favilink
!!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 72: attempt to call field 'modulenonxmlparse' (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}} |
---|---|
possessive
|
makes the item name possessive while preserving the color formatting.
{{favilink | Q Girl | possessive}} |
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}} Compare to tooltip when this parameter is not specified: Lua error at line 72: attempt to call field 'modulenonxmlparse' (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 72: attempt to call field 'modulenonxmlparse' (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 72: attempt to call field 'modulenonxmlparse' (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 72: attempt to call field 'modulenonxmlparse' (a nil value). |
local p = {}
local cargo= mw.ext.cargo
local htmlparse = require'Module:HTMLParse'
local colorparse = require'Module:ColorParse'
function p.favilink(frame, searchtype)
local displayname_tooltip_override = false
local args = frame
if frame == mw.getCurrentFrame() then
args = require('Module:ProcessArgs').merge(true)
else
frame = mw.getCurrentFrame()
end
--[Getting query results...]
local name
local modifier
searchtype = searchtype or 'PlainName'
if args ~= nil and args ~= '' then
if args[1] ~= nil and args[1] ~= '' then
name = mw.text.trim(frame:preprocess(args[1]))
modifier = mw.text.trim(frame:preprocess(args[2]))
else
error "There is no argument specified! [[Category:pages with favilink errors]]"
end
end
local wherestr = ''
if (searchtype == 'PlainName') then
wherestr = ' AND BINARY PlainName="' .. name:gsub("'", "\'") .. '"'
elseif (searchtype == 'ID') then
wherestr = ' AND BINARY ObjectID="' .. name:gsub("'", "\'") .. '"'
elseif (searchtype == '_pageName') then
wherestr = ' AND BINARY _pageName="' .. name:gsub("'", "\'") .. '"'
end
local result = cargo.query('GeneralData','_pageName=Page, DisplayName, Image, DisplayChar, PlainName',{where='_pageNamespace="0"' .. wherestr, default=name, limit='1'} )
if not next(result) then
return '[[' .. name.. ']][[Category:pages with favilink errors]]'
else
name = result[1]['PlainName']
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.modulenonxmlparse('&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,'ID')
end
function p.pagenamefavilink(frame)
return p.favilink(frame,'_pageName')
end
return p