Module:PublicSubpageWatchlist

From Wikibooks, open books for an open world
Jump to: navigation, search
Documentation[edit] [history] [purge]

Generates a list of links to all non-redirect pages under a prefix, including the root, and to the corresponding talk pages. The list allows using the Related Changes tool as an improvised public watchlist for a book. The implementation uses Module:Subpages and Template:La2.

Usage[edit]

{{#invoke: PublicSubpageWatchlist | linksList | Chess}}

See also[edit]

This module is an implementation of w:Help:Public watchlist for subpages.

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