Module:PastWikithons
From BASAbaliWiki
Documentation for this module may be created at Module:PastWikithons/doc
local p = {} local competitions = {} local competitionsInfo = {} function addToSet(set, key) set[key] = true end function removeFromSet(set, key) set[key] = nil end function setContains(set, key) return set[key] ~= nil end function p.display( frame ) local div = mw.html.create( 'div' ) div:addClass('wikithon-list-legacy') div:addClass('bali-wikiton-list') -- https://github.com/SemanticMediaWiki/SemanticScribunto/blob/master/docs/README.md -- build list of unique wikithons names local result = mw.smw.ask { '[[Category:Article]]', '[[Competition::+]]', '?Competition', '?Question', '?Question id', '?Question ban', '?Topic', limit = 10, mainlabel = '-' } if result and #result then for num, entityData in pairs( result ) do local c = entityData['Competition'] if not setContains(competitions, c) then addToSet(competitions, c) competitionsInfo[c] = { question = entityData['Question'], question_id = entityData['Question id'], question_ban = entityData['Question ban'], topic = entityData['Topic'] } end end end for k, v in pairs( competitions ) do local questionText = frame:preprocess( '<en>'..competitionsInfo[k].question..'</en><id>'..competitionsInfo[k].question_id..'</id><ban>'..competitionsInfo[k].question_ban..'</ban>' ) local topicImage = mw.title.makeTitle( 'File', 'Topic-'..competitionsInfo[k].topic..'.jpg') local wikithonLink = frame:callParserFunction( '#queryformlink', { 'form=Article_search', 'link text=' .. questionText, 'link type=link', 'query string=Article_search[Type]=Government&shelf=Government&_run' } ) local wikithonLinkBtn = frame:callParserFunction( '#queryformlink', { 'form=Article_search', 'link text=View', 'link type=link', 'query string=Article_search[Type]=Government&shelf=Government&_run' } ) local wikithonDiv = div:tag('div') wikithonDiv:addClass('bali-wikiton') if topicImage.file.exists then local url = frame:preprocess( '{{filepath:' .. topicImage.text .. '}}' ) wikithonDiv:attr('data-background-image', url) end --wikithonDiv:cssText('background-image: url('..topicImageUrl..')') local wikithonTags = wikithonDiv:tag('div') wikithonTags:addClass('bali-tags') local wikithonRow = wikithonDiv:tag('div') wikithonRow:addClass('bali-wikiton__row') local rowText = wikithonRow:tag('div') rowText:addClass('bali-wikiton__text') rowText:wikitext(wikithonLink) local rowBtn = wikithonRow:tag('span') rowBtn:addClass('bali-wikiton__button') rowBtn:wikitext(wikithonLinkBtn) end -- fetch wikithons artiles per wikithon --[=====[ for k, v in pairs( competitions ) do local competition = k local ulWikithon = div:tag('ul') ulWikithon:addClass('wikithon-list-legacy--item') ulWikithon:wikitext(competition) local result = mw.smw.ask { '[[Category:Article]]', '[[Competition::' .. competition ..']]', limit = 10, mainlabel = 'origin' } if result and #result then for num, entityData in pairs( result ) do local liPage = ulWikithon:tag('li') liPage:addClass('wikithon-list-legacy--page') liPage:wikitext(entityData.origin) end end end --]=====] return div end return p