Difference between revisions of "Module:HonorTabs"

From Pathfinder Wiki
m ((just to add a message for the previous edit) added support for crosslink honors)
 
(115 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
 +
local honorUtils = require ( "Module:HonorUtils" )
 +
local utilities = require ( "Module:Utilities" )
 +
local C_srcIsNotHonor = false
  
function p.hello( frame )
+
function p.generateHonorTabs( frame )
return "Hello, world!"
+
local parentFrame = frame:getParent()
 +
mw.log('HonorTabs.generateHonorTabs (frame:getTitle): '..frame:getTitle())
 +
mw.log('HonorTabs.generateHonorTabs (parentFrame:getTitle): '..parentFrame:getTitle())
 +
local landingPage = parentFrame.args['landingPage']
 +
if landingPage == nil or landingPage == '' then
 +
landingPage = frame:expandTemplate{ title='GetHonorLandingPage' }
 +
landingPage = mw.ustring.gsub(landingPage,"[\n\r]", "")
 +
end
 +
 +
local langSuffix = frame:expandTemplate{ title='GetLangSuffix' }
 +
tVariants = honorUtils.getVariantsData( frame, landingPage )
 +
 +
local strActPageTitle = mw.title.getCurrentTitle().text
 +
local bIsLandingPage = false
 +
if ( strActPageTitle == landingPage ) then
 +
bIsLandingPage = true
 +
end
 +
 +
local tActVariantInfo = honorUtils.getActVariantInfo( frame )
 +
local bbIsRequirementsPage = false
 +
local bIsAnswerKeyPage = false
 +
local bIsLessonPlansPage = false
 +
local bIsWorksheetPage = false
 +
if (tActVariantInfo ~= nil) then
 +
if (tActVariantInfo['subPage'] == 'Requirements') then
 +
bIsRequirementsPage = true
 +
elseif (tActVariantInfo['subPage'] == 'Answer Key') then
 +
bIsAnswerKeyPage    = true
 +
-- if the langsuffix is empty and the variant has an source language set
 +
-- then we should use that one if my thoughts are correct
 +
if ((langSuffix == nil or langSuffix == '') and
 +
tVariants ~= nil and tVariants['answers'] ~= nil) then
 +
local variantNumber = tActVariantInfo['variantNumber']
 +
local srcLangSuffix = tVariants['answers'][variantNumber]['srcLangSuffix']
 +
mw.log('HonorTabs.generateHonorTabs: Set the langSuffix to the source language of the answer key page. srcLangSuffix: '..srcLangSuffix)
 +
langSuffix = srcLangSuffix
 +
end
 +
elseif (tActVariantInfo['subPage'] == 'Lesson Plans') then
 +
bIsLessonPlansPage = true
 +
elseif (tActVariantInfo['subPage'] == 'Worksheet') then
 +
bIsWorksheetPage  = true
 +
end
 +
end
 +
 +
local tTabsData = convertVariantsToTabs( frame, tVariants, landingPage, langSuffix )
 +
local tCrosslinkhonors = honorUtils.getCrosslinkhonorsData( frame, landingPage )
 +
local tCrosslinkhonorsTabs = convertCrosslinkhonorsToTabs( frame, tCrosslinkhonors, tVariants, landingPage, langSuffix )
 +
 +
tTabsData = mergeTabsData( tTabsData, tCrosslinkhonorsTabs )
 +
 +
local HTMLCodeString = ""
 +
-- create the overview tab
 +
HTMLCodeString = HTMLCodeString .. createDropdownTab( frame, tTabsData['overview'], 'Overview', 'Ove', bIsLandingPage)
 +
-- create requirement tab
 +
HTMLCodeString = HTMLCodeString .. createDropdownTab( frame, tTabsData['requirements'], 'Requirements', 'Req', bIsRequirementsPage)
 +
-- create answer variants tab
 +
HTMLCodeString = HTMLCodeString .. createDropdownTab( frame, tTabsData['answers'], 'Answer Key', 'Ans', bIsAnswerKeyPage)
 +
if (utilities.isSysOp() == true) then
 +
-- create lesson plans tab
 +
HTMLCodeString = HTMLCodeString .. createDropdownTab( frame, tTabsData['lessonPlans'], 'Lesson Plans', 'lesPlans', bIsLessonPlansPage)
 +
-- create worksheets tab
 +
HTMLCodeString = HTMLCodeString .. createDropdownTab( frame, tTabsData['worksheets'], 'Worksheet', 'work', bIsWorksheetPage)
 +
end
 +
 +
local tabContainer = mw.html.create( 'ul' )
 +
tabContainer
 +
:attr( 'id', 'honor-nav' )
 +
:attr( 'class', 'noprint')
 +
:wikitext( HTMLCodeString )
 +
return tostring( tabContainer )
 
end
 
end
  
function p.getLangSuffix( frame )
+
function mergeTabsData( tVariantsTabs, tCrosslinkhonorsTabs )
return frame:expandTemplate{ title = 'GetLangSuffix' }
+
tTabs = initializeTabStruct()
end
+
tTabs.overview = utilities.concatTable(tTabs.overview, tVariantsTabs.overview)
 
+
tTabs.requirements = utilities.concatTable(tTabs.requirements, tVariantsTabs.requirements)
function p.createAnswerTab( frame )
+
tTabs.answers = utilities.concatTable(tTabs.answers, tVariantsTabs.answers)
if frame.args.answerVariants then
+
tTabs.lessonPlans = utilities.concatTable(tTabs.lessonPlans, tVariantsTabs.lessonPlans)
result_string = outputVariantsTab(frame, prepareAnswerVariants( frame, frame.args.landingPage, frame.args.answerVariants))
+
tTabs.worksheets = utilities.concatTable(tTabs.worksheets, tVariantsTabs.worksheets)
return result_string
+
else
+
if (tCrosslinkhonorsTabs.overview ~= nil and tCrosslinkhonorsTabs.overview[1] ~= nil) then
return "There aren't any answer variants!"
+
tCrosslinkhonorsTabs.overview[1].showSeperatorInfront = true
 +
tTabs.overview = utilities.concatTable(tTabs.overview, tCrosslinkhonorsTabs.overview)
 +
end
 +
if (tCrosslinkhonorsTabs.requirements ~= nil and tCrosslinkhonorsTabs.requirements[1] ~= nil) then
 +
tCrosslinkhonorsTabs.requirements[1].showSeperatorInfront = true
 +
tTabs.requirements = utilities.concatTable(tTabs.requirements, tCrosslinkhonorsTabs.requirements)
 +
end
 +
if (tCrosslinkhonorsTabs.answers ~= nil and tCrosslinkhonorsTabs.answers[1] ~= nil) then
 +
tCrosslinkhonorsTabs.answers[1].showSeperatorInfront = true
 +
tTabs.answers = utilities.concatTable(tTabs.answers, tCrosslinkhonorsTabs.answers)
 +
end
 +
if (tCrosslinkhonorsTabs.lessonPlans ~= nil and tCrosslinkhonorsTabs.lessonPlans[1] ~= nil) then
 +
tCrosslinkhonorsTabs.lessonPlans[1].showSeperatorInfront = true
 +
tTabs.lessonPlans = utilities.concatTable(tTabs.lessonPlans, tCrosslinkhonorsTabs.lessonPlans)
 +
end
 +
if (tCrosslinkhonorsTabs.worksheets ~= nil and tCrosslinkhonorsTabs.worksheets[1] ~= nil) then
 +
tCrosslinkhonorsTabs.worksheets[1].showSeperatorInfront = true
 +
tTabs.worksheets = utilities.concatTable(tTabs.worksheets, tCrosslinkhonorsTabs.worksheets)
 
end
 
end
 +
 +
return tTabs
 
end
 
end
  
function prepareAnswerVariants(frame, landingPage, variants)
+
function convertVariantsToTabs( frame, tVariants, landingPage, langSuffix )
-- check the input variables
+
mw.log('HonorTabs.convertVariantsToTabs: Start converting!')
if (frame == nil or landingPage == nil or landingPage == "") then
+
tTabs = initializeTabStruct()
return "fatal error"
+
local strDefaultLinkTitle = ''
 +
if ( tVariants == nil ) then
 +
mw.log('HonorTabs.convertVariantsToTabs: invalid Variants table (nil)!')
 +
return nil;
 
end
 
end
if (variants == nil or variants == "") then
+
if ( tVariants['requirements'] == nil ) then
local linkTitle = frame:expandTemplate{ title = 'Localize', args = { 'Answer Key' } }
+
mw.log('HonorTabs.convertVariantsToTabs: No Requirement Variants! Create default Tab.')
return {url="[[" .. landingPage .. "/Answer_key" .. frame:expandTemplate{title='GetLangSuffix'} .. "|" .. linkTitle .. "]]"}
+
local pageTitle = landingPage..'/Requirements'..langSuffix
 +
local linkTitle = utilities.localize( 'GC', 'Authorities' )
 +
strDefaultLinkTitle = linkTitle
 +
-- check if Localization returned something, if not set the original string
 +
if ( linkTitle == '' ) then
 +
linkTitle = 'Requirements'
 +
end
 +
tTabs['requirements'][1] = {
 +
pageTitle = pageTitle,
 +
linkTitle = linkTitle,
 +
wikiLink = '[['..pageTitle..'|'..linkTitle..']]'
 +
}
 +
else
 +
mw.log('HonorTabs.convertVariantsToTabs: '..#tVariants['requirements']..' Requriement Variants to convert!')
 +
for varKey, variant in pairs(tVariants['requirements']) do
 +
local linkTitle = ""
 +
if ( variant['authorities'] == nil ) then
 +
mw.log('HonorTabs.convertVariantsToTabs: Invalid Requirement Variant (Authorities)!')
 +
else
 +
for authorityKey, authority in pairs(variant['authorities']) do
 +
if ( #linkTitle > 0 ) then
 +
linkTitle = linkTitle..' & '..authority['translated']
 +
else
 +
linkTitle = authority['translated']
 +
end
 +
-- add authority to the ovierview/lesson plans/worksheets link title
 +
if ( #strDefaultLinkTitle > 0 ) then
 +
strDefaultLinkTitle = strDefaultLinkTitle..' & '..authority['translated']
 +
else
 +
strDefaultLinkTitle = authority['translated']
 +
end
 +
end
 +
end
 +
local strVariantNumber = ''
 +
-- add number only for variants bigger than 1
 +
if varKey > 1 then
 +
strVariantNumber = '_'..varKey
 +
end
 +
local pageTitle = landingPage..'/Requirements'..strVariantNumber..langSuffix
 +
tTabs['requirements'][varKey] = {
 +
pageTitle = pageTitle,
 +
linkTitle = linkTitle,
 +
wikiLink = '[['..pageTitle..'|'..linkTitle..']]'
 +
}
 +
mw.log('HonorTabs.convertVariantsToTabs (Tab URL '..varKey..': '..tTabs['requirements'][varKey]['wikiLink'])
 +
end
 +
mw.log('HonorTabs.convertVariantsToTabs: '..#tTabs['requirements']..' Requirement Variants were converted to Tabs!')
 
end
 
end
+
if ( tVariants['answers'] == nil ) then
-- get the variants
+
mw.log('HonorTabs.convertVariantsToTabs: No Answer Variants! Check if there is a Requirement Variant to get the Authority.')
local t_variants = explode(";;", variants)
+
local linkTitle = ''
+
if ( tVariants['requirements'] ~= nil ) then
-- get the subvariants & translate it
+
-- as no answer variant is defined we just use the first requirement variant of the honor
for key, variant in pairs(t_variants) do
+
local reqVariant = tVariants['requirements'][1]
t_variants[key] = {
+
if (reqVariant['authorities'] ~= nil ) then
orig = variant,
+
for authorityKey, authority in pairs(reqVariant['authorities']) do
split = explode(";", variant)
+
if ( #linkTitle > 0 ) then
 +
linkTitle = linkTitle..' & '..authority['translated']
 +
else
 +
linkTitle = authority['translated']
 +
end
 +
end
 +
end
 +
end
 +
 +
if ( linkTitle == '' ) then
 +
mw.log('HonorTabs.convertVariantsToTabs: No Requirement Variants to set answer variants text, so default to GC!')
 +
linkTitle = utilities.localize( 'GC', 'Authorities' )
 +
end
 +
local pageTitle = landingPage..'/Answer_Key'..langSuffix
 +
tTabs['answers'][1] = {
 +
pageTitle = pageTitle,
 +
linkTitle = linkTitle,
 +
wikiLink = '[['..pageTitle..'|'..linkTitle..']]'
 
}
 
}
for subkey, subVariant in pairs(t_variants[key]['split']) do
+
else
local trans = frame:expandTemplate{ title = 'Localize', args = { subVariant, 'Answer Variants' } }
+
mw.log('HonorTabs.convertVariantsToTabs: '..#tVariants['answers']..' Answer Variants to convert!')
local t_splitTrans = {
+
for varKey, variant in pairs(tVariants['answers']) do
orig = subVariant,
+
local linkTitle = ""
translation = trans
+
if ( variant['countries'] == nil or variant['countries']['split'] == nil) then
 +
mw.log('HonorTabs.convertVariantsToTabs: There are probably no Countries defined or something went horribly wrong!')
 +
else
 +
for countryKey, country in pairs(variant['countries']['split']) do
 +
if ( #linkTitle > 0 ) then
 +
linkTitle = linkTitle..' & '..country['translated']
 +
else
 +
linkTitle = country['translated']
 +
end
 +
end
 +
end
 +
if ( variant['authority'] == nil ) then
 +
mw.log('HonorTabs.convertVariantsToTabs: No Authority for this variant!')
 +
else
 +
mw.log('HonorTabs.convertVariantsToTabs (variant["authority"]): '..variant['authority'])
 +
-- get the authority
 +
local authority = tVariants['requirements'][tonumber(variant['authority'])]['authorities'][1]['translated']
 +
-- check if there are countries if not, parentheses are not needed
 +
if ( linkTitle == '' ) then
 +
linkTitle = authority
 +
else
 +
-- if there is only one requirement variant, don't show the authority (it's the only one available)
 +
if ( #tTabs['requirements'] > 1 ) then
 +
linkTitle = linkTitle..' ('..authority..')'
 +
else
 +
mw.log("HonorTabs.convertVariantsToTabs: Authority wasn't added, because there is only one!")
 +
end
 +
end
 +
end
 +
local strVariantNumber = ''
 +
-- add number only for variants bigger than 1
 +
if varKey > 1 then
 +
strVariantNumber = '_'..varKey
 +
end
 +
local locLangSuffix = langSuffix
 +
if ( variant['srcLangSuffix'] == locLangSuffix ) then
 +
-- Source Language of the answer key is the same than the content language in use
 +
-- that the link doesn't lead to the copy of the translation extension
 +
-- the langSuffix needs to be removed
 +
locLangSuffix = ''
 +
elseif ( variant['srcLangSuffix'] ~= '' and locLangSuffix == '' ) then
 +
-- Source Language is set and locLangSuffix is an empty string
 +
-- as the locLangSuffix is empty the current content language is english
 +
-- so we need to add /en to the link of this variant because it's source language
 +
-- is NOT english (source language pages have NO language suffix)
 +
locLangSuffix = '/en'
 +
end
 +
local pageTitle = landingPage..'/Answer_Key'..strVariantNumber..locLangSuffix
 +
tTabs['answers'][varKey] = {
 +
pageTitle = pageTitle,
 +
linkTitle = linkTitle,
 +
wikiLink = '[['..pageTitle..'|'..linkTitle..']]'
 
}
 
}
t_variants[key]['split'][subkey] = t_splitTrans
+
mw.log('HonorTabs.convertVariantsToTabs (Tab URL '..varKey..': '..tTabs['answers'][varKey]['wikiLink'])
 
end
 
end
 +
mw.log('HonorTabs.convertVariantsToTabs: '..#tTabs['answers']..' Answer Variants were converted to Tabs!')
 
end
 
end
 
 
-- assamble link
+
local tDefaultTabs = {
for key, variant in pairs(t_variants) do
+
{
linkTitle = ""
+
subPage = '', --overview or landingPage
local len = #linkTitle
+
tabsTableName = 'overview'
for subkey, subvariant in pairs(t_variants[key]['split']) do
+
},
if (#linkTitle > 0) then
+
{
linkTitle = linkTitle .. " & " .. subvariant['translation']
+
subPage = '/Lesson Plans',
else
+
tabsTableName = 'lessonPlans'
linkTitle = subvariant['translation']
+
},
 +
{
 +
subPage = '/Worksheets',
 +
tabsTableName = 'worksheets'
 +
}
 +
}
 +
for i=1, #tDefaultTabs do
 +
local tDefaultTabData = {
 +
pageTitle = landingPage..tDefaultTabs[i].subPage..langSuffix,
 +
linkTitle = strDefaultLinkTitle,
 +
wikiLink = '[['..landingPage..tDefaultTabs[i].subPage..langSuffix..'|'..strDefaultLinkTitle..']]'
 +
}
 +
table.insert(tTabs[tDefaultTabs[i].tabsTableName], tDefaultTabData)
 +
end
 +
return tTabs
 +
end
 +
 
 +
function convertCrosslinkhonorsToTabs( frame, tCrosslinkhonors, tVariants, landingPage, langSuffix )
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs: Start converting!')
 +
tTabs = initializeTabStruct()
 +
if ( tCrosslinkhonors == nil or #tCrosslinkhonors <= 0 ) then
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs: No Crosslinkhonors to convert!')
 +
return tTabs
 +
end
 +
--clh = crosslinkhonor
 +
for clhKey, crosslinkhonor in pairs(tCrosslinkhonors) do
 +
if (crosslinkhonor.tVariants == nil) then
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs: Crosslinkhonor has no Variants!')
 +
end
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (crosslinkhonor.name): '..crosslinkhonor.name)
 +
strClhLandingPage = frame:expandTemplate{
 +
title='GetHonorLandingPage',
 +
args = { honor = crosslinkhonor.name }
 +
}
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (strClhLandingPage): '..strClhLandingPage)
 +
 +
local strClhDefaultLinkTitle = ''
 +
if ( crosslinkhonor.tVariants['requirements'] == nil ) then
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs: No Requirement Variants! Create default entry.')
 +
local strDefaultAuth = utilities.localize( 'GC', 'Authorities' )
 +
strClhDefaultLinkTitle = strDefaultAuth
 +
local pageTitle = strClhLandingPage..'/Requirements'..langSuffix
 +
table.insert(tTabs.requirements, {
 +
pageTitle = pageTitle,
 +
linkTitle = strDefaultAuth,
 +
wikiLink = '[['..pageTitle..'|'..strDefaultAuth..']]'
 +
})
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (requirement default pageTitle): '..pageTitle)
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (requirement default linkTitle): '..strDefaultAuth)
 +
else
 +
for varKey, variant in pairs(crosslinkhonor.tVariants['requirements']) do
 +
local linkTitle = ""
 +
if ( variant['authorities'] == nil ) then
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs: Invalid Requirement Variant (Authorities)!')
 +
else
 +
for authorityKey, authority in pairs(variant['authorities']) do
 +
if ( #linkTitle > 0 ) then
 +
linkTitle = linkTitle..' & '..authority['translated']
 +
else
 +
linkTitle = authority['translated']
 +
end
 +
-- add authority to the ovierview/lesson plans/worksheets link title
 +
if ( #strClhDefaultLinkTitle > 0 ) then
 +
strClhDefaultLinkTitle = strClhDefaultLinkTitle..' & '..authority['translated']
 +
else
 +
strClhDefaultLinkTitle = authority['translated']
 +
end
 +
end
 +
end
 +
 +
local strVariantNumber = ''
 +
-- add number only for variants bigger than 1
 +
if varKey > 1 then
 +
strVariantNumber = '_'..varKey
 +
end
 +
 +
local pageTitle = strClhLandingPage..'/Requirements'..strVariantNumber..langSuffix
 +
table.insert(tTabs.requirements, {
 +
pageTitle = pageTitle,
 +
linkTitle = linkTitle,
 +
wikiLink = '[['..pageTitle..'|'..linkTitle..']]',
 +
})
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (requirement '..varKey..' pageTitle): '..pageTitle)
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (requirement '..varKey..' linkTitle): '..linkTitle)
 +
end
 +
end
 +
 +
if ( crosslinkhonor.tVariants['answers'] == nil ) then
 +
local linkTitle = ''
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs: No Answer Variants! Check if there is a Requirement Variant to get the Authority.')
 +
if ( crosslinkhonor.tVariants['requirements'] ~= nil ) then
 +
-- as no answer variant is defined we just use the first requirement variant of the honor
 +
local reqVariant = crosslinkhonor.tVariants['requirements'][1]
 +
if (reqVariant['authorities'] ~= nil ) then
 +
for authorityKey, authority in pairs(reqVariant['authorities']) do
 +
if ( #linkTitle > 0 ) then
 +
linkTitle = linkTitle..' & '..authority['translated']
 +
else
 +
linkTitle = authority['translated']
 +
end
 +
end
 +
end
 +
end
 +
 +
if ( linkTitle == '' ) then
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs: No Requirement Variants to set answer variants text, so default to GC!')
 +
linkTitle = utilities.localize( 'GC', 'Authorities' )
 +
end
 +
local pageTitle = strClhLandingPage..'/Answer Key'..langSuffix
 +
table.insert(tTabs.answers, {
 +
pageTitle = pageTitle,
 +
linkTitle = linkTitle,
 +
wikiLink = '[['..pageTitle..'|'..linkTitle..']]',
 +
})
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (answer default pageTitle): '..pageTitle)
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (answer default linkTitle): '..linkTitle)
 +
else
 +
for varKey, variant in pairs(crosslinkhonor.tVariants['answers']) do
 +
local linkTitle = ''
 +
if ( variant['countries'] == nil or variant['countries']['split'] == nil) then
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs: There are probably no Countries defined or something went horribly wrong!')
 +
else
 +
for countryKey, country in pairs(variant['countries']['split']) do
 +
if ( #linkTitle > 0 ) then
 +
linkTitle = linkTitle..' & '..country['translated']
 +
else
 +
linkTitle = country['translated']
 +
end
 +
end
 +
end
 +
if ( variant['authority'] == nil ) then
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs: No Authority for this variant!')
 +
else
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (variant["authority"]): '..variant['authority'])
 +
-- get the authority
 +
mw.log('*DEBUG* '..tostring(crosslinkhonor.tVariants['requirements']))
 +
mw.log('*DEBUG* '..tostring(#crosslinkhonor.tVariants['requirements']))
 +
mw.log('*DEBUG* '..tostring(crosslinkhonor.tVariants['requirements'][tonumber(variant['authority'])]))
 +
mw.log('*DEBUG* '..tostring(crosslinkhonor.tVariants['requirements'][tonumber(variant['authority'])]['authorities']))
 +
mw.log('*DEBUG* '..tostring(crosslinkhonor.tVariants['requirements'][tonumber(variant['authority'])]['authorities'][1]))
 +
mw.log('*DEBUG* '..tostring(crosslinkhonor.tVariants['requirements'][tonumber(variant['authority'])]['authorities'][1]['translated']))
 +
local authority = crosslinkhonor.tVariants['requirements'][tonumber(variant['authority'])]['authorities'][1]['translated']
 +
-- check if there are countries if not, parentheses are not needed
 +
if ( linkTitle == '' ) then
 +
linkTitle = authority
 +
else
 +
linkTitle = linkTitle..' ('..authority..')'
 +
end
 +
end
 +
local strVariantNumber = ''
 +
-- add number only for variants bigger than 1
 +
if varKey > 1 then
 +
strVariantNumber = '_'..varKey
 +
end
 +
local locLangSuffix = langSuffix
 +
if ( variant['srcLangSuffix'] == locLangSuffix ) then
 +
-- Source Language of the answer key is the same than the content language in use
 +
-- that the link doesn't lead to the copy of the translation extension
 +
-- the langSuffix needs to be removed
 +
locLangSuffix = ''
 +
elseif ( variant['srcLangSuffix'] ~= '' and locLangSuffix == '' ) then
 +
-- Source Language is set and locLangSuffix is an empty string
 +
-- as the locLangSuffix is empty the current content language is english
 +
-- so we need to add /en to the link of this variant because it's source language
 +
-- is NOT english (source language pages have NO language suffix)
 +
locLangSuffix = '/en'
 +
end
 +
local pageTitle = landingPage..'/Answer_Key'..strVariantNumber..locLangSuffix
 +
table.insert(tTabs.answers, {
 +
pageTitle = pageTitle,
 +
linkTitle = linkTitle,
 +
wikiLink = '[['..pageTitle..'|'..linkTitle..']]'
 +
})
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (answer '..varKey..' pageTitle): '..pageTitle)
 +
mw.log('HonorTabs.convertCrosslinkhonorsToTabs (answer '..varKey..' linkTitle): '..linkTitle)
 
end
 
end
 
end
 
end
t_variants[key]['url'] = "[[" .. landingPage .. " (" .. variant['orig'] .. ")/Answer_key" .. frame:expandTemplate{title='GetLangSuffix'} .. "|" .. linkTitle .. "]]"
+
 +
local tDefaultTabs = {
 +
{
 +
subPage = '', --overview or landingPage
 +
tabsTableName = 'overview'
 +
},
 +
{
 +
subPage = '/Lesson Plans',
 +
tabsTableName = 'lessonPlans'
 +
},
 +
{
 +
subPage = '/Worksheets',
 +
tabsTableName = 'worksheets'
 +
}
 +
}
 +
for i=1, #tDefaultTabs do
 +
local tDefaultTabData = {
 +
pageTitle = strClhLandingPage..tDefaultTabs[i].subPage..langSuffix,
 +
linkTitle = strClhDefaultLinkTitle,
 +
wikiLink = '[['..strClhLandingPage..tDefaultTabs[i].subPage..langSuffix..'|'..strClhDefaultLinkTitle..']]'
 +
}
 +
table.insert(tTabs[tDefaultTabs[i].tabsTableName], tDefaultTabData)
 +
end
 
end
 
end
+
return tTabs
return t_variants
+
end
 +
 
 +
function createSimpleTab( wikiLink )
 +
local HTMLCode = mw.html.create( 'li' )
 +
HTMLCode
 +
:addClass( 'honor-nav-item' )
 +
:wikitext( wikiLink )
 +
return tostring( HTMLCode )
 
end
 
end
  
function outputVariantsTab(frame, variants)
+
function createDropdownTab ( frame, tConfig, text, id, isSelflink )
 
local HTMLCode = ""
 
local HTMLCode = ""
 
local HTMLCodeString = ""
 
local HTMLCodeString = ""
if (variants == nil or #variants < 1) then  
+
if ( tConfig == nil ) then
-- should not happen!
+
mw.log('HonorTabs.createDropdownTab: Invalid Tab Config (nil)!')
elseif (#variants == 1) then
+
elseif ( #tConfig < 1 ) then
HTMLCode = mw.html.create( 'li' )
+
mw.log('HonorTabs.createDropdownTab: Invalid Tab Config (< 1)!')
HTMLCode
+
elseif ( #tConfig == 1 ) then
:addClass( 'honor-nav-item' )
+
mw.log('HonorTabs.createDropdownTab (num, text, id, isSelflink): 1 Option, '..text..', '..id..', '..tostring(isSelflink))
:wikitext( variants[1].url )
+
local transText = utilities.localize( text )
HTMLCodeString = tostring( HTMLCode )
+
-- check if Localization returned something, if not set the original string
 +
if ( transText == '' ) then
 +
transText = text
 +
end
 +
HTMLCodeString = createSimpleTab( '[['..tConfig[1].pageTitle..'|'..transText..']]' )
 
else
 
else
 +
mw.log('HonorTabs.createDropdownTab (num, text, id, isSelflink): '..#tConfig..' Options, '..text..', '..id..', '..tostring(isSelflink))
 
-- now there should be more then 1 variants
 
-- now there should be more then 1 variants
 
local HTMLTabParent = mw.html.create( 'li' )
 
local HTMLTabParent = mw.html.create( 'li' )
 +
local buttonArgs = {}
 +
buttonArgs['tagname'] = 'button'
 +
buttonArgs['class'] = 'dropdown-toggle'
 +
if (isSelflink == true) then
 +
buttonArgs['class'] = buttonArgs['class'] .. ' selflink'
 +
end
 +
buttonArgs['type'] = 'button'
 +
buttonArgs['id'] = 'dropdown'..id..'Keys'
 +
buttonArgs['data-toggle'] = 'dropdown'
 +
buttonArgs['aria-haspopup'] = 'true'
 +
buttonArgs['aria-expanded'] = 'false'
 +
buttonText = utilities.localize( text )
 +
-- check if Localization returned something, if not set the original string
 +
if ( buttonText == '' ) then
 +
buttonText = text
 +
end
 +
local dropdownButton = frame:extensionTag('htmltag', buttonText, buttonArgs)
 
HTMLTabParent
 
HTMLTabParent
 
:addClass( 'honor-nav-item' )
 
:addClass( 'honor-nav-item' )
 
:addClass( 'dropdown' )
 
:addClass( 'dropdown' )
:wikitext( frame:expandTemplate{title='User:DesignerThan/Button'} )
+
:wikitext( dropdownButton )
 
 
 
HTMLVariantsContainer = mw.html.create( 'div' )
 
HTMLVariantsContainer = mw.html.create( 'div' )
 
HTMLVariantsContainer
 
HTMLVariantsContainer
 
:addClass( 'dropdown-menu' )
 
:addClass( 'dropdown-menu' )
:attr( 'aria-labelledby', 'dropdownAnswerKeys')
+
:attr( 'aria-labelledby', 'dropdown'..id..'Keys')
for key, variant in pairs(variants) do
+
for key, tab in pairs(tConfig) do
 +
if (tab.showSeperatorInfront == true) then
 +
HTMLSeperator = mw.html.create( 'div' )
 +
HTMLSeperator
 +
:addClass('dropdown-divider')
 +
HTMLVariantsContainer:node( HTMLSeperator )
 +
end
 
HTMLVariantLink = mw.html.create( 'span' )
 
HTMLVariantLink = mw.html.create( 'span' )
 
HTMLVariantLink
 
HTMLVariantLink
 
:addClass( 'dropdown-item' )
 
:addClass( 'dropdown-item' )
:wikitext( variant.url )
+
:wikitext( tab.wikiLink )
 
:done()
 
:done()
 
HTMLVariantsContainer:node( HTMLVariantLink )
 
HTMLVariantsContainer:node( HTMLVariantLink )
Line 100: Line 540:
 
end
 
end
 
return HTMLCodeString
 
return HTMLCodeString
 +
end
 +
 +
function generateTabURL( frame, page, langSuffix, text )
 +
-- check inputs
 +
if ( page == nil or page == "" ) then return 'fatal error' end
 +
 +
local transText = utilities.localize( text )
 +
-- check if Localization returned something, if not set the original string
 +
if ( transText == '' ) then
 +
transText = text
 +
end
 +
 +
return '[[' .. page .. langSuffix .. '|' .. transText .. ']]'
 
end
 
end
  
-- explode(seperator, string)
+
function initializeTabStruct()
function explode(seperator,str)
+
return {
  local t, ll
+
overview = {},
  t={}
+
answers = {},
  ll=0
+
requirements = {},
  if(#str == 1) then
+
lessonPlans = {},
      return {str}
+
worksheets = {}
  end
+
}
  while true do
 
      l = string.find(str, seperator, ll, true) -- find the next d in the string
 
      if l ~= nil then -- if "not not" found then..
 
        table.insert(t, string.sub(str,ll,l-1)) -- Save it in our array.
 
        ll = l + string.len(seperator) -- save just after where we found it for searching next time.
 
      else
 
        table.insert(t, string.sub(str,ll)) -- Save what's left in our array.
 
        break -- Break at end, as it should be, according to the lua manual.
 
      end
 
  end
 
  return t
 
 
end
 
end
  
 
return p
 
return p

Latest revision as of 19:07, 5 September 2021

Documentation for this module may be created at Module:HonorTabs/doc

local p = {}
local honorUtils = require ( "Module:HonorUtils" )
local utilities = require ( "Module:Utilities" )
local C_srcIsNotHonor = false

function p.generateHonorTabs( frame )
	local parentFrame = frame:getParent()
	mw.log('HonorTabs.generateHonorTabs (frame:getTitle): '..frame:getTitle())
	mw.log('HonorTabs.generateHonorTabs (parentFrame:getTitle): '..parentFrame:getTitle())
	local landingPage = parentFrame.args['landingPage']
	if landingPage == nil or landingPage == '' then
		landingPage = frame:expandTemplate{ title='GetHonorLandingPage' }
		landingPage = mw.ustring.gsub(landingPage,"[\n\r]", "")
	end
	
	local langSuffix = frame:expandTemplate{ title='GetLangSuffix' }
	tVariants = honorUtils.getVariantsData( frame, landingPage )
	
	local strActPageTitle = mw.title.getCurrentTitle().text
	local bIsLandingPage = false
	if ( strActPageTitle == landingPage ) then
		bIsLandingPage = true
	end
	
	local tActVariantInfo = honorUtils.getActVariantInfo( frame )
	local bbIsRequirementsPage	= false
	local bIsAnswerKeyPage		= false
	local bIsLessonPlansPage	= false
	local bIsWorksheetPage		= false
	if (tActVariantInfo ~= nil) then
		if (tActVariantInfo['subPage'] == 'Requirements') then
			bIsRequirementsPage	= true
		elseif (tActVariantInfo['subPage'] == 'Answer Key') then
			bIsAnswerKeyPage    = true
			-- if the langsuffix is empty and the variant has an source language set
			-- then we should use that one if my thoughts are correct
			if ((langSuffix == nil or langSuffix == '') and 
				tVariants ~= nil and tVariants['answers'] ~= nil) then
				local variantNumber = tActVariantInfo['variantNumber']
				local srcLangSuffix = tVariants['answers'][variantNumber]['srcLangSuffix']
				mw.log('HonorTabs.generateHonorTabs: Set the langSuffix to the source language of the answer key page. srcLangSuffix: '..srcLangSuffix)
				langSuffix = srcLangSuffix
				end
		elseif (tActVariantInfo['subPage'] == 'Lesson Plans') then
			bIsLessonPlansPage = true
		elseif (tActVariantInfo['subPage'] == 'Worksheet') then
			bIsWorksheetPage   = true
		end
	end
	
	local tTabsData = convertVariantsToTabs( frame, tVariants, landingPage, langSuffix )
	local tCrosslinkhonors = honorUtils.getCrosslinkhonorsData( frame, landingPage )
	local tCrosslinkhonorsTabs = convertCrosslinkhonorsToTabs( frame, tCrosslinkhonors, tVariants, landingPage, langSuffix )
	
	tTabsData = mergeTabsData( tTabsData, tCrosslinkhonorsTabs )
	
	local HTMLCodeString = ""
	-- create the overview tab
	HTMLCodeString = HTMLCodeString .. createDropdownTab( frame, tTabsData['overview'], 'Overview', 'Ove', bIsLandingPage)
	-- create requirement tab
	HTMLCodeString = HTMLCodeString .. createDropdownTab( frame, tTabsData['requirements'], 'Requirements', 'Req', bIsRequirementsPage)
	-- create answer variants tab
	HTMLCodeString = HTMLCodeString .. createDropdownTab( frame, tTabsData['answers'], 'Answer Key', 'Ans', bIsAnswerKeyPage)
	if (utilities.isSysOp() == true) then
		-- create lesson plans tab
		HTMLCodeString = HTMLCodeString .. createDropdownTab( frame, tTabsData['lessonPlans'], 'Lesson Plans', 'lesPlans', bIsLessonPlansPage)
		-- create worksheets tab
		HTMLCodeString = HTMLCodeString .. createDropdownTab( frame, tTabsData['worksheets'], 'Worksheet', 'work', bIsWorksheetPage)
	end
	
	local tabContainer = mw.html.create( 'ul' )
	tabContainer
		:attr( 'id', 'honor-nav' )
		:attr( 'class', 'noprint')
		:wikitext( HTMLCodeString )
	return tostring( tabContainer )
end

function mergeTabsData( tVariantsTabs, tCrosslinkhonorsTabs )
	tTabs = initializeTabStruct()
	tTabs.overview		= utilities.concatTable(tTabs.overview, tVariantsTabs.overview)
	tTabs.requirements	= utilities.concatTable(tTabs.requirements, tVariantsTabs.requirements)
	tTabs.answers		= utilities.concatTable(tTabs.answers, tVariantsTabs.answers)
	tTabs.lessonPlans	= utilities.concatTable(tTabs.lessonPlans, tVariantsTabs.lessonPlans)
	tTabs.worksheets	= utilities.concatTable(tTabs.worksheets, tVariantsTabs.worksheets)
	
	if (tCrosslinkhonorsTabs.overview ~= nil and tCrosslinkhonorsTabs.overview[1] ~= nil) then
		tCrosslinkhonorsTabs.overview[1].showSeperatorInfront = true
		tTabs.overview = utilities.concatTable(tTabs.overview, tCrosslinkhonorsTabs.overview)
	end
	if (tCrosslinkhonorsTabs.requirements ~= nil and tCrosslinkhonorsTabs.requirements[1] ~= nil) then
		tCrosslinkhonorsTabs.requirements[1].showSeperatorInfront = true
		tTabs.requirements = utilities.concatTable(tTabs.requirements, tCrosslinkhonorsTabs.requirements)
	end
	if (tCrosslinkhonorsTabs.answers ~= nil and tCrosslinkhonorsTabs.answers[1] ~= nil) then
		tCrosslinkhonorsTabs.answers[1].showSeperatorInfront = true
		tTabs.answers = utilities.concatTable(tTabs.answers, tCrosslinkhonorsTabs.answers)
	end
	if (tCrosslinkhonorsTabs.lessonPlans ~= nil and tCrosslinkhonorsTabs.lessonPlans[1] ~= nil) then
		tCrosslinkhonorsTabs.lessonPlans[1].showSeperatorInfront = true
		tTabs.lessonPlans = utilities.concatTable(tTabs.lessonPlans, tCrosslinkhonorsTabs.lessonPlans)
	end
	if (tCrosslinkhonorsTabs.worksheets ~= nil and tCrosslinkhonorsTabs.worksheets[1] ~= nil) then
		tCrosslinkhonorsTabs.worksheets[1].showSeperatorInfront = true
		tTabs.worksheets = utilities.concatTable(tTabs.worksheets, tCrosslinkhonorsTabs.worksheets)
	end
	
	return tTabs
end

function convertVariantsToTabs( frame, tVariants, landingPage, langSuffix )
	mw.log('HonorTabs.convertVariantsToTabs: Start converting!')
	tTabs = initializeTabStruct()
	local strDefaultLinkTitle = ''
	if ( tVariants == nil ) then
		mw.log('HonorTabs.convertVariantsToTabs: invalid Variants table (nil)!')
		return nil;
	end
	if ( tVariants['requirements'] == nil ) then
		mw.log('HonorTabs.convertVariantsToTabs: No Requirement Variants! Create default Tab.')
		local pageTitle = landingPage..'/Requirements'..langSuffix
		local linkTitle = utilities.localize( 'GC', 'Authorities' )
		strDefaultLinkTitle = linkTitle
		-- check if Localization returned something, if not set the original string
		if ( linkTitle == '' ) then
			linkTitle = 'Requirements'
		end
		tTabs['requirements'][1] = {
			pageTitle = pageTitle,
			linkTitle = linkTitle,
			wikiLink = '[['..pageTitle..'|'..linkTitle..']]'
		}
	else
		mw.log('HonorTabs.convertVariantsToTabs: '..#tVariants['requirements']..' Requriement Variants to convert!')
		for varKey, variant in pairs(tVariants['requirements']) do
			local linkTitle = ""
			if ( variant['authorities'] == nil ) then
				mw.log('HonorTabs.convertVariantsToTabs: Invalid Requirement Variant (Authorities)!')
			else
				for authorityKey, authority in pairs(variant['authorities']) do
					if ( #linkTitle > 0 ) then
						linkTitle = linkTitle..' & '..authority['translated']
					else
						linkTitle = authority['translated']
					end
					-- add authority to the ovierview/lesson plans/worksheets link title
					if ( #strDefaultLinkTitle > 0 ) then
						strDefaultLinkTitle = strDefaultLinkTitle..' & '..authority['translated']
					else
						strDefaultLinkTitle = authority['translated']
					end
				end
			end
			local strVariantNumber = ''
			-- add number only for variants bigger than 1
			if varKey > 1 then
				strVariantNumber = '_'..varKey
			end
			local pageTitle = landingPage..'/Requirements'..strVariantNumber..langSuffix
			tTabs['requirements'][varKey] = {
				pageTitle = pageTitle,
				linkTitle = linkTitle,
				wikiLink = '[['..pageTitle..'|'..linkTitle..']]'
			}
			mw.log('HonorTabs.convertVariantsToTabs (Tab URL '..varKey..': '..tTabs['requirements'][varKey]['wikiLink'])
		end
		mw.log('HonorTabs.convertVariantsToTabs: '..#tTabs['requirements']..' Requirement Variants were converted to Tabs!')
	end
	if ( tVariants['answers'] == nil ) then
		mw.log('HonorTabs.convertVariantsToTabs: No Answer Variants! Check if there is a Requirement Variant to get the Authority.')
		local linkTitle = ''
		if ( tVariants['requirements'] ~= nil ) then
			-- as no answer variant is defined we just use the first requirement variant of the honor
			local reqVariant = tVariants['requirements'][1]
			if (reqVariant['authorities'] ~= nil ) then
				for authorityKey, authority in pairs(reqVariant['authorities']) do
					if ( #linkTitle > 0 ) then
						linkTitle = linkTitle..' & '..authority['translated']
					else
						linkTitle = authority['translated']
					end
				end
			end
		end
		
		if ( linkTitle == '' ) then
			mw.log('HonorTabs.convertVariantsToTabs: No Requirement Variants to set answer variants text, so default to GC!')
			linkTitle = utilities.localize( 'GC', 'Authorities' )
		end
		local pageTitle = landingPage..'/Answer_Key'..langSuffix
		tTabs['answers'][1] = {
			pageTitle = pageTitle,
			linkTitle = linkTitle,
			wikiLink = '[['..pageTitle..'|'..linkTitle..']]'
		}
	else
		mw.log('HonorTabs.convertVariantsToTabs: '..#tVariants['answers']..' Answer Variants to convert!')
		for varKey, variant in pairs(tVariants['answers']) do
			local linkTitle = ""
			if ( variant['countries'] == nil or variant['countries']['split'] == nil) then
				mw.log('HonorTabs.convertVariantsToTabs: There are probably no Countries defined or something went horribly wrong!')
			else
				for countryKey, country in pairs(variant['countries']['split']) do
					if ( #linkTitle > 0 ) then
						linkTitle = linkTitle..' & '..country['translated']
					else
						linkTitle = country['translated']
					end
				end
			end
			if ( variant['authority'] == nil ) then
				mw.log('HonorTabs.convertVariantsToTabs: No Authority for this variant!')
			else
				mw.log('HonorTabs.convertVariantsToTabs (variant["authority"]): '..variant['authority'])
				-- get the authority
				local authority = tVariants['requirements'][tonumber(variant['authority'])]['authorities'][1]['translated']
				-- check if there are countries if not, parentheses are not needed
				if ( linkTitle == '' ) then
					linkTitle = authority
				else
					-- if there is only one requirement variant, don't show the authority (it's the only one available)
					if ( #tTabs['requirements'] > 1 ) then
						linkTitle = linkTitle..' ('..authority..')'
					else
						mw.log("HonorTabs.convertVariantsToTabs: Authority wasn't added, because there is only one!")
					end
				end
			end
			local strVariantNumber = ''
			-- add number only for variants bigger than 1
			if varKey > 1 then
				strVariantNumber = '_'..varKey
			end
			local locLangSuffix = langSuffix
			if ( variant['srcLangSuffix'] == locLangSuffix ) then
				-- Source Language of the answer key is the same than the content language in use
				-- that the link doesn't lead to the copy of the translation extension
				-- the langSuffix needs to be removed
				locLangSuffix = ''
			elseif ( variant['srcLangSuffix'] ~= '' and locLangSuffix == '' ) then
				-- Source Language is set and locLangSuffix is an empty string
				-- as the locLangSuffix is empty the current content language is english
				-- so we need to add /en to the link of this variant because it's source language
				-- is NOT english (source language pages have NO language suffix)
				locLangSuffix = '/en'
			end
			local pageTitle = landingPage..'/Answer_Key'..strVariantNumber..locLangSuffix
			tTabs['answers'][varKey] = {
				pageTitle = pageTitle,
				linkTitle = linkTitle,
				wikiLink = '[['..pageTitle..'|'..linkTitle..']]'
			}
			mw.log('HonorTabs.convertVariantsToTabs (Tab URL '..varKey..': '..tTabs['answers'][varKey]['wikiLink'])
		end
		mw.log('HonorTabs.convertVariantsToTabs: '..#tTabs['answers']..' Answer Variants were converted to Tabs!')
	end
	
	local tDefaultTabs = {
		{
			subPage = '', --overview or landingPage
			tabsTableName = 'overview'
		},
		{
			subPage = '/Lesson Plans',
			tabsTableName = 'lessonPlans'
		},
		{
			subPage = '/Worksheets',
			tabsTableName = 'worksheets'
		}
	}
	for i=1, #tDefaultTabs do
		local tDefaultTabData = {
			pageTitle = landingPage..tDefaultTabs[i].subPage..langSuffix,
			linkTitle = strDefaultLinkTitle,
			wikiLink = '[['..landingPage..tDefaultTabs[i].subPage..langSuffix..'|'..strDefaultLinkTitle..']]'
		}
		table.insert(tTabs[tDefaultTabs[i].tabsTableName], tDefaultTabData)
	end
	return tTabs
end

function convertCrosslinkhonorsToTabs( frame, tCrosslinkhonors, tVariants, landingPage, langSuffix )
	mw.log('HonorTabs.convertCrosslinkhonorsToTabs: Start converting!')
	tTabs = initializeTabStruct()
	if ( tCrosslinkhonors == nil or #tCrosslinkhonors <= 0 ) then
		mw.log('HonorTabs.convertCrosslinkhonorsToTabs: No Crosslinkhonors to convert!')
		return tTabs
	end
	--clh = crosslinkhonor
	for clhKey, crosslinkhonor in pairs(tCrosslinkhonors) do
		if (crosslinkhonor.tVariants == nil) then
			mw.log('HonorTabs.convertCrosslinkhonorsToTabs: Crosslinkhonor has no Variants!')
		end
		mw.log('HonorTabs.convertCrosslinkhonorsToTabs (crosslinkhonor.name): '..crosslinkhonor.name)
		strClhLandingPage = frame:expandTemplate{ 
			title='GetHonorLandingPage', 
			args = { honor = crosslinkhonor.name } 
		}
		mw.log('HonorTabs.convertCrosslinkhonorsToTabs (strClhLandingPage): '..strClhLandingPage)
		
		local strClhDefaultLinkTitle = ''
		if ( crosslinkhonor.tVariants['requirements'] == nil ) then
			mw.log('HonorTabs.convertCrosslinkhonorsToTabs: No Requirement Variants! Create default entry.')
			local strDefaultAuth = utilities.localize( 'GC', 'Authorities' )
			strClhDefaultLinkTitle = strDefaultAuth
			local pageTitle = strClhLandingPage..'/Requirements'..langSuffix
			table.insert(tTabs.requirements, {
				pageTitle = pageTitle,
				linkTitle = strDefaultAuth,
				wikiLink = '[['..pageTitle..'|'..strDefaultAuth..']]'
			})
			mw.log('HonorTabs.convertCrosslinkhonorsToTabs (requirement default pageTitle): '..pageTitle)
			mw.log('HonorTabs.convertCrosslinkhonorsToTabs (requirement default linkTitle): '..strDefaultAuth)
		else
			for varKey, variant in pairs(crosslinkhonor.tVariants['requirements']) do
				local linkTitle = ""
				if ( variant['authorities'] == nil ) then
					mw.log('HonorTabs.convertCrosslinkhonorsToTabs: Invalid Requirement Variant (Authorities)!')
				else
					for authorityKey, authority in pairs(variant['authorities']) do
						if ( #linkTitle > 0 ) then
							linkTitle = linkTitle..' & '..authority['translated']
						else
							linkTitle = authority['translated']
						end
						-- add authority to the ovierview/lesson plans/worksheets link title
						if ( #strClhDefaultLinkTitle > 0 ) then
							strClhDefaultLinkTitle = strClhDefaultLinkTitle..' & '..authority['translated']
						else
							strClhDefaultLinkTitle = authority['translated']
						end
					end
				end
				
				local strVariantNumber = ''
				-- add number only for variants bigger than 1
				if varKey > 1 then
					strVariantNumber = '_'..varKey
				end
				
				local pageTitle = strClhLandingPage..'/Requirements'..strVariantNumber..langSuffix
				table.insert(tTabs.requirements, {
					pageTitle = pageTitle,
					linkTitle = linkTitle,
					wikiLink = '[['..pageTitle..'|'..linkTitle..']]',
				})
				mw.log('HonorTabs.convertCrosslinkhonorsToTabs (requirement '..varKey..' pageTitle): '..pageTitle)
				mw.log('HonorTabs.convertCrosslinkhonorsToTabs (requirement '..varKey..' linkTitle): '..linkTitle)
			end
		end
		
		if ( crosslinkhonor.tVariants['answers'] == nil ) then
			local linkTitle = ''
			mw.log('HonorTabs.convertCrosslinkhonorsToTabs: No Answer Variants! Check if there is a Requirement Variant to get the Authority.')
			if ( crosslinkhonor.tVariants['requirements'] ~= nil ) then
				-- as no answer variant is defined we just use the first requirement variant of the honor
				local reqVariant = crosslinkhonor.tVariants['requirements'][1]
				if (reqVariant['authorities'] ~= nil ) then
					for authorityKey, authority in pairs(reqVariant['authorities']) do
						if ( #linkTitle > 0 ) then
							linkTitle = linkTitle..' & '..authority['translated']
						else
							linkTitle = authority['translated']
						end
					end
				end
			end
			
			if ( linkTitle == '' ) then
				mw.log('HonorTabs.convertCrosslinkhonorsToTabs: No Requirement Variants to set answer variants text, so default to GC!')
				linkTitle = utilities.localize( 'GC', 'Authorities' )
			end
			local pageTitle = strClhLandingPage..'/Answer Key'..langSuffix
			table.insert(tTabs.answers, {
				pageTitle = pageTitle,
				linkTitle = linkTitle,
				wikiLink = '[['..pageTitle..'|'..linkTitle..']]',
			})
			mw.log('HonorTabs.convertCrosslinkhonorsToTabs (answer default pageTitle): '..pageTitle)
			mw.log('HonorTabs.convertCrosslinkhonorsToTabs (answer default linkTitle): '..linkTitle)
		else
			for varKey, variant in pairs(crosslinkhonor.tVariants['answers']) do
				local linkTitle = ''
				if ( variant['countries'] == nil or variant['countries']['split'] == nil) then
					mw.log('HonorTabs.convertCrosslinkhonorsToTabs: There are probably no Countries defined or something went horribly wrong!')
				else
					for countryKey, country in pairs(variant['countries']['split']) do
						if ( #linkTitle > 0 ) then
							linkTitle = linkTitle..' & '..country['translated']
						else
							linkTitle = country['translated']
						end
					end
				end
				if ( variant['authority'] == nil ) then
					mw.log('HonorTabs.convertCrosslinkhonorsToTabs: No Authority for this variant!')
				else
					mw.log('HonorTabs.convertCrosslinkhonorsToTabs (variant["authority"]): '..variant['authority'])
					-- get the authority
					mw.log('*DEBUG* '..tostring(crosslinkhonor.tVariants['requirements']))
					mw.log('*DEBUG* '..tostring(#crosslinkhonor.tVariants['requirements']))
					mw.log('*DEBUG* '..tostring(crosslinkhonor.tVariants['requirements'][tonumber(variant['authority'])]))
					mw.log('*DEBUG* '..tostring(crosslinkhonor.tVariants['requirements'][tonumber(variant['authority'])]['authorities']))
					mw.log('*DEBUG* '..tostring(crosslinkhonor.tVariants['requirements'][tonumber(variant['authority'])]['authorities'][1]))
					mw.log('*DEBUG* '..tostring(crosslinkhonor.tVariants['requirements'][tonumber(variant['authority'])]['authorities'][1]['translated']))
					local authority = crosslinkhonor.tVariants['requirements'][tonumber(variant['authority'])]['authorities'][1]['translated']
					-- check if there are countries if not, parentheses are not needed
					if ( linkTitle == '' ) then
						linkTitle = authority
					else
						linkTitle = linkTitle..' ('..authority..')'
					end
				end
				local strVariantNumber = ''
				-- add number only for variants bigger than 1
				if varKey > 1 then
					strVariantNumber = '_'..varKey
				end
				local locLangSuffix = langSuffix
				if ( variant['srcLangSuffix'] == locLangSuffix ) then
					-- Source Language of the answer key is the same than the content language in use
					-- that the link doesn't lead to the copy of the translation extension
					-- the langSuffix needs to be removed
					locLangSuffix = ''
				elseif ( variant['srcLangSuffix'] ~= '' and locLangSuffix == '' ) then
					-- Source Language is set and locLangSuffix is an empty string
					-- as the locLangSuffix is empty the current content language is english
					-- so we need to add /en to the link of this variant because it's source language
					-- is NOT english (source language pages have NO language suffix)
					locLangSuffix = '/en'
				end
				local pageTitle = landingPage..'/Answer_Key'..strVariantNumber..locLangSuffix
				table.insert(tTabs.answers, {
					pageTitle = pageTitle,
					linkTitle = linkTitle,
					wikiLink = '[['..pageTitle..'|'..linkTitle..']]'
				})
				mw.log('HonorTabs.convertCrosslinkhonorsToTabs (answer '..varKey..' pageTitle): '..pageTitle)
				mw.log('HonorTabs.convertCrosslinkhonorsToTabs (answer '..varKey..' linkTitle): '..linkTitle)
			end
		end
	
		local tDefaultTabs = {
			{
				subPage = '', --overview or landingPage
				tabsTableName = 'overview'
			},
			{
				subPage = '/Lesson Plans',
				tabsTableName = 'lessonPlans'
			},
			{
				subPage = '/Worksheets',
				tabsTableName = 'worksheets'
			}
		}
		for i=1, #tDefaultTabs do
			local tDefaultTabData = {
				pageTitle = strClhLandingPage..tDefaultTabs[i].subPage..langSuffix,
				linkTitle = strClhDefaultLinkTitle,
				wikiLink = '[['..strClhLandingPage..tDefaultTabs[i].subPage..langSuffix..'|'..strClhDefaultLinkTitle..']]'
			}
			table.insert(tTabs[tDefaultTabs[i].tabsTableName], tDefaultTabData)
		end
	end
	return tTabs
end

function createSimpleTab( wikiLink )
	local HTMLCode = mw.html.create( 'li' )
	HTMLCode
		:addClass( 'honor-nav-item' )
		:wikitext( wikiLink )
	return tostring( HTMLCode )
end

function createDropdownTab ( frame, tConfig, text, id, isSelflink )
	local HTMLCode = ""
	local HTMLCodeString = ""
	if ( tConfig == nil ) then
		mw.log('HonorTabs.createDropdownTab: Invalid Tab Config (nil)!')
	elseif ( #tConfig < 1 ) then
		mw.log('HonorTabs.createDropdownTab: Invalid Tab Config (< 1)!')
	elseif ( #tConfig == 1 ) then
		mw.log('HonorTabs.createDropdownTab (num, text, id, isSelflink): 1 Option, '..text..', '..id..', '..tostring(isSelflink))
		local transText = utilities.localize( text )
		-- check if Localization returned something, if not set the original string
		if ( transText == '' ) then
			transText = text
		end
		HTMLCodeString = createSimpleTab( '[['..tConfig[1].pageTitle..'|'..transText..']]' )
	else
		mw.log('HonorTabs.createDropdownTab (num, text, id, isSelflink): '..#tConfig..' Options, '..text..', '..id..', '..tostring(isSelflink))
		-- now there should be more then 1 variants
		local HTMLTabParent = mw.html.create( 'li' )
		local buttonArgs = {}
		buttonArgs['tagname'] = 'button'
		buttonArgs['class'] = 'dropdown-toggle'
		if (isSelflink == true) then
			buttonArgs['class'] = buttonArgs['class'] .. ' selflink'
		end
		buttonArgs['type'] = 'button'
		buttonArgs['id'] = 'dropdown'..id..'Keys'
		buttonArgs['data-toggle'] = 'dropdown'
		buttonArgs['aria-haspopup'] = 'true'
		buttonArgs['aria-expanded'] = 'false'
		buttonText = utilities.localize( text )
		-- check if Localization returned something, if not set the original string
		if ( buttonText == '' ) then
			buttonText = text
		end
		local dropdownButton = frame:extensionTag('htmltag', buttonText, buttonArgs)
		HTMLTabParent
			:addClass( 'honor-nav-item' )
			:addClass( 'dropdown' )
			:wikitext( dropdownButton )
		
		HTMLVariantsContainer = mw.html.create( 'div' )
		HTMLVariantsContainer
			:addClass( 'dropdown-menu' )
			:attr( 'aria-labelledby', 'dropdown'..id..'Keys')
		for key, tab in pairs(tConfig) do
			if (tab.showSeperatorInfront == true) then
				HTMLSeperator = mw.html.create( 'div' )
				HTMLSeperator
					:addClass('dropdown-divider')
				HTMLVariantsContainer:node( HTMLSeperator )
			end
			HTMLVariantLink = mw.html.create( 'span' )
			HTMLVariantLink
				:addClass( 'dropdown-item' )
				:wikitext( tab.wikiLink )
				:done()
			HTMLVariantsContainer:node( HTMLVariantLink )
		end
		HTMLVariantsContainer:done()
		HTMLTabParent:node( HTMLVariantsContainer )
		HTMLCodeString = tostring( HTMLTabParent )
	end
	return HTMLCodeString
end
		
function generateTabURL( frame, page, langSuffix, text )
	-- check inputs
	if ( page == nil or page == "" ) then return 'fatal error' end
	
	local transText = utilities.localize( text )
	-- check if Localization returned something, if not set the original string
	if ( transText == '' ) then
		transText = text
	end
	
	return '[[' .. page .. langSuffix .. '|' .. transText .. ']]'
end

function initializeTabStruct()
	return {
		overview = {},
		answers = {},
		requirements = {},
		lessonPlans = {},
		worksheets = {}
	}
end

return p