Module:Favilink

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! " 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! " 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!)' 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 == '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 = displayimg if string.len(displayimg) > 4 then if string.sub(displayimg, -4) == '.png' then img = '' end end

local spandisplay = displayname_tooltip_override == true and ' '..display..' ' 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( .. 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