Shin'etsu Main Line

Shin'etsu Main Line

Shinetsu Main Line
Map Legend
Red: Shinetsu Main Line
Blue: Shinano Railway Line, Kita-Shinano Line and Myōkō Haneuma Line
Overview
Native name 信越本線
Status Operarional
Locale Gunma, Nagano, Niigata prefectures
Operation
Opened Stages between 1885-1904
Closed Yokokawa - Karuizawa: 1 October 1997
Karuizawa - Shinonoi: 1 October 1997 (Converted to the Shinano Railway Line)
Nagano - Naoetsu: 14 March 2015 (Converted to the Shinano Railway Kita-Shinano Line and the Echigo Tokimeki Railway Myōkō Haneuma Line)
Operator(s) JR East
Technical
Line length 181.5 km (112.8 mi)
Track gauge 1,067 mm (3 ft 6 in)
Electrification 1,500 V DC overhead catenary
Route map

1. Takasaki - Yokokawa

Jōetsu Shinkansen, Takasaki Line
Jōshin Dentetsu Jōshin Line
0.0 Takasaki
Jōetsu Line
Former Tobu Takasaki Line
2.4 Kita-Takasaki
Jōetsu Shinkansen
Hokuriku Shinkansen
6.4 Gumma-Yawata
10.6 Annaka
17.6 Isobe
22.7 Matsuida Since 1962
Matsuida Until 1962
23.9 Nishi-Matsuida
29.7 Yokokawa
Usui Horsecar
31.5 Maruyama (Signal Box) Until 1966
35.8 Kumanotaira (Signal Box) Until 1997
40.1 Yagasaki (Signal Box) Until 1966
Former Kusakaru Dentetsu
40.9 Karuizawa
Hokuriku Shinkansen, Shinano Railway Line

2. Sinonoi-Nagano

Hokuriku Shinkansen, Shinano Railway Line
Shinonoi Line
0.0 Shinonoi
2.1 Imai
4.3 Kawanakajima
5.9 Saigawa (Signal Box) Until 1935
Saigawa
6.4 Amori
Zenkōji Hakuba Dentetsu
Former South Nagano Line
9.3 Nagano
Nagano Electric Railway
Hokuriku Shinkansen,
Shinano Railway Kita-Shinano Line

3. Naoetsu-Niigata

ETR-Myōkō Haneuma Line
ETR-Nihonkai Hisui Line
0.0 Naoetsu Since 1899
0.2 Naoetsu Until 1899
1.4 Naoetsu Port Until 1959
Sekigawa
0.8 Kasuga Shinden Until 1906
2.7 Kuroi
Kubiki Railway Line
7.1 Saigata
Hokuetsu Express Hokuhoku Line
9.4 Dosokohama
11.2 Katamachi
14.0 Jogehama
17.6 Kakizaki
21.2 Takehana (Signal Box) Until 1973
23.5 Yoneyama
27.4 Kasashima
29.6 Oumigawa
32.6 Kujiranami
36.3 Kashiwazaki
Echigo Line
39.3 Ibarame
42.2 Yasuda
44.8 Kitajo
48.1 Echigo-Hirota
50.8 Nagatori
Tsukayama Tunnel
53.9 Nishi-Tsukayama (Signal Box) Until 1967
55.8 Tsukayama
Nishi-Shibuumikawa Until 1900
Higashi-Shibuumikawa Until 1900
60.5 Echigo-Iwatsuka
Former Echigo Kotsu Nagaoka Line
63.3 Raikōji
Shinano River
67.4 Maekawa
Jōetsu Line
70.0 Miyauchi
71.4 Minami-Nagaoka Freight Terminal
Jōetsu Shinkansen
73.0 Nagaoka
75.5 Kita-Nagaoka
79.9 Oshikiri
82.0 Kariyada (Signal Box) Until 1945
84.4 Mitsuke
88.5 Obiori
91.1 Tōkōji
94.6 Sanjō
Yahiko Line
96.2 Higashi-Sanjō
Former Yahiko Line
100.0 Honai
103.8 Kamo
Kanbara Railway Line
107.9 Hanyūda
111.1 Tagami
114.8 Yashiroda
117.9 Furutsu
Banetsu West Line
121.1 Niitsu
Uetsu Main Line
122.6 Satsukino
124.9 Ogikawa
129.8 Kameda
132.2
0.0##
Echigo-Ishiyama
Hakushin Line
Higashi-Niigata
2.4## Niigata Freight Terminal
134.4
0.0#
Kami-Nuttari (Signal Box)
2.1# Yakejima
3.8# East Niigata Port
5.5# Ōgata Until 1941
136.2
0.0**
Nuttari Until 2010
1.4** Niigata Port Until 1986
136.3
1.9#
Niigata Since 1958
138.1 Niigata Until 1958
4.3# Bandai Until 1965
Jōetsu Shinkansen
Echigo Line

