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 11:34, 29 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>";

    local date;

    for _, dateStr in pairs( frame.args ) do
        list = list .. "<li>"

        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);
        list = list .. line(date)

        if not (place=="") then
            list = list .. " ("..place..")"
        end
        list = list .."</li>"
        count=count+1
    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;