Module:DPLlua: Difference between revisionsGive feedback
osrsw>CephHunter Created page with "-- <nowiki> local dpl = {} dpl.pipe = '¦' local dataContentMarker = '`#@@#`' local usesInclude = {} -- Custom function for splitting a string because mw.text.split() is waa..." |
osrsw>CephHunter No edit summary |
||
| Line 1: | Line 1: | ||
-- <nowiki> | -- <nowiki> | ||
local dpl = {} | local dpl = {} | ||
local checkType = require( 'libraryUtil' ).checkType | |||
dpl.pipe = '¦' | dpl.pipe = '¦' | ||
| Line 197: | Line 198: | ||
local _usesInclude = table.remove( usesInclude, 1 ) | local _usesInclude = table.remove( usesInclude, 1 ) | ||
local res = {} | local res = {} | ||
query = query:gsub( '<p>Extension:DynamicPageList .-</p>', function(item) res.error = item; return '' end) | |||
if not query:match( '^@@' ) then -- @@ is used when no result is found | if not query:match( '^@@' ) then -- @@ is used when no result is found | ||
if _usesInclude then | if _usesInclude then | ||
query = query:gsub( '\127\'"`UNIQ%-%-nowiki%-%x+%-QINU`"\'\127', function(item) return '<nowiki>' .. item .. '</nowiki>' end ) -- Unstrip nowiki so we can clean their content | |||
query = mw.text.unstripNoWiki( query ) | |||
query = query:gsub( dataContentMarker..'(.-)'..dataContentMarker, escape ) | query = query:gsub( dataContentMarker..'(.-)'..dataContentMarker, escape ) | ||
query = query:gsub( '{|.-|%-', '') -- Remove the header of the table | query = query:gsub( '{|.-|%-', '') -- Remove the header of the table | ||
| Line 206: | Line 211: | ||
query = query:gsub( '|}', '|-' ) | query = query:gsub( '|}', '|-' ) | ||
end | end | ||
query = trim( query ) | query = trim( query ) | ||
query = split( query, '|-', true ) -- Results of the returned pages are separated by |- | query = split( query, '|-', true ) -- Results of the returned pages are separated by |- | ||
for _, v in ipairs( query ) do | for _, v in ipairs( query ) do | ||
if v:match( '%S' ) then | if v:match( '%S' ) then | ||
| Line 215: | Line 220: | ||
local title = v:match( '^|%[%[(.-)|' ) | local title = v:match( '^|%[%[(.-)|' ) | ||
local dataList = v:match( '^|.-|.-|(.*)' ) -- This is everything after the title | local dataList = v:match( '^|.-|.-|(.*)' ) -- This is everything after the title | ||
if not _usesInclude then | if not _usesInclude then | ||
if title and title ~= '' then | if title and title ~= '' then | ||
| Line 224: | Line 229: | ||
dataList = split( dataList, '|', true ) | dataList = split( dataList, '|', true ) | ||
local _dataList = {} | local _dataList = {} | ||
for _, dataItem in ipairs( dataList ) do | for _, dataItem in ipairs( dataList ) do | ||
dataItem = unEscape( dataItem ) | dataItem = unEscape( dataItem ) | ||
| Line 234: | Line 239: | ||
dataItem = dataItem:gsub( '%b{}', function(x) return x:gsub( '§', '|' ) end ) -- Restore pipe characters inside links and templates | dataItem = dataItem:gsub( '%b{}', function(x) return x:gsub( '§', '|' ) end ) -- Restore pipe characters inside links and templates | ||
dataItem = dataItem:gsub( '%b[]', function(x) return x:gsub( '§', '|' ) end ) | dataItem = dataItem:gsub( '%b[]', function(x) return x:gsub( '§', '|' ) end ) | ||
dataItem = dataItem:gsub( '<nowiki>(.-)</nowiki>', function(x) return mw.getCurrentFrame():extensionTag( 'nowiki', x ) end ) -- Restrip nowiki | |||
dataItem = trim( dataItem ) | dataItem = trim( dataItem ) | ||
if dataItem:match( '§' ) then -- Check if we included a template | if dataItem:match( '^§' ) then -- Check if we included a full template | ||
dataItem = split( dataItem, ' | dataItem = split( dataItem, '\n§', true ) | ||
local _dataItem = {} | local _dataItem = {} | ||
for i, item in ipairs( dataItem ) do | for i, item in ipairs( dataItem ) do | ||
if i | if i == 1 then -- First item doesn't start with a \n so it still has § in front of it | ||
if item:find( '=' ) then -- Check if the parameter is named or unnamed | item = item:sub( 3 ) | ||
end | |||
if item:find( '=' ) then -- Check if the parameter is named or unnamed | |||
local param, value = item:match( '^%s*(.-)%s*=%s*(.-)%s*$' ) | |||
_dataItem[ param ] = value | |||
else | |||
table.insert( _dataItem, trim( item ) ) | |||
end | end | ||
end | end | ||
dataItem = _dataItem | dataItem = _dataItem | ||
end | end | ||
table.insert( _dataList, dataItem ) | table.insert( _dataList, dataItem ) | ||
end | end | ||
if title and title ~= '' then | if title and title ~= '' then | ||
table.insert( res, { title=title, include=_dataList } ) | table.insert( res, { title=title, include=_dataList } ) | ||
| Line 274: | Line 282: | ||
for i = 1, #queries do | for i = 1, #queries do | ||
checkType( 'Module:DPLlua.ask', i, queries[i], 'table' ) | |||
removeFormattingSettings( queries[i] ) | removeFormattingSettings( queries[i] ) | ||
queries[i] = formatDpl( queries[i] ) | queries[i] = formatDpl( queries[i] ) | ||