Jump to content

Module:Sandbox/Od Mishehu/top25

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Od Mishehu (talk | contribs) at 17:25, 28 May 2019. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {};

p.list = function(frame)
    text = "This article has been viewed enough times in a single week to make it into the [[WP:TOP25|top 25 viewed articles of that week]]";

    frame = frame:getParent();

    args = frame.args
    
    Date = require('Module:Date')._Date

    local int count=0;
    local list="<ul>";

    for num, dateStr in pairs( frame.args ) do
        if not( tonumber(num)==nil) then
            list = list .. "<li>[[Wikipedia:Top 25 Report/"

            local index = string.find(dateStr,'(',1,true)
            local place=""
            if not (index==nil) then
                place=string.sub(dateStr,index+1,-2)
                dateStr=string.sub(dateStr,0,index-1)
            end
            date = Date(dateStr);
            diff=6;
            date2 = date+diff;

            local range = "";

            if not (date2:text("%Y")==date:text("%Y")) then
                range = date:text("%B %-d, %Y").." to "..date2:text("%B %-d, %Y")
            else
                if not (date2:text("%B")==date:text("%B")) then
                    range = date:text("%B %-d") .. " to "..date2:text("%B %-d, %Y")
                else
                    range = date:text("%B %-d") .. " to "..date2:text("%-d, %Y")
                end
            end
        
            list = list..range .."|"..range.."]]"
            if not (place=="") then
                list = list .. " ("..place..")"
            end
            list = list .."</li>"
            count=count+1
        end
    end
    list = list .. "</ul>\n"

    if count>5 then
        list = frame:expandTemplate{title="Collapse top",args={"The weeks in which this happened",bg="#fff1d2"}} .. list .. frame:expandTemplate{title="Collapse bottom",args={}}
    else
        list = "<br/>The weeks in which this happened:" .. list
    end

    if mw.title.getCurrentTitle().namespace==1 then
        text =text.."[[Category:Pages in the Top 25 Report]]";
    end
    return  frame:expandTemplate{title="tmbox", args={text=text .. list}}

end

return p;