Khác biệt giữa bản sửa đổi của “Mô đun:Redirect hatnote”

Nội dung được xóa Nội dung được thêm vào
Lùi đến phiên bản 26171242 lúc 2017-02-06 16:19:00 của Boyconga278 dùng popups
Không có tóm lược sửa đổi
Thẻ: Người dùng mới sửa mô đun
Dòng 1:
-- Mô đun này tạo ra một "redirect" hatnote. Nó trông như thế này:
--[[
-- '"X" chuyển hướng tới đây. Đối với các sử dụng khác, xem Y.'
-- This module produces a "redirect" hatnote. It looks like this:
-- Nó thực hiện mẫu {{redirect}}.
-- '"X" redirects here. For other uses, see Y.'
-- It implements the {{redirect}} template.
--]]
 
local mHatnote = require('Mô đunModule:Hatnote')
local mHatList = require('Mô đunModule:Hatnote list')
local mArguments --lazilykhởi initializetạo lười biếng
local libraryUtil = require('libraryUtil')
local checkTypekiemTraLoai = libraryUtil.checkType
local checkTypeMultikiemTraLoaiNhieu = libraryUtil.checkTypeMulti
 
local p = {}
 
local function getTitlelayTieuDe(...)
local successthanhCong, titleObjdoiTuongTieuDe = pcall(mw.title.new, ...)
if successthanhCong then
return titleObjdoiTuongTieuDe
else
return nil
Hàng 23 ⟶ 21:
end
 
function p.redirectchuyenHuong(framekhung)
mArguments = require('Mô đunModule:Arguments')
local args = mArguments.getArgs(framekhung, {parentOnly=true})
--Lấy số lượng chuyển hướng
--Get number of redirects
local numRedirectssoLuongChuyenHuong = tonumber(framekhung.args[1]) or 1
-- CreateTạo thebảng optionstùy tablechọn.
local optionstuyChon = {}
optionstuyChon.selfref = args.selfref
return p._redirect_chuyenHuong(args, numRedirectssoLuongChuyenHuong, optionstuyChon)
end
 
