Module:Sandbox/Mathglot/Xreadership

local p = {}

-- HELPER FUNCTIONS --
local function notblank(v) return (v or '' ) ~= '' end
local function ifblank(v, alt1, alt2) return notblank(v) and v or (notblank(alt1) and alt1 or alt2) end
local function plainlink(link) return tostring(mw.html.create('span'):addClass('plainlinks'):wikitext(link)) end
local xviews = require('Sandbox/Mathglot/Xviews/sandbox')

-- {{User:Mathglot/sandbox/Templates/Xreadership}}
function p._xreadership(rargs)
	-- rargs includes 1, days, 2, pv, title, expanded
	local ts =  mw.getCurrentFrame():extensionTag{
		name = 'templatestyles',
		args = {src = 'Template:Hidden begin/styles.css'}
	}

	rargs.days = ifblank(rargs[1], rargs.days, xviews.gCOUNT())
	rargs.pv = ifblank(rargs[2], rargs.pv)
	
	local link = function(text) return plainlink(
		'[https://pageviews.toolforge.org/?project=en.wikipedia.org&platform=all-access&agent=user&range=latest-' ..
		mw.text.encode(mw.text.trim(rargs.days)) .. 
		'&pages=' .. 
		mw.text.encode(mw.text.trim(ifblank(rargs.pv, tostring(mw.title.getCurrentTitle().subjectPageTitle)))) ..
		' ' .. text .. ']'
	) end
	
	local title = rargs.title
	if not notblank(title) then
		local summary = xviews._summary(nil, {days = rargs.days})
		
		if ifblank(rargs.pv, false) then
			title = '[[' .. rargs.pv .. ']]'
		else
			local this = mw.title.getCurrentTitle()
			if this:inNamespace(1) then
				title = 'this article'
			elseif this.isTalkPage then
				title =  this.subjectPageTitle
			else
				title = 'this page'
			end
			title = title .. ' <span style="font-weight:initial;font-size:100%; padding-left:2em; color:#77">(experimental)</span>'
		end
		title = title .. '<div style="margin-top:0.3em; text-align:left; padding-left:2em; font-weight:initial">' .. summary .. '.</div>'
	end
	
	local header = link('Daily pageviews') .. ' of ' .. title
	
	local contentTable = {
		missing = "The [[/pageviews|pageviews file]] is missing; " ..
			"please [[/pageviews|create it]], and add data from the 'Download' function of the " ..
			link('pageviews tool') ..
			". See [[User:Mathglot/sandbox/Templates/Xreadership#Instructions|§&nbsp;Instructions]] for details." ..
			"<!--no cat -->",
		stale = "The [[/pageviews|pageviews file]] file is stale; please " ..
			link("update it") ..
			"; see [[User:Mathglot/sandbox/Templates/Xreadership#Instructions|§&nbsp;Instructions]]." ..
			"[[Category:Pages with experimental page views chart enabled]][[Category:Pages with stale experimental page views chart]]",
		aging = "The [[/pageviews|pageviews file]] should be " ..
			link("updated") ..
			" soon. If not updated before age exceeds " ..
			xviews.gSTALE() ..
			"days, the chart will be hidden until it is. See [[User:Mathglot/sandbox/Templates/Xreadership#Maintenance|§&nbsp;Maintenance]]." ..
			"[[Category:Pages with experimental page views chart needing update]]"
	}
	
	local isStale = xviews._isStale()
	
	local content = contentTable[isStale] or ''
	if ifblank(isStale, 'aging') == 'aging' then
		content = content .. xviews._xviews({ct = rargs.days}) ..
			"[[Category:Pages with experimental page views chart enabled]]"
	end
	
	local hidden = mw.html.create('div')
		:attr('class', 'hidden-begin mw-collapsible')
		:addClass(notblank(rargs.expanded) and '' or 'mw-collapsed')
		:css('font-size', '100%')
	hidden:tag('div')
		:attr('class', 'hidden-title skin-nightmode-reset-color')
		:css('font-weight', 'bold')
		:wikitext(header)
	hidden:tag('div')
		:attr('class', 'hidden-content mw-collapsible-content')
		:cssText('background:#fffaef; border:1px dotted gray; padding:2px 4px; text-align: left;')
		:wikitext(content)	
	local targs = {
		name = 'Xreadership',
		style = 'border-spacing:4px',
		image = '[[File:Simpleicons Business horizontal-bars-chart.svg|48px]]',
		text = tostring(hidden)
	}
	return ts .. require('Module:Message box').tmbox(targs)
end
function p.xreadership(frame)
	return p._xreadership(frame.args)
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.