Module:Discussion ping
Appearance
![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
This module implements {{discussion ping}}.
Usage
{{#invoke:discussion ping|main|}}
Example
{{#invoke:discussion ping|main|1=[[User:Example]] [[User:Example2|Example]]}}
yields Script error: The module returned a nil value. It is supposed to return an export table.
{{#invoke:discussion ping|main|title=User:Awesome Aasim/Example discussion#Some_discussion}}
yields Script error: The module returned a nil value. It is supposed to return an export table.
{{#invoke:discussion ping|main|title=User:Awesome Aasim/Example discussion}}
yields Script error: The module returned a nil value. It is supposed to return an export table.
Note: For really large pages, this template or module falls apart.
--- This module extracts all the users in either a marked LST or in wikitext and
-- generates links reflecting a courtesy ping.
--
-- @module Courtesy ping
-- @require Module:Arguments
-- @release alpha
local p = {}
local getArgs = require("Module:Arguments").getArgs
--- Makes a user link
-- @param {table} userTitle the title for the user object
-- @return {string} the formatted user link in the form of a ping
function makeUserLink( userTitle )
return mw.ustring.format( '@[[%s|%s]]', userTitle.prefixedText, userTitle.text )
end
--- Entry point for module
-- @param {table} frame processing frame
-- @return {string} wikitext
function p.main( frame )
local args = getArgs( frame )
if not mw.isSubsting() or args['__demo'] then
error( "[[Module:Courtesy ping]] must be substituted" )
end
local links = {}
local wikitext = args['wikitext'] or args[1] or nil
local lstCallText = args['title'] or nil
if lstCallText then
wikitext = frame:callParserFunction('#lsth', { lstCallText })
elseif not wikitext then
error( "Wikitext or a page title with section must be specified!" )
end
wikitext = mw.text.unstripNoWiki( wikitext )
local wikitextArray = mw.text.split( wikitext )
local inWikiLink = false
local inPipedLink = false
local toProcess = ''
for k,v in ipairs( wikitextArray ) do
if k ~= 1 then
if inWikiLink then
if wikitextArray[ k ] == '|' then
inPipedLink = true
inWikiLink = false
else
toProcess = toProcess .. v
end
end
if not inWikiLink and not inPipedLink then
if wikitextArray[ k ] == '[' and wikitextArray[ k - 1 ] == '['
then
toProcess = ''
inWikiLink = true
end
else
if wikitextArray[ k ] == ']' and wikitextArray[ k - 1 ] == ']'
then
toProcess = mw.ustring.sub( toProcess,
mw.ustring.len( toProcess ) - 2 )
links = table.insert( links, toProcess )
toProcess = ''
inWikiLink = false
inPipedLink = false
end
end
end
end
local out = ''
for k,v in pairs(links) do
local title = mw.title.new( v )
if title.namespace == 2 and not title.isSubpage then
out = out .. ' ' .. makeUserLink( title )
end
end
return '<!-- Begin [[Module:Courtesy ping]] --> ' .. mw.text.trim( out )
.. ' <!-- End [[Module:Courtesy ping]] -->'
end