Module:PageLinks:修订间差异

删除的内容 添加的内容
zhwiki>EqJjgOa8rVvsRmZL
小 普通繁简转换功能在Editnotices无法发挥作用,用Lan模块替代其进行转换
 
enwiki>Axolitl
Make search exact per talk page (ping: @User:Myceteae and User:Scyrme)
标签:已被回退
第1行:
local ToolbarBuilder = require('Module:Toolbar')
local mLan = require('Module:Lan')
 
local p = {} -- Page object
第8行 ⟶ 第7行:
-- Define a custom error message for this module.
local function err(msg, section)
local help
return '<strong class="error">[[模块:PageLinks|' .. mLan._main({['zh-hans']='模块', ['zh-hant']='模組'}, mw.getCurrentFrame()) .. ':PageLinks]]錯誤:' .. msg .. '。</strong>[[Category:有错误的PageLinks嵌入]]'
if section then
help = ' ([[Template:Page-multi#' .. section .. '|help]])'
else
help = ''
end
local cat
if demo == 'yes' then
cat = ''
else
cat = '[[Category:PageLinks transclusions with errors]]'
end
return '<span class="error">[[Template:Page-multi|Page-multi]] error: ' .. msg
.. help .. '.</span>' .. cat
end
 
第14行 ⟶ 第26行:
-- To add more link types, write a function that produces an individual link, and put --
-- it at the bottom of the list below. Then, add a link code for your function to the --
-- "linktypes" table. Try and make the code three letters or less.
--
-- If you want more helper strings, you can define them in the generatePageDataStrings --
第29行 ⟶ 第41行:
 
local function makeTalkLink()
return '[[' .. tostring(p.talkPageTitle) .. '|讨论talk]]'
end
 
local function makeWhatLinksHereLinkmakeTalkOrSubjectLink()
if p.isTalkPage then
return '[[Special:WhatLinksHere/' .. p.fullText .. '|' .. mLan._main({['zh-hans']='链接', ['zh-hant']='連結'}, mw.getCurrentFrame()) .. ']]'
return '[[:' .. tostring(p.subjectPageTitle) .. '|subject]]'
else
return '[[' .. tostring(p.talkPageTitle) .. '|talk]]'
end
end
 
local function makeWhatLinksHereLink2makeWhatLinksHereLink()
return '[[Special:WhatLinksHere/' .. p.fullText .. '|' .. mLan._main({['zh-hans']='链', ['zh-hant']='連'}, mw.getCurrentFrame()) .. '入links]]'
end
 
local function makeRelatedChangesLink()
return '[[Special:RelatedChanges/' .. p.fullText .. '|相关related]]'
end
 
local function makeEditLink()
return '[[Special:EditPage/' .. p.fullText .. '|edit]]'
local url = p:fullUrl( 'action=edit' );
return '[' .. url .. ' 编辑]'
end
 
local function makeHistoryLink()
localreturn url'[[Special:PageHistory/' =.. p:fullUrl(.fullText .. 'action=|history]]' );
return '[' .. url .. ' 历史]'
end
 
local function makeWatchLink()
localreturn url'[' =.. p:fullUrl( 'action=watch' ); .. ' watch]'
return '[' .. url .. ' 监视]'
end
 
local function makeTargetLogsLink()
local url = mw.uri.fullUrl( 'Special:Log', 'page=' .. mw.uri.encode(p.fullText) )
return '[' .. tostring(url) .. ' 日志logs]'
end
 
local function makeEditFilterLogLink()
local url = mw.uri.fullUrl( 'Special:AbuseLog', 'wpSearchTitle=' .. mw.uri.encode(p.fullText) )
return '[' .. tostring(url) .. ' 编辑过滤器日志abuse&nbsp;filter&nbsp;log]'
end
 
local function StatsGrokSeURLmakePageViewsLink(year, month, langargs)
local endDate, startDate = "", ""
local url = 'http://stats.grok.se/' .. lang .. '/' .. year .. string.format("%0.2d",month) .. '/' .. mw.uri.encode( p.fullText )
return url
end
 
if args.date then
local function monthsago(months)
local rvdate = osstring.dategsub(args.date,"-","*t")
date = os.time{year=string.sub(date,1,4), month=string.sub(date,5,6), day=string.sub(date,7,8)}
if rv.month < months + 1 then
endDate = os.date("%Y-%m-%d", date - (1*86400))
rv.month = 12 + (rv.month - months)
startDate = os.date("%Y-%m-%d", date - (30*86400))
rv.year = rv.year - 1
else
rv.monthendDate = rvos.month date("%Y- months%m-%d")
startDate = os.date("%Y-%m-%d", os.time() - (60*86400))
end
 
local project = string.sub(mw.site.server,3)
return rv
local url = mw.uri.encode(p.fullText, "WIKI")
local urlargs = '?start=' .. startDate .. '&end=' .. endDate .. '&project=' .. project .. '&pages=' .. tostring(url)
 
