Module:Favilink: Difference between revisions
No edit summary |
(replaced raw text with mw.html) |
||
Line 9: | Line 9: | ||
--[Getting query results...] | --[Getting query results...] | ||
local name = frame | |||
local modifier = arg or '' | |||
local name = mw.text.trim(frame.args[1]) or '' | --local name = mw.text.trim(frame.args[1]) or '' | ||
local modifier = mw.text.trim(frame.args[2]) or '' | --local modifier = mw.text.trim(frame.args[2]) or '' | ||
local result = cargo.query('GeneralData','_pageName=Page, DisplayName, Image, DisplayChar',{where='_pageNamespace="0" AND PlainName="' .. name:gsub("'", "''") .. '"', default=name, limit='1'} ) | local result = cargo.query('GeneralData','_pageName=Page, DisplayName, Image, DisplayChar',{where='_pageNamespace="0" AND PlainName="' .. name:gsub("'", "''") .. '"', default=name, limit='1'} ) | ||
Line 53: | Line 53: | ||
end | 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 | end | ||
return p | return p |
Revision as of 18:04, 8 September 2019
!!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 16: attempt to call method 'gsub' (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 16: attempt to call method 'gsub' (a nil value). |
---|---|
possessive
|
makes the item name possessive while preserving the color formatting.
{{favilink | Q Girl | possessive}} Lua error at line 16: attempt to call method 'gsub' (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 16: attempt to call method 'gsub' (a nil value).
Compare to tooltip when this parameter is not specified: Lua error at line 16: attempt to call method 'gsub' (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 16: attempt to call method 'gsub' (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 16: attempt to call method 'gsub' (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 16: attempt to call method 'gsub' (a nil value). |
local p = {}
local cargo= mw.ext.cargo
local htmlparse = require'Module:HTMLParse'
local colorparse = require'Module:ColorParse'
function p.favilink(frame,arg)
local displayname_tooltip_override = false
--[Getting query results...]
local name = frame
local modifier = arg or ''
--local name = mw.text.trim(frame.args[1]) or ''
--local modifier = mw.text.trim(frame.args[2]) or ''
local result = cargo.query('GeneralData','_pageName=Page, DisplayName, Image, DisplayChar',{where='_pageNamespace="0" AND PlainName="' .. name:gsub("'", "''") .. '"', default=name, limit='1'} )
if not next(result) then
return 'There wasn\'t any results!'
end
local pagelink = result[1]['Page'] or name
local displayname = result[1]['DisplayName'] or name
local image = 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(name)
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
return p