The Shinetsu Main Line (信越本線 Shin'etsu-honsen) is a railway line, consisting of three geographically separated sections, operated by the East Japan Railway Company (JR East) in Japan. Originally one continuous line, the first section (29.7 km) connects Takasaki Station to Yokokawa Station in Gunma Prefecture, the second section (9.3 km) connects Shinonoi Station to Nagano Station in Nagano Prefecture and the third section (136.3 km) connects Naoetsu Station to Niigata Station in Niigata Prefecture. Additionally, there are three freight branches; from Echigo-Ishiyama Station to Niigata Freight Terminal, from Kami-Nuttari Junction to Nuttari Station, and from Kami-Nuttari Junction to Higashi-Niigata-kō Station. The name of the line refers to the old names for Nagano and Niigata Prefectures, Shinano (信濃) and Echigo (越後).

The original line was separated into two sections as a result of the abandonment of the section between Yokokawa and Karuizawa and the reassignment of operations over the section between Karuizawa and Shinonoi to the third-sector Shinano Railway, both occurring on October 1, 1997 in conjunction with the opening of the Nagano Shinkansen between Takasaki and Nagano stations. The abandoned section through the Usui Pass was famous for its steep 66.7 gradient.[1]

When the Hokuriku Shinkansen extension to Kanazawa opened on 14 March 2015, the portion of the Shinetsu Main Line between Nagano and Naoetsu was also spun off to two third-sector railway operators, the Shinano Railway in Nagano Prefecture, and the Echigo Tokimeki Railway in Niigata Prefecture. This resulted in the present status of the line with three separate sections.[2]

Contents

  • Stations 1
    • Takasaki–Yokokawa 1.1
    • Yokokawa–Shinonoi 1.2
    • Shinonoi–Nagano 1.3
    • Nagano–Naoetsu 1.4
    • Naoetsu–Niigata 1.5
  • History 2
    • Double-tracking 2.1
    • Electrification 2.2
    • Separation into sections 2.3
    • Former connecting lines 2.4
  • References 3

Stations

Takasaki–Yokokawa

Station Distance
(km)
Connections Location
Takasaki 0.0 Joetsu Shinkansen, Hokuriku Shinkansen, Takasaki Line, Hachikō Line, Jōetsu Line, Ryōmō Line
Joshin Dentetsu Joshin Line
Takasaki Gunma Prefecture
Kita-Takasaki 2.4  
Gumma-Yawata 6.4  
Annaka 10.6   Annaka
Isobe 17.6  
Matsuida 22.7  
Nishi-Matsuida 23.9  
Yokokawa 29.7  

Yokokawa–Shinonoi

The section between Yokokawa and Karuizawa was closed and the section between Karuizawa and Shinonoi was transferred to the ownership of the third-sector railway operator Shinano Railway from 1 October 1997 with the opening of the Hokuriku Shinkansen (Nagano Shinkansen) between Takasaki and Nagano.

Shinonoi–Nagano

Station Distance
(km)
Connections Location
Shinonoi 0.0 Shinonoi Line,
Shinano Railway Line
Nagano Nagano Prefecture
Imai 2.1  
Kawanakajima 4.3  
Amori 6.4  
Nagano 9.3 Hokuriku Shinkansen
Shinano Railway Kita-Shinano Line
Nagano Electric Railway

Nagano–Naoetsu

The section between Nagano and Naoetsu was transferred to the ownership of the third-sector railway operators Shinano Railway and Echigo Tokimeki Railway from 14 March 2015 with the opening of the Hokuriku Shinkansen extension north of Nagano.

Naoetsu–Niigata

Station Distance
(km)
Connections Location
Naoetsu 84.3 Echigo Tokimeki Railway Myōkō Haneuma Line
Echigo Tokimeki Railway Nihonkai Hisui Line
Jōetsu Niigata Prefecture
Kuroi 87.0  
Saigata 91.4 Hokuhoku Line
Dosokohama 93.7  
Katamachi 95.5  
Jōgehama 98.3  
Kakizaki 101.9  
Yoneyama 107.8   Kashiwazaki
Kasashima 111.7  
Ōmigawa 113.9  
Kujiranami 116.9  
Kashiwazaki 120.6 Echigo Line
Ibarame 123.6  
Yasuda 126.5  
Kitajō 129.1  
Echigo-Hirota 132.4  
Nagatori 135.1  
Tsukayama 140.1   Nagaoka
Echigo-Iwatsuka 144.8  
Raikōji 147.6  
Maekawa 151.7  
Miyauchi 154.3 Jōetsu Line
Minami-Nagaoka Freight Terminal 155.7  
Nagaoka 157.3 Jōetsu Shinkansen
Kita-Nagaoka 159.8  
Oshikiri 164.2  
Mitsuke 168.7   Mitsuke
Obiori 172.8   Sanjō
Tōkōji 175.4  
Sanjō 178.9  
Higashi-Sanjō 180.5 Yahiko Line
Honai 184.3  
Kamo 188.1   Kamo
Hanyūda 192.2   Tagami
Tagami 195.4  
Yashiroda 199.1   Akiha-ku, Niigata
Furutsu 202.2  
Niitsu 205.4 Uetsu Main Line, Banetsu West Line
Satsukino 206.9  
Ogikawa 209.2  
Kameda 214.1   Kōnan-ku, Niigata
Echigo-Ishiyama 216.5   Higashi-ku, Niigata
Kaminuttari Junction (218.7)   Chūō-ku, Niigata
Niigata 220.6 Jōetsu Shinkansen, Hakushin Line, Echigo Line

History

Abt rack railway loco used on the Usui Pass line, note the 'shoe' ahead of the nearest wheel to collect power via a third rail

The Japanese Government Railways opened the Takasaki to Yokokawa section in 1885, the Naoetsu to Sekiyama section the following year, and the Sekiyama - Nagano - Karuizawa section in 1888. In order to surmount the 552 metre altitude difference between Yokokawa and Karuizawa (which are 10 km apart), it then constructed an Abt rack section through the Usui Pass, which opened in 1893, and was double-tracked for 1 km from Karuizawa to the top of the rack section. A horse-drawn tramway operated between Yokokawa and Karuizawa until the rack section opened.

The Hokuetsu Railway opened the Naoetsu to Nagaoka section in 1897, extending the line to Niigata in 1904. Both companies were nationalised in 1907. In 1912, the rack section was electrified using third rail at 600 V DC, this being the first use of this method in Japan.require('Module:No globals')

local p = {}

-- articles in which traditional Chinese preceeds simplified Chinese local t1st = { ["228 Incident"] = true, ["Chinese calendar"] = true, ["Lippo Centre, Hong Kong"] = true, ["Republic of China"] = true, ["Republic of China at the 1924 Summer Olympics"] = true, ["Taiwan"] = true, ["Taiwan (island)"] = true, ["Taiwan Province"] = true, ["Wei Boyang"] = true, }

-- the labels for each part local labels = { ["c"] = "Chinese", ["s"] = "simplified Chinese", ["t"] = "traditional Chinese", ["p"] = "pinyin", ["tp"] = "Tongyong Pinyin", ["w"] = "Wade–Giles", ["j"] = "Jyutping", ["cy"] = "Cantonese Yale", ["poj"] = "Pe̍h-ōe-jī", ["zhu"] = "Zhuyin Fuhao", ["l"] = "literally", }

-- article titles for wikilinks for each part local wlinks = { ["c"] = "Chinese language", ["s"] = "simplified Chinese characters", ["t"] = "traditional Chinese characters", ["p"] = "pinyin", ["tp"] = "Tongyong Pinyin", ["w"] = "Wade–Giles", ["j"] = "Jyutping", ["cy"] = "Yale romanization of Cantonese", ["poj"] = "Pe̍h-ōe-jī", ["zhu"] = "Bopomofo", }

-- for those parts which are to be treated as languages their ISO code local ISOlang = { ["c"] = "zh", ["t"] = "zh-Hant", ["s"] = "zh-Hans", ["p"] = "zh-Latn-pinyin", ["tp"] = "zh-Latn", ["w"] = "zh-Latn-wadegile", ["j"] = "yue-jyutping", ["cy"] = "yue", ["poj"] = "hak", ["zhu"] = "zh-Bopo", }

local italic = { ["p"] = true, ["tp"] = true, ["w"] = true, ["j"] = true, ["cy"] = true, ["poj"] = true, } -- Categories for different kinds of Chinese text local cats = { ["c"] = "", ["s"] = "", ["t"] = "", }

function p.Zh(frame) -- load arguments module to simplify handling of args local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame) return p._Zh(args) end function p._Zh(args) local uselinks = not (args["links"] == "no") -- whether to add links local uselabels = not (args["labels"] == "no") -- whether to have labels local capfirst = args["scase"] ~= nil

        local t1 = false -- whether traditional Chinese characters go first
        local j1 = false -- whether Cantonese Romanisations go first
        local testChar
        if (args["first"]) then
                 for testChar in mw.ustring.gmatch(args["first"], "%a+") do
          if (testChar == "t") then
           t1 = true
           end
          if (testChar == "j") then
           j1 = true
           end
         end
        end
        if (t1 == false) then
         local title = mw.title.getCurrentTitle()
         t1 = t1st[title.text] == true
        end