return '[//pageviews.toolforge.org/' .. urlargs .. ' stats]'
end
 
local function makeViewsLastMonthStatsGrokSeLinkmakeHistory500Link()
local whenurl = monthsagop:fullUrl(1 'action=history&limit=500' );
return '[' .. StatsGrokSeURL(when.year,url when.month,. 'en') .. 'long 统计history]'
end
 
local function makeSearchLink()
local url = mw.uri.fullUrl( 'Special:Search', 'search="' .. mw.uri.encode(p.fullText) .. '"&fulltext=1&ns0=1')
return '[' .. tostring(url) .. ' search]'
end
 
第97行 ⟶ 第118行:
 
local linktypes = {
{'t' , = makeTalkLink},
ts = makeTalkOrSubjectLink,
{'wlh' , makeWhatLinksHereLink},
wlh = makeWhatLinksHereLink,
{'wlh2' , makeWhatLinksHereLink2},
{'rc' , = makeRelatedChangesLink},
{'edit', = makeEditLink},
{'h' , = makeHistoryLink},
{'w' , = makeWatchLink},
{'tl' , = makeTargetLogsLink},
{'efl' , = makeEditFilterLogLink},
{['vlm-sgs'] ,= makeViewsLastMonthStatsGrokSeLink}makePageViewsLink,
pv = makePageViewsLink,
h500 = makeHistory500Link,
srch = makeSearchLink
}
 
local function getLink(linktype, args)
local func = linktypes[linktype]
local linkNumber
if func then
for i, value in ipairs(linktypes) do
return func(args)
if value[1] == linktype then
else
linkNumber = i
return err('"' .. linktype .. '" is not a valid link code', 'Not a valid link code')
break
end
end
if not linkNumber then
return err('“' .. linktype .. '”不是有效的链接代码', '非有效链接代码')
end
local result = linktypes[linkNumber][2]()
if type(result) ~= 'string' then
return err(
'代码“' .. linktype .. '”的函数没有返回字符串值',
'函数未返回字符串值'
)
end
return result
end
 
第136行 ⟶ 第148行:
if type(k) == 'number' and p then
numArgsExist = true
targs[k] = getLink(v, args)
end
end
targs.style = args.small and 'font-size: 90%;'
targs.separator = args.separator or 'dot'
targs.class = 'lx'
 
if numArgsExist == false then
return nil -- Don't return a toolbar if no numeric arguments exist. -- this bit looks odd
第152行 ⟶ 第165行:
-- If the page name is absent or blank, return an error and a tracking category.
if args.page == '' or not args.page then
return err('没有探测到页面no page detected')
end
local noError
noError, p = pcall(mw.title.new, args.page)
if not noError then
return err('pcall mw.title 失败failed')
end
if args.exists and (not p or p['id'] == 0) then
return err('未找到页面page not found')
end
end
第175行 ⟶ 第188行:
-- It is used in the module documentation.
local function getLinkTable(args)
demo = args.demo -- Set the demo variable.
-- Generate the page data strings and return any errors.
local dataStringError = generatePageDataStrings(args)
if dataStringError then
return dataStringError
end
-- Build a table of all of the links.
local header_row = mw.html.create('tr')
-- Build a table of all of the links.
:tag('th'):wikitext('Code'):done()
local result = '<table class="wikitable plainlinks sortable">'
:tag('th'):wikitext('Preview'):done()
.. '\n<tr><th>代码</th><th>预览</th></tr>'
local result = mw.html.create('table')
for i, value in ipairs(linktypes) do
:addClass('wikitable'):addClass('plainlinks'):addClass('sortable')
local code = value[1]
:node(header_row)
result = result .. "\n<tr><td>'''" .. code .. "'''</td><td>" .. getLink(code) .. '</td></tr>'
for code, _ in pairs(linktypes) do
end
local row = mw.html.create('tr')
result = result .. '\n</table>'
:tag('th'):wikitext(code):done()
:tag('td'):wikitext(getLink(code, args)):done()
return result
result:node(row)
end
return tostring(result)
end
 
第201行 ⟶ 第217行:
return dataStringError
end
 
local linktype = args[1]
if not linktype then
return err('没有指定链接类型no link type specified')
end
local result = getLink(linktype, args)
result = result .. generateTrackingCategories()
return result
第217行 ⟶ 第233行:
if dataStringError then
return dataStringError
end
 
-- Build the template output.
local result = makeToolbar(args) -- Get the toolbar contents.
第271行 ⟶ 第287行:
origArgs = frame
end
 
-- Strip whitespace, and treat blank arguments as nil.
-- 'page', and 'separator' have different behaviour depending on
第282行 ⟶ 第298行:
end
end
 
return func(args)
end