Difference between revisions of "Module:HonorUtils"

From Pathfinder Wiki
(- adding support for crosslink honors)
 
(57 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
local notUseLUAPattern = true
+
local utilities = require ( "Module:Utilities" )
 +
local C_notUseLUAPattern = true
 +
local C_srcIsNotHonor = false
  
function p.getExpandedHonorVariantsV2( frame, landingPage )
+
-- returns a table with the type and the number of the variant of the act. page
 +
function p.getActVariantInfo( frame )
 +
local pageTitle = frame:expandTemplate{ title = 'PAGENAMEwithoutLang' }
 +
mw.log('HonorUtils.getActVariantInfo (pageTitle): '..pageTitle)
 +
local tPageTitle = mw.text.split(pageTitle, '/', C_notUseLUAPattern)
 +
 +
local subPageString = tPageTitle[3]
 +
if (subPageString == nil) then
 +
mw.log('HonorUtils.getActVariantInfo: It is not a valid Subpage (nil)!')
 +
return nil
 +
end
 +
 +
local variantNumber = utilities.getNumber(subPageString)
 +
if (variantNumber == nil) then
 +
-- if the page has no number then it is mostlikely number one
 +
-- and if it is an invalid subpage then the number won't be used anyway's
 +
variantNumber = 1
 +
end
 +
local tReturn = {
 +
variantNumber = variantNumber
 +
}
 +
-- check for valid subpages
 +
if ( mw.ustring.find(subPageString, 'Requirements', 0, C_notUseLUAPattern) ~= nil ) then
 +
mw.log('HonorUtils.getActVariantInfo: It is the Requirements Variant '..variantNumber)
 +
tReturn['variantType'] = 'requirements'
 +
tReturn['subPage'] = 'Requirements'
 +
elseif (mw.ustring.find(subPageString, 'Answer Key', 0, C_notUseLUAPattern) ~= nil ) then
 +
mw.log('HonorUtils.getActVariantInfo: It is the Answer Key Variant '..variantNumber)
 +
tReturn['variantType'] = 'answerKey'
 +
tReturn['subPage'] = 'Answer Key'
 +
elseif (mw.ustring.find(subPageString, 'Lesson Plans', 0, C_notUseLUAPattern) ~= nil ) then
 +
mw.log('HonorUtils.getActVariantInfo: It is the Lesson Plans page, no variant possible.')
 +
tReturn['subPage'] = 'Lesson Plans'
 +
elseif (mw.ustring.find(subPageString, 'Answer Key', 0, C_notUseLUAPattern) ~= nil ) then
 +
mw.log('HonorUtils.getActVariantInfo: It is the Worksheet page, no variant possible.')
 +
tReturn['subPage'] = 'Worksheet'
 +
else
 +
mw.log('HonorUtils.getActVariantInfo: It is a invalid Subpage!')
 +
return nil
 +
end
 +
return tReturn
 +
end
 +
 
 +
function p.getVariantsData( frame, landingPage, variantType, variantNumber )
 +
if ( frame == nil ) then
 +
frame = mw.getCurrentFrame()
 +
mw.log( 'HonorUtils.getVariantsData (frame): '..frame:getTitle() )
 +
end
 
if ( landingPage == nil or landingPage == "" ) then
 
if ( landingPage == nil or landingPage == "" ) then
 
landingPage = frame:expandTemplate{ title='GetHonorLandingPage' }
 
landingPage = frame:expandTemplate{ title='GetHonorLandingPage' }
 
end
 
end
local tVariants = {}
+
local getAnswerVariants = true
tVariants['answers'] = {}
+
local tAnswerVariants = nil
tVariants['answers']['orig'] = getHonorVariants( 'answer', landingPage, false )
+
local getRequirementVariants = true
tVariants['answers']['split'] = mw.text.split(tVariants['answers']['orig'], '|', notUseLUAPattern)
+
local tRequirementVariants = nil
tVariants['requirements'] = {}
+
tVariants['requirements']['orig'] = getHonorVariants( 'requirement', landingPage, false )
+
-- check if only one variant is needed
tVariants['requirements']['split']  = mw.text.split(tVariants['requirements']['orig'], '|', notUseLUAPattern)
+
if ( variantType ~= nil and variantType ~= '' ) then
 +
if (variantType == 'requirements') then
 +
getAnswerVariants = false
 +
elseif (variantType == 'answerKey') then
 +
getRequirementVariants = false
 +
else
 +
mw.log( 'HonorUtils.getVariantsData: Invalid variantType!' )
 +
return nil;
 +
end
 +
end
 +
 
 +
if ( getAnswerVariants == true ) then
 +
tAnswerVariants = getHonorVariants( 'answerKey', landingPage, C_srcIsNotHonor, variantNumber )
 +
if ( tAnswerVariants == nil ) then
 +
mw.log("HonorUtils.getVariantsData: It isn't possible to get any answer variant's data!")
 +
end
 +
end
 +
 +
if ( getRequirementVariants == true ) then
 +
tRequirementVariants = getHonorVariants( 'requirements', landingPage, C_srcIsNotHonor, variantNumber )
 +
if ( tRequirementVariants == nil ) then
 +
mw.log("HonorUtils.getVariantsData: It isn't possible to get any requirement variant's data!")
 +
end
 +
end
 +
 +
local tVariants = {
 +
answers = tAnswerVariants,
 +
requirements = tRequirementVariants
 +
}
 
 
tVariants = p.expandHonorVariantsV2( frame, tVariants )
+
tVariants = expandHonorVariants( frame, tVariants )
 
 
tVariants = p.translateHonorVariantsV2( frame, tVariants )
+
tVariants = translateHonorVariants( frame, tVariants )
 
return tVariants
 
return tVariants
 
end
 
end
  
function p.expandHonorVariantsV2( frame, tVariants )
+
function p.getCrosslinkhonorsData( frame, landingPage )
 +
local tCrosslinkhonor = {}
 +
if ( frame == nil ) then
 +
frame = mw.getCurrentFrame()
 +
mw.log( 'HonorUtils.getCrosslinkhonorsData (frame): '..frame:getTitle() )
 +
end
 +
mw.log( 'HonorUtils.getCrosslinkhonorsData (landingPage - function Argument): '..tostring(landingPage) )
 +
if ( landingPage == nil or landingPage == "" ) then
 +
landingPage = frame:expandTemplate{ title='GetHonorLandingPage' }
 +
mw.log( 'HonorUtils.getCrosslinkhonorsData (landingPage - from Template): '..landingPage )
 +
end
 +
 +
local tCrosslinkhonors = getCrosslinkhonors( landingPage, C_srcIsNotHonor )
 +
 +
if ( tCrosslinkhonors ~= nil and #tCrosslinkhonors ~= 0 ) then
 +
for key, crosslinkhonor in pairs(tCrosslinkhonors) do
 +
--clh = crosslinkhonor
 +
local strClhLandingPage = frame:expandTemplate{
 +
title='GetHonorLandingPage',
 +
args = { honor = crosslinkhonor }
 +
}
 +
tCrosslinkhonors[key] = {
 +
name = crosslinkhonor,
 +
landingPage = strClhLandingPage,
 +
tVariants = p.getVariantsData( frame, strClhLandingPage )
 +
}
 +
end
 +
else
 +
tCrosslinkhonors = {}
 +
end
 +
 
 +
return tCrosslinkhonors
 +
end
 +
 
 +
function expandHonorVariants( frame, tVariants )
 
local tRetVariants = tVariants
 
local tRetVariants = tVariants
 
if ( tVariants == nil ) then
 
if ( tVariants == nil ) then
mw.log('HonorUtils.expandHonorVariantsV2: No Variants to Expand (nil)!')
+
mw.log('HonorUtils.expandHonorVariants: No Variants to Expand (nil)!')
 
return {}
 
return {}
 
end
 
end
if ( tVariants['answers'] == nil or tVariants['answers']['split'] == nil ) then
+
if ( tVariants['answers'] == nil ) then
mw.log('HonorUtils.expandHonorVariantsV2: No Answer Variants to Expand!')
+
mw.log('HonorUtils.expandHonorVariants: No Answer Variants to Expand!')
 
else
 
else
 
-- expand the answer Variants
 
-- expand the answer Variants
local tAnswers = tVariants['answers']['split']
+
local tAnswers = tVariants['answers']
mw.log('HonorUtils.expandHonorVariantsV2: There are '..#tAnswers..' Answer Variants to Expand!')
+
mw.log('HonorUtils.expandHonorVariants: There are '..#tAnswers..' Answer Variants to Expand!')
 
for key, variant in pairs(tAnswers) do
 
for key, variant in pairs(tAnswers) do
mw.log('HonorUtils.expandHonorVariantsV2 (key, variant): '..key..', '..variant)
+
mw.log('HonorUtils.expandHonorVariants (key, variant): '..key..', '..variant)
-- seperate Countries and Authority
 
local tSplitAnsVariant = mw.text.split(variant, ';;', notUseLUAPattern)
 
 
local tActVariant = {
 
local tActVariant = {
 
orig = variant,
 
orig = variant,
 
countries = {}
 
countries = {}
 
}
 
}
tActVariant['countries']['orig'] = tSplitAnsVariant[1]
+
-- seperate the Countries
+
-- seperate the source language suffix
tActVariant['countries']['split'] = mw.text.split(tActVariant['countries']['orig'], ';', notUseLUAPattern)
+
local tSplitAnsVariant = mw.text.split(variant, '/', C_notUseLUAPattern)
mw.log('HonorUtils.expandHonorVariantsV2 (Countries - Orig): '..tActVariant['countries']['orig'])
+
if (tSplitAnsVariant[2] ~= nil and tSplitAnsVariant[2] ~= '') then
 +
tActVariant['srcLangSuffix'] = '/'..tSplitAnsVariant[2]
 +
mw.log('HonorUtils.expandHonorVariants (srcLangSuffix): '..tActVariant['srcLangSuffix'])
 +
else
 +
mw.log('HonorUtils.expandHonorVariants: There is no source language set, default to english, which is an empty string ;)')
 +
tActVariant['srcLangSuffix'] = ''
 +
end
 +
 +
-- seperate Countries and Authority
 +
tSplitAnsVariant = mw.text.split(tSplitAnsVariant[1], ';;', C_notUseLUAPattern)
 +
if ( tSplitAnsVariant[1] ~= '') then
 +
tActVariant['countries']['orig'] = tSplitAnsVariant[1]
 +
-- seperate the Countries
 +
tActVariant['countries']['split'] = mw.text.split(tActVariant['countries']['orig'], ';', C_notUseLUAPattern)
 +
mw.log('HonorUtils.expandHonorVariants (Countries - Orig): '..tActVariant['countries']['orig'])
 +
else
 +
mw.log('HonorUtils.expandHonorVariants: There are no countries for that variant!')
 +
end
 
-- set the authority
 
-- set the authority
 
if ( tSplitAnsVariant[2] == nil ) then
 
if ( tSplitAnsVariant[2] == nil ) then
tActVariant['authority'] = ''
+
tActVariant['authority'] = nil
 +
mw.log('HonorUtils.expandHonorVariants (Authority): nil')
 
else
 
else
 
tActVariant['authority'] = tSplitAnsVariant[2]
 
tActVariant['authority'] = tSplitAnsVariant[2]
 +
mw.log('HonorUtils.expandHonorVariants (Authority): '..tActVariant['authority'])
 
end
 
end
mw.log('HonorUtils.expandHonorVariantsV2 (Authority): '..tActVariant['authority'])
 
 
-- save act. Variant into the table
 
-- save act. Variant into the table
 
tAnswers[key] = tActVariant
 
tAnswers[key] = tActVariant
 
end
 
end
tVariants['answers']['split'] = tAnswers
+
tVariants['answers'] = tAnswers
mw.log('HonorUtils.expandHonorVariantsV2: '..#tVariants['answers']['split']..' Answer Variants expanded!')
+
mw.log('HonorUtils.expandHonorVariants: '..#tVariants['answers']..' Answer Variants expanded!')
 
end
 
end
if ( tVariants['requirements'] == nil or tVariants['requirements']['split'] == nil ) then
+
if ( tVariants['requirements'] == nil ) then
mw.log('HonorUtils.expandHonorVariantsV2: No Requirement Variants to Expand!')
+
mw.log('HonorUtils.expandHonorVariants: No Requirement Variants to Expand!')
 
else
 
else
 
-- expand the requirement Variants
 
-- expand the requirement Variants
local tRequirements = tVariants['requirements']['split']
+
local tRequirements = tVariants['requirements']
mw.log('HonorUtils.expandHonorVariantsV2: There are '..#tRequirements..' Requirement Variants to Expand!')
+
mw.log('HonorUtils.expandHonorVariants: There are '..#tRequirements..' Requirement Variants to Expand!')
 
for key, variant in pairs(tRequirements) do
 
for key, variant in pairs(tRequirements) do
mw.log('HonorUtils.expandHonorVariantsV2 (key, variant): '..key..', '..variant)
+
mw.log('HonorUtils.expandHonorVariants (key, variant): '..key..', '..variant)
 
-- seperate Authorities
 
-- seperate Authorities
local tSplitReqVariant = mw.text.split(variant, ';', notUseLUAPattern)
+
local tSplitReqVariant = mw.text.split(variant, ';', C_notUseLUAPattern)
 
local tActReqVariant = {
 
local tActReqVariant = {
 
orig = variant,
 
orig = variant,
Line 73: Line 200:
 
tRequirements[key] = tActReqVariant
 
tRequirements[key] = tActReqVariant
 
end
 
end
tVariants['requirements']['split'] = tRequirements
+
tVariants['requirements'] = tRequirements
mw.log('HonorUtils.expandHonorVariantsV2: '..#tVariants['requirements']['split']..' Requirement Variants expanded!')
+
mw.log('HonorUtils.expandHonorVariants: '..#tVariants['requirements']..' Requirement Variants expanded!')
 
end
 
end
 
return tRetVariants
 
return tRetVariants
 
end
 
end
  
function p.getExpandedHonorVariants(frame, variantsString, landingPage, targetPage)
+
function translateHonorVariants( frame, tVariants )
-- check the input variables
 
if (frame == nil or landingPage == nil or landingPage == "" or targetPage == nil or targetPage == "") then
 
return "fatal error"
 
end
 
if (variantsString == nil or variantsString == "") then
 
local linkTitle = frame:expandTemplate{ title = 'Localize', args = { targetPage } }
 
return {
 
{
 
url = "[[" .. landingPage .. "/" .. targetPage .. frame:expandTemplate{title='GetLangSuffix'} .. "|" .. linkTitle .. "]]"
 
}
 
}
 
end
 
 
local t_variants = p.expandHonorVariants(frame, variantsString)
 
t_variants = p.translateHonorVariants(frame, t_variants)
 
t_variants = p.createHonorVariantsURLs(frame, t_variants, landingPage, targetPage)
 
return t_variants
 
end
 
 
 
function p.expandHonorVariants(frame, variantsString)
 
if (variantsString == nil or variantsString == "") then return {} end
 
 
local t_variants = mw.text.split( variantsString, ';;', notUseLUAPattern )
 
 
for key, variant in pairs(t_variants) do
 
t_variants[key] = {
 
orig = variant,
 
countries = mw.text.split( variant, ';', notUseLUAPattern )
 
}
 
end
 
 
return t_variants
 
end
 
 
 
function p.translateHonorVariantsV2( frame, tVariants )
 
 
local tRetVariants = tVariants
 
local tRetVariants = tVariants
 
if ( tRetVariants == nil ) then
 
if ( tRetVariants == nil ) then
mw.log('HonorUtils.translateHonorVariantsV2: There are no Variants (nil)!')
+
mw.log('HonorUtils.translateHonorVariants: There are no Variants (nil)!')
 
end
 
end
if ( tRetVariants['answers'] == nil or tRetVariants['answers']['split'] == nil) then
+
if ( tRetVariants['answers'] == nil ) then
mw.log('HonorUtils.translateHonorVariantsV2: There are no Answer Variants!')
+
mw.log('HonorUtils.translateHonorVariants: There are no Answer Variants!')
 
else
 
else
mw.log('HonorUtils.translateHonorVariantsV2: There are '..#tRetVariants['answers']['split']..' Answer Variants to translate!')
+
mw.log('HonorUtils.translateHonorVariants: There are '..#tRetVariants['answers']..' Answer Variants to translate!')
for varKey, variant in pairs(tRetVariants['answers']['split']) do
+
for varKey, variant in pairs(tRetVariants['answers']) do
 
if ( variant == nil or variant['countries'] == nil or variant['countries']['split'] == nil ) then
 
if ( variant == nil or variant['countries'] == nil or variant['countries']['split'] == nil ) then
mw.log('HonorUtils.translateHonorVariantsV2: Answer Variant is invalid!')
+
mw.log('HonorUtils.translateHonorVariants: Answer Variant is invalid!')
 
else
 
else
mw.log('HonorUtils.translateHonorVariantsV2: There are '..#variant['countries']['split']..' Answer Variant Countries to translate!')
+
mw.log('HonorUtils.translateHonorVariants: There are '..#variant['countries']['split']..' Answer Variant Countries to translate!')
 
for countryKey, country in pairs(variant['countries']['split']) do
 
for countryKey, country in pairs(variant['countries']['split']) do
local trans = frame:expandTemplate{ title = 'Localize', args = { country, 'Answer Variants' } }
+
local trans = utilities.localize( country, 'Countries' )
tRetVariants['answers']['split'][varKey]['countries'][countryKey] = {
+
-- check if Localization returned something, if not set the original string
 +
mw.log('HonorUtils.translateHonorVariants (country, trans): '..country..', '..trans)
 +
if ( trans == '' ) then
 +
trans = country
 +
end
 +
tRetVariants['answers'][varKey]['countries']['split'][countryKey] = {
 
orig = country,
 
orig = country,
 
translated = trans
 
translated = trans
 
}
 
}
 
end
 
end
mw.log('HonorUtils.translateHonorVariantsV2: '..#tRetVariants['answers']['split'][varKey]['countries']..' Answer Variant Countries were translated!')
+
mw.log('HonorUtils.translateHonorVariants: '..#tRetVariants['answers'][varKey]['countries']['split']..' Answer Variant Countries were translated!')
end
 
if ( variant['authority'] == nil ) then
 
mw.log('HonorUtils.translateHonorVariantsV2: Answer Variant has no authority set!')
 
else
 
mw.log('HonorUtils.translateHonorVariantsV2: There is a Answer Variant Authority to translate!')
 
local trans = frame:expandTemplate{ title = 'Localize', args = { variant['authority'], 'Authorities' } }
 
tRetVariants['answers']['split'][varKey]['authority'] = {
 
orig = variant['authority'],
 
translated = trans
 
}
 
mw.log('HonorUtils.translateHonorVariantsV2: Answer Variant Authority got translated!')
 
 
end
 
end
 
end
 
end
mw.log('HonorUtils.translateHonorVariantsV2: '..#tRetVariants['answers']['split']..' Answer Variants were translated!')
+
mw.log('HonorUtils.translateHonorVariants: '..#tRetVariants['answers']..' Answer Variants were translated!')
 
end
 
end
if ( tRetVariants['requirements'] == nil or tRetVariants['requirements']['split'] == nil) then
+
if ( tRetVariants['requirements'] == nil ) then
mw.log('HonorUtils.translateHonorVariantsV2: There are no Requirement Variants!')
+
mw.log('HonorUtils.translateHonorVariants: There are no Requirement Variants!')
 
else
 
else
mw.log('HonorUtils.translateHonorVariantsV2: There are '..#tRetVariants['requirements']['split']..' Requriement Variants to translate!')
+
mw.log('HonorUtils.translateHonorVariants: There are '..#tRetVariants['requirements']..' Requriement Variants to translate!')
for varKey, variant in pairs(tRetVariants['requirements']['split']) do
+
for varKey, variant in pairs(tRetVariants['requirements']) do
 
if ( variant == nil or variant['authorities'] == nil ) then
 
if ( variant == nil or variant['authorities'] == nil ) then
mw.log('HonorUtils.translateHonorVariantsV2: Requriement Variant is invalid!')
+
mw.log('HonorUtils.translateHonorVariants: Requriement Variant is invalid!')
 
else
 
else
mw.log('HonorUtils.translateHonorVariantsV2: There are '..#variant['authorities']..' Requriement Variant Authorities to translate!')
+
mw.log('HonorUtils.translateHonorVariants: There are '..#variant['authorities']..' Requriement Variant Authorities to translate!')
 
for authorityKey, authority in pairs(variant['authorities']) do
 
for authorityKey, authority in pairs(variant['authorities']) do
local trans = frame:expandTemplate{ title = 'Localize', args = { authority, 'Answer Variants' } }
+
local trans = utilities.localize( authority, 'Authorities' )
tRetVariants['requirements']['split'][varKey]['authorities'][authorityKey] = {
+
-- check if Localization returned something, if not set the original string
 +
if ( trans == '' ) then
 +
trans = authority
 +
end
 +
tRetVariants['requirements'][varKey]['authorities'][authorityKey] = {
 
orig = authority,
 
orig = authority,
 
translated = trans
 
translated = trans
 
}
 
}
 
end
 
end
mw.log('HonorUtils.translateHonorVariantsV2: '..#tRetVariants['requirements']['split'][varKey]['authorities']..' Requriement Variant Authorities were translated!')
+
mw.log('HonorUtils.translateHonorVariants: '..#tRetVariants['requirements'][varKey]['authorities']..' Requriement Variant Authorities were translated!')
 
end
 
end
 
end
 
end
mw.log('HonorUtils.translateHonorVariantsV2: '..#tRetVariants['answers']['split']..' Requriement Variants were translated!')
+
mw.log('HonorUtils.translateHonorVariants: '..#tRetVariants['requirements']..' Requriement Variants were translated!')
 
end
 
end
 
return tRetVariants
 
return tRetVariants
 
end
 
end
  
function p.translateHonorVariants(frame, variants)
+
function getCrosslinkhonors( src, srcIsHonor )
local ret_t_variants = variants
+
local frame = mw.getCurrentFrame()
for varKey, variant in pairs(variants) do
+
mw.log('HonorUtils.getCrosslinkhonors (frame): '..frame:getTitle())
for countryKey, country in pairs(variant['countries']) do
+
local parentFrame = frame:getParent()
local trans = frame:expandTemplate{ title = 'Localize', args = { country, 'Answer Variants' } }
+
local strActPageTitle = mw.title.getCurrentTitle().text
local t_countryTrans = {
+
mw.log('HonorUtils.getCrosslinkhonors (strActPageTitle): '..strActPageTitle)
orig = country,
+
local srcMode = 'dpl' -- it can be 'vardefine', 'parentFrame' or 'dpl' (default)
translation = trans
+
local cntCrosslinkhonors = 0
}
+
-- check if we are on the landing page of the wanted honor
ret_t_variants[varKey]['countries'][countryKey] = t_countryTrans
+
-- if yes we are able to use DPL
 +
-- if not we check if we are inside of the Template:HonorLanding
 +
-- if yes we can use the parentFrame method
 +
-- if not then we use the vardefine method
 +
local bIsLandingPage = false
 +
if ( srcIsHonor == true and strActPageTitle == 'AY Honors/'..src or
 +
strActPageTitle == src ) then
 +
bIsLandingPage = true
 +
end
 +
mw.log('HonorUtils.getCrosslinkhonors: Is it the honors landing page? '..tostring(bIsLandingPage))
 +
if ( bIsLandingPage ~= true ) then
 +
mw.log('HonorUtils.getCrosslinkhonors: Get variants data with DPL!')
 +
cntCrosslinkhonors = tonumber(p.getHonorMetadata(src, 'cnt_crosslinkhonors', srcIsHonor))
 +
srcMode = 'dpl'
 +
-- check if we are inside of Template:HonorLanding
 +
elseif ( parentFrame ~= nil and
 +
parentFrame:getTitle() == 'Template:HonorLanding' and
 +
parentFrame.args['cnt_crosslinkhonors'] ~= nil and
 +
parentFrame.args['cnt_crosslinkhonors'] ~= ''
 +
) then
 +
mw.log('HonorUtils.getCrosslinkhonors: Get Crosslinkhonors from parent Frame!')
 +
srcMode = 'parentFrame'
 +
cntCrosslinkhonors = parentFrame.args['cnt_crosslinkhonors']
 +
else
 +
mw.log('HonorUtils.getCrosslinkhonors: Get Crosslinkhonors from vardefine!')
 +
srcMode = 'vardefine'
 +
cntCrosslinkhonors = utilities.getVar('cnt_crosslinkhonors')
 +
end
 +
if (cntCrosslinkhonors == nil or cntCrosslinkhonors == '' or tonumber(cntCrosslinkhonors) == 0) then
 +
mw.log('HonorUtils.getCrosslinkhonors: There are no Crosslinkhonors!')
 +
return nil
 +
end
 +
mw.log('HonorUtils.getCrosslinkhonors (cntCrosslinkhonors): '..cntCrosslinkhonors)
 +
local actLink = 0
 +
local tCrosslinkhonorArguments = {}
 +
-- get all Crosshonor Links
 +
for actLink = 1, cntCrosslinkhonors, 1 do
 +
mw.log('HonorUtils.getCrosslinkhonors (actLink): '..actLink)
 +
tCrosslinkhonorArguments[actLink] = 'crosslinkhonor_'..actLink
 +
end
 +
 +
local tCrosslinkhonors = {}
 +
if ( srcMode == 'vardefine' ) then
 +
for key, crosslinkhonorArg in pairs(tCrosslinkhonorArguments) do
 +
tCrosslinkhonors[key] = utilities.getVar(crosslinkhonorArg)
 
end
 
end
end
+
elseif ( srcMode == 'parentFrame' ) then
return ret_t_variants
+
for key, crosslinkhonorArg in pairs(tCrosslinkhonorArguments) do
end
+
tCrosslinkhonors[key] = parentFrame.args[crosslinkhonorArg]
 
 
function p.createHonorVariantsURLs(frame, variants, landingPage, targetPage)
 
local t_variants = variants
 
local langSuffix = frame:expandTemplate{title='GetLangSuffix'}
 
for key, variant in pairs(variants) do
 
local linkTitle = ""
 
for countryKey, country in pairs(variant['countries']) do
 
if (#linkTitle > 0) then
 
linkTitle = linkTitle .. " & " .. country['translation']
 
else
 
linkTitle = country['translation']
 
end
 
 
end
 
end
t_variants[key]['url'] ="[[" .. landingPage .. "_(" .. variant['orig'] .. ")/" .. targetPage .. langSuffix .. "|" .. linkTitle .. "]]"
+
else
 +
local strCrosslinkhonorArguments = mw.text.listToText(tCrosslinkhonorArguments, ':', ':')
 +
mw.log('HonorUtils.getCrosslinkhonors (strCrosslinkhonorArguments): '..strCrosslinkhonorArguments)
 +
local strCrosslinkhonors = p.getHonorMetadata(src, strCrosslinkhonorArguments, srcIsHonor)
 +
strCrosslinkhonors = mw.ustring.gsub(strCrosslinkhonors,"[\n\r]", "")
 +
mw.log('HonorUtils.getCrosslinkhonors (strCrosslinkhonors): '..strCrosslinkhonors)
 +
tCrosslinkhonors = mw.text.split(strCrosslinkhonors, '|', C_notUseLUAPattern)
 
end
 
end
return t_variants
+
mw.log('HonorUtils.getCrosslinkhonors (#tCrosslinkhonors): '..#tCrosslinkhonors)
 +
return tCrosslinkhonors
 
end
 
end
  
function getHonorVariants(variantType, src, srcIsHonor)
+
function getHonorVariants( variantType, src, srcIsHonor, variantNumber )
 +
local frame = mw.getCurrentFrame()
 +
mw.log('HonorUtils.getHonorVariants (frame): '..frame:getTitle())
 +
local parentFrame = frame:getParent()
 +
local strActPageTitle = mw.title.getCurrentTitle().text
 +
mw.log('HonorUtils.getHonorVariants (strActPageTitle): '..strActPageTitle)
 +
local variantSrcMode = 'dpl' -- it can be 'vardefine', 'parentFrame' or 'dpl' (default)
 
if (variantType == nil or variantType == '') then
 
if (variantType == nil or variantType == '') then
 
variantType = 'requirement'
 
variantType = 'requirement'
 +
mw.log('HonorUtils.getHonorVariants: No variant Type set, default to requirements!')
 +
end
 +
local cntOfVariantsArgString = 'cnt_'..variantType..'_variants'
 +
local cntOfVariants = 0
 +
-- check if we are on the landing page of the wanted honor
 +
-- if yes we are able to use DPL
 +
-- if not we check if we are inside of the Template:HonorLanding
 +
-- if yes we can use the parentFrame method
 +
-- if not then we use the vardefine method
 +
local bIsLandingPage = false
 +
if ( srcIsHonor == true and strActPageTitle == 'AY Honors/'..src or
 +
strActPageTitle == src ) then
 +
bIsLandingPage = true
 +
end
 +
mw.log('HonorUtils.getHonorVariants: Is it the honors landing page? '..tostring(bIsLandingPage))
 +
if ( bIsLandingPage ~= true ) then
 +
mw.log('HonorUtils.getHonorVariants: Get variants data with DPL!')
 +
cntOfVariants = tonumber(p.getHonorMetadata(src, cntOfVariantsArgString, srcIsHonor))
 +
variantSrcMode = 'dpl'
 +
-- check if we are inside of Template:HonorLanding
 +
elseif ( parentFrame ~= nil and
 +
parentFrame:getTitle() == 'Template:HonorLanding' and
 +
parentFrame.args[cntOfVariantsArgString] ~= nil and
 +
parentFrame.args[cntOfVariantsArgString] ~= ''
 +
) then
 +
mw.log('HonorUtils.getHonorVariants: Get variants data from parent Frame!')
 +
variantSrcMode = 'parentFrame'
 +
cntOfVariants = parentFrame.args[cntOfVariantsArgString]
 +
else
 +
mw.log('HonorUtils.getHonorVariants: Get variants data from vardefine!')
 +
variantSrcMode = 'vardefine'
 +
cntOfVariants = utilities.getVar(cntOfVariantsArgString)
 
end
 
end
local cntOfVariants = tonumber(p.getHonorMetadata(src, 'cnt_'..variantType..'_variants', srcIsHonor))
+
if (cntOfVariants == nil or cntOfVariants == '' or tonumber(cntOfVariants) == 0) then
if (cntOfVariants == nil or cntOfVariants == 0) then
 
 
mw.log('HonorUtils.getHonorVariants: There are no '..variantType..' variants!')
 
mw.log('HonorUtils.getHonorVariants: There are no '..variantType..' variants!')
return ''
+
return nil
 
end
 
end
 
mw.log('HonorUtils.getHonorVariants (cntOfVariants): '..cntOfVariants)
 
mw.log('HonorUtils.getHonorVariants (cntOfVariants): '..cntOfVariants)
 
local actVariant = 0
 
local actVariant = 0
 
local tVariantArguments = {}
 
local tVariantArguments = {}
for actVariant = 1, cntOfVariants, 1 do
+
variantNumber = tonumber(variantNumber)
mw.log('HonorUtils.getHonorVariants (actVariant): '..actVariant)
+
if ( variantNumber ~= nil ) then
tVariantArguments[actVariant] = variantType .. '_variant_' .. actVariant
+
-- only get the defined Variant
 +
if ( variantNumber <= cntOfVariants ) then
 +
tVariantArguments[1] = variantType..'_'..variantNumber
 +
else
 +
mw.log('HonorUtils.getHonorVariants: invalid variantNumber ('..variantNumber..')!')
 +
return nil
 +
end
 +
else
 +
-- get all variants
 +
for actVariant = 1, cntOfVariants, 1 do
 +
mw.log('HonorUtils.getHonorVariants (actVariant): '..actVariant)
 +
tVariantArguments[actVariant] = variantType .. '_' .. actVariant
 +
end
 +
end
 +
 +
local tVariants = {}
 +
if ( variantSrcMode == 'vardefine' ) then
 +
for key, variantArg in pairs(tVariantArguments) do
 +
tVariants[key] = utilities.getVar(variantArg)
 +
end
 +
elseif ( variantSrcMode == 'parentFrame' ) then
 +
for key, variantArg in pairs(tVariantArguments) do
 +
tVariants[key] = parentFrame.args[variantArg]
 +
end
 +
else
 +
local strVariantArguments = mw.text.listToText(tVariantArguments, ':', ':')
 +
mw.log('HonorUtils.getHonorVariants (strVariantArguments): '..strVariantArguments)
 +
local strVariant = p.getHonorMetadata(src, strVariantArguments, srcIsHonor)
 +
strVariant = mw.ustring.gsub(strVariant,"[\n\r]", "")
 +
mw.log('HonorUtils.getHonorVariants (strVariant): '..strVariant)
 +
tVariants = mw.text.split(strVariant, '|', C_notUseLUAPattern)
 
end
 
end
local strVariantArguments = mw.text.listToText(tVariantArguments, ':', ':')
+
mw.log('HonorUtils.getHonorVariants (#tVariants): '..#tVariants)
mw.log('HonorUtils.getHonorVariants (strVariantArguments): '..strVariantArguments)
+
return tVariants
local strVariant = p.getHonorMetadata(src, strVariantArguments, srcIsHonor)
 
strVariant = mw.ustring.gsub(strVariant,"[\n\r]", "")
 
mw.log('HonorUtils.getHonorVariants (strVariant): '..strVariant)
 
return strVariant
 
 
end
 
end
  

Latest revision as of 18:55, 5 September 2021

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

local p = {}
local utilities = require ( "Module:Utilities" )
local C_notUseLUAPattern = true
local C_srcIsNotHonor = false

-- returns a table with the type and the number of the variant of the act. page
function p.getActVariantInfo( frame )
	local pageTitle = frame:expandTemplate{ title = 'PAGENAMEwithoutLang' }
	mw.log('HonorUtils.getActVariantInfo (pageTitle): '..pageTitle)
	local tPageTitle = mw.text.split(pageTitle, '/', C_notUseLUAPattern)
	
	local subPageString = tPageTitle[3]
	if (subPageString == nil) then
		mw.log('HonorUtils.getActVariantInfo: It is not a valid Subpage (nil)!')
		return nil
	end
	
	local variantNumber = utilities.getNumber(subPageString)
	if (variantNumber == nil) then
		-- if the page has no number then it is mostlikely number one
		-- and if it is an invalid subpage then the number won't be used anyway's
		variantNumber = 1
	end
	local tReturn = {
		variantNumber = variantNumber
	}
	-- check for valid subpages
	if ( mw.ustring.find(subPageString, 'Requirements', 0, C_notUseLUAPattern) ~= nil ) then
		mw.log('HonorUtils.getActVariantInfo: It is the Requirements Variant '..variantNumber)
		tReturn['variantType'] = 'requirements'
		tReturn['subPage'] = 'Requirements'
	elseif (mw.ustring.find(subPageString, 'Answer Key', 0, C_notUseLUAPattern) ~= nil ) then
		mw.log('HonorUtils.getActVariantInfo: It is the Answer Key Variant '..variantNumber)
		tReturn['variantType'] = 'answerKey'
		tReturn['subPage'] = 'Answer Key'
	elseif (mw.ustring.find(subPageString, 'Lesson Plans', 0, C_notUseLUAPattern) ~= nil ) then
		mw.log('HonorUtils.getActVariantInfo: It is the Lesson Plans page, no variant possible.')
		tReturn['subPage'] = 'Lesson Plans'
	elseif (mw.ustring.find(subPageString, 'Answer Key', 0, C_notUseLUAPattern) ~= nil ) then
		mw.log('HonorUtils.getActVariantInfo: It is the Worksheet page, no variant possible.')
		tReturn['subPage'] = 'Worksheet'
	else
		mw.log('HonorUtils.getActVariantInfo: It is a invalid Subpage!')
		return nil
	end
	return tReturn
end

function p.getVariantsData( frame, landingPage, variantType, variantNumber )
	if ( frame == nil ) then
		frame = mw.getCurrentFrame()
		mw.log( 'HonorUtils.getVariantsData (frame): '..frame:getTitle() )
	end
	if ( landingPage == nil or landingPage == "" ) then
		landingPage = frame:expandTemplate{ title='GetHonorLandingPage' }
	end
	local getAnswerVariants = true
	local tAnswerVariants = nil
	local getRequirementVariants = true
	local tRequirementVariants = nil
	
	-- check if only one variant is needed
	if ( variantType ~= nil and variantType ~= '' ) then
		if (variantType == 'requirements') then
			getAnswerVariants = false
		elseif (variantType == 'answerKey') then
			getRequirementVariants = false
		else
			mw.log( 'HonorUtils.getVariantsData: Invalid variantType!' )
			return nil;
		end
	end

	if ( getAnswerVariants == true ) then
		tAnswerVariants = getHonorVariants( 'answerKey', landingPage, C_srcIsNotHonor, variantNumber )
		if ( tAnswerVariants == nil ) then
			mw.log("HonorUtils.getVariantsData: It isn't possible to get any answer variant's data!")
		end
	end
	
	if ( getRequirementVariants == true ) then
		tRequirementVariants = getHonorVariants( 'requirements', landingPage, C_srcIsNotHonor, variantNumber )
		if ( tRequirementVariants == nil ) then
			mw.log("HonorUtils.getVariantsData: It isn't possible to get any requirement variant's data!")
		end
	end
	
	local tVariants = {
		answers = tAnswerVariants,
		requirements = tRequirementVariants
	}
	
	tVariants = expandHonorVariants( frame, tVariants )
	
	tVariants = translateHonorVariants( frame, tVariants )
	return tVariants
end

function p.getCrosslinkhonorsData( frame, landingPage )
	local tCrosslinkhonor = {}
	if ( frame == nil ) then
		frame = mw.getCurrentFrame()
		mw.log( 'HonorUtils.getCrosslinkhonorsData (frame): '..frame:getTitle() )
	end
	mw.log( 'HonorUtils.getCrosslinkhonorsData (landingPage - function Argument): '..tostring(landingPage) )
	if ( landingPage == nil or landingPage == "" ) then
		landingPage = frame:expandTemplate{ title='GetHonorLandingPage' }
		mw.log( 'HonorUtils.getCrosslinkhonorsData (landingPage - from Template): '..landingPage )
	end
	
	local tCrosslinkhonors = getCrosslinkhonors( landingPage, C_srcIsNotHonor )
	
	if ( tCrosslinkhonors ~= nil and #tCrosslinkhonors ~= 0 ) then
		for key, crosslinkhonor in pairs(tCrosslinkhonors) do
			--clh = crosslinkhonor
			local strClhLandingPage = frame:expandTemplate{ 
				title='GetHonorLandingPage', 
				args = { honor = crosslinkhonor } 
			}
			tCrosslinkhonors[key] = {
				name = crosslinkhonor,
				landingPage = strClhLandingPage,
				tVariants = p.getVariantsData( frame, strClhLandingPage )
			}
		end
	else
		tCrosslinkhonors = {}
	end

	return tCrosslinkhonors
end

function expandHonorVariants( frame, tVariants )
	local tRetVariants = tVariants
	if ( tVariants == nil ) then
		mw.log('HonorUtils.expandHonorVariants: No Variants to Expand (nil)!')
		return {}
	end
	if ( tVariants['answers'] == nil ) then
		mw.log('HonorUtils.expandHonorVariants: No Answer Variants to Expand!')
	else
		-- expand the answer Variants
		local tAnswers = tVariants['answers']
		mw.log('HonorUtils.expandHonorVariants: There are '..#tAnswers..' Answer Variants to Expand!')
		for key, variant in pairs(tAnswers) do
			mw.log('HonorUtils.expandHonorVariants (key, variant): '..key..', '..variant)
			local tActVariant = {
				orig = variant,
				countries = {}
			}
			
			-- seperate the source language suffix
			local tSplitAnsVariant = mw.text.split(variant, '/', C_notUseLUAPattern)
			if (tSplitAnsVariant[2] ~= nil and tSplitAnsVariant[2] ~= '') then
				tActVariant['srcLangSuffix'] = '/'..tSplitAnsVariant[2]
				mw.log('HonorUtils.expandHonorVariants (srcLangSuffix): '..tActVariant['srcLangSuffix'])
			else
				mw.log('HonorUtils.expandHonorVariants: There is no source language set, default to english, which is an empty string ;)')
				tActVariant['srcLangSuffix'] = ''
			end
			
			-- seperate Countries and Authority
			tSplitAnsVariant = mw.text.split(tSplitAnsVariant[1], ';;', C_notUseLUAPattern)
			if ( tSplitAnsVariant[1] ~= '') then
				tActVariant['countries']['orig'] = tSplitAnsVariant[1]
				-- seperate the Countries
				tActVariant['countries']['split'] = mw.text.split(tActVariant['countries']['orig'], ';', C_notUseLUAPattern)
				mw.log('HonorUtils.expandHonorVariants (Countries - Orig): '..tActVariant['countries']['orig'])
			else
				mw.log('HonorUtils.expandHonorVariants: There are no countries for that variant!')
			end
			-- set the authority
			if ( tSplitAnsVariant[2] == nil ) then
				tActVariant['authority'] = nil
				mw.log('HonorUtils.expandHonorVariants (Authority): nil')
			else
				tActVariant['authority'] = tSplitAnsVariant[2]
				mw.log('HonorUtils.expandHonorVariants (Authority): '..tActVariant['authority'])
			end
			-- save act. Variant into the table
			tAnswers[key] = tActVariant
		end
		tVariants['answers'] = tAnswers
		mw.log('HonorUtils.expandHonorVariants: '..#tVariants['answers']..' Answer Variants expanded!')
	end
	if ( tVariants['requirements'] == nil ) then
		mw.log('HonorUtils.expandHonorVariants: No Requirement Variants to Expand!')
	else
		-- expand the requirement Variants
		local tRequirements = tVariants['requirements']
		mw.log('HonorUtils.expandHonorVariants: There are '..#tRequirements..' Requirement Variants to Expand!')
		for key, variant in pairs(tRequirements) do
			mw.log('HonorUtils.expandHonorVariants (key, variant): '..key..', '..variant)
			-- seperate Authorities
			local tSplitReqVariant = mw.text.split(variant, ';', C_notUseLUAPattern)
			local tActReqVariant = {
				orig = variant,
				authorities = tSplitReqVariant
			}
			tRequirements[key] = tActReqVariant
		end
		tVariants['requirements'] = tRequirements
		mw.log('HonorUtils.expandHonorVariants: '..#tVariants['requirements']..' Requirement Variants expanded!')
	end
	return tRetVariants
end

function translateHonorVariants( frame, tVariants )
	local tRetVariants = tVariants
	if ( tRetVariants == nil ) then
		mw.log('HonorUtils.translateHonorVariants: There are no Variants (nil)!')
	end
	if ( tRetVariants['answers'] == nil ) then
		mw.log('HonorUtils.translateHonorVariants: There are no Answer Variants!')
	else
		mw.log('HonorUtils.translateHonorVariants: There are '..#tRetVariants['answers']..' Answer Variants to translate!')
		for varKey, variant in pairs(tRetVariants['answers']) do
			if ( variant == nil or variant['countries'] == nil or variant['countries']['split'] == nil ) then
				mw.log('HonorUtils.translateHonorVariants: Answer Variant is invalid!')
			else
				mw.log('HonorUtils.translateHonorVariants: There are '..#variant['countries']['split']..' Answer Variant Countries to translate!')
				for countryKey, country in pairs(variant['countries']['split']) do
					local trans = utilities.localize( country, 'Countries' )
					-- check if Localization returned something, if not set the original string
					mw.log('HonorUtils.translateHonorVariants (country, trans): '..country..', '..trans)
					if ( trans == '' ) then
						trans = country
					end
					tRetVariants['answers'][varKey]['countries']['split'][countryKey] = {
						orig = country,
						translated = trans
					}
				end
				mw.log('HonorUtils.translateHonorVariants: '..#tRetVariants['answers'][varKey]['countries']['split']..' Answer Variant Countries were translated!')
			end
		end
		mw.log('HonorUtils.translateHonorVariants: '..#tRetVariants['answers']..' Answer Variants were translated!')
	end
	if ( tRetVariants['requirements'] == nil ) then
		mw.log('HonorUtils.translateHonorVariants: There are no Requirement Variants!')
	else
		mw.log('HonorUtils.translateHonorVariants: There are '..#tRetVariants['requirements']..' Requriement Variants to translate!')
		for varKey, variant in pairs(tRetVariants['requirements']) do
			if ( variant == nil or variant['authorities'] == nil ) then
				mw.log('HonorUtils.translateHonorVariants: Requriement Variant is invalid!')
			else
				mw.log('HonorUtils.translateHonorVariants: There are '..#variant['authorities']..' Requriement Variant Authorities to translate!')
				for authorityKey, authority in pairs(variant['authorities']) do
					local trans = utilities.localize( authority, 'Authorities' )
					-- check if Localization returned something, if not set the original string
					if ( trans == '' ) then
						trans = authority
					end
					tRetVariants['requirements'][varKey]['authorities'][authorityKey] = {
						orig = authority,
						translated = trans
					}
				end
				mw.log('HonorUtils.translateHonorVariants: '..#tRetVariants['requirements'][varKey]['authorities']..' Requriement Variant Authorities were translated!')
			end
		end
		mw.log('HonorUtils.translateHonorVariants: '..#tRetVariants['requirements']..' Requriement Variants were translated!')
	end
	return tRetVariants
end

function getCrosslinkhonors( src, srcIsHonor )
	local frame = mw.getCurrentFrame()
	mw.log('HonorUtils.getCrosslinkhonors (frame): '..frame:getTitle())
	local parentFrame = frame:getParent()
	local strActPageTitle = mw.title.getCurrentTitle().text
	mw.log('HonorUtils.getCrosslinkhonors (strActPageTitle): '..strActPageTitle)
	local srcMode = 'dpl' -- it can be 'vardefine', 'parentFrame' or 'dpl' (default)
	local cntCrosslinkhonors = 0
	-- check if we are on the landing page of the wanted honor
	-- if yes we are able to use DPL
	-- if not we check if we are inside of the Template:HonorLanding
	-- if yes we can use the parentFrame method
	-- if not then we use the vardefine method
	local bIsLandingPage = false
	if ( srcIsHonor == true and strActPageTitle == 'AY Honors/'..src or
		 strActPageTitle == src ) then
		bIsLandingPage = true
	end
	mw.log('HonorUtils.getCrosslinkhonors: Is it the honors landing page? '..tostring(bIsLandingPage))
	if ( bIsLandingPage ~= true ) then
		mw.log('HonorUtils.getCrosslinkhonors: Get variants data with DPL!')
		cntCrosslinkhonors = tonumber(p.getHonorMetadata(src, 'cnt_crosslinkhonors', srcIsHonor))
		srcMode = 'dpl'
	-- check if we are inside of Template:HonorLanding
	elseif ( parentFrame ~= nil and
		 parentFrame:getTitle() == 'Template:HonorLanding' and
		 parentFrame.args['cnt_crosslinkhonors'] ~= nil and 
		 parentFrame.args['cnt_crosslinkhonors'] ~= '' 
		) then
		mw.log('HonorUtils.getCrosslinkhonors: Get Crosslinkhonors from parent Frame!')
		srcMode = 'parentFrame'
		cntCrosslinkhonors = parentFrame.args['cnt_crosslinkhonors']
	else
		mw.log('HonorUtils.getCrosslinkhonors: Get Crosslinkhonors from vardefine!')
		srcMode = 'vardefine'
		cntCrosslinkhonors = utilities.getVar('cnt_crosslinkhonors')
	end
	if (cntCrosslinkhonors == nil or cntCrosslinkhonors == '' or tonumber(cntCrosslinkhonors) == 0) then
		mw.log('HonorUtils.getCrosslinkhonors: There are no Crosslinkhonors!')
		return nil
	end
	mw.log('HonorUtils.getCrosslinkhonors (cntCrosslinkhonors): '..cntCrosslinkhonors)
	local actLink = 0
	local tCrosslinkhonorArguments = {}
	-- get all Crosshonor Links
	for actLink = 1, cntCrosslinkhonors, 1 do
		mw.log('HonorUtils.getCrosslinkhonors (actLink): '..actLink)
		tCrosslinkhonorArguments[actLink] = 'crosslinkhonor_'..actLink
	end
	
	local tCrosslinkhonors = {}
	if ( srcMode == 'vardefine' ) then
		for key, crosslinkhonorArg in pairs(tCrosslinkhonorArguments) do
			tCrosslinkhonors[key] = utilities.getVar(crosslinkhonorArg)
		end
	elseif ( srcMode == 'parentFrame' ) then
		for key, crosslinkhonorArg in pairs(tCrosslinkhonorArguments) do
			tCrosslinkhonors[key] = parentFrame.args[crosslinkhonorArg]
		end
	else
		local strCrosslinkhonorArguments = mw.text.listToText(tCrosslinkhonorArguments, ':', ':')
		mw.log('HonorUtils.getCrosslinkhonors (strCrosslinkhonorArguments): '..strCrosslinkhonorArguments)
		local strCrosslinkhonors = p.getHonorMetadata(src, strCrosslinkhonorArguments, srcIsHonor)
		strCrosslinkhonors = mw.ustring.gsub(strCrosslinkhonors,"[\n\r]", "")
		mw.log('HonorUtils.getCrosslinkhonors (strCrosslinkhonors): '..strCrosslinkhonors)
		tCrosslinkhonors = mw.text.split(strCrosslinkhonors, '|', C_notUseLUAPattern)
	end
	mw.log('HonorUtils.getCrosslinkhonors (#tCrosslinkhonors): '..#tCrosslinkhonors)
	return tCrosslinkhonors
end

function getHonorVariants( variantType, src, srcIsHonor, variantNumber )
	local frame = mw.getCurrentFrame()
	mw.log('HonorUtils.getHonorVariants (frame): '..frame:getTitle())
	local parentFrame = frame:getParent()
	local strActPageTitle = mw.title.getCurrentTitle().text
	mw.log('HonorUtils.getHonorVariants (strActPageTitle): '..strActPageTitle)
	local variantSrcMode = 'dpl' -- it can be 'vardefine', 'parentFrame' or 'dpl' (default)
	if (variantType == nil or variantType == '') then
		variantType = 'requirement'
		mw.log('HonorUtils.getHonorVariants: No variant Type set, default to requirements!')
	end
	local cntOfVariantsArgString = 'cnt_'..variantType..'_variants'
	local cntOfVariants = 0
	-- check if we are on the landing page of the wanted honor
	-- if yes we are able to use DPL
	-- if not we check if we are inside of the Template:HonorLanding
	-- if yes we can use the parentFrame method
	-- if not then we use the vardefine method
	local bIsLandingPage = false
	if ( srcIsHonor == true and strActPageTitle == 'AY Honors/'..src or
		 strActPageTitle == src ) then
		bIsLandingPage = true
	end
	mw.log('HonorUtils.getHonorVariants: Is it the honors landing page? '..tostring(bIsLandingPage))
	if ( bIsLandingPage ~= true ) then
		mw.log('HonorUtils.getHonorVariants: Get variants data with DPL!')
		cntOfVariants = tonumber(p.getHonorMetadata(src, cntOfVariantsArgString, srcIsHonor))
		variantSrcMode = 'dpl'
	-- check if we are inside of Template:HonorLanding
	elseif ( parentFrame ~= nil and
		 parentFrame:getTitle() == 'Template:HonorLanding' and
		 parentFrame.args[cntOfVariantsArgString] ~= nil and 
		 parentFrame.args[cntOfVariantsArgString] ~= '' 
		) then
		mw.log('HonorUtils.getHonorVariants: Get variants data from parent Frame!')
		variantSrcMode = 'parentFrame'
		cntOfVariants = parentFrame.args[cntOfVariantsArgString]
	else
		mw.log('HonorUtils.getHonorVariants: Get variants data from vardefine!')
		variantSrcMode = 'vardefine'
		cntOfVariants = utilities.getVar(cntOfVariantsArgString)
	end
	if (cntOfVariants == nil or cntOfVariants == '' or tonumber(cntOfVariants) == 0) then
		mw.log('HonorUtils.getHonorVariants: There are no '..variantType..' variants!')
		return nil
	end
	mw.log('HonorUtils.getHonorVariants (cntOfVariants): '..cntOfVariants)
	local actVariant = 0
	local tVariantArguments = {}
	variantNumber = tonumber(variantNumber)
	if ( variantNumber ~= nil ) then
		-- only get the defined Variant
		if ( variantNumber <= cntOfVariants ) then
			tVariantArguments[1] = variantType..'_'..variantNumber
		else
			mw.log('HonorUtils.getHonorVariants: invalid variantNumber ('..variantNumber..')!')
			return nil
		end
	else
		-- get all variants
		for actVariant = 1, cntOfVariants, 1 do
			mw.log('HonorUtils.getHonorVariants (actVariant): '..actVariant)
			tVariantArguments[actVariant] = variantType .. '_' .. actVariant
		end
	end
	
	local tVariants = {}
	if ( variantSrcMode == 'vardefine' ) then
		for key, variantArg in pairs(tVariantArguments) do
			tVariants[key] = utilities.getVar(variantArg)
		end
	elseif ( variantSrcMode == 'parentFrame' ) then
		for key, variantArg in pairs(tVariantArguments) do
			tVariants[key] = parentFrame.args[variantArg]
		end
	else
		local strVariantArguments = mw.text.listToText(tVariantArguments, ':', ':')
		mw.log('HonorUtils.getHonorVariants (strVariantArguments): '..strVariantArguments)
		local strVariant = p.getHonorMetadata(src, strVariantArguments, srcIsHonor)
		strVariant = mw.ustring.gsub(strVariant,"[\n\r]", "")
		mw.log('HonorUtils.getHonorVariants (strVariant): '..strVariant)
		tVariants = mw.text.split(strVariant, '|', C_notUseLUAPattern)
	end
	mw.log('HonorUtils.getHonorVariants (#tVariants): '..#tVariants)
	return tVariants
end

function p.getHonorMetadata(src, metadata, srcIsHonor)
	local frame = mw.getCurrentFrame()
	local lPage = ''
	if (src ~= '' and src ~= nil) then
		if (srcIsHonor == true) then
			lPage = 'AY Honors/' .. src
		else
			lPage = src
		end
	end
	lPage = frame:expandTemplate{ title = 'GetHonorLandingPage', args = {page = lPage}}
	return frame:preprocess( '{{#dpl:|debug=0|title=' .. lPage .. '|include={HonorLanding}:' .. metadata ..'}}' )
end

return p