Modul:PageLinks
This module makes {{page-multi}} work, and is modeled on {{user-multi}}. See that template's documentation for more information.
Tracking/maintenance category
local ToolbarBuilder = require('Module:Toolbar')
local p = {} -- Page object
local trackingCategories = {} -- Table for storing the tracking categories.
local demo
-- Define a custom error message for this module.
local function err(msg, section)
local help
if section then
help = ' ([[Skabelon:Page-multi#' .. section .. '|hjælp]])'
else
help = ''
end
local cat
if demo == 'yes' then
cat = ''
else
cat = '[[Category:PageLinks transklusioner med fejl]]'
end
return '<span class="error">[[Skabelon:Page-multi|Page-multi]] error: ' .. msg
.. help .. '.</span>' .. cat
end
----------------------------------------------------------------------------------------------
-- 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 --
-- function below. --
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
-- LINK FUNCTIONS START --
----------------------------------------------------------------------------------------------
local function makePageLink()
return p.fullText and '[[:' .. p.fullText .. '|' .. p.fullText .. ']]' or ''
end
local function makeTalkLink()
return '[[' .. tostring(p.talkPageTitle) .. '|diskussion]]'
end
local function makeWhatLinksHereLink()
return '[[Special:WhatLinksHere/' .. p.fullText .. '|links]]'
end
local function makeRelatedChangesLink()
return '[[Special:RelatedChanges/' .. p.fullText .. '|related]]'
end
local function makeEditLink()
local url = p:fullUrl( 'action=edit' );
return '[' .. url .. ' redigér]'
end
local function makeHistoryLink()
local url = p:fullUrl( 'action=history' );
return '[' .. url .. ' historik]'
end
local function makeWatchLink()
local url = p:fullUrl( 'action=watch' );
return '[' .. url .. ' watch]'
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 filter log]'
end
local function StatsGrokSeURL(year, month, lang)
local url = 'http://stats.grok.se/' .. lang .. '/' .. year .. string.format("%0.2d",month) .. '/' .. mw.uri.encode( p.fullText, "PATH" )
return url
end
local function monthsago(months)
local rv = os.date("*t")
if rv.month < months + 1 then
rv.month = 12 + (rv.month - months)
rv.year = rv.year - 1
else
rv.month = rv.month - months
end
return rv
end
local function makeViewsLastMonthStatsGrokSeLink()
local when = monthsago(1)
return '[' .. StatsGrokSeURL(when.year, when.month, 'da') .. ' stat]'
end
----------------------------------------------------------------------------------------------
-- LINK FUNCTIONS END --
-- To enable new link functions, add the code to the "linktypes" table directly below. --
----------------------------------------------------------------------------------------------
local linktypes = {
{'t' , makeTalkLink},
{'wlh' , makeWhatLinksHereLink},
{'rc' , makeRelatedChangesLink},
{'edit', makeEditLink},
{'h' , makeHistoryLink},
{'w' , makeWatchLink},
{'tl' , makeTargetLogsLink},
{'efl' , makeEditFilterLogLink},
{'vlm-sgs' , makeViewsLastMonthStatsGrokSeLink},
}
local function getLink(linktype)
local linkNumber
for i, value in ipairs(linktypes) do
if value[1] == linktype then
linkNumber = i
break
end
end
if not linkNumber then
return err('"' .. linktype .. '" is not a valid link code', 'Ikke en gyldig link kode')
end
local result = linktypes[linkNumber][2]()
if type(result) ~= 'string' then
return err(
'the function for code "' .. linktype .. '" did not return a string value',
'Function did not return a string value'
)
end
return result
end
local function makeToolbar(args)
local targs = {}
local numArgsExist = false
for k, v in pairs(args) do
if type(k) == 'number' and p then
numArgsExist = true
targs[k] = getLink(v)
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
else
return ToolbarBuilder.main(targs)
end
end
local function generatePageDataStrings(args)
-- 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('siden ikke fundet')
end
end
local function generateTrackingCategories()
if demo == 'yes' then
return ''
else
return table.concat(trackingCategories)
end
end
-- This function generates a table of all available link types, with their previews.
-- 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 result = '<table class="wikitable plainlinks sortable">'
.. '\n<tr><th>Code</th><th>Preview</th></tr>'
for i, value in ipairs(linktypes) do
local code = value[1]
result = result .. "\n<tr><td>'''" .. code .. "'''</td><td>" .. getLink(code) .. '</td></tr>'
end
result = result .. '\n</table>'
return result
end
local function getSingleLink(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
local linktype = args[1]
if not linktype then
return err('no link type specified')
end
local result = getLink(linktype)
result = result .. generateTrackingCategories()
return result
end
local function getLinksToolbar(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 the template output.
local result = makeToolbar(args) -- Get the toolbar contents.
result = (result or '') .. generateTrackingCategories()
return result
end
local function getLinks(args)
local result = getLinksToolbar(args)
if result then
if args.sup then
result = '<sup>' .. result .. '</sup>'
end
result = ' ' .. result
else
result = '' -- If there are no links specified, don't return the toolbar at all.
end
if args.nopage then
result = '<span>' .. result .. '</span>'
else
if p then
result = '<span>' .. makePageLink() .. result .. '</span>'
else
result = '<span>[[' .. args.page .. ']]' .. result .. '</span>'
end
end
return result
end
local function getExampleLinks(args)
-- This function enables example output without having to specify any
-- parameters to #invoke.
args.demo = 'yes'
args.page = 'Example'
return getLinks(args)
end
local function makeWrapper(func)
return function (frame)
-- If called via #invoke, use the args passed into the invoking template.
-- Otherwise, for testing purposes, assume args are being passed directly in.
local origArgs
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
for k, v in pairs(frame.args) do
origArgs = frame.args
break
end
else
origArgs = frame
end
-- Strip whitespace, and treat blank arguments as nil.
-- 'page', and 'separator' have different behaviour depending on
-- whether they are blank or nil, so keep them as they are.
local args = {}
for k, v in pairs(origArgs) do
v = mw.text.trim(v)
if v ~= '' or k == 'page' or k == 'separator' then
args[k] = v
end
end
return func(args)
end
end
return {
main = makeWrapper(getLinks),
single = makeWrapper(getSingleLink),
toolbar = makeWrapper(getLinksToolbar),
linktable = makeWrapper(getLinkTable),
example = makeWrapper(getExampleLinks)
}
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve









