Module:PublicSubpageWatchlist

local _M = {}
 
local subpages = require('Module:Subpages').subpages
 
function _M.linksList(frame)
	local page, talk, text, success = frame.args[1];
	local pageList = {};
	
	if not page then
		page = mw.title.getCurrentTitle();
	else
		success, page = pcall(mw.title.new, page, 0);
		if not success then
			return ''
		end
	end

	talk = mw.site.namespaces[page.namespace].talk.name;
	text = page.text;
	page = page.prefixedText;

    for entry, count in subpages(page) do
    	if count > 1000 then
    		break;
    	end
    	if count ~= 1 then
    		table.insert(pageList, table.concat{ '* [[:', page, entry, ']]', ' ([[', talk, ':', text, entry, '|talk]])' });
    	else
    		table.insert(pageList, table.concat{ '* [[:', page, ']]', ' ([[', talk, ':', text, '|talk]])' });
    	end
    end
    
    return table.concat( pageList, '\n' );
end
 
return _M