الفرق بين المراجعتين لصفحة: «وحدة:اخر مقالة»
لا ملخص تعديل |
لا ملخص تعديل |
||
| سطر ٦: | سطر ٦: | ||
local wiki_api_endpoint = mw.uri.new("https://ar.ciyaye-kurmenc.com/api.php") | local wiki_api_endpoint = mw.uri.new("https://ar.ciyaye-kurmenc.com/api.php") | ||
local category_name = "قرى_منطقة_عفرين" | local category_name = "قرى_منطقة_عفرين" | ||
local params = { | |||
action = "query", | action = "query", | ||
format = "json", | format = "json", | ||
| سطر ٢٠: | سطر ١٩: | ||
local url = wiki_api_endpoint:extendWithPath("api.php"):setQuery(params):fullUrl() | local url = wiki_api_endpoint:extendWithPath("api.php"):setQuery(params):fullUrl() | ||
local | local response = mw.http.get(url) | ||
if data and data.query and data.query.categorymembers and #data.query.categorymembers > 0 then | if response then | ||
local data = mw.text.jsonDecode(response) | |||
if data and data.query and data.query.categorymembers and #data.query.categorymembers > 0 then | |||
local last_article_title = data.query.categorymembers[1].title | |||
return "<h2>Last Article in " .. category_name .. " Category:</h2><p>" .. last_article_title .. "</p>" | |||
else | |||
return "<p>No articles found in the " .. category_name .. " category.</p>" | |||
end | |||
else | else | ||
return "<p> | return "<p>Error fetching data from the API.</p>" | ||
end | end | ||
end | end | ||
return p | |||
مراجعة ٢٠:٠١، ١٥ ديسمبر ٢٠٢٣
يمكن إنشاء صفحة توثيق الوحدة في وحدة:اخر مقالة/شرح
-- Module code: وحدة:اخر_مقالة
local p = {}
function p.getLastArticleFromCategory(frame)
local wiki_api_endpoint = mw.uri.new("https://ar.ciyaye-kurmenc.com/api.php")
local category_name = "قرى_منطقة_عفرين"
local params = {
action = "query",
format = "json",
list = "categorymembers",
cmtitle = "Category:" .. category_name,
cmlimit = 1,
cmprop = "title",
cmtype = "page",
cmsort = "timestamp",
cmdir = "desc",
}
local url = wiki_api_endpoint:extendWithPath("api.php"):setQuery(params):fullUrl()
local response = mw.http.get(url)
if response then
local data = mw.text.jsonDecode(response)
if data and data.query and data.query.categorymembers and #data.query.categorymembers > 0 then
local last_article_title = data.query.categorymembers[1].title
return "<h2>Last Article in " .. category_name .. " Category:</h2><p>" .. last_article_title .. "</p>"
else
return "<p>No articles found in the " .. category_name .. " category.</p>"
end
else
return "<p>Error fetching data from the API.</p>"
end
end
return p