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

أُضيف ١٧٠ بايت ،  ١٥ ديسمبر ٢٠٢٣
لا يوجد ملخص تحرير
لا ملخص تعديل
لا ملخص تعديل
سطر ٦: سطر ٦:
     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 = {
    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 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