-- based on setting/preference specify order local orderlist = {"c", "s", "t", "p", "tp", "w", "j", "cy", "poj", "zhu", "l"} if (t1) then orderlist[2] = "t" orderlist[3] = "s" end if (j1) then orderlist[4] = "j" orderlist[5] = "cy" orderlist[6] = "p" orderlist[7] = "tp" orderlist[8] = "w" end -- rename rules. Rules to change parameters and labels based on other parameters if args["hp"] then -- hp an alias for p ([hanyu] pinyin) args["p"] = args["hp"] end if args["tp"] then -- if also Tongyu pinyin use full name for Hanyu pinyin labels["p"] = "Hanyu Pinyin" end if (args["s"] and args["s"] == args["t"]) then -- Treat simplified + traditional as Chinese if they're the same args["c"] = args["s"] args["s"] = nil args["t"] = nil elseif (not (args["s"] and args["t"])) then -- use short label if only one of simplified and traditional labels["s"] = labels["c"] labels["t"] = labels["c"] end local body = "" -- the output string local params -- for creating HTML spans local label -- the label, i.e. the bit preceeding the supplied text local val -- the supplied text -- go through all possible fields in loop, adding them to the output for i, part in ipairs(orderlist) do if (args[part]) then -- build label label = "" if (uselabels) then label = labels[part] if (capfirst) then label = mw.language.getContentLanguage():ucfirst(

