Module:Top 25 report: Difference between revisions
Appearance
Content deleted Content added
mNo edit summary |
Miscellaneous code formatting |
||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
require("Module:No globals") |
|||
⚫ | |||
local function range(date) |
local function range(date) |
||
local date2 = date + 6 |
local date2 = date + 6 |
||
if |
if date2:text("%Y") ~= date:text("%Y") then |
||
return date:text("%B %-d, %Y").." to "..date2:text("%B %-d, %Y") |
return date:text("%B %-d, %Y") .. " to " .. date2:text("%B %-d, %Y") |
||
else |
else |
||
if not (date2:text("%B")==date:text("%B")) then |
if not (date2:text("%B") == date:text("%B")) then |
||
return date:text("%B %-d") .. " to "..date2:text("%B %-d, %Y") |
return date:text("%B %-d") .. " to " .. date2:text("%B %-d, %Y") |
||
else |
else |
||
return date:text("%B %-d") .. " to "..date2:text("%-d, %Y") |
return date:text("%B %-d") .. " to " .. date2:text("%-d, %Y") |
||
end |
end |
||
end |
end |
||
Line 16: | Line 18: | ||
local function line(date) |
local function line(date) |
||
local link = "[[Wikipedia:Top 25 Report/" |
local link = "[[Wikipedia:Top 25 Report/" |
||
local range = range(date) |
local range = range(date) |
||
link = link..range .."|"..range.."]]" |
link = link .. range .. "|" .. range .. "]]" |
||
return link |
return link |
||
end |
end |
||
Line 28: | Line 29: | ||
p.list = function(frame) |
p.list = function(frame) |
||
local text = "This article has been viewed enough times in a single week to appear in the [[Wikipedia:Top 25 Report|Top 25 Report]]" |
local text = "This article has been viewed enough times in a single week to appear in the [[Wikipedia:Top 25 Report|Top 25 Report]]" |
||
local txtstyle = "text-align: left;" |
local txtstyle = "text-align: left;" |
||
⚫ | |||
⚫ | |||
local args = frame.args |
local args = frame.args |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local errors = {} |
local errors = {} |
||
for _, dateStr in pairs( |
for _, dateStr in pairs(frame.args) do |
||
dateStr = mw.text.trim(dateStr) |
dateStr = mw.text.trim(dateStr) |
||
if |
if string.lower(dateStr) == "until" then |
||
isUntil = true |
isUntil = true |
||
else |
else |
||
local index = string.find(dateStr,'(',1,true) |
local index = string.find(dateStr,'(',1,true) |
||
local place="" |
local place = "" |
||
if |
if index then |
||
place=string.sub(dateStr,index+1,-2) |
place = string.sub(dateStr,index+1,-2) |
||
dateStr=string.sub(dateStr,0,index-1) |
dateStr = string.sub(dateStr,0,index-1) |
||
end |
end |
||
local newDate = Date(dateStr) |
local newDate = Date(dateStr) |
||
if newDate == nil then |
if newDate == nil then |
||
table.insert(errors, dateStr) |
table.insert(errors, dateStr) |
||
else |
else |
||
if isUntil then |
if isUntil then |
||
isUntil = false |
isUntil = false |
||
date = date+7 |
date = date + 7 |
||
while date<newDate do |
while date < newDate do |
||
list = list .. "<li>" .. line(date) .. "</li>" |
list = list .. "<li>" .. line(date) .. "</li>" |
||
count = count +1 |
count = count + 1 |
||
date = date + 7 |
date = date + 7 |
||
end |
end |
||
Line 73: | Line 70: | ||
list = list .. line(date) |
list = list .. line(date) |
||
if |
if place ~= "" then |
||
list = list .. " ("..place..")" |
list = list .. " (" .. place .. ")" |
||
end |
end |
||
list = list .."</li>" |
list = list .. "</li>" |
||
count=count+1 |
count = count + 1 |
||
end |
end |
||
end |
end |
||
Line 83: | Line 80: | ||
list = list .. "</ul>\n" |
list = list .. "</ul>\n" |
||
if count>5 then |
if count > 5 then |
||
list = '<table class="mw-collapsible autocollapse" width=100% style="border:1px solid silver; text-align:left; padding:1px;"><tr bgcolor=#fff1d2 style="text-align:center;><th>The weeks in which this happened:</th></tr><tr bgcolor=#fff><td><div style="column-count:4;">' .. list .. '</div></td></tr></table>' |
list = '<table class="mw-collapsible autocollapse" width=100% style="border:1px solid silver; text-align:left; padding:1px;"><tr bgcolor=#fff1d2 style="text-align:center;><th>The weeks in which this happened:</th></tr><tr bgcolor=#fff><td><div style="column-count:4;">' .. list .. '</div></td></tr></table>' |
||
txtstyle = "text-align: center;" |
txtstyle = "text-align: center;" |
||
text = text .. " '''" .. tostring(count) .. "''' times." |
text = text .. " '''" .. tostring(count) .. "''' times." |
||
elseif count==0 then |
elseif count == 0 then |
||
text = text .. "." |
text = text .. "." |
||
elseif count==1 then |
elseif count == 1 then |
||
list = " The week in which this happened:" .. list |
list = " The week in which this happened:" .. list |
||
text = text .. "." |
text = text .. "." |
||
Line 97: | Line 94: | ||
end |
end |
||
if mw.title.getCurrentTitle().namespace==1 then |
if mw.title.getCurrentTitle().namespace == 1 then |
||
text = text .. "[[Category:Pages in the Top 25 Report]]" |
text = text .. "[[Category:Pages in the Top 25 Report]]" |
||
end |
end |
||
text = text .. list |
text = text .. list |
||
Line 105: | Line 102: | ||
text = text .. table.concat(errors,"\n#") .. "\n" |
text = text .. table.concat(errors,"\n#") .. "\n" |
||
end |
end |
||
return frame:expandTemplate{title="tmbox", args={text=text, image="[[File:Article blue.svg|35px|link=]]", textstyle=txtstyle}} |
return frame:expandTemplate{title = "tmbox", args = {text = text, image = "[[File:Article blue.svg|35px|link = ]]", textstyle = txtstyle}} |
||
end |
end |
||
p.header = function(frame) |
p.header = function(frame) |
||
local text = frame:expandTemplate{title="Wikipedia:Top 25 Report/Template:Header", args={}} |
local text = frame:expandTemplate{title = "Wikipedia:Top 25 Report/Template:Header", args = {}} |
||
text = text .. "__NOTOC__\n" |
text = text .. "__NOTOC__\n" |
||
if mw.title.getCurrentTitle().subpageText == "Report header" then |
if mw.title.getCurrentTitle().subpageText == "Report header" then |
||
Line 116: | Line 113: | ||
end |
end |
||
frame = frame:getParent() |
frame = frame:getParent() |
||
Date = require('Module:Date')._Date |
|||
local date = Date(frame.args[1]) |
local date = Date(frame.args[1]) |
||
text = text .. '<div style="height:10px;clear:both;"></div>\n' |
text = text .. '<div style="height:10px;clear:both;"></div>\n' |
||
text = text .. "==Most Popular Wikipedia Articles of the Week (" |
text = text .. "== Most Popular Wikipedia Articles of the Week (" |
||
text = text .. range(date).. ")==\n" |
text = text .. range(date) .. ") ==\n" |
||
count=0 |
local count = 0 |
||
for index, nameStr in pairs(frame.args) do |
for index, nameStr in pairs(frame.args) do |
||
if not (index == 1) then |
if not (index == 1) then |
||
Line 138: | Line 135: | ||
else |
else |
||
local i = 2 |
local i = 2 |
||
while i<= count do |
while i <= count do |
||
text = text .. userLink(frame.args[i]) .. ", " |
text = text .. userLink(frame.args[i]) .. ", " |
||
i = i + 1 |
i = i + 1 |
||
Line 149: | Line 146: | ||
text = text .. "''\n\n← [[Wikipedia:Top 25 Report/" |
text = text .. "''\n\n← [[Wikipedia:Top 25 Report/" |
||
if |
if frame.args[1] == "January 6, 2013" then |
||
text = text .. "December 2012|December 2012 monthly report]]" |
text = text .. "December 2012|December 2012 monthly report]]" |
||
else |
else |
||
text = text .. range(date-7) .. "|Last week's report]]" |
text = text .. range(date-7) .. "|Last week's report]]" |
||
end |
end |
||
if |
if mw.title.getCurrentTitle().subpageText ~= "Top 25 Report" then |
||
text = text .. " – [[Wikipedia:Top 25 Report/" .. range(date+7) .. "|Next week's report]] →" |
text = text .. " – [[Wikipedia:Top 25 Report/" .. range(date+7) .. "|Next week's report]] →" |
||
key = "Top 25 " .. date:text("%Y%m%d") |
key = "Top 25 " .. date:text("%Y%m%d") |
||
end |
end |
||
if mw.title.getCurrentTitle().namespace==4 then |
if mw.title.getCurrentTitle().namespace == 4 then |
||
text = text.."[[Category:Wikipedia Top 25 Report|"..key.."]]" |
text = text .. "[[Category:Wikipedia Top 25 Report|" .. key .. "]]" |
||
end |
end |
||
return text |
return text |
||
end |
end |
||
return p |
return p |
Revision as of 01:14, 23 January 2021
![]() | This module depends on the following other modules: |
Implements {{Top 25 report}}
local p = {}
require("Module:No globals")
local Date = require('Module:Date')._Date
local function range(date)
local date2 = date + 6
if date2:text("%Y") ~= date:text("%Y") then
return date:text("%B %-d, %Y") .. " to " .. date2:text("%B %-d, %Y")
else
if not (date2:text("%B") == date:text("%B")) then
return date:text("%B %-d") .. " to " .. date2:text("%B %-d, %Y")
else
return date:text("%B %-d") .. " to " .. date2:text("%-d, %Y")
end
end
end
local function line(date)
local link = "[[Wikipedia:Top 25 Report/"
local range = range(date)
link = link .. range .. "|" .. range .. "]]"
return link
end
local function userLink(username)
return string.format("[[User:%s|%s]]", username, username)
end
p.list = function(frame)
local text = "This article has been viewed enough times in a single week to appear in the [[Wikipedia:Top 25 Report|Top 25 Report]]"
local txtstyle = "text-align: left;"
frame = frame:getParent()
local args = frame.args
local count = 0
local list = "<ul>"
local date
local isUntil = false
local errors = {}
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 index then
place = string.sub(dateStr,index+1,-2)
dateStr = string.sub(dateStr,0,index-1)
end
local newDate = Date(dateStr)
if newDate == nil then
table.insert(errors, dateStr)
else
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 place ~= "" then
list = list .. " (" .. place .. ")"
end
list = list .. "</li>"
count = count + 1
end
end
end
list = list .. "</ul>\n"
if count > 5 then
list = '<table class="mw-collapsible autocollapse" width=100% style="border:1px solid silver; text-align:left; padding:1px;"><tr bgcolor=#fff1d2 style="text-align:center;><th>The weeks in which this happened:</th></tr><tr bgcolor=#fff><td><div style="column-count:4;">' .. list .. '</div></td></tr></table>'
txtstyle = "text-align: center;"
text = text .. " '''" .. tostring(count) .. "''' times."
elseif count == 0 then
text = text .. "."
elseif count == 1 then
list = " The week in which this happened:" .. list
text = text .. "."
else
list = " The weeks in which this happened:" .. list
text = text .. " '''" .. tostring(count) .. "''' times."
end
if mw.title.getCurrentTitle().namespace == 1 then
text = text .. "[[Category:Pages in the Top 25 Report]]"
end
text = text .. list
if #errors > 0 then
text = text .. "\n\n<big><span style=\"color:red\">'''The following dates couldn't be parsed:'''</span></big>\n#"
text = text .. table.concat(errors,"\n#") .. "\n"
end
return frame:expandTemplate{title = "tmbox", args = {text = text, image = "[[File:Article blue.svg|35px|link = ]]", textstyle = txtstyle}}
end
p.header = function(frame)
local text = frame:expandTemplate{title = "Wikipedia:Top 25 Report/Template:Header", args = {}}
text = text .. "__NOTOC__\n"
if mw.title.getCurrentTitle().subpageText == "Report header" then
return text
end
frame = frame:getParent()
local date = Date(frame.args[1])
text = text .. '<div style="height:10px;clear:both;"></div>\n'
text = text .. "== Most Popular Wikipedia Articles of the Week ("
text = text .. range(date) .. ") ==\n"
local count = 0
for index, nameStr in pairs(frame.args) do
if not (index == 1) then
count = count + 1
end
end
if count > 0 then
text = text .. "''Prepared with commentary by "
if count == 1 then
text = text .. userLink(frame.args[2])
elseif count == 2 then
text = text .. userLink(frame.args[2]) .. " and " .. userLink(frame.args[3])
else
local i = 2
while i <= count do
text = text .. userLink(frame.args[i]) .. ", "
i = i + 1
end
text = text .. " and " .. userLink(frame.args[count+1])
end
end
local key = " "
text = text .. "''\n\n← [[Wikipedia:Top 25 Report/"
if frame.args[1] == "January 6, 2013" then
text = text .. "December 2012|December 2012 monthly report]]"
else
text = text .. range(date-7) .. "|Last week's report]]"
end
if mw.title.getCurrentTitle().subpageText ~= "Top 25 Report" then
text = text .. " – [[Wikipedia:Top 25 Report/" .. range(date+7) .. "|Next week's report]] →"
key = "Top 25 " .. date:text("%Y%m%d")
end
if mw.title.getCurrentTitle().namespace == 4 then
text = text .. "[[Category:Wikipedia Top 25 Report|" .. key .. "]]"
end
return text
end
return p