Module:Favilink: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
(Have to test call parser function outside of debug console)
 
mNo edit summary
 
(76 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local cargo= mw.ext.cargo
local h = {}
local htmlparse = require'Module:HTMLParse'
local htmlparse = require'Module:HTMLParse'
local colorparse = require'Module:ColorParse'
local colorparse = require'Module:ColorParse'
local util = require'Module:Favilink Utility'
local util_args = require('Module:Args Utility')


function p.favilink(frame,arg)
function p.favilink(frame, searchtype)


--[Getting query results...]
--[Getting query results...]
--local name = frame
--local modifier = arg or ''
local name=frame.args[1] or ''
local modifier=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 name
local modifier


if not next(result) then
frame=mw.getCurrentFrame()
  return 'There wasn\'t any results!'
 
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 h.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 h.main(name, searchtype, modifier)
else 
    error "There is no argument specified! [[Category:pages with favilink errors]]"
end
end
 
function h.main(name, searchtype, modifier)
if searchtype == '_pageName' then
name = name:gsub("'", "'")
end
local result = util.favilink(name, searchtype)
 
if result ~= nil then
name = result['PlainName']
else
return '[[' .. name.. ']](favilink error!)[[Category:pages with favilink errors]]'
end
 
local pagelink = result['Page'] or name
local displayname = result['DisplayName'] or name
local displayimg = result['Display']
 
return p.format(pagelink,
displayname,
displayimg,
modifier,
name)
end
end


local pagelink = result[1]['Page'] or name
function p.format(pagelink, displayname, displayimg, modifier, name)
local displayname = result[1]['DisplayName'] or name
local displayname_tooltip_override = false
local image = result[1]['Image'] or 'None'
local display
local displaychar = result[1]['DisplayChar'] or ''
local modifier = modifier or ""
    if modifier == '' then
display = displayname
elseif 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 == 'displayname-tooltip-override' then
display = displayname
displayname_tooltip_override = true
    elseif string.sub(modifier,1,7) == 'prefix:' then
        modifier = string.sub(modifier,8)
        display = colorparse.parse('&y'..modifier..' ')..displayname
    elseif string.sub(modifier,1,7) == 'suffix:' then
        modifier = string.sub(modifier,8)
        display = displayname..colorparse.parse(' &y'..modifier)
else
display = colorparse.parse('&y'..modifier)
end


--[Setting display name modifiers...]
local img = displayimg
local display
if displayimg ~= nil then
if string.len(displayimg) > 4 then
if string.sub(displayimg, -4) == '.png' then
    img = '[[File:' .. displayimg.. '|16px|link='..pagelink..'|alt=]]'
end
end
end


if modifier == 'plural' then
local spandisplay = displayname_tooltip_override == true and '<span title="'..name..'">'..display..'</span>' or display
  local displayresult = htmlparse.pluralize( {args= {html = displayname} })
  display=displayresult


elseif modifier == 'possessive' then
local qudimage = mw.html.create('span')
  local displayresult = htmlparse.make_possessive({ args = {html = displayname} })
qudimage
  display=displayresult
        :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


elseif modifier == '' then
function p.idfavilink(frame)
  display = displayname
return p.favilink(frame,'ObjectID')
else
  display= colorparse.modulenonxmlparse(name)
end
end


local imageexists = frame:callParserFunction{name = '#ifexists', args={'File:'.. image, 'yeah', 'nah'}}
function p.pagenamefavilink(frame)
return imageexists
return p.favilink(frame,'_pageName')
--return '<span class="qud-image"><span class="qud-image-link-image-container">' .. display
end


function p.favilinkformat(frame)
return p.format(frame.args['pagelink'],
frame.args['displayname'],
frame.args['displayimg'],
frame.args['modifier'],
frame.args['name'])
end
end


function p.favilinkformatinline(frame)
local util_text = require('Module:Text Utility')
frame=mw.getCurrentFrame()
local argsstr = table.concat(frame.args, '')
local args = util_text.split(argsstr, '%s*;;;%s*')
return p.format(args[1],
args[2],
args[3],
'',
args[4])
end
return p
return p

Latest revision as of 00:22, 25 July 2023

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}}

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}}

antimatter cells

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

Q Girl's

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}}

lanterned mental aggregator

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

plasma grenade mk II

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

A really spicy meatball


local p = {}
local h = {}
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 h.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 h.main(name, searchtype, modifier)
	else  
    	error "There is no argument specified! [[Category:pages with favilink errors]]"
	end
end

function h.main(name, searchtype, modifier)
	if searchtype == '_pageName' then
		name = name:gsub("'", "&#39;")
	end
	local result = util.favilink(name, searchtype)

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

	local pagelink = result['Page'] or name
	local displayname = result['DisplayName'] or name
	local displayimg = result['Display']

	return p.format(pagelink,
					displayname,
					displayimg,
					modifier,
					name)
end

function p.format(pagelink, displayname, displayimg, modifier, name)
	local displayname_tooltip_override = false
	local display
	local modifier = modifier or ""
	
    if modifier == '' then
		display = displayname
	elseif 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 == 'displayname-tooltip-override' then
		display = displayname
		displayname_tooltip_override = true
    elseif string.sub(modifier,1,7) == 'prefix:' then
        modifier = string.sub(modifier,8)
        display = colorparse.parse('&y'..modifier..' ')..displayname
    elseif string.sub(modifier,1,7) == 'suffix:' then
        modifier = string.sub(modifier,8)
        display = displayname..colorparse.parse(' &y'..modifier)
	else
		display = colorparse.parse('&y'..modifier)
	end

	local img = displayimg
	if displayimg ~= nil then
		if string.len(displayimg) > 4 then
			if string.sub(displayimg, -4) == '.png' then
    			img = '[[File:' .. displayimg.. '|16px|link='..pagelink..'|alt=]]'
			end
		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

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

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

function p.favilinkformat(frame)
	return p.format(frame.args['pagelink'],
					frame.args['displayname'],
					frame.args['displayimg'], 
					frame.args['modifier'],
					frame.args['name'])
end

function p.favilinkformatinline(frame)
	local util_text = require('Module:Text Utility')
	frame=mw.getCurrentFrame()
	local argsstr = table.concat(frame.args, '')
	local args = util_text.split(argsstr, '%s*;;;%s*')
	return p.format(args[1],
					args[2],
					args[3], 
					'',
					args[4])
end
return p