Double-tracking

The Karuizawa to Nagano section was double-tracked between 1917 and 1920, with the Nagaoka to Miyauchi section double-tracked in 1931, and the Niitsu - Kamo section in 1944. Double-tracking of the remainder of the Niigata to Naoetsu line was undertaken in sections between 1958 and 1973.

Double-tracking of the remainder of the Takasaki to Kaminagano line was undertaken in sections between 1963 and 1973, commencing with the replacement of the rack mechanism with an adhesion only electrified (1,500 V DC catenary) operation on the 1 in 15 (6.7%) grade. The rack equipment was initially kept as a contingency, and removed two months after the adhesion-only operation commenced and had proved its reliability.

The Kurohime to Myoko-Kogen section was double-tracked in conjunction with a realignment in 1980. The Mure to Kurohime section was also realigned and prepared for double-tracking (including new double-track size tunnels), but the second track was not laid.

Electrification

The Miyauchi to Nagaoka section was electrified in 1947 at 1,500 V DC in conjunction with the electrification of the Joetsu Line, with the Nagaoka to Niigata section electrified in 1962, the same year the Takasaki to Yokokawa section was commissioned to facilitate the extension to Nagano the following year via the new adhesion line through the Usui Pass mentioned above. The Nagano to Naoetsu section was electrified in 1966, and extended to Miyauchi in 1969.

