This module transcludes the |abstract= parameter from a page (typically from the {{article info}} template) and checks to see if text is longer than a defined character limit. If it is, it creates a collapsed version truncated to the first paragaphs under that character limit, with the subsequent paragraphs shown upon clicking.

Usage edit

{{Abstract
| 1 = pagename to extract abstract from
| limit = number of characters to crop to (default = 0)
| toggle = unique identifier to use if multiple collapsed abstracts will appear on a page (default = "0")
}}

Example edit

{{#invoke:Abstract|main|WikiJournal of Medicine/Viewer interaction with YouTube videos about hysterectomy recovery|limit=500|toggle=1}}
Objective: We aim to evaluate hysterectomy-recovery related videos on YouTube. Methods: This cross-sectional study analyzed videos available through the YouTube interface. We calculated the views-per-day and interactions (comments, “thumbs up or down”) per 1,000 views for relevant videos. The publishers were categorized into patients, physicians, hospitals, media, industry, nonprofit, government and “other”. Video characteristics were compared between these categories using non-paramettric tests. [...]
Results: We analyzed 2,092 YouTube videos related to hysterectomy recovery; 959 relevant videos published from August 30, 2006 to June 16, 2017 were included. The largest number of relevant videos were published by patients (48.6%), followed by physicians (15.8%), hospitals (12.7%), media (7.8%), and industry (7.6%). Views per day were similar between videos published by patients and physicians (median 2.1, vs median 2.6, p = 0.31). Videos published by patients had more interaction in the form of “thumbs up” votes (median 8.6/1,000 views, p<0.01) and comments (median 2.7/1,000 views, p<0.01) as compared to other categories. Conclusion: Almost half of the hysterectomy videos on YouTube are posted by patients and have more viewer interaction than other categories. Physicians should consider partnering with patient advocates to improve viewer interaction.

See also edit


local Transcluder = require( 'Module:Transcluder' )

local p = {}

-- Helper function to handle errors
function getError( message, value )
	if type( message ) == 'string' then
		message = Transcluder.getError( message, value )
	end
	return message
end

function p.main( frame )
	local args = Transcluder.parseArgs( frame )

	-- Make sure the requested page exists
	local page = args[1]
	if not page then return getError( 'no-page' ) end
	local title = mw.title.new( page )
	if not title then return getError( 'no-page' ) end
	if title.isRedirect then title = title.redirectTarget end
	if not title.exists then return getError( 'page-not-found', page ) end
	page = title.prefixedText

	-- Get the abstract
	local ok, abstract = pcall( Transcluder.get, page, {
		only = 'parameters',
		parameters = 'abstract',
		noBold = true,
		noLinks = true,
		files = 0,
		references = 0,
		templates = '-efn,efn-la,efn-ua,efn-lr,sfn,refn,notetag,notetag-ua,rp,pp,fig'
	} )
	if not ok then
		return getError( 'Abstract not found' );
	end

	-- Strip the abstract further
	abstract = frame:preprocess( abstract )
	abstract = Transcluder.removeLinks( abstract )
	abstract = abstract:gsub( '%[[^ ]- ([^]]-)%]', '%1' )

	-- If the abstract is too long, collapse the excess
	local limit = tonumber( args['limit'] ) or 0
	if #abstract > limit then
		local constantContent = abstract:sub( 0, limit );
		local remainingContent = abstract:sub( limit );
		local constantContent = constantContent .. remainingContent:match( '^(.-%.)' )
		local collapsedContent =  abstract:sub( #constantContent + 1 )
		if #collapsedContent > 0 then
			abstract = frame:expandTemplate{
				title = 'Collapsible toggle',
				args = {
					constantContent .. ' [...]',
					collapsedContent,
					collapsed = true,
					toggle = tonumber( args['toggle'] ) or 0
				}
			}
		end
	end
	return abstract
end

return p