function p._redirect_chuyenHuong(args, numRedirectssoLuongChuyenHuong, optionstuyChon, currentTitletieuDeHienTai, redirectTitletieuDeChuyenHuong, targetTitletieuDeMucTieu)
-- Xác thực đầu vào. Không cần kiểm tra tieuDeHienTai, tieuDeChuyenHuong hoặc
-- Validate the input. Don't bother checking currentTitle, redirectTitle or
-- tieuDeMucTieu, vì chúng chỉ được sử dụng trong kiểm tra.
-- targetTitle, as they are only used in testing.
checkTypekiemTraLoai('_redirect_chuyenHuong', 1, args, 'table')
checkTypekiemTraLoai('_redirect_chuyenHuong', 2, numRedirectssoLuongChuyenHuong, 'number', true)
soLuongChuyenHuong = soLuongChuyenHuong or 1
numRedirects = numRedirects or 1
checkTypekiemTraLoai('_redirect_chuyenHuong', 3, optionstuyChon, 'table', true)
optionstuyChon = optionstuyChon or {}
currentTitletieuDeHienTai = currentTitletieuDeHienTai or mw.title.getCurrentTitle()
-- Lấy bảng chuyển hướng
-- Get the table of redirects
local redirectchuyenHuong = {}
for i = 1, numRedirectssoLuongChuyenHuong do
-- Trả về lỗi nếu thiếu tham số chuyển hướng.
-- Return an error if a redirect parameter is missing.
if not args[i] then
return mHatnote.makeWikitextError(
'tham số đổichuyển hướng bị thiếu',
'Template:Redirect#Errors',
'Bản mẫu:Đổi hướng#Các lỗi',
args.category
)
end
redirectchuyenHuong[i] = args[i]
end
-- GenerateTạo thevăn textbản.
local formattedRedirectchuyenHuongDaDinhDang = {}
for k,v in pairs(redirectchuyenHuong) do
formattedRedirectchuyenHuongDaDinhDang[k] = '"' .. v .. '"'
end
local textvanBan = {
mHatList.andList(formattedRedirectchuyenHuongDaDinhDang) .. ' ' .. (#redirectchuyenHuong == 1 and 'đổichuyển hướng' or 'đổichuyển hướng') .. ' tới đây.',
mHatList._forSee(args, #redirectchuyenHuong + 1, {title = redirectchuyenHuong[1]})
}
textvanBan = table.concat(textvanBan, ' ')
-- Chức năng để thêm danh mục
-- Functionality for adding categories
local categoryTablebangDanhMuc = {}
function addCategorythemDanhMuc(cat)
if cat and cat ~= '' then
-- AddThêm bytheo indexchỉ tomục avoidđể duplicatestránh trùng lặp
categoryTablebangDanhMuc[string.format('[[Thể loạiCategory:%s]]', cat)] = true
end
end
--Tạo danh mục theo dõi
--Generate tracking categories
local mhOptionsmhTuyChon = {}
for k,v in pairs(redirectchuyenHuong) do
-- Chúng ta không cần danh mục theo dõi nếu lời gọi mẫu đã được
-- We don't need a tracking category if the template invocation has been
-- sao chép trực tiếp từ tài liệu, hoặc nếu chúng ta không ở trong không gian chính hoặc danh mục.
-- copied directly from the docs, or if we aren't in main- or category-space.
if not v:find('^REDIRECT%d*$') and v ~= 'TERM' --
and currentTitletieuDeHienTai.namespace == 0 or currentTitletieuDeHienTai.namespace == 14
then
redirectTitletieuDeChuyenHuong = redirectTitletieuDeChuyenHuong or getTitlelayTieuDe(v)
if not redirectTitletieuDeChuyenHuong or not redirectTitletieuDeChuyenHuong.exists then
addCategorythemDanhMuc('Thiếu trang đổichuyển hướng')
elseif not redirectTitletieuDeChuyenHuong.isRedirect then
addCategorythemDanhMuc('Bài viết có hatnote đổichuyển hướng cần kiểm tra lại')
else
local mRedirectmChuyenHuong = require('Mô đunModule:Redirect')
local targetmucTieu = mRedirectmChuyenHuong.getTarget(redirectTitletieuDeChuyenHuong)
targetTitletieuDeMucTieu = targetTitletieuDeMucTieu or targetmucTieu and getTitlelayTieuDe(targetmucTieu)
if targetTitletieuDeMucTieu and targetTitletieuDeMucTieu ~= currentTitletieuDeHienTai then
addCategorythemDanhMuc('Bài viết có hatnote đổichuyển hướng cần kiểm tra lại')
end
end
end
 
-- GenerateTạo thecác optionstùy tochọn passđể totruyền vào [[Mô đunModule:Hatnote]].
if currentTitletieuDeHienTai.namespace == 0 and not mhOptionsmhTuyChon.selfref
and redirectTitletieuDeChuyenHuong and redirectTitletieuDeChuyenHuong.namespace ~= 0
then
-- WeChúng areta onđang a mainspacetrên page,một andtrang thekhông gian chính, và hatnote startsbắt đầu với cái with somethingđó
-- likenhư "Wikipedia:Foo redirectschuyển herehướng tới đây", sovì vậy tự động automaticallygắn labelnhãn it as
-- amột self-referencetham chiếu tự.
mhOptionsmhTuyChon.selfref = true
else
mhOptionsmhTuyChon.selfref = optionstuyChon.selfref
end
end
--nối tất cả các danh mục
--concatenate all the categories
local categorydanhMuc = ''
for k,v in pairs(categoryTablebangDanhMuc) do
categorydanhMuc = categorydanhMuc .. k
end
 
return mHatnote._hatnote(textvanBan, mhOptionsmhTuyChon) .. categorydanhMuc
end