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 17:31, 28 May 2019 (Disable category unless in the Talk: namespace). 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 _, dateStr in pairs( frame.args ) do
        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
    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;