Module:Excerpt slideshow/sandbox: Difference between revisions

Content deleted Content added
sync with live version of the module
shuffle around
 
(15 intermediate revisions by 4 users not shown)
Line 1:
local p = {}
local excerptModule = require('Module:Excerpt/portals/sandbox')
local slideshowModule = require('Module:Random slideshow/sandbox')
local randomModule = require('Module:Random')
 
Line 88:
end
)
end
 
local replacePipesWithMagicword = function(t)
return mw.ustring.gsub(t, '|', '{{!}}')
end
 
Line 114 ⟶ 110:
return frame:preprocess(t)
end
-- else replace pipes and remove internal linebreaks
return replacePipesWithMagicword(mw.ustring.gsub(t, '\n*', ''))
end
 
local cleanUpExcerpt = function(excerpt)
-- strip galleries
excerpt = mw.ustring.gsub(excerpt, "<%s*[Gg]allery.->.-<%s*/%s*[Gg]allery%s*>", "")
-- strip tables and block templates; strip newlines and replace pipes within inline templates
excerpt = mw.ustring.gsub(excerpt..'\n', '\n?%b{}\n?', processBraces)
-- replace wikitext bulleted lists with html bulleted lists
excerpt = gsubWikitextLists(excerpt, '*', 'ul', 'li')
-- replace wikitext numbered lists with html numbered lists
excerpt = gsubWikitextLists(excerpt, '#', 'ol', 'li')
excerpt = mw.text.trim(excerpt)
return excerpt
end
 
Line 134 ⟶ 143:
excerpt = nil
end
if excerpt and excerpt ~= '' and #excerpt > 10 then -- check again in case we had a few characters plus (Full article...)
excerpt = mw.ustring.gsubcleanUpExcerpt(excerpt, '|', '&#124;')
-- temporarily take off the '''[[Page title|Read more...]]''' link if present
if readmore_textoptions.more then
readmore_start_index, readmore_end_index, readmore_text = mw.ustring.find(excerpt, "(%s*'''%b[]''')$", -350) --- Starting from end should improve efficiency. 350 characters allows for long page titles and/or a long custom label for the link
excerpt = excerpt .. " ('''[[" .. title .. "|" .. options.more .. "]]''')"
if readmore_start_index then
excerpt = mw.ustring.sub(excerpt, 1, readmore_start_index-1)
end
end
if excerpt and excerpt ~= '' and #excerpt > 10 then -- check again in case we had a few characters plus Read more...
-- strip galleries
excerpt = mw.ustring.gsub(excerpt, "<%s*[Gg]allery.->.-<%s*/%s*[Gg]allery%s*>", "")
-- strip tables and block templates; strip newlines and replace pipes within inline templates
excerpt = mw.ustring.gsub(excerpt..'\n', '\n?%b{}\n?', processBraces)
-- replace pipes within links
excerpt = mw.ustring.gsub(excerpt, '%b[]', replacePipesWithMagicword)
-- replace other pipes with html entity
excerpt = mw.ustring.gsub(excerpt, '|', '&#124;')
-- replace wikitext bulleted lists with html bulleted lists
excerpt = gsubWikitextLists(excerpt, '*', 'ul', 'li')
-- replace wikitext numbered lists with html numbered lists
excerpt = gsubWikitextLists(excerpt, '#', 'ol', 'li')
excerpt = mw.text.trim(excerpt)
-- add back the "Read more..." link if it was present
if readmore_text then
excerpt = excerpt .. readmore_text
end
local text = '<div style{{=}}"text-align:left;">' .. mw.ustring.gsub(excerpt, '%c', '<br>') .. '</div>'
table.insert(galleryArgs, 'File:Blank.png')
table.insert(galleryArgs, text)
Line 181 ⟶ 170:
options.paraflags = excerptModule.numberFlags(args.paragraphs or "") -- parse paragraphs, e.g. "1,3-5" → {"1","3-5"}
options.fileflags = excerptModule.numberFlags(args.files or "") -- parse file numbers
options.ignoreOnlyincludes = options.ignoreOnlyincludes == nil and true or options.ignoreOnlyincludes -- default to true
if args.nostubs and isDeclined(args.nostubs) then
options.nostubs = false
Line 214 ⟶ 204:
-- begin BHG addition for tracking source pages
local thisPage = mw.title.getCurrentTitle().nsText .. ":" .. mw.title.getCurrentTitle().text
thisPage = thisPage:gsub('_', ' ') -- fix the nsText part, until [[phab:T369784]] is resolved
local thisBareParam = mw.ustring.gsub(args[ii], "^([^#]+).*$", "%1", 1) -- strip any section anchor from the parameter's page name
thisBareParam = thisBareParam:gsub('_', ' ') -- support underscores in parameter's page name
if (thisPage == thisBareParam) then
usesEmbeddedList = true;
Line 257 ⟶ 249:
local parent = frame.getParent(frame)
local output = p._excerpt(parent.args, 'random')
return frame:extensionTag{ name='templatestyles', args = { src='Module:Random slideshow/sandbox/styles.css'} }
return .. frame:preprocess(output)
end
 
Line 264 ⟶ 257:
local parent = frame.getParent(frame)
local output = p._excerpt(parent.args, 'linked')
return frame:extensionTag{ name='templatestyles', args = { src='Module:Random slideshow/sandbox/styles.css'} }
return .. frame:preprocess(output)
end
 
Line 271 ⟶ 265:
local parent = frame.getParent(frame)
local output = p._excerpt(parent.args, 'listitem')
return frame:extensionTag{ name='templatestyles', args = { src='Module:Random slideshow/sandbox/styles.css'} }
return .. frame:preprocess(output)
end
 
Line 279 ⟶ 274:
p._excerpt = function(_args, method)
local args = cleanupArgs(_args)
args.more = excerptModule.getMoreLinkText(_args.more)
-- check for blank value in more parameter
if _args.more and not args.more then
args.more = "Read more..." -- default text for blank more=
end
local options = makeOptions(args)
local limit = args.limit and tonumber(args.limit) or DEFAULT_LIMIT
Line 294 ⟶ 286:
return slideshowModule._main(galleryArgs, false, 'excerptSlideshow-container') .. checksourcepages()
end
 
p._cleanUpExcerpt = cleanUpExcerpt
 
-- begin BHG addition for tracking source pages