편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.
최신판 | 당신의 편집 | ||
22번째 줄: | 22번째 줄: | ||
case-insensitive; they are not "SupportedLanguages" for MediaWiki, so | case-insensitive; they are not "SupportedLanguages" for MediaWiki, so | ||
they are not "KnownLanguageTags" for MediaWiki). | they are not "KnownLanguageTags" for MediaWiki). | ||
To be more restrictive, we exclude any character | To be more restrictive, we exclude any character that is not | ||
ASCII and not a lowercase letter, minus-hyphen, or digit, and any code | |||
that does not start by a letter or does not finish by a letter or digit. | |||
of that has more than 8 characters between hyphens, or has two hyphens. | |||
--]] | --]] | ||
or string.find(subpage, "^[%l][%-%d%l]*[%d%l]$") ~= nil | or string.find(subpage, "^[%l][%-%d%l]*[%d%l]$") ~= nil | ||
and string.find(subpage, "[%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l]") == nil | and string.find(subpage, "[%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l][%d%l]") == nil | ||
and string.find(subpage, "%-%-") == nil | and string.find(subpage, "%-%-") == nil | ||
then | then | ||
return subpage | return subpage | ||
50번째 줄: | 37번째 줄: | ||
end | end | ||
--[[Get the last subpage of | --[[Get the last subpage of the current page if it is a translation. | ||
]] | ]] | ||
function this. | function this.getLanguageSubpage() | ||
--[[This code does not work ib all namespaces where the Translate tool works. | |||
--[[This code does not work | |||
-- It works in the main namespace on Meta because it allows subpages there | -- It works in the main namespace on Meta because it allows subpages there | ||
-- It would not work in the main namespace of English Wikipedia (but the | -- It would not work in the main namespace of English Wikipedia (but the | ||
84번째 줄: | 52번째 줄: | ||
-- bug of Meta-Wiki. The work-around is to split the full title and then | -- bug of Meta-Wiki. The work-around is to split the full title and then | ||
-- get the last titlepart. | -- get the last titlepart. | ||
local subpage = title.subpageText | local subpage = mw.title.getCurrentTitle().subpageText | ||
--]] | --]] | ||
local titleparts = mw.text.split(mw.title.getCurrentTitle().fullText, '/') | |||
local subpage = titleparts[#titleparts] | |||
return this.checkLanguage(subpage, '') | |||
end | end | ||
108번째 줄: | 63번째 줄: | ||
]] | ]] | ||
function this.getFrameLanguageSubpage(frame) | function this.getFrameLanguageSubpage(frame) | ||
local titleparts = mw.text.split(frame:getParent():getTitle(), '/') | |||
local subpage = titleparts[#titleparts] | |||
return this.checkLanguage(subpage, '') | |||
end | end | ||
171번째 줄: | 128번째 줄: | ||
]] | ]] | ||
local title | local title | ||
local namespace = args[' | local namespace = args['namespace'] or '' | ||
if (namespace ~= '') -- Checks for | if (namespace ~= '') -- Checks for namespace parameter for custom ns. | ||
then | then | ||
title = this.title(namespace, pagename) -- Costly | title = this.title(namespace, pagename) -- Costly | ||
189번째 줄: | 146번째 줄: | ||
if (subpage == '') | if (subpage == '') | ||
then | then | ||
subpage = this. | subpage = this.getLanguageSubpage() | ||
end | end | ||
if (subpage == '') | if (subpage == '') | ||
248번째 줄: | 205번째 줄: | ||
-- Copy args pseudo-table to a proper table so we can feed it to expandTemplate. | -- Copy args pseudo-table to a proper table so we can feed it to expandTemplate. | ||
-- Then render the pagename. | -- Then render the pagename. | ||
local pargs = (frame:getParent() or {}).args | local pargs = (frame:getParent() or {}).args | ||
local arguments = {} | local arguments = {} | ||
273번째 줄: | 229번째 줄: | ||
end | end | ||
arguments['template'] = title -- override the existing parameter of the base template name supplied with the full name of the actual template expanded | arguments['template'] = title -- override the existing parameter of the base template name supplied with the full name of the actual template expanded | ||
arguments[' | arguments['namespace'] = nil -- discard the specified namespace override | ||
arguments['uselang'] = args['uselang'] -- argument forwarded into parent frame | arguments['uselang'] = args['uselang'] -- argument forwarded into parent frame | ||
arguments['noshift'] = args['noshift'] -- argument forwarded into parent frame | arguments['noshift'] = args['noshift'] -- argument forwarded into parent frame | ||
return frame:expandTemplate{title = ':' .. title, args = arguments} | return frame:expandTemplate{title = ':' .. title, args = arguments} | ||
end | end | ||
return this | return this |