模組:ArticleAlertGrouping

require('strict')

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
     local args = getArgs(frame)
     return p._main(args)
end

function p._main(args)

     local workflow_names = {
          COPYVIO = '侵权',
          CSD = '快速删除',
          DRV = '存废复核',
          DYK = '新条目推荐',
          FA = '特色内容',
          FAME = '关注度',
          GA = '优良条目',
          IFD = '档案存废讨论',
          ITN = '新闻动态候选',
          MM = '合并',
          MV = '移动请求',
          NOZH = '非中文内容',
          PP = '保护',
          PR = '同行评审',
          RFC = '正在讨论的条目',
          SPLIT = '拆分',
          SUB = '小小作品',
          TFC = '今日首页特色内容',
          TGA = '今日首页优良条目',
          TRANS = '迁移到其他计划',
          VFD = '页面存废',
     }

     local wikitext = mw.title.new(args[1]):getContent()
     local source_by_worksflow = {}
     local pos_start, pos_end = 0, 0

     while true do
          pos_start =  mw.ustring.find(wikitext,'\n;', pos_end + 1)
          if pos_start == nil then break end
          pos_end =  mw.ustring.find(wikitext, '\n[^*]', pos_start + 1)

          local text = mw.ustring.sub(wikitext, pos_start, pos_end)
          local _pos_start =  mw.ustring.find(text, ';')
          local _pos_end =  mw.ustring.find(text, '\n', _pos_start + 1)
          local key =  mw.ustring.sub(text, _pos_start + 1 , _pos_end - 1)
          local value =  mw.ustring.sub(text, _pos_end + 1)
          source_by_worksflow[key] = value
     end

     local enabled_workflows = mw.text.split( args.workflows, '%s*,%s*' )
     local ret = {}

     for _, v in ipairs(enabled_workflows) do
          local workflow_title = workflow_names[v]
          if source_by_worksflow[workflow_title] ~= nil then
               table.insert(ret, '; ' .. workflow_title .. '\n' .. source_by_worksflow[workflow_title])
          end
     end

   return mw.getCurrentFrame():preprocess(table.concat( ret, '\n' ))

end

return p