Separation into sections

In 1997, following the opening of the Nagano Shinkansen, the Yokokawa to Karuizawa section was closed, and the Karuizawa to Shinonoi section transferred to the third-sector Shinano Railway.

The Shinetsu Main Line ran roughly parallel to the route of the Hokuriku Shinkansen extension from Nagano to Kanazawa which opened on 14 March 2015. With the opening of the Hokuriku Shinkansen, control of local passenger services on the sections of the Shinetsu Main Line running through Nagano and Niigata prefectures was transferred to the following two third-sector operating companies owned primarily by the respective prefectures and municipalities.[2]

Former connecting lines

The Kubiki Railway prior to 1940
A train on the Uomuna line in 1937, prior to its conversion to 1,067 mm gauge

(Note - for the connections at stations between Karuizawa and Shinonoi, see Shinano Railway Line)

  • Nagano Station: The Zenkoji Hakuba Railway Co. opened a 7 km line to Susohana Guchi in 1936. A proposal for the line to be extended to Hakuba on the Oito Line did not eventuate, and the line closed in 1944.
  • Kuroi Station: The Kubiki Railway Co. opened a 15 km 762 mm (2 ft 6 in) gauge line to Uragawara between 1914 and 1916, with the line closing in 1971.
  • Raikoji Station: The Nagaoka Railway Co. opened a 39 km line to Teradomari (on the Echigo Line) between 1915 and 1921. This company introduced Japan's first diesel railcar in 1928, and in 1951 electrified 31 km of the line at 750 V DC in 70 days, completing the balance the following year. Significant typhoon damage occurred in 1966, and in 1972, passenger services ceased between Raikoji and Nishinagaoka, with the entire line becoming freight-only three years later. The line closed in 1995.
The 13 km 762 mm (2 ft 6 in) gauge Uonuma Railway to Nishiojiya was opened in 1911, and nationalised in 1922. It was converted to 1,067 mm (3 ft 6 in) gauge in 1954, freight services ceased in 1960, and the line closed in 1984.
  • Nagaoka Station: The Tochio Railway opened a 27 km 762 mm (2 ft 6 in) gauge line to Tochio and Yūkyūzan between 1915 and 1924.[3] The line was electrified at 600 V DC in 1948, with this being raised to 750 V DC in 1956. CTC signalling was commissioned in 1961, freight services ceased in 1967, and the line closed between 1973 and 1975.
  • Higashi Sanjo Station: The Echigo Railway Co. opened the 8 km line to Echigo Nagasawa in 1927, and was nationalised two months later. Freight services ceased in 1960, and the line closed in 1985.
  • Kamo Station: The Kanbara Railway Co. operated a line to Gosen on the Ban'etsu West Line from 1923 until 2002.

References

This article incorporates material from the corresponding article in the Japanese WorldHeritage.


-- Module:Hatnote -- -- -- -- This module produces hatnote links and links to related articles. It -- -- implements the and meta-templates and includes -- -- helper functions for other Lua hatnote modules. --


local libraryUtil = require('libraryUtil') local checkType = libraryUtil.checkType local mArguments -- lazily initialise Module:Arguments local yesno -- lazily initialise Module:Yesno

local p = {}


-- Helper functions


local function getArgs(frame) -- Fetches the arguments from the parent frame. Whitespace is trimmed and -- blanks are removed. mArguments = require('Module:Arguments') return mArguments.getArgs(frame, {parentOnly = true}) end

local function removeInitialColon(s) -- Removes the initial colon from a string, if present. return s:match('^:?(.*)') end

function p.findNamespaceId(link, removeColon) -- Finds the namespace id (namespace number) of a link or a pagename. This -- function will not work if the link is enclosed in double brackets. Colons -- are trimmed from the start of the link by default. To skip colon -- trimming, set the removeColon parameter to true. checkType('findNamespaceId', 1, link, 'string') checkType('findNamespaceId', 2, removeColon, 'boolean', true) if removeColon ~= false then link = removeInitialColon(link) end local namespace = link:match('^(.-):') if namespace then local nsTable = mw.site.namespaces[namespace] if nsTable then return nsTable.id end end return 0 end

