模块:Phrases/Query:修订间差异

来自「荏苒之境」
// via Wikitext Extension for VSCode
无编辑摘要
第7行: 第7行:
local query = {}
local query = {}


local function get(table_name, config)
local function get(table_name, language, config)
     local theme_order_by = config.theme_order_by and escape_sql(config.theme_order_by)
     local theme_order_by = config.theme_order_by and escape_sql(config.theme_order_by)
     local phrase_order_by = config.phrase_order_by and escape_sql(config.phrase_order_by)
     local phrase_order_by = config.phrase_order_by and escape_sql(config.phrase_order_by)
第20行: 第20行:


     local r = {}
     local r = {}
     for _, theme in ipairs(themes) do
     for _, theme_entry in ipairs(themes) do
    local theme = theme_entry.Theme
         local phrase_query = cargo.query(table_name, "Phrase", {
         local phrase_query = cargo.query(table_name, "Phrase", {
             where = "Theme='"..escape_sql(theme).."'",
             where = "Theme='"..escape_sql(theme).."' AND Language='"..escape_sql(language).."'",
             orderBy = phrase_order_by,
             orderBy = phrase_order_by,
             limit = phrase_limit_per_theme,
             limit = phrase_limit_per_theme,
         })
         })
         local phrases = {}
         local phrases = {}
         for _, entry in phrase_query do
         for _, entry in pairs(phrase_query) do
             phrases[#phrases+1] = entry.Phrase
             phrases[#phrases+1] = entry.Phrase
         end
         end
         r[theme] = phrases
         r[#r+1] = {theme, phrases}
     end
     end
     return r
     return r
end
end
query.get = get


query.show = function(frame)
query.show = function(frame)

2025年8月23日 (六) 20:40的版本

此模块的文档可以在模块:Phrases/Query/doc创建

local translation = require("Module:Template translation")
local utils_str = require("Module:Utils/String")

local cargo = mw.ext.cargo
local escape_sql = utils_str.escape_sql

local query = {}

local function get(table_name, language, config)
    local theme_order_by = config.theme_order_by and escape_sql(config.theme_order_by)
    local phrase_order_by = config.phrase_order_by and escape_sql(config.phrase_order_by)
    local theme_limit = config.theme_limit
    local phrase_limit_per_theme = config.phrase_limit_per_theme

    local themes = cargo.query("PhraseThemes", "Theme", {
        where = "PhraseTable='"..table_name.."'",
        orderBy = theme_order_by,
        limit = theme_limit
    })

    local r = {}
    for _, theme_entry in ipairs(themes) do
    	local theme = theme_entry.Theme
        local phrase_query = cargo.query(table_name, "Phrase", {
            where = "Theme='"..escape_sql(theme).."' AND Language='"..escape_sql(language).."'",
            orderBy = phrase_order_by,
            limit = phrase_limit_per_theme,
        })
        local phrases = {}
        for _, entry in pairs(phrase_query) do
            phrases[#phrases+1] = entry.Phrase
        end
        r[#r+1] = {theme, phrases}
    end
    return r
end

query.get = get

query.show = function(frame)
    local args = frame.args
    local table_name = escape_sql(args.table)

    local parent_frame = frame:getParent()
	local language = translation.getCurrentLanguageSubpage()
	if language == nil or language == "" then
		language = "zh-cn"
	end

    local t = {"<ul>"}


    return table.concat(t)
end

return query