Halo Esports Wiki
Halo Esports Wiki
[checked revision][checked revision]
Donut (talk | contribs)
m (Protected "Module:DPLUtil": Syncing content across wikis ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
Donut (talk | contribs)
m (Syncing content across wikis)
Line 1: Line 1:
local m_text = require('Module:Text')
+
local util_text = require('Module:TextUtil')
 
local util_table = require('Module:TableUtil')
 
local util_table = require('Module:TableUtil')
 
local lang = mw.getLanguage('en')
 
local lang = mw.getLanguage('en')
 
local p = {}
 
local p = {}
  +
  +
function p.query(args, frame)
  +
if not frame then
  +
frame = mw.getCurrentFrame()
 
end
  +
args[1] = ''
  +
return frame:callParserFunction{
  +
name = '#dpl:',
  +
args = args
  +
}
  +
end
  +
  +
function p.truncateResult(tbl)
  +
if not next(tbl) then
 
return {}
  +
end
 
table.remove(tbl, #tbl)
 
return tbl
  +
end
  +
  +
function p.getListOfPagenames(args, frame)
  +
args.format = ',%PAGE%,;;,'
  +
args.debug = 0
  +
local result = p.query(args, frame)
  +
local tbl = util_text.split(result or '',';;')
  +
return p.truncateResult(tbl)
  +
end
  +
   
 
function p.escape(link)
 
function p.escape(link)
Line 28: Line 56:
 
}
 
}
 
newlinks = newlinks .. mw.title.getCurrentTitle().text
 
newlinks = newlinks .. mw.title.getCurrentTitle().text
return m_text.split(newlinks,';')
+
return util_text.split(newlinks,';')
 
end
 
end
   
Line 48: Line 76:
 
args = args
 
args = args
 
}
 
}
local tbl = m_text.split(list,';')
+
local tbl = util_text.split(list,';')
if not next(tbl) then
+
return p.truncateResult(tbl)
return {}
 
end
 
table.remove(tbl, #tbl)
 
return tbl
 
 
end
 
end
   

Revision as of 04:37, 16 April 2019

To edit the documentation or categories for this module, click here.


local util_text = require('Module:TextUtil')
local util_table = require('Module:TableUtil')
local lang = mw.getLanguage('en')
local p = {}

function p.query(args, frame)
	if not frame then
		frame = mw.getCurrentFrame()
	end
	args[1] = ''
	return frame:callParserFunction{
		name = '#dpl:',
		args = args
	}
end

function p.truncateResult(tbl)
	if not next(tbl) then
		return {}
	end
	table.remove(tbl, #tbl)
	return tbl
end

function p.getListOfPagenames(args, frame)
	args.format = ',%PAGE%,;;,'
	args.debug = 0
	local result = p.query(args, frame)
	local tbl = util_text.split(result or '',';;')
	return p.truncateResult(tbl)
end
		

function p.escape(link)
	link = link or ''
	link = string.gsub(link,'%(','\\%(')
	link = string.gsub(link,'%)','\\%)')
	link = string.gsub(link,'%+','\\%+')
	return link
end

function p.whichPagesExist(links, frame)
	if not frame then frame = mw.getCurrentFrame() end
	for k, link in ipairs(links) do
		links[k] = lang:ucfirst(p.escape(link))
	end
	newlinks = frame:callParserFunction{
		name = '#dpl:',
		args = {
			'',
			titleregexp = table.concat(links,'|'),
			format = ',%PAGE%,;,',
			namespace = '',
			debug = 0,
		}
	}
	newlinks = newlinks .. mw.title.getCurrentTitle().text
	return util_text.split(newlinks,';')
end

function p.whatRedirectsHere(page, settings, frame)
	local args = {
		'',
		linksto = page,
		redirects = 'only',
		namespace = '',
		format = ',,%PAGE%;,',
		debug = '0'
	}
	util_table.merge(args, settings)
	if not frame then
		frame = mw.getCurrentFrame()
	end
	local list = frame:callParserFunction{
		name = '#dpl',
		args = args
	}
	local tbl = util_text.split(list,';')
	return p.truncateResult(tbl)
end

return p