function p.formatPages(...) -- Formats a list of pages using formatLink and returns it as an array. Nil -- values are not allowed. local pages = {...} local ret = {} for i, page in ipairs(pages) do ret[i] = p._formatLink(page) end return ret end

function p.formatPageTables(...) -- Takes a list of page/display tables and returns it as a list of -- formatted links. Nil values are not allowed. local pages = {...} local links = {} for i, t in ipairs(pages) do checkType('formatPageTables', i, t, 'table') local link = t[1] local display = t[2] links[i] = p._formatLink(link, display) end return links end

function p.makeWikitextError(msg, helpLink, addTrackingCategory) -- Formats an error message to be returned to wikitext. If -- addTrackingCategory is not false after being returned from -- Module:Yesno, and if we are not on a talk page, a tracking category -- is added. checkType('makeWikitextError', 1, msg, 'string') checkType('makeWikitextError', 2, helpLink, 'string', true) yesno = require('Module:Yesno') local title = mw.title.getCurrentTitle() -- Make the help link text. local helpText if helpLink then helpText = ' (help)' else helpText = end -- Make the category text. local category if not title.isTalkPage and yesno(addTrackingCategory) ~= false then category = 'Hatnote templates with errors' category = string.format( '%s:%s', mw.site.namespaces[14].name, category ) else category = end return string.format( '%s', msg, helpText, category ) end


-- Format link -- -- Makes a wikilink from the given link and display values. Links are escaped -- with colons if necessary, and links to sections are detected and displayed -- with " § " as a separator rather than the standard MediaWiki "#". Used in -- the template.


function p.formatLink(frame) local args = getArgs(frame) local link = args[1] local display = args[2] if not link then return p.makeWikitextError( 'no link specified', 'Template:Format hatnote link#Errors', args.category ) end return p._formatLink(link, display) end

function p._formatLink(link, display) -- Find whether we need to use the colon trick or not. We need to use the -- colon trick for categories and files, as otherwise category links -- categorise the page and file links display the file. checkType('_formatLink', 1, link, 'string') checkType('_formatLink', 2, display, 'string', true) link = removeInitialColon(link) local namespace = p.findNamespaceId(link, false) local colon if namespace == 6 or namespace == 14 then colon = ':' else colon = end -- Find whether a faux display value has been added with the | magic -- word. if not display then local prePipe, postPipe = link:match('^(.-)|(.*)$') link = prePipe or link display = postPipe end -- Find the display value. if not display then local page, section = link:match('^(.-)#(.*)$') if page then display = page .. ' § ' .. section end end -- Assemble the link. if display then return string.format('%s', colon, link, display) else return string.format('%s%s', colon, link) end end


-- Hatnote -- -- Produces standard hatnote text. Implements the template.


function p.hatnote(frame) local args = getArgs(frame) local s = args[1] local options = {} if not s then return p.makeWikitextError( 'no text specified', 'Template:Hatnote#Errors', args.category ) end options.extraclasses = args.extraclasses options.selfref = args.selfref return p._hatnote(s, options) end

