Module:PublicationRecommendedItems: Difference between revisions
From MaRDI portal
Tag: Undo |
try transform to take data from wikibase |
||
| Line 1: | Line 1: | ||
local helper = require('Module:HelperMethods') | local helper = require('Module:HelperMethods') | ||
local mwHtml = require('mw.html') | local mwHtml = require('mw.html') | ||
local p = {} | local p = {} | ||
-- | ---------------------------------------------------------------------- | ||
function p. | -- Build recommendations list from direct Wikibase statements | ||
---------------------------------------------------------------------- | |||
function p.buildRecommendationList(entityId) | |||
local ul = mw.html.create('ul') | local ul = mw.html.create('ul') | ||
local likeIcon = '👍' | local likeIcon = '👍' | ||
local dislikeIcon = '👎' | local dislikeIcon = '👎' | ||
local statements = | |||
local | mw.wikibase.getBestStatements(entityId, 'P1643') | ||
if not statements or #statements == 0 then | |||
return tostring(ul) | |||
end | |||
for _, stmt in ipairs(statements) do | |||
local mainsnak = stmt.mainsnak | |||
if mainsnak | |||
and mainsnak.snaktype == 'value' | |||
and mainsnak.datavalue | |||
and mainsnak.datavalue.type == 'wikibase-entityid' | |||
then | |||
local targetQid = 'Q' .. mainsnak.datavalue.value.numeric-id | |||
local label = | |||
mw.wikibase.getLabel(targetQid) | |||
or helper.titleNotAvailableStr() | |||
local baseLink = | |||
'https://portal.mardi4nfdi.de/wiki/Publication:' | |||
.. targetQid | |||
local modifiedLink = | |||
baseLink | |||
.. '?source=recommendation&referrer=' | |||
.. entityId | |||
local currentPubLink = | |||
entityId:gsub('Q', 'Publication:') | |||
ul:node(li) | local likeLink = | ||
'https://portal.mardi4nfdi.de/wiki/' | |||
.. currentPubLink | |||
.. '?reaction=like&target=' | |||
.. targetQid | |||
local dislikeLink = | |||
'https://portal.mardi4nfdi.de/wiki/' | |||
.. currentPubLink | |||
.. '?reaction=dislike&target=' | |||
.. targetQid | |||
local li = mw.html.create('li') | |||
li:wikitext('[' .. modifiedLink .. ' ' .. label .. '] ') | |||
li:wikitext('[' .. likeLink .. ' ' .. likeIcon .. '] ') | |||
li:wikitext('[' .. dislikeLink .. ' ' .. dislikeIcon .. ']') | |||
ul:node(li) | |||
end | end | ||
end | end | ||
| Line 55: | Line 71: | ||
end | end | ||
-- | ---------------------------------------------------------------------- | ||
-- Entry point | |||
---------------------------------------------------------------------- | |||
function p.getCitesWorkList(frame) | function p.getCitesWorkList(frame) | ||
local entityId = frame.args[1] | |||
if not entityId or entityId == '' then | |||
if not | |||
return "No records found" | return "No records found" | ||
end | end | ||
local list = | |||
p.buildRecommendationList(entityId) | |||
if not list or list == '' then | |||
return nil | return nil | ||
end | |||
return [[ | |||
<div class="keywords-header"> | <div class="keywords-header"> | ||
<span class="keywords-title">Recommendations</span> | <span class="keywords-title">Recommendations</span> | ||
<div class="keywords-line"></div> | <div class="keywords-line"></div> | ||
</div> | |||
<div class="keywords-list"> | |||
]] .. list .. [[ | |||
</div> | </div> | ||
]] | ]] | ||
end | end | ||
return p | return p | ||
Revision as of 23:28, 4 January 2026
Documentation for this module may be created at Module:PublicationRecommendedItems/doc
local helper = require('Module:HelperMethods')
local mwHtml = require('mw.html')
local p = {}
----------------------------------------------------------------------
-- Build recommendations list from direct Wikibase statements
----------------------------------------------------------------------
function p.buildRecommendationList(entityId)
local ul = mw.html.create('ul')
local likeIcon = '👍'
local dislikeIcon = '👎'
local statements =
mw.wikibase.getBestStatements(entityId, 'P1643')
if not statements or #statements == 0 then
return tostring(ul)
end
for _, stmt in ipairs(statements) do
local mainsnak = stmt.mainsnak
if mainsnak
and mainsnak.snaktype == 'value'
and mainsnak.datavalue
and mainsnak.datavalue.type == 'wikibase-entityid'
then
local targetQid = 'Q' .. mainsnak.datavalue.value.numeric-id
local label =
mw.wikibase.getLabel(targetQid)
or helper.titleNotAvailableStr()
local baseLink =
'https://portal.mardi4nfdi.de/wiki/Publication:'
.. targetQid
local modifiedLink =
baseLink
.. '?source=recommendation&referrer='
.. entityId
local currentPubLink =
entityId:gsub('Q', 'Publication:')
local likeLink =
'https://portal.mardi4nfdi.de/wiki/'
.. currentPubLink
.. '?reaction=like&target='
.. targetQid
local dislikeLink =
'https://portal.mardi4nfdi.de/wiki/'
.. currentPubLink
.. '?reaction=dislike&target='
.. targetQid
local li = mw.html.create('li')
li:wikitext('[' .. modifiedLink .. ' ' .. label .. '] ')
li:wikitext('[' .. likeLink .. ' ' .. likeIcon .. '] ')
li:wikitext('[' .. dislikeLink .. ' ' .. dislikeIcon .. ']')
ul:node(li)
end
end
return tostring(ul)
end
----------------------------------------------------------------------
-- Entry point
----------------------------------------------------------------------
function p.getCitesWorkList(frame)
local entityId = frame.args[1]
if not entityId or entityId == '' then
return "No records found"
end
local list =
p.buildRecommendationList(entityId)
if not list or list == '' then
return nil
end
return [[
<div class="keywords-header">
<span class="keywords-title">Recommendations</span>
<div class="keywords-line"></div>
</div>
<div class="keywords-list">
]] .. list .. [[
</div>
]]
end
return p