มอดูล:Requested articles

จากวิกิพีเดีย สารานุกรมเสรี
Documentation icon คู่มือการใช้งานมอดูล[ดู] [แก้] [ประวัติ] [ล้างแคช]

การใช้งาน

มอดูลนี้สุ่มลิงก์ในหน้าวิกิพีเดีย:บทความที่ต้องการ มาแสดงผลในหน้า พิเศษ:ปรับปรุงล่าสุด

วิธีใช้ ให้เรียก {{#invoke:Requested articles|main|จำนวนลิงก์ที่ต้องการจะให้แสดง}}

เช่น

{{#invoke:Requested articles|main|3}} จะแสดงผล ช่างทำวัตถุทองแดง^ ผู้เชี่ยวชาญ^ หิมะน้ำแข็ง^

local p = {}
local random = require('Module:Math')._random

function p.main(frame)
	total = tonumber(frame.args[1])
	links = {}
	content = mw.title.new('วิกิพีเดีย:บทความที่ต้องการ'):getContent()
	for thlink, enlink in content:gmatch('* %[%[(%S-)%]%] %(%[%[(:en:%S-)%]%]%)') do
		if not thlink:find(']', 1, true) then
			table.insert(links, {thlink, enlink})
		end
	end
	selected = {}
	out = {}
	while #out < total do
		num = random(#links)
		if not selected[num] then
			selected[num] = true
			table.insert(out, '[[' .. links[num][1] .. ']][[' .. links[num][2] .. '|^]]')
		end
	end
	return table.concat(out, ' ')
end

return p