Module:Favilink: Difference between revisions
Jump to navigation
Jump to search
(added search by alias fallthrough) |
mNo edit summary |
||
Line 43: | Line 43: | ||
wherestr = ' AND Aliases HOLDS "' .. name:gsub("'", "\'") .. '"' | wherestr = ' AND Aliases HOLDS "' .. name:gsub("'", "\'") .. '"' | ||
elseif searchtype == 'ID' then | elseif searchtype == 'ID' then | ||
wherestr = ' AND IDAliases HOLDS "' .. name:gsub("'", "\'") .. '"' | |||
end | end | ||
result = cargo.query('GeneralData','_pageName=Page, DisplayName, Image, DisplayChar, PlainName',{where='_pageNamespace="0"' .. wherestr, default=name, limit='1'} ) | result = cargo.query('GeneralData','_pageName=Page, DisplayName, Image, DisplayChar, PlainName',{where='_pageNamespace="0"' .. wherestr, default=name, limit='1'} ) | ||
if next(result) then | if not next(result) then | ||
else | |||
resulttrue = 1 | resulttrue = 1 | ||
end | end |
Revision as of 19:12, 27 October 2019
Documentation
[purge]
!!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}}
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: |
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 86: 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 86: 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 86: 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
--[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
local wherestr = ''
if (searchtype == 'PlainName') then
wherestr = ' AND PlainName="' .. name:gsub("'", "\'") .. '"'
elseif (searchtype == 'ID') then
wherestr = ' AND BINARY ObjectID="' .. name:gsub("'", "\'") .. '"'
elseif (searchtype == '_pageName') then
wherestr = ' AND _pageName="' .. name:gsub("'", "\'") .. '"'
end
local result = cargo.query('GeneralData','_pageName=Page, DisplayName, Image, DisplayChar, PlainName',{where='_pageNamespace="0"' .. wherestr, default=name, limit='1'} )
local resulttrue = 0
--[If there was no result, search by alias instead]
if not next(result) then
if searchtype == 'PlainName' then
wherestr = ' AND Aliases HOLDS "' .. name:gsub("'", "\'") .. '"'
elseif searchtype == 'ID' then
wherestr = ' AND IDAliases HOLDS "' .. name:gsub("'", "\'") .. '"'
end
result = cargo.query('GeneralData','_pageName=Page, DisplayName, Image, DisplayChar, PlainName',{where='_pageNamespace="0"' .. wherestr, default=name, limit='1'} )
if not next(result) then
else
resulttrue = 1
end
else
resulttrue = 1
end
if resulttrue == 1 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.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