الفرق بين المراجعتين لصفحة: «وحدة:اخر مقالة»

أُضيف ٣١٣ بايت ،  ١٥ ديسمبر ٢٠٢٣
لا يوجد ملخص تحرير
لا ملخص تعديل
لا ملخص تعديل
 
(٤ مراجعات متوسطة بواسطة نفس المستخدم غير معروضة)
سطر ١: سطر ١:
-- Module code: وحدة:اخر_مقالة
    -- local wiki_api_endpoint = "https://ar.ciyaye-kurmenc.com/api.php"
    -- local category_name = "قرى_منطقة_عفرين"
local p = {}
local p = {}


سطر ٥: سطر ٩:
     local category_name = "قرى_منطقة_عفرين"
     local category_name = "قرى_منطقة_عفرين"


 
     local params = {
     local params = {
         action = "query",
         "action=query",
         format = "json",
         "format=json",
         list = "categorymembers",
         "list=categorymembers",
         cmtitle = "Category:" .. category_name,
         "cmtitle=Category:" .. category_name,
         cmlimit = 1,
         "cmlimit=1",
         cmprop = "title",
         "cmprop=title",
         cmtype = "page",
         "cmtype=page",
         cmsort = "timestamp",
         "cmsort=timestamp",
         cmdir = "desc",
         "cmdir=desc",
     }
     }


     local url = wiki_api_endpoint .. "?" .. mw.uri.encodeQueryString(params)
     local url = wiki_api_endpoint .. "?" .. table.concat(params, "&")
     local data = mw.text.jsonDecode(mw.http.get(url))
     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 last_article_title = data.query.categorymembers[1].title
        local data = mw.text.jsonDecode(response)
        return "<h2>Last Article in " .. category_name .. " Category:</h2><p>" .. last_article_title .. "</p>"
       
        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>No articles found in the " .. category_name .. " category.</p>"
         return "<p>Error fetching data from the API.</p>"
     end
     end
end
end


return p
return p