Module:Discussion ping

--- 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 )
	return p._main( args, frame )
end

function p._main( args, frame )
	frame = frame or mw.getCurrentFrame()
	if not mw.isSubsting() and not args['__demo'] then
		error( "[[Module:Courtesy ping]] must be substituted" )
	end
	local links = {}
	local noPing = {}
	local i = 1
	while args["noping" .. i] do
		noPing[ args[ "noping" .. i ] ] = true
		i = i + 1	
	end
	local wikitext = args['wikitext'] or args[1] or nil
	local pageToInclude = args['title'] or ''
	local lstTitle = mw.title.new( pageToInclude )
	if not wikitext and lstTitle then
		if lstTitle.fragment and lstTitle.fragment ~= ''  then
			wikitext = frame:callParserFunction('#lsth', { lstTitle.prefixedText, lstTitle.fragment })
		else
			wikitext = frame:preprocess(lstTitle:getContent())
		end
	elseif not wikitext then
		error( "Wikitext or a page title with section must be specified!" )
	end
	mw.log( wikitext )
	
	-- Thanks ChatGPT
	for link, display in mw.ustring.gmatch(wikitext, "%[%[([^%[%]|]+)%|?([^%[%]]*)%]%]") do
		mw.logObject({link, display})
	    if display == "" then
	        display = link  -- No display text, so use the link itself
	    end
		if not links[ link ] then links[ link ] = mw.title.new( link ) end
	end
	-- local wikitextArray = mw.text.split( wikitext, '' )
	-- local inWikiLink = false
	-- local inPipedLink = false
	-- local trimmed = false
	-- local toProcess = ''
	-- for k,v in ipairs( wikitextArray ) do
	-- 	if k ~= 1 then
	-- 		if inWikiLink then
	-- 			toProcess = toProcess .. v
	-- 			if wikitextArray[ k ] == '|' then
	-- 				toProcess = mw.ustring.sub( toProcess, 0,
	-- 					mw.ustring.len( toProcess ) - 1 )
	-- 				trimmed = true
	-- 				inPipedLink = true
	-- 				inWikiLink = false
	-- 			end
	-- 		end
	-- 		if not inWikiLink and not inPipedLink then
	-- 			trimmed = false
	-- 			if wikitextArray[ k ] == '[' and wikitextArray[ k - 1 ] == '['
	-- 				then
	-- 				toProcess = ''
	-- 				inWikiLink = true
	-- 			end
	-- 		else
	-- 			if wikitextArray[ k ] == ']' and wikitextArray[ k - 1 ] == ']'
	-- 				then
	-- 				if not trimmed then
	-- 					toProcess = mw.ustring.sub( toProcess, 0,
	-- 						mw.ustring.len( toProcess ) - 2 )
	-- 					trimmed = true
	-- 				end
	-- 				links[ toProcess ] = mw.title.new( toProcess )
	-- 				toProcess = ''
	-- 				inWikiLink = false
	-- 				inPipedLink = false
	-- 			end
	-- 		end
	-- 	end
	-- end
	
	mw.logObject( links )
	
	local out = {}
	
	for k,v in pairs(links) do
		mw.logObject( v )
		if v ~= nil then
			if v.namespace == 2 and not v.isSubpage and not noPing[ v.text ] then
				table.insert( out, makeUserLink( v ) )
			end
		end
	end
	
	return '<!-- Begin [[Module:Courtesy ping]] -->' .. mw.text.trim( table.concat( out, ' ' ) )
		.. '<!-- End [[Module:Courtesy ping]] -->'	
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.