Модуль:RandomSong: различия между версиями
Admin (обсуждение | вклад) мНет описания правки |
Admin (обсуждение | вклад) мНет описания правки |
||
| Строка 2: | Строка 2: | ||
local dpl_result = mw.getCurrentFrame():expandTemplate{ | local dpl_result = mw.getCurrentFrame():expandTemplate{ | ||
title = 'DynamicPageList', | title = 'DynamicPageList', | ||
-- args = { | |||
-- category = 'Песни', | |||
-- mode = 'none', | |||
-- suppresserrors = 'true', | |||
-- noresultsfooter = 'false', | |||
-- count = 'max', | |||
-- ordermethod = 'random', | |||
-- namespace = '0', | |||
-- allowcachedresults = 'true', | |||
-- format = '*[[%PAGE%]]\n', | |||
-- } | |||
} | } | ||
Версия от 14:34, 23 июня 2023
Для документации этого модуля может быть создана страница Модуль:RandomSong/doc
-- Получаем список страниц из <DynamicPageList>
local dpl_result = mw.getCurrentFrame():expandTemplate{
title = 'DynamicPageList',
-- args = {
-- category = 'Песни',
-- mode = 'none',
-- suppresserrors = 'true',
-- noresultsfooter = 'false',
-- count = 'max',
-- ordermethod = 'random',
-- namespace = '0',
-- allowcachedresults = 'true',
-- format = '*[[%PAGE%]]\n',
-- }
}
-- Разбиваем список по строкам
local dpl_rows = mw.text.split(dpl_result, '\n')
-- Удаляем последнюю пустую строку, которая была добавлена форматированием
table.remove(dpl_rows)
-- Получаем случайное значение из списка страниц
local random_page = dpl_rows[math.random(#dpl_rows)]
-- Выводим выбранную страницу
return random_page