Module:QueryBelleSummary: Difference between revisions

From Victory Belles Community Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 2: Line 2:
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo


function p.Main( frame )
function p._main( args )
print('supposed to start lua here...')
local belle = args[1] and mw.text.trim(args[1])
     local tables = 'MISC_BelleMoreInfo'
     local tables = 'MISC_BelleMoreInfo'
     local fields = 'MISC_BelleMoreInfo.TXT_Summary'
     local fields = 'MISC_BelleMoreInfo.TXT_Summary'


     local args = {
     local args = {
         where = 'FK_Belle = "{{#replace:{{PAGENAME}}|'|\'}}"',
         where = 'FK_Belle = belle',
default ='Description not defined',
default ='Description not defined',
limit = 1
limit = 1
Line 21: Line 21:
     end
     end
     end
     end
end
function p.main(frame)
return p._main(frame:getParent().args)
end
end


return p
return p

Revision as of 22:21, 1 June 2023

Description[edit source]

Retrieve a Belle's ingame Summary text. Only necessary because of a conflict between ConfirmEdit/QuestyCaptcha and Cargo that resulted in Cargo-stored text containing double quotes turning into the HTML escaped version when retrieved like the below.

Quote-fail.png

To Use[edit source]

This code was written for the NewBellePage template but if needed elsewhere, copy and paste the following.

{{#invoke:QueryBelleSummary|main|belle={{#replace:{{PAGENAME}}|'|\'}}}}

If not using the name of the page, swap PAGENAME with the Belle's name. The "replace" code is needed to handle names that contain single quotes which would otherwise cause database errors if not properly escaped prior to being queried for.

On NewBellePage, the text is also italicized.


local p = {}
local cargo = mw.ext.cargo

function p._main( args )
	local belle = args[1] and mw.text.trim(args[1])
    local tables = 'MISC_BelleMoreInfo'
    local fields = 'MISC_BelleMoreInfo.TXT_Summary'

    local args = {
        where = 'FK_Belle = belle',
		default ='Description not defined',
		limit = 1
    }
    local results = cargo.query( tables, fields, args )
    for r = 1, #results do
        local result = results[r]
        if result == nil then
        	return 'Empty Cargo...'
    	else 
        	return result.TXT_Summary
    	end
    end
end

function p.main(frame)
	return p._main(frame:getParent().args)
end

return p