Module:Top 25 report

Implements {{Top 25 report}}

Module:Top 25 report

local p = {}
require('strict')
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]]"

	frame = frame:getParent()
	local args = frame.args
	local list = {}

	local date
	local isUntil = false
	local errors = {}

	for parameter, dateStr in pairs(frame.args) do
		dateStr = mw.text.trim(dateStr)
		if string.lower(dateStr) == "until" then
			isUntil = true
		elseif parameter == "collapse" then
			 -- Ignore the collapse parameter
		elseif parameter == "ranks" then
		     -- Ignore the parameter ranks used by capsulebot.
		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
						table.insert(list, line(date))
						date = date + 7
					end
				end
				date = newDate
				
				local entry = line(date)
				if place ~= "" then
					entry = entry .. " (" .. place .. ")"
				end
				table.insert(list, entry)
			end
		end
	end
	
	local count = #list
	list.style = "display:inline-block"
	list = require("Module:List").makeList("horizontal", list)

	if count == 0 then
		text = text .. "."
		text = text .. list
	elseif count == 1 then
		list = " The week in which this happened: " .. list
		text = text .. "."
		text = text .. list
	elseif (args["collapse"] == "yes" or (args["collapse"] == nil and count >= 10)) then
		text = text .. " '''" .. tostring(count) .. "''' times."
		text = '<div class="mw-collapsible mw-collapsed"><div>' .. text .. ' The weeks in which this happened:</div><div class="mw-collapsible-content">'.. list .. '</div></div>'
	else
		list = " The weeks in which this happened: " .. list
		text = text .. " '''" .. tostring(count) .. "''' times."
		text = text .. list
	end

	if mw.title.getCurrentTitle().namespace == 1 then
		text = text .. "[[Category:Pages in the Wikipedia Top 25 Report]]"
	end
	
	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 require('Module:Message box').main( 'tmbox', {
		text = text,
	    image = "[[File:Article blue.svg|22px|alt=icon]]"
	})

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

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.