Module:TestModule: Difference between revisions

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


function p.hello( frame )
function funcRecurseLineage(parentTopic)
return "Hello, world!"


   -- if row.shape == targetShape then
--Check for children of the parent topic
  -- output = output .. " <li>" .. "[[" .. row.shape .. "]]"
local output = ""
   -- end
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
end


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


local fruits, errors1 = mw.ext.externaldata.getWebData {
function funcRecurseLineageNumber(parentID)
    url = "https://discoursedb.org/wiki/Special:GetData/Fruits_data"
  , data = "name=Name,color=Color,shape=Shape"
  , format = "CSV with header"
}


  local topics, errors2 = mw.ext.externaldata.getExternalData {
--Check for children of the parent topic
   source = CaseData
local output = ""
   , query = childrenTopics
  local topics, errors = mw.ext.externaldata.getExternalData {
   , data = "topicName = topic_name"
   source = "CaseData",
   , parameters = "parentTopic"
   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 i, fruit in ipairs(fruits) do
  --For each child topic, add them as a list item, and check for their children
  output = output .. " <li>" .. "[[" .. fruit.shape .. "]]"
  for i, topic in ipairs(topics) do
  output = output .. " <li>" .. "[[" .. topic.topicName .. "]]"
  output = output .. funcRecurseLineageNumber(topic.topicID)
  end
  output = output .. "</ul>"
  end
  end


  for i, error in ipairs(errors2) do
  return output
  output = output .. " <li>" .. "[[" .. error .. "]]"
 
end
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)


return errors2
end
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


return p
return p