Module:pages: Difference between revisions
No edit summary |
support different splits for different mammoth pages |
||
| Line 285: | Line 285: | ||
end | end | ||
local ns = title.namespace | local ns = title.namespace | ||
-- (main), | -- (main), Appendix, Thesaurus, Citations, Reconstruction. | ||
return (ns == 0 or ns == | return (ns == 0 or ns == 100 or ns == 110 or ns == 114 or ns == 118) and | ||
title.contentModel == "wikitext" | title.contentModel == "wikitext" | ||
end | end | ||
| Line 413: | Line 413: | ||
return content | return content | ||
end | end | ||
end | |||
--[==[ | |||
Convert a physical pagename (or the current pagename, if {nil} is passed in) to its logical equivalent, but only if | |||
the physical pagename refers to one of the splits of a mammoth page such as [[a]]. Otherwise this simply returns the | |||
subpage (the part after the last slash in namespace other than the main one, otherwise the same as passed in), unless | |||
`include_base` is specified, in which case the return value will be the whole pagename minus the namespace, including | |||
the base (the part before the final slash). | |||
FIXME: This should be augmented with logic to handle unsupported titles, which is currently in process_page() in | |||
[[Module:headword/page]], so that it is a general physical-to-logical conversion function. | |||
Examples: | |||
* {physical_to_logical_pagename_if_mammoth("a")} → {"a"} | |||
* {physical_to_logical_pagename_if_mammoth("a/languages A to L")} → {"a"} (since [[a]] is marked as a mammoth page in [[Module:links/data]]) | |||
* {physical_to_logical_pagename_if_mammoth("50/50")} → {"50/50"} (since [[50/50]] is in the main namespace) | |||
* {physical_to_logical_pagename_if_mammoth("Appendix:Lojban/a")} → "a" | |||
* {physical_to_logical_pagename_if_mammoth("Appendix:Lojban/a", true)} → "Lojban/a" | |||
* {physical_to_logical_pagename_if_mammoth("Reconstruction:Proto-Slavic/a")} → "a" | |||
* {physical_to_logical_pagename_if_mammoth("Reconstruction:Proto-Slavic/a", true)} → "Proto-Slavic/a" | |||
* {physical_to_logical_pagename_if_mammoth("User:Example/sandbox/foo")} → "foo" | |||
* {physical_to_logical_pagename_if_mammoth("User:Example/sandbox/foo", true)} → "Example/sandbox/foo" | |||
]==] | |||
function export.physical_to_logical_pagename_if_mammoth(title, include_base) | |||
if title == nil then | |||
title = mw.title.getCurrentTitle() | |||
elseif not is_title(title) then | |||
title = mw.title.new(title) | |||
end | |||
if title.nsText == "" then | |||
-- Formerly we checked for the specific known subpages of a given mammoth split page, e.g. we would convert | |||
-- [[a/languages M to Z]] to [[a]] assuming that [[a/languages M to Z]] was one of the splits, but not | |||
-- [[a/languages N to Z]]. To simplify this, we just convert anything with the right mammoth split page format | |||
-- on the assumption that it's unlikely we will ever have a legitimate non-mammoth-split pagename of this sort. | |||
local pagename = title.text | |||
local mammoth_root_page = pagename:match("^(.*)/languages [A-Z] to [A-Z]$") | |||
if mammoth_root_page then | |||
pagename = mammoth_root_page | |||
end | |||
return pagename | |||
elseif include_base then | |||
return title.text | |||
else | |||
return title.subpageText | |||
end | |||
end | |||
--[==[ | |||
Obsolete name for `physical_to_logical_pagename_if_mammoth`. FIXME: Replace all uses and remove. | |||
]==] | |||
function export.safe_page_name(title) | |||
return export.physical_to_logical_pagename_if_mammoth(title) | |||
end | end | ||
| Line 456: | Line 509: | ||
do | do | ||
local L2_sections | local L2_sections, current_L2 | ||
local function get_L2_sections() | local function get_L2_sections() | ||
| Line 466: | Line 519: | ||
A function which returns the name of the L2 language section which contains the current {#invoke}.]==] | A function which returns the name of the L2 language section which contains the current {#invoke}.]==] | ||
function export.get_current_L2() | function export.get_current_L2() | ||
if current_L2 ~= nil then | |||
return current_L2 or nil -- Return nil if current_L2 is false (i.e. there's no L2). | |||
end | |||
local section = get_current_section() | local section = get_current_section() | ||
while section > 0 do | while section > 0 do | ||
local L2 = (L2_sections or get_L2_sections())[section] | local L2 = (L2_sections or get_L2_sections())[section] | ||
if L2 then | if L2 then | ||
current_L2 = L2 | |||
return L2 | return L2 | ||
end | end | ||
section = section - 1 | section = section - 1 | ||
end | end | ||
current_L2 = false | |||
return nil | |||
end | end | ||
end | end | ||
return export | return export | ||