From c1cab1e7fcf7b2e4de2fae0091a8d9d41e6b6e71 Mon Sep 17 00:00:00 2001 From: Tphamtranba <119475427+Bapham12@users.noreply.github.com> Date: Tue, 14 Apr 2026 22:09:17 +0700 Subject: [PATCH 1/2] Add CheckSizeImage.lua to validate image aspect ratio --- Other/CheckSizeImage.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Other/CheckSizeImage.lua diff --git a/Other/CheckSizeImage.lua b/Other/CheckSizeImage.lua new file mode 100644 index 0000000..9f066cf --- /dev/null +++ b/Other/CheckSizeImage.lua @@ -0,0 +1,23 @@ +local p = {} + +function p.main(frame) + local result = "" + local title = mw.title.new(mw.text.trim(frame.args[1]), 6) + + if (title ~= nil and title.fileExists) then + local image = title.file + local w = image.width + local h = image.height + local ratio = w/h + + -- Nếu tỷ lệ w/h > 2.5 hoặc < 0.5 thì báo lỗi + if (ratio < 0.5 or ratio > 2.5) then + local span = mw.html.create("span"):attr("class", "error"):wikitext("Hình ảnh chọn lọc phải có tỷ lệ chiều rộng/chiều cao từ 0.5 đến 2.5. Hình này đang có tỷ lệ là " .. math.floor(ratio * 100) / 100 .. " [= " .. w .. "/" .. h .. "].") + result = tostring(span) + end + end + + return result +end + +return p From cf348f08f7bc205a71b1266bded664c437460c22 Mon Sep 17 00:00:00 2001 From: Tphamtranba <119475427+Bapham12@users.noreply.github.com> Date: Tue, 14 Apr 2026 22:09:55 +0700 Subject: [PATCH 2/2] Add MaxWidthResponsive.lua for image width handling --- Other/MaxWidthResponsive.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Other/MaxWidthResponsive.lua diff --git a/Other/MaxWidthResponsive.lua b/Other/MaxWidthResponsive.lua new file mode 100644 index 0000000..5918e9d --- /dev/null +++ b/Other/MaxWidthResponsive.lua @@ -0,0 +1,25 @@ +local p = {} + +function p.main(frame) + local result = "" + local title = mw.title.new(mw.text.trim(frame.args[1]), 6) + + if (title ~= nil and title.fileExists) then + local image = title.file + local w = image.width + local h = image.height + local maxWidth = 430 * (w / h) + + -- Nếu chiều cao > chiều rộng (w/h < 1) thì cung cấp max-width + -- để max-height luôn đạt 430px + if (w/h < 1) then + result = "max-width: " .. maxWidth .. "px;" + else + result = "max-width: 430px;" + end + end + + return result +end + +return p