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 p = {} -- Page object
第8行 ⟶ 第7行:
-- Define a custom error message for this module.
local function err(msg, section)
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
第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) .. '|
end
local function
if p.isTalkPage then
return '[[:' .. tostring(p.subjectPageTitle) .. '|subject]]'
else
return '[[' .. tostring(p.talkPageTitle) .. '|talk]]'
end
end
local function
return '[[Special:WhatLinksHere/' .. p.fullText .. '|
end
local function makeRelatedChangesLink()
return '[[Special:RelatedChanges/' .. p.fullText .. '|
end
local function makeEditLink()
return '[[Special:EditPage/' .. p.fullText .. '|edit]]'
end
local function makeHistoryLink()
end
local function makeWatchLink()
end
local function makeTargetLogsLink()
local url = mw.uri.fullUrl( 'Special:Log', 'page=' .. mw.uri.encode(p.fullText) )
return '[' .. tostring(url) .. '
end
local function makeEditFilterLogLink()
local url = mw.uri.fullUrl( 'Special:AbuseLog', 'wpSearchTitle=' .. mw.uri.encode(p.fullText) )
return '[' .. tostring(url) .. '
end
local function
local endDate, startDate = "", ""
if args.date then
date = os.time{year=string.sub(date,1,4), month=string.sub(date,5,6), day=string.sub(date,7,8)}
endDate = os.date("%Y-%m-%d", date - (1*86400))
startDate = os.date("%Y-%m-%d", date - (30*86400))
else
startDate = os.date("%Y-%m-%d", os.time() - (60*86400))
end
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
local
return '[' ..
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 = {
ts = makeTalkOrSubjectLink,
wlh = makeWhatLinksHereLink,
pv = makePageViewsLink,
h500 = makeHistory500Link,
srch = makeSearchLink
}
local function getLink(linktype, args)
local func = linktypes[linktype]
if func then
return func(args)
else
return err('"' .. linktype .. '" is not a valid link code', 'Not a valid link code')
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('
end
local noError
noError, p = pcall(mw.title.new, args.page)
if not noError then
return err('pcall mw.title
end
if args.exists and (not p or p['id'] == 0) then
return err('
end
end
第175行 ⟶ 第188行:
-- It is used in the module documentation.
local function getLinkTable(args)
-- Build a table of all of the links.
local header_row = mw.html.create('tr')
:tag('th'):wikitext('Code'):done()
:tag('th'):wikitext('Preview'):done()
local result = mw.html.create('table')
:addClass('wikitable'):addClass('plainlinks'):addClass('sortable')
:node(header_row)
for code, _ in pairs(linktypes) do
local row = mw.html.create('tr')
:tag('th'):wikitext(code):done()
:tag('td'):wikitext(getLink(code, args)):done()
result:node(row)
end
return tostring(result)
end
第201行 ⟶ 第217行:
return dataStringError
end
local linktype = args[1]
if not linktype then
return err('
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
| |||