Jump to content

Module:TestModule: Difference between revisions

From NewsWikiTestbed
AdamZachar (talk | contribs)
No edit summary
AdamZachar (talk | contribs)
No edit summary
 
(40 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {} --p stands for package
local p = {}


function funcRecurseLineage(output, parentTopic)
function funcRecurseLineage(parentTopic)


--Check for children of the parent topic
local output = ""
  local topics, errors = mw.ext.externaldata.getExternalData {
  local topics, errors = mw.ext.externaldata.getExternalData {
   source = "CaseData",
   source = "CaseData",
   query = "childrenTopics",
   query = "childrenTopics", --Note: this query is deprecated in deference to ChildrenTopicsByID, since it relied on topics.topic_parentname
   data = "topicName=topic_name",
   data = "topicName=topic_name",
   parameters = parentTopic
   parameters = parentTopic
   }
   }


--If there are children topics, start a new layer of the list
  if topics ~= nil then
  if topics ~= nil then
   output = output .. "<ul>"
   output = output .. "<ul>"


  --For each child topic, add them as a list item, and check for their children
   for i, topic in ipairs(topics) do
   for i, topic in ipairs(topics) do
  output = output .. " <li>" .. "[[" .. topic.topicName .. "]]"
  output = output .. funcRecurseLineage(topic.topicName)
  end
  output = output .. "</ul>"
end
return output
end
function p.recurseLineage( frame )
return funcRecurseLineage(frame.args.parentTopic)  --Note: this query is deprecated in deference to ChildrenTopicsByID


  output = output .. " <li>" .. "[[" .. topic.topicName .. "]]"
end


  local childTopics, errors3 = mw.ext.externaldata.getExternalData {
    source = "CaseData",
    query = "childrenTopics",
    data = "topicName=topic_name",
    parameters = topic.topicName
  }


  if childTopics ~= nil then
function funcRecurseLineageNumber(parentID)
    output = output .. "<ul>"
    for i, childTopic in ipairs(childTopics) do
    output = output .. " <li>" .. "[[" .. childTopic.topicName .. "]]"
    end
    output = output .. "</ul>"
  end


--Check for children of the parent topic
local output = ""
local topics, errors = mw.ext.externaldata.getExternalData {
  source = "CaseData",
  query = "childrenTopicsByID",
  data = "topicName=topic_name, topicID=topic_id",
  parameters = parentID
  }
--If there are children topics, start a new layer of the list
if topics ~= nil then
  output = output .. "<ul>"
  --For each child topic, add them as a list item, and check for their children
  for i, topic in ipairs(topics) do
  output = output .. " <li>" .. "[[" .. topic.topicName .. "]]"
  output = output .. funcRecurseLineageNumber(topic.topicID)
   end
   end
   output = output .. "</ul>"
   output = output .. "</ul>"
  end
  end


Line 43: Line 63:
end
end


function testFunc()
return "test!"
end


function p.recurseLineage( frame )
function p.recurseLineageByID( frame )
 
local topics, errors = mw.ext.externaldata.getExternalData {
  source = "CaseData",
  query = "childrenTopicsByID",
  data = "topicName=topic_name, topicID=topic_id",
  parameters = frame.args.parentID
  }


  --final = funcRecurseLineage({output=frame.args.output, parentTopic=frame.args.parentTopic})
  if topics == nil then return "N/A" end


  return testFunc()
  return funcRecurseLineageNumber(frame.args.parentID)


end
end


function p.topicLineage( frame )
function p.topicIDByName( frame )
 
local output = ""
local parentTopic = frame.args.parentTopic


  local topics, errors = mw.ext.externaldata.getExternalData {
  local topics, errors = mw.ext.externaldata.getExternalData {
   source = "CaseData",
   source = "CaseData",
   query = "childrenTopics",
   query = "oneTopic",
   data = "topicName=topic_name",
   data = "topicID=topic_id",
   parameters = parentTopic
   parameters = frame.args.topicName
   }
   }


  if topics ~= nil then
  if topics == nil then return 0 end


  output = output .. "<ul>"
return topics.topicID


  for i, topic in ipairs(topics) do
end


  output = output .. " <li>" .. "[[" .. topic.topicName .. "]]"
function p.topicListByCaseName( frame )


  local childTopics, errors3 = mw.ext.externaldata.getExternalData {
local output = ""
    source = "CaseData",
    query = "childrenTopics",
    data = "topicName=topic_name",
    parameters = topic.topicName
  }


  if childTopics ~= nil then
local topics, errors = mw.ext.externaldata.getExternalData {
    output = output .. "<ul>"
  source = "CaseData",
    for i, childTopic in ipairs(childTopics) do
  query = "topicsByCase",
    output = output .. " <li>" .. "[[" .. childTopic.topicName .. "]]"
  data = "topicName=topic_name",
    end
  parameters = frame.args.caseTitle
    output = output .. "</ul>"
  }
  end


  end
if topics == nil then return output end


  output = output .. "</ul>"
output = output .. "<ul>"


for i, topic in ipairs(topics) do
  output = output .. " <li>" .. "[[" .. topic.topicName .. "]]"
  end
  end
output = output .. "</ul>"


  return output
  return output


end
end


return p
return p

Latest revision as of 11:36, 20 June 2025


local p = {}

function funcRecurseLineage(parentTopic)

 --Check for children of the parent topic
 local output = ""
 local topics, errors = mw.ext.externaldata.getExternalData {
   source = "CaseData",
   query = "childrenTopics", --Note: this query is deprecated in deference to ChildrenTopicsByID, since it relied on topics.topic_parentname
   data = "topicName=topic_name",
   parameters = parentTopic
  }

 --If there are children topics, start a new layer of the list
 if topics ~= nil then
  output = output .. "<ul>"

  --For each child topic, add them as a list item, and check for their children
  for i, topic in ipairs(topics) do
   output = output .. " <li>" .. "[[" .. topic.topicName .. "]]"
   output = output .. funcRecurseLineage(topic.topicName)
  end
  output = output .. "</ul>"
 end

 return output

end


function p.recurseLineage( frame )

 return funcRecurseLineage(frame.args.parentTopic)  --Note: this query is deprecated in deference to ChildrenTopicsByID

end


function funcRecurseLineageNumber(parentID)

 --Check for children of the parent topic
 local output = ""
 local topics, errors = mw.ext.externaldata.getExternalData {
   source = "CaseData",
   query = "childrenTopicsByID",
   data = "topicName=topic_name, topicID=topic_id",
   parameters = parentID
  }

 --If there are children topics, start a new layer of the list
 if topics ~= nil then
  output = output .. "<ul>"

  --For each child topic, add them as a list item, and check for their children
  for i, topic in ipairs(topics) do
   output = output .. " <li>" .. "[[" .. topic.topicName .. "]]"
   output = output .. funcRecurseLineageNumber(topic.topicID)
  end
  output = output .. "</ul>"
 end

 return output

end


function p.recurseLineageByID( frame )

 local topics, errors = mw.ext.externaldata.getExternalData {
   source = "CaseData",
   query = "childrenTopicsByID",
   data = "topicName=topic_name, topicID=topic_id",
   parameters = frame.args.parentID
  }

 if topics == nil then return "N/A" end

 return funcRecurseLineageNumber(frame.args.parentID)

end

function p.topicIDByName( frame )

 local topics, errors = mw.ext.externaldata.getExternalData {
   source = "CaseData",
   query = "oneTopic",
   data = "topicID=topic_id",
   parameters = frame.args.topicName
  }

 if topics == nil then return 0 end

 return topics.topicID

end

function p.topicListByCaseName( frame )

 local output = ""

 local topics, errors = mw.ext.externaldata.getExternalData {
   source = "CaseData",
   query = "topicsByCase",
   data = "topicName=topic_name",
   parameters = frame.args.caseTitle
  }

 if topics == nil then return output end

 output = output .. "<ul>"

 for i, topic in ipairs(topics) do
  output = output .. " <li>" .. "[[" .. topic.topicName .. "]]"
 end

 output = output .. "</ul>"

 return output

end

return p