Module:PageLinks:修订间差异

删除的内容 添加的内容
enwiki>Axolitl
Make search exact per talk page (ping: @User:Myceteae and User:Scyrme)
标签:已被回退
CaelLab-import​(留言 | 贡献)
huifu bei enwiki daoru dingti de banben (shangyiban zhwiki>EqJjgOa8rVvsRmZL)
标签:手工回退
 
第1行:
local ToolbarBuilder = require('Module:Toolbar')
local mLan = require('Module:Lan')
 
local p = {} -- Page object
第7行 ⟶ 第8行:
-- Define a custom error message for this module.
local function err(msg, section)
return '<strong class="error">[[模块:PageLinks|' .. mLan._main({['zh-hans']='模块', ['zh-hant']='模組'}, mw.getCurrentFrame()) .. ':PageLinks]]錯誤:' .. msg .. '。</strong>[[Category:有错误的PageLinks嵌入]]'
local help
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
 
第26行 ⟶ 第14行:
-- 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 --
第41行 ⟶ 第29行:
 
local function makeTalkLink()
return '[[' .. tostring(p.talkPageTitle) .. '|talk讨论]]'
end
 
local function makeTalkOrSubjectLinkmakeWhatLinksHereLink()
return '[[Special:WhatLinksHere/' .. p.fullText .. '|' .. mLan._main({['zh-hans']='链接', ['zh-hant']='連結'}, mw.getCurrentFrame()) .. ']]'
if p.isTalkPage then
return '[[:' .. tostring(p.subjectPageTitle) .. '|subject]]'
else
return '[[' .. tostring(p.talkPageTitle) .. '|talk]]'
end
end
 
local function makeWhatLinksHereLinkmakeWhatLinksHereLink2()
return '[[Special:WhatLinksHere/' .. p.fullText .. '|links' .. mLan._main({['zh-hans']='链', ['zh-hant']='連'}, mw.getCurrentFrame()) .. '入]]'
end
 
local function makeRelatedChangesLink()
return '[[Special:RelatedChanges/' .. p.fullText .. '|related相关]]'
end
 
local function makeEditLink()
local url = p:fullUrl( 'action=edit' );
return '[[Special:EditPage/' .. p.fullText .. '|edit]]'
return '[' .. url .. ' 编辑]'
end
 
local function makeHistoryLink()
returnlocal '[[Special:PageHistory/'url ..= p.fullText ..:fullUrl( '|action=history]]' );
return '[' .. url .. ' 历史]'
end
 
local function makeWatchLink()
returnlocal '['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 makePageViewsLinkStatsGrokSeURL(argsyear, month, lang)
local url = 'http://stats.grok.se/' .. lang .. '/' .. year .. string.format("%0.2d",month) .. '/' .. mw.uri.encode( p.fullText )
local endDate, startDate = "", ""
return url
end
 
local function monthsago(months)
if args.date then
local daterv = stringos.gsubdate(args.date,"-","*t")
if rv.month < months + 1 then
date = os.time{year=string.sub(date,1,4), month=string.sub(date,5,6), day=string.sub(date,7,8)}
rv.month = 12 + (rv.month - months)
endDate = os.date("%Y-%m-%d", date - (1*86400))
rv.year = rv.year - 1
startDate = os.date("%Y-%m-%d", date - (30*86400))
else
endDaterv.month = osrv.date("%Ymonth -%m-%d") months
startDate = os.date("%Y-%m-%d", os.time() - (60*86400))
end
 
return rv
local project = string.sub(mw.site.server,3)
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 makeHistory500LinkmakeViewsLastMonthStatsGrokSeLink()
local urlwhen = p:fullUrlmonthsago( 'action=history&limit=500' 1);
return '[' .. urlStatsGrokSeURL(when.year, 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
 
第118行 ⟶ 第97行:
 
local linktypes = {
{'t' =, makeTalkLink},
{'wlh' , makeWhatLinksHereLink},
ts = makeTalkOrSubjectLink,
{'wlh2' , makeWhatLinksHereLink2},
wlh = makeWhatLinksHereLink,
{'rc' =, makeRelatedChangesLink},
{'edit =', makeEditLink},
{'h' =, makeHistoryLink},
{'w' =, makeWatchLink},
{'tl' =, makeTargetLogsLink},
{'efl' =, makeEditFilterLogLink},
[{'vlm-sgs'] =, makePageViewsLinkmakeViewsLastMonthStatsGrokSeLink},
pv = makePageViewsLink,
h500 = makeHistory500Link,
srch = makeSearchLink
}
 
local function getLink(linktype, args)
local linkNumber
local func = linktypes[linktype]
for i, value in ipairs(linktypes) do
if func then
if value[1] == linktype then
return func(args)
linkNumber = i
else
break
return err('"' .. linktype .. '" is not a valid link code', 'Not a valid link code')
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
 
第148行 ⟶ 第136行:
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
第165行 ⟶ 第152行:
-- 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
第188行 ⟶ 第175行:
-- 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.
-- Build a table of all of the links.
local header_row = mw.html.create('tr')
local result = '<table class="wikitable plainlinks sortable">'
:tag('th'):wikitext('Code'):done()
.. '\n<tr><th>代码</th><th>预览</th></tr>'
:tag('th'):wikitext('Preview'):done()
for i, value in ipairs(linktypes) do
local result = mw.html.create('table')
local code = value[1]
:addClass('wikitable'):addClass('plainlinks'):addClass('sortable')
result = result .. "\n<tr><td>'''" .. code .. "'''</td><td>" .. getLink(code) .. '</td></tr>'
:node(header_row)
end
for code, _ in pairs(linktypes) do
result = result .. '\n</table>'
local row = mw.html.create('tr')
:tag('th'):wikitext(code):done()
return result
:tag('td'):wikitext(getLink(code, args)):done()
result:node(row)
end
return tostring(result)
end
 
第217行 ⟶ 第201行:
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
第233行 ⟶ 第217行:
if dataStringError then
return dataStringError
end
 
-- Build the template output.
local result = makeToolbar(args) -- Get the toolbar contents.
第287行 ⟶ 第271行:
origArgs = frame
end
 
-- Strip whitespace, and treat blank arguments as nil.
-- 'page', and 'separator' have different behaviour depending on
第298行 ⟶ 第282行:
end
end
 
return func(args)
end