Jump to content

Module:Top 25 report

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Od Mishehu (talk | contribs) at 12:37, 29 May 2019 (Allow spaces and uppercase for "until"). 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>";

    local date;
    local isUntil = false;

    for _, dateStr in pairs( frame.args ) do
        dateStr = mw.text.trim(dateStr)
        if (string.lower(dateStr) == "until") then
            isUntil = true
        else
            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
            local newDate = Date(dateStr);
            if isUntil then
                isUntil = false
                date = date+7
                while date<newDate do
                    list = list .. "<li>" .. line(date) .. "</li>"
                    count = count +1
                    date = date + 7
                end
            end
            date = newDate
            list = list .. "<li>"

            list = list .. line(date)

            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


function line(date)
    local link = "[[Wikipedia:Top 25 Report/"

    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
        
    link = link..range .."|"..range.."]]"
    return link

end

return p;