Jump to content

Module:Get short description

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Qwerfjkl (talk | contribs) at 14:36, 16 October 2022. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args, frame)
end


function p._main(args, frame)
	local title = args.page
	local nomatch = args.nomatch or ""
	page = mw.title.new(title)
	if not page then
		--bad title
		return '<strong class="error">No page given</strong>'
	end
	local content = page:getContent()

	if not content then
		--page does not exist
		return '<strong class="error">"'..title..'" does not exist</strong>'
	end
	content = frame:preprocess(content) -- expand content

	local sd = mw.ustring.match(content, '<div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">([^<]+)') or nomatch
	return tostring(sd)
end


return p