function p._hatnote(s, options) checkType('_hatnote', 1, s, 'string') checkType('_hatnote', 2, options, 'table', true) local classes = {'hatnote'} local extraclasses = options.extraclasses local selfref = options.selfref if type(extraclasses) == 'string' then classes[#classes + 1] = extraclasses end if selfref then classes[#classes + 1] = 'selfref' end return string.format( '
%s
', table.concat(classes, ' '), s )

end

return p-------------------------------------------------------------------------------- -- Module:Hatnote -- -- -- -- This module produces hatnote links and links to related articles. It -- -- implements the and meta-templates and includes -- -- helper functions for other Lua hatnote modules. --


local libraryUtil = require('libraryUtil') local checkType = libraryUtil.checkType local mArguments -- lazily initialise Module:Arguments local yesno -- lazily initialise Module:Yesno

local p = {}


-- Helper functions


local function getArgs(frame) -- Fetches the arguments from the parent frame. Whitespace is trimmed and -- blanks are removed. mArguments = require('Module:Arguments') return mArguments.getArgs(frame, {parentOnly = true}) end

local function removeInitialColon(s) -- Removes the initial colon from a string, if present. return s:match('^:?(.*)') end

function p.findNamespaceId(link, removeColon) -- Finds the namespace id (namespace number) of a link or a pagename. This -- function will not work if the link is enclosed in double brackets. Colons -- are trimmed from the start of the link by default. To skip colon -- trimming, set the removeColon parameter to true. checkType('findNamespaceId', 1, link, 'string') checkType('findNamespaceId', 2, removeColon, 'boolean', true) if removeColon ~= false then link = removeInitialColon(link) end local namespace = link:match('^(.-):') if namespace then local nsTable = mw.site.namespaces[namespace] if nsTable then return nsTable.id end end return 0 end

function p.formatPages(...) -- Formats a list of pages using formatLink and returns it as an array. Nil -- values are not allowed. local pages = {...} local ret = {} for i, page in ipairs(pages) do ret[i] = p._formatLink(page) end return ret end

function p.formatPageTables(...) -- Takes a list of page/display tables and returns it as a list of -- formatted links. Nil values are not allowed. local pages = {...} local links = {} for i, t in ipairs(pages) do checkType('formatPageTables', i, t, 'table') local link = t[1] local display = t[2] links[i] = p._formatLink(link, display) end return links end

function p.makeWikitextError(msg, helpLink, addTrackingCategory) -- Formats an error message to be returned to wikitext. If -- addTrackingCategory is not false after being returned from -- Module:Yesno, and if we are not on a talk page, a tracking category -- is added. checkType('makeWikitextError', 1, msg, 'string') checkType('makeWikitextError', 2, helpLink, 'string', true) yesno = require('Module:Yesno') local title = mw.title.getCurrentTitle() -- Make the help link text. local helpText if helpLink then helpText = ' (help)' else helpText = end -- Make the category text. local category if not title.isTalkPage and yesno(addTrackingCategory) ~= false then category = 'Hatnote templates with errors' category = string.format( '%s:%s', mw.site.namespaces[14].name, category ) else category = end return string.format( '%s', msg, helpText, category ) end


-- Format link -- -- Makes a wikilink from the given link and display values. Links are escaped -- with colons if necessary, and links to sections are detected and displayed -- with " § " as a separator rather than the standard MediaWiki "#". Used in -- the template.


function p.formatLink(frame) local args = getArgs(frame) local link = args[1] local display = args[2] if not link then return p.makeWikitextError( 'no link specified', 'Template:Format hatnote link#Errors', args.category ) end return p._formatLink(link, display) end

function p._formatLink(link, display) -- Find whether we need to use the colon trick or not. We need to use the -- colon trick for categories and files, as otherwise category links -- categorise the page and file links display the file. checkType('_formatLink', 1, link, 'string') checkType('_formatLink', 2, display, 'string', true) link = removeInitialColon(link) local namespace = p.findNamespaceId(link, false) local colon if namespace == 6 or namespace == 14 then colon = ':' else colon = end -- Find whether a faux display value has been added with the | magic -- word. if not display then local prePipe, postPipe = link:match('^(.-)|(.*)$') link = prePipe or link display = postPipe end -- Find the display value. if not display then local page, section = link:match('^(.-)#(.*)$') if page then display = page .. ' § ' .. section end end -- Assemble the link. if display then return string.format('%s', colon, link, display) else return string.format('%s%s', colon, link) end end


-- Hatnote -- -- Produces standard hatnote text. Implements the template.


function p.hatnote(frame) local args = getArgs(frame) local s = args[1] local options = {} if not s then return p.makeWikitextError( 'no text specified', 'Template:Hatnote#Errors', args.category ) end options.extraclasses = args.extraclasses options.selfref = args.selfref return p._hatnote(s, options) end

function p._hatnote(s, options) checkType('_hatnote', 1, s, 'string') checkType('_hatnote', 2, options, 'table', true) local classes = {'hatnote'} local extraclasses = options.extraclasses local selfref = options.selfref if type(extraclasses) == 'string' then classes[#classes + 1] = extraclasses end if selfref then classes[#classes + 1] = 'selfref' end return string.format( '
%s
', table.concat(classes, ' '), s )

end

return p
  1. ^
  2. ^ a b
  3. ^