विकिपीडिया
bhwiki
https://bh.wikipedia.org/wiki/%E0%A4%AE%E0%A5%81%E0%A4%96%E0%A5%8D%E0%A4%AF_%E0%A4%AA%E0%A4%A8%E0%A5%8D%E0%A4%A8%E0%A4%BE
MediaWiki 1.46.0-wmf.22
first-letter
मीडिया
विशेष
वार्तालाप
प्रयोगकर्ता
प्रयोगकर्ता वार्ता
विकिपीडिया
विकिपीडिया वार्ता
चित्र
चित्र वार्ता
मीडियाविकि
मीडियाविकि वार्ता
टेम्पलेट
टेम्पलेट वार्ता
मदद
मदद वार्ता
श्रेणी
श्रेणी वार्ता
TimedText
TimedText talk
Module
Module talk
Event
Event talk
उत्तर प्रदेश
0
4349
790088
787351
2026-04-03T00:04:38Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790088
wikitext
text/x-wiki
{{Infobox state
| name = उत्तर प्रदेश
| official_name =
| type = [[भारत के राज्य अउरी संघ राज्यक्षेत्र|राज्य]]
| image_skyline = {{Photomontage
| photo1a = Taj Mahal (105136313).jpeg
| photo2a = PremMandirSideViewFromCanteen.jpg
| photo2b = 62 Fatehpur Sikrí 11.jpg
| photo3a = India-5163 - Flickr - archer10 (Dennis).jpg
| photo3b = Manikarnika Cremation Ghat, Varanasi.jpg
| photo4a = On the banks of New Yamuna bridge, Allahabad.jpg
| spacing = 1
| color_border = black
| color = black
| size = 260
| foot_montage = From top, left to right:<br />[[Taj Mahal]], Prem Mandir in [[Vrindavan]], [[Fatehpur Sikri]], [[Sarnath]], [[Manikarnika Ghat]], [[New Yamuna Bridge]]
}}
| image_shield = Seal of Uttar Pradesh.png
| image_caption = बीच में: [[बनारस]] क मुंशी घाट; ऊपर से घड़ी के दिसा में: [[ताज महल]]; [[काशी विश्वनाथ मंदिर]]; बुलंद दरवाजा; एत्मादुदौला के मकबरा; [[इलाहाबाद]] में [[नया यमुना पुल]]; [[सारनाथ]] में धम्मेक स्तूप; प्रेम मंदिर, मथुरा; [[इलाहाबाद विश्वविद्यालय]]
| seal_alt =
| image_map = India UP.svg
| image_map1 = India_Uttar_Pradesh_location_map.svg
| map_caption = भारत में लोकेशन
| coordinates = {{coord|26.85|80.91|region:IN-UP_type:adm1st|display=inline,title}}
| coor_pinpoint =
| coordinates_footnotes =
| subdivision_type = देस
| subdivision_name = {{flag|भारत}}
| established_title = राज्य के दर्जा
| established_date = 26 जनवरी 1950
{{hidden end}}
| parts_type = [[उत्तर प्रदेश के जिला सभ के लिस्ट|जिला]]
| parts_style = para
| p1 = [[उत्तर प्रदेश के जिला सभ के लिस्ट|75]]<ref name="GOI_2011" />
| seat_type = राजधानी
| seat = [[लखनऊ]]
| government_footnotes =
| governing_body = उत्तर प्रदेश सरकार
| leader_title = राज्यपाल
| leader_name = [[आनंदी बेन पटेल]]<ref>{{cite news|title=Anandiben Patel sworn-in as UP governor|url=https://economictimes.indiatimes.com/news/politics-and-nation/anandiben-patel-sworn-in-as-up-governor/articleshow/70431152.cms|accessdate=3 अगस्त 2019|agency=पीटीआइ|publisher=दि इकोनामिक टाइम्स|date=29 जुलाई 2019}}</ref>
| leader_title1 = मुख्यमंत्री
| leader_name1 = [[आदित्यनाथ|योगी आदित्यनाथ]] ([[भारतीय जनता पार्टी|भाजपा]])
| leader_title2 = [[उत्तर प्रदेश बिधानसभा|बिधानसभा]]
| leader_name2 = {{Plainlist|
* दू सदनी
* [[उत्तर प्रदेश बिधानपरिषद|बिधानपरिषद]] 100
* [[उत्तर प्रदेश बिधानसभा|बिधानसभा]] 404
}}
| leader_title3 = [[भारतीय संसद|संसद सीट]]
| leader_name3 = {{Plainlist|
* [[राज्यसभा]] 31
* [[लोकसभा]] 80
}}
| leader_title4 = हाइकोर्ट
| leader_name4 = [[इलाहाबाद हाइकोर्ट]]
| unit_pref = Metric<!-- or US or UK -->
| area_footnotes =
| area_total_km2 = 240928
| area_note =
| area_rank = [[रकबा के आधार पर भारत के राज्य अउरी संघ राज्यक्षेत्र|4था]]
| elevation_footnotes =
| elevation_m =
| population_footnotes = <ref name="GOI_2011">{{cite web|title=Statistics of Uttar Pradesh|url=http://upgov.nic.in/upstateglance.aspx|work=Census of India 2011|publisher=UP Government|date=1 मार्च 2011|accessdate=31 जुलाई 2012|archive-date=2012-04-26|archive-url=https://web.archive.org/web/20120426235914/http://upgov.nic.in/upstateglance.aspx|url-status=dead}}</ref>
| population_total = 199281477
| population_as_of = 2011
| population_rank = 1
| population_density_km2 = auto
| population_note =
| population_demonym =
| demographics_type1 = भाषा
| demographics1_title1 = ऑफिशियल
| demographics1_info1 = [[हिंदी भाषा|हिंदी]]
| demographics1_title2 = दूसर ऑफिशियल
| demographics1_info2 = [[उर्दू]]
| demographics1_title3 = अन्य लोकल
| demographics1_info3 = [[भोजपुरी]], अवधी
| timezone1 = [[भारतीय मानक समय|आइएसटी]]
| utc_offset1 = +05:30
| blank_name_sec1 = एचडीआइ
| blank_info_sec1 = {{increase}} 0.5415 (<span style="color:#FFA500;">medium</span>)
| blank1_name_sec1 = एचडीआइ रैंक
| blank1_info_sec1 = 18<sup>वाँ</sup> (2007-08)
| blank_name_sec2 = साक्षरता
| blank_info_sec2 = {{Plainlist|
* 69.72%
* 79.24% (पुरुष)
* 59.26% (महिला)
}}
| area_code_type = UN/LOCODE
| area_code = IN-UP
| registration_plate = UP 01—XX
| website = [http://www.up.gov.in/ www.up.gov.in]
| footnotes =
}}
'''उत्तर प्रदेश''' [[भारत]] क सभसे ढेर जनसंख्या वाला राज्य आ दुनिया में सभसे ढेर जनसंख्या वाला देस-उपबिभाग बाटे। भारतीय उपमहादीप के [[उत्तर भारत|उत्तरी]]-बिचला इलाक में पड़े वाला एह राज्य के कुल आबादी लगभग 200 मिलियन (20 करोड़)बाटे। [[लखनऊ]] एह राज्य के राजधानी हवे।
ब्रिटिश andi Mandi Sandi kidney yeh de kha w/o or us ji maa randiशासन के दौरान 1 अप्रैल 1937 के यूनाइटेड प्रोविंस के नाँव से ई प्रदेश के रूप में बनावल गइल आ आजादी के बाद 1950 में एकर नाँव बदल के '''उत्तर प्रदेश''' रखाइल। 9 नवंबर 2000 के एह राज्य से उत्तरी पहाड़ी इलाका के अलग क के [[उत्तराखंड|उत्तरांचल]] (अब उत्तराखंड) राज्य बनल। वर्तमान में, प्रशासन खातिर ई अठारह गो मंडल आ 75 जिला में बिभाजित कइल गइल बा।
भूगोलीय रूप से ई राज्य [[सिंधु गंगा के मैदान|गंगा के मैदान]] के सपाट हिस्सा में स्थित बा आ इहाँ उष्णकटिबंधीय मानसूनी जलवायु पावल जाले। राज्य के पछिम ओर [[राजस्थान]]; उत्तर-पच्छिम में [[हरियाणा]], [[दिल्ली]] आ [[हिमाचल प्रदेश]]; उत्तर में [[उत्तराखंड]] आ [[नेपाल]]; पूरुब ओर [[बिहार]] आ दक्खिन ओर [[मध्य प्रदेश]] बाड़ें; जबकि एकदम दक्खिन-पूरुब के छोर पर एकर कुछ सीमा [[झारखंड]] आ [[छत्तीसगढ़]] के साथ भी सटल बा। कुल 243,290 बर्ग किलोमीटर (93,933 बर्गमील) रकबा वाला ई राज्य भारत के 7.33% भाग हवे आ चउथा सबसे बड़ राज्य भी हवे।
अर्थब्यवस्था के आकार के मामिला में ई भारत के तीसरा सभसे बड़ राज्य बा जहाँ जीडीपी ₹9,763 बिलियन (US$150 बिलियन) बाटे। खेती आ सर्विस क्षेत्र प्रमुख आर्थिक कामकाज बाड़ें; सर्विस सेक्टर में परिवहन, पर्यटन, होटल, अचल संपत्ति, इंशोरेंस आ फाइनेंस संबंधी चीज सामिल बाटे। [[गाजियाबाद, उत्तर प्रदेश|गाजियाबाद]], [[बुलंदशहर]], [[कानपुर]], [[गोरखपुर]], [[इलाहाबाद]], [[भदोही]], [[रायबरेली]], [[मुरादाबाद]], [[बरेली]], [[अलीगढ़]], [[सोनभद्र]], आ [[बनारस]] एह राज्य में औद्योगिक रूप से महत्व वाला शहर बाने।
प्राचीन आ मध्य्कालीन दौर में उत्तर प्रदेश ताकतवर राज सभ के भूमि रहल बा। इहाँ प्राकृतिक आ इतिहासी पर्यटन के कई जगह बा जइसे की [[आगरा]], बनारस, [[कौशांबी]], [[बलियाँ]], श्रावस्ती, गोरखपुर, [[कुशीनगर]], लखनऊ, इलाहाबाद वगैरह। धार्मिक रूप से [[हिंदू धर्म]] के सबसे प्रमुख शाखा वैष्णव मत के दू गो अवतार [[राम]] आ [[कृष्ण]] एही राज्य में पैदा भइल बतावल जालें आ [[अजोध्या]] आ [[मथुरा]] प्रसिद्ध धार्मिक तीर्थ हवें। गंगा के तीरे बसल बनारस आ गंगा आ यमुना नदी के संगम पर मौजूद इलाहाबाद के हिंदू धरम में बहुत महत्व बा। दूर उत्तर-पूरुब कोना पर मौजूद गोरखपुर नाथ सम्प्रदाय के संस्थापक [[गोरखनाथ]] के भूमि मानल जाले।
== इतिहास ==
=== आदिकाल ===
शिकार आ भोजन संग्रह करे वाला आदिम मनुष्य लोग के उपस्थिति एह इलाका में रहल जहाँ आज के उत्तर प्रदेश बा<ref>{{cite book|url=https://books.google.com/books?id=gMoJj-0Z94UC&pg=PA69|page=69|title=Recent Advances in Indo-Pacific Prehistory: proceedings of the international symposium held at Poona |author=Virendra N. Misra, Peter Bellwood|isbn=90-04-07512-7|accessdate=23 July 2012|year=1985}}</ref><ref>{{cite book|url=https://books.google.com/books?id=r4s-YsP6vcIC&pg=PA58|page=58|title=The Rise of Civilization in India and Pakistan|author=Bridget Allchin, Frank Raymond Allchin|publisher=Cambridge University Press|isbn=0-521-28550-X|accessdate=23 July 2012|date=29 July 1982}}</ref><ref>{{cite book |author1=Hasmukhlal Dhirajlal Sankalia |author2=Shantaram Bhalchandra Deo |author3=Madhukar Keshav Dhavalikar |date=1985 |title=Studies in Indian Archaeology: Professor H.D. Sankalia Felicitation Volume |url=https://books.google.com/books?id=35DP1Z-2dnYC&pg=PA96 |publisher=Popular Prakashan |page=96 |isbn=978-0-86132-088-2}}</ref> आ अनुमान बा की ई लोग<ref>Confidence limits for the age are 85 (±11) and 72 (±8) thousand years ago.</ref> 85,000 से 72,000 साल पहिले इहाँ रहे। इहाँ से पुरापाषाणकाल के चीज भी मिलल बा जे 21,000–31,000 साल पुरान बतावल गइल बा<ref>{{cite journal|last1=Gibling|first1=Sinha|last2=Sinha|first2=Roy|last3=Roy|first3=Tandon|last4=Tandon|first4=Jain|last5=Jain|first5=M|title=Quaternary fluvial and eolian deposits on the Belan river, India: paleoclimatic setting of Paleolithic to Neolithic archeological sites over the past 85,000 years|journal=Quaternary Science Reviews|volume=27|page=391|year=2008|doi=10.1016/j.quascirev.2007.11.001|issue=3–4|ref=harv}}</ref> आ मेसोलिथिक/माइक्रोलिथिक जमाना के आदिम लोग के 10550–9550 ईसा पूर्व के बस्ती के अवशेष [[प्रतापगढ़ जिला]] से मिलल बा जेह में पालतू मवेशी, बकरी आ भेड़ पाले आ खेती के सुरुआत के प्रमाण कम से कम 6000 ईसा पूर्व तक ले के मिलल बा जे धीरे-धीरे c. 4000 से 1500 ईसापूर्व ले बिकसित भइल; सिंधु घाटी सभ्यता आ हड़प्पा संस्कृति के दौर से होत वैदिक काल आ लोहा के जुग ले आइल।<ref>{{cite book|url=https://books.google.com/books?id=W6zQHNavWlsC&pg=PA263|publisher=University of Michigan Press|year= 2000|isbn=0-472-11013-6|page=263|title=God-apes and Fossil Men|author=Kenneth A. R. Kennedy|accessdate=23 July 2012}}</ref><ref>{{cite book|url=https://books.google.com/books?id=r4s-YsP6vcIC&pg=PA119|page=119|publisher=Cambridge University Press|isbn=0-521-28550-X|year=1982|title=The Rise of Civilization in India and Pakistan|author=Bridget Allchin, Frank Raymond Allchin|accessdate=23 July 2012}}</ref><ref>{{cite web|url=http://www.ias.ac.in/jbiosci/nov2001/491.pdf |title=Prehistoric human colonization of India |format=PDF |accessdate=5 April 2012}}</ref>
===प्राचीन जुग===
[[File:Rama in forest.jpg|thumb|upright|left|alt=राम क पेंटिंग, बगल में सीता आ लक्ष्मन भी बाने|राम के बनगमन के दृश्य, सीता आ लछमन के साथ।]]
महाजनपद काल में कोसल राज्य के बिस्तार ओही इलाका में रहे जवन आज के जमाना के उत्तर प्रदेश के सीमा के भीतर आवे ला।<ref name="Sen1999">{{cite book|author=Sailendra Nath Sen|title=Ancient Indian History And Civilization|url=https://books.google.com/books?id=Wk4_ICH_g1EC&pg=PA105|accessdate=1 अक्टूबर 2012|date=1 जनवरी 1999|publisher=New Age International|isbn=978-81-224-1198-0|pages=105–106}}</ref> हिंदू कथा के मोताबिक अवतारी पुरुष राम अजोध्या के राजा रहलन जे कोसल के राजधानी रहे।<ref name="Buck2000">{{cite book|author=William Buck|title=Ramayana|url=https://books.google.com/books?id=vvuIp2kqIkMC|accessdate=1 अक्टूबर 2012|date=1 January 2000|publisher=Motilal Banarsidass Publ.|isbn=978-81-208-1720-3}}</ref> [[कृष्ण]], हिंदू कथा के अन्य पात्र, जिनके महाभारत में प्रमुख भूमिका रहल आ जिनके [[बिष्णु]] के अवतार मानल जाला, उत्तर प्रदेश के मथुरा में पैदा भइल बतावल जालें।<ref name="Sen1999"/> महाभारत के लड़ाई ऊपरी दुआबा आ दिल्ली के आसपास के इलाका में भइल रहल जहाँ कुरु महाजनपद रहल आ पांडव लोग के शासन भइल। इतिहास के हिसाब से कुरु जनपद के काल उहे हवे जे करिया आ लाल माटी के बर्तन वाला जुग हवे, यानि उत्तरी-पच्छिमी भारत में लोहा जुग के सुरुआत, लगभग 1000 ईसा पूर्व के समय।<ref name="Sen1999"/>
दक्खिन भारत पर हमला करे वाला ज्यादातर लोग गंगा के मैदान के इलाका से जरूर गुजरल जेकरा आज के उत्तर प्रदेश कहल जाला। एह इलाका पर कंट्रोल कइल सगरी भारतीय साम्राज्य सभ खातिर बहुत महत्व के चीज रहल बा आ अपना स्थायित्व आ बिकास खातिर सगरी बड़हन साम्राज्य सभ एह इलाका के महत्व दिहले बाने, एह में [[मौर्य साम्राज्य|मौर्य]] (320–200 BC), कुषाण (CE 100–250), गुप्त (350–600), आ गुर्जर-प्रतिहार (650–1036) साम्राज्य के नाँव गिनावल जा सकत बाटे।<ref name="White2010">{{cite book|author=Richard White|title=The Middle Ground: Indians, Empires, and Republics in the Great Lakes Region, 1650-1815|url=https://books.google.com/books?id=fHLfiOZVzmMC|accessdate=1 अक्टूबर 2012|date=8 November 2010|publisher=Cambridge University Press|isbn=978-1-107-00562-4}}</ref> गुप्त साम्राज्य के तूर देवे वाला हूण आक्रमण के पाछे-पाछे गंगा के मैदान के एह इलाका में कन्नौज के उदय भइल।<ref name="Corporation2007">{{cite book|author=Marshall Cavendish Corporation|title=World and Its Peoples: Eastern and Southern Asia|url=https://books.google.com/books?id=V1pQkwIXTG0C&pg=PA331|accessdate=1 अक्टूबर 2012|date=September 2007|publisher=Marshall Cavendish|isbn=978-0-7614-7631-3|pages=331–335}}</ref> हर्षवर्धन (590–647) के राज में कन्नौज के राजघराना अपना चरम पर पहुँच गइल।<ref name="Corporation2007"/> एह समय ई पंजाब से लेके गुजरात ले आ पूरुब में बंगाल से उड़ीसा ले बिस्तार लिहले रहल।<ref name="Sen1999"/> एह में मध्य भारत के कुछ अइसन इलाका भी शामिल रहल जे [[नर्मदा नदी]] के दक्खिन के इलाका रहल, पूरा गंगा-जमुना मैदान टेम्पलेट एकर भाग रहबे कइल।<ref name="Chopra2003"/> वर्तमान भारत में कई समुदाय बाने जे अपना के एह कन्नौज के राज से फइलल लोग के बंसज बतावे ला।<ref name="Bowman2000"/> हर्ष के मउअति के बाद उनके ई साम्राज्य कई राजघराना सभ में टूट गइल, इनहन पर गुर्जर-प्रतिहार लोग आक्रमण कइल आ शासन कइल, एकरा बाद ई लोग के बंगाल के पाल बंस के भी चुनौती दिहल।<ref name="Chopra2003">{{cite book|author=Pran Nath Chopra|title=A Comprehensive History of Ancient India|url=https://books.google.com/books?id=gE7udqBkACwC&pg=PA196|accessdate=1 अक्टूबर 2012|date=1 दिसंबर 2003|publisher=Sterling Publishers Pvt. Ltd|isbn=978-81-207-2503-4|page=196}}</ref> कन्नौज पर दक्खिनी भारत के राष्ट्रकूट बंस के लोग द्वारा आठवी से दसवीं सदी के बीच भी कई गो आक्रमण भइल।<ref>The History of India by Kenneth Pletcher p.102</ref><ref>The City in South Asia by James Heitzman p.37</ref>
===मध्यकाल आ सुरुआती आधुनिक जुग===
16वीं सदी में, फरगाना घाटी (आधुनिक उजबेकिस्तान) के रहे वाला आ तैमूर आ चंगेज खान के बंसज, [[बाबर]] द्वारा खैबर दर्रा से हो के दक्खिनी एशिया में आक्रमण कइल गइल आ [[मुग़ल साम्राज्य]] के स्थापना भइल जेह में वर्तमान समय के अफगानिस्तान, पाकिस्तान, उत्तर भारत आ बांग्लादेश के हिस्सा आवे लें।<ref>[http://www.ucalgary.ca/applied_history/tutor/islam/empires/mughals/ The Islamic World to 1600: Rise of the Great Islamic Empires (The Mughal Empire)] {{webarchive |url=https://web.archive.org/web/20110927121217/http://www.ucalgary.ca/applied_history/tutor/islam/empires/mughals/ |date=27 September 2011 }}</ref> मुग़ल लोग मध्य एशिया के तुर्क लोग के बंसज रहे आ इनहन लोग के बंस में मंगोल पूर्वज लोग के भी मिलावट रहे। मुग़ल काल में उत्तर प्रदेश के इलाका साम्राज्य के हिरदय (हार्टलैंड) नियर बन गइल।<ref name="Bowman2000">{{cite book|author=John Stewart Bowman|title=Columbia Chronologies of Asian History and Culture|url=https://books.google.com/books?id=cYoHOqC7Yx4C&pg=PA273|accessdate=2 अगस्त 2012|year=2000|publisher=Columbia University Press|isbn=978-0-231-11004-4|page=273}}</ref> मुग़ल शासक बाबर आ हुमायूँ [[दिल्ली]] से शासन कइल।<ref name="Schimmel2004">{{cite book|author=Annemarie Schimmel|title=The Empire of the Great Mughals: History, Art and Culture|url=https://books.google.com/books?id=N7sewQQzOHUC|accessdate=1 अक्टूबर 2012|date=5 February 2004|publisher=Reaktion Books|isbn=978-1-86189-185-3}}</ref><ref name="Hindustan)Hiro2006">{{cite book|author1=Babur (Emperor of Hindustan)|author2=Dilip Hiro|title=Babur Nama: Journal of Emperor Babur|url=https://books.google.com/books?id=VW2HJL689wgC|accessdate=1 अक्टूबर 2012|date=1 मार्च 2006|publisher=Penguin Books India|isbn=978-0-14-400149-1}}</ref> साल 1540 में अफगान योद्धा, [[शेर शाह सूरी]] द्वारा मुग़ल बादशाह हुमायूँ के हरा के उत्तर प्रदेश पर अधिकार जमा लिहल गइल।<ref name="Ramirez-Faria2007">{{cite book|author=Carlos Ramirez-Faria|title=Concise Encyclopeida Of World History|url=https://books.google.com/books?id=gGKsS-9h4BYC&pg=PA171|accessdate=2 अगस्त 2012|date=1 January 2007|publisher=Atlantic Publishers & Dist|isbn=978-81-269-0775-5|page=171}}</ref> शेर शाह आ उनके लड़िका इस्लाम शाह द्वारा उत्तर प्रदेश पर ग्वालियर से शासन कइल गइल।<ref name=hindustan>{{cite book|last=Stronge|first=Susan|title=Mughal Hindustan is renowned for its opulence|date=16 अक्टूबर 2012|publisher=The Arts of the Sikh Kingdoms (V&A 1999)|location=London|page=255|url=https://books.google.com/books?id=PVrSYgEACAAJ&dq=hindustan+by+mughal|accessdate=23 July 2012|isbn=9788174366962}}</ref> इस्लाम शाह के मौत के बाद उनके परधानमंत्री हेमू उत्तर प्रदेश के ''डि फैक्टो'' शासक बन गइल अ एह राज में बिहार, मध्य प्रदेश, आ बंगाल के पच्छिमी हिस्सा भी शामिल रहल। हेमू आपन टाइटिल ''हेमचंद्र विक्रमादित्य'' रखलें आ उनके औपचारिक राज्यारोहण दिल्ली के पुराना किला में 7 अक्टूबर 1556 के भइल। पानीपत के दूसरा जुद्ध में हेमू के निधन भइल आ उत्तर प्रदेश पर [[अकबर]] क शासन स्थापित भइल।<ref name="Agrawal1983">{{cite book|author=Ashvini Agrawal|title=Studies In Mughal History|url=https://books.google.com/books?id=AZdCrUxFAHEC&pg=PA30|accessdate=27 July 2012|date=1 January 1983|publisher=Motilal Banarsidass Publ.|isbn=978-81-208-2326-6|pages=30–46}}</ref> अकबर द्वारा [[आगरा]] आ फतेहपुर सीकरी से शासन चलावल गइल।<ref>Fergus Nicoll, ''Shah Jahan: The Rise and Fall of the Mughal Emperor'' (2009)</ref> 18वीं सदी में मुगल साम्राज्य के पतन के बाद खाली जगह के मराठा साम्राज्य द्वारा भरल गइल आ मराठा लोग उत्तर प्रदेश पर हमला कइल जेह में रोहिल्ला लोग हार गइल आ रुहेलखण्ड पर रघुनाथ राव आ मल्हाराव होलकर के शासन हो गइल। मराठा आ रोहिल्ला लोग के बिचा में संघर्ष के अंत भइल 18{{nbsp}}दिसंबर 1788 के, जब नजीबुद्दौला के पोता गुलाम कादिर के महादजी सिंधिया द्वारा हरा के गिरफ्तार क लिहल गइल। 1803 में दूसरा आंग्ल-मराठा जुद्ध के बाद ब्रिटिश ईस्ट इंडिया कंपनी द्वारा मराठा लोग के हरा दिहल गइल आ उत्तर प्रदेश पर [[ब्रिटिश राज|अंग्रेजी राज]] स्थापित हो गइल।<ref>{{cite book
|last = Mayaram
|first = Shail
|title = Against history, against state: counterperspectives from the margins Cultures of history
|publisher = Columbia University Press, 2003
|isbn = 978-0-231-12731-8}}</ref>
====ब्रिटिश राज में====
{{Infobox
| above = उत्तर प्रदेश के नाँव बदलाव आ क्षेत्र बदलाव के समयरेखा<ref>{{Cite web |url=http://www.hindustantimes.com/lucknow/uttar-pradesh-day-how-the-state-was-born-67-years-back/story-Y2JhCTBIo2UuQYvQSTBNgN.html |title=आर्काइव कॉपी के बा |access-date=2017-06-27 |archive-date=2017-05-03 |archive-url=https://web.archive.org/web/20170503114407/http://www.hindustantimes.com/lucknow/uttar-pradesh-day-how-the-state-was-born-67-years-back/story-Y2JhCTBIo2UuQYvQSTBNgN.html |url-status=dead }}</ref>
| label2 = 1807 | data2 = सीडेड एंड कॉन्कर्ड प्रोविंस
| label3 = 14 नवं 1834 | data3 = आगरा प्रेसिडेंसी
| label4 = 1 जन 1836 | data4 = नार्थ-वेस्टर्न प्रोविंस
| label5 = 3 अप्रै 1858 | data5 = ब्रिटिश अवध अलग भइल, दिल्ली के नार्थ-वेस्टर्न प्रोविंस से बिलगा के पंजाब में सामिल कइल गइल
| label6 = 1 अप्रै 1871 | data6 = अजमेर, मेवाड़ आ केकरी के अलग कमिश्नर-शिप में डालल गइल
| label7 = 15 फर 1877 | data7 = नार्थ वेस्टर्न प्रोविंस में अवध के शामिल कइल गइल
| label8 = 22 मार्च 1902 | data8 = 'आगरा अवध संजुक्त प्रांत' नाँव कइल गइल
| label9 = 3 जन 1921 | data9 = 'ब्रिटिश भारत के संजुक्त प्रांत' नाँव कइल गइल
| label10 = 1 अप्रै 1937 | data10 = 'संजुक्त प्रान्त (यूनाइटेड प्रोविंस)' नाँव कइल गइल
| label11 = 1 अप्रै 1946 | data11 = खुद शासन के स्वीकार कइल गइल
| label12 = 15 अग 1947 | data12 = आजाद भारत के राज्य
| label13 = 24 जन 1950 | data13 = नाँव बदल के 'उत्तर प्रदेश' कइल गइल
| label14 = 9 नवं 2000 | data14 = वर्तमान [[उत्तराखंड]] के 'उत्तरांचल' के नाँव से अलग राज्य बनावल गइल।
}}
18वीं सदी के दूसरा हिस्सा में उत्तर भारत में कई गो लड़ाई, बंगाल से सुरू हो के पच्छिम के ओर बढ़त क्रम में, भइल आ इलाका धीरे-धीरे ब्रिटिश ईस्ट इंडिया कंपनी के शासन में आ गइल।<ref name="Kudaisya2006">{{cite book |author=Gyanesh Kudaisya |title=Region, nation, "heartland": Uttar Pradesh in India's body-politic |year=1994 |publisher=LIT Verlag Münster |isbn=978-3-8258-2097-8 |pages=126–376}}</ref> [[अजमेर]] आ [[जयपुर]] के राजघराना एही कंपनी राज में नार्थ-वेस्टर्न टेरीटरी (उत्तर-पच्छिमी इलाका) में शामिल कइल गइल रहल आ एकर नाँव तब "नार्थ-वेस्टर्न प्रोविंस" (आगरा के) रखल गइल रहे। बाद में यूपी भारत के पाँचवाँ सभसे बड़ राज्य बनल, बाकिर ई तबो ब्रिटिश भारत के सभसे छोट राज्य रहे।<ref name="Sivaramakrishnan1999">{{cite book|author=K. Sivaramakrishnan|title=Modern Forests: Statemaking and Environmental Change in Colonial Eastern India|url=https://books.google.com/books?id=TM7oYBG4M04C&pg=PA240|accessdate=26 July 2012|date=3 December 1999|publisher=Stanford University Press|isbn=978-0-8047-4556-7|pages=240–276}}</ref> एकर राजधानी दू बेर आगरा आ इलाहाबाद के बीच एहर-ओहर कइल गइल।<ref>{{cite book |title=Town Planning Regeneration of Cities|author=Ashutosh Joshi|publisher=New India Publishing|date= 1 जनवरी 2008|isbn=8189422820 |page=237 |url=https://books.google.com/books?id=UFaGME0XDBkC&pg=PA151&dq=Naini&hl=en&sa=X&ei=CN7OUsznI8yTrgeDwYDgCw&ved=0CDEQ6AEwATgU#v=onepage&q=Allahabad%20capital&f=false }}</ref>
ब्रिटिश शासन से गम्हिराहे असंतोख के चलते बंगाल रेजीमेंट के सिपाही लोग जे मेरठ में तैनात रहल, बिद्रोह क दिहल। एह घटना में उत्तर प्रदेश के [[मंगल पांडे]] के बिद्रोह के सुरुआत करे के श्रेय दिहल जाला।<ref name="Mukherjee2005">{{cite book|author=Rudrangshu Mukherjee|title=Mangal Pandey: brave martyr or accidental hero?|url=https://books.google.com/books?id=-SluAAAAMAAJ|accessdate=1 अक्टूबर 2012|date=1 जून 2005|publisher=पेंगुइन बुक्स|isbn=978-0-14-303256-4}}</ref> एकरे बाद क्रम से बिद्रोह के बिस्तार होत गइल आ इतिहास में ई [[1857 के बिद्रोह]] भा भारत के पहिली आजादी के लड़ाई के रूप में देखल जाला। कानपुर में नाना साहेब, तात्यां टोपे, आ अजीमुल्ला, लखनऊ में बेगम हजरत महल, झाँसी में रानी लक्ष्मीबाई, बरेली में खान बहादुर खान, फैजाबाद में मौलवी अहमदुल्लाह, कालपी में ताँत्या टोपे, इलाहाबाद में लियाकत अली, मेरठ में कदम सिंह आ मथुरा में देवी सिंह एह बिद्रोह के अगुआई कइल लोग। कुछ दिन बाद जब ब्रिटिश सासन दोबारा आपन सत्ता कायम क लिहलस, 1 नवंबर 1958 के इलाहाबाद में दरबार के आयोजन कइल गइल आ लार्ड कैनिंग महारानी के घोषणापत्र पढ़लें आ एकरे बाद भारत के सत्ता ईस्ट इंडिया कंपनी के हाथ से सीधे इंग्लैंड के महारानी के हाथ में चल गइल। बिद्रोह के बिफलता के बाद के राजीनीतिक स्थिति में अंग्रेज लोग आपन स्थिति अउरी पोढ़ करे खाती बिद्रोही प्रदेश सभ के बाँट के नया तरीका से राजनीतिक बिभाजन कइल। नार्थ-वेस्ट प्रोविंस के दिल्ली इलाका के पंजाब के संघे बिलय क दिहल गइल, अजमेर आ मारवाड़ के राजपुताना में बिलय कइल गइल, अवध के नया राज्य के रूप में स्थापित कइल गइल आ एकर नाँव 'नार्थ वेस्टर्न प्रोविंस ऑफ आगरा एंड अवध' रखल गइल, जेकरा के 1902 में 'यूनाइटेड प्रोविंस ऑफ आगरा एंड अवध' क दिहल गइल।<ref name="(India)Drake-Brockman1934">{{cite book|author1=United Provinces of Agra and Oudh (India)|author2=D.L. Drake-Brockman|title=District Gazetteers of the United Provinces of Agra and Oudh: supp.D.Pilibhit District|url=https://books.google.com/books?id=VUNuAAAAMAAJ|accessdate=1 अक्टूबर 2012|year=1934|publisher=Supdt., Government Press, United Provinces}}</ref> आमतौर पर एकरा के यूनाइटेड प्रोविंस भा यूपी कहल जाए लागल।<ref name="Chakrabarti1997">{{cite book|author=Dilip K. Chakrabarti|title=Colonial Indology: sociopolitics of the ancient Indian past|url=https://books.google.com/books?id=ADZuAAAAMAAJ|accessdate=26 जुलाई 2012|date=1 जून 1997|publisher=Munshiram Manoharlal Publishers Pvt. Ltd.|location=Michigan|isbn=978-81-215-0750-9|page=257}}</ref><ref name="Cohn1996">{{cite book|author=Bernard S. Cohn|title=Colonialism and Its Forms of Knowledge: The British in India|url=https://books.google.com/books?id=uIalYaenrTkC|accessdate=26 जुलाई 2012|date=19 अगस्त 1996|publisher=प्रिंसटन यूनिवर्सिटी प्रेस|isbn=978-0-691-00043-5|page=189}}</ref>
1920 में राजधानी के इलाहाबाद से लखनऊ ले जाइल गइल। हाईकोर्ट के इलाहाबादे में रहे दिहल गइल बाकी एगो बेंच के स्थापना लखनउओ में कइल गइल। इलाहाबाद आज भी बिबिध प्रशासनिक आ सरकारी बिभागन के मुख्यालय बा आ महत्व के शहर हवे।<ref name="Nair2004">{{cite book|author=K. Balasankaran Nair|title=Law Of Contempt Of Court In India|url=https://books.google.com/books?id=gujNYPcNETMC|accessdate=26 जुलाई 2012|date=1 जनवरी 2004|publisher=अटलांटिक पब्लिशर्स & डिस्ट्री॰|isbn=978-81-269-0359-7|page=320}}</ref> उत्तर प्रदेश भारत के राजनीति में आपन केंद्रीय महत्व बाद में भी कायम रखले रहल आ भारत के आजादी के लड़ाई में ई इलाका बहुत गरमागरमी वाला रहल। एही दौर में उत्तर प्रदेश में बनारस हिंदू विश्वविद्यालय, अलीगढ़ मुस्लिम विश्वविद्यालय, आ दारुल-उलूम देवबंद जइसन आधुनिक शिक्षा के केंद्र सभ के स्थापना भइल। क्रांतिकारी लोग में राम प्रसाद बिस्मिल आ चंद्रशेखर आजाद नियर लोग आ मोतीलाल नेहरू, जवाहरलाल नेहरू, मदन मोहन मालवीय, गोबिंद बल्लभ पंत नियर लोग उत्तर प्रदेश के रहल जे भारत के आजादी के आंदोलन में राष्ट्रीय स्तर पर सक्रिय रहल आ एकर अगुआई कइल। कांग्रेस के लखनऊ सत्र में 11 अप्रैल 1936 के आल इंडिया किसान सभा के स्थापना भइल आ परसिद्ध राष्ट्रवादी स्वामी सहजानंद सरस्वती के पहिला अध्यक्ष बनावल गइल,<ref>{{cite book
| first = Bandyopādhyāya
| last = Śekhara
| title = From Plassey to Partition: A History of Modern India
| publisher = Orient Longman
| year = 2004
| isbn = 978-81-250-2596-2
| page = 407
}}</ref> एकर मकसद ढेर दिना से चल आइल रहल खेतिहर लोग के असंतोख के दूर कइल आ जमींदारी ब्यवस्था के तहत बड़हन भूस्वामी लोग के द्वारा खेतिहर लोगग के जमीन अधिकार पर हमला के खिलाफ खेतिहर लोग के आगे कइल आ भारत में किसान आंदोलन के सुरुआत कइल भी एकर उद्देश्य रहल।<ref>{{cite book
| first = Śekhara
| last = Bandyopādhyāya
| title = From Plassey to Partition: A History of Modern India
| publisher = Orient Longman
| year = 2004
| isbn = 978-81-250-2596-2
| page = 406
}}</ref> सन 1942 के भारत छोड़ो आंदोलन में, [[बलियाँ]] जिला में चित्तू पांडे के अगुआई में ब्रिटिश राज के कुछ दिन खातिर खतम क दिहल गइल रहे। बलियाँ के, एकरे आजादी के लड़ाई में उग्र योगदान खातिर "बागी बलियाँ" के नाँव से जानल जाला।<ref name="Chatterji2006">{{cite book|author=Bankim Chandra Chatterji|title=Anandamath|url=https://books.google.com/books?id=7Gmjn63ogDUC|accessdate=26 July 2012|date=15 जनवरी 2006|publisher=Orient Paperbacks|isbn=978-81-222-0130-7|page=168}}</ref>
====आजादी के बाद====
भारत के आजादी के बाद, यूनाइटेड प्रोविंस के नाँव बदल के "उत्तर प्रदेश" कइल गइल, एकर छोट नाँव यूपी के ओही तरे रखे खातिर,<ref>{{cite web|title=Uttar Pradesh - States and Union Territories |url=http://www.archive.india.gov.in/knowindia/state_uts.php?id=28 |website=Know India: National Portal of India |accessdate=14 जुलाई 2015}}</ref><ref>{{cite web |title=Uttar Pradesh |url=http://www.whatisindia.com/issues/uttarpra/uttar_general.html |publisher=What is India |accessdate=8 अक्टूबर 2016 |date=22 अगस्त 2007}}</ref> एकरा संबंधी नोटिफिकेशन के संघ के गजट में 24 जनवरी 1950 के छापल गइल।<ref>{{Cite web |last=archive |first=From our online |date=2017-05-02 |title=Uttar Pradesh introduces new transfer policy |url=https://www.newindianexpress.com/nation/2017/May/02/uttar-pradesh-introduces-new-transfer-policy-1600219.html |access-date=2026-01-13 |website=The New Indian Express |language=en}}</ref> ई राज्य से अबले आठ गो भारतीय परधानमंत्री हो चुकल बा लोग आ संसद में लोकसभा में सभसे ढेर हिस्सेदारी एही राज्य के बा। एकरा बावजूद भी, राजीनीतिक रूप से एतना महत्व वाला ई राज्य अपराध आ भ्रष्टाचार के चलते आर्थिक आ सामाजिक रूप से पिछड़पन के सिकार बा। जातीय आ सामुदायिक हिंसा से कई बेर परभावित भइल बा।<ref>{{cite news|title=Communal violence|url=http://www.business-standard.com/article/current-affairs/uttar-pradesh-tops-home-ministry-list-on-communal-violence-114080601639_1.html |accessdate=25 अगस्त 2014 |work=[[बिजनेस स्टैंडर्ड]] |agency=कोटक महिंद्रा बैंक |publisher=आनंद प्रकाशन |date=6 अगस्त 2014}}</ref> 1992 में अजोध्या में बाबरी महजिद के ध्वस्त करे के घटना के बाद राज्य में आ भारत भर में हिंसा भइल।<ref name="communal violence">{{cite news|last=communal violence|first=in uttar pradesh|title=Communal conflicts in state|url=http://www.tehelka.com/what-led-to-the-muzaffarnagar-communal-riots/|accessdate=12 January 2014|newspaper=Tehalka|archive-date=12 January 2014|archive-url=https://web.archive.org/web/20140112232933/http://www.tehelka.com/what-led-to-the-muzaffarnagar-communal-riots/|url-status=dead}}</ref> साल 2000 एकर उत्तरी पहाड़ी भाग के बिलगा के अलग राज्य [[उत्तराखंड]] बनावल गइल।<ref name=separation>{{cite book |author1=J. C. Aggarwal |author2=S. P. Agrawal |date=1995 |title=Uttarakhand: Past, Present, and Future |url=https://books.google.com/books?id=alRh51xE_v0C&pg=PA391 |publisher=Concept Publishing Company of India |page=391 |isbn=978-81-7022-572-0}}</ref>
== भूगोल ==
<!-- {{Main article|उत्तर प्रदेश के भूगोल}} -->
[[File:Indo-Gangetic Plain.jpg|thumb|alt="photograph"|गंगा के मैदान के हिस्सा]]
उत्तर प्रदेश के कुल रकबा 2,43,290 बर्ग किलोमीटर बा, आ एह मायने में ई भारत के चउथा सभसे बड़हन राज्य बा। ई भारत के उत्तरी भाग में स्थित बा आ एकर अंतरराष्ट्रीय चौहद्दी नेपाल के साथ बा। एह राज्य के उत्तर में हिमालय परबत शुरू हो जाला,<ref name=land>{{cite web|title=Most critical factors|url=http://upenvis.nic.in/Database/Land_830.aspx|publisher=Uttar Pradesh climate department|accessdate=22 जुलाई 2012}}</ref> बाकी प्रदेश के ज्यादातर इलाका मैदानी बा आ ई मैदान हिमालय के पहाड़ी इलाका के तुलना में एकदम्मे अलग चीज बाड़ें।<ref name=Geography>{{cite web|title=Uttar Pradesh Geography|url=http://www.uponline.in/About/Profile/Geography/index.html|publisher=Uttar Pradesh State Profile|accessdate=22 July 2012|archive-date=23 July 2012|archive-url=https://web.archive.org/web/20120723070728/http://www.uponline.in/About/Profile/geography/index.html|url-status=dead}}</ref> मैदानी इलाका के भी कई भाग में बाँटल जाला: ऊपरी गंगा मैदान, गंगा-जमुना दुआबा, घाघरा मैदान, आ तराई के मैदान।<ref name=Terai>{{cite web|title=The larger Gangetic Plain|url=http://www.gecafs.org/publications/Publications/IGP_Paper.pdf|publisher=Gecafs|accessdate=22 July 2012|archive-date=26 December 2013|archive-url=https://web.archive.org/web/20131226202743/http://www.gecafs.org/publications/Publications/IGP_Paper.pdf|url-status=dead}}</ref> प्रदेश के दक्खिनी इलाका में [[बिंध्य परबत श्रेणी|बिंध्य परबत]] के पठारी हिस्सा बा।<ref name=autogenerated8>{{cite web|title=Gangetic Plains and Vindhya Hills and plateau. |url=http://zeenews.india.com/state-elections-2012/up/profile.html/2 |publisher=[[Zee news]] |accessdate=22 July 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120406104938/http://zeenews.india.com/state-elections-2012/up/profile.html/2 |archivedate=6 April 2012 }}</ref> ई दक्खिनी हिस्सा में मुख्य रूप से कड़ेर चट्टानी इलाका, पहाड़ी आ पठार आ मैदानी घाटी पावल जालीं। मैदान के उत्तरी हिस्सा में भाबर आ तराई के इलाका पावल जाला, तराई में दलदली जमीन, जंगल आ लमहर हाथी घास पावल जाले।<ref name="BhargavaBhatt2005"/> भाबर के इलाका में नदी सभ के पानी काफी हद तक जमीन के नीचे (अंडरग्राउंड) बहे ला आ तराई के समानांतर ई पातर पट्टी के रूप में बा।<ref name="BhargavaBhatt2005"/> मुख्य मैदानी इलाका के तीन हिस्सा में बाँटल जाला: पूरबी उत्तर प्रदेश, जेह में 14 गो जिला सामिल बाने, अक्सर सूखा या बाढ़ के स्थिति पैदा हो जाले, बहुत घन आबादी होखे के कारण प्रति बेकती जमीन के रकबा कम बा आ बिपन्नता के इलाका मानल जाला; बिचला उत्तर प्रदेश आ पच्छिमी उत्तर प्रदेश के स्थिति कुछ बेहतर बा आ नहर इत्यादी के बिकास के कारण सिंचनी के सुबिधान बा।<ref name="BhargavaBhatt2005"/> उत्तर प्रदेश के कई इलाका सभ में जलजमाव (वाटरलॉगिंग) या फिर ऊसर जमीन के टुकड़ा भी पावल जालें।<ref name="BhargavaBhatt2005">{{cite book|author1=Gopal K. Bhargava|author2=Shankarlal C. Bhatt|title=Land and people of Indian states and union territories. 28. Uttar Pradesh|url=https://books.google.com/books?id=FCG5hGZ-hJsC&pg=PA31|accessdate=5 अक्टूबर 2012|year=2005|publisher=Gyan Publishing House|isbn=978-81-7835-384-5|pages=31–33}}</ref> एकरे अलावा, राज्य के बहुत सारा हिस्सा सूखा वाला इलाका भी बा। राज्य में कुल 32 गो गिनावे लायक छोट-बड़ नदी बाड़ी जिनहन में गंगा, यमुना, सरजू, बेतवा वगैरह के हिंदू धरम में भी महत्व बाटे।<ref name=rivers>{{cite news|title=Rivers of Uttar Pradesh|url=http://economictimes.indiatimes.com/topiclist/Rivers-of-Uttar-Pradesh|publisher=[[The Economic Times]]|accessdate=22 July 2012}}</ref>
उत्तर परदेश में गहन खेती होला।<ref name=glossary>{{cite web|title=The Glossary of Meteorology |url=http://amsglossary.allenpress.com/glossary/preface2 |publisher=Allen Press Inc. |accessdate=23 July 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20121005143046/http://amsglossary.allenpress.com/glossary/preface2 |archivedate=5 अक्टूबर 2012 }}</ref> मैदानी हिस्सा के निचला इलाका सभ में बहुत उपजाऊँ जमीन बा। कुछ पहाड़ी ढाल सभ पर भी गहन खेती होले हालाँकि ई सिंचनी के सुबिधा पर निर्भर होला।<ref name=Irrigation>{{cite web|title=Potential Creation and Utilisation|url=http://irrigation.up.nic.in/aboutus_irrigation_potential.htm|publisher=Irrigation department U.P|accessdate=22 July 2012|archive-date=13 February 2012|archive-url=https://web.archive.org/web/20120213084300/http://irrigation.up.nic.in/aboutus_irrigation_potential.htm|url-status=dead}}</ref> शिवालिक के पहाड़ी ढाल, जे एह प्रदेश के सभसे उत्तरी हिस्सा में बाने, के बाद तुरंते नीचे दक्खिन के ओर "भाबर" के इलाका हवे जहाँ हिमालयी नदी सभ द्वारा ले आइल बोल्डर आ मोट बालू के बनल जमीन हवे।<ref name=Preface>{{cite web|title=Purports to define every important meteorological term likely to be found in the literature today. |url=http://amsglossary.allenpress.com/glossary/preface1 |publisher=Allen Press,Inc. |accessdate=22 July 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120712214139/http://amsglossary.allenpress.com/glossary/preface1 |archivedate=12 July 2012 }}</ref> तराई आ भाबर के एह पातर पट्टी में इतिहासी रूप से घन [[बन]] रहल हवें, अभिन ले भी कुछ इलाका में बन मिले लें।<ref name="Singh1998">{{cite book|author=Vir Singh|title=Mountain Ecosystems: A Scenario of Unsustainability|url=https://books.google.com/books?id=SX7ML4-0oGQC&pg=PA102|accessdate=27 July 2012|publisher=Indus Publishing|isbn=978-81-7387-081-1|pages=102–264}}</ref>
===जलवायु===
<!-- {{main article|उत्तर प्रदेश के जलवायु}} -->
[[File:Monsoon clouds Lucknow.JPG|thumb|alt=refer to adjacent text|लखनऊ शहर के ऊपर मानसून के बादर।]]
उत्तर प्रदेश में [[नम उपोष्णकटिबंधी जलवायु]] होले आ साल में चार गो [[सीजन]] होला।<ref name="Board2008" /> दिसंबर से फरवरी के बीच जाड़ा, आ मार्च से मई ले गरमी के सीजन होला। एकरे बाद [[मानसून]] के सीजन आवे ला जून से सितंबर ले रहे ला।<ref name=Climate>{{cite web|title=Climate change impacts|url=http://upenvis.nic.in/Database/Climate_861.aspx|publisher=Uttar Pradesh climate department|accessdate=22 July 2012}}</ref> गर्मी के सीजन बहुत ढेर अतिमान वाला होला जब अधिकतम तापमान 48 °C से ऊपर ले चहुँप जाला।<ref name=climate009>{{cite web|title=Climate|url=http://www.webindia123.com/uttar/index.htm|publisher=Uttar Prades:Land. Suni System (P) Ltd.|accessdate=5 अगस्त 2012}}</ref> गंगा के मैदान में जलवायु उप-आर्द्र से ले के अर्द्ध-शुष्क के बीच पावल जाले।<ref name=Climate/> राज्य के औसत सालाना बरखा 650 मिमी होले जबकि उत्तरी-पूरबी कोने के जिला सभ में ई 1000 मिमी होले,<ref name=rainfall>{{cite web|last=Government of Uttar Pradesh, Lucknow|first=Irrigation Department Uttar Pradesh|title=Average rainfall pattern of Uttar Pradesh|url=http://idup.gov.in/wps/portal/!ut/p/c0/04_SB8K8xLLM9MSSzPy8xBz9CP0os3ifUEcnYzdTEwMLVy8TA89gU38XT-8AIwM3A_2CbEdFAHA_W1g!|publisher=Irrigation Department Uttar Pradesh|accessdate=22 July 2012|archive-date=24 August 2012|archive-url=https://web.archive.org/web/20120824174636/http://idup.gov.in/wps/portal/!ut/p/c0/04_SB8K8xLLM9MSSzPy8xBz9CP0os3ifUEcnYzdTEwMLVy8TA89gU38XT-8AIwM3A_2CbEdFAHA_W1g!|url-status=dead}}</ref> क्रम से पच्छिम के ओर बरखा के मात्रा में कमी आवत जाले। इहाँ ज्यादातर बरखा मानसून के बंगाल के खाड़ी वाली शाखा से होला। जाड़ा के सीजन में भी कुछ बरखा होले जे पच्छिमी डिस्टर्बेंस के कारण होले आ चक्रवाती प्रकार के होले।<ref name="Board2008">{{cite book|author=Upkar Prakashan - Editorial Board|title=Uttar Pradesh General Knowledge|url=https://books.google.com/books?id=_ce8FpJzR-4C&pg=PA26|accessdate=9 मार्च 2011|year=2008|publisher=Upkar Prakashan|isbn=978-81-7482-408-0|pages=26–}}</ref><ref name=WesDist>{{cite news|last=Sethi|first=Nitin|title=Met dept blames it on 'western disturbance'|url=http://articles.timesofindia.indiatimes.com/2007-02-13/india/27887812_1_met-dept-disturbance-rains|accessdate=9 मार्च 2011|newspaper=दि टाइम्स ऑफ इंडिया|date=13 February 2007|archive-date=2011-08-11|archive-url=https://web.archive.org/web/20110811031649/http://articles.timesofindia.indiatimes.com/2007-02-13/india/27887812_1_met-dept-disturbance-rains|url-status=dead}}</ref>
{{Weather box
|location = उत्तर प्रदेश
|metric first = yes
|single line = yes
|Jan high C = 29.9
|Feb high C = 31.9
|Mar high C = 35.4
|Apr high C = 37.7
|May high C = 36.9
|Jun high C = 31.7
|Jul high C = 28.4
|Aug high C = 27.4
|Sep high C = 29.4
|Oct high C = 31.4
|Nov high C = 30.1
|Dec high C = 28.9
|year high C =
|Jan low C = 11.0
|Feb low C = 12.1
|Mar low C = 15.8
|Apr low C = 19.9
|May low C = 22.4
|Jun low C = 22.9
|Jul low C = 22.2
|Aug low C = 21.6
|Sep low C = 20.8
|Oct low C = 18.5
|Nov low C = 14.4
|Dec low C = 11.5
|year low C =
|precipitation colour = green
|Jan precipitation mm = 0
|Feb precipitation mm = 3
|Mar precipitation mm = 2
|Apr precipitation mm = 11
|May precipitation mm = 40
|Jun precipitation mm = 138
|Jul precipitation mm = 163
|Aug precipitation mm = 129
|Sep precipitation mm = 155
|Oct precipitation mm = 68
|Nov precipitation mm = 28
|Dec precipitation mm = 4
|year precipitation mm =
|Jan precipitation days = 0.1
|Feb precipitation days = 0.3
|Mar precipitation days = 0.3
|Apr precipitation days = 1.1
|May precipitation days = 3.3
|Jun precipitation days = 10.9
|Jul precipitation days = 17.0
|Aug precipitation days = 16.2
|Sep precipitation days = 10.9
|Oct precipitation days = 5.0
|Nov precipitation days = 2.4
|Dec precipitation days = 0.3
|Jan sun = 291.4
|Feb sun = 282.8
|Mar sun = 300.7
|Apr sun = 303.0
|May sun = 316.2
|Jun sun = 186.0
|Jul sun = 120.9
|Aug sun = 111.6
|Sep sun = 177.0
|Oct sun = 248.44
|Nov sun = 270.0
|Dec sun = 288.3
|year sun =
|source 1 =<ref>{{cite web|url=http://125.21.185.44/citywx/city_weather1.php?id=42369 |title=Local Weather Report |publisher=Local Weather Report and Forecast Department |date=21 May 2012 |accessdate=18 July 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120501134209/http://125.21.185.44/citywx/city_weather1.php?id=42369 |archivedate=1 May 2012 }}</ref>||date=जून 2012
}}
<!-- [[File:Anandabodhi.jpg|thumb|alt=refer to adjacent text|Anandabodhi tree in Jetavana Monastery, [[Sravasti]]]]
[[File:Tropaeolum majus.jpg|thumb|right|alt=Tropaeolum majus|A hybrid nasturtium (''[[Tropaeolum majus]]'') showing nectar spur, found mainly in [[Hardoi district]]]]
-->
<center>
{| class="wikitable" style="text-align:center"
| colspan="13" style="text-align:center;font-size:120%;background:#E8EAFA;"|उत्तर प्रदेश के बिबिध शहर सभ के औसत ऊपरी आ निचला तापमान
|- style="background:#e5afaa; color:#000"
| '''शहर'''
| '''जन'''
| '''फर'''
| '''मार्च'''
| '''अप्रै'''
| '''मई'''
| '''जून'''
| '''जुल'''
| '''अग'''
| '''सित'''
| '''अक्टू'''
| '''नवं'''
| '''दिसं'''
|- style="background:#f8f3ca; color:#000"
|[[लखनऊ]]<ref name=lucknowweather>{{cite web|title=Weather Report & Forecast for Lucknow |url=http://www.imd.gov.in/section/climate/lucknow.htm |publisher=India Meteorological Department |accessdate=5 अक्टूबर 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20130208074134/http://www.imd.gov.in/section/climate/lucknow.htm |archivedate= 8 February 2013 |df= }}</ref>
| 73/44
| 79/49
| 90/58
| 101/69
| 105/76
| 102/81
| 92/79
| 90/78
| 92/76
| 91/66
| 79/53
| 75/45
|- style="background:#c5dfe1; color:#000"
| [[कानपुर]]<ref name=kanpurweather>{{cite web|title=Weather Report & Forecast for Kanpur |url=http://www.imd.gov.in/section/climate/kannur2.htm |publisher=India Meteorological Department |accessdate=5 अक्टूबर 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20140202134824/http://www.imd.gov.in/section/climate/kannur2.htm |archivedate=2 February 2014 }}</ref>
| 91/71
| 92/72
| 92/75
| 93/78
| 92/78
| 85/74
| 84/73
| 84/72
| 88/78
| 88/74
| 89/74
| 90/71
|- style="background:#f8f3ca; color:#000"
| [[गाजियाबाद]]<ref name=ghazForecast>{{cite web|title=Weather Report & Forecast for Ghaziabad |url=http://www.weather.com/weather/wxclimatology/monthly/INXX0051 |publisher=India Meteorological Department |accessdate=24 September 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20131113174957/http://www.weather.com/weather/wxclimatology/monthly/INXX0051 |archivedate=13 November 2013 }}</ref>
| 70/45
| 73/50
| 84/59
| 97/70
| 102/79
| 100/82
| 93/81
| 91/79
| 93/75
| 91/66
| 82/55
| 73/46
|- style="background:#c5dfe1; color:#000"
| [[इलाहाबाद]]<ref name=AllahabadForecast>{{cite web|title=Weather Report & Forecast for Allahabaad |url=http://www.imd.gov.in/section/climate/allahabad2.htm |publisher=India Meteorological Department |accessdate=24 September 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20121031015105/http://www.imd.gov.in/section/climate/allahabad2.htm |archivedate=31 अक्टूबर 2012 }}</ref>
| 74/47
| 81/52
| 92/62
| 103/73
| 108/80
| 104/83
| 93/79
| 91/78
| 92/77
| 92/69
| 86/57
| 77/49
|- style="background:#f8f3ca; color:#000"
| [[आगरा]]<ref name=agraweather>{{cite web|title=Weather Report & Forecast for Agra |url=http://www.imd.gov.in/section/climate/agra2.htm |publisher=India Meteorological Department |accessdate=5 अक्टूबर 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20140202135110/http://www.imd.gov.in/section/climate/agra2.htm |archivedate=2 February 2014 }}</ref>
| 72/45
| 75/51
| 90/60
| 101/72
| 107/80
| 105/84
| 95/79
| 91/78
| 93/76
| 93/67
| 85/55
| 75/47
|- style="background:#c5dfe1; color:#000"
| [[बनारस]]<ref name=varaweather>{{cite web|title=Weather Report & Forecast for Varanasi |url=http://www.imd.gov.in/section/climate/varanasi2.htm |publisher=India Meteorological Department |accessdate=5 अक्टूबर 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120709160100/http://www.imd.gov.in/section/climate/varanasi2.htm |archivedate=9 July 2012 }}</ref>
| 74/47
| 80/52
| 92/61
| 102/72
| 106/80
| 102/83
| 92/79
| 91/794
| 91/77
| 90/69
| 85/57
| 76/49
|- style="background:#f8f3ca; color:#000"
| [[गोरखपुर]]<ref name=gorweather>{{cite web|title=Weather Report & Forecast for Gorakhpur |url=http://www.imd.gov.in/section/climate/gorakhpur2.htm |publisher=India Meteorological Department |accessdate=5 अक्टूबर 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20100109193600/http://www.imd.gov.in/section/climate/gorakhpur2.htm |archivedate=9 January 2010 }}</ref>
| 74/49
| 80/53
| 91/72
| 103/77
| 99/79
| 92/78
| 91/78
| 91/76
| 91/70
| 85/59
| 76/51
| 76/49
|- style="background:#c5dfe1; color:#000"
| [[बरेली]]<ref name=bareiweather>{{cite web|title=Weather Report & Forecast for Bareilly |url=http://www.imd.gov.in/section/climate/bareilly2.htm |publisher=India Meteorological Department |accessdate=5 अक्टूबर 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120603055234/http://www.imd.gov.in/section/climate/bareilly2.htm |archivedate=3 जून 2012 }}</ref>
| 71/47
| 77/57
| 88/60
| 99/70
| 105/77
| 102/81
| 93/79
| 91/78
| 92/76
| 90/67
| 83/56
| 74/48
|}</center>
==बनस्पति आ जियाजंतु==
{| class="toccolours" style="margin:1em; float:right; width:25%;"
|+ '''उत्तर प्रदेश के राजकीय चीन्हा'''<ref>{{cite web |url=http://www.pannatigerreserve.in/kids/state.htm |title=State Animal, Bird, Tree and Flower |website=Panna Tiger Reserve |accessdate=29 अगस्त 2014 |archive-date=2014-10-13 |archive-url=https://web.archive.org/web/20141013002319/http://www.pannatigerreserve.in/kids/state.htm |url-status=dead }}</ref><ref name="dance">{{cite web |title=Music & Dance |url=http://uptourism.gov.in/pages/top/experience/top-experience-music-and-dance |website=uptourism.gov.in |publisher=''Uttar Pradesh Tourism'' |accessdate=3 मार्च 2017 |archive-date=2017-01-23 |archive-url=https://web.archive.org/web/20170123210405/http://www.uptourism.gov.in/pages/top/experience/top-experience-music-and-dance |url-status=dead }}</ref>
|-
| '''राजकीय पशु'''
| बारहसिंगा || [[File:The barasingha.jpg|50px]]
|-
| '''राजकीय पक्षी'''
| [[सारस]] || [[File:Grus antigone Luc viatour.jpg|50px]]
|-
| '''राजकीय वृक्ष'''
| अशोक || [[File:Ashoka (Polyalthia longifolia) flowers W IMG 7050.jpg|50px]]
|-
| '''राजकीय फूल'''
| पलाश || [[File:STS 001 Butea monosperma.jpg|50px]]
|-
| '''राजकीय नाच'''
| कत्थक || [[File:Kathak 3511900193 986f6440f6 b retouched.jpg|50px]]
|-
| '''राजकीय खेल'''
| हाकी || [[File:Field hockey.jpg|50px]]
|}
{{Multiple image
| align = left
| direction = vertical
| header =
| header_align = left/right/center
| header_background =
| footer =
| footer_align = left/right/center
| footer_background =
| width = 220
| image1 = Ganges calling.jpg|thumb
| width1 =
| alt1 =
| caption1 = [[तराई]] के इलाका
| image2 = Gavialis gangeticus, ZOO Praha 045.jpg|thumb
| width2 =
| alt2 =
| caption2 =[[घड़ियाल]] (''Gavialis gangeticus'') [[गंगा नदी]] में पावल जाला
}}
राज्य में प्राकृतिक संसाधन पर्याप्त रूप से मौजूद बा।<ref name=Flora>{{cite web|title=Uttar Pradesh Forest Corporation |url=http://www.upforestcorporation.in/Default.aspx |publisher=Forest department uttar pradesh |accessdate=23 जुलाई 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20130120145111/http://www.upforestcorporation.in/Default.aspx |archivedate=20 January 2013 |df= }}</ref> साल 2011 में राज्य में कुल दर्ज कइल गइल बन क्षेत्र {{convert|16583|km2|sqmi|abbr=on}} रहे जे राज्य के कुल भूगोली रकबा के 6.88% इलाका पर बिस्तार लिहले रहल।<ref name="fsiwbforest">{{cite web|url=http://www.fsi.org.in/cover_2011/uttarapradesh.pdf|format=PDF|title=Forest and tree resources in states and union territories: Uttar Pradesh|work=India state of forest report 2009|publisher=Forest Survey of India, Ministry of Environment & Forests, Government of India|accessdate=4 मार्च 2012|archive-date=2013-11-07|archive-url=https://web.archive.org/web/20131107201030/http://www.fsi.org.in/cover_2011/uttarapradesh.pdf|url-status=dead}}</ref> तेजी से बनकटाई आ जानवरन के शिकार के बावजूद अभिन ले राज्य में बनस्पति आ जियाजंतु के मामिला में भरपूर बिबिधता देखे के मिले ला। कई प्रकार के फेड़न के प्रजाति, बिबिध छोट-बड़ मैमल, रेप्टाइल आ कीड़ा-मकोड़ा के प्रजाति ऊपरी समशीतोष्ण जंगली इलाका में पावल जालीं। कई प्रकार के पौधा जंगली रूप से पावल जालें जे जड़ी-बूटी के तौर पर इस्तेमाल होलें<ref>{{cite web|url=http://bsienvis.nic.in/medi.htm#Balanites |title=Aegyptica |publisher=Bsienvis.nic.in |accessdate=21 September 2009 |url-status=dead |archiveurl=https://web.archive.org/web/20090506192204/http://bsienvis.nic.in/medi.htm |archivedate=6 May 2009 }}</ref> आ एह तरह के दवा-बीरो वाला पौधा सभ के ब्यापारिक रूप से भी उपजावल जाला। तराई-दुआर इलाका में चारा के रूप में इस्तेमाल होखे वाली घास भी मिले ले आ कागज उद्योग में इस्तेमाल होखे वाली घास भी। नम-पतझड़ वाला फेड़ सभ गंगा के मैदान में नदी के किनारे वाला इलाका में पावल जालें। ई मैदान बिबिध प्रकार के कीरा-बिच्छी आ अन्य रेंगे वाला जंतु सभ के आवास भी हवे। गंगा आ अन्य नद्दी सभ में बिबिध प्रजाति के मछरी आ खेखड़ा, झींगा, डोंका वगैरह भी मिले लें। बिंध्य इलाका आ पठारी भाग में बब्बुर आ औरी अइसने सूखा इलाका के फेड़ मिले लें। चिंकारा पुराना समय में बहुत पावल जाय आ नीलगाय अभिन भी बहुत संख्या में मिले लीं।<ref name=animals>{{cite web|title=Bird Sanctuary |url=http://www.up-tourism.com/destination/wild_life/wild_life.htm |publisher=U.P tourism |accessdate=23 July 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120704191031/http://www.up-tourism.com/destination/wild_life/wild_life.htm |archivedate=4 July 2012 }}</ref><ref name=Predominant>{{cite web|title=Sanctuary Park in U.P |url=http://www.up-tourism.com/destination/wild_life/places_of_interest.htm#Suhelva |publisher=U.P tourism |accessdate=23 July 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120718025605/http://www.up-tourism.com/destination/wild_life/places_of_interest.htm |archivedate=18 July 2012 }}</ref>
पूरा मैदानी इलाका में उष्णकटिबंधीय पतझड़ वाली बनस्पति मिले ले आ जमीन ले भरपूर घाम के पहुँच के चलते घास आ झाड़ीदार पौधा भी खूब पावल जालें।<ref name="Vegetation and Flora">{{cite web|title=Few patches of natural forest|url=http://upgov.nic.in/upwealth.aspx|publisher=State government of Uttar Pradesh|accessdate=22 July 2012|archive-date=20 May 2012|archive-url=https://web.archive.org/web/20120520140217/http://upgov.nic.in/upwealth.aspx|url-status=dead}}</ref> खेती बदे, प्राचीन समय में मैदानी इलाका के जंगल सभ के साफ़ कइल गइल आ अब कहीं-कहीं कुछ टुकड़ा बचल बाने जहाँ प्राकृतिक जंगल होखे। दक्खिनी हिस्सा में पठारी भाग में अइसन कुछ इलाका बचल बाने जहाँ कांटेदार पौधा आ सूखा इलाका वाली झाडी के इलाका पथरीला जमीन होखे के कारण साफ़ नइखे कइल गइल।<ref name="Thorny Forest">{{cite web|last=The Forests and biodiversity|first=in UP are important in many ways|title=Miscellaneous Statistics|url=http://upenvis.nic.in/Database/Forest_838.aspx|publisher= Ministry of Environment and Forests|accessdate=22 July 2012}}</ref> अइसन जंगल कम बरखा वाला क्षेत्र (50–70 सेमी), आ औसत तापमान 25-27 °C आ कम नमी वाला क्षेत्र में बाने।
उत्तर प्रदेश में चिरई सभ के बिबिध प्रजाति मिले लीं।<ref name=Avifauna>{{cite web|title=Conservation of the Avifauna|url=http://ww.orientalbirdclub.org/publications/forktail/14pdfs/Javed-Dudwa.pdf|publisher=[[Dudhwa National Park]]|accessdate=20 July 2012}}{{Dead link|date=November 2023 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> प्रमुख प्रजाति में [[घरेलू गौरइया]], मैना, गंगा मैना, पंडुक, कबूतर, मोर, सुग्गा, कोयल, बुलबुल, चोंचा, मछरेंगा, कठफोड़वे, आ अउरी कई चिरई गिनावल जा सके लीं। राज्य में बखीरा, चंबल, चंद्रप्रभा, हस्तिनापुर, कैमूर आ सुरहा ताल नियर कई गो पक्षी-बिहार स्थापित कइल गइल बाने।<ref name="sanctuaries">{{cite web|title=Major wildlife sanctuaries and reserves of Uttar Pradesh|url=https://sites.google.com/site/viveklpm/wild-and-zoo-animal-care-and-management/major-wildlife-sanctuaries-and-reserves-in-india/major-wildlife-sanctuaries-and-reserves-of-uttar-pradesh|publisher=''sites.google.com''|accessdate=4 February 2017}}</ref><ref name="Bakhira">{{cite web |title= Bakhira Bird Sanctuary |url= http://upforest.gov.in/StaticPages/bakhirabird_Home.aspx |website= upforest.gov.in |publisher= ''UP Forest and Wildlife Department'' |accessdate= 4 February 2017 |archive-date= 4 February 2017 |archive-url= https://web.archive.org/web/20170204170352/http://upforest.gov.in/StaticPages/bakhirabird_Home.aspx |url-status= dead }}</ref><ref name="Chambal Gharial">{{cite web|title=National Chambal Gharial Wildlife Sanctuary|url=http://nationalchambalsanctuary.in/|publisher=''National Chambal Sanctuary''|accessdate=4 February 2017|archive-date=1 January 2017|archive-url=https://web.archive.org/web/20170101110955/http://www.nationalchambalsanctuary.in/|url-status=dead}}</ref><ref name="Chandra Prabha">{{cite web |title=Chandra Prabha Wildlife Sanctuary And Picnic Spots |url=http://www.uptourism.gov.in/pages/top/explore/top-explore-chandra-prabha |website=uptourism.gov.in |publisher=''Uttar Pradesh Tourism'' |accessdate=4 February 2017 |archive-date=4 February 2017 |archive-url=https://web.archive.org/web/20170204170953/http://www.uptourism.gov.in/pages/top/explore/top-explore-chandra-prabha |url-status=dead }}</ref><ref name="Hastinapur Wild Life">{{cite web |title= Hastinapur Wild Life Sanctuary |url= http://upforest.gov.in/STATICpages/hastinapurwild_Home.aspx |website= upforest.gov.in |publisher= ''P Forest and Wildlife Department'' |accessdate= 4 February 2017 |archive-date= 4 February 2017 |archive-url= https://web.archive.org/web/20170204170724/http://upforest.gov.in/STATICpages/hastinapurwild_Home.aspx |url-status= dead }}</ref><ref name="Kaimoor Wild Life">{{cite web |title= Kaimoor Wild Life Sanctuary |url= http://upforest.gov.in/StaticPages/kaimoorwildlife_Home.aspx |website= upforest.gov.in |publisher= ''Forest and Wildlife Department Uttar Pradesh'' |accessdate= 4 February 2017 |archive-date= 4 February 2017 |archive-url= https://web.archive.org/web/20170204171033/http://upforest.gov.in/StaticPages/kaimoorwildlife_Home.aspx |url-status= dead }}</ref><ref>{{cite web |title= Inside Okhla Bird Sanctuary |url= http://upforest.gov.in/STATICpages/okhlabird_Home.aspx |website= upforest.gov.in |publisher= ''UP Forest and Wildlife Department'' |accessdate= 4 February 2017 |archive-date= 4 February 2017 |archive-url= https://web.archive.org/web/20170204171135/http://upforest.gov.in/STATICpages/okhlabird_Home.aspx |url-status= dead }}</ref>
रेप्टाइल, यानी रेंगे वाला जीव में बिस्तुइया, गिरगिट, गोह, कोबरा (गहुअन), करइत, धामिन, घड़ियाल वगैरह पावल जाला। महसीर, टेंगना आ ट्राउट मछरी पावल जालीं। कई जियाजंतु सभ जे पहिले इहाँ पावल जायँ अब बिलुप्त भी हो चुकल बाने आ कई खतरा में भी बाने।<ref name="S.k.agarwal">{{cite book|author=S. K. Agarwal|title=Environment Biotechnology|url=https://books.google.com/books?id=0UeDTX6HEK8C&pg=PA61|accessdate=25 July 2012|publisher=APH Publishing|isbn=978-81-313-0294-1|page=61}}</ref> सरकार के कोसिस के बावजूद कई तरह के जानवरन के शिकार से भी खतरा बा।<ref name=fauna>{{cite web|title=Processing of manuscripts of Fauna |url=http://zsi.gov.in/right_menu/Annual%20Meeting/Annual%20Meeting%202011-12/HQ/Fauna.pdf |publisher=Indian Government |accessdate=22 July 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20130505093620/http://zsi.gov.in/right_menu/Annual%20Meeting/Annual%20Meeting%202011-12/HQ/Fauna.pdf |archivedate=5 May 2013 }}</ref>
=={{anchor|Constituent regions}}{{anchor|Regions and cities}}प्रशासनिक बिभाजन आ शहर==
[[File:Uttar Pradesh administrative divisions.svg|right|thumb|200px|alt="Administrative Divisions"|[[उत्तर प्रदेश के मंडल सभ]]]]
{{Main article|उत्तर प्रदेश के मंडल सभ|उत्तर प्रदेश के जिला सभ के लिस्ट}}
उत्तर प्रदेश के प्रशासनिक रूप से कुल 75 गो जिला में बाँटल गइल बा आ ई जिला 18 गो मंडल में ब्यवस्थित बाने।<ref name=divisions>{{cite web|title=State division of Uttar Pradesh |url=http://india.gov.in/knowindia/districts/andhra1.php?stateid=UP |publisher=Government of India |accessdate=22 जुलाई 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120510202421/http://india.gov.in/knowindia/districts/andhra1.php?stateid=UP |archivedate=10 मई 2012 }}</ref> हर जिला के प्रशासन जिलाधिकारी के हाथ में होला जे एगो आईएएस अधिकारी होलें। मंडल यानि कमिशनरी के मुखिया कमिश्नर (मंडलायुक्त) होलें।
हर एक जिला के कई गो तहसील में बाँटल गइल बा। तहसील के प्रशासन के काम डिप्टी कलक्टर (एसडीएम) के जिम्मे होला आ ऊ लोग जिलाधिकारी (डीएम) के रिपोट करे ला। तहसील के नीचे ब्लॉक होलें, हालाँकि ई प्रशासनिक स्तर न हवें बलुक पंचायती राज आ बिकास के कामकाज खातिर बनावल इकाई हऽ। ब्लाक यानि बिकासखंड स्तर पर बीडीओ राज्य के अधिकारी आ ब्लाक प्रमुख जनता के प्रतिनिधि होलें। हर ब्लाक के ग्रामपंचायत में बाँटल गइल बा, एकर मुखिया जनता द्वारा चुनल प्रतिनिधि - ग्राम परधान होलें। एक ठो ग्राम पंचायत में कई गो गाँव सामिल हो सके लें।<ref name=blocks>{{cite web|title=Directory of district, sub division, panchayat samiti/ block and gram panchayats in Uttar Pradesh|url=http://panchayatiraj.up.nic.in/Acts%20And%20Rules%20Pdfs/Panchayat%20Raj%20Act_1947_ch6.57-70.pdf|work=Panchayati Raj Department|accessdate=5 अक्टूबर 2012}}</ref> ब्लाक में शहरी इलाका भी हो सके लें, जइसे छोट जनगणना कस्बा (''सेंसस टाउन'')<ref name=panchayat>{{cite web|title=Administration of block|url=http://panchayatiraj.up.nic.in/Acts%20And%20Rules%20Pdfs/Panchayat%20Raj%20Act_1947_ch4.38-50.pdf|work=Panchayati Raj Department|accessdate=5 अक्टूबर 2012}}</ref> जबकि बड़हन नगर सभ में अलग से नगर पंचायत के गठन होला।
उत्तर प्रदेश में सभसे बड़हन प्रशासनिक बिभाग, 18 गो मंडल सभ के लिस्ट नीचे दिहल बा:
{| style="margin-left:30px"
{{col-begin}}
{{col-break|width=57%}}
{{ordered list|start=1
|[[सहारनपुर मंडल|सहारनपुर]]
|[[मुरादाबाद मंडल|मुरादाबाद]]
|[[बरेली मंडल|बरेली]]
|[[लखनऊ मंडल|लखनऊ]]
|[[देवीपाटन मंडल|देवीपाटन]]
|[[बस्ती मंडल|बस्ती]]
|[[गोरखपुर मंडल|गोरखपुर]]
|[[मेरठ मंडल|मेरठ]]
|[[अलीगढ़ मंडल|अलीगढ़]]
}}
{{col-break}}
{{ordered list|start=10
|[[आगरा मंडल|आगरा]]
|[[कानपुर मंडल|कानपुर]]
|[[फैजाबाद मंडल|फैजाबाद]]
|[[आजमगढ़ मंडल|आजमगढ़]]
|[[झाँसी मंडल|झाँसी]]
|[[चित्रकूट मंडल|चित्रकूट]]
|[[इलाहाबाद मंडल|इलाहाबाद]]
|[[वाराणसी मंडल|वाराणसी]]
|[[मिर्जापुर मंडल|मिर्जापुर]]|
}}
{{Col-end}}
|}
नीचे उत्तर प्रदेश के सभसे ढेर जनसंख्या वाला छह गो जिला आ भारत के जिला सभ में इनहन के रैंक दिहल गइल बा:<ref name=districts1>{{cite web|title=Indian Districts by population|url=http://www.census2011.co.in/district.php|work=2011 Census of India|accessdate=5 अक्टूबर 2012}}</ref>
{| class="sortable wikitable"
|- style="background:#ccc; text-align:center;"
! रैंक (भारत में) !! जिला !! जनसंख्या !! बढ़ती दर (%) !! लिंगानुपात (औरत, प्रति 1000 पुरुष पर) !! साक्षरता (%)
|- style="vertical-align: middle; text-align: center;"
| 13 || [[इलाहाबाद जिला|इलाहाबाद]] || 5,954,391 || 20.63 || 901 || 72.32
|- style="vertical-align: middle; text-align: center;"
| 26 || [[मुरादाबाद जिला|मुरादाबाद]] || 4,772,006 || 25.22 || 906 || 56.77
|- style="vertical-align: middle; text-align: center;"
| 27 || [[गाजियाबाद जिला|गाजियाबाद]] || 4,681,645 || 42.27 || 881 || 78.07
|- style="vertical-align: middle; text-align: center;"
| 30 || [[आजमगढ़ जिला|आजमगढ़]] || 4,613,913 || 17.11 || 1019 || 70.93
|- style="vertical-align: middle; text-align: center;"
| 31 || [[लखनऊ जिला|लखनऊ]] || 4,589,838 || 25.82 || 917 || 77.29
|- style="vertical-align: middle; text-align: center;"
| 32 || [[कानपुर नगर जिला|कानपुर नगर]] || 4,581,268 || 9.92 || 862 || 79.65
|}
{| class="infobox" style="text-align:center; width:; margin-right:8px; font-size:90%"
! colspan=1 |
! colspan="6" style="padding:0.6em 0; line-height:1.1em;" | [[जनसंख्या अनुसार उत्तर प्रदेश के शहरन के लिस्ट|उत्तर प्रदेश के दसलाखी शहर]] (2011 के जनगणना)
! colspan=1 |
|-
! style="text-align:left;background:#f5f5f5;" | नाँव
! style="text-align:left;background:#f5f5f5;" | जनसंख्या
! style="text-align:center;background:#f5f5f5;" |
! style="text-align:center;background:#f5f5f5;" |
! style="text-align:left;background:#f5f5f5;" | नाँव
! style="text-align:left;background:#f5f5f5;" | जनसंख्या
! rowspan=11 |
<!-- Please do not change population numbers for individual metro areas. These numbers are all from the 2011 census and are all for CMA's (census metropolitan areas). Using different definitions of metro area or population estimates from different years or sources depending on the city provides a poor basis for comparison and ranking of the cities. You can find the census population data at http://censusindia.gov.in/2011-prov-results/prov_data_products_up.htmlLANG=Eng&T=201&S=3&O=D&RPP=150 -->
|-
| style="text-align:left;background:#f0f0f0;" | [[कानपुर]] || 2,920,067 || ||||style="text-align:left;background:#f0f0f0;"|[[लखनऊ]] || 2,901,474
|-
| style="text-align:left;background:#f0f0f0;" | [[गाजियाबाद]] || 2,358,525 || ||||style="text-align:left;background:#f0f0f0;" |[[आगरा]] || 1,746,467
|-
| style="text-align:left;background:#f0f0f0;" | [[बनारस]] || 1,435,113 || ||||style="text-align:left;background:#f0f0f0;" | [[मेरठ]] || 1,424,908
|-
| style="text-align:left;background:#f0f0f0;" | [[इलाहाबाद]] || 1,216,719 || ||||style="text-align:left;background:#f0f0f0;" |[[बरेली]] || 979,933
|}
अन्य राज्य सभ के तुलना में, उत्तर प्रदेश में [[जनसंख्या अनुसार उत्तर प्रदेश के शहरन के लिस्ट|सभसे ढेर मेट्रो शहर]] बाने।<ref name="metropolitan cities">{{cite news|title=Development of 13 metropolitan cities in Uttar Pradesh|url=http://www.indianexpress.com/news/panels-to-draft-development-plans-for-13-cities/674326/|accessdate=13 जुलाई 2012|newspaper=The Indian Express|date=30 अगस्त 2010}}</ref><ref name="Metro cities">{{cite web|title=The area and density of metropolitan cities |url=http://urbanindia.nic.in/theministry/subordinateoff/tcpo/AREA_POP/CHAPTER-4.PDF |publisher=The Ministry of Urban Development |accessdate=22 जुलाई 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20121015142027/http://urbanindia.nic.in/theministry/subordinateoff/tcpo/AREA_POP/CHAPTER-4.PDF |archivedate=15 अक्टूबर 2012 |df= }}</ref> राज्य के कुल वास्तविक शहरी जनसंख्या 44.4 मिलियन रहल, ई भारत के कुल शहरी जनसंख्या के 11.8% बा आ एह तरीका से अन्य राज्यन के तुलना में उत्तर प्रदेश दूसरा स्थान पर बा।<ref name="Population info">{{cite web|title=Provisional population totals, Census of India 2011 |url=http://censusindia.gov.in/2011-prov-results/paper2/data_files/india/Rural_Urban_2011.pdf |publisher=Census of India 2011 |format=PDF |page=19 |accessdate=14 मार्च 2012}}</ref> जनगणना 2011 के अनुसार, कुल 15 गो शहरी संकुल अइसन रहलें जिनहन के जनसंख्या 5,00,000 से ढेर रहल।<ref name=Datasheet>{{cite web|title=Provisional population totals paper 1 of 2011 : Uttar Pradesh|url=http://censusindia.gov.in/2011-prov-results/prov_data_products_up.html|publisher=Census of India 2011|accessdate=23 July 2012 }}</ref> कुल 14 गो नगर निगम रहलें, आ नोएडा अलग से एगो बिधिक संस्था द्वारा प्रशासित कइल जाला।<ref name="GENERAL AMENDMENT">{{cite web |title=The Uttar Pradesh municipal corporation |url=http://sec.up.nic.in/acts_rules/MUNICIPAL%20CORPORATION_1959_eng/Municipal_Corp_Act_1959_chap1.pdf |publisher=Municipal corporation of Uttar Pradesh |url-status=dead |archiveurl=https://web.archive.org/web/20120324141206/http://sec.up.nic.in/acts_rules/MUNICIPAL%20CORPORATION_1959_eng/Municipal_Corp_Act_1959_chap1.pdf |archivedate=24 मार्च 2012 |accessdate=22 जुलाई 2012}}</ref>
साल 2011 में, मायावती के मुख्यमंत्री काल में कैबिनेट मंत्री लोग ई निश्चय कइल कि उत्तर प्रदेश के चार गो राज्यन में बाँट दिहल जाय - पूर्वांचल, बुंदेलखंड, अवध प्रदेश आ पच्छिम प्रदेश। इनहन में क्रम से अठाईस, सात, तेईस, आ सत्रह गो जिला शामिल कइल जाए वाला रहलें। 2012 के चुनाव में जीत पावे वाली समाजवादी पार्टी के अखिलेश सरकार एह प्रस्ताव के नकार दिहलस।<ref>{{cite web | url=http://www.thehindu.com/todays-paper/article2631472.ece | title=Maya splits U.P. poll scene wide open | publisher=[[दि हिंदू]] | date=16 नवंबर 2011 | accessdate=15 जून 2013 | author=Khan, Atiq |location=Lucknow}}</ref>
==जनसांख्यिकी==
{{main article|उत्तर प्रदेश के जनसांख्यिकी}}
{{IndiaCensusPop
| title= जनसंख्या बढ़ती
| 1951= 60274000
| 1961= 70144000
| 1971= 83849000
| 1981= 105137000
| 1991= 132062000
| 2001= 166198000
| 2011= 199581477
| estimate=
| estyear=
| estref=
| footnote=स्रोत:भारत के जनगणना
}}
{{Pie chart
|thumb = right
|caption = उत्तर प्रदेश में धर्म (2011)<ref name=census2011>{{cite web
|publisher= Office of the Registrar General and Census Commissioner, India | url=http://www.census2011.co.in/data/religion/state/9-uttar-pradesh.html | title=Uttar Pradesh Religion Census 2011 |accessdate=2011-12-04}}</ref>
|label1 = [[हिंदू धर्म|हिंदू]]
|color1 = Orange
|value1 = 79.73
|label2 = [[इस्लाम]]
|color2 = Green
|value2 = 19.26
|label3 = [[सिख धर्म|सिख]]
|color3 = DarkKhaki
|value3 = 0.32
|label4 = [[ईसाई धर्म|इसाई]]
|color4 = DodgerBlue
|value4 = 0.18
|label5 = [[जैन धर्म|जैन]]
|color5 = red
|value5 = 0.11
|label6 = अन्य धर्म
|color6 = Gray
|value6 = 0.51
}}
उत्तर प्रदेश बिसाल जनसंख्या आ तेज जनसंख्या बढ़ती दर वाला राज्य बा। 1991 से 2001 के बीच प्रदेश के जनसंख्या में 26% के बढ़ती भइल।<ref name=population>{{cite web|title=The density of population in U.P. |url=http://upenvis.nic.in/Database/Overview_847.aspx |publisher=Environment and Related Issues Department U.P|accessdate=23 जुलाई 2012}}</ref> ई भारत के सभसे ढेर जनसंख्या वाला राज्य हवे, जहाँ 1 मार्च 2011 के कुल 199,581,477 निवासी लोग रहल।<ref name=autogenerated7>{{cite web|title=Provisional population totals|url=http://censusindia.gov.in/2011-prov-results/paper2/data_files/UP/7-pop-12-22.pdf|publisher=Census of India 2011|accessdate=23 जुलाई 2012}}</ref> एह तरीका से भारत देस के कुल जनसंख्या में उत्तर प्रदेश के हिस्सा 16.16% रहल। भले उत्तर प्रदेश भारत के चउथा सभसे बड़हन रकबा वाला राज्य होखे, एतना बिसाल जनसंख्या के कारण इहाँ के जनघनत्व 828 ब्यक्ति प्रति वर्गकिलोमीटर बा आ ई देस के सभसे घन बसल राज्यन में से एक बा।
2011 में, उत्तर प्रदेश में मानव लिंगानुपात 908 रहल (यानी 1000 मरदाना पर 908 जनाना), जे पूरा देस के औसत लिंगानुपात 933 के तुलना में कम रहल।<ref name="GOI_2011">{{cite web|title=Statistics of Uttar Pradesh|url=http://upgov.nic.in/upstateglance.aspx|work=Census of India 2011|publisher=UP Government|date=1 मार्च 2011|accessdate=31 जुलाई 2012|archive-date=2012-04-26|archive-url=https://web.archive.org/web/20120426235914/http://upgov.nic.in/upstateglance.aspx|url-status=dead}}</ref> 2001–2011 के बीच दशकीय बृद्धि दर (उत्तराखंड के सामिल क के) 20.09% रहल जे देस भर के औसत 17.64% से ढेर रहल।<ref name=Decennial>{{cite web|title=Decennil growth of population by census|url=http://www.cwc.nic.in/Water_Data_Pocket_Book_2006/t9.01final.pdf|work=Census of India (2011)|accessdate=5 अक्टूबर 2011|archive-date=2009-04-10|archive-url=https://web.archive.org/web/20090410021912/http://www.cwc.nic.in/Water_Data_Pocket_Book_2006/t9.01final.pdf|url-status=dead}}</ref><ref name=decennialgrowth>{{cite web|title=Decennial growth rate and density for 2011 at a glance for Uttar Pradesh and the districts: provisional population totals paper 1 of 2011 |url=http://www.censusindia.gov.in/2011-prov-results/prov_data_products_up.html|work=Census of India(2011)|accessdate=5 अक्टूबर 2011}}</ref> उत्तर प्रदेश में गरीबी रेखा से नीचे जीवन बितावे वाला लोग के भी भारी जनसंख्या बाटे।<ref name=poverty/> योजना आयोग के रिलीज कइल अनुमान के मोताबिक राज्य में कुल 59 मिलियन (5.9 करोड़) लोग गरीबी रेखा से नीचे रहल जे पूरा भारत के अउरी कवनो भी राज्य के तुलना में ढेर रहल।<ref name=poverty>{{cite web |title=The state with large no. of peoples living below poverty line|url=http://pib.nic.in/newsite/erelease.aspx?relid=49731 |work=Government of India|publisher=Press Information Bureau|accessdate=5 अक्टूबर 2012}}</ref><ref name=commission>{{cite web |url=http://planningcommission.nic.in/news/pre_pov2307.pdf |title=Press Note on Poverty Estimates, 2011-12 |website=योजना आयोग |publisher=भारत सरकार |accessdate=11 अगस्त 2014}}</ref>
2011 के जनगणना के अनुसार, भारत के सभसे ढेर जनसंख्या वाला उत्तर प्रदेश, कुल हिंदू आ मुसलमान जनसंख्या के मामिला में भी सभसे ऊपर रहल।<ref>{{cite web|url=http://www.deccanherald.com/content/497347/muslim-population-grew-faster-census.html|title=Muslim population grew faster: Census}}</ref> धरम के आधार पर, साल 2011 के जनसंख्या में 79.73% हिंदू, 19.26% मुसलमान, 0.32% सिख, 0.18% ईसाई, 0.11% जैन, 0.10% बौद्ध, आ 0.30% अन्य दूसर धरम माने वाला लोग रहल।<ref>[http://www.censusindia.gov.in/2011census/C-01/DDW09C-01%20MDDS.XLS C1 - Population by religious community, Uttar Pradesh.] भारत के जनगणना, 2011. पहुँचतिथि 10 सितंबर 2011.</ref>
राज्य में 2011 के आँकड़ा अनुसार साक्षारता दर 67.7% रहल, जे राष्ट्रीय औसत 74% से कमे रहल।<ref name="Literacy rate">{{cite web|title=Uttar Pradesh Profile |url=http://censusindia.gov.in/2011census/censusinfodashboard/stock/profiles/en/IND009_Uttar%20Pradesh.pdf|publisher=Census of India 2011|accessdate=16 अक्टूबर 2010}}</ref><ref name="literacy rates">{{cite web |title= A comparison of the literacy rates |url= http://censusmp.gov.in/censusmp/All-PDF/6Literacy21.12.pdf |publisher= censusmp.gov.in |accessdate= 16 अक्टूबर 2010 |archive-date= 2012-04-17 |archive-url= https://web.archive.org/web/20120417110338/http://censusmp.gov.in/censusmp/All-PDF/6Literacy21.12.pdf |url-status= dead }}</ref> पुरुष साक्षारता 79% आ औरतन के साक्षरता दर 59% रहल। एकरे पहिले, 2001 के जनगणना में कुल साक्षरता दर 56.27%, पुरुष साक्षरता 67% आ औरतन के साक्षरता दर 43% दर्ज कइल गइल रहल।<ref name=Literacy>{{cite web |title=Literacy rate in Uttar Pradesh |url= http://www.census2011.co.in/census/state/uttar+pradesh.html |publisher= Census of India 2011 |accessdate= 16 अक्टूबर 2010}}</ref>
[[हिंदी भाषा|हिंदी]]इहाँ के प्रमुख भाषा हवे आ आँकड़ा के मोताबिक (91.32%) लोग<ref name="2011lang">{{cite web|url=http://nclm.nic.in/shared/linkimages/NCLM50thReport.pdf |title=Report of the Commissioner for linguistic minorities: 50th report (July 2012 to जून 2013) |publisher=Commissioner for Linguistic Minorities, Ministry of Minority Affairs, Government of India |format=PDF |accessdate=4 दिसंबर 2016 |url-status=dead |archiveurl=https://web.archive.org/web/20160708012438/http://nclm.nic.in/shared/linkimages/NCLM50thReport.pdf |archivedate= 8 जुलाई 2016 |df= }}</ref> अपना के हिंदी भाषी बतावल। [[उर्दू]] दुसरही भाषा हवे जे राजकाज में इस्तेमाल होले।<ref name="2011lang"/> [[भोजपुरी]] अन्य प्रमुख भाषा बा जे पूर्वांचल में बिसाल जनसंख्या द्वारा बोलल जाले हालाँकि, भारत सरकार एकरा के हिंदी के बोली माने ले जवना कारण भोजपुरी आ हिंदी दूनो के वास्तविक बोले वाला लोग के संख्या के अंजाद लगावल कठिन बा।
==सरकार आ प्रशासन==
{{Main article|उत्तर प्रदेश सरकार}}
[[File:Vidhan Sabha (at day).jpg|thumb|alt=उत्तर प्रदेश के बिधान सभा के बिल्डिंग|उत्तर प्रदेश बिधानसभा, ई उत्तर प्रदेश के बिधायिका के निचला सदन हवे|453x453px]]
राज्य कसे शासन प्रातिनिधिक लोकतंत्र के संसदीय सिस्टम से चले ला। उत्तर प्रदेश भारत के सात गो अइसन राज्य सभ में से एक बा जहाँ दू सदन वाली विधायिका बाटे: निचला सदन के बिधान सभा आ ऊपरी सदन के बिधान परिषद कहल जाला।<ref name="vidhan parishad">{{cite web|title=UP vidhan parishad|url=http://legislativebodiesinindia.nic.in/UttarPradesh-LC.htm|publisher=Government of India|accessdate=22 July 2012}}</ref><ref name="Vidhan Sabha">{{cite web|title=UP vidhan sabha structure|url=http://legislativebodiesinindia.nic.in/UTTAR%20PRADESH.htm|publisher=Government of India|accessdate=22 July 2012}}</ref> उत्तर प्रदेश बिधान सभा में कुल 404 सीट बा इनहन खातिर जनता सीधे आपन प्रतिनिधि चुने ले जे लोग के बिधायक कहल जाला। बिधान सभा के सदस्य, यानी ई बिधायक लोग पाँच बरिस खातिर चुनल जाला। उत्तर प्रदेश के बिधान परिषद, यानी ऊपरी सदन, 100 सदस्य वाला एगो परमानेंट सदन हवे आ दू तिहाई सदस्य (33 गो) हर दूसरा साल चुनल जाला। चूँकि, भारतीय संसद में उत्तर प्रदेश के सभसे ढेर लेजिस्लेटर (सांसद) लोग जाला, ई राज्य देस के राजनीति मेंभी बहुत महत्व के मानल जाला।<ref name="elections">{{cite web|last=Four other states seen as barometer of support for federal government.|title=Legislative elections in Uttar Pradesh|url=http://www.aljazeera.com/news/asia/2012/02/2012286478579763.html|publisher=Al Jazeera|accessdate=8 फरवरी 2012}}</ref> भारतीय संसद में 80 गो लोक सभा सदस्य आ 31 गो राज्यसभा सदस्य उत्तरे प्रदेश के होला लोग।<ref>{{cite web|url=http://164.100.47.5/Newmembers/memberstatewise.aspx |title=Statewise List |publisher=164.100.47.5 |date= |accessdate=29 जुलाई 2015}}</ref><ref>{{cite web|url=http://rajyasabha.nic.in/rsnew/faq/freaq1.asp |title=Rajya Sabha |publisher=Rajya Sabha |date= |accessdate=29 जुलाई 2015}}</ref><ref name="Grover1989">{{cite book|author=Verinder Grover|title=Legislative Council in State Legislatures|url=https://books.google.com/books?id=fRqrO0Hx0Y0C&pg=PA37|accessdate=27 जुलाई 2012|publisher=Deep & Deep Publications|isbn=978-81-7100-193-4|pages=37–255}}</ref><ref>{{cite web |url= http://rajyasabha.nic.in/rsnew/rsat_work/chapter-2.pdf|format=PDF|title=राज्य सभा के संघटन |work=राज्य सभा |publisher=राज्य सभा सेक्रेट्रीयेट |location=नई दिल्ली |pages=24–25 |accessdate=15 फरवरी 2012}}</ref>
उत्तर प्रदेश में लोकतांत्रिक रूप से शासन के संबैधानिक मुखिया राज्यपाल (गवर्नर) होलें जिनके नियुक्ति राष्ट्रपति द्वारा कइल जाला। राज्यपाल के कार्यकाल पाँच साल होला।<ref>{{cite web |title=Role of The Governor |url= http://upgovernor.gov.in/upgovernor.gov.in/roleofgov.htm |website= upgovernor.gov.in |publisher=''Raj Bhavan Uttar Pradesh''|accessdate=17 मार्च 2017}}</ref> बिधान सभा में मेजारिटी के दल भा गठबंधन के नेता के राज्यपाल द्वारा मुख्यमंत्री नियुक्त कइल जाला आ इनके सलाह अनुसार बाकी मंत्रिमंडल के भी नियुक्ति राज्यपाले करे लें। प्रतीकात्मक रूप से सरकार के मुखिया राज्यपाल होलें आ रोजमर्रा के सरकारी कामकाज के जिम्मेदारी मुख्यमंत्री आ उनके मंत्रिमंडल के होला।
हर जिला के प्रशासन जिलाधिकारी (डीएम) के हाथे होला जे भारतीय प्रशासनिक सेवा (आइएएस) अधिकारी होलें आ इनके मातहत राज्य सेवा के अधिकारी लोग होला।<ref name=judiciary>{{cite web |title= Judiciary in the state |url= http://www.allahabadnagarnigam.in/Hindi/download_hindifont_hin.htm |publisher= इलाहाबाद नगर निगम |accessdate= 17 फरवरी 2011 |archive-date= 2012-08-01 |archive-url= https://web.archive.org/web/20120801195906/http://www.allahabadnagarnigam.in/hindi/download_hindifont_hin.htm |url-status= dead }}</ref> पुलिस कप्तान ({{abbr|एसपी|सुपरिंटेंडेंट ऑफ पुलिस}}), भारतीय पुलिस सेवा (आइपीएस) अधिकारी होलें आ इनके सहायता में राज्य पुलिस के अधिकारी लोग होला।<ref name="BhargavaBhatt2005"/> न्यायपालिका में इहाँ सभसे ऊपर [[इलाहाबाद हाइकोर्ट]] बा जेकर एगो बेंच लखनऊ में भी बा। एकरे नीचे हर जिला में जिला न्यायालय आ सत्र न्यायालय बाने आ तहसील स्तर पर भी कुछ मुकदमा के सुनवाई होला।<ref name=courts/> हाइकोर्ट के मुख्य न्यायाधीस के नियुक्ती राष्ट्रपति द्वारा, सुप्रीम कोर्ट के मुख्य न्यायाधीस के सलाह पर होले।<ref name="BhargavaBhatt2005"/> बाकी जज लोग के नियुक्ति इहाँ के मुख्य न्यायाधीश के सलाह पर राष्ट्रपति द्वारा होले।<ref name=courts>{{cite web |title= Uttar Pradesh judiciary |url= http://www.mapsofindia.com/uttar-pradesh/local-government/judiciary.html |publisher= Maps of India |accessdate=19 September 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120904072538/http://www.mapsofindia.com/uttar-pradesh/local-government/judiciary.html |archivedate=4 September 2012 }}</ref><ref name=Constitution>{{cite web|title=Constitutional setup|url=http://www.upgov.nic.in/upconstitution.aspx|publisher=[[उत्तर प्रदेश सरकार]]|accessdate=19 सितंबर 2012|archive-date=2012-09-25|archive-url=https://web.archive.org/web/20120925090047/http://www.upgov.nic.in/upconstitution.aspx|url-status=dead}}</ref> निचली अदालत सभ, दू हिस्सा में बिभाजित होलीं: उत्तर प्रदेश सिविल न्यायिक सेवा आ उत्तर प्रदेश उच्च न्यायिक सेवा।<ref name="BhargavaBhatt2005"/> जहाँ सिविल जूडीशियल सर्विस में सिविल जज (जूनियर डिवीजन)/चीफ जूडीशियल मजिस्ट्रेट ओही जे, उत्तर प्रदेश के हायर जूडीशियल सेवा में सिविल आ सेशन (सत्र) जज लोग होला।<ref name="BhargavaBhatt2005"/><ref name="Civil Judiciary">{{cite web|title=Subordinate Civil Judiciary in Uttar Pradesh|url=http://www.allahabadhighcourt.in/event/TheHistoryRoleSubordinateJudiciaryBBPrasad.pdf|publisher=[[इलाहाबाद हाईकोर्ट]]|accessdate=19 सितंबर 2012}}</ref>
उत्तर प्रदेश के राजनीति में भारतीय राष्ट्रीय कांग्रेस, समाजवादी पार्टी, बहुजन समाज पार्टी आ भारतीय जनता पार्टी नियर चार गो राजनीतिक दल के मुख्य भूमिका बाटे। उत्तर प्रदेश के राजनीतिग्य लोग भारत के राष्ट्रीय राजनीति में भी प्रमुख भूमिका अदा कइले बा, कुछ लोग काफी ऊँच पद तक ले चहुँपल बा, जइसे कि परधानमंत्री। एह मामिला में उत्तर प्रदेश के ''अंडर अचीवर'' भी मानल जाला कि देस के आठ गो परधानमंत्री देवे के बावजूद भी ई राज्य अभिन ले गरीब राज्य बा।<ref name="politically crucial state">{{cite web|title=UP: the nerve centre of politics|url=http://zeenews.india.com/state-elections-2012/up/issues.html|publisher=[[जी न्यूज]]|accessdate=22 जुलाई 2012}}</ref>
{{clear}}
==अर्थब्यवस्था==
[[File:A Busy road in Main Market.JPG|thumb|left|alt=सड़क के किनारे लागल दुकान|सड़क के किनारे लागल दुकान सभ। उत्तर प्रदेश में भारी जनसंख्या गैर-औपचारिक सेक्टर में रोजगार पावे ले।]]
{| class="wikitable" cellspacing="1" style="float:right; width:260px; margin:0 0 1em 1em; background:#f4f5f6; border:#c6c7c8 solid; font-size:90%;"
| colspan="2" style="background:#c2d6e5; text-align:center;"| '''राज्य के नेट घरेलू उत्पाद, फैक्टर लागत पर आ चालू कीमत पर (2004–05 आधार)<ref name=rbinsdpstat>{{cite web
|url=http://www.rbi.org.in/scripts/PublicationsView.aspx?id=13592
|title=Net state domestic product at factor cost—state-wise (at current prices)
|date=15 सितंबर 2011
|accessdate=7 फरवरी 2012
|work=Handbook of statistics on Indian economy
|publisher=[[भारतीय रिजर्व बैंक]]
|url-status=dead
|archiveurl=https://web.archive.org/web/20120309001542/http://rbi.org.in/scripts/PublicationsView.aspx?id=13592
|archivedate=9 मार्च 2012
|df=dmy
}}</ref>'''
आँकड़ा करोड़ रुपिया में
|-
! साल || नेट घरेलू उत्पाद
|-
| 2004–2005 || 229,074
|-
| 2005–2006 || 256,699
|-
| 2006–2007 || 294,031
|-
| 2007–2008|| 332,352
|-
| 2008–2009 || 384,718
|-
| 2009–2010 || 453,020
|}
अगर [[नेट घरेलू उत्पाद|राज्य के नेट घरेलू उत्पाद]] (NSDP) के हिसाब से देखल जाय, महाराष्ट्र के बाद उत्तर प्रदेश भारत के दुसरा सभसे बड़ अर्थब्यवस्था हवे, जहाँ NSDP {{INRConvert|14.46|lc}} बा,<ref name=":0" /> आ एह तरीका से भारत के अर्थब्यवस्था में एकर जोगदान 8.406 % के बा। खेतीबारी एह राज्य के लोग के मुख्य पेशा हवे।<ref name=resources>{{cite web|title=The state profile |url=http://www.phdcci.in/admin/userfiles/file/Research-Bureau/Uttar-Pradesh.pdf |publisher=PHD Chember |accessdate=20 September 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20121224141248/http://www.phdcci.in/admin/userfiles/file/Research-Bureau/Uttar-Pradesh.pdf |archivedate=24 दिसंबर 2012 }}</ref> इंडिया ब्रांड इक्विटी फाउंडेशन के रपट के मोताबिक, साल 2014–15 में देस के कुल खाद्यान उत्पादन में उत्तर प्रदेश के 19% सझियाई रहल। साल 2014–15 में खाद्यान्न उत्पादन 47,773.4 हजार टन रहल। इहाँ गोहूँ मुख्य खाद्यान फसल हवे आ [[ऊखि]] प्रमुख आमदनी वाली फसल ह।<ref name="Policy">{{cite web|url=http://www.lexuniverse.com/industrial-policy/india/uttar-pradesh/uttar-pradesh2.html|title=Industrial policy of Uttar Pradesh|publisher=Lex Universe|accessdate=20 September 2012|archive-date=1 May 2012|archive-url=https://web.archive.org/web/20120501052825/http://www.lexuniverse.com/industrial-policy/india/uttar-pradesh/uttar-pradesh2.html|url-status=dead}}</ref> भारतीय चीनी मिल एसोसिएशन (ISMA) के रपट के मोताबिक, भारत में कुल ऊख के उत्पादन साल 2015 के सितंबर महीना में खतम होखे वाला बित्त बरिस में 28.3 मिलियन टन रहल जेह में से 10.47 मिलियन टन महाराष्ट्र में आ 7.35 मिलियन टन उत्तर प्रदेश से रहल।<ref>{{Cite web|url=http://www.indiansugar.com/NewsDetails.aspx?nid=4584|title=Indian sugar mills association|website=www.indiansugar.com|access-date=2016-08-08}}</ref>
राज्य में उद्योग सभ के संकेद्रण कई टुकड़ा में बा। मुख्य उद्योग क्षेत्र में कानपुर आ नोएडा गिनावल जा सके ला। पूर्वांचल में भी कुछ उद्योग लागल बाने। बनारस-मुग़लसराय इलाका में रेलवे से संबंधित उद्योग लागल बाने जइसे मंडुआडीह में डीजल लोकोमोटिव कारखाना बा। इलाहाबाद के उपनगरी इलाका के रूप में नैनी में भी उद्योग क्षेत्र बा, आ जौनपुर में सतहरिया उद्योग क्षेत्र बिकसित कइल जा रहल बा। उत्तर प्रदेश में मुख्य उद्योग सभ में इंजीनियरी उत्पाद, इलेक्ट्रानिक्स, इलेक्ट्रिक सामान, केबिल, स्टील, चमड़ा से बनल सामान, कपड़ा उद्योग, गहना, ऑटोमोबाइल, रेल डिब्बा वगैरह बाने। छोटहन साइज के उद्योग सभ के संख्या उत्तर प्रदेश में सगरी राज्यन के तुलना में सभसे ढेर बा; कुल भारत के 23 लाख अइसन छोट इकाई सभ के लगभग 12 हिस्सा इहँवे उत्तरे प्रदेश में बा।<ref name="resources" /> With 359 manufacturing clusters, cement is the top sector of [[Ministry of Micro, Small and Medium Enterprises|SMEs]] in UP.<ref name="ET-20130620-SMEs">{{cite web | url=http://economictimes.indiatimes.com/news/emerging-businesses/sme-policy-trends/smes-employ-close-to-40-of-indias-workforce-but-contribute-only-17-to-gdp/articleshow/20496337.cms?curpg=2 | title=SMEs employ close to 40% of India's workforce, but contribute only 17% to GDP | work=The Economic TImes| date=9 Jun 2013<!-- , 05.00AM IST -->| accessdate=20 जून 2013 | author=Malini Goyal}}</ref>
==शिक्षा==
{{Main article|उत्तर प्रदेश में शिक्षा}}
{{See also|उत्तर प्रदेश में उच्चशिक्षा संस्थान सभ के लिस्ट}}
[[File:JRHU - Main Building.jpg|thumb|left|alt=दुनिया के पहिला बिकलांग बिस्वबिद्यालय |[[जगद्गुरु रामभद्राचार्य बिकलांग विश्वविद्यालय|जेआरएचयू]] दुनिया के पहिला बिकलांग शिक्षा केंद्र हवे]]
उत्तर प्रदेश में शिक्षा के बहुत पुरान परंपरा चल आइल बा भले ई इतिहासी दौर में उच्चबर्ग आ धार्मिक बिद्यालयन ले सीमित रहल होखे।<ref name=schools>{{cite news|title=Islamic religious schools|url=http://articles.timesofindia.indiatimes.com/keyword/madrassas|archive-url=https://archive.is/20130103081247/http://articles.timesofindia.indiatimes.com/keyword/madrassas|dead-url=yes|archive-date=3 जनवरी 2013|publisher=[[दि टाइम्स ऑफ इंडिया]]|accessdate=25 अप्रैल 2003}}</ref> संस्कृत-आधारित शिक्षा इहाँ [[बैदिक काल]] से ले के [[गुप्त साम्राज्य|गुप्त काल]] ले रहल आ एकरे बाद संस्कृति के बिकासक्रम में, पाली, फ़ारसी, आ अरबी बिद्या के चलन आइल। हिंदू-बौद्ध-मुसलमानी बिद्या के सामूहिक रूप तब तक ले इहाँ के बिसेसता रहल जबले ब्रिटिश राज के उदय ना भइल। वर्तमान इस्कूल-से-इन्वर्सिटी वाला सिस्टम बाकी भारत के साथे-साथ इहाँ भी स्थापित भइल आ एह सिस्टम के बिकास में ब्रिटिश राज आ ईसाई मिशनरी सभ के योगदान हवे।<ref name="Education System">{{cite web|title=British colonial administration system in state education system|url=http://www.upeducation.net/|publisher=State Education Board|accessdate=25 अप्रैल 2003|archive-date=2003-04-21|archive-url=https://web.archive.org/web/20030421195013/http://upeducation.net/|url-status=dead}}</ref> राज्य में इस्कूल सभ या त सरकार द्वारा चलावल जालें या फिर प्राइवेट संस्था (ट्रस्ट) द्वारा। ज्यादातर इस्कूल सभ में पढ़ाई के माध्यम के रूप में हिंदी के इस्तेमाल होला; एकरे अलावा इंग्लिश-मीडियम इस्कूल भी बाने आ संस्कृत पाठशाला आ मदरसा भी जहाँ क्रम से अंग्रेजी, संस्कृत आ उर्दू माध्यम में पढ़ाई होला। सीबीएससी आ आइसीएससी बोर्ड से जुड़ल इस्कूल सभ में अंग्रेजी माध्यम से पढ़ाई होला।<ref name=Facts>{{cite web|title=Uttar Pradesh Facts & Figures|url=http://www.upeducation.net/Facts/|publisher=Uttar Pradesh education department|accessdate=16 अक्टूबर 2010|archive-date=2011-04-03|archive-url=https://web.archive.org/web/20110403071219/http://www.upeducation.net/facts/|url-status=dead}}</ref>
[[File:Chattar Manzil 2005.jpg|thumb|270px|alt=Central Drug Research Institute|सेंट्रल ड्रग रिसर्च इंस्टीट्यूट के बिल्डिंग]]
उत्तर प्रदेश में कुल 45 गो विश्वविद्यालय बाने,<ref name=universities>{{cite web|title=List of universities|url=http://www.educationinfoindia.com/Universities/U-up.htm|publisher=Education department of india|accessdate=16 अक्टूबर 2010|archive-date=2017-04-11|archive-url=https://web.archive.org/web/20170411015723/http://www.educationinfoindia.com/Universities/U-up.htm|url-status=dead}}</ref> जेह में 5 गो केंद्रीय विश्वविद्यालय, 28 गो राज्य विश्वविद्यालय, 8 डीम्ड विश्वविद्यालय, 2 गो आइआइटी, 1 ठो आइआइएम (लखनऊ), 1 ठो एनआइटी (इलाहाबाद), आ 2 गो ट्रिपल आइटी, 1 ठो नेशनल लॉ कॉलेज आ कई सारा इंजीनियरिंग कालेज आ पॉलिटेकनिक कॉलेज अउरी आइटीआई बाने।<ref name=Universities>{{cite web|title=List of Universities in Uttar Pradesh|url=http://www.upeducation.net/universities/|publisher=Education department of U.P|accessdate=27 जून 2012|archive-date=2012-06-21|archive-url=https://web.archive.org/web/20120621081900/http://www.upeducation.net/universities/|url-status=dead}}</ref> उत्तर प्रदेश के प्रतिष्ठित विश्वविद्यालय आ उच्च शिक्षा संस्थान सभ में <!-- अच्छर क्रम में -->अलीगढ़ मुस्लिम विश्वविद्यालय, आईआईटी कानपुर, आईआईएम लखनऊ, इलाहाबाद विश्वविद्यालय, किंग जार्ज मेडिकल कॉलेज (केजीएमसी), बनारस हिंदू यूनिवर्सिटी (बीएचयू), मोतीलाल नेहरू नेशनल इंस्टीट्यूट ऑफ टेक्नोलॉजी (एमएनआईटी), संजय गाँधी पीजीआई प्रमुख बाने।<ref name=IIT>{{cite news|title=Kanpur schools welcome IIT Council formula|url=http://timesofindia.indiatimes.com/topic/IIT-Kanpur|publisher=[[दि टाइम्स ऑफ इंडिया]]|accessdate=27 जून 2012}}</ref><ref name=IIM>{{cite web|title=Official Website of IIM Lucknow|url=http://www.iiml.ac.in/|publisher=IIM Lucknow|accessdate=11 अप्रैल 2012|archive-date=2012-04-13|archive-url=https://web.archive.org/web/20120413144029/http://www.iiml.ac.in/|url-status=dead}}</ref>
==पर्यटन==
{{Main article|उत्तर प्रदेश में पर्यटन}}
[[File:Kumbh Mela 2013 Sangam, Allahabd.jpg|thumb|right|alt= कुंभ मेला सभसे बिसाल मेला हवे| इलाहाबाद के संगम पर 2013 के कुंभ मेला।]]
घरेलू पर्यटन के हिसाब से देखल जाय त उत्तर प्रदेश में सभसे ढेर पर्यटक लोग आवे ला, ई संख्या 71 मिलियन (7.1 करोड़) बा,<ref name="Board2010">{{cite book|author=Upkar Prakashan - Editorial Board|title=Uttar Pradesh General Knowledge|url=https://books.google.com/books?id=_ce8FpJzR-4C&pg=PA46|accessdate=26 July 2012|date=1 September 2010|publisher=Upkar Prakashan|isbn=978-81-7482-408-0|pages=46–287}}</ref><ref name=Tourism>{{cite web|title=Performance of Tourist Centres in Uttar Pradesh|url=http://journal.asci.org.in/Vol.40(2010–11)/40_1_Masood%20H%20Siddiqui.pdf|publisher=Uttar Pradesh Tourist Department|date=8 July 2012}}{{Dead link|date=October 2023 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> जेकर वजह इहाँ के बिबिधता वाला भूगोल, संस्कृति, तिहुआर, स्मारक, प्राचीन पूजा अस्थान आ बौद्ध बिहार वगैरह के मौजूदगी बा। हर साल अकेले इलाहाबाद में माघ मेलवे में लाखन गो श्रद्धालू लोग नहान करे आवे ला।<ref name="MacLean2008">{{cite book|author=Kama MacLean|title=Pilgrimage and Power: The Kumbh Mela in Allahabad, 1765-1954|url=https://books.google.com/books?id=MALacgnsroMC|accessdate=25 July 2012|date=29 अगस्त 2008|publisher=Oxford University Press|isbn=978-0-19-533894-2}}</ref> इहे मेला हर 12वाँ बरिस अउरी बिसाल पैमाना पर आयोजित होला आ कुंभ मेला कहाला, एह समय लगभग एक करोड़ लोग एह गंगा-जमुना के संगम पर एकट्ठा हो जाला आ ई लोगन के दुनिया में सभसे बड़ समागम बन जाला।<ref name="Magh Mela">{{cite news|title=Hindus gather for the Kumbh Mela at the Ganges in India and Maha Shivaratri in Allahabad|url=http://www.telegraph.co.uk/news/picturegalleries/worldnews/7222387/pictures-Hindus-gather-for-the-Kumbh-Mela-in-India-and-Maha-Shivaratri-in-Nepal.html|publisher=The Daily Telegraph|accessdate=25 January 2011|date=12 February 2010}}</ref>
इतिहासी रूप से महत्त्व के जगह बनारस खुद भी बा आ एकरे लगे सारनाथ भी बा<ref name=SARNATH>{{cite web|title=SARNATH GENERAL INFORMATION|url=http://varanasi.nic.in/tourist/tourist7.html|publisher=Tourism department of Varanasi|accessdate=8 July 2012}}</ref> जहाँ गौतम बुद्ध आपन पहिला उपदेस दिहले रहलें; एकरे उत्तर में गोरखपुर के आगे कुशीनगर भी बौद्ध धरम के लोग खातिर महत्व के अस्थान बा जहाँ बुद्ध के निधन भइल। सारनाथ में मौजूद [[अशोक स्तंभ|अशोक के खम्हा]] आ एकर सिंह मुकुट दुनो राष्ट्रीय महत्त्व के चीज बा। बनारस से लगभग 80 किमी के दूरी पर मौजूद [[गाजीपुर]] अपना गंगा घाट खातिर भी मशहूर बा आ हेइजे लार्ड कार्नवालिस के निधन भइल रहल आ उनुके मकबरा मौजूद बा।<ref name="Joon">{{cite book|author=Sanjeev Joon|title=Complete Guide for SSC|url=https://books.google.com/books?id=E9YfW2709psC&pg=RA2-PA93|accessdate=25 July 2012|publisher=Tata McGraw-Hill Education|isbn=978-0-07-070645-3|page=255}}</ref> राज्य में कई गो पक्षी बिहार भी बाने, जइसे एटा में, समसपुर में, आ [[बलियाँ]] में [[सुरहा ताल]]।
राजधानी लखनऊ में भी कई सारा इतिहासी धरोहर भवन मौजूद बाने।<ref name=Monuments>{{cite web|title=List of Monuments - Uttar Pradesh|url=http://asi.nic.in/asi_monu_alphalist_uttarpradesh_lucknow.asp|publisher=Archaeological Survey of India|date=8 July 2012}}</ref><ref name="Bara Imambara">{{cite web|title=The historical monument called Bara Imambara of Lucknow that is also known as Asfi Imambara|url=http://www.lucknow.org.uk/tourist-attractions/bara-imambara.html|publisher=Lucknow online news|accessdate=8 July 2012|archive-date=3 February 2012|archive-url=https://web.archive.org/web/20120203233602/http://www.lucknow.org.uk/tourist-attractions/bara-imambara.html|url-status=dead}}</ref> इहाँ अवध काल के ब्रिटिश रेजीडेंसी के भवन अबहिन ले संरक्षित बा आ एकर जीर्णोद्धार भी कइल गइल बा। बड़ा आ छोटा इमामबाड़ा आ अउरी कई गो भवन बाने जिनहन के देखे लोग आवे ला। उत्तर प्रदेश में आगरा आ एकरे नजदीक में तीन गो [[बिस्व धरोहर स्थल|बिस्व धरोहर अस्थान]] बाने: [[ताज महल]], आगरा के किला आ फतेहपुर सीकरी।
पर्यटन के बढ़ावा देवे खातिर इहाँ 1972 में पर्यटन डाइरेक्टरेट के स्थापना कइल गइल जेकर मुखिया एगो आइएएस अफसर होलें। एकरे बाद 1974 में उत्तर प्रदेश राज्य पर्यटन निगम के स्थापना कइल गइल जे पर्यटन से जुड़ल बानिज्यिक क्रियाकलाप के देखरेख करे ला।<ref name=autogenerated10>{{cite web|title=The Tourism Development Policy |url=http://www.up-tourism.com/about_tourism.htm |publisher=Department of Tourism, Uttar Pradesh |accessdate=8 जुलाई 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120614064428/http://www.up-tourism.com/about_tourism.htm |archivedate=14 जून 2012 }}</ref>
==सेहत आ सेहत सुबिधा==
[[File:District Hospital.jpg|thumb|right|कानपुर देहात के जिला अस्पताल]]
उत्तर प्रदेश में सरकारी आ निजी क्षेत्र मिला के बड़हन पैमाना पर स्वास्थ्य सुबिधा खातिर [[इंफ्रास्ट्रक्चर]] के बिकास भइल बा बाकी सेहत के अलग-अलग पैरामीटर पर अन्य राज्य सभ से तुलना कइल जाय त इहाँ के परफारमेंस बहुत उत्साहजनक नइखे। भले पब्लिक आ प्राइवेट सेक्टर में स्वास्थ्य सुबिधा के लमहर-चाकर इन्फ्रास्ट्रक्चर मौजूद होखे, इहँवा के बिसाल जनसंख्या के कारण ई जरूरत भर के ना बाटे आ अइसन सेवा सभ के डिमांड पूरा ना क पावे ला।
पछिला 15 साल में, उत्तर प्रदेश के जनसंख्या में लगभग 25 प्रतिशत से अधिका के बढ़ती भइल बा। जबकि, सरकारी स्वास्थ्य केंद्र, जवन पब्लिक सेक्टर के सभसे अगिला मोर्चा के स्वास्थ्य सुबिधा बा, इनहन के संख्या में आठ प्रतिशत के गिरावट आइल बा।<ref name="health"/> छोटहन उपकेंद्र सभ, जहाँ जनता के पहिला संपर्क एह सुबिधा सभ से होला, इनहन के संख्या में बस 2 प्रतिशत के बढती भइल बा अगर 2015 के पहिले के 25 साल में भइल बदलाव के देखल जाय, जबकि एही समय में राज्य के जनसँख्या में 51 परसेंट से ढेर के बढ़ती भइल बा।<ref name="health"/> एगो नया पैदा भइल बच्चा के जिए के आशा के तुलना कइल जाय त बिहार के तुलना में ओकर जीवन प्रत्याशा चार बरिस कम, हरियाणा के तुलना में पाँच साल कम, आ हिमाचल प्रदेश के तुलना में सात बरिस कम रहे ला। भारत के स्तर पर, सगरी छुआछूत से फइले वाली भा गैर-छुआछूत वाली बेमारी सभ में उत्तर प्रदेश लगभग सभन में सभसे ढेर केस वाला रहल, एह में टाईफाइड से होखे वाला मउअत के 48 परसेंट (2014); 17 परसेंट कैंसर से होखे वाला मौत आ 18 परसेंट टीबी से होखे वाला मउअत (2015) उत्तर प्रदेश से रहल।<ref name="health"/> महतारी मउअत दर के मामिला में आसाम के बाद उत्तर प्रदेश भारत में दूसरा नमर प बाटे आ इहाँ हर एक लाख जचगी करे वाली औरतन में से 285 के मौत के एभरेज (2013) बाटे, आ सौ में 62 गर्भवती औरतन के जचगी के बाद जवन कमसेकम स्वास्थ्य-सुबिधा मिले के चाहीं ऊ ना उपलब्ध हो पावे ला।<ref name="health">{{cite web|title=Factsheet- Uttar Pradesh|url=http://www.censusindia.gov.in/vital_statistics/AHSBulletins/AHS_Factsheets_2012-13/FACTSHEET-UTTAR_PRADESH.pdf|website=censusindia.gov.in|publisher=''Ministry of Home Affairs''|accessdate=14 अगस्त 2017|ref=health}}</ref>
अभिन भी राज्य में 42 प्रतिशत औरत, संख्या में ई 15 लाख से ढेर होखी, घरहीं जचगी करे लीं। अइसन जचगी सभ में से लगभग दू तिहाई हिस्सा (61 प्रतिशत) सुरक्षित ना होला।<ref name="Health and Family">{{cite web|title=State of Health in Uttar Pradesh- Urban Health Resource Center|url=http://www.uhrc.in/downloads/Reports/up.pdf|website=uhrc.in|publisher=''Ministry of Health and Family Welfare''|accessdate=14 अगस्त 2017}}</ref> शिशु मौत दर के आँकड़ा उत्तर प्रदेश में हाई बाटे, नवजात मौत दर (NNMR) से पाँच बरिस के भीतर मरे वाला बच्चा सभ के इंडिकेटर देखल जाय त हर 1000 जनमल बच्चा सभ में से 64 गो मर जालें, एह में से 35 गो महीना के भीतरे मर जालें आ 50 गो साल भर के उमिर पूरा ना का पावे लें।<ref name="Rural">{{cite web|title=Rural Health Statistics|url=http://wcd.nic.in/sites/default/files/RHS_1.pdf|website=wcd.nic.in|publisher=''Ministry of Health and Family Welfare Statistics Division''|accessdate=14 अगस्त 2017}}</ref> अगर भारत के मानक के हिसाब से देखल जाय, प्रदेश के लगभग एक तिहाई हिस्सा ग्रामीण जनसंख्या मूलभूत स्वास्थ्य सुबिधा से बंचित बाटे।<ref name="Delivery">{{cite web|title=Public Private Partnership in Uttar Pradesh Health Care Delivery System|url=http://www.cehat.org/go/uploads/PPP/bibisratpaper.pdf|website=cehat.org|publisher=''UPHSDP''|accessdate=14 अगस्त 2017|archive-date=2017-03-29|archive-url=https://web.archive.org/web/20170329140924/http://www.cehat.org/go/uploads/PPP/bibisratpaper.pdf|url-status=dead}}</ref> हाल में, [[गोरखपुर]] में 60 ढेर बच्चन के अस्पताल में मौत हो गइल, एकर कारण उहाँ ऑक्सीजन के सप्लाई में कमी होखल बतावल गइल।<ref name="oxygen">{{cite news|title=India to Investigate 64 Children’s Deaths at Hospital in Uttar Pradesh|url=https://www.wsj.com/articles/indian-province-to-investigate-64-childrens-deaths-at-hospital-1502628951|agency=Wall Street Journal}}</ref>
==संस्कृति==
===भाषा आ साहित्य===
{{Main article|उत्तर प्रदेश के भाषा}}
[[File:Kurukshetra.jpg|thumb|230px|alt=एगो हाथ से लिखल पोथी|कुरुक्षेत्र के जुद्ध, महाभारत]]
बहुत सारा वैदिक मंत्र सभ के रचना प्राचीन काल में एह इलाका में भइल जे आज उत्तर प्रदेश के अंदर पड़े ला। महर्षि व्यास, जे परंपरागत रूप से वेद सभ के बिभाजन करे वाला मानल जालें आ पुराणन आ महाभारत के रचइता मानल जालें आ जिनके समर्पित तिहुआर गुरु पूर्णिमा आज भी एह क्षेत्र में मनावल जाला, उत्तर परदेस के कालपी के नजदीक जमुना नदी के एगो दीप पर जनमल बतावल जालें।<ref>[https://books.google.com/books?id=KnCxH85Vra4C&pg=PA205&lpg=PA205&dq=vyasa+born+yamuna&source=bl&ots=aX4O103DiT&sig=1pMtLNI3Ajf8Bz56WirIu2leukM&hl=en&sa=X&ei=E-jyU7eVBpaPuAS46YGIBw&ved=0CDcQ6AEwBA#v=onepage&q=vyasa%20born%20yamuna&f=false Essays on the Mahābhārata], Arvind Sharma, Motilal Banarsidass Publisher, p. 205</ref><ref name=ci>{{cite book|title=Awakening Indians to India|url=https://books.google.com/books?id=AIU4LzftaPAC&pg=PA167&dq=%22Guru+Purnima%22+-inpublisher:icon&cd=8#v=onepage&q=%22Guru%20Purnima%22%20-inpublisher%3Aicon&f=false|year=2008|publisher=Chinmaya Mission|isbn=81-7597-434-6|page=167|accessdate=5 अगस्त 2012}}{{Dead link|date=September 2023 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> बाद के समय में, हिंदी साहित्य आ लोक साहित्य में एह प्रदेश के बहुत योगदान रहल बा आ [[तुलसीदास]], सूरदास आ [[कबीरदास]] नियर लोग एही राज्य से रहल बा। बनारस पुराना समय से शिक्षा आ साहित्य के केंद्र रहल चल आइल बा। आधुनिक समय (19वीं आ 20वीं-सदी) के [[हिंदी भाषा]] के साहित्य में भी बहुत सारा लोग के नाँव गिनावल जा सके ला जइसे कि भारतेंदु हरिश्चंद्र, जयशंकर प्रसाद, मैथिलीशरण गुप्त, [[मुंशी प्रेमचंद]], [[महादेवी वर्मा]], सुभद्राकुमारी चौहान, सूर्यकांत त्रिपाठी निराला, बाबू गुलाबराय, अज्ञेय, हरिवंश राय बच्चन, [[हजारी प्रसाद द्विवेदी]],<ref name=authors>{{cite web|title=The Indus Valley Civilization|url=http://www.hindunet.org/hindu_history/ancient/indus/indus_civ.html|publisher=The Hindu universe|accessdate=8 July 2012}}</ref> शिवप्रसाद सिंह आ काशीनाथ सिंह वगैरह।
राज्य के कबो-कबो ''हिंदी हार्टलैंड'' (मने कि, हिंदी हृदय प्रदेश) भी कहल जाला।<ref>{{cite web|url=http://www.newkerala.com/topstory-fullnews-67268.html |title=Three indian children to attend J8 summit in Rome.:. newkerala.com Online News |publisher=New kerala |accessdate=21 September 2009 |url-status=dead |archiveurl=https://web.archive.org/web/20110614094016/http://www.newkerala.com/topstory-fullnews-67268.html |archivedate=14 जून 2011 }}</ref> [[हिंदी भाषा]] राज्य के प्रशासन के ऑफिशियल भाषा 1951 के उत्तर प्रदेश ऑफिशियल भाषा अधिनियम से बनल आ 1989 में एह अधिनियम में सुधार कइल गइल आ [[उर्दू]] के अतिरिक्त भाषा के दर्जा दिहल गइल।<ref>{{cite web|url=http://uplegassembly.nic.in/UPLL.HTML |title=Uttar Pradesh Legislature |publisher=U.P assembly |accessdate=21 September 2009 |url-status=dead |archiveurl=https://web.archive.org/web/20090619093010/http://www.uplegassembly.nic.in/UPLL.HTML |archivedate=19 जून 2009 }}</ref> भाषा बिज्ञान के हिसाब से राज्य के बिस्तार [[हिंदी पट्टी]] के पच्छिमी, मध्य आ पूरबी हिंदी तीनो के कुछ इलाका कभर करे ला। मुख्य भाषा आ बोली सभ में अवधी, [[भोजपुरी]], ब्रजभाषा, बुन्देली, कनौजी, बघेली आ कड़ी बोली गिनावल जाली सऽ।<ref>{{cite web|url=http://www.ethnologue.com/show_language.asp?code=bfy |title=Ethnologue report for language code: bfy |publisher=Ethnologue|accessdate=21 September 2009}}</ref>
===संगीत आ नाच===
उत्तर प्रदेश से आवे वाला संगीत के क्षेत्र के हस्ती लोग में अनूप जलोटा, गिरिजा देवी, किशन महराज, विकास महराज,<ref>{{cite web |url=http://www.varanasi.nic.in/ |title=Official Website Of Varanasi District |publisher=Varanasi.nic.in |date= |accessdate=2015-07-29 |archive-date=2019-08-02 |archive-url=https://web.archive.org/web/20190802010349/http://www.varanasi.nic.in/ |url-status=dead }}</ref> नौशाद अली, रविशंकर, शुबहा मुद्गल, सिद्धेश्वरी देवी, तलत महमूद आ उस्ताद [[बिस्मिल्ला ख़ाँ|बिस्मिल्ला खान]] के नाँव प्रमुख बा। परसिद्ध गजल गायिका बेगम अख्तर उत्तरे परदेश के रहली। लोक संगीत के भी इहाँ बहुत धनी परंपरा बा आ ब्रज क्षेत्र के रसिया आ होरी कृष्ण भक्ति के संगीत हवे। अन्य लोग संगीत के रूप में फगुआ, कजरी, चैती, सोहर, ठुमरी, बिरहा, आ सोरठी बाटे। लखनऊ में भातखंडे संगीत संस्थान आ इलाहाबाद में प्रयाग संगीत समीति इहाँ के प्रमुख संगीत शिक्षा के संस्थान बाड़ें।<ref name=Institute>{{cite web|title=Bhatkhande music institute|url=http://www.upeducation.net/universities/Bhatkhande_Music_Institute/|publisher=Uttar Pradesh Education Department|accessdate=25 July 2012|archive-date=10 January 2012|archive-url=https://web.archive.org/web/20120110184217/http://www.upeducation.net/universities/Bhatkhande_Music_Institute/|url-status=dead}}</ref>
शाश्त्रीय नाच के बिधा [[कथक]] के पैदाइश उत्तरे प्रदेश में भइल।<ref name="dance"/> तबला आ पखावज के साथ एह नाच के प्रस्तुति उत्तर भारतीय संगीत पर आधारित होले।<ref>{{cite web|title=North Indian: Kathak|url=http://www.worldartswest.org/plm/guide/printablepages/kathak.pdf|publisher=Dance style loacator|accessdate=23 जून 2012|archive-date=2013-05-08|archive-url=https://web.archive.org/web/20130508154646/http://www.worldartswest.org/plm/guide/printablepages/kathak.pdf|url-status=dead}}</ref> शास्त्रीय नाच के चार गो घराना प्रमुख बाने: लखनऊ घराना, अज्राड़ा घराना, फर्रूखाबाद घराना आ बनारस घराना।<ref name=gharana>{{cite web|title=Lucknow gharana, developed with Kathak. |url=http://www.hindustaniclassical.com/lucknow.asp |publisher=Hindustani classical music |accessdate=23 July 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20100605174519/http://www.hindustaniclassical.com/lucknow.asp |archivedate=5 जून 2010 }}</ref><ref name="benaras gharna">{{cite web|title=Benaras Gharana, traditional style and way of teaching and performing Indian classical music. |url=http://www.benaresmusicacademy.com/page-1|publisher=Benares music academy|accessdate=23 जून 2012}}</ref> [[पूर्वांचल]] के लोक नाच में धोबिअऊ आ कहरऊ नाच के ख़ास अस्थान बा।
===मेला आ परब-तिहुआर===
[[File:India - Varanasi sun greet - 0270.jpg|thumb|230px|alt=संझा आरती|[[बनारस]] में घाट पर गंगा आरती करत हिंदू पुजारी]]
[[दिपावली]], [[होली]] आ [[रामनवमी]] उत्तर प्रदेश के बहुत प्रमुख तिहुआर हवें। इलाहाबाद के [[कुंभ मेला]] सभसे बड़हन मेला हवे।<ref name=Mela>{{cite web|title=Kumbh Mela - India|url=https://www.youtube.com/watch?v=WqvzEjgYTFA|publisher=[[YouTube]]|accessdate=18 July 2012}}</ref> बरसाना आ मथुरा में होली के पहिले लट्ठमार होली एक ठो परसिद्ध तिहुआर हवे। [[बुद्ध पूर्णिमा]], जहिया [[गौतम बुद्ध]] के जनम, ज्ञान, आ निर्वाण तीनो भइल, बौद्ध लोग आ हिंदू लोग के पावन परब हवे। अन्य तिहुआर सभ में ईद-उल-फ़ित्र, बकरीद, बिजयदसिमी, खिचड़ी, बसंत पंचिमी, सतुआन, जन्माष्टमी, देव दीपावली, गंगा दसहरा, छठ पूजा, महावीर जयंती, मोहर्रम, आ हनुमान जयंती प्रमुख बाने।<ref name=traditions>{{cite web|title=The glorious traditions and mythological legacy |url=http://www.up-tourism.com/destination/varanasi/fair_festival.htm |publisher=Department of tourism U.P |accessdate=18 July 2012 |url-status=dead |archiveurl=https://web.archive.org/web/20120629052417/http://www.up-tourism.com/destination/varanasi/fair_festival.htm |archivedate=29 जून 2012 }}</ref> आगरा के [[ताज महोत्सव]], आधुनिक समय के चीज हवे आ संस्कृति के बिबिध रंगीन रूप देखे के मिले ला।<ref name="Braj Holi">{{cite news|title=The Braj Holi: Legend in real life |url=http://www.hindustantimes.com/News-Feed/lifestyle/The-Braj-Holi-Legend-in-real-life/Article1-675341.aspx |accessdate=13 जुलाई 2012 |work=[[हिन्दुस्तान टाइम्स]] |date=19 मार्च 2011 |url-status=dead |archiveurl=https://web.archive.org/web/20110322041343/http://www.hindustantimes.com/News-Feed/lifestyle/The-Braj-Holi-Legend-in-real-life/Article1-675341.aspx |archivedate=22 मार्च 2011 }}</ref> इलाहाबाद में, त्रिवेणी महोत्सव भी मनावल जाला।
===खानपान===
{{Main article|उत्तर प्रदेश के खाना}}
[[File:Vegetarian Curry.jpeg|alt=photograph|thumb|230px|उत्तर प्रदेशी थाली, नान, दाल, रायता, आ शाही पनीर के संघे।]]
[[File:Paan, (betel leaves) being served with silver foil, India.jpg|thumb|230px|चानी के वरक लागल पान।]]
रोज-रोज खाइल जाए वाला खाना में, उत्तर भारत के बाकी इलाका नियर, उत्तर प्रदेश में भी थाली में [[रोटी]], दाल, सब्जी आ चावल (भात) प्रमुख भोजन हवे। एकरे संघे, चटनी, रायता, [[अँचार]] आ पापड़ नियर चीज चटकार करे खातिर भोजन के सहजोगी आइटम हवें सऽ। खास मोका महाले, रोटी के जगह पूड़ी खाइल जाला। अइसन मोका सभ पर कड़ाही में छान के बनावल पकवान सभ के प्रमुखता हो जाला, इनहन के पक्का खाना कहल जाला। पूड़ी, कचउड़ी, सब्जी, पोलाव, पापड़, रायता आ मीठा आइटम में खीर (तस्मई) भा सेवई खाइल जाला। पेय (पियल जाए वाला) चीज सभ में छाछ (भा माँठा) अभिन भी बहुत सारा लोग पसंद करे ला। भोजन के बाद पान खाए-खियावे के चलन भी हवे।
बहुत सारा समुदाय-बिरादरी सभ के आपन ख़ास पकवान भी होला। जैन, कायस्थ आ मुसलमान लोग के अपना तरीका के भोजन होला। एही तरीका से एह बड़हन राज्य में क्षेत्र के अनुसार भी बिबिधता देखे के मिले ला। अवधी खाना, लखनऊ के परभाव में कबाब, बिरियानी, कीमा आ निहारी नियर पकवान सभ खातिर बहुत परसिद्ध हवे। मिठाई के आइटम में, खुरचन, बरफी, पेड़ा, गुलाबजामुन, पेठा, राबड़ी नियर चीज बहुत चलन में बाड़ी आ हिंदू लोग के भोजन में इनहन के बहुत प्रमुख अस्थान बाटे। लखनऊ के चाट आ बनारस के पान अपना सवाद आ सामग्री खाती पुरा दुनिया में मशहूर हवे।<ref name=paan>{{cite news|title=Banarasi paan or tobacco|url=http://timesofindia.indiatimes.com/topic/Banarasi-paan-or-tobacco|accessdate=14 July 2012|work=[[दि टाइम्स ऑफ इंडिया]]|date=28 अप्रैल 2012}}</ref>
अवधी खानपान पर मुख्य रूप से लखनऊ क परभाव देखल जाला। नबाब लोग के शासन काल में, मुगलई पकवान के इहाँ चलन बहुत बढ़ल आ एही कारण इहाँ के भोजन भी काश्मीर, मध्य एशिया, पंजाब आ हैदराबादी पकवान सभ से परभावित भइल; आज शहर के अपना नबाबी खाना खातिर जानल जाला।<ref name="books.google.nl">{{cite book|url=https://books.google.com/books?id=v-2TyjzZhZEC&pg=PA10&lpg=PA10&dq=central+asian+influence+on+mughal+cuisine|title=Royal Mughal Ladies and Their Contributions|accessdate=1 जून 2014|isbn=9788121207607|author1=Mukherjee|first1=Soma|year=2001}}</ref>
लखनऊ के बावर्ची आ रकाबदार लोग इहाँ खास 'दम पुख्त' स्टाइल शुरू कइल (जेह में कई तरह के "दम" शामिल बाने, इनहन के मद्धिम आँच पर देरी ले पकावल जाला) आ अब ई लखनऊ के खास चीन्हा बन चुकल बा। एही स्टाइल के बिस्तार के रूप में, कबाब, कोरमा, बिरियानी, कलिया, कुलचा, जरदा, शीरमाल, रूमाली रोटी, आ वरकी पराठा भी लखनऊ के खास चीज मानल जाला। अवध के खाना खाली भर बिबिधते के मामिला में धनी नइखे, पकवान बनावे में इस्तेमाल होखे वाला सामान में भी बहुत चीज शामिल कइल जाला जेह में इलायची, केसर आ जाफरान नियर खुशबूदार मसाला वगैरह गिनावल जा सके लें।
पूरबी उत्तर प्रदेश के खाना, जहाँ भोजपुरी संस्कृति बा, कुछ अलगे किसिम के होला। आम उत्तर परदेशी थाली इहाँ ओइसने होले जइसन बाकी उत्तर भारत में, बाकी पूरुब बढ़े पर भात के महत्त्व आ मछरी के महत्व बढ़त जाला। खास परब तिहुआरन पर पूड़ी कचौड़ी के साथ कढ़ी-बरी वगैरह के महत्व भी बढ़ जाला। भउरी-चोखा ([[लिट्टी]]-चोखा), सतुआ आ दही-चिउड़ा एह इलाका में काफी चलन में रहल बा। तराई के इलाका में मछरी के परभाव बढ़त देखल जाला।
===पहिनावा===
उत्तर प्रदेश के लोग के पहिनावा में परंपरागत पहिनावा आ पच्छिमी स्टाइल के पहिनावा, दुनों सामिल बा।<ref name=Costumes>{{cite web|title=Costumes of Uttar Pradesh|url=http://www.indfy.com/uttar-pradesh/dresses.html|publisher=Indify|accessdate=1 अक्टूबर 2012}}</ref> परंपरागत रूप से एह इलाका में धोती-कुरता भा पैजामा-कुरता मरदाना लोग के पोशाक हवे आ औरतन के पोशाक [[साड़ी]] आ सलवार-कमीज हवे।<ref name=Costumes/> नया जमाना के लोग अब पैंट-बुशट, जींस-टीशर्ट भी पहिरत बा। टोपी आ पगड़ी पुरुष लोग के पोशाक के हिस्सा हवे।<ref name=Costumes/> शेरवानी आ चूड़ीदार पैजामा, मर्दाना लोग बिसेस मोका-महाले पहिरे ला जइसे कि शादी बियाह भा तिहुआर के समय पर।{{r|Costumes}}
==मीडिया==
उत्तर प्रदेश से कई गो अंग्रेजी, हिंदी आ उर्दू अखबार आ पत्रिका सभ के प्रकाशन होला। अंग्रेजी के ''पायनियर'' के अस्थापना 1865 में जार्ज एलेन द्वारा इलाहाबाद में कइल गइल।<ref name=dasgupta>{{cite journal|doi=10.1017/S0026749X00015092|author=Das Gupta, Uma|year= 1977|title=The Indian Press 1870–1880: A Small World of Journalism|url=http://journals.cambridge.org/action/displayAbstract?fromPage=online&aid=2701888|journal=Modern Asian Studies|volume=11|issue=2|pages=213–235|format=see pages 233–234|jstor=311549|ref=harv}}</ref> ''[[अमर उजाला]]'', ''[[दैनिक जागरण]]'', ''[[हिंदुस्तान (अखबार)|हिन्दुस्तान]]'' वगैरह के भारी सर्कुलेशन बा आ इनहन के लोकल संस्करण कई जगह से छपे ला। इहाँ छपे आ बिकाये वाला प्रमुख अंग्रेजी अखबार सभ में ''[[दि टेलीग्राफ (कलकत्ता)|दि टेलीग्राफ]]'', ''[[दि टाइम्स ऑफ इंडिया]]'', ''[[हिंदुस्तान टाइम्स]]'', ''[[दि हिंदू]]'', ''[[दि स्टेट्समैन]]'', ''[[दि इंडियन एक्सप्रेस]]'', आ ''[[एशियन एज]]'' बाड़ें। अर्थजगत आ फाइनेंस से जुड़ल प्रमुख अखबार ''[[दि इकोनॉमिक टाइम्स]]'', ''[[दि फाइनेंशियल एक्सप्रेस (भारत)|दि फाइनेंशियल एक्सप्रेस]]'', ''[[बिजनेस लाइन]]'', आ ''[[बिजनेस स्टैंडर्ड ]]'' के सर्कुलेशन उल्लेख जोग बा। देसी भाषा सभ में भी कई गो अखबार बिकालें जेह में नेपाली, गुजराती, पंजाबी, बंगाली, ओडिया आ उर्दू भाषा के अखबार शामिल बाड़ें, हालाँकि इनहन के पाठक लोग के संख्या गिनल चुनल बा।
दूरदर्शन राज्य द्वारा चलावल जाये वाला टीवी चैनल हवे। एकरे अलावा बिबिध हिंदी, अंग्रेजी आ क्षेत्रीय भाषा सभ के चैनल केबिल प्रसारण आ डिश द्वारा उपलब्ध बाने। 24 घंटा समाचार प्रसारण वाला चैनल में ''[[एनडीटीवी इंडिया]]'', ''[[डीडी न्यूज]]'', ''जी न्यूज'', ''जन टीवी'', ''आइबीएन-7'', ''आज तक'' आ ''एबीपी न्यूज'' प्रमुख बाने। आल इंडिया रेडियो (आकाशवाणी) राज्य के रेडियो चैनल हवे। एकरे अलावा 32 गो प्राइवेट फ्रीक्वेंसी वाला एफएम चैनल के प्रसारण उत्तर प्रदेश के अलग-अलग शहर सभ में हो रहल बा।<ref name="RADIO STATIONS">{{cite web|title=Radio Stations in Uttar Pradesh, India|url=http://www.asiawaves.net/india/uttar-pradesh-radio.htm|publisher=Asiawaves|accessdate=14 July 2012}}</ref><ref name="FM Stations">{{cite web|title=Indian FM Stations Statewise|url=http://fmstations.bharatiyamobile.com/Indian-FM-Stations-Statewise.php?state=Uttar+Pradesh&location=Aligarh|publisher=Bharatiya mobile|accessdate=14 July 2012}}</ref> सेलफोन नेटवर्क सभ में राज्य के मालिकाना वाला बीएसएनएल बा आ प्राइवेट में वोडाफोन, रिलायंस, एयरटेल, एयरसेल, टेलिनोर, टाटा इंडीकॉम, आइडिया सेलुलर आ टाटा डूकोमो बाने। कुछ चुनल शहर सभ में ब्राडबैंड के सुबिधा उपलब्ध बा जे बीएसएनएल आ कुछ प्राइवेट कंपनी सभ द्वारा उपलब्ध करावल जाले।<ref name=cellular>{{cite web|title=Uttar Pradesh (East)|url=http://www.india-cellular.com/UPE-page.html|publisher=India cellular phone industry|accessdate=14 July 2012}}</ref> बीएसएनएल आ अन्य प्रदाता सभ द्वारा डायल-अप सेवा भी उपलब्ध करावल जाले।<ref name="dial up">{{cite web|title=Internet Service Provider|url=http://www.datainfocom.in/services/isp.htm|publisher=Data Infocom Limited|accessdate=14 July 2012|archive-date=25 July 2012|archive-url=https://web.archive.org/web/20120725111443/http://datainfocom.in/services/isp.htm|url-status=dead}}</ref>
==संदर्भ==
{{Reflist|35em}}
{{भारत के राज्य अउरी संघ राज्यक्षेत्र}}
{{उत्तर प्रदेश}}
{{Uttar Pradesh topics}}
[[श्रेणी:उत्तर प्रदेश| ]]
[[श्रेणी:भारत के राज्य अउरी संघ राज्यक्षेत्र]]
[[श्रेणी:भारत के राज्य]]
rdlgma5san2sxs0tdcs13ovix6wtv44
तबला
0
5291
790109
787361
2026-04-03T06:55:21Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790109
wikitext
text/x-wiki
{{Infobox Instrument
|name=
|image=Tabla.jpg
|background=percussion
|classification= भारतीय ताल बाजा
|range= लकड़ी के गट्टा के हथौड़ी से मार के सुर साधल जाला
|related= [[पखावज]], [[मिरदंग]], [[खोल]], [[ढोलक]], [[नगारा]], [[बोंगो]]
}}
'''तबला''' एकठो बाजा भारतीय बाजा हवे, जे ताल देवे के साज के रूप में बजावल जाला। तबला में दू गो चमड़ा मढ़ल हिस्सा होलें जिनहन के ''दाहिना'' आ ''बायाँ'' कहल जाला। तकनीकी रूप से दाहिना के '''''तबला''''' आ बायाँ के ''डुग्गी'' या ''धामा'' कहल जाला। बायाँ के साइज बड़हन होला आ आवाज गंभीर, जबकि दाहिना के आवाज ऊँच सुर में होला आ एकर आकार पातर होला।
परंपरा अनुसार एकर उत्पत्ति पखावज से भइल मानल जाला, हालाँकि, कुछ लोग एकर पैदाइश पच्छिमी एशिया में बतावे ला।<ref>{{Cite web |title=Class Material: Introduction to Tabla, the Ancient Indian Drums |url=http://web.mit.edu/chintanv/www/tabla/class_material/Introduction%20to%20Tabla.ppt |access-date=2026-01-13 |website=web.mit.edu |format=ppt}}</ref>
==ताल के बोल==
;दाहिना के बोल:
* ता/ना - किनारा पर तर्जनी (पहिली) अँगुरी से, ठोकर के बाद अँगुरी तुरंत उठ जाले।
* ती - मैदान में तर्जनी से ठोकर, अँगुरी तुरंत उठ जाले।
* तिन् - सियाही पर तर्जनी से ठोकर, अँगुरी तुरंत उठ जाले।
* ते - तर्जनी के अलावा बाकी तीन अँगुरी (या खाली बिचली अँगुरी) से सियाही पर, अँगुरी कुछ देर खातिर टिके ले जेवना से गुंजन न होखे।
* टे - तर्जनी अँगुरी से सियाही पर, गुंजन ना।
;बायाँ के बोल:
* धा/धे - पहिली अँगुरी से बीच में ठोकर
* क/के - पूरा हथोरी सपाट रख दिहल जाला, गुंजन ना।
*घिस्सा - बीच में ठोकर के बाद हथोरी के पछिला हिस्सा के आगे बीच के सियाही के ओर सरकावल जाला, जेकरा से गुंजन धीरे-धीरे बंद होला।
===तबला के ताल===
[[File:Tabla_drums_demo.webm|thumb|तबला बजावे के उदाहरण]]
भारतीय संगीत में चलन में ताल सभ में कुछ अइसन बाने जे धीमा लय में बजावे पर अधिक निखर के सामने आवे लें। हालाँकि, कुछ ताल तेज लय में बजावे पर ढेर निखरे लें, तीन ताल एक ठो अइसन ताल हवे जे मंद आ तेज दूनों लय में नीक लागे ला।
भारतीय संगीत में समय के साथ बदलाव में बाजा भी बदलल आ ओही के साथ ताल के चलन भी। जहाँ पुराना समय में मिरदंग आ पखावज के चलन ढेर रहे, लंबा ताल सभ के प्रचलन रहल। बाद में छोट बंद वाला ताल सभ प्रमुख हो गइलेन। उदाहरन खातिर बॉलीवुड के गाना में सभसे ढेर चलनसार ताल दादरा आ कहरवा हवें।
नीचे तबला पर बजावल जाए वाला कुछ प्रमुख ताल सभ के संछेप लिस्ट दिहल जात बा:
{| class="wikitable"
|-
! नाँव
! मात्रा
! खंड
! बिभाग
|-
| [[तीनताल]] (त्रिताल या तिनतल्ला)
| 16
| 4+4+4+4
| X 2 0 3
|-
| [[झूमरा]]
| 14
| 3+4+3+4
| X 2 0 3
|-
| [[तिलवाड़ा]]
| 16
| 4+4+4+4
| x 2 0 3
|-
| [[धमार]]
| 14
| 5+2+3+4
| X 2 0 3
|-
| [[एकताल]] आ चौताल
| 12
| 2+2+2+2+2+2
| X 0 2 0 3 4
|-
| [[झपताल]]
| 10
| 2+3+2+3
| X 2 0 3
|-
| [[कहरवा]]
| 8
| 4+4
|X 0
|-
| [[रूपक]]
| 7
| 3+2+2
| X 2 3
|-
| [[दादरा]]
| 6
| 3+3
| X 0
|}
==प्रसिद्ध तबला वादक==
अल्ला रक्खा<ref name="autogenerated1">{{cite web |url=https://khabar.ndtv.com/video/show/news/tabla-player-sandip-das-received-grammy-awards-449163 |title=बनारस घराने के तबला वादक संदीप दास को मिला ग्रैमी अवॉर्ड वीडियो - हिंदी न्यूज़ वीडियो एनडीटीवी ख़बर |publisher=Khabar.ndtv.com |date=2017-02-13 |accessdate=2017-02-26 |archive-date=2017-02-20 |archive-url=https://web.archive.org/web/20170220173227/https://khabar.ndtv.com/video/show/news/tabla-player-sandip-das-received-grammy-awards-449163 |url-status=dead }}</ref> ज़ाकिर हुसैन<ref>{{cite web|author=Biography by Craig Harris |url=http://www.allmusic.com/artist/zakir-hussain-mn0000695019/biography |title=Zakir Hussain | Biography & History |publisher=AllMusic |date=1951-03-09 |accessdate=2017-02-26}}</ref> संदीप दास<ref name="autogenerated1"/>
{{Indian musical instruments}}
[[श्रेणी:बाजा]]
== References ==
<references />
{{संगीत-आधार}}
9ukv9hp6lsq0iufagc66t50kjl94vcu
हनुमान
0
8242
790260
777256
2026-04-03T08:56:43Z
Sultansin
39915
790260
wikitext
text/x-wiki
{{Infobox deity
| type = हिंदू
| name = हनुमान
| image = Maruti.JPG
| caption = हनुमान, राजा रवि वर्मा के बनावल चित्र
| affiliation = [[देव (हिंदू धर्म)|देव]]<br>[[राम|श्रीराम]] आ [[सीता]] के भक्त (बैष्णव मत)<br>[[शिव]] के अवतार भा अंश
| deity of = बल, बुद्धि, भक्ति आ बिद्या के देवता
| parents = अंजना (महतारी)<br>केशरी, पवनदेव<ref name=debroy184>{{cite book|author=Bibek Debroy|title=The Mahabharata: Volume 3|url=https://books.google.com/books?id=af1qFbouaVMC&pg=PA184|year=2012|publisher=Penguin Books|isbn=978-0-14-310015-7|pages=184 with footnote 686}}</ref> भा [[शिव]] (पिता)
| weapon = गदा
| texts = [[रामायण]], [[रामचरितमानस]], [[हनुमान चलीसा]], बजरंग बाण, शिव पुराण<ref>{{cite book|url=https://books.google.co.in/books?id=19aoCgAAQBAJ&pg=PT193|title=Hinduism in the Modern World|author=Brian A. Hatcher|publisher=Routledge|year=2015|isbn=9781135046309}}</ref>
| festivals = हनुमान जयंती
}}
'''हनुमान''', [[हिंदू धर्म]] में एगो [[देवता]] हवें जिनकर रूप [[बानर]] के ह। हनुमान के अनन्य [[राम]]भक्त के रूप में मानल जाला<ref name="Williams2008p146"/> आ भारतीय उपमहादीप आ दक्खिन-पुरुब एशिया में मिले वाला "[[रामायण]]" के बिबिध रूप आ पाठ सभ में हनुमान एगो प्रमुख चरित्र हवें।<ref name="Claus2003p280"/> हनुमान के चिरंजीवी मानल जाला आ एह रूप में इनके बिबरन अउरी कई ग्रंथ सभ, जइसे कि [[महाभारत]],<ref name="Williams2008p146"/> कई गो पुराण सभ में आ जैन ग्रंथ सभ,<ref name=brithanuman/> बौद्ध,<ref name=whitfield212/> आ सिख धर्म के ग्रंथ सभ में मिले ला।<ref name="louis143"/> कई ग्रंथ सभ में हनुमान के [[शिव]] के अवतार<ref name="Williams2008p146"/> भा अंश भी मानल गइल बा।{{sfn|Devi Vanamali|2016|p=27}} हनुमान के अंजना आ केशरी के बेटा मानल जाला, आ कुछ कथा सभ के मोताबिक पवन देव के भी, काहें कि इनके जनम में पवनदेव के भी योगदान रहे।<ref name=debroy184/><ref name="Melton2010p1310">{{cite book|author1=J. Gordon Melton|author2=Martin Baumann|title=Religions of the World: A Comprehensive Encyclopedia of Beliefs and Practices, 2nd Edition|url= https://books.google.com/books?id=v2yiyLLOj88C |year= 2010|publisher=ABC-CLIO|isbn=978-1-59884-204-3|pages=1310–1311}}</ref>
हिंदू धरम में हनुमान के देवता भा पूज्य चरित्र के रूप में परतिष्ठा कब भइल ई बिबाद के बिसय बा। एहू बारे में बिबाद बा कि इनके पहिले का स्वरुप रहल आ वर्तमान देवता के रूप से केतना अलग रहल।{{sfn|अंबा प्रसाद श्रीवास्तव|2000|p=}} बैकल्पिक थियरी सभ के अनुसार इनके बहुत प्राचीन साबित कइल जाला, ग़ैर-आर्य देवता के रूप में कल्पित कइल जाला जेकरा के बाद में वैदिक आर्य लोग संस्कृताइज क लिहल, या फिर साहित्य में इनके धार्मिक प्रतीकवाद के उपज आ यक्ष रुपी देवता लोग के फ्यूजन से गढ़ल देवता के रूप में भी कल्पित कइल जाला।<ref name=ludvik2/><ref name="Philip_2007"/>{{rp|39–40}}
हालाँकि, हिंदू धर्म के परसिद्ध कृति रामायण महाकाव्य आ एकरे बाद के बिबिध रामकथा सभ में हनुमान एगो प्रमुख चरित्र के रूप में मौजूद बाने, इनके पूजा करे के बिबरन प्राचीन आ मध्यकालीन ग्रंथ सभ में आ पुरातात्विक खोदाई से मिलल सबूत सभ में कम मिले के बात कहल जाला। अमेरिकी भारतबिद, फिलिप लुटगेंडार्फ, जे हनुमान पर अध्ययन करे खाती मशहूर बाने, माने लें कि हनुमान के धार्मिक आ पूज्य देवता के रूप में महत्व रामायण के रचना के लगभग 1,000 साल बाद दूसरी सहस्राब्दी ईसवी में भइल जब इस्लाम के भारत में आगमन भइल।<ref name="Paula Richman 2010">Paula Richman (2010), ''Review: Lutgendorf, Philip's Hanuman's Tale: The Messages of a Divine Monkey'', The Journal of Asian Studies; Vol 69, Issue 4 (Nov 2010), pages 1287-1288</ref> भक्ति आन्दोलन के संत, जइसे कि समर्थ रामदास वगैरह लोग द्वारा हनुमान के राष्ट्रवाद आ अत्याचार के खिलाफ बिद्रोह के चीन्हा के रूप में स्थापित कइल गइल।<ref name=lele114/> आज के ज़माना में इनके मुर्ती, चित्र आ मंदिर बहुत आम बाने।<ref name="JonesRyan2006p177">{{cite book|author1=Constance Jones|author2=James D. Ryan|title=Encyclopedia of Hinduism|url=https://books.google.com/books?id=OgMmceadQ3gC |year=2006|publisher=Infobase Publishing|isbn=978-0-8160-7564-5|pages=177–178}}</ref> हनुमान के "ताकत, हीरोइक कामकर्ता आ सबल क्षमता" के साथ "कृपालु, आ राम के प्रति भावनात्मक भक्ति" के चीन्हा के रूप में शक्ति आ भक्ति के आदर्श मिलजुल रूप वाला देवता के रूप में परतिष्ठा भइल।<ref name=lutgendorf26>{{cite book | author=Philip Lutgendorf | title=Hanuman's Tale: The Messages of a Divine Monkey | url=https://books.google.com/books?id=fVFC2Nx-LP8C&pg=PA31 | accessdate=14 July 2012 | year= 2007 | publisher=Oxford University Press | isbn=978-0-19-530921-8 |pages=26–32, 116, 257–259, 388–391}}</ref> बाद के साहित्य में हनुमान के मल्लजुद्ध, आ कलाबाजी के देवता के रूप में भी आ ग्यानी-ध्यानी बिद्वान के रूप में भी स्थापना भइल।<ref name="Williams2008p146">{{cite book|author=George M. Williams|title=Handbook of Hindu Mythology|url=https://books.google.com/books?id=N7LOZfwCDpEC&pg=PA146 |year=2008|publisher=Oxford University Press|isbn=978-0-19-533261-2|pages=146–148}}</ref> इनके निरूपण आत्म-नियंत्रण, बिस्वास आ आस्था, नियत कारज में सेवा के भावना के छिपल निरूपण भइल जेकर बाहरी रूप भले बानर के बा।<ref name="JonesRyan2006p177"/><ref name="Lutgendorf 1997 311–332">{{cite journal | last=Lutgendorf | first=Philip | title=Monkey in the Middle: The Status of Hanuman in Popular Hinduism | journal=Religion | publisher=Routledge | volume=27 | issue=4 | year=1997| doi=10.1006/reli.1997.0095 | pages=311–332}}</ref><ref name=ludvik2>{{cite book|author=Catherine Ludvik|title=Hanumān in the Rāmāyaṇa of Vālmīki and the Rāmacaritamānasa of Tulasī Dāsa|url=https://books.google.com/books?id=KCXQN0qoAe0C |year=1994|publisher=Motilal Banarsidass|isbn=978-81-208-1122-5|pages=2–9}}</ref>
हिंदू धर्म में एगो बहुत चलनसार देवता होखे के साथे-साथ हनुमान जैन आ बौद्ध धर्म में भी मौजूद बाने।<ref name=brithanuman/><ref>{{cite journal | last=Lutgendorf | first=Philip | title=My Hanuman Is Bigger Than Yours | journal=History of Religions | publisher=University of Chicago Press | volume=33 | issue=3 | year=1994 | doi=10.1086/463367 | pages=211–245}}</ref> इहे ना, बलुक भारत से बहरें के कई देसन में हनुमान के बिबिध रूप में परतिष्ठा बा, जइसे कि म्यांमार, थाइलैंड, कंबोडिया, मलेशिया आ बाली अउरी इंडोनेशिया में हनुमान के पूजल जाला भा इनके मुर्ती के निरूपण मिले ला। बाहरी देसन में हनुमान के चित्रण कुछ अलग तरीका से भी मिले ला जे हिंदू धर्म के हनुमान से भिन्न बा। उदाहरण खाती कुछ संस्कृति में हनुमान के बिसाल छाती वाला शक्तिशाली देव के रूप में जरूर कल्पित कइल जाला बाकिर उनके ब्रह्मचारी रूप में ना बलुक बियाह करे आ लइका-फइका वाला रूप में मानल गइल बा जइसे भारतो के कुछ इलाकाई हिस्सा में मानल जाला। कुछ बिद्वान लोग के अइसन मत भी बा कि परसिद्ध चीनी काब्यात्मक उपन्यास "शीयूजी" (पच्छिम के यात्रा), जे चीनी यात्री ह्वेन सांग (602–664 ईसवी) के भारत यात्रा के बिबरण से परभावित हो के लिखल गइल रहे, एह में कौतुक आ साहस भरल बानर के चरित्तर वाला हीरो, हनुमान के कथा से प्रेरणा ले के रचल गइल हवे।<ref name=brithanuman>Wendy Doniger, [https://www.britannica.com/topic/Hanuman Hanuman: Hindu mythology], Encyclopaedia Britannica; For a summary of the Chinese text, see [https://www.britannica.com/topic/Xiyouji Xiyouji: NOVEL BY WU CHENG’EN]</ref><ref>H. S. Walker (1998), [https://pdfs.semanticscholar.org/0e76/16987a9845d9aefc84e0aaf88f4ffd6a3a4b.pdf Indigenous or Foreign? A Look at the Origins of the Monkey Hero Sun Wukong] {{Webarchive|url=https://web.archive.org/web/20200524122431/https://pdfs.semanticscholar.org/0e76/16987a9845d9aefc84e0aaf88f4ffd6a3a4b.pdf |date=2020-05-24 }}, Sino-Platonic Papers, No. 81. September 1998, Editor: Victor H. Mair, University of Pennsylvania</ref>विभिन्न विद्वान लोग सुझाव दिहले बा कि हनुमान ने चीनी महाकाव्य जर्नी टू द वेस्ट के केंद्रीय पात्र सन वुकोंग की अवधारणा के प्रभावित काईले होइहे।[19][20]
==नाँव==
[[File:A Hanuman sculpture in Singapore.jpg|left|upright=0.8|thumb|160px|प्रणाम के मुद्रा में हाथ जोड़ले हनुमान]]
"हनुमान" नाँव, जे इनके सभसे चलनसार नाँव हवे, के उत्पत्ति आ अरथ के बारे में लोग एकमत नइखे। हिंदू धरम में एकही देवता के कई गो नाँव होखल बहुत आम बात हवे। कौनों-न-कौनों बिसेसता भा लच्छन के आधार पर देवता लोग के बिबिध नाँव रखल गइल हवें।<ref name="Philip_2007"/>{{rp|31–32}} हनुमान के भी कई गो अउरी नाँव बाड़ें जइसे कि आंजनेय, अंजनीसुत, अंजनी पुत्र, मारुति, पवनसुत, बजरंगबली वगैरह बाकी एह में से सभके इस्तेमाल हमेशा ना होला। आम तौर प सभसे चलन में हनुमाने हवे।
एह नाँव के पाछे एगो ब्याख्या ई दिहल जाला कि हनुमान जी बचपन में सुरुज भगवान के सुघर फल बूझ के लपक लिहलें आ मुँह में भर लिहलें जवना से चारों ओर अन्हियारी फइल गइल आ हनुमान के मुँह से सुरुज के बहरें निकासे खाती इंद्र अपना बज्र से प्रहार कइलेन जवना से हनुमान जी के दाढ़ी ("संस्कृत में ''हनु'') कुछ टेढ़ भ गइल। एही के बाद टेढ़ हनु वाला, इनके हनुमान कहल जाए लागल।<ref name="Philip_2007"/>{{rp|31–32}}
एगो दूसर ब्याख्या ई कइल जाला कि संस्कृत में "हन्" के अरथ होला नास होखल, आ "मान" के अरथ होला गरब भा अभिमान; एह आधार पर हनुमान के अरथ बतावल जाला कि जेकर भक्ति में आपन मान नष्ट हो गइल होखे। अइसन इनके द्वारा राम आ सीता के भक्ति में अनन्य समर्पण आ भक्ति के कारण बतावल जाला। एह तरीका से हनुमान के ताकत, शक्ति आ बीरता के साथे साथ भावुक आ दयालु अउरी भक्त देवता के रूप में कल्पित कइल जाला आ भक्ति आ शक्ति दुन्नों के चीन्हा के रूप में देखल जाला।<ref name="Philip_2007">{{cite book | author=Philip Lutgendorf | title=Hanuman's Tale: The Messages of a Divine Monkey | url=https://books.google.com/books?id=fVFC2Nx-LP8C&pg=PA31 | accessdate=14 July 2012 | year= 2007 | publisher=Oxford University Press | isbn=978-0-19-530921-8 }}</ref>{{rp|31–32}}
एगो तिसरहा मत जैन धरम में मिले ला। एह कथा के मोताबिक हनुमान अपना बचपन के दिन एगो अइसन [[दीप]] पर बितवलें जेकर नाँव ''हनुरुह'' रहे; एही दीप के नाँव पर इनकरो नाँव हनुमान धरा गइल।<ref name="Philip_2007"/>{{rp|189}}
हनुमान शब्द के भाषाई बिबिधता के रूप में ''हनुमत'', ''अनुमान'' ([[तमिल भाषा|तमिल]] में), ''हनुमंत'' ([[कन्नड़]]), ''हनुमंथुदु'' ([[तेलुगु भाषा|तेलुगु]]) वगैरह मिले लें। हनुमान के अलावा इनके अन्य कई नाँव नीचे दिहल जा रहल बाने:
* ''आंजनेय'',<ref>{{cite book|title=India through the ages|last=Gopal|first=Madan|year= 1990| page= 68|editor=K.S. Gautam|publisher=Publication Division, Ministry of Information and Broadcasting, Government of India}}</ref> जेकर बिबिध रूप बाड़ें: ''अंजनीसुत'', ''अंजनेयार'' (तमिल) ''आंजनेयादु'' (तेलुगु)। ई सगरी नाँव इनके महतारी अंजना के नाँव पर रखल हवें आ इनहन के मतलब होला "अंजनी के बेटा"।
* ''केशरी नंदन'', पिता केशरी के नाँव पर, जेकर मतलब बा "केशरी के बेटा"
* ''मारुति'', (''मरुत'' माने पवन या वायुदेव) "पवन के बेटा";<ref name="Claus2003p280"/> अन्य नाँव में ''पवनसुत'', ''पवनपुत्र'', ''वायुनंदन'' वगैरह।
* ''बजरंग बली'', "जेकर अंग बज्र नियर बलवान होखे"; ई नाँव उत्तर भारत के देहाती इलाका में बहुत चलनसार हवे।<ref name="Philip_2007"/>{{rp|31–32}}
* ''संकट मोचन'', "संकट से छुटकारा दियावे वाला"<ref name="Philip_2007"/>{{rp|31–32}}
* ''महावीर''', मने की महान बीर,
* ''कपीश'', कपि, मने बानर लोग के स्वामी वगैरह।
{{clear}}
==इहो देखल जाय==
* [[हनुमान चलीसा]]
* [[संकट मोचन मंदिर]]
==संदर्भ==
{{Reflist|33em}}
==स्रोत==
{{refbegin}}
* {{cite book|ref=harv|author=Devi Vanamali|title=Shree Hanuman Leela|url=https://books.google.com/books?id=Jg4WDgAAQBAJ&pg=PA27|year=2016|publisher=Manjul Publishing|isbn=978-81-8322-724-7}}
<!-- {{sfn|माहेश्वरी|1998|p=}} -->
* {{cite book|ref=harv|last=माहेश्वरी|first=प्रेमचन्द्र|title=हिंदी रामकाव्य का स्वरुप और विकास|url=https://books.google.com/books?id=4gV7Xo9L4WgC&pg=PA128|year=1998|publisher=वाणी प्रकाशन}}
* {{cite book|ref=harv|author=अंबा प्रसाद श्रीवास्तव|title=Rāmāyaṇa kā ācāra darśana|url=https://books.google.com/books?id=8SkuQRyd5f0C&pg=PA185|year=2000|publisher=Bhāratīya Jñānapiṭha|isbn=978-81-263-0283-3}}
{{refend}}
==बाहरी कड़ी==
{{Commons category|Hanuman}}
* [https://www.britannica.com/topic/Hanuman हनुमान] - ''Encyclopædia Britannica'' {{in lang|en}}
[https://hanumanchalisalyrics.co.in/ Hanuman Chalisa - Lyrics mp3 ringtone]
{{हिंदू देवी-देवता}}
[[श्रेणी:हिंदू धर्म]]
[[श्रेणी:देवी-देवता]]
atxgs9xnsf3bezr8rt6xarrm6i7eznn
पर्यावरण प्रदूषण
0
9495
790263
789751
2026-04-03T10:21:56Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790263
wikitext
text/x-wiki
[[चित्र:Emissão+de+gases+poluentes.jpg|thumb|right|220px|कारखाना के चिमनी से निकलत धुआँ, [[हवा प्रदूषण]]]]
[[चित्र:CoalcliffICC.jpg|thumb|right|220px|ऑस्ट्रेलिया में कोयला के संयंत्र। कोयला के दहन से कार्बन डाइऑक्साइड के निर्माण होला, साथ ही साथ सल्फर डाइऑक्साइड के भी अलग-अलग मात्रा में उत्पादन होला।]]
'''पर्यावरण प्रदूषण''' भा '''पर्यावरणीय प्रदूषण''' ({{Langx|en|environmental pollution}}), चाहे खाली भर '''प्रदूषण''' ({{Lang|en|pollution}}), अइसन घटना हऽ जेवना में [[प्राकृतिक पर्यावरण]] में कौनो अइसन चीज क प्रवेश होला जेवना से [[पर्यावरण]] के नोकसान पहुँचे, ओकर क्वालिटी खराब होखे। जवनी चीज की प्रवेश से अइसन होला ओ पदार्थन के प्रदूषक पदार्थ कहल जाला।<ref>[http://hindi.indiawaterportal.org/content/%E0%A4%9C%E0%A4%B2-%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A4%A6%E0%A5%82%E0%A4%B7%E0%A4%A3-%E0%A4%95%E0%A5%8D%E0%A4%AF%E0%A4%BE-%E0%A4%B9%E0%A5%88 जलप्रदूषण क्या है?] {{Webarchive|url=https://web.archive.org/web/20140716163134/http://hindi.indiawaterportal.org/content/%E0%A4%9C%E0%A4%B2-%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A4%A6%E0%A5%82%E0%A4%B7%E0%A4%A3-%E0%A4%95%E0%A5%8D%E0%A4%AF%E0%A4%BE-%E0%A4%B9%E0%A5%88 |date=2014-07-16 }} इण्डिया वाटर पोर्टल (उतारल गइल 29.06.2014 के)</ref> आमतौर पर पर्यावरण में कई प्राकृतिक कारण से अइसन पादर्थ सभ के प्रवेश हो सके ला जे नोकसानदेह होखे, जइसे कि जंगल के आग से निकलल धुँआ चाहे ज्वालामुखी से निकले वाली गैस आ धुँआ, बाकी एह शब्द के इस्तेमाल [[पर्यावरण पर मनुष्य के परभाव|मनुष्य द्वारा]] पर्यावरण में पहुँचावल जा रहल खराब परभाव वाली चीजन खातिर होखे ला।<ref name="Britannica">{{cite web|title=pollution {{!}} Definition, History, & Facts|url=https://www.britannica.com/science/pollution-environment|website=Encyclopedia Britannica|accessdate=6 मई 2020|language=en}}</ref> ई प्रदूषक सभ ठोस, द्रव चाहे गैस के रूप में पदार्थ हो सके ला चाहे गर्मी वगैरह के रूप में एनर्जी हो सके ले; बस अगर प्रदूषक तत्व के पर्यावरण में एतना तेजी से प्रवेश हो रहल बा कि ऊ प्राकृतिक रूप से गैर-नोकसानदेह रूप में बदल जाय चाहे छितरा जाय, तब ऊ प्रदूषण कहल जाई।<ref name="Britannica" />
प्रदूषण क कई गो प्रकार हो सकेला। आमतौर पर पर्यावरण की जवनी अंग में प्रदूषक चीज क प्रवेश होला ओही की नाँव पर ओ प्रकार का भी नाँव रखल जाला। जइसे अगर पानी में कौनो कूड़ा-कचरा फेकला से पानी क गुणवत्ता खराब होखे त ए के [[पानी प्रदूषण|जल प्रदूषण]] कहल जाई।
एही प्रकार से [[वायु प्रदूषण]] आ [[माटी प्रदूषण|मिट्टी प्रदूषण]] क नाँव धराइल बा। कई बेर जवनी चीज से प्रदूषण होला ओहू की नाँव पर प्रदूषण की प्रकार क नाँव धरा जाला जइसे कि आवाज से होखे वाला प्रदूषण के आवाज प्रदूषण आ प्रकाश से होखे वाला के प्रकाश प्रदूषण कहल जाला।
प्रदूषण से आदमी के सेहत पर बहुत किसिम के खराब परभाव पड़े लें। हाले में विश्व स्वास्थ्य संगठन की एगो आकलन की हिसाब से साल 2012 में हवा प्रदूषण की कारण करीब 70 लाख लोगन के आपन जान गंवावे के पड़ल।<ref name="BBC">[http://www.bbc.co.uk/hindi/science/2014/03/140325_world_air_pollution_sk.shtml वायु प्रदूषण से साल भर में 70 लाख मौतें] BBC हिंदी, (उतारल गइल 29.06.2014 के)</ref>
== इतिहास ==
प्रदूषण के सुरुआत आदमी के द्वारा एकट्ठा हो के एक जगह रहे के एकदम सुरुआती दौर से शुरू होला, जबसे मनुष्य झुंड में बस्ती बना के रहे शुरू कइल; आखिर आजो बिबिध अध्ययन में अइसन पुराना बस्ती सभ के ओही सभ चीजन से पहिचान कइल जाला जे ओह जमाना के आबादी द्वारा कबाड़ के रूप में छोड़ल गइल।<ref name="Britannica" /> हालाँकि, प्रदूषण तबतक ले कौनों समस्या ना रहल जबतक के हर ब्यक्ति के लगे निवास करे खातिर पर्याप्त जगह रहे। मूल रूप से कोइला के इस्तेमाल आ शहरीकरण से एह समस्या के सुरुआत दर्ज कइल जाला; भले ऊ हजार दू हजार साल पुरान शहर सभ होखें। धातु पघिलावे के काम में भट्ठी के इस्तेमाल से प्रदूषण के उदाहरण बहुत पुराना समय के सभ्यता सभ में मिले ला।
बाद के प्रदूषण मुख्य रूप से उद्योग क्रांति के बाद के समस्या हवे। बिबिध किसिम के उद्योग सभ में कोइला के इस्तेमाल से उपजे वाला धुँआ आ एह उद्योग सभ से निकले वाला कचरा प्रदूषण के सभसे प्रमुख वजह बनल।
== प्रकार चाहे रूप ==
[[चित्र:Canal-pollution.jpg|thumb|right|220px|मांट्रियल की एगो नहर में कूड़ा-कचरा]]
प्रदूषण के बर्गीकरण कई आधार पर कइल जा सके ला आ एकरा के कई प्रकार में बाँटल जा सके ला। पर्यावरण भा इकोसिस्टम के कवन अंग में प्रदूषक तत्व प्रवेश का रहल बाड़ें एह आधार पर, प्रदूषक तत्व के आधार पर, भा मनुष्य के ओह कामकाज के आधार पर जवना से प्रदूषण हो रहल बा, ई कुछ अइसन आधार बाड़ें जिन्हन के हिसाब से बाँट के प्रदूषण के प्रकार बतावल जाला। नीचे ई संछेप में दिहल गइल बा:
=== पर्यावरण के अंग अनुसार ===
====[[हवा प्रदूषण]]====
पृथिवी के [[वायुमंडल]] में मौजूद हवा के गुणवत्ता सगरी जीवधारी सभ आ [[इकोसिस्टम]] के सही से संचालन खाती बहुत महत्व के चीज बा। अगर हवा में प्रदूषक तत्व के प्रवेश होखे आ ओह कारण से हवा के गुणवत्ता में कमी आवे, एकर परभाव जीव-जंतु, जेह में मनुष्य भी शामिल बाड़ें, आ इकोसिस्टम के काम करे पर खराब असर डाले तब स्थिति [[हवा प्रदूषण]] होला। सभसे आम रूप धुँआ के प्रवेश से हवा के गुणवत्ता में खराबी बा।<ref name="Stern2015">{{cite book|author=Arthur C. Stern|title=Sources of Air Pollution and Their Control: Air Pollution|url=https://books.google.com/books?id=_WUhBQAAQBAJ&pg=PP1|date=4 December 2015|publisher=Elsevier|isbn=978-1-4832-6828-6|pages=1–}}</ref> चाहे ई धुँआ उद्योग सभ के चिमनी से निकले वाला होखे, डीजल-पेट्रोल से चले वाली गाड़ी सभ के होखे, खेत में बेकार डाठ जरावे से होखे। शहरीकरण आ उद्योगीकरण के कारण पूरा दुनिया में धुँआ से होखे वाला हवा प्रदूषण एगो समस्या बाटे। एकरे अलावा धूर के महीन कण वगैरह के हवा में चहुँपे से भी हवा प्रदूषण होला।<ref name="Stern2015" />
आम गैस सभ जे हवा प्रदूषण खातिर जिम्मेदार बाड़ी उनहन में कार्बन मोनोऑक्साइड, सल्फर डाइऑक्साइड, क्लोरोफ्ल्यूरोकार्बन (CFCs) आ नाइट्रोजन के आक्साइड बाड़ें जे उद्योग सभ आ मोटरगाड़ी आ से पैदा होखे लें। फोटोकेमिकल ओजोन आ स्मॉग के पैदाइश तब होखे ला जब नाइट्रोजन के ऑक्साइड सभ आ हाइड्रोकार्बन सभ सुरुज के रोशनी के साथे रिएक्शन करे लें। [[पार्टिकुलेट मैटर]], या फिर महीन धूर में माइक्रोमीटर साइज PM<sub>10</sub> से PM<sub>2.5</sub> हवा के प्रदूषण के कारण बने ला।
हावा प्रदूषण केतना नोक्सान्देह हो सकेला एकर अंजाद एही से लगावल जा सके ला कि [[बिस्व स्वास्थ्य संगठन]] के एगो आकलन की हिसाब से साल 2012 में हावा प्रदूषण के चलते करीब 70 लाख लोगन के आपन जान गंवावे के पड़ल।<ref name="BBC" />
====[[जल प्रदूषण]]====
पानी परदूषण भा जल प्रदूषण पानी के भंडार सभ में नोकसानदेह चीजन के प्रवेश से होला। [[नदी]], [[झील]], ताल, [[समुंद्र]] आ जमीन के नीचे के जलसोता सभ में सीधे या फिर अप्रत्यक्ष रूप से नोक्सानदेह पदार्थन के पहुँचे से उनहन में मौजूद पानी के क्वालिटी खराब हो जाला आ जिंदा जिया-जंतु आ बनस्पति सभ खातिर इस्तमाल लायक ना रह जाला।
मनुष्य के कई तरह के कामकाज सभ से पानी के क्वालिटी खराब हो सके ले। आमतौर पर शहर आ बस्ती सभ से निकले वाला गंदा पानी आसपास के नदी चाहे झील में पहुँच के ओकरा के गंदा क सके ला। शहर सभ में कई किसिम के उद्योग अइसन होलें जिनहन से गंदगी आ नोकसानदेह पदार्थ बाहर निकले लें आ पानी में छोड़ दिहल जालें। एकरे अलावा खेती में इस्तेमाल होखे वाली केमिकल वाली खाद आ बिबिध किसिम के कीटनाशक सभ अंत में बहि के पानी में पहुँचे लें आ नदी के पानी के गंदा क सके लें।
====[[माटी प्रदूषण]]====
[[माटी]] में मनुष्य द्वारा नोकसान देह पदार्थ छोड़े से भा कौनों अन्य तरीका से माटी के प्राकृतिक सिस्टम के खराब करे से होला। अधिकतर, ई उद्योग से निकले वाला कचड़ा आ गंदा पानी से, खेती में बहुत ढेर खाद आ कीटनाशक के इस्तमाल से आ शहरी कचड़ा के बिना शोधले फेंके से होला।
माटी में परदूषण भा कंटामिनेशन खातिर जिम्मेदार मुख्य पदार्थ सभ में पेट्रोलियम हाइड्रोकार्बन (पेट्रोलियम तेल से निकले वाला कार्बनिक पदार्थ, जइसे प्लास्टिक, पन्नी वगैरह), कीटनाशक, आ भारी घातु के कण शामिल बाने।
====[[समुंद्री प्रदूषण]]====
समुंद्री प्रदूषण [[समुंद्र]] आ सागर सभ के पानी में अइसन पदार्थ के प्रवेश होला जे नोकसानदेह होखे। ई प्रदूषक तत्व सभ आम कचरा-कबाड़ हो सके ला, रासायनिक पदार्थ (केमिकल) हो सके लें, [[प्लास्टिक]] हो सके ला, खेती किसानी के इस्तेमाल के खाद आ कीटनाशक के बह के समुंद्र में पहुँचे वाला हिस्सा हो सके ला आ अउरी किसिम-किसिम के नोकसान पहुँचावे वाला चीज हो सके ला। साथे साथ कौनों जगह के समुंदरी पानी में आक्रमणकारी प्रजाति के पहुँच जाए के भी समुंद्री प्रदूषण में गिनल जा सके ला।
लगभग अस्सी प्रतिशत समुंदरी प्रदूषण जमीनी सतह से चीजन के समुंद्र में पहुँचे से होला।
=== प्रदूषक तत्व के आधार पर ===
* ठोस कचड़ा प्रदूषण
* [[शोर प्रदूषण]] — तेज, खराब, कर्कश आवाज जे अनचाहल होखे आ जेवना से परेशानी होखे शोर प्रदूषण हऽ।
* [[प्रकाश प्रदूषण]]
* रासायनिक प्रदूषण
* [[रेडियोएक्टिव प्रदूषण]] — अइसन स्थिति हवे जब कौनों इलाका जमीन में, ठोस पदार्थ सभ में, द्रव सभ में, चाहे गैसे में रेडियोएक्टिव पदार्थ के जमाव (डिपोजीशन) होखे चाहे मौजूदगी होखे, आ ई मौजूदगी अनचाहल होखे। एह पदार्थ सभ के क्षय होला आ इनहन से खतरनाक रेडियेशन निकले ला।
=== मनुष्य के क्रिया के आधार प ===
* कृषि प्रदूषण
* औद्योगिक प्रदूषण
== कीमत ==
प्रदूषण के कीमत चुकावे के पड़े ला।<ref>[https://www.washingtonpost.com/news/energy-environment/wp/2016/01/29/the-staggering-economic-cost-of-air-pollution/ The staggering economic cost of air pollution] By Chelsea Harvey, ''Washington Post'', January 29, 2016</ref><ref>[https://www.sciencedaily.com/releases/2008/11/081112124418.htm Freshwater Pollution Costs US At Least $4.3 Billion A Year], ''[[Science Daily]]'', November 17, 2008</ref><ref>[https://www.theguardian.com/environment/2014/jun/30/the-human-cost-of-chinas-untold-soil-pollution-problem The human cost of China's untold soil pollution problem], ''[[The Guardian]]'', Monday 30 June 2014 11.53 EDT</ref> अइसन मैन्यूफैक्चरिंग के कामकाज जे [[हवा प्रदूषण]] पैदा करे, पूरा समाज खातिर सेहत संबधी नोकसान पैदा करे ला जेकर पूरा समाज के कीमत चुकावे के पड़े ला। एह तरह के हवा के गंदगी के साफ़ करे में कीमत चुकावे के पड़े ला। अइसन मैन्यूफैक्चरिंग कामकाज में पैदा होखे वाला हवा प्रदूषण के "निगेटिव एक्सटर्नलिटी" पैदा करे ला जेकर परिभाषा ई हवे कि “जब कौनों फर्म अइसन उत्पादन करे जे ओह लोगन के नोकसान पहुँचावे जे लोग के फर्म द्वारा कौनों किसिम के कंपेनशेसन नइखे दिहल जा रहल।"<ref name=":0">{{Cite book|title=Public finance and public policy|last=Jonathan.|first=Gruber|date=2013|publisher=Worth Publishers|isbn=978-1-4292-7845-4|edition= 4th|location=New York|oclc=819816787}}</ref> एकर एगो अउरी उदाहरण दिहल जा सके ला, जइसे कि कौनों कपड़ा धोवे वाली फर्म एगो इस्टील बनावे वाली फर्म के लगे होखे, इस्टील के फर्म से निकले वाली गंदगी के कारन कपड़ा धोवे वाली फर्म के बेसी खर्चा करे के पड़ी।<ref>{{Cite book|title=Environmental economics|last=D.|first=Kolstad, Charles|date=2011|publisher=Oxford University Press|isbn=978-0-19-973264-7|edition= 2nd|location=New York|oclc=495996799}}</ref>
एही तरह से प्रदूषण कौनों उत्पादन क रहे वाली फर्म के ऊपर भी कीमत देवे के जरूरत पैदा करे ला। उदाहरण खातिर अगर फर्म पर कानूनी रूप से दबाव होखे कि कम प्रदूषण करे के बाटे, अइसना में प्रदूषण कम करे के उपाय में ओह फर्म के खर्चा लागी, एकरा के अबैटमेंट कॉस्ट कहल जाला; अगर हर एक अगिला इकाई बस्तु के उत्पादन पर लागे वाली अइसन कीमत के गिनती कइल जाय तब ऊ मार्जिनल अबैटमेंट कीमत कहाई।<ref>{{cite web|url=http://www.econport.org/content/handbook/Environmental/pollution-control-revised/Abatement-MAC.html|title=Abatement and Marginal Abatement Cost (MAC)|website=www.econport.org|language=en|access-date=2018-03-07|archive-date=2018-02-28|archive-url=https://web.archive.org/web/20180228124154/http://www.econport.org/content/handbook/Environmental/pollution-control-revised/Abatement-MAC.html|url-status=dead}}</ref> 2005 के एगो इस्टीमेट के अनुसार अमेरिका में प्रदूषण से एह तरह के रोक में लागे वाली पूँजी आ फर्म चलावे के खर्चा में एह काम के खर्चा लगभग $27 बिलियन के रहल।<ref>{{cite web|url=https://www.epa.gov/environmental-economics/pollution-abatement-costs-and-expenditures-2005-survey|title=Pollution Abatement Costs and Expenditures: 2005 Survey {{!}} US EPA|last=EPA,OA,OP,NCEE|first=US|website=US EPA|language=en|access-date=2018-03-07}}</ref>
== प्रभाव ==
=== मनुष्य के सेहत पर ===
पर्यावरण प्रदूषण दुनिया के हर हिस्सा में मनई के प्रभावित करेला। अक्टूबर 2017 में लैंसेट कमीशन ऑन पॉल्यूशन एंड हेल्थ के एगो अध्ययन बतवलस कि वैश्विक प्रदूषण—खासकर जहरीला हवा, पानी, मिट्टी आ काम करे के जगह—हर साल करीब नौ मिलियन लोगन के जान ले लेला। ई संख्या एड्स, तपेदिक (ट्यूबरकुलोसिस भा टीबी) आ मलेरिया से मिल के होखे वाला मौत सभ से तीन गुना जादे बा, आ युद्ध आ दोसर तरह के मानव हिंसा से होखे वाला मौत से लगभग 15 गुना जादे बा।
अध्ययन के नतीजा रहे कि प्रदूषण [[एंथ्रोपोसीन]] युग के सबसे बड़ा अस्तित्व संबंधी चुनौती में से एक बा। ई धरती के जीवन–समर्थन प्रणाली के स्थिरता के खतरा में डालता, आ मानव समाज के सस्टेनेबिलिटी पर भी संकट खड़ा करेला।
=== पर्यावरण पर परभाव ===
[[चित्र:Pacific-garbage-patch-map 2010 noaamdp.jpg|thumb|प्रशांत महासागर में बिसाल कचरा चकती]]
प्रदूषण [[पर्यावरण]] में कई रूप में आ ब्यापक तरीका से मौजूद बा। एकर कई किसिम के परभाव पर्यावरण पर पड़े लें:
* बायोमैग्निफिकेशन (Biomagnification) के घटना में कई किसिम के बिसैला पदार्थ सभ (जइसे कि हैभी धातु सभ) जिया जंतु सभ के अलग-अलग भोजन स्तर (ट्राफिक लेवल) से हो के गुजर सके लें आ इनहन के घन हो के एकट्ठा होखत जाए के घटना देखे में आवे ला। मतलब ई कि निचला लेवल के जीव के शरीर में जेतना मात्रा में इनहन के होखल पावल जाला ओकरा से बेसी मात्रा में ई ओह जीव सभ के भीतर एकट्ठा हो जालें जे पहिलका जीव सभ के खालें।
* [[कार्बन डाइआक्साइड]] के पर्यावरण में निकास से समुंद्र सभ के एसिडिटी में बढ़ती होला, एकरा चलते पृथिवी पर समुंद्र सभ के pH मान घटत जा रहल बाटे।
* [[ग्रीनहाउस गैस]] सभ के पर्यावरण में निकास के चलते [[बैस्विक गरमाव]] के घटना चालू बा जे पूरा पृथिवी के [[इकोसिस्टम]] के परभावित क रहल बा।
* [[आक्रमणकारी प्रजाति]] सभ के आ जाए से कौनों इकोसिस्टम में मूलनिवासी प्रजाति सभ के घटती हो सके ला आ एकरा चलते जीवबीबिधता में घटाव हो सके ला। अइसन हमलावर प्रजाति के पौधा सभ अइसन कचरा छोड़ सके लें जेकरा चलते ओह जगह के माटी के अंदर आ ओह पर्यावरण के अंदर रासायनिक बदलाव हो जाय।
* नाइट्रोजन ऑक्साइड सभ बरखा के साथे बरिस के माटी के रासायनिक कंपोजीशन बदल सके लें आ एकरा चलते कौनों इकोसिस्टम के प्रजाति सभ के कंपोजीशन में बदलाव हो सके ला।
* [[स्मॉग]] आ धुंध (हेज) के चलते सुरुज के रोशनी, घाम, के मात्रा में कमी आ सके ला जेकरा चलते पौधा सभ के आपन खाना बनावे (फोटोसिंथेसिस) के काम में कमी आ सके ला। [[स्मॉग]] आ धुंध के चलते ट्रोपोस्फीयर में ओजोन के मात्रा में बढ़ती हो सके ला आ इहो पौधा सभ के नोकसान चहुँपावे ला।
* माटी के उपज शक्ति में कमी आ सके ला जेकरा चलते पौधा सभ के कमी आ जीव सभ के प्रजाति में कमी आ सके ला।
* [[सल्फर डाइआक्साइड]] आ [[नाइट्रोजन ऑक्साइड]] के पर्यावरण में बढ़ती के चलते एसिड बरखा हो सके ला। एसिड बरखा से माटी पे pH में कमी आ सके ला।
* पानी में जीवीय पदार्थ (ऑर्गेनिक मैटर) के प्रदूषण से एह में ऑक्सीजन के कमी हो सके ला आ एकरा कारन ओह पानी में रहे वाला जीव सभ के ऊपर खराब परभाव पड़े ला, जीव सभ के संख्या में कमी आ सके ला।
== कंट्रोल ==
[[चित्र:Litter trap.jpg|thumb|ऑस्ट्रेलिया के यारा नदी में एगो जाल जे कूड़ा-कचरा के फँसा ले ला।]]
प्रदूषण नियंत्रण चाहे प्रदूषण कंट्रोल शब्द के इस्तेमाल पर्यावरण के मैनेजमेंट खातिर कइल जाला जेकरा चलते प्रदूषण के कम कइल जा सके। एह में प्रदूषण फइलावे वाला चीज सभ पर रोक लगावल शामिल बा। अगर प्रदूषण कंट्रोल के उपाय न इस्तेमाल कइल जाय तब बिबिध किसिम के कचड़ा जे अतिउपभोग से, ठंढा देसन में गर्मी करे वाला उपाय सभ से, खेती में इस्तेमाल होखे वाला खाद आ कीटनाशक सभ से, खनन से, उद्योग से आ परिवहन से निकल के पर्यावरण में चहुँप जाई। एकरा चलते पर्यावरण के सेहत के नोकसान पहुँची। [[प्रदूषण रोकथाम]] आ [[कचरा घटाव]] के उपाय सभ के सभसे बेसी महत्व दिहल जाला, हालाँकि, प्रदूषण कंट्रोल के औरी उपाय भी बाने। प्राकृतिक जमीन के कौनों किसिम के बिकास करत समय अइसन तकनीक के इस्तेमाल भी कइल जा सके ला जवना से कि जमीन के बिकास (लैंड डेवलपमेंट) के पर्यावरण पर परभाव के कम कइल जा सके।
===Practices===
* [[Recycling]]
* [[Reuse|Reusing]]
* [[Waste minimisation]]
* [[Environmental mitigation|Mitigating]]
* [[Pollution prevention|Preventing]]
* [[Compost]]
===Pollution control devices===
* [[Air pollution|Air pollution control]]
** [[Thermal oxidiser|Thermal oxidizer]]
* [[Dust collector|Dust collection systems]]
** [[Dust collector#Types of baghouses|Baghouses]]
** [[Cyclonic separation|Cyclones]]
** [[Electrostatic precipitator]]s
* [[Scrubber]]s
** [[Baffle spray scrubber]]
** [[Cyclonic spray scrubber]]
** [[Ejector venturi scrubber]]
** [[Mechanically aided scrubber]]
** [[Spray tower]]
** [[Wet scrubber]]
* [[Sewage treatment]]
** [[Sedimentation (water treatment)|Sedimentation]] (Primary treatment)
** [[Activated sludge|Activated sludge biotreaters]] (Secondary treatment; also used for industrial wastewater)
** [[Aerated lagoon]]s
** [[Constructed wetlands]] (also used for urban runoff)
* [[Industrial wastewater treatment]]
** [[API oil-water separator]]s<ref name="Aqueous">{{cite book|author=Beychok, Milton R.|title=Aqueous Wastes from Petroleum and Petrochemical Plants|edition= 1st|publisher=John Wiley & Sons|year=1967|lccn=67019834|isbn=978-0-471-07189-1|title-link=Aqueous Wastes from Petroleum and Petrochemical Plants}}</ref><ref>{{cite book|author=American Petroleum Institute (API)|title=Management of Water Discharges: Design and Operations of Oil–Water Separators|edition= 1st|publisher=American Petroleum Institute|date=February 1990|id=|authorlink=American Petroleum Institute}}</ref>
** [[Biofilter]]s
** [[Dissolved air flotation]] (DAF)
** [[Powdered activated carbon treatment]]
** [[Ultrafiltration]]
* [[Vapor recovery|Vapor recovery systems]]
* [[Phytoremediation]]
{{clear}}
== इहो देखल जाय ==
{{Div col|2}}
* [[पर्यावरण]]
* [[पर्यावरण बिज्ञान]]
* [[मानव भूगोल]]
* [[भौतिक भूगोल]]
* [[इकोलॉजी|पारिस्थितिकी]]
* [[पर्यावरण पर मनुष्य के परभाव]]
* [[जलवायु बदलाव]]
* [[बैस्विक गरमाव]]
{{Div col end}}
== संदर्भ ==
{{reflist|30em}}
== बाहरी कड़ी ==
{{Commons category|Pollution}}
* [http://www.cpcb.nic.in/ केंद्रीय प्रदूषण नियंत्रण बोर्ड] के वेबसाइट।
* [http://www.epa.gov/superfund/ EPA.gov] – manages Superfund sites and the pollutants in them (CERCLA). Map [https://web.archive.org/web/20101002082045/http://toxmap.nlm.nih.gov/toxmap/main/index.jsp the EPA Superfund]
* [http://www.epa.gov/tri/ Toxic Release Inventory] – tracks how much waste US companies release into the water and air. Gives permits for releasing specific quantities of these pollutants each year. Map [http://toxmap.nlm.nih.gov/toxmap/main/index.jsp EPA's Toxic Release Inventory] {{Webarchive|url=https://web.archive.org/web/20101002082045/http://toxmap.nlm.nih.gov/toxmap/main/index.jsp |date=2010-10-02 }}
* [http://www.atsdr.cdc.gov/index.html Agency for Toxic Substances and Disease Registry] – Top 20 pollutants, how they affect people, what US industries use them and the products in which they are found
* [http://sis.nlm.nih.gov/enviro/toxtutor.html#toxtutor Toxicology Tutorials from the National Library of Medicine] {{Webarchive|url=https://web.archive.org/web/20160520221533/https://sis.nlm.nih.gov/enviro/toxtutor.html#toxtutor |date=2016-05-20 }} – resources to review human toxicology.
* [https://web.archive.org/web/20061026012447/http://www.blacksmithinstitute.org/ten.php World's Worst Polluted Places 2007], according to the [[Blacksmith Institute]]
* [http://www.time.com/time/specials/2007/article/0,28804,1661031_1661028_1661020,00.html The World's Most Polluted Places] {{Webarchive|url=https://web.archive.org/web/20130824192451/http://www.time.com/time/specials/2007/article/0,28804,1661031_1661028_1661020,00.html |date=2013-08-24 }} at Time.com (a division of Time Magazine)
* [https://web.archive.org/web/20080104003923/http://www.logtv.com/films/chelyabinsk/index.htm Chelyabinsk: The Most Contaminated Spot on the Planet] Documentary Film by Slawomir Grünberg (1996)
* [https://www.bbc.com/hindi/india-52176065 कोरोना वायरस: भारत में लॉकडाउन प्रदूषण के मोर्चे पर एक वरदान है?], बीबीसी हिंदी पर एगो रपट।
* [https://www.sciencedirect.com/topics/earth-and-planetary-sciences/environmental-pollution Environmental Pollution], sciencedirect.com पर टोपिक ओवरव्यू।
{{प्रदूषण}}
{{पर्यावरण}}
{{Authority control}}
[[श्रेणी:प्रदूषण| ]]
[[श्रेणी:पर्यावरण]]
[[श्रेणी:पर्यावरण भूगोल]]
[[श्रेणी:पर्यावरण बिज्ञान]]
awywv8fwg8068qnf67o50ih1z3bitjk
अल्बानिया
0
10527
790081
780264
2026-04-02T22:08:45Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790081
wikitext
text/x-wiki
{{Infobox country
| conventional_long_name = अल्बानिया गनराज्य
| native_name = ''{{lang|sq|Republika e Shqipërisë}}''
| common_name = अल्बानिया
| national_motto = {{small|(official)}}
{{vunblist
| {{native phrase|sq|italics=off|"Ti Shqipëri, më jep nder, më jep emrin Shqipëtar"}}
| {{nowrap|{{small|"You Albania, give me honor, give me the name Albanian"}}}}
}}
| national_anthem =
{{vunblist
| {{native name|sq|nolink=yes| [[Himni i Flamurit|Betimi mbi flamur]]}}
| {{small|''Oath on the flag''}}
| <center>[[File:Hymni i Flamurit instrumental.ogg]]</center>
}}
| image_flag = Flag of Albania.svg
| image_coat = Coat of arms of Albania.svg
| symbol_type = Coat of arms
| image_map = Europe-Albania.svg
| map_caption = {{map caption |location_color=orange |region=Europe |region_color=dark grey |legend=Location Albania Europe.png}}
| image_map2 = Albania-map.png
| official_languages = [[अल्बेनियन भाषा]]<sup>a</sup>
| capital = [[तिराना]]
| latd=41 |latm=20 |latNS=N |longd=19 |longm=48 |longEW=E
| largest_city = राजधानी
| demonym = [[अल्बेनियन]]
| government_type = [[Unitary state|Unitary]] [[Parliamentary system|parliamentary]] [[constitutional republic]]
| ethnic_groups =
| leader_title1 = [[List of heads of state of Albania|President]]
| leader_name1 = [[Bujar Nishani]]
| leader_title2 = [[List of Prime Ministers of Albania|Prime Minister]]
| leader_name2 = [[Edi Rama]]
| leader_title3 = [[Chairman of the Parliament of Albania|Speaker of the parliament]]
| leader_name3 = [[Ilir Meta]]
| legislature = ''[[Parliament of Albania|Kuvendi]]''
| area_rank = 143rd
| area_magnitude = 1 E10
| area_km2 = 28748
| area_sq_mi = 11100 <!--Do not remove per [[WP:MOSNUM]]-->
| percent_water = 4.7
| population_estimate = 3,020,209 <ref>{{cite web |url=https://www.cia.gov/library/publications/the-world-factbook/geos/al.html |title=The World Factbook |publisher=Cia.gov |date= |accessdate=2014-08-18 |archive-date=2018-12-24 |archive-url=https://web.archive.org/web/20181224211117/https://www.cia.gov/library/publications/the-world-factbook/geos/al.html |url-status=dead }}</ref>
| population_estimate_year = 2014
| population_census = 2,821,977<ref name="Population and Housing Census 2011">{{cite web|title=Population and Housing Census 2011|url=http://www.instat.gov.al/en/themes/population/publications/books/2012/main-results-of-population-and-housing-census-2011.aspx|publisher=INSTAT (Albanian Institute of Statistics)|access-date=2014-08-26|archive-date=2017-08-03|archive-url=https://web.archive.org/web/20170803171148/http://www.instat.gov.al/en/themes/population/publications/books/2012/main-results-of-population-and-housing-census-2011.aspx|url-status=dead}}</ref>
| population_census_year = 2011
| population_density_km2 = 98
| population_density_sq_mi = 254 <!--Do not remove per [[WP:MOSNUM]]-->
| population_density_rank = 63rd
| GDP_PPP_year = 2014
| GDP_PPP = $31 billion <ref name=Min2>{{cite web |url=http://www.financa.gov.al/files/userfiles/Programimi_EkonomikoFiskal/Kuadri_Makroekonomik_dhe_Fiskal/KMF_Periudhen_2014-2016_VKM_NR.73_date_23.01.2013.pdf |title=Ministry of Economy of Albania |date= |accessdate=2014-02-15 |archive-date=2017-02-05 |archive-url=https://web.archive.org/web/20170205231156/http://www.financa.gov.al/files/userfiles/Programimi_EkonomikoFiskal/Kuadri_Makroekonomik_dhe_Fiskal/KMF_Periudhen_2014-2016_VKM_NR.73_date_23.01.2013.pdf |url-status=dead }}</ref>
| GDP_PPP_rank =
| GDP_PPP_per_capita = $9,903<ref name=imf2>{{cite web|url=http://www.imf.org/external/pubs/ft/weo/2014/01/weodata/weorept.aspx?pr.x=79&pr.y=13&sy=2012&ey=2019&scsm=1&ssd=1&sort=country&ds=.&br=1&c=914&s=NGDPD%2CNGDPDPC%2CPPPGDP%2CPPPPC&grp=0&a= |title=Report for Selected Countries and Subjects |publisher=Imf.org |date=2006-09-14 |accessdate=2014-08-15}}</ref>–$11,400<ref name=Min2/>
| GDP_PPP_per_capita_rank =
| GDP_nominal_year = 2014
| GDP_nominal = $14 billion<ref name=imf2/>
| GDP_nominal_rank =
| GDP_nominal_per_capita = $5,000<ref name=imf2/>
| GDP_nominal_per_capita_rank =
| Gini_year = 2008
| Gini_change = <!--increase/decrease/steady-->
| Gini = 26.7 <!--number only-->
| Gini_ref = <ref>{{cite web |url=https://www.cia.gov/library/publications/the-world-factbook/fields/2172.html |title=Distribution of family income – Gini index |work=The World Factbook |publisher=CIA |accessdate=1 September 2009 |archiveurl=https://web.archive.org/web/20090513124910/https://www.cia.gov/library/publications/the-world-factbook/fields/2172.html |archivedate=13 May 2009 |url-status=dead }}</ref>
| Gini_rank =
| HDI_year = 2013<!-- Please use the year to which the data refers, not the publication year-->
| HDI_change = increase <!--increase/decrease/steady-->
| HDI = 0.716 <!--number only-->
| HDI_ref = <ref name="HDI">{{cite web |url=http://hdr.undp.org/en/media/HDR_2010_EN_Table1.pdf |title=Human Development Report 2010 |year=2010 |publisher=United Nations |accessdate=5 November 2010}}</ref>
| HDI_rank = 95th
| sovereignty_type = [[History of the Albanian state|Formation]]
| established_event1 = [[Principality of Arbër]]
| established_date1 = 1190
| established_event2 = [[League of Lezhë]]
| established_date2 = 2 मार्च 1444
| established_event3 = [[Independent Albania]]
| established_date3 = 28 November 1912
| established_event4 = [[Principality of Albania]]
| established_date4 = 29 July 1913
| established_event5 = {{nowrap|[[Constitution of Albania|Current constitution]]}}
| established_date5 = 28 November 1998
| currency = [[Albanian lek|Lek]]
| currency_code = ALL
| country_code = AL
| time_zone = [[Central European Time|CET]]
| utc_offset = +1
| time_zone_DST = [[Central European Summer Time|CEST]]
| utc_offset_DST = +2
| drives_on = right
| calling_code = [[Telephone numbers in Albania|355]]
| date_format = dd/mm/yyyy
| cctld = [[.al]]
| footnote_a = [[Greek language|Greek]], [[Vlach language|Vlach]], [[Macedonian language|Macedonian]], and other regional languages are government-recognized minority languages.
}}
'''अल्बानिया''' ({{Lang|en|[[:en:Albania|Albania]]}}) [[यूरोप]] में एगो देस बाटे।<ref>{{cite web|url=https://hindi.news18.com/news/knowledge/worlds-first-atheist-country-albania-mrj-3174175.html|title=वो मुस्लिम देश, जो दुनिया का पहला नास्तिक देश बन गया|access-date=2020-11-06|archive-date=2020-10-14|archive-url=https://web.archive.org/web/20201014030245/https://hindi.news18.com/news/knowledge/worlds-first-atheist-country-albania-mrj-3174175.html|url-status=dead}}</ref> एकर राजधानी [[तिराना]] हवे।
{{clear}}
==संदर्भ==
<references/>
{{Sovereign states of Europe}}
[[श्रेणी:यूरोप के देस]]
[[श्रेणी:अल्बानिया]]
[[श्रेणी:यूनाइटेड नेशंस के सदस्य देस]]
[[श्रेणी:नाटो के सदस्य देश]]
{{यूरोप-भू-आधार}}
6aii0lws1pfzbgtgnd3nw3fik2gckmp
टेम्पलेट:बिहार के प्रमंडल तथा जिला
10
14738
790089
677425
2026-04-03T00:57:45Z
~2026-20458-81
39911
Imamul HAK
790089
wikitext
text/x-wiki
[[Image:BiharDistricts_hi.svg|right|250px|thumb|<center>बिहार के जिला मानचित्र</center>]]
<!--[[Image:GayaLocation.jpg|right|260px|thumb|District map of Bihar]] -->
{| class="wikitable"
! [[बिहार के प्रमंडल|प्रमंडल]]
! मुख्यालय
! align="center" | [[बिहार के जिला|जिला]]
|-
| [[1.भागलपुर प्रमंडल|भागलपुर]] || [[भागलपुर]] || [[बाँका जिला|बाँका]], [[भागलपुर जिला|भागलपुर]]
|-
| [[2.दरभंगा प्रमंडल|दरभंगा]] || [[दरभंगा]] || [[दरभंगा जिला|दरभंगा]], [[मधुबनी जिला|मधुबनी]], [[समस्तीपुर जिला|समस्तीपुर]]
|-
| [[3.कोसी प्रमंडल|कोसी]] || [[सहरसा]] || [[मधेपुरा जिला|मधेपुरा]], [[सहरसा जिला|सहरसा]], [[सुपौल जिला|सुपौल]]
|-
| [[4.मगध प्रमंडल|मगध]] || [[गया, भारत|गया]] || [[अरवल जिला|अरवल]], [[औरंगाबाद (बिहार)|औरंगाबाद]], [[गया जिला|गया]], [[जहानाबाद जिला|जहानाबाद]], [[नवादा जिला|नवादा]]
|-
| [[5.मुंगेर प्रमंडल|मुंगेर]] || [[मुंगेर]] || [[जमुई जिला|जमुई]], [[खगडिया जिला|खगडिया]], [[मुंगेर जिला|मुंगेर]], [[लखीसराय जिला|लखीसराय]], [[शेखपुरा जिला|शेखपुरा]], [[बेगुसराय जिला|बेगुसराय]]
|-
| [[6.पटना प्रमंडल|पटना]] || [[पटना]] || [[भोजपुर जिला|भोजपुर]], [[बक्सर जिला|बक्सर]], [[कैमुर जिला|कैमुर]], [[पटना जिला|पटना]], [[रोहतास जिला|रोहतास]], [[नालंदा जिला|नालंदा]]
|-
| [[7.पूर्णिया प्रमंडल|पूर्णिया]] || [[पूर्णिया]] || [[अररिया जिला|अररिया]], [[कटिहार जिला|कटिहार]], [[किशनगंज जिला|किशनगंज]], [[पूर्णिया जिला|पूर्णिया]]
|-
| [[8.सारण प्रमंडल|सारण]] || [[छपरा]] ||[[गोपालगंज जिला|गोपालगंज]], [[सारण जिला|सारण]], [[सिवान जिला|सिवान]]
|-
| [[9.तिरहुत प्रमंडल|तिरहुत]] || [[ मुजफ्फरपुर]] || [[पुर्वी चम्पारण जिला|पुर्वी चम्पारण]], [[मुजफ्फरपुर जिला|मुजफ्फरपुर]], [[शिवहर जिला|शिवहर]], [[सीतामढी जिला|सीतामढी]], [[वैशाली जिला|वैशाली]], [[पश्चिम चम्पारण जिला|पश्चिम चम्पारण]]
|}<noinclude>[[Category:बिहार टेम्पलेट]]</noinclude>
rq9mdx5gw71goezvwqh8pgxh7hcgvxg
8 फरवरी
0
21678
790080
707935
2026-04-02T21:08:53Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790080
wikitext
text/x-wiki
{{कैलेंडर}}
{{पिछला कुछ बरिस में ई दिन}}
{{दिन}}
== घटना ==
* [[1238]] – [[मंगोल लोग]] रूसी शहर [[व्लादिमीर]] के फूँक दिहल।
==जनम==
* [[1828]] – [[जूल्स वर्न]], फ्रांसीसी लेखक, कवी आ नाटककार (नि. 1905)<ref>{{cite book|author=Jules Verne|title=The Exploration Of The World: eBook Edition|url=https://books.google.com/books?id=L5JsBQAAQBAJ&pg=PT4|date=17 November 2014|publisher=Jazzybee Verlag|isbn=978-3-8496-4648-6|pages=4–}}</ref>
==निधन==
==तिहुआर, छुट्टी अउरी खास महत्व ==
* [[प्रोपोज डे]] (भारत) – [[वैलेंटाइन्स डे|वैलेंटाइन डे]] के पहिले वाला हप्ता के सिरीज में एगो दिवस जहिया लोग अपना प्रेमी-प्रेमिका के प्रपोज करे ला।<ref>{{cite news |title=Happy Propose Day 2022: Wishes, Messages, Quotes, Images, Greetings, Facebook & Whatsapp status - Times of India |url=https://timesofindia.indiatimes.com/life-style/relationships/love-sex/happy-propose-day-2022-wishes-messages-quotes-images-facebook-whatsapp-status/articleshow/89410643.cms |access-date=8 फरवरी 2022 |work=The Times of India |language=en}}</ref><ref>{{cite news |title=Propose Day 2022: किसी से करना चाहते हैं प्यार का इजहार तो भेजें ये संदेश, शुरू करें अपनी प्रेम कहानी का नया अध्याय |url=https://ndtv.in/lifestyle/happy-propose-day-2022-propose-day-messages-propose-day-whatspp-status-propose-day-wishes-propose-day-quotes-in-hindi-propose-day-sher-2753595 |access-date=8 फरवरी 2022 |work=NDTVIndia |archive-date=2022-02-08 |archive-url=https://web.archive.org/web/20220208024224/https://ndtv.in/lifestyle/happy-propose-day-2022-propose-day-messages-propose-day-whatspp-status-propose-day-wishes-propose-day-quotes-in-hindi-propose-day-sher-2753595 |url-status=dead }}</ref>
* [[सेफ़र इंटरनेट डे]] – इंटरनेट सुरक्षा संबंधी दिवस।<ref>{{cite web |title=Home - Safer Internet Day - BIK Community |url=https://www.saferinternetday.org/ |website=Safer Internet Day |access-date=8 फरवरी 2022}}</ref>
{{commons|February 8|8 फरवरी}}
{{साल के महीना सभ}}
[[श्रेणी:साल के दिन]]
[[श्रेणी:फरवरी]]
fbkme2v6z7ncs9von23ctcdel32zbze
टेम्पलेट:Infobox color
10
24328
790273
236841
2026-04-03T11:37:33Z
SM7
3953
अनुबाद कइल गइल
790273
wikitext
text/x-wiki
{{infobox
| above = {{{title|<includeonly>{{PAGENAME}}</includeonly>}}}
| subheader = {{#if:{{{bgcolor|{{{hex|}}}}}}| }}
| subheaderstyle = line-height:10px; background-color:#{{{bgcolor|{{{hex}}}}}}; color:#{{{bgcolor|{{{hex}}}}}}
| image = {{#invoke:InfoboxImage|InfoboxImage|image={{{image|}}}|size={{{image_size|{{{photo-size|}}}}}}|sizedefault=frameless|alt={{{alt|}}}}}
| caption = {{{caption|}}}
| header2 = {{#if:{{{frequency|}}}|[[स्पेक्ट्रल कलर|स्पेक्ट्रल कोऑर्डिनेट]]}}
| label3 = [[Wavelength]]
| data3 = {{#if:{{{wavelength|}}}|{{{wavelength}}} [[नैनोमीटर|nm]]}}
| label4 = [[Frequency]]
| data4 = {{#if:{{{frequency|}}}|{{{frequency}}} [[टेराहर्ट्ज|THz]]}}
| header5 = {{#if:{{{symbolism|}}}|आम नाँव}}
| data6 = {{{symbolism||yy}}}
| header8 = <includeonly><span style="position: relative; float: right; font-size: 70%">[[File:Gtk-dialog-info.svg|15px|About these coordinates|link=Wikipedia:WikiProject Color/Normalized Color Coordinates]]</span> Colo{{#ifeq:{{lc:{{{spelling}}}}}|colour|u}}r coordinates</includeonly>
| label9 = [[वेब कलर#हेक्स ट्रिप्लेट|हेक्स ट्रिप्लेट]]
| data9 = {{#if:{{{hex|}}}|#{{{hex}}}}}
| label10 = {{#if:{{{sRGB}}}|[[आरजीबी कलर स्पेस|sRGB]]|{{#if:{{{rgbspace}}}|{{{rgbspace}}}|[[आरजीबी कलर मॉडल|RGB]]}}}}<sup>'''B'''</sup> ([[लाल रंग|r]], [[हरियर रंग|g]], [[नीला रंग|b]])
| data10 = {{#if:{{{r|}}}|({{{r}}}, {{{g}}}, {{{b}}})}}
| label11 = {{nowrap|[[सीएमवाईके कलर मॉडल|CMYK]]<sup>'''H'''</sup> ([[cyan|c]], [[magenta|m]], [[yellow|y]], [[black|k]])}}
| data11 = {{#if:{{{c|}}}|{{nowrap|({{{c}}}, {{{m}}}, {{{y}}}, {{{k}}})}}}}
| label12 = {{nowrap|[[एचएसवी कलर स्पेस|HSV]] ([[hue|h]], [[Saturation (color theory)|s]], [[Brightness|v]])}}
| data12 = {{#if:{{{h|}}}|{{nowrap|({{{h}}}°, {{{s}}}%, {{{v}}}%)}}}}
| label13 = [[एचएसएल कलर स्पेस|HSL]] ([[hue|hslH]], [[Saturation (color theory)|hslS]], [[Lightness (color)|hslL]])
| data13 = {{#if:{{{hslL|}}}|({{{hslH}}}°, {{{hslS}}}%, {{{hslL}}}%)}}
| label14 = सोर्स
| data14 = <includeonly>{{#if:{{{source|}}}|{{{source}}}|<sup><nowiki>[</nowiki>[[Wikipedia:WikiProject Color/Sources for Color Coordinates|Unsourced]]<nowiki>]</nowiki></sup>{{main other|[[श्रेणी:WikiProject Color articles needing infobox sources]]}}}}</includeonly>
| label15 = [[कलर स्पेस]]
| data15 = {{{colorspace|}}}
| data16 = {{#if:{{{r|}}}|'''B''': Normalized to <nowiki>[</nowiki>0–255] (byte)<br>}}{{#if:{{{c|}}}|'''H''': Normalized to <nowiki>[</nowiki>0–100] (hundred)}}
| data17 = {{{caveat|}}}
| header18 = {{#if:{{{variations|}}}|{{{variationstitle|{{{title}}} के कुछ शेड सभ|}}}}}
| label19 = {{{variation1|}}}
| data19 = {{#if:{{{variation1|}}}|<span style="background-color:{{{variation1color|{{{variation1}}}}}}; border:1px solid {{{variation1color|{{{variation1}}}}}};display:block"> </span>}}
| label20 = {{{variation2|}}}
| data20 = {{#if:{{{variation2|}}}|<span style="background-color:{{{variation2color|{{{variation2}}}}}}; border:1px solid {{{variation2color|{{{variation2}}}}}};display:block"> </span>}}
| label21 = {{{variation3|}}}
| data21 = {{#if:{{{variation3|}}}|<span style="background-color:{{{variation3color|{{{variation3}}}}}}; border:1px solid {{{variation3color|{{{variation3}}}}}};display:block"> </span>}}
| label22 = {{{variation4|}}}
| data22 = {{#if:{{{variation4|}}}|<span style="background-color:{{{variation4color|{{{variation4}}}}}}; border:1px solid {{{variation4color|{{{variation4}}}}}};display:block"> </span>}}
| label23 = {{{variation5|}}}
| data23 = {{#if:{{{variation5|}}}|<span style="background-color:{{{variation5color|{{{variation5}}}}}}; border:1px solid {{{variation5color|{{{variation5}}}}}};display:block"> </span>}}
| label24 = {{{variation6|}}}
| data24 = {{#if:{{{variation6|}}}|<span style="background-color:{{{variation6color|{{{variation6}}}}}}; border:1px solid {{{variation6color|{{{variation6}}}}}};display:block"> </span>}}
| label25 = {{{variation7|}}}
| data25 = {{#if:{{{variation7|}}}|<span style="background-color:{{{variation7color|{{{variation7}}}}}}; border:1px solid {{{variation7color|{{{variation7}}}}}};display:block"> </span>}}
| label26 = {{{variation8|}}}
| data26 = {{#if:{{{variation8|}}}|<span style="background-color:{{{variation8color|{{{variation8}}}}}}; border:1px solid {{{variation8color|{{{variation8}}}}}};display:block"> </span>}}
}}<noinclude>{{documentation}}<!-- PLEASE ADD THIS TEMPLATE'S CATEGORIES TO THE /doc SUBPAGE, THANKS --></noinclude>
sgt37jmcysjyj87pkik6e9urbmzxm7g
790274
790273
2026-04-03T11:41:03Z
SM7
3953
अनुबाद कइल गइल
790274
wikitext
text/x-wiki
{{infobox
| above = {{{title|<includeonly>{{PAGENAME}}</includeonly>}}}
| subheader = {{#if:{{{bgcolor|{{{hex|}}}}}}| }}
| subheaderstyle = line-height:10px; background-color:#{{{bgcolor|{{{hex}}}}}}; color:#{{{bgcolor|{{{hex}}}}}}
| image = {{#invoke:InfoboxImage|InfoboxImage|image={{{image|}}}|size={{{image_size|{{{photo-size|}}}}}}|sizedefault=frameless|alt={{{alt|}}}}}
| caption = {{{caption|}}}
| header2 = {{#if:{{{frequency|}}}|[[स्पेक्ट्रल कलर|स्पेक्ट्रल कोऑर्डिनेट]]}}
| label3 = [[वेवलेंथ]]
| data3 = {{#if:{{{wavelength|}}}|{{{wavelength}}} [[नैनोमीटर|nm]]}}
| label4 = [[फ्रीक्वेंसी]]
| data4 = {{#if:{{{frequency|}}}|{{{frequency}}} [[टेराहर्ट्ज|THz]]}}
| header5 = {{#if:{{{symbolism|}}}|आम नाँव}}
| data6 = {{{symbolism||yy}}}
| header8 = <includeonly><span style="position: relative; float: right; font-size: 70%">[[File:Gtk-dialog-info.svg|15px|About these coordinates|link=Wikipedia:WikiProject Color/Normalized Color Coordinates]]</span> Colo{{#ifeq:{{lc:{{{spelling}}}}}|colour|u}}r coordinates</includeonly>
| label9 = [[वेब कलर#हेक्स ट्रिप्लेट|हेक्स ट्रिप्लेट]]
| data9 = {{#if:{{{hex|}}}|#{{{hex}}}}}
| label10 = {{#if:{{{sRGB}}}|[[आरजीबी कलर स्पेस|sRGB]]|{{#if:{{{rgbspace}}}|{{{rgbspace}}}|[[आरजीबी कलर मॉडल|RGB]]}}}}<sup>'''B'''</sup> ([[लाल रंग|r]], [[हरियर रंग|g]], [[नीला रंग|b]])
| data10 = {{#if:{{{r|}}}|({{{r}}}, {{{g}}}, {{{b}}})}}
| label11 = {{nowrap|[[सीएमवाईके कलर मॉडल|CMYK]]<sup>'''H'''</sup> ([[सियान|c]], [[मजेंटा|m]], [[पीयर रंग|y]], [[करिया|k]])}}
| data11 = {{#if:{{{c|}}}|{{nowrap|({{{c}}}, {{{m}}}, {{{y}}}, {{{k}}})}}}}
| label12 = {{nowrap|[[एचएसवी कलर स्पेस|HSV]] ([[ह्यू|h]], [[सैचुरेशन (कलर थियरी)|s]], [[ब्राइटनेस|v]])}}
| data12 = {{#if:{{{h|}}}|{{nowrap|({{{h}}}°, {{{s}}}%, {{{v}}}%)}}}}
| label13 = [[एचएसएल कलर स्पेस|HSL]] ([[ह्यू|hslH]], [[सैचुरेशन (कलर थियरी)|hslS]], [[लाइटनेस (कलर)|hslL]])
| data13 = {{#if:{{{hslL|}}}|({{{hslH}}}°, {{{hslS}}}%, {{{hslL}}}%)}}
| label14 = सोर्स
| data14 = <includeonly>{{#if:{{{source|}}}|{{{source}}}|<sup><nowiki>[</nowiki>[[Wikipedia:WikiProject Color/Sources for Color Coordinates|Unsourced]]<nowiki>]</nowiki></sup>{{main other|[[श्रेणी:WikiProject Color articles needing infobox sources]]}}}}</includeonly>
| label15 = [[कलर स्पेस]]
| data15 = {{{colorspace|}}}
| data16 = {{#if:{{{r|}}}|'''B''': <nowiki>[</nowiki>0–255] (बाईट) पर नॉर्मलाइज कइल<br>}}{{#if:{{{c|}}}|'''H''': <nowiki>[</nowiki>0–100] (सौ) पर नॉर्मलाइज कइल}}
| data17 = {{{caveat|}}}
| header18 = {{#if:{{{variations|}}}|{{{variationstitle|{{{title}}} के कुछ शेड सभ|}}}}}
| label19 = {{{variation1|}}}
| data19 = {{#if:{{{variation1|}}}|<span style="background-color:{{{variation1color|{{{variation1}}}}}}; border:1px solid {{{variation1color|{{{variation1}}}}}};display:block"> </span>}}
| label20 = {{{variation2|}}}
| data20 = {{#if:{{{variation2|}}}|<span style="background-color:{{{variation2color|{{{variation2}}}}}}; border:1px solid {{{variation2color|{{{variation2}}}}}};display:block"> </span>}}
| label21 = {{{variation3|}}}
| data21 = {{#if:{{{variation3|}}}|<span style="background-color:{{{variation3color|{{{variation3}}}}}}; border:1px solid {{{variation3color|{{{variation3}}}}}};display:block"> </span>}}
| label22 = {{{variation4|}}}
| data22 = {{#if:{{{variation4|}}}|<span style="background-color:{{{variation4color|{{{variation4}}}}}}; border:1px solid {{{variation4color|{{{variation4}}}}}};display:block"> </span>}}
| label23 = {{{variation5|}}}
| data23 = {{#if:{{{variation5|}}}|<span style="background-color:{{{variation5color|{{{variation5}}}}}}; border:1px solid {{{variation5color|{{{variation5}}}}}};display:block"> </span>}}
| label24 = {{{variation6|}}}
| data24 = {{#if:{{{variation6|}}}|<span style="background-color:{{{variation6color|{{{variation6}}}}}}; border:1px solid {{{variation6color|{{{variation6}}}}}};display:block"> </span>}}
| label25 = {{{variation7|}}}
| data25 = {{#if:{{{variation7|}}}|<span style="background-color:{{{variation7color|{{{variation7}}}}}}; border:1px solid {{{variation7color|{{{variation7}}}}}};display:block"> </span>}}
| label26 = {{{variation8|}}}
| data26 = {{#if:{{{variation8|}}}|<span style="background-color:{{{variation8color|{{{variation8}}}}}}; border:1px solid {{{variation8color|{{{variation8}}}}}};display:block"> </span>}}
}}<noinclude>{{documentation}}<!-- PLEASE ADD THIS TEMPLATE'S CATEGORIES TO THE /doc SUBPAGE, THANKS --></noinclude>
j5neeu95p0d6lxgeb8x1w5mzvkt1m49
गुंटूर जिला
0
28521
790264
762528
2026-04-03T11:00:53Z
~2026-20465-90
39916
790264
wikitext
text/x-wiki
{{Infobox India district
| Name = गुंटूर जिला
| Local =
| State = आंध्र प्रदेश
| Division =
| HQ = गुंटूर
| Map = Guntur in Andhra Pradesh (India).svg
| Coordinates =
| Area = 11391
| Population = 4889230<ref name="demographics" />
| Year = 2011
| Urban =
| Literacy =
| SexRatio =
| Collector =
| Tehsils =
| LokSabha =
| Assembly =
| Highways =
| Vehicle =
| Rain =
| Website = http://guntur.nic.in/
}}
'''गुंटूर जिला''' भारत के [[आंध्र प्रदेश]] राज्य में एक जिला है। इसका मुख्यालय [[गुंटूर]] शहर हैं। इसका कुल रकबा 11391 वर्ग कि॰मी॰ है।
==जनसंख्या==
साल 2011 के जनगणना के हिसाब से गुंटूर जिला के कुल जनसंख्या 4889230 है जनसंख्या घनत्व 429 है।<ref name="demographics">{{cite web|title=Anantapur district profile|url=http://www.ap.gov.in/Pages/Districts.aspx|publisher=Andhra Pradesh State Portal|archivedate=15 July 2014|access-date=15 May 2016|archive-url=https://web.archive.org/web/20140715100812/http://www.ap.gov.in/Pages/Districts.aspx|url-status=dead}}</ref>
==इसे भी देखें ==
* [[आंध्र प्रदेश के जिला]]
{{clear}}
==संदर्भ==
{{Reflist|35em}}
==बाहरी कड़ी==
{{Commons category|Guntur district|गुंटूर जिला}}
* [http://guntur.nic.in/ ऑफिशियल वेबसाइट]
{{आंध्र प्रदेश}}
{{भारत-भू-आधार}}
[[श्रेणी:आंध्र प्रदेश के जिला]]
[[श्रेणी:गुंटूर जिला]]
[[श्रेणी:भारत के जिला]]
t2gaflieevww6yh9az0f5vbid8iyib2
चइत
0
36174
790096
776437
2026-04-03T04:25:55Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790096
wikitext
text/x-wiki
{{महीना पट्टी भोजपुरी}}
{{Infobox month
| image = Jaipur Chaitra month.jpg
| alt =
| caption = ''चैत्र मास'', जयपुर के मिनियेचर पेंटिंग (वारसा के म्यूजियम में)
| native_name = {{Native name|sa|चैत्र}}
| calendar = [[हिंदू कलेंडर]]
| num = 12
| days =
| season = [[बसंत]]
| gregorian = फरवरी-मार्च
| holidays = * [[होली]]
* [[नवरातर]]
* [[नया साल]] (नव संवत्सर, काशी क्षेत्र)
* [[गुड़ी पड़वा]]
* [[राम नउमी]]
| prev_month = [[फागुन]]
| next_month = [[बइसाख]]
}}
'''चइत''' ({{lang-sa|चैत्र}}) [[हिंदू कलेंडर]] के एक ठो महीना बा। ई कई क्षेत्रन में साल के पहिला महीना हवे जे [[फागुन]] के बाद आ [[बइसाख]] के पहिले आवे ला।
[[काशी]] क्षेत्र में प्रचलन में [[बिक्रम संवत]] के अनुसार चइत के अँजोरिया ([[शुक्लपक्ष]]) से नया साल के सुरुआत होला। एह तरह से एह महीना के आधा हिस्सा पुरान साल में पड़ेला आ आधा नया साल में। अंग्रेजी ([[ग्रेगरियन कैलेंडर|ग्रेगोरियन कैलेंडर]]) के हिसाब से एह महीना के सुरुआत कौनों फिक्स डेट के ना पड़ेला बलुक खसकत रहेला। आमतौर पर ई [[मार्च]]-[[अप्रैल]] के महीना में पड़े ला।
[[भारतीय राष्ट्रीय पंचांग]], जेवन सुरुज आधारित होला, में चइत पहिला महीना हवे आ ग्रेगोरियन कैलेंडर के 20/21 मार्च से एकर सुरुआत होले। [[नेपाल]] में प्रयुक्त कैलेंडर के हिसाब से ई साल के अंतिम महीना हवे। [[बंगाली कैलेंडर]] में भी ई आखिरी महीना होला।
== तिहुआर ==
=== घाँटो ===
'''घांटो''' [[भोजपुरी संस्कृति]] के बड़ा निर्मल सहज अनुराग से सराबोर भइल भाई बहिन के त्यौहार ह। [[चइत]] सुदी [[एकादशी]] के दिन हर लड़की औरत नदी नहाये जाके नदी के पवित्र पांकी लेआवेला लोग। उहे माँटि-पांकी से बनेली 'कोइलर" "कोतवाल" आ "घांटो"। एकरा के सुखा के चिकन बनावन जाला ई सब अपना भाई के बधाई बहिन करेली अपना भाई के अमर होखे के गीत गावेली। यह अवसर के ई गीत बड़ा लोकप्रिय बा ''"कवना बने रहलू ए कोइलर… कवना बने…."''।
फिर आवेला सतुआन के दिन वो दिन भाई लाठी ले के बगईचा में जाला लोग अ बहिन फांड में कोइलर ले के जाली अ आम के फेंड पर बिग देली फिर भाई कोइलर के खोज के लाठी से मार गिरावेले। ई संस्कृति भाई बहिन के बचपन के खेल नियन लागेला अ भाई बहिन के प्रेम बढ़ावेला। [[सतुआन]] के बिहान भइला बहिन फांड में घाँटों आ कोतवाल के ले के नदी किनार पर जईहे आ फांड में लेके नदी में बोर के भाई के आगे दे देदेवेली भाई एकरो के लाठी से पिटे ले पूरा गांव जुटला आ खुसी से ई त्यौहार मनावल जाला।
घांटो लोकगीतन के एको प्रकार हवे। एकरा के झलकुटिया [[चइता]] कहल जाला।<ref>{{cite news |title=फगुआ के बाद आ गइल चइत के उतपाती महीना, लेले मस्ती के आलम |url=https://hindi.news18.com/news/bhojpuri-news/beautiful-month-of-chaitra-arrived-after-fagua-know-what-is-the-importance-3542702.html |access-date=20 मार्च 2022 |work=News18 हिंदी |date=31 मार्च 2021 |language=hi |archive-date=2021-05-15 |archive-url=https://web.archive.org/web/20210515162645/https://hindi.news18.com/news/bhojpuri-news/beautiful-month-of-chaitra-arrived-after-fagua-know-what-is-the-importance-3542702.html |url-status=dead }}</ref>
=== नवरातर ===
{{main|नवरातर}}
बसंत के [[नवरातर]] चइत महीना के अंजोर में मनावल जाला आ एक्कम से नउमी ले चले ला। एकरा समापन [[रामनउमी]] के दिने होखे ला।
=== रामनउमी ===
{{main|रामनउमी}}
[[रामनउमी]] चाहे राम नवमी चइत महीना के प्रमुख तिहुआर हवे। एह दिन [[राम]] के जनम के दिन के रूप में मनावल जाला। ई चइत महीना के [[नवरातर]] के अंतिम दिन भी होला।
== इहो देखल जाय ==
* [[चैती]]
* [[चइता]]
== संदर्भ ==
{{Reflist}}
{{हिंदू कलेंडर}}
[[श्रेणी:हिंदू कलेंडर के महीना]]
{{हिंदू-आधार}}
a90q42wge6eawocgidhec65bk0hcvi8
जेनिफर विंगेट
0
38552
790097
762599
2026-04-03T05:43:30Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790097
wikitext
text/x-wiki
{{Infobox person
| name= जेनिफर विंगेट
| image = Jennifer Winget at the 25th SOL Lions Gold Awards 2018 (15) (cropped).jpg
| caption= 25वाँ एसओएल लायंस गोल्ड अवार्ड 2018 में विंगेट
| birth_name= जेनिफर विंगेट
| birth_date = {{Birth date and age|df=yes|1985|5|30}}<ref>{{cite web |author=Aaqilah |url=http://entertainment.oneindia.in/television/news/2014/jennifer-winget-birthday-what-is-karan-singh-grover-surprise-wifey-141480.html |title=Jennifer Winget's Birthday: What Is Karan Singh Grover's Surprise For Wifey? - Oneindia Entertainment |publisher=Entertainment.oneindia.in |date=30 मई 2014 |accessdate=2 अगस्त 2014 |archive-date=2014-06-18 |archive-url=https://web.archive.org/web/20140618202900/http://entertainment.oneindia.in/television/news/2014/jennifer-winget-birthday-what-is-karan-singh-grover-surprise-wifey-141480.html |url-status=dead }}</ref><ref>{{cite web |url=http://us.india.com/stream/jennifer-winget-birthday-bumps-10-things-to-know-about-the-indian-tv-star-67699/ |title=Jennifer Winget Birthday Bumps: 10 Things to know about the Indian TV star! |publisher=India.com |date=30 मई 2014 |accessdate=16 अक्टूबर 2014 |archive-date=2015-01-11 |archive-url=https://web.archive.org/web/20150111182811/http://us.india.com/stream/jennifer-winget-birthday-bumps-10-things-to-know-about-the-indian-tv-star-67699/ |url-status=dead }}</ref>
| birth_place = [[गोरेगाँव]], मुंबई, भारत<ref>{{cite web|url=http://www.thenewsreports.com/jennifer-winget-gears-up-for-cinematic-debut-with-kunal-kohlis-phir-se/10962/devrupa-rakshit|title=Jennifer Winget gears up for cinematic debut with Kunal Kohli's 'Phir Se'|work=The News Reports|accessdate=20 दिसंबर 2014|archive-date=2015-03-18|archive-url=https://web.archive.org/web/20150318223403/http://www.thenewsreports.com/jennifer-winget-gears-up-for-cinematic-debut-with-kunal-kohlis-phir-se/10962/devrupa-rakshit|url-status=dead}}</ref>
| occupation = ऐक्ट्रेस, टीवी होस्ट
| spouse = {{marriage|[[करण सिंह ग्रोवर]]|2012|2014|reason=तलाक}}<ref name="Karan-Jennifer divorce">{{cite web|last1=Bajwa|first1=Dimpal|title=Karan Singh Grover confirms divorce with Jennifer Winget on Twitter|url=http://indianexpress.com/article/entertainment/television/karan-singh-grover-confirms-divorce-with-jennifer-winget-on-twitter/|publisher=Indian Express|accessdate=15 December 2014|date=9 दिसंबर 2014}}</ref>
| nationality = [[भारत|भारतीय]]
| residence =
| years_active = 1988–अबतक
}}
'''जेनिफर विंगेट''' एक ठो भारतीय फिलिम ऐक्ट्रेस बाड़ी। जेनिफर विंगेट के [[बॉलीवुड|हिंदी सिनेमा]] में एक्टिंग करे खातिर [[बॉलीवुड ऐक्ट्रेस लोग के लिस्ट|बॉलीवुड ऐक्ट्रेस]] के रूप में जानल जाला।
==संदर्भ==
{{Reflist}}
==बाहरी कड़ी==
{{commonscat|Jennifer Winget|जेनिफर विंगेट}}
* {{IMDb name|1764355}}
[[श्रेणी:हिंदी फिलिम ऐक्ट्रेस]]
[[श्रेणी:जियत लोग]]
[[श्रेणी:1985 में जनम]]
[[श्रेणी:मुंबई के लोग]]
{{actor-stub}}
ekx9ldvp32o1jb21hjgzs4mrswgjqx8
इनस्टाइल
0
40875
790087
781231
2026-04-02T23:23:23Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790087
wikitext
text/x-wiki
{{Infobox magazine
| title = इनस्टाइल
| image_file = InStyle.svg
| editor = लौरा ब्राउन
| frequency =
| category = [[सेलिब्रिटी]], मानव रूचि के कथा, [[समाचार]]
| total_circulation = 1,810,539 (US)<ref>{{cite web|title=Consumer Magazines|url=http://abcas3.auditedmedia.com/ecirc/magtitlesearch.asp|publisher=Alliance for Audited Media |accessdate=10 फरवरी 2014}}</ref><br />146,507 (UK)<ref>{{cite web|title=ABC Certificates and Reports: Instyle UK|url=http://www.abc.org.uk/Products-Services/Product-Page/?tid=11817|publisher=Audit Bureau of Circulations (UK)|accessdate=14 फरवरी 2014|quote=ABC July - दिसंबर 2012, print and digital editions.|archive-date=2016-03-04|archive-url=https://web.archive.org/web/20160304002023/http://www.abc.org.uk/Products-Services/Product-Page/?tid=11817|url-status=dead}}</ref>
| circulation_year = 2013
| company = [[Time Inc.]]
| firstdate = {{start date and age|1994|6}}
| country = [[United States]]
| language = [[English language|English]]
| website = {{URL|www.instyle.com}}
| issn = 1076-0830
}}
'''''इनस्टाइल''''' ({{Lang|en|''[[:en:InStyle|InStyle]]''}}) अमेरिका में औरतन के एक ठो महीनावार छपे वाली पत्रिका बा जे [[टाइम इंक.]] द्वारा प्रकाशित कइल जाला। एह पत्रिका में बिज्ञापन के अलावा, ब्यूटी, फैशन, मनोरंजन आ सेलिब्रिटी लोग के जीवन शैली पर सामग्री छपे ला। लॉरा ब्राउन एकर संपादिका बाड़ी<ref>{{cite web|url=http://www.instylemag.com.au/about.asp|title=InStyle Magazine-About|accessdate=21 मार्च 2012|archive-date=2012-05-10|archive-url=https://web.archive.org/web/20120510113357/http://www.instylemag.com.au/about.asp|url-status=dead}}</ref> अमेरिका से सुरू होखे के बाद ''इनस्टाइल'' सन् 2012 तक ले कुल 17 अन्य देसन में आपन विस्तार क चुकल बा।<ref>{{cite web|url=http://www.magxone.com/instyle/simona-patruleasa-instyle-romania-july-2012/|title=Simona Patruleasa InStyle Romania July 2012|work=Magxone.com|date=23 जुलाई 2012|accessdate=28 मई 2013}}</ref><ref>{{cite web |url=http://www.pacificmags.com.au/pages/Magazines/Magazine.aspx?mid=888805db-4099-40db-8fb1-5f38829bf012 |title=Pacific Magazines: In Style |accessdate=21 मार्च 2012 |archive-date=2018-03-14 |archive-url=https://web.archive.org/web/20180314184907/http://www.pacificmags.com.au/Pages/Magazines/Magazine.aspx?mid=888805db-4099-40db-8fb1-5f38829bf012 |url-status=dead }}</ref>
{{clear}}
==संदर्भ==
{{Reflist|35em}}
[[श्रेणी:पत्रिका]]
[[श्रेणी:अमेरिकी पत्रिका]]
{{mag-stub}}
nq28aks2uw31njeq2mu8nudap6gx3mc
सोशल मीडिया
0
47584
790056
788606
2026-04-02T16:33:12Z
SM7
3953
सुधार कइल गइल
790056
wikitext
text/x-wiki
[[File:A serviceman accesses social media channels using a smart phone, outside MOD Main Building in London MOD 45156045.jpg|thumb|230px|alt=केहू के हाथ में मोबाइल फोन, पाछे बिल्डिंग, सडक आ घास देखात बा|[[स्मार्टफोन|मोबाइल]] पर [[फेसबुक]] पन्ना]]
'''सोशल मीडिया''' ({{Langx|en|social meddia}}) आजकाल्ह के इलेक्ट्रानिक जुग में [[वेबसाइट|वेब]] आ [[इंटरनेट]] आधारित माध्यम बा जेकरा इस्तेमाल करे वाला लोग आपन बात-बिचार आपस में साझा क सकत बा।<ref>{{cite web|url=https://www.merriam-webster.com/dictionary/social%20media |title=Social Media | Definition of Social Media by Merriam-Webster |publisher=Merriam-webster.com |date= |accessdate=2017-06-25}}</ref> कई ठो सोशल नेटवर्किंग साइट आ सर्विस अउरी माइक्रोब्लागिंग वेबसाइट सभ ई सुबिधा देत बाड़ी कि प्रयोगकर्ता आपन खुद के कंटेंट (छोट ब्लॉग, टिप्पणी, फोटो, एनीमेशन, बीडियो वगैरह सामग्री) के इंटरनेट आधारित समुदाय (वर्चुअल कम्युनिटी) में साझा क सकत बा।<ref>{{cite web|url=http://communications.tufts.edu/marketing-and-branding/social-media-overview/ |title=Social Media Overview - Communications |publisher=Communications.tufts.edu |date= |accessdate=2017-06-25}}</ref> एही तरे दुसरे लोगन के कंटेंट पर टिप्पणी भा राय जाहिर क सकत बा, दुबारा साझा क सकत बा या फिर खराब कंटेंट के रिपोर्ट क सकत बा।
आजकाल्ह के कुछ प्रमुख [[सोशल नेटवर्किंग सर्विस]] सभ में [[फेसबुक]], [[वाट्सएप]], [[ट्विटर]], [[यूट्यूब]], [[फेसबुक मैसेंजर|मैसेंजर]], [[वाइबर]], [[टंबलर]], [[लिंक्डइन]], [[वीचैट]] वगैरह बाने।
सोशल मीडिया, सामन्य मीडिया से कई रूप में अलग भी बा। तेजी भा तात्कालिकता, कंटेंट के गुणवत्ता (क्वालिटी), पहुँच, बहुलता (कई स्रोत, कई उपभोक्ता) वगैरह कई बिंदु गिनावल जा सके लें जिनहन के आधार पर सामान्य मीडिया (जइसे [[अखबार]], टीवी, रेडियो) से ई मीडिया अलग बा।
सोशल मीडिया के अच्छा आ खराब दुनों तरह के परभाव भी लोगन द्वारा अखियान कइल जा रहल बा।<ref>{{cite web|author=Čeština |url=https://www.linkedin.com/pulse/positive-negative-effects-social-media-society-ali-kingston |title=Positive and Negative Effects of Social Media on Society |publisher=LinkedIn |date=2015-10-31 |accessdate=2017-06-25}}</ref> साइबरबकैती, [[ट्रोल|ट्रोलिंग]] आ ऑनलाइन हरासमेंट वगैरह के मामिला सोझा आइल बाने आ डिप्रेसन आ कुछ अन्य मनोबैज्ञानिक समस्या<ref>{{cite web|author=About the Author |url=https://www.psychologytoday.com/blog/nurturing-self-compassion/201703/mental-health-and-the-effects-social-media |title=Mental Health and the Effects of Social Media |language=en |publisher=Psychology Today |date= |accessdate=2017-06-25}}</ref> में बढ़ती के कारण के रूप में भी सोशल मीडिया के भूमिका होखे के दावा कइल जा रहल बा। लाभ के चीज में, लोगन के आपन राय जाहिर करे, दूसरा लोग के राय जाने, बिबिध स्रोत से उपलब्ध जानकारी के तुलना करे वगैरह के अवसर में भारी बढ़ती भइल बा।
==इहो देखल जाय==
* [[सोशल नेटवर्किंग सर्विस]]
* [[कम्युनिकेशन]]
* [[ट्रोल|ट्रोलिंग]]
==संदर्भ==
{{Reflist|35em}}
[[श्रेणी:सोशल मीडिया| ]]
[[श्रेणी:इंटरनेट संस्कृति]]
[[श्रेणी:समाज]]
{{internet-stub}}
{{society-stub}}
fuaz6az1j7qmklnfp6j0k348f11i3eb
790057
790056
2026-04-02T16:37:09Z
SM7
3953
संदर्भ जोड़ल/सुधारल गइल
790057
wikitext
text/x-wiki
[[File:A serviceman accesses social media channels using a smart phone, outside MOD Main Building in London MOD 45156045.jpg|thumb|230px|alt=केहू के हाथ में मोबाइल फोन, पाछे बिल्डिंग, सडक आ घास देखात बा|[[स्मार्टफोन|मोबाइल]] पर [[फेसबुक]] पन्ना]]
'''सोशल मीडिया''' ({{Langx|en|social meddia}}) आजकाल्ह के इलेक्ट्रानिक जुग में [[वेबसाइट|वेब]] आ [[इंटरनेट]] आधारित माध्यम बा जेकरा इस्तेमाल करे वाला लोग आपन बात-बिचार आपस में साझा क सकत बा।<ref>{{cite web|url=https://www.merriam-webster.com/dictionary/social%20media |title=Social Media | Definition of Social Media by Merriam-Webster |publisher=Merriam-webster.com |date= |accessdate=2017-06-25}}</ref> कई ठो सोशल नेटवर्किंग साइट आ सर्विस अउरी माइक्रोब्लागिंग वेबसाइट सभ ई सुबिधा देत बाड़ी कि प्रयोगकर्ता आपन खुद के कंटेंट (छोट ब्लॉग, टिप्पणी, फोटो, एनीमेशन, बीडियो वगैरह सामग्री) के इंटरनेट आधारित समुदाय (वर्चुअल कम्युनिटी) में साझा क सकत बा।<ref>{{cite web|url=http://communications.tufts.edu/marketing-and-branding/social-media-overview/ |title=Social Media Overview - Communications |publisher=Communications.tufts.edu |date= |accessdate=2017-06-25}}</ref> एही तरे दुसरे लोगन के कंटेंट पर टिप्पणी भा राय जाहिर क सकत बा, दुबारा साझा क सकत बा या फिर खराब कंटेंट के रिपोर्ट क सकत बा।
आजकाल्ह के कुछ प्रमुख [[सोशल नेटवर्किंग सर्विस]] सभ में [[फेसबुक]], [[वाट्सएप]], [[ट्विटर]], [[यूट्यूब]], [[फेसबुक मैसेंजर|मैसेंजर]], [[वाइबर]], [[टंबलर]], [[लिंक्डइन]], [[वीचैट]] वगैरह बाने।
सोशल मीडिया, सामन्य मीडिया से कई रूप में अलग भी बा। तेजी भा तात्कालिकता, कंटेंट के गुणवत्ता (क्वालिटी), पहुँच, बहुलता (कई स्रोत, कई उपभोक्ता) वगैरह कई बिंदु गिनावल जा सके लें जिनहन के आधार पर सामान्य मीडिया (जइसे [[अखबार]], टीवी, रेडियो) से ई मीडिया अलग बा।
सोशल मीडिया के अच्छा आ खराब दुनों तरह के परभाव भी लोगन द्वारा अखियान कइल जा रहल बा।<ref>{{cite web|author=Čeština |url=https://www.linkedin.com/pulse/positive-negative-effects-social-media-society-ali-kingston |title=Positive and Negative Effects of Social Media on Society |publisher=LinkedIn |date=2015-10-31 |accessdate=2017-06-25}}</ref> साइबरबकैती, [[ट्रोल|ट्रोलिंग]] आ ऑनलाइन हरासमेंट वगैरह के मामिला सोझा आइल बाने आ डिप्रेसन आ कुछ अन्य मनोबैज्ञानिक समस्या<ref>{{cite web |last1=Minamitani |first1=Kenta |title=Social Media Addiction and Mental Health: The Growing Concern for Youth Well-Being |url=https://law.stanford.edu/2024/05/20/social-media-addiction-and-mental-health-the-growing-concern-for-youth-well-being/ |website=Stanford Law School |access-date=2 April 2026 |language=en |date=20 मई 2024}}</ref><ref>{{cite web |title=Social media’s impact on our mental health and tips to use it safely {{!}} Cultivating Health |url=https://health.ucdavis.edu/blog/cultivating-health/social-medias-impact-our-mental-health-and-tips-to-use-it-safely/2024/05 |website=cultivating-health |language=en}}</ref> में बढ़ती के कारण के रूप में भी सोशल मीडिया के भूमिका होखे के दावा कइल जा रहल बा। लाभ के चीज में, लोगन के आपन राय जाहिर करे, दूसरा लोग के राय जाने, बिबिध स्रोत से उपलब्ध जानकारी के तुलना करे वगैरह के अवसर में भारी बढ़ती भइल बा।
==इहो देखल जाय==
* [[सोशल नेटवर्किंग सर्विस]]
* [[कम्युनिकेशन]]
* [[ट्रोल|ट्रोलिंग]]
==संदर्भ==
{{Reflist|35em}}
[[श्रेणी:सोशल मीडिया| ]]
[[श्रेणी:इंटरनेट संस्कृति]]
[[श्रेणी:समाज]]
{{internet-stub}}
{{society-stub}}
tdgw9lf7tptvvcww3hbxr6doe40yp28
5जी
0
52551
790079
786424
2026-04-02T21:06:38Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790079
wikitext
text/x-wiki
[[File:5th generation mobile network (5G) logo.jpg|thumb|5G लोगो]]
'''पाँचवाँ जेनरेशन के मोबाइल नेटवर्क''' (5th generation mobile networks) या फिर '''पाँचवीं पीढ़ी के वायरलेस सिस्टम''' के '''5जी''' (उच्चारण: फाइव जी) के छोट नाँव से जानल जाला, नया आ भाबिस्य में इस्तेमाल होखे खाती प्रस्तावित [[मोबाइल यंत्र|मोबाइल]] [[टेलीकम्यूनिकेशन नेटवर्क|नेटवर्क सिस्टम]] बाटे जे मिलीमीटर बैंड (28, 38, आ 60 GHz) में काम करी आ ई वर्तमान 4जी सिस्टम से आगे के चीज होखी। संचार कंपनी एरिक्सन द्वारा नवंबर 2017 में भारत में एह तकनीक के प्रदर्शन भी कइल गइल आ सरकार के साल 2020 तक 5जी ले आवे के लक्ष्य के खाती आपन प्रतिबद्धता जतावल गइल।<ref>{{cite web |url=https://khabar.ndtv.com/news/tech/ericsson-demonstrated-5g-technology-for-the-first-time-in-the-country-1776969 |title=Ericsson demonstrated 5G technology for the first time in the country - एरिक्सन ने देश में पहली बार किया 5 G तकनीक का प्रदर्शन |publisher=Khabar.ndtv.com |date=2017-11-18 |accessdate=2018-01-07 |archive-date=2019-08-26 |archive-url=https://web.archive.org/web/20190826093010/https://khabar.ndtv.com/news/tech/ericsson-demonstrated-5g-technology-for-the-first-time-in-the-country-1776969 |url-status=dead }}</ref> हाले में एक ठो खबर में एटी&टी (AT&T) द्वारा दुनिया के पहिला फाइवजी फोन भी ले आवे के बात कहल गइल बा जे एह साल, 2018 के अंत में आई, एह तरीका से दू गो अमेरिकी कंपनी साल 2018 में फाइवजी फोन ले आवे खाती तइयारी में बाड़ी सऽ काहें कि वेरिजोन कंपनी पिछले साल एह बात के घोषणा क चुकल बा।<ref>{{cite web |author=Antonio Villas-BoasJan 4, 2018, 08.38 PM |url=https://www.businessinsider.in/ATT-and-Verizons-5G-networks-are-coming-this-year-and-your-internet-speeds-will-be-insanely-fast-when-they-arrive/articleshow/62369590.cms |title=AT&T and Verizon's 5G networks are coming this year and your internet speeds will be insanely fast when they arrive | Business Insider India |language=en |publisher=Businessinsider.in |date= |accessdate=2018-01-07 }}{{Dead link|date=May 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref>
==इहो देखल जाय==
* [[4जी]]
* [[टेलीकम्यूनिकेशन नेटवर्क]]
== संदर्भ ==
{{reflist|33em}}
==बाहरी कड़ी==
* [http://www.bbc.com/hindi/science/2014/12/141203_5g_internet_network_vr 5जीः कैसी होगी 800 जीबीपीएस की स्पीड?], [[बीबीसी|बीबीसी हिंदी]] पर {{In lang|hi}}।
[[श्रेणी:इंटरनेट]]
[[श्रेणी:टेलीकम्यूनिकेशन]]
[[श्रेणी:मोबाइल टेलिकम्यूनिकेशन]]
{{mobile-stub}}
a62dex6uf8ei081tpgegt31wtnffxdv
दक्खिन-पूरबी एशियाई राष्ट्र सभ के संगठन
0
53745
790110
781296
2026-04-03T07:40:24Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790110
wikitext
text/x-wiki
{{आसियान लेबल वाला नक्शा (नीला)}}
'''दक्खिन-पूरबी एशियाई राष्ट्र संगठन''' ({{Lang|en|Association of Southeast Asian Nations}}) संक्षेप में (ASEAN-'''आसियान''') दक्खिन-पूरब एशिया में स्थित 10 देश सभ के एगो क्षेत्रीय संगठन हवे, जवन आपस में आर्थिक विकास, समृद्धि, शांति आ स्थिरता कायम रखे खातिर काम करेले जा। एकर मुख्यालय [[इंडोनेशिया]] के [[जकार्ता]] में बा। आसियान के स्थापना 8 अगस्त 1967 में [[थाईलैंड]] के राजधानी [[बैंकॉक]] में भइल रहल।
==सदस्य देश सभ<ref name="News18 India 2018">{{cite web | title=गणतंत्र दिवस परेड 2018: फिर नया इतिहास बनेगा और दुनिया देखेगी– News18 हिंदी | website=News18 India | date=25 January 2018 | url=https://hindi.news18.com/news/nation/republic-day-2018-know-waht-is-new-this-time-and-list-of-10-asean-leaders-attending-as-chief-guests-1245984.html | language=हिंदी भाषा | accessdate=26 January 2018 | archive-date=25 January 2018 | archive-url=https://web.archive.org/web/20180125144259/https://hindi.news18.com/news/nation/republic-day-2018-know-waht-is-new-this-time-and-list-of-10-asean-leaders-attending-as-chief-guests-1245984.html | url-status=dead }}</ref>==
#[[ब्रुनेई]]
#[[कंबोडिया]]
#[[इंडोनेशिया]]
#[[लाओस]]
#[[मलेशिया]]
#[[म्यांमार]]
#[[फिलीपींस]]
#[[सिंगापुर]]
#[[थाइलैंड]]
#[[वियतनाम]]
==इहो देखल जाय==
* [[दक्षिण एशियाई क्षेत्रीय सहयोग संगठन]]
==संदर्भ==
{{reflist}}
[[श्रेणी:एशिया]]
2u2fot5bvjpkwhv8y2vd0qod6y0ve77
नासा
0
54058
790058
789958
2026-04-02T16:45:10Z
SM7
3953
/* भविष्य के योजना */ +विकिकड़ी जोड़ल गइल
790058
wikitext
text/x-wiki
{{Infobox government agency
| name = नेशनल एरोनॉटिक्स एंड स्पेस एडमिनिस्ट्रेशन<br><small>National Aeronautics and Space Administration</small>
| seal = NASA seal.svg
| seal_width = 150
| seal_caption = मोहर
| logo = NASA logo.svg
| logo_width = 160
| logo_caption = नासा के चीन्हा
| image = Flag of the National Aeronautics and Space Administration.svg
| image_size = 150
| image_caption = झंडा
| formed = {{Start date and age|1958|07|29}}
| preceding1 = ''नेशनल एडवाइजरी कमिटी फॉर एरोनॉटिक्स'' (NACA) (1915–1958)<ref name="CentNACA">[http://www.centennialofflight.net/essay/Evolution_of_Technology/NACA/Tech1.htm US Centennial of Flight Commission, NACA] {{Webarchive|url=https://web.archive.org/web/20140220005256/http://www.centennialofflight.net/essay/Evolution_of_Technology/NACA/Tech1.htm |date=2014-02-20 }}. centennialofflight.net. Retrieved on November 3, 2011.</ref>
| jurisdiction = अमेरिकी सरकार
| headquarters = टू इंडिपेंडेंट चौक, [[वाशिंगटन, डी॰सी॰]], [[अमेरिका]]
| coordinates = {{Coord|38|52|59|N|77|0|59|W|type:landmark_region:US-DC|display=inline,title}}
| motto = ''फॉर दि बेनिफिट ऑफ आल''<ref name="motto">{{cite web |url=http://www.lightmillennium.org/2004_newyear/gokoglu_nasa_stands_forall.html |title=NASA stands "for the benefit of all."—Interview with NASA's Dr. Süleyman Gokoglu |accessdate= |publisher=The Light Millennium |date=2007 |author=Lale Tayla |author2=Figen Bingul |last-author-amp=yes}}</ref><br>
(सभका फायदा खाती)
| employees = 17,381+<ref>{{cite web |url=https://wicn.nssc.nasa.gov/c10/cgi-bin/cognosisapi.dll?b_action=powerPlayService&m_encoding=UTF-8&BZ=1AAABgNNr_f942m2PQWuDQBCF~8yOaS9hdlTUgwd1DRHamEahZ6NjCTFuUFOaf981KYTSzu7wHm__gV2ryJdFme~STIXjpAfO1BMQHSShS5TK2I89x~NXsYt24AfKd4Mg8mLHMM~WvJtGu2S9jcp1CLSqdT9xPxnX6q7hAdwYHOyrE4OtFttBt4eOgTC57HlcgKsMea7qY~XBv9F3PRxbPdQz~LM245YqkmWSbzZpUmZGotc0~Ae14rewRRQSEaVEIQQKFwWhmI8QUdcZOD2dO31lHgGDvDeBukxXI0DtPP0yP2m4MfaFq082kADygWwDsATaAwX3QD4C8afk7c7m~qBbP_obQJNj2A%3D%3D |title=Workforce Profile |publisher=NASA |date=जनवरी 11, 2011 |accessdate=दिसंबर 17, 2012}}</ref>
| budget = {{increase}} {{US$|19.5 बिलियन|link=yes}}<ref>https://www.nasa.gov/sites/default/files/atoms/files/fy_2017_nasa_agency_fact_sheet.pdf</ref> (2017),<ref name="NASA Gets a Budget Hike for 2016">{{cite web |url=http://www.planetary.org/blogs/casey-dreier/2015/1216-nasa-gets-an-extraordinary-budget-in-2016.html |title=[Updated] An Extraordinary Budget for NASA in 2016 - Congressional omnibus increases the space agency's budget by $1.3 billion |publisher=The Planetary Society |date=दिसंबर 18, 2015 |accessdate=February 4, 2016 |author=Dreier, Casey}}</ref>
| chief1_name =
| chief1_position =
| chief2_name =
| chief2_position =
| website = {{URL|nasa.gov}}
}}
नैशनल एरोनॉटिक्स एंड स्पेस एडमिनिस्ट्रेशन (National Aeronautics and Space Administration), जेकरा संक्षेप में '''नासा''' (NASA) कहल जाला, अमेरिका सरकार के एगो स्वतंत्र एजेंसी हऽ। ई संस्था अमेरिका के अंतरिक्ष प्रोग्राम, हवाई विज्ञान (एरोनॉटिक्स) आ अंतरिक्ष रिसर्च खातिर जिम्मेदार बा। नासा के मुख्य मकसद अंतरिक्ष अन्वेषण, वैज्ञानिक खोज आ हवाई टेक्नोलॉजी में प्रगति करावल बा।<ref>[https://www.nasa.gov/about/ NASA About]</ref>
नासा आपन अर्थ ऑब्जर्विंग सिस्टम से धरती के वातावरण आ जलवायु के गहिर समझ बनावेला।<ref>[https://science.nasa.gov/earth-science/ NASA Earth Science]</ref> हेलियोफिजिक्स प्रोग्राम से सूर्य आ स्पेस वेदर के पढ़ाई करे ला।<ref>[https://science.nasa.gov/heliophysics/ NASA Heliophysics]</ref> न्यू होराइजंस जइसन रोबोटिक मिशन से नासा सौरमंडल के ग्रह-उपग्रह आ छोट-छोट पिंड सभ के खोज-परख करेला।<ref>[https://www.nasa.gov/mission/new-horizons/ New Horizons Mission]{{Dead link|date=September 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> ग्रेट ऑब्ज़रवेटरी प्रोग्राम से बिग बैंग आ खगोल भौतिकी पर रिसर्च कइल जाला।<ref>[https://science.nasa.gov/astrophysics/programs/grand-observatories NASA Great Observatories]{{Dead link|date=September 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> नासा कई गो अंतरराष्ट्रीय संस्था सभ संगे ग्रीनहाउस गैस जइसन डाटा शेयर करके पर्यावरण बचावे में मदद करेला।<ref>[https://climate.nasa.gov/ NASA Climate]</ref>
== इतिहास ==
नासा के स्थापना 29 जुलाई 1958 के "नेशनल एरोनॉटिक्स एंड स्पेस एक्ट" के तहत भइल। ई आपन पुरान संस्था "नेशनल एडवाइजरी कमिटी फॉर एरोनॉटिक्स (NACA)" के जगहा पर बनल।<ref>[https://history.nasa.gov/naca/NACAorigin.html NACA to NASA Transition]</ref> 1 अक्टूबर 1958 से नासा आपन काम शुरू कइलस। तब से लेके आज ले अमेरिकी अंतरिक्ष अन्वेषण के सभ प्रोग्राम नासा के हाथ में रहल, जइसन कि अपोलो चंद्रमा अभियान, स्कायलैब स्पेस स्टेशन आ बाद में स्पेस शटल।<ref>[https://history.nasa.gov/ NASA History]</ref>
== आज के काम ==
आज नासा अंतरराष्ट्रीय अंतरिक्ष स्टेशन के सपोर्ट करत बा।<ref>[https://www.nasa.gov/mission/iss/ International Space Station]{{Dead link|date=September 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> चंद्रमा पर दुबारा आदमी भेजे खातिर आर्टेमिस प्रोग्राम चला रहल बा।<ref>[https://www.nasa.gov/specials/artemis/ Artemis Program]</ref> ओरायन क्रू वाहन आ कारोबारी क्रू वाहन बनावे पर भी काम हो रहल बा। ई एजेंसी लॉन्च सर्विस प्रोग्राम (LSP) खातिर जिम्मेदार बा, जे मानवरहित लॉन्चन के तैयारी आ गिनती देखेला।<ref>[https://www.nasa.gov/centers/kennedy/launchingrockets/lsp.html NASA LSP]{{Dead link|date=September 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref>
== नासा के शुरुआती मिशन ==
नासा के स्थापना 1958 में भइल। सुरु में प्रोजेक्ट मर्करी आ प्रोजेक्ट जेमिनी जइसन मिशन भइल, जे मानव अंतरिक्ष यात्रा खातिर नींव रखलस।<ref>[https://www.nasa.gov/mission/mercury-gemini/ Mercury & Gemini]{{Dead link|date=September 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref>
== मुख्य उपलब्धि ==
'''अपोलो प्रोग्राम''': 20 जुलाई 1969 के अपोलो 11 मिशन में नील आर्मस्ट्रांग आ बज़ एल्ड्रिन पहिला बेर चंद्रमा पर उतरलन।<ref>[https://www.nasa.gov/mission/apollo-11/ Apollo 11]</ref>
'''हबल टेलीस्कोप''': 1990 में लॉन्च भइल आ ई अबले लाखों गैलेक्सी, नीहारिका, ब्लैक होल आ डार्क एनर्जी के पढ़ाई में मदद कइले बा।<ref>[https://hubblesite.org/ Hubble Site]</ref>
'''मंगल रोवर्स''': स्पिरिट, ऑपर्च्युनिटी, क्यूरियोसिटी आ पर्सीवरेंस मंगल ग्रह के सतह, मिट्टी आ मौसम के पढ़ाई कइलन। इंजेन्यूटी हेलिकॉप्टर पहिला बार दोसरा ग्रह पर उड़ल।<ref>[https://mars.nasa.gov/ Mars Missions]</ref>
'''वॉयेजर मिशन''': 1977 में लॉन्च भइल वॉयेजर 1 आ 2 अब तारन के बीच के अंतरिक्ष (Interstellar Space) में पहुँच गइल बा।<ref>[https://voyager.jpl.nasa.gov/ NASA Voyager]</ref>
== हालिया मिशन (2024–2025) ==
'''यूरोपा क्लिपर''': बृहस्पति के चंद्रमा यूरोपा पर पानी के खोज खातिर भेजल गइल।<ref>[https://europa.nasa.gov/ Europa Clipper]</ref>
'''ब्लू घोस्ट मिशन 1''': जनवरी 2025 में लॉन्च भइल आ मार्च 2025 में चंद्रमा पर सफलतापूर्वक उतर गइल।<ref>[https://www.nasa.gov/press-release/ NASA Press Release 2025]</ref>
'''SPHEREx''': फरवरी 2025 में लॉन्च भइल, जे ब्रह्मांड के इतिहास के 3D नक्शा बनावत बा।<ref>[https://www.jpl.nasa.gov/missions/spherex NASA SPHEREx]</ref>
'''EscaPADE''': 2025 में मंगल के वायुमंडल आ सौर हवा के असर के पढ़ाई खातिर दूगो छोट सैटेलाइट भेजल गइल।<ref>[https://www.nasa.gov/escapade/ NASA EscaPADE]</ref>
== भविष्य के योजना ==
'''आर्टेमिस प्रोग्राम''': चंद्रमा पर दुबारा आदमी भेजल जाई।<ref>[https://www.nasa.gov/specials/artemis/ Artemis Future Plans]</ref><ref>[https://www.wondersinspace.com/everything-about-artemis-program/ Everything About the Artemis Program] Wonders in Space</ref>
'''आर्टेमिस I (2022)''': मानवरहित परीक्षण।<ref>[https://www.nasa.gov/artemis-1 Artemis I]</ref>
'''[[आर्टेमिस 2|आर्टेमिस II]] (2026)''': मानव समेत मिशन, चंद्रमा के चक्कर लगाई।<ref>[https://www.nasa.gov/artemis-2 Artemis II]{{Dead link|date=September 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref>
'''[[आर्टेमिस 3|आर्टेमिस III]] (2027)''': 1972 के बाद पहिला बेर मानव चंद्रमा पर उतराई।<ref>[https://www.nasa.gov/artemis-3 Artemis III]</ref>
'''लूनर गेटवे''': चंद्रमा के कक्षा में नया स्टेशन बनावल जाई।<ref>[https://www.nasa.gov/gateway Lunar Gateway]</ref>
'''ड्रैगनफ्लाई''': 2027 में शनि के चंद्रमा टाइटन पर उड़न यान भेजल जाई।<ref>[https://dragonfly.jhuapl.edu/ Dragonfly Mission]</ref>
'''निसार (NISAR)''': नासा-इसरो मिलके पृथिवी के सतह आ प्राकृतिक आपदा सभ के निगरानी खातिर 2025 में लॉन्च करी।<ref>[https://nisar.jpl.nasa.gov/ NISAR Mission]</ref>
== निष्कर्ष ==
नासा अंतरिक्ष अनुसंधान में एगो महत्वपूर्ण संस्था हऽ। ई मानव जाति के ब्रह्मांड समझे आ अंतरिक्ष यात्रा करे में मदद कइले बा। नासा के आने वाला मिशन अउरी रोमांचक खोज सामने ले आई। ई खाली साइंस आ टेक्नोलॉजी के प्रतीक ना हऽ, बल्कि मानव सपना आ अनंत संभावना के प्रतीक हऽ।
==नोट==
<references group="नोट"/>
==संदर्भ==
{{Reflist|35em}}
==बाहरी कड़ी==
{{Authority control}}
[[श्रेणी:नासा| ]]
[[श्रेणी:अमेरिकी सरकारी एजेंसी]]
[[श्रेणी:अमेरिकी सरकार]]
[[श्रेणी:वाशिंगटन, डी.सी.]]
[[श्रेणी:अंतरिक्ष अनुसंधान]]
{{astronomy-stub}}
py0nq29lhp3g7xs5lwf9k7nrvo0tqez
अंतरिक्ष यान
0
54059
790103
715344
2026-04-03T06:10:45Z
SM7
3953
पन्ना [[स्पेसक्राफ्ट]] पर अनुप्रेषित कइल गइल
790103
wikitext
text/x-wiki
#REDIRECT [[स्पेसक्राफ्ट]]
iw40o8708ffbn95sjokzlzyn3am9h3j
Module:WPSHIPS utilities
828
64572
790194
622701
2019-01-13T20:06:31Z
en>Trappist the monk
0
+landing ship;
790194
Scribunto
text/plain
require('Module:No globals')
local wpsu={}
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_list =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KDM'] = true, -- Kongelige Danske Marine
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_list =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_list =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if ship_type_list [ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if ship_type_list [ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if ship_type_list [ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if ship_type_list [frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not nationality_list [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if nationality_list [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif ship_prefix_list[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (ship_type_list) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
function wpsu.ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
function wpsu.hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
function wpsu.navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix)
local error_msg = '';
if not is_set (control) then
control = '';
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if 1 > tonumber (control) or 6 < tonumber (control) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>'; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then
dab = ' (' .. dab .. ')'; -- for all other cases that display dab
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
return link .. '|' .. link_name .. ']]';
end
--[[--------------------------< W P S U . S H I P >------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
]]
function wpsu.ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
return _ship (prefix, name, dab, control, unlinked_prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< I N F O B O X _ L I S T S >----------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, wpsu.unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
function wpsu.unbulleted_list (frame)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == frame.args[1]:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if frame.args[1]:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
end
return frame.args[1]; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (frame.args[1]), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
function wpsu.infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
if frame.args[1]:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
frame.args[1] = frame.args[1]:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return frame.args[1]; -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
function wpsu.cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
return wpsu;
9j8ruk3qzz5st98tcy4oi9rhzv04r72
790195
790194
2019-05-22T07:43:45Z
en>MSGJ
0
+Indian Coast Guard Ship
790195
Scribunto
text/plain
require('Module:No globals')
local wpsu={}
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_list =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KDM'] = true, -- Kongelige Danske Marine
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_list =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_list =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if ship_type_list [ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if ship_type_list [ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if ship_type_list [ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if ship_type_list [frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not nationality_list [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if nationality_list [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif ship_prefix_list[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (ship_type_list) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
function wpsu.ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
function wpsu.hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
function wpsu.navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix)
local error_msg = '';
if not is_set (control) then
control = '';
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if 1 > tonumber (control) or 6 < tonumber (control) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>'; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then
dab = ' (' .. dab .. ')'; -- for all other cases that display dab
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
return link .. '|' .. link_name .. ']]';
end
--[[--------------------------< W P S U . S H I P >------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
]]
function wpsu.ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
return _ship (prefix, name, dab, control, unlinked_prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< I N F O B O X _ L I S T S >----------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, wpsu.unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
function wpsu.unbulleted_list (frame)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == frame.args[1]:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if frame.args[1]:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
end
return frame.args[1]; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (frame.args[1]), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
function wpsu.infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
if frame.args[1]:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
frame.args[1] = frame.args[1]:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return frame.args[1]; -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
function wpsu.cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
return wpsu;
ky7nj78a8n2fuy0os7pyjgcb8l7qfvx
790196
790195
2019-07-28T14:19:58Z
en>Trappist the monk
0
+KM;
790196
Scribunto
text/plain
require('Module:No globals')
local wpsu={}
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_list =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDM'] = true, -- Kongelige Danske Marine
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_list =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_list =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if ship_type_list [ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if ship_type_list [ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if ship_type_list [ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if ship_type_list [frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not nationality_list [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if nationality_list [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif ship_prefix_list[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (ship_type_list) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
function wpsu.ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
function wpsu.hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
function wpsu.navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix)
local error_msg = '';
if not is_set (control) then
control = '';
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if 1 > tonumber (control) or 6 < tonumber (control) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>'; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then
dab = ' (' .. dab .. ')'; -- for all other cases that display dab
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
return link .. '|' .. link_name .. ']]';
end
--[[--------------------------< W P S U . S H I P >------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
]]
function wpsu.ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
return _ship (prefix, name, dab, control, unlinked_prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< I N F O B O X _ L I S T S >----------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, wpsu.unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
function wpsu.unbulleted_list (frame)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == frame.args[1]:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if frame.args[1]:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
end
return frame.args[1]; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (frame.args[1]), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
function wpsu.infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
if frame.args[1]:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
frame.args[1] = frame.args[1]:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return frame.args[1]; -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
function wpsu.cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
return wpsu;
j5jfm3vi6edq04v65ujirlxg8k1jqbd
790197
790196
2019-07-28T15:11:49Z
en>Trappist the monk
0
+KA, KLD;
790197
Scribunto
text/plain
require('Module:No globals')
local wpsu={}
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_list =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_list =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_list =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if ship_type_list [ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if ship_type_list [ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if ship_type_list [ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if ship_type_list [frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not nationality_list [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if nationality_list [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif ship_prefix_list[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (ship_type_list) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
function wpsu.ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
function wpsu.hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
function wpsu.navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix)
local error_msg = '';
if not is_set (control) then
control = '';
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if 1 > tonumber (control) or 6 < tonumber (control) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>'; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then
dab = ' (' .. dab .. ')'; -- for all other cases that display dab
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
return link .. '|' .. link_name .. ']]';
end
--[[--------------------------< W P S U . S H I P >------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
]]
function wpsu.ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
return _ship (prefix, name, dab, control, unlinked_prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< I N F O B O X _ L I S T S >----------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, wpsu.unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
function wpsu.unbulleted_list (frame)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == frame.args[1]:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if frame.args[1]:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
end
return frame.args[1]; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (frame.args[1]), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
function wpsu.infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
if frame.args[1]:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
frame.args[1] = frame.args[1]:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return frame.args[1]; -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
function wpsu.cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
return wpsu;
3jnkoytl9c07gupitiuwud0w74jrb34
790198
790197
2020-07-23T00:56:39Z
en>Trappist the monk
0
+KDB;
790198
Scribunto
text/plain
require('Module:No globals')
local wpsu={}
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_list =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_list =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_list =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if ship_type_list [ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if ship_type_list [ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if ship_type_list [ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if ship_type_list [frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not nationality_list [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if nationality_list [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif ship_prefix_list[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (ship_type_list) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
function wpsu.ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
function wpsu.hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
function wpsu.navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix)
local error_msg = '';
if not is_set (control) then
control = '';
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if 1 > tonumber (control) or 6 < tonumber (control) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>'; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then
dab = ' (' .. dab .. ')'; -- for all other cases that display dab
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
return link .. '|' .. link_name .. ']]';
end
--[[--------------------------< W P S U . S H I P >------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
]]
function wpsu.ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
return _ship (prefix, name, dab, control, unlinked_prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< I N F O B O X _ L I S T S >----------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, wpsu.unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
function wpsu.unbulleted_list (frame)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == frame.args[1]:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if frame.args[1]:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
end
return frame.args[1]; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (frame.args[1]), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
function wpsu.infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
if frame.args[1]:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
frame.args[1] = frame.args[1]:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return frame.args[1]; -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
function wpsu.cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
return wpsu;
qfhy19the99aamg5rott6fjble4xd6i
790199
790198
2020-07-28T21:29:32Z
en>Trappist the monk
0
+IIS, IRIS;
790199
Scribunto
text/plain
require('Module:No globals')
local wpsu={}
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_list =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_list =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_list =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if ship_type_list [ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if ship_type_list [ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if ship_type_list [ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if ship_type_list [frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not nationality_list [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if nationality_list [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif ship_prefix_list[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (ship_type_list) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
function wpsu.ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
function wpsu.hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
function wpsu.navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix)
local error_msg = '';
if not is_set (control) then
control = '';
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if 1 > tonumber (control) or 6 < tonumber (control) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>'; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then
dab = ' (' .. dab .. ')'; -- for all other cases that display dab
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
return link .. '|' .. link_name .. ']]';
end
--[[--------------------------< W P S U . S H I P >------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
]]
function wpsu.ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
return _ship (prefix, name, dab, control, unlinked_prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< I N F O B O X _ L I S T S >----------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, wpsu.unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
function wpsu.unbulleted_list (frame)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == frame.args[1]:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if frame.args[1]:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
end
return frame.args[1]; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (frame.args[1]), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
function wpsu.infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
if frame.args[1]:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
frame.args[1] = frame.args[1]:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return frame.args[1]; -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
function wpsu.cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
return wpsu;
sna6a5cc5rixmj6t27b5ueibj221jn2
790200
790199
2020-12-18T23:02:03Z
en>The Bushranger
0
adding 'RS'
790200
Scribunto
text/plain
require('Module:No globals')
local wpsu={}
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_list =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_list =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_list =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if ship_type_list [ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if ship_type_list [ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if ship_type_list [ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if ship_type_list [frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not nationality_list [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if nationality_list [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif ship_prefix_list[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (ship_type_list) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
function wpsu.ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
function wpsu.hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
function wpsu.navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix)
local error_msg = '';
if not is_set (control) then
control = '';
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if 1 > tonumber (control) or 6 < tonumber (control) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>'; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then
dab = ' (' .. dab .. ')'; -- for all other cases that display dab
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
return link .. '|' .. link_name .. ']]';
end
--[[--------------------------< W P S U . S H I P >------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
]]
function wpsu.ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
return _ship (prefix, name, dab, control, unlinked_prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< I N F O B O X _ L I S T S >----------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, wpsu.unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
function wpsu.unbulleted_list (frame)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == frame.args[1]:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if frame.args[1]:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
end
return frame.args[1]; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (frame.args[1]), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
function wpsu.infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
if frame.args[1]:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
frame.args[1] = frame.args[1]:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return frame.args[1]; -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
function wpsu.cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
return wpsu;
nx10u1wr0g4fj2jqr54dqs1acxj6ju1
790201
790200
2021-03-07T16:12:16Z
en>Trappist the monk
0
detect {{clear}} (and redirects) misused as list markup;
790201
Scribunto
text/plain
require('Module:No globals')
local wpsu={}
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_list =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_list =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_list =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if ship_type_list [ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if ship_type_list [ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if ship_type_list [ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if ship_type_list [frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not nationality_list [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if nationality_list [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif ship_prefix_list[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (ship_type_list) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
function wpsu.ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
function wpsu.hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
function wpsu.navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix)
local error_msg = '';
if not is_set (control) then
control = '';
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if 1 > tonumber (control) or 6 < tonumber (control) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>'; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then
dab = ' (' .. dab .. ')'; -- for all other cases that display dab
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
return link .. '|' .. link_name .. ']]';
end
--[[--------------------------< W P S U . S H I P >------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
]]
function wpsu.ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
return _ship (prefix, name, dab, control, unlinked_prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< I N F O B O X _ L I S T S >----------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, wpsu.unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
function wpsu.unbulleted_list (frame)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == frame.args[1]:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if frame.args[1]:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '{{clear}}', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
end
return frame.args[1]; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (frame.args[1]), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
function wpsu.infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
if frame.args[1]:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
frame.args[1] = frame.args[1]:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return frame.args[1]; -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
function wpsu.cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
return wpsu;
9739t4ohz2yxsbrn7lw3ne6q2oxk564
790202
790201
2021-03-07T16:27:27Z
en>Trappist the monk
0
790202
Scribunto
text/plain
require('Module:No globals')
local wpsu={}
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_list =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_list =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_list =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if ship_type_list [ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if ship_type_list [ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if ship_type_list [ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if ship_type_list [frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not nationality_list [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if nationality_list [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif ship_prefix_list[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (ship_type_list) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
function wpsu.ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
function wpsu.hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
function wpsu.navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix)
local error_msg = '';
if not is_set (control) then
control = '';
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if 1 > tonumber (control) or 6 < tonumber (control) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>'; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then
dab = ' (' .. dab .. ')'; -- for all other cases that display dab
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
return link .. '|' .. link_name .. ']]';
end
--[[--------------------------< W P S U . S H I P >------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
]]
function wpsu.ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
return _ship (prefix, name, dab, control, unlinked_prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< I N F O B O X _ L I S T S >----------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, wpsu.unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
function wpsu.unbulleted_list (frame)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == frame.args[1]:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if frame.args[1]:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
elseif frame.args[1]:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', frame.args[1], showerrs); -- return an error message with maintenance category
end
return frame.args[1]; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (frame.args[1]), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', frame.args[1], showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
function wpsu.infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
if frame.args[1]:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
frame.args[1] = frame.args[1]:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return frame.args[1]; -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
function wpsu.cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
return wpsu;
5z1uznml6pgobfootuidjv3szbc8cm5
790203
790202
2021-06-23T12:52:03Z
en>Trappist the monk
0
sync from sandbox;
790203
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" height="30" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" height="30" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
navsource = navsource,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
}
m871wz8toklt1obaw49nuydnhhab2f1
790204
790203
2021-06-23T15:44:12Z
en>Trappist the monk
0
790204
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, ' <span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" height="30" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" height="30" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
navsource = navsource,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
}
tuc534hyhm5slyzhcolnue6uykbilch
790205
790204
2021-07-04T19:54:16Z
en>Trappist the monk
0
sync from sandbox;
790205
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" height="30" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" height="30" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword> and |filename=<filename>
{{#invoke:WPSHIPS utilities|plimsoll_subtitle|{{{filename}}}|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[2] then
return nil;
end
local scan_num = args_t[1]:match ('%d%d%l(%d%d%d%d)'); -- get the scan number
if scan_num then
scan_num = (0 == (tonumber(scan_num) %2)) and 'even' or 'odd'; -- get even of odd for use as subtitles_xlate_t{} index
else
return nil; -- TODO: better return?
end
local subtitle = data.subtitles_t[args_t[2]]; -- to see if we are using predefined subtitles
if not subtitle then
return ': ' .. args_t[2]; -- not predefined so return whatever |subtitle= holds with leading ': '
end
subtitle = data.subtitles_xlate_t[scan_num][args_t[2]]; -- do we need to translate?
if subtitle then
subtitle = data.subtitles_t[subtitle]; -- yes, get subtitle by translation
else
subtitle = data.subtitles_t[args_t[2]]; -- no, get subtitle without translation
end
return ': ' .. subtitle;
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
}
auyrno9iz98hnp6bittvgyrt9401pr8
790206
790205
2021-07-04T23:41:58Z
en>Trappist the monk
0
sync from sandbox;
790206
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" height="30" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" height="30" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
}
0yi8p1tdy3zmgiip5xeggs6n10ghv6p
790207
790206
2021-09-11T06:00:05Z
en>Goszei
0
style tweak (match "History" header)
790207
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" height="30" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
}
54v95rohvgoiktrsg0njh39c3qqbb1y
790208
790207
2021-09-11T06:06:50Z
en>Goszei
0
try a new style
790208
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" style="background-color:#C3D6EF;text-align:left;vertical-align:middle;">');
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" style="background-color:#C3D6EF;text-align:left;vertical-align:middle;">');
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" style="background-color:#C3D6EF;text-align:left;vertical-align:middle;">');
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
}
2rauaypmx35vo26k8logh6um0r1c4ja
790209
790208
2021-09-11T06:08:41Z
en>Goszei
0
fix mistakes
790209
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" style="background-color:#C3D6EF;text-align:center;vertical-align:middle;">');
table.insert (html_out_t, 'History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" style="background-color:#C3D6EF;text-align:center;vertical-align:middle;">');
table.insert (html_out_t, 'General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" style="background-color:#C3D6EF;text-align:center;vertical-align:middle;">');
table.insert (html_out_t, 'Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
}
9i37w1aqvbsx6gxrsxh4kbaxpnr6cjd
790210
790209
2021-09-11T06:17:30Z
en>Goszei
0
partial undo
790210
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
}
758lgjaxj7lolftmv3m1zeyfd15ch2c
790211
790210
2022-05-17T22:24:28Z
en>Trappist the monk
0
790211
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_unbulleted_list = _unbulleted_list,
}
ohgfmqigk453m9d3t7s3x4hmxyxu0lk
790212
790211
2022-05-17T22:53:31Z
en>Trappist the monk
0
790212
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_ship_name_format = do_ship_name_format, -- external entry points from another module
_infobox_ship_flag = _infobox_ship_flag,
_unbulleted_list = _unbulleted_list,
}
2vzvr3tbfsts1hod0fu0lwgm8vgn01e
790213
790212
2022-05-18T16:36:10Z
en>Trappist the monk
0
790213
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none none">
<li>Subname 2a</li>
<ul style="list-style:none none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style:none none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
l7wz4ytlid13f88ggt99v9eixqictc4
790214
790213
2022-07-21T00:55:10Z
en>Izno
0
remove none none; not necessary for currently supported browsers
790214
Scribunto
text/plain
require('Module:No globals')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
608ulsgj6zb6fyezn6zfaj4xqzt0gt9
790215
790214
2022-10-21T21:17:06Z
en>WOSlinker
0
use require('strict') instead of require('Module:No globals')
790215
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
0ft8g8qq0ls23lsdvgl3f48ivxsyoc0
790216
790215
2022-11-13T15:56:45Z
en>Trappist the monk
0
790216
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local error_map = { -- [1] is error message; [2] is error category
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'};
}
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
assembles an error message from message text, help link, and error category.
]]
local function make_error_msg (msg, cat, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ');
table.insert (out, error_map[msg][1]);
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'}));
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'}));
end
return table.concat (out);
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
625vms16x427nwem5b9827wbu4kdckg
790217
790216
2023-03-03T23:05:16Z
en>Trappist the monk
0
+sclass;
790217
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:Sandbox/trappist the monk/sclass|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name');
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type');
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template then -- class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
bvbszicmpbu0l8rz6swrn39mcv6pwyo
790218
790217
2023-03-03T23:44:34Z
en>Trappist the monk
0
fix;
790218
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name');
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type');
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template then -- class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
02vnl8l1ff3d0zesz0puuk4b7295jrv
790219
790218
2023-03-04T20:00:46Z
en>Trappist the monk
0
790219
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name');
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type');
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
60o6smb32o112nfwzkyj9sidcjjnfjo
790220
790219
2023-03-04T20:11:46Z
en>Trappist the monk
0
790220
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '[[';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
ng7crelaxqdzodbilc316sf3c4dkl5s
790221
790220
2024-03-30T17:34:27Z
en>Trappist the monk
0
790221
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '';
if is_set (prefix) then
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink
else
link = link .. name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
------
local target_object = mw.title.new (link).redirectTarget;
if target_object then
link = target_object.text; -- avoid the redirect
end
------
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name .. dab;
elseif is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = dab;
else
link_name = prefix .. dab;
end
elseif '6' == control then -- prefix and name
if unlinked_prefix then -- 'unlinked prefix'?
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render
link_name = name;
else
link_name = prefix .. ' ' .. name;
end
end
end
if unlinked_whole then
return link_name;
else
return '[[' .. link .. '|' .. link_name .. ']]';
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?)
local control = frame.args[4];
local unlinked_prefix = 'yes' == frame.args.up;
local unlinked_whole = 'no' == frame.args.link;
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
batvwssmr1zazjysqzp88fexx20op2f
790222
790221
2024-04-01T14:37:05Z
en>Trappist the monk
0
790222
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.text; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|wl={{{wl|}}}|up={{{up|}}}}}
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
k2uofm55ro8dsihd0a6vtpjasrwqls4
790223
790222
2024-04-05T17:45:48Z
en>Trappist the monk
0
790223
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = ' missing name';
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = ' missing disambiguator';
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = ' missing prefix';
elseif '4' == control then -- displaying only the prefix
error_msg = 'invalid control parameter: ' .. control;
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = 'invalid control parameter: ' .. control;
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = ' missing prefix';
end
if is_set (error_msg) then
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS: template ship parameter errors]]';
end
if template then
return '<span style="color:#d33">Error: {{', template, '}}: ' .. error_msg .. '</span>' .. category; -- return an error message with template name; don't bother with making a link
end
return '<span style="color:#d33">' .. error_msg .. '</span>' .. category; -- return an error message without template name; don't bother with making a link
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.text; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|wl={{{wl|}}}|up={{{up|}}}|_template=<template name>}}
Parameters are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
|_template= template name for error messages; this way because template name does not always match <prefix>
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame, {frameOnly = true});
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t._template);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
s82pu5uecnqvx12yfdrrtt55r3fuc4w
790224
790223
2024-04-06T18:50:51Z
en>Trappist the monk
0
790224
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '');
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '');
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '');
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = error_msg_make ('invalid_control', template, control);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '');
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.text; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship');
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
fnmgk53e0v5el529c7lt9t69ft79fx0
790225
790224
2024-04-07T15:10:36Z
en>Trappist the monk
0
790225
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', nil, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', nil, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', nil, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, nil, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, nil, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', nil, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.text; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship');
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
64fvcy622a6hx3e314cxq60077vv6xa
790226
790225
2024-04-08T20:04:03Z
en>Trappist the monk
0
790226
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.text; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
qndbmviqsemkml7s8pn9km7jjzaefal
790227
790226
2024-04-12T00:41:55Z
en>Trappist the monk
0
790227
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.text; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
iy34atcskokkbx9pur1bmjmskvc6wjs
790228
790227
2024-06-24T13:40:12Z
en>Trappist the monk
0
790228
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.fullText; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
khs0mh90do3bi83f10670yjy015aahq
790229
790228
2024-10-22T16:15:20Z
en>Trappist the monk
0
+is_empty_ibox_template();
790229
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.fullText; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I S _ E M P T Y _ I B O X _ T E M P L A T E >----------------------------------
temporary(?) code to add Category:WPSHIPS: articles with empty infobox templates when empty infobox templates
are encountered. A template is empty when no parameters have assigned values or when the only parameter with an
assigned value is |Hide header=
when 'empty', returns the category name; nil else
]]
local function is_empty_ibox_template (args_t)
local i = 0;
for k, v in pairs (args_t) do
i = i + 1;
end
if ((1 == i) and args_t['Hide header']) or (0 == i) then
return '[[Category:WPSHIPS: articles with empty infobox templates]]';
end
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
hm1h8zvlid743u3nvdz4exmt4giivqj
790230
790229
2025-01-31T18:40:53Z
en>Frietjes
0
[[Special:LintErrors/night-mode-unaware-background-color]] to match https://en.wikipedia.org/w/index.php?title=Module%3AWPMILHIST_Infobox_style&diff=1232708594&oldid=860617822
790230
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.org/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.fullText; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I S _ E M P T Y _ I B O X _ T E M P L A T E >----------------------------------
temporary(?) code to add Category:WPSHIPS: articles with empty infobox templates when empty infobox templates
are encountered. A template is empty when no parameters have assigned values or when the only parameter with an
assigned value is |Hide header=
when 'empty', returns the category name; nil else
]]
local function is_empty_ibox_template (args_t)
local i = 0;
for k, v in pairs (args_t) do
i = i + 1;
end
if ((1 == i) and args_t['Hide header']) or (0 == i) then
return '[[Category:WPSHIPS: articles with empty infobox templates]]';
end
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
4fl71ofzs8znvh2a6klgnbxmja0ff3e
790231
790230
2025-06-20T12:52:45Z
en>Trappist the monk
0
switch navsource.org → navsource.net; see [[Wikipedia_talk:WikiProject_Ships#Navsource_URL_change?]];
790231
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.net/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.fullText; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I S _ E M P T Y _ I B O X _ T E M P L A T E >----------------------------------
temporary(?) code to add Category:WPSHIPS: articles with empty infobox templates when empty infobox templates
are encountered. A template is empty when no parameters have assigned values or when the only parameter with an
assigned value is |Hide header=
when 'empty', returns the category name; nil else
]]
local function is_empty_ibox_template (args_t)
local i = 0;
for k, v in pairs (args_t) do
i = i + 1;
end
if ((1 == i) and args_t['Hide header']) or (0 == i) then
return '[[Category:WPSHIPS: articles with empty infobox templates]]';
end
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
6bm9yrqe8qf355lni5x5qj6xhuvj1hm
790232
790231
2025-10-03T22:29:39Z
en>Trappist the monk
0
790232
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.net/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link); -- get title object for <link> (ship article)
if target_object.isRedirect then -- if <link> is a redirect
link = target_object.redirectTarget.fullText; -- get the redirect's title object and from that get the target title; follow the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I S _ E M P T Y _ I B O X _ T E M P L A T E >----------------------------------
temporary(?) code to add Category:WPSHIPS: articles with empty infobox templates when empty infobox templates
are encountered. A template is empty when no parameters have assigned values or when the only parameter with an
assigned value is |Hide header=
when 'empty', returns the category name; nil else
]]
local function is_empty_ibox_template (args_t)
local i = 0;
for k, v in pairs (args_t) do
i = i + 1;
end
if ((1 == i) and args_t['Hide header']) or (0 == i) then
return '[[Category:WPSHIPS: articles with empty infobox templates]]';
end
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
lo5b1s7waa8jiggjp9clpgciw3j24us
790233
790232
2025-10-05T12:38:13Z
en>Trappist the monk
0
Undid revision [[Special:Diff/1314920348|1314920348]] by [[Special:Contributions/Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) too many expensive function calls on some articles;
790233
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.net/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.fullText; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I S _ E M P T Y _ I B O X _ T E M P L A T E >----------------------------------
temporary(?) code to add Category:WPSHIPS: articles with empty infobox templates when empty infobox templates
are encountered. A template is empty when no parameters have assigned values or when the only parameter with an
assigned value is |Hide header=
when 'empty', returns the category name; nil else
]]
local function is_empty_ibox_template (args_t)
local i = 0;
for k, v in pairs (args_t) do
i = i + 1;
end
if ((1 == i) and args_t['Hide header']) or (0 == i) then
return '[[Category:WPSHIPS: articles with empty infobox templates]]';
end
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
6bm9yrqe8qf355lni5x5qj6xhuvj1hm
790234
790233
2025-10-20T16:03:44Z
en>Trappist the monk
0
790234
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {' has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.net/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.fullText; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I S _ E M P T Y _ I B O X _ T E M P L A T E >----------------------------------
temporary(?) code to add Category:WPSHIPS: articles with empty infobox templates when empty infobox templates
are encountered. A template is empty when no parameters have assigned values or when the only parameter with an
assigned value is |Hide header=
when 'empty', returns the category name; nil else
]]
local function is_empty_ibox_template (args_t)
local i = 0;
for k, v in pairs (args_t) do
i = i + 1;
end
if ((1 == i) and args_t['Hide header']) or (0 == i) then
return '[[Category:WPSHIPS: articles with empty infobox templates]]';
end
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
jux91i3ae02pipn86asogfccsbu1ncu
790235
790234
2025-10-20T16:08:11Z
en>Trappist the monk
0
790235
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.net/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.fullText; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. ' ' .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. ' ' .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I S _ E M P T Y _ I B O X _ T E M P L A T E >----------------------------------
temporary(?) code to add Category:WPSHIPS: articles with empty infobox templates when empty infobox templates
are encountered. A template is empty when no parameters have assigned values or when the only parameter with an
assigned value is |Hide header=
when 'empty', returns the category name; nil else
]]
local function is_empty_ibox_template (args_t)
local i = 0;
for k, v in pairs (args_t) do
i = i + 1;
end
if ((1 == i) and args_t['Hide header']) or (0 == i) then
return '[[Category:WPSHIPS: articles with empty infobox templates]]';
end
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
hmfr259iicmscw17nnx5ayjfg4e9bqm
790236
787245
2026-01-13T23:19:12Z
en>Izno
0
and add ib-ship-error in the couple of errors here that are exclusive to infobox ship
790236
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error ib-ship-error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error ib-ship-error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.net/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.fullText; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error ib-ship-error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error ib-ship-error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. ' ' .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. ' ' .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I S _ E M P T Y _ I B O X _ T E M P L A T E >----------------------------------
temporary(?) code to add Category:WPSHIPS: articles with empty infobox templates when empty infobox templates
are encountered. A template is empty when no parameters have assigned values or when the only parameter with an
assigned value is |Hide header=
when 'empty', returns the category name; nil else
]]
local function is_empty_ibox_template (args_t)
local i = 0;
for k, v in pairs (args_t) do
i = i + 1;
end
if ((1 == i) and args_t['Hide header']) or (0 == i) then
return '[[Category:WPSHIPS: articles with empty infobox templates]]';
end
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
1y85umdj1te7ht4zc91sdjg6ewv19b9
790237
790236
2026-04-03T08:35:24Z
SM7
3953
43 revisions imported from [[:en:Module:WPSHIPS_utilities]]
790236
Scribunto
text/plain
require('strict')
local get_args = require ('Module:Arguments').getArgs;
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css
local data = mw.loadData ('Module:WPSHIPS utilities/data');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
--[[--------------------------< E R R O R _ M A P _ T >--------------------------------------------------------
]]
local error_map_t = { -- [1] is error message; [2] is error category
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'};
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'},
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'},
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'},
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'},
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'},
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from message text and category in <error_map_t>. creates a help link to the category
page; categorizes only main and template namespaces.
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true
]]
local function error_msg_make (msg_idx, template, detail, no_cat, link_template_name)
local out = {};
local category;
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); --TODO: simplify?
if template then
if link_template_name then
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '}));
else
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors
end
end
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail>
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also?
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'[[', error_map_t[msg_idx][2], ']]'}));
end
return table.concat (out); -- make a big string and done
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< S I Z E O F _ S H I P _ T Y P E >----------------------------------------------
Returns the size in words of ship type. Inputs are the fragment table, the number of elements in the fragment table,
and the number of words that make up nationality.
The number of fragments (words) in a ship name dictate the possible sizes of ship type. If nationality takes one fragment,
and ship type takes four fragments, then the minimum number of fragments in a composite ship name is:
5 = 1 (nationality) + 3 (ship type) + 1 (ship name) (same as 4 fragments (words) after nationality)
This function starts at the longest possible series of fragments that might be ship type. This order is important becuase
some ship types might begin with similar fragments: 'ship' and 'ship of the line'. Starting with the least possible
series of fragments (1) would find 'ship' and make 'of the line' part of the italicized name.
Returns 0 if there is no recognizable ship type.
]]
local function sizeof_ship_type (frag, frag_len, nat_len)
local ship_type;
if 5 <= (frag_len - nat_len) then -- must have at least five fragments after nationality for four-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+4); -- four-word ship type
if data.ship_type_t[ship_type] then
return 4;
end
end
if 4 <= (frag_len - nat_len) then -- must have at least four fragments after nationality for three-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+3); -- three-word ship type
if data.ship_type_t[ship_type] then
return 3;
end
end
if 3 <= (frag_len - nat_len) then -- must have at least three fragments after nationality for two-word ship type
ship_type = table.concat (frag, ' ', nat_len+1, nat_len+2); -- two-word ship type
if data.ship_type_t[ship_type] then
return 2;
end
end
if 2 <= (frag_len - nat_len) then -- must have at least two fragments after nationality for one-word ship type
if data.ship_type_t[frag[nat_len+1]] then -- one-word ship type
return 1;
end
end
return 0; -- no recognizable ship type
end
--[[--------------------------< S I Z E O F _ N A T I O N A L I T Y >------------------------------------------
This function the size (in words) of the nationality from the fragments table. Nationality may be one or two
words that occupy the first one or two positions in the table.
Returns the number of words that identify the nationality:
1 for French or German, etc.
2 for United States;
0 when table doesn't have a recognizable nationality
]]
local function sizeof_nationality (frag, frag_len)
local nat = '';
if not data.nationality_t [frag[1]] then -- if not a one-word nationality
if 2 <= frag_len - 2 then -- must have at least two fragments after nationality for minimal ship type and name
nat = table.concat (frag, ' ', 1, 2);
if data.nationality_t [nat] then -- is it a two-word nationality?
return 2; -- yes
else
return 0; -- no
end
end
return 0; -- not one-word and not enough fragments for two-word
end
return 1; -- one-word nationality
end
--[[-------------------------< D O _ S H I P _ N A M E _ F O R M A T >-----------------------------------------
This function applies correct styling to ship and ship-class names. These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.
This function requires one argument:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional arguments to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Arguments are passed in a table.
to call this function locally:
do_ship_name_format ({['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs}) or
args = {['name=name'], ['dab']=dab, ['sclass']=sclass, ['adj']=adj, ['showerrs']=showerrs};
do_ship_name_format (args)
The function returns the formatted name or, if unable to format the name, the original name and an unformatted error message.
]]
local function do_ship_name_format (args)
local name_sans_dab; -- the ship or class name without a trailing parenthetical dab
local dab; -- the dab stripped from the name
local fragments = {}; -- a table of words that make up name_sans_dab
local ship_type; -- a word or phrase that describes a ship
local type_len; -- the number of words that describe a ship
local nat_len; -- the number of words used to specify a ship's nationality
local name = ''; -- the reassembles and formatted ship name
local error_msg = ''; -- a repository for error messages if any
-- args.name = mw.text.decode (args.name); -- replace html entities in title with their characters; doesn't work for & and & in prefix
args.name = args.name:gsub ("'", "\'"); -- replace html appostrophe with the character
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
-- args.name = args.name:gsub ("&", "&");
if args.name:match ('.+%-class%s+%a+') then -- if a ship-class
fragments = mw.text.split (args.name, '-class' ); -- split at -class
if '2' == args.sclass then -- for DISPLAYTITLE and infobox caption when class not named for a member of the class
if 'off' == args.adj then
return fragments[1] .. ' class'; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return args.name; -- nothing to do so return original unformatted name
end
if 'off' == args.adj then
return "''" .. fragments[1] .. "'' class"; -- for infobox caption do noun form <name> class (no hyphen, no ship type)
end
return "''" .. fragments[1] .. "''-class" .. fragments[2]; -- and return formatted adjectival name
end
-- not a ship class so try to format a ship name
name_sans_dab, dab = args.name:match('^(.+)%s+(%b())%s*$'); -- split name into name_sans_dab and dab
if is_set (dab) then
dab = ' ' .. dab; -- insert a space for later reassembly
else
name_sans_dab = args.name; -- because without a dab, the string.match returns nil
dab = ''; -- empty string for concatenation
end
fragments = mw.text.split (name_sans_dab, '%s' ); -- split into a table of separate words
nat_len = sizeof_nationality (fragments, #fragments); -- get the number of words in the ship's nationality
if 0 < nat_len then -- if not zero we have a valid nationality
type_len = sizeof_ship_type (fragments, #fragments, nat_len); -- get the number of words in the ship type
if 0 < type_len then -- if not zero, ship type is valid; nationality and type not italics, the rest is name
name = "''" .. table.concat (fragments, ' ', nat_len + type_len + 1) .. "''"; -- format name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the nationality or ship type or dab
end
name = table.concat (fragments, ' ', 1, nat_len + type_len) .. " " .. name; -- assemble everything but dab
else
error_msg = ' unrecognized ship type;'; -- valid nationality, invalid ship type
end
elseif data.ship_prefix_t[fragments[1]] then -- if the first fragment is a ship prefix
name = table.remove (fragments, 1); -- fetch it from the table
name = name .. " ''" .. table.concat (fragments, ' ') .. "''"; -- assemble formatted name
else
error_msg = ' no nationality or prefix;'; -- invalid nationality and first word in ship name not a valid prefix
end
if is_set (name) then -- name will be set if we were able to format it
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
if is_set (dab) then
if dab:match ('%(%u+[%- ]?%d+%)') or -- one or more uppercase letters, optional space or hyphen, one or more digits
dab:match ('%(%d+[%- ]?%u+%)') or -- one or more digits, optional space or hyphen, one or more uppercase letters
dab:match ('%(%u[%u%-]*%-%d+%)') or -- one or more uppercase letters with hyphens, a hyphen, one or more digits (e.g., T-AO-157)
dab:match ('%([12]%d%d%d%)') then -- four digits representing year in the range 1000–2999
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
-- last chance, is there a ship type in the dab?
for key, _ in pairs (data.ship_type_t) do -- spin through the ship type list and see if there is a ship type (key) in the dab
if dab:find ('%f[%a]' .. key .. '%f[^%a]') then -- avoid matches that are not whole word
name = "''" .. table.concat (fragments, ' ') .. "''"; -- format the name
if 'none' == args.dab then -- for |infobox caption=nodab
return name; -- return the formatted name without the dab
end
return name .. dab; -- return the formatted name with the dab
end
end
error_msg = error_msg .. ' no ship type in dab;';
if 'none' == args.dab then -- for |infobox caption=nodab
return table.concat (fragments, ' '), error_msg; -- return the unformatted name without the dab, and an error message
end
end
return args.name, error_msg; -- return original un-formatted name with unformatted error message if any
end
--[[-------------------------< S H I P _ N A M E _ F O R M A T >-----------------------------------------------
This function is the external interface to do_ship_name_format().
The function requires one parameter:
|name= (required): a name is required; if missing or empty, this function returns an error message (may or may not be visible depending on where it is used)
used in {{infobox ship begin}} to provide a value for {{DISPLAYTITLE:}} and to provide a value for |infobox caption=
{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}
Optional parameters to support {{infobox ship begin}}:
|dab=none – displays ship name without parenthetical disambiguator; use when |infobox caption=nodab
|sclass=2 – for ship classes only; displays class name without italics (parameter name is loosely similar to {{slcass2}} which does the same thing); use when |infobox caption=class
|adj=off – for ship classes only; displays class name as a noun (no hyphen, no ship type); use when |infobox caption=class
Other optional parameters:
|showerrs=yes – marginally useful; can display error messages if the module invocation is not buried in a template
Values from the above parameters are placed in a table and that table passed as an argument in the call to do_ship_name_format().
do_ship_name_format() returns two strings: a name and an error message. If do_ship_name_format() could format the name, it returns the formatted name and
an empty string for the error message. If it could not format the name, do_ship_name_format() returns the original name and an error message.
Formatting of the error message, in response to |showerrs=yes is the responsibility of the calling function.
]]
local function ship_name_format(frame)
local name = ''; -- destination of the formatted ship name
local error_msg = ''; -- destination of any error message
if not is_set (frame.args.name) then -- if a ship name not provided
if 'yes' == frame.args.showerrs then -- and we're supposed to show errors
error_msg = '<span style="font-size:100%; font-weight:normal" class="error ib-ship-error">Empty name</span>'; -- return an empty string error message if there is no name
end
else
name, error_msg = do_ship_name_format (frame.args); -- get formatted name and error message
if is_set (error_msg) and 'yes' == frame.args.showerrs then -- if appropriate, show error message
error_msg = '<span style="font-size:100%; font-weight:normal" class="error ib-ship-error">' .. error_msg .. '</span>';
else
error_msg = ''; -- for concatenation
end
end
return name .. error_msg; -- return name and error message
end
--[[--------------------------< H N S A >----------------------------------------------------------------------
Similar to {{navsource}}, this code supports {{hnsa}} by attempting to construct a link to a ship article at the
the Historic Nava Ships Association website.
The template has the form:
{{hnsa|<page>|<name>}}
where:
<page> is the name of the page at http://hnsa.org/hnsa-ships/<page>
<name> (optional) is the name of the ship; if left blank, the template uses the current page title; if a ship name, it is formatted
from which this code produces:
[http://hnsa.org/hnsa-ships/<page> <name>] at Historic Naval Ships Association
]]
local function hnsa (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing hsna page</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.hnsa.org/hnsa-ships/',
pframe.args[1],
'/ ',
ship_name,
'] at Historic Naval Ships Association',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< N A V S O U R C E >------------------------------------------------------------
This version of the template {{navsource}} was added as a test vehicle for do_ship_name_format().
]]
local function navsource (frame)
local pframe = frame:getParent() -- get arguments from calling template frame
local ship_name = '';
local error_msg = '';
local article_title = mw.title.getCurrentTitle().text; -- fetch the article title
if not is_set (pframe.args[1]) then
return '<span style="font-size:100%; font-weight:normal" class="error">missing navsource URLcode</span>';
end
local fmt_params = {['name']='', ['showerrs']=nil};
if is_set (pframe.args.showerrs) then -- if showerrs set in template, override showerrs in #invoke:
fmt_params.showerrs = pframe.args.showerrs; -- template value
else
fmt_params.showerrs = frame.args.showerrs; -- invoke value
end
if is_set (pframe.args[2]) then
fmt_params.name = pframe.args[2];
else
fmt_params.name = article_title; -- use article title
end
ship_name, error_msg = do_ship_name_format (fmt_params);
if is_set (error_msg) and is_set (pframe.args[2]) then -- if unable to format the name
local escaped_name = pframe.args[2]:gsub("([%(%)%.%-])", "%%%1"); -- escape some of the Lua magic characters
if pframe.args[2] == article_title or -- is name same as article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '%f[%s]') or -- is name a word or words substring of article title?
nil ~= article_title:find ('%f[%a]' .. escaped_name .. '$') then -- is name a word or words substring that ends article title?
ship_name = "''" .. pframe.args[2] .. "''"; -- non-standard 'name'; perhaps just the name without prefix and dab;
error_msg = ''; -- unset because we think we have a name
end
end
if is_set (error_msg) and 'yes' == fmt_params.showerrs then
error_msg = '<span style="font-size:100%; font-weight:normal" class="error">' .. error_msg .. '</span>';
else
error_msg = ''; -- unset so it doesn't diplay
end
local output = {
'[http://www.navsource.net/archives/',
pframe.args[1],
'.htm Photo gallery] of ',
ship_name,
' at NavSource Naval History',
error_msg,
}
return table.concat (output);
end
--[[--------------------------< _ S H I P >--------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
]]
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, template, no_cat)
local error_msg = '';
local category = '';
if not is_set (control) then
control = ''; -- if not provided, ensure that control is empty string for comparisons
elseif control:find ('%-') then -- shortcut for |link=no when using a format control parameter ...|SSBN-659|-6}} same as ...|SSBN-659|6|link=no}}
unlinked_whole = true; -- set the unlinked flag
control = control:match ('%d'); -- strip out the hyphen
end
-- dispose of error conditions straight away
if not is_set (name) then -- this is the only required parameter
error_msg = error_msg_make ('missing_name', template, '', no_cat, true);
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it
error_msg = error_msg_make ('missing_dab', template, '', no_cat, true);
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
elseif '4' == control then -- displaying only the prefix
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
elseif is_set (control) then
if ('number' ~= type (tonumber (control))) or (1 ~= control:len()) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a single-digit number 1 through 6
error_msg = error_msg_make ('invalid_control', template, control, no_cat, true);
end
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes
error_msg = error_msg_make ('missing_prefix', template, '', no_cat, true);
end
if is_set (error_msg) then
return error_msg;
end
local link_name;
local link = '';
if is_set (prefix) then
link = prefix .. ' ' .. name; -- begin assembling the article name (link) portion of the wikilink
else
link = name;
end
if is_set (dab) then
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses
end
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect
if target_object then
link = target_object.fullText; -- get the target title to avoid linking through the redirect
end
name = "''" .. name .. "''"; -- name is always italicized so do it now
if '1' == control then
link_name = dab; -- special case when displaying only the dab, don't wrap in parentheses
end
if is_set (dab) then -- for all other cases that display dab
if '5' == control then
dab = " \'\'" .. dab .. "\'\'"; -- for prefix with dab display HMS A1. italicize the dab
else
dab = ' (' .. dab .. ')'; -- except for dab-only, all others display with parentheses
end
end
if not is_set (control) then -- when control not set: prefix, name, and dab
if is_set (prefix) then
link_name = prefix .. ' ' .. name .. dab;
else
link_name = name .. dab;
end
else -- when control is not 1 or none
if '2' == control then -- name only
link_name = name;
elseif '3' == control then -- name and dab
link_name = name .. dab;
elseif '5' == control then -- prefix and dab
link_name = prefix .. dab;
elseif '6' == control then -- prefix and name
link_name = prefix .. ' ' .. name;
end
end
if '5' ~= control and'6' ~= control and is_set (control) then
unlinked_prefix = false; -- no prefix so don't try to unlink it
end
if unlinked_whole then
return link_name; -- no linking desired so done
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done
else
return '[[' .. link .. '|' .. link_name .. ']]'; -- construct the wikilink and done
end
end
--[[--------------------------< S H I P >----------------------------------------------------------------------
This is a possible replacement for the template {{ship}}. It has better error detection and handling.
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc
{{#invoke:WPSHIPS_utilities|ship|_template=<template name>}}
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}}
Parameters in the module frame are:
there are no module frame parameters
Parameters in the template frame are:
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc)
{{{2|}}} – ship's name (required)
{{{3|}}} – disambiguator (year, hull or pennant number, etc)
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship (frame) -- this version not supported from the template yet
local args_t = get_args (frame);
local prefix = args_t[1] or ''; -- fetch positional parameters into named variables for readability
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[4];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat);
end
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error
detection and handling.
This function is the externally accessible entry point for those templates
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}}
Parameters in the module frame are:
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc)
|_template= template name for error messages; optional when |prefix= same as template name
Parameters in the template frame are:
{{{1|}}} – ship's name (required)
{{{2|}}} – disambiguator (year, hull or pennant number, etc)
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed)
|wl= – when set to 'no', rendering is not wikilinked
|up= – when set to 'yes' prefix (if rendered) is not linked
]]
local function ship_prefix_templates (frame) -- this version not supported from the templates yet
local args_t = get_args (frame);
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string
local control = args_t[3];
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat);
end
--[[--------------------------< L I S T _ E R R O R >----------------------------------------------------------
Assembles an error message, the original parameter value and, if appropriate a category. The error message precedes
the existing value of the parameter. If the first non-whitespace character in the parameter is a '*', set prefix to
a '*' and sep to '\n'. For line-break lists, set prefix to empty string and sep to '<br />'.
Category is appended to the end of the returned value only for pages in article space.
Inputs:
prefix – a string of characters that precede the error message span; typically '' and '*'
message – the error message to be displayed; goes inside the span
sep – a string of characters that separates the span from the parameter value; typically '\n' and '<br />'
param_val – the unmodified parameter value
showerrs – a boolean, true to display the error message text
]]
local function list_error (prefix, message, sep, param_val, showerrs)
local err_msg = '%s<span style="font-size:100%%" class="error ib-ship-error">list error: %s ([[:Category:WPSHIPS:Infobox list errors|help]])</span>%s%s%s';
local category = '';
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space
category = '[[Category:WPSHIPS:Infobox list errors]]';
end
if true == showerrs then
return string.format (err_msg, prefix, message, sep, param_val, category); -- put it all together
else
return param_val .. category;
end
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
Mediawiki:Common.css imposes limitations on plain, unbulleted lists. The template {{plainlist}} does not render this correctly:
{{plainlist|
*Item 1
*Item 2
**Item 2a
***Item 2a1
**Item 2b
*Item 3}}
The above renders without proper indents for items marked ** and ***.
If the list is not wrapped in {{plainlist}} then the above list is rendered with bullets which is contrary to the Infobox ship usage guide.
This code translates a bulleted list into an html unordered list:
<ul style="list-style:none; margin:0;">
<li>Name 1</li>
<li>Name 2</li>
<ul style="list-style:none">
<li>Subname 2a</li>
<ul style="list-style:none">
<li>Subname 2a1</li>
</ul>
<li>Subname 2b</li>
</ul>
<li>Name 3</li>
</ul>
There are rules:
1. The parameter value must begin with a splat but may have leading and trailing whitespace.
2. Each list item after the first must begin on a new line just as is required by normal bulleted lists.
3. When adding a sublevel, the number of splats may increase by one and never more. This is illegal:
*item
***item
When any of these rules are violated, unbulleted_list() returns the original text and adds the article
to Category:WPSHIPS:Infobox list errors. Error messaging in this function is somewhat sketchy so they are
disabled. After initial adoption, better error messaging could/should be implemented.
This function receives the content of one parameter:
{{#invoke:WPSHIPS utilities|unbulleted_list|{{{param|}}}}}
]]
local function _unbulleted_list (param)
local showerrs = true; -- set to false to hide error messages
local List_item_otag = '<li style="padding-left: .4em; text-indent: -.4em;">'; -- hanging indent markup; everything moves right with padding-left; first line moved left by neg indent
if nil == param:match ('^%s*%*') then -- parameter value must begin with a splat (ignoring leading white space)
if param:match ('<[%s/]*[Bb][Rr][%s/]*>') then -- if the parameter value has a list using variants of <br /> tag
return list_error ('', '<br /> list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('<div style="clear:') then
return list_error ('', '{{clear}} list', '<br />', param, showerrs); -- return an error message with maintenance category
elseif param:match ('.+\n%*') then -- if the parameter value has text followed by an unordered list
return list_error ('', 'mixed text and list', '<br />', param, showerrs); -- return an error message with maintenance category
end
return param; -- return the parameter as is
end
local item_table = mw.text.split (mw.text.trim (param), '\n'); -- trim white space from end then make a table of bulleted items by splitting on newlines
if 1 == #item_table then -- if only one bulleted item, no need for a list
return (item_table[1]:gsub ('^%*%s*', '')); -- trim off the splat and any following white space and done
end
if item_table[1]:match ('^%*%*+') then -- if first list item uses more than one splat, that's an error
return list_error ('*', 'too many * at start of list', '\n', param, showerrs); -- return an error message with maintenance category
end
local html_table = {}; -- table to hold the html output
local level = 1; -- used to indicate when a new <ul> is required
local splats = 0; -- number of splats that start each item in the list
local item = ''; -- the item text
table.insert (html_table, '<ul style="list-style:none; margin:0;">') -- this for first <ul> tag; sets no bullets and no indent
for _,v in ipairs (item_table) do
splats, item = v:match ('(%*+)%s*(.*)'); -- split the item into splats and item text
if nil == splats then -- nil if there is an extra line between items
return list_error ('*', 'list item missing markup', '\n', param, showerrs); -- return an error message with maintenance category
elseif '' == item then
return list_error ('*', 'empty list item', '\n', param, showerrs); -- return an error message with maintenance category
elseif item:match ('^[;:]') then -- if the list item is mixed unordered list / description list markup (*:)
return list_error ('*', 'mixed list type', '\n', param, showerrs); -- return an error message with maintenance category
end
splats = splats:len(); -- change string of splats into a number indicating how many splats there are
if splats == level then -- if at the same level as previous item
table.insert (html_table, List_item_otag .. item .. '</li>');
elseif splats == level + 1 then -- number of splats can only increase by one
level = splats; -- record the new level
table.insert (html_table, '<ul style="list-style: none">'); -- add a new sublist
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item
elseif splats < level then -- from three splats to one splat for example
while splats < level do
table.insert (html_table, '</ul>'); -- close each sub <ul> until level and splats match
level = level - 1;
end
table.insert (html_table, List_item_otag .. item .. '</li>'); -- add the item
else -- jumping more than one level up – one splat to three splats for example – is an error
return list_error ('*', 'too many asterisks', '\n', param, showerrs); -- return an error message with maintenance category
end
end
while 0 < level do
table.insert (html_table, '</ul>'); -- close each <ul> until level counted down to zero
level = level - 1;
end
return table.concat (html_table, '\n'); -- return the list as a string
end
--[[--------------------------< U N B U L L E T E D _ L I S T >------------------------------------------------
external entry point
]]
local function unbulleted_list (frame)
return _unbulleted_list (frame.args[1])
end
--[=[-------------------------< _I N F O B O X _ S H I P _ F L A G >--------------------------------------------
Output of {{shipboxflag|USA}}:
[[File:Flag of the United States.svg|100x35px|alt=|link=]]
Image syntax:
[[File:Name|Type|Border|Location|Alignment|Size|link=Link|alt=Alt|Caption]]
This function standardizes the size of flag images in the infobox ship career header by simply overwriting the Size
parameter value in the Image wikilink with |100x28px. This size leave a 1px gap between the top and bottom of the flag image and
the header edge. A similar left-side gap of 2px is supplied by {{infobox ship career}}.
]=]
local function _infobox_ship_flag (image)
if image:match ('|[%s%dx]+px%s*') then -- is there a size positional parameter?
image = image:gsub('|[%s%dx]+px%s*', '%|100x28px'); -- overwrite it with |100x28px
else
return '<span style="font-size:100%" class="error ib-ship-error">malformed flag image</span>'
end
return image; -- return the modified image
end
--[=[-------------------------< I N F O B O X _ S H I P _ F L A G >--------------------------------------------
external entry point
]=]
local function infobox_ship_flag (frame)
if not is_set (frame.args[1]) then -- if |Ship flag= not set
return ''; -- return empty string
end
return _infobox_ship_flag (frame.args[1]); -- return the modified image
end
--[=[-------------------------< C I T E _ D A N F S _ T I T L E >----------------------------------------------
This function attempts to render a DANFS article title in more or less proper (per Wikipedia) format for the
template {{cite danfs}}. DANFS titles typically take one of four forms:
<ship name> <disambiguator> <hull number>
<ship name> <hull number>
<ship name> <disambiguator>
<ship name>
Here, we extract the various parts, italicize the ship name and reassemble for use by the cite danfs |title= parameter.
To call this function:
|title={{#invoke:WPSHIPS utilities|cite_danfs_title|{{{title}}}}}
]=]
local function cite_danfs_title (frame)
local name;
local disambiguator;
local hullnum;
if not is_set (frame.args[1]) then -- if |title= not set
return ''; -- return empty string
end
name, disambiguator, hullnum = frame.args[1]:match ('(.-)( [XVI]+)( %([^%)]+%))$');
if not (name and disambiguator and hullnum) then
disambiguator = ''; -- empty string for concatenation
name, hullnum = frame.args[1]:match ('(.-)( %([^%)]+%))$');
if not (name and hullnum) then
hullnum = ''; -- empty string for concatenation
name, disambiguator = frame.args[1]:match ('(.-)( [XVI]+)$');
if not (name and disambiguator) then
disambiguator = '';
name = frame.args[1]; -- just a name or something we don't recognize
end
end
end
return table.concat ({"''", name, "''", disambiguator, hullnum}); -- reassemble and done
end
--[[--------------------------< S Y N O N Y M _ C H E C K >----------------------------------------------------
support function for infoboxen functions
there are a handful of infoboxen parameters that are synonymous pairs. This function is called to see if both
of the parameters in a synonymous pair have been assigned a value. When both have assigned values, each gets an
error message appended to it. Most of the synonymous pairs are UK Emglish v US English so the variable names
<args_t> table of template parameters and values
<uk_param> UK English parameter name
<us_param> US English parameter name
<error_flag> boolean that this function sets true when both of a pair are set; controls addition of maint category
]]
local function synonym_check (args_t, uk_param, us_param, error_flag)
if args_t[uk_param] and args_t[us_param] then
args_t[uk_param] = args_t[uk_param] .. ' ' .. error_msg_make ('synonymous'); -- both are set so append error message with category
args_t[us_param] = args_t[us_param] .. ' ' .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category
return true; -- inform the calling function that it needs to emit maint category
end
return error_flag; -- no match so return unmodified <error_flag>
end
--[[--------------------------< L I N E _ I T E M S >----------------------------------------------------------
support function for infoboxen functions
This function handles all infobox ship parameters that are 'line items' (label followed by value) because all
of these sorts of parameters are rendered with exacty the same formatting.
params_t{} is a table of tables where the params_t{} keys are the template's parameter names. The params_t{}
values are sequences where [1] is an index number that defines where in the rendering the label/value pair is
positioned and [2] is the label that will be rendered when the parameter has a value.
This indexing is used because params_t{} is not a sequence and because pairs() does not necessarily return the
'next' k/v pair.
This function spins through params_t{} and writes html for parameters that have assigned values into temp_t{}
according to the 'index' value in the associated sequance table. When parameters are missing or empty, this
function writes an empty string into the associated location in lines_t{} so that lines_t{} can be concatenated
into a string value that is returned to the calling function.
args_t is the arguments table from the template frame.
]]
local function line_items (args_t, params_t)
local lines_t = {}; -- a sequence table of rendered label/value html lines; one for each key in params_t{}
for k, v in pairs (params_t) do -- k is templat e parameter name; v is a sequence table with index and associated label
local temp_t = {} -- initialize/reinitialize for next line item
if not args_t[k] then -- if no assigned value then
lines_t[v[1]] = ''; -- set to empty string for concatenation
else
table.insert (temp_t, '<tr style="vertical-align:top;"><td style="font-weight: bold">'); -- open the line item row and cell
table.insert (temp_t, v[2]); -- add parameter's label text
table.insert (temp_t, '</td><td>'); -- close that cell and open the parameter value cell
table.insert (temp_t, _unbulleted_list (args_t[k])); -- add the parameter's value; formatted as unordered list if appropriate
table.insert (temp_t, '</td></tr>\n'); -- close that cell and this row
end
lines_t[v[1]] = table.concat (temp_t); -- concatenate and put the line item in the lines sequence table at the index position
end
return table.concat (lines_t); -- make a big string of line items and done
end
--[[--------------------------< I S _ E M P T Y _ I B O X _ T E M P L A T E >----------------------------------
temporary(?) code to add Category:WPSHIPS: articles with empty infobox templates when empty infobox templates
are encountered. A template is empty when no parameters have assigned values or when the only parameter with an
assigned value is |Hide header=
when 'empty', returns the category name; nil else
]]
local function is_empty_ibox_template (args_t)
local i = 0;
for k, v in pairs (args_t) do
i = i + 1;
end
if ((1 == i) and args_t['Hide header']) or (0 == i) then
return '[[Category:WPSHIPS: articles with empty infobox templates]]';
end
end
--[[--------------------------< I N F O B O X _ S H I P _ C A R E E R >----------------------------------------
implements {{Infobox ship career}}
{{#invoke:WPSHIPS utilities|infobox_ship_career}}
]]
local function infobox_ship_career (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
if not ('title' == args_t['Hide header']) then -- |Hide header=title then no title bar
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>History</th></tr>\n');
end
if args_t['Ship country'] and args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '<span style="padding-left:1em">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</span>');
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship country'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;text-align:center;vertical-align:middle;font-size:110%;">');
table.insert (html_out_t, args_t['Ship country']);
table.insert (html_out_t, '</th></tr>\n');
elseif args_t['Ship flag'] then
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;color:inherit;padding-left:2px;">');
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag']));
table.insert (html_out_t, '</th></tr>\n');
end
end
table.insert (html_out_t, line_items (args_t, data.infobox_career_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C H A R A C T E R I S T I C S >----------------------
implements {{Infobox ship characteristics}}
{{#invoke:WPSHIPS utilities|infobox_ship_characteristics}}
]]
local function infobox_ship_characteristics (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
local error_flag = false; -- controls emission of maint category when synonymous parameters are both set
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set
error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set
error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag);
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>General characteristics');
if args_t['Header caption'] then
table.insert (html_out_t, ' ');
table.insert (html_out_t, args_t['Header caption']);
end
table.insert (html_out_t, '</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_characteristics_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I N F O B O X _ S H I P _ C L A S S _ O V E R V I E W >------------------------
implements {{Infobox ship class overview}}
{{#invoke:WPSHIPS utilities|infobox_ship_class_overview}}
]]
local function infobox_ship_class_overview (frame)
local args_t = get_args (frame); -- get a table of all parameters in the template call
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates
if err_cat then
return err_cat; -- template is empty so return the category and done
end
local html_out_t = {}; -- html table text goes here
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower();
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header
table.insert (html_out_t, '<tr><th colspan="2" ');
table.insert (html_out_t, styles.header_bar); -- style from WPMILHIST
table.insert (html_out_t, '>Class overview</th></tr>\n');
end
table.insert (html_out_t, line_items (args_t, data.infobox_class_overview_params_t)); -- add all of the rest of the template's html
--mw.logObject (table.concat (html_out_t));
return table.concat (html_out_t); -- make a big string and done
end
--[[--------------------------< I S _ P L I M S O L L _ F I L E N A M E >--------------------------------------
validate cite plimsoll |filename=<filename>
<filename> format is: YYvssss.pdf where
YY - least significant two digits of four-digit first year in a two-year range
30 -> 1930–1931
allowed values are all integers between and including 30–45
v - a single lowercase letter 'a' or 'b'
'a' -> volume I
'b' -> volume II
ssss - scan number begins with 0001
odd numbered scans have English headings
even numbered scans have French headings
{{#invoke:WPSHIPS utilities|is_plimsoll_filename|{{{filename}}}}}
]]
local function is_plimsoll_filename (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
local year, volume, scan;
if args_t[1] then -- this to avoid script errors when args_t[1] missing
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts
end
if not year then return nil end -- nil when no match so we're done
year = tonumber (year);
scan = tonumber (scan);
if (30 > year) or (45 < year) then return nil end
if not (('a' == volume) or ('b' == volume)) then return nil end
if (1 > scan) then return nil end
return true;
end
--[[--------------------------< S E T _ P L I M S O L L _ D A T E >--------------------------------------------
create two-year range from first two digits in |filename=<filename>
30 -> 1930–1931
{{#invoke:WPSHIPS utilities|set_plimsoll_date|{{{filename}}}}}
]]
local function set_plimsoll_date (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if not args_t[1] then
return nil;
end
local year = args_t[1]:match ('(%d%d)%l%d%d%d%d'); -- get the intial year
year = 1900 + tonumber (year); -- make it a four-digit year
return string.format ('%d–%d', year, year + 1); -- and then add one for the second year in the range
end
--[[--------------------------< S E T _ P L I M S O L L _ S U B T I T L E >-----------------------------------1
used in {{cite plimsoll}}
return appropriate subtitle string given |subtitle=<keyword>
{{#invoke:WPSHIPS utilities|set_plimsoll_subtitle|{{{subtitle}}}}}
]]
local function set_plimsoll_subtitle (frame)
local subtitle = get_args (frame)[1]; -- get the subtitle parameter
if not subtitle then
return nil;
end
if not data.subtitles_t[subtitle] then
return ': ' .. subtitle; -- not predefined so return whatever |subtitle= holds with leading ': '
end
return ': ' .. data.subtitles_t[subtitle]; -- return predefined subtitle with leading ': '
end
--[[--------------------------< S E T _ P L I M S O L L _ U R L >----------------------------------------------
create plimsoll url from |filename=<filename>
{{#invoke:WPSHIPS utilities|set_plimsoll_url|{{{filename}}}}}
]]
local function set_plimsoll_url (frame)
local args_t = get_args (frame); -- get a table of all parameters in the invoke
if args_t[1] then
return string.format ('https://plimsoll.southampton.gov.uk/shipdata/pdfs/%s/%s',
args_t[1]:match ('(%d%d)%l%d%d%d%d'), -- get the year path portion from <filename>
args_t[1]); -- append <filename> onto the end, and done
end
end
--[[--------------------------< S C L A S S >------------------------------------------------------------------
implements {{sclass}} and {{sclass2}}
{{#invoke:WPSHIPS utilities|sclass}}
]]
local function sclass (frame)
local args_t = get_args (frame);
local parent = frame:getParent();
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that)
local class_name = args_t[1]; -- names to make it easier to understand
local ship_type = args_t[2];
local format = args_t[3];
local ship_type_dab = args_t[4];
local class_name_dab = args_t[5];
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean
if not class_name then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'class name', no_cat);
end
if not ship_type then -- when omitted, abandon with error message
return error_msg_make ('missing', template, 'ship type', no_cat);
end
if format then
if tonumber (format) then -- if <format> has a value that is a number
format = tonumber (format); -- make it a number for comparisons
if 5 < format then -- is <format> outside of allowed range
return error_msg_make ('format', template, format, no_cat);
end
else -- <format> could not be converted to a number
return error_msg_make ('format', template, format, no_cat);
end
end
local out_t = {}; -- output goes here
table.insert (out_t, '[['); -- open the wikilink
table.insert (out_t, class_name); -- build the wikilink to the class article
table.insert (out_t, '-class ');
table.insert (out_t, ship_type); -- add ship type
if class_name_dab then -- when class article is disambiguated
table.insert (out_t, ' ('); -- add the disambiguator
table.insert (out_t, class_name_dab);
table.insert (out_t, ')');
end
table.insert (out_t, '|');
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class
table.insert (out_t, '\'\''); -- class name is italicized
table.insert (out_t, class_name);
table.insert (out_t, '\'\'');
else
table.insert (out_t, class_name); -- class name is a common attribute; plain text
end
if not format or (3 == format) then -- when format is omitted, same as format #3
table.insert (out_t, '-class]] [['); -- open ship-type wikilink
if ship_type_dab then -- when ship-type article is disambiguated
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ' ('); -- and the disambiguator
table.insert (out_t, ship_type_dab);
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and
end
table.insert (out_t, ship_type); -- add ship type
table.insert (out_t, ']]'); -- close ship-type wikilink
end
if 0 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class]]');
end
if 1 == format then -- no separate ship-type wikilink
table.insert (out_t, '-class ');
table.insert (out_t, ship_type);
table.insert (out_t, ']]');
end
if 2 == format then -- ship-type is not wikilinked
table.insert (out_t, '-class]] ');
table.insert (out_t, ship_type);
end
if 4 == format then -- noun form; no ship type
table.insert (out_t, ' class]]');
end
if 5 == format then -- class name only; no '-class' annotation
table.insert (out_t, ']]');
end
return table.concat (out_t);
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
cite_danfs_title = cite_danfs_title, -- external entry points for templates and invokes
hnsa = hnsa,
infobox_ship_career = infobox_ship_career,
infobox_ship_characteristics = infobox_ship_characteristics,
infobox_ship_class_overview = infobox_ship_class_overview,
infobox_ship_flag = infobox_ship_flag,
is_plimsoll_filename = is_plimsoll_filename,
navsource = navsource,
sclass = sclass,
set_plimsoll_subtitle = set_plimsoll_subtitle,
set_plimsoll_date = set_plimsoll_date,
set_plimsoll_url = set_plimsoll_url,
ship = ship, -- experiment
ship_prefix_templates = ship_prefix_templates, -- experiment
ship_name_format = ship_name_format,
unbulleted_list = unbulleted_list,
_infobox_ship_flag = _infobox_ship_flag, -- external entry points from another module
_ship_name_format = do_ship_name_format,
_synonym_check = synonym_check,
_unbulleted_list = _unbulleted_list,
}
1y85umdj1te7ht4zc91sdjg6ewv19b9
पार्टन (पार्टिकल फिजिक्स)
0
69520
790068
656331
2026-04-02T17:13:25Z
SM7
3953
सुधार कइल गइल
790068
wikitext
text/x-wiki
[[पार्टिकल फिजिक्स]] में '''पार्टन मॉडल''', [[हेड्रॉन]] (जइसे प्रोटोन आ न्यूट्रान) के समझावे वाला एगो मॉडल हवे, जवन [[रिचर्ड फाइनमैन]] द्वारा प्रस्तावित कइल गइल रहे। ई मॉडल खास तौर पर क्वांटम क्रोमोडायनेमिक्स (QCD) से जुड़ल प्रक्रिया आ परस्पर क्रिया (इंटरैक्शन) के दौरान, ऊर्जावान कण टक्कर (हाई-एनर्जी पार्टिकल कोलीजन) में पैदा होखे वाला विकिरण के झड़ी (पार्टन शॉवर) के समझे में मदद करेला।
{{Physics-stub}}
n4z0wzfjx0b1j4nakz5ayegc3quwob5
790069
790068
2026-04-02T17:13:45Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:पार्टिकल फिजिक्स]] जोड़ल गइल
790069
wikitext
text/x-wiki
[[पार्टिकल फिजिक्स]] में '''पार्टन मॉडल''', [[हेड्रॉन]] (जइसे प्रोटोन आ न्यूट्रान) के समझावे वाला एगो मॉडल हवे, जवन [[रिचर्ड फाइनमैन]] द्वारा प्रस्तावित कइल गइल रहे। ई मॉडल खास तौर पर क्वांटम क्रोमोडायनेमिक्स (QCD) से जुड़ल प्रक्रिया आ परस्पर क्रिया (इंटरैक्शन) के दौरान, ऊर्जावान कण टक्कर (हाई-एनर्जी पार्टिकल कोलीजन) में पैदा होखे वाला विकिरण के झड़ी (पार्टन शॉवर) के समझे में मदद करेला।
{{Physics-stub}}
[[श्रेणी:पार्टिकल फिजिक्स]]
lo2m4uy5g4tpxjlvy6abenhvns55kxa
790070
790069
2026-04-02T17:14:14Z
SM7
3953
SM7 पन्ना [[पार्टन (कण भौतिकी)]] के [[पार्टन (पार्टिकल फिजिक्स)]] पर स्थानांतरण कइलें
790069
wikitext
text/x-wiki
[[पार्टिकल फिजिक्स]] में '''पार्टन मॉडल''', [[हेड्रॉन]] (जइसे प्रोटोन आ न्यूट्रान) के समझावे वाला एगो मॉडल हवे, जवन [[रिचर्ड फाइनमैन]] द्वारा प्रस्तावित कइल गइल रहे। ई मॉडल खास तौर पर क्वांटम क्रोमोडायनेमिक्स (QCD) से जुड़ल प्रक्रिया आ परस्पर क्रिया (इंटरैक्शन) के दौरान, ऊर्जावान कण टक्कर (हाई-एनर्जी पार्टिकल कोलीजन) में पैदा होखे वाला विकिरण के झड़ी (पार्टन शॉवर) के समझे में मदद करेला।
{{Physics-stub}}
[[श्रेणी:पार्टिकल फिजिक्स]]
lo2m4uy5g4tpxjlvy6abenhvns55kxa
पिछोला झील
0
74304
790266
667516
2026-04-03T11:13:45Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790266
wikitext
text/x-wiki
{{Infobox body of water
| name = पिछोला झील
| image = Udaipur Lake India.JPG
| caption =
| image_bathymetry =
| caption_bathymetry =
| location = [[राजस्थान]]
| coords = {{coord|24.572|N|73.679|E|type:waterbody|display=inline,title}}
| lake_type = साफ पानी के झील
| inflow =
| outflow =
| catchment = {{convert|55|km2|abbr=on}}
| basin_countries = [[भारत]]
| length = {{convert|4|km|abbr=on}}
| width = {{convert|3|km|abbr=on}}
| area = {{convert|696|ha|abbr=on}}
| depth = {{convert|4.32|m|abbr=on}}
| max-depth = {{convert|8.5|m|abbr=on}}
| volume = {{convert|13.08|e6m3}}
| residence_time =
| shore =
| elevation =
| islands = जग निवास, जग मंदिर अउरी आर्सी विलास
| cities = [[उदयपुर]]
}}
'''पिछोला झील''' भारतीय राज्य [[राजस्थान]] के [[उदयपुर]] शहर में एगो बनावटी झील बाटे। एकर निर्माण 1362 में भइल आ ई साफ पानी के झील हवे। एकर नाँव एकरे बगल के गाँव पिछोला के नाँव पर रखल गइल।<ref name = Badipol>{{Cite web|url=http://www.udaipur.org.uk/lakes/pichola-lake.html|title=Pichola Lake|access-date=2020-03-29|archive-date=2020-02-19|archive-url=https://web.archive.org/web/20200219184000/http://www.udaipur.org.uk/lakes/pichola-lake.html|url-status=dead}}</ref><ref>{{Cite web|url=http://udaipur.nic.in/lake.htm |title=Lakes |url-status=dead |archiveurl=https://web.archive.org/web/20100819233456/http://udaipur.nic.in/lake.htm |archivedate=19 August 2010 }}</ref> ई उदयपुर शहर के आसपास मौजूद कई ठे झील सभ के झुंड के हिस्सा हवे जिनहन के निर्माण कई सौ साल में भइल जवना से कि शहर में पिए के पानी आ सिंचनी खातिर पानी के बेवस्था हो सके। एही झीलवे में जग मंदिर आ जग निवास नाँव के दू गो भवन दीप पर मौजूद बाड़ें जहाँ से एह झील के अलग-अलग हिस्सन के खुबसूरती के नजारा कइल जा सके ला।<ref name = Badipol/><ref name=pichola>{{Cite web|url=https://www.thepalaceonwheels.org/blog/travel-guide-lake-pichola-udaipur/|title=Lake Pichola Udaipur|url-status=dead|archiveurl=https://web.archive.org/web/20081027110153/http://www.indiasite.com/rajasthan/udaipur/lakepichola.html|archivedate=27 October 2008|df=dmy-all}}</ref>
{{clear}}
==संदर्भ==
{{Reflist|33em}}
==बाहरी कड़ी==
{{Commons category}}
*[http://www.vedantawakeup.com/lakes-in-udaipur/ All famous lakes in Udaipur Rajasthan]
*[https://web.archive.org/web/20090413154840/http://www.mewarindia.com/ency/ency.html The Mewar Encyclopedia]
[[श्रेणी:राजस्थान के भूगोल]]
[[श्रेणी:उदयपुर]]
inatdor2q98oq7g0taqqs6t8u9a39jj
केसरिया रंग
0
83514
790275
781629
2026-04-03T11:42:06Z
SM7
3953
ज्ञानसंदूक जोड़ल गइल== संदर्भ =={{Reflist|29em}}
790275
wikitext
text/x-wiki
{{for|अउरी अरथ सभ|केसरिया}}
{{infobox colour
| title=Saffron
| hex=F4C430
| source=Maerz and Paul<ref>
The colour displayed in the colour box above matches the colour called ''saffron'' in the 1930 book by Maerz and Paul ''A Dictionary of Colour'' New York:1930 McGraw-Hill; the colour ''saffron'' is displayed on page 43 Plate 10, Colour Sample K8.
</ref>
| isccname=Vivid yellow}}
'''केसरिया रंग''' ({{Lang|en|saffron}}) [[पीयर]] चाहे संतरहवा रंग के एगो किसिम हवे। ई गहिरा पीयर (डार्क पीला) होखे ला। रंग के नाँव [[केसर]] से लिहल गइल हवे जे एक किसिम के मसाला हवे आ [[केसर के पौधा]] से बनावल जाला। भारत के झंडा में तीन गो पट्टी में से सभसे ऊपरी पट्टी एही केसरिया रंग के होखे ला।
[[अंग्रेजी]] में एकरा के सैफ्रौन कलर आ [[उर्दू]] में ज़ाफ़रानी रंग कहल जाला।
[[श्रेणी:रंग]]
mu4e44xzdfui06jk5lkusr1oet5tomf
790276
790275
2026-04-03T11:42:38Z
SM7
3953
सुधार कइल गइल
790276
wikitext
text/x-wiki
{{for|अउरी अरथ सभ|केसरिया}}
{{infobox colour
| title=Saffron
| hex=F4C430
| source=Maerz and Paul<ref>
The colour displayed in the colour box above matches the colour called ''saffron'' in the 1930 book by Maerz and Paul ''A Dictionary of Colour'' New York:1930 McGraw-Hill; the colour ''saffron'' is displayed on page 43 Plate 10, Colour Sample K8.
</ref>
| isccname=Vivid yellow}}
'''केसरिया रंग''' ({{Lang|en|saffron}}) [[पीयर]] चाहे संतरहवा रंग के एगो किसिम हवे। ई गहिरा पीयर (डार्क पीला) होखे ला। रंग के नाँव [[केसर]] से लिहल गइल हवे जे एक किसिम के मसाला हवे आ [[केसर के पौधा]] से बनावल जाला। भारत के झंडा में तीन गो पट्टी में से सभसे ऊपरी पट्टी एही केसरिया रंग के होखे ला।
[[अंग्रेजी]] में एकरा के सैफ्रौन कलर आ [[उर्दू]] में ज़ाफ़रानी रंग कहल जाला।
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:रंग]]
pnnhyk3i448tdw6515jduk8m6s0wozw
790277
790276
2026-04-03T11:44:01Z
SM7
3953
ज्ञानसंदूक जोड़ल गइल
790277
wikitext
text/x-wiki
{{for|अउरी अरथ सभ|केसरिया}}
{{infobox colour
| title=Saffron
| hex=F4C430
| source=Maerz and Paul<ref>
The colour displayed in the colour box above matches the colour called ''saffron'' in the 1930 book by Maerz and Paul ''A Dictionary of Colour'' New York:1930 McGraw-Hill; the colour ''saffron'' is displayed on page 43 Plate 10, Colour Sample K8.
</ref>
| isccname=Vivid yellow}}
{{infobox colour
| title=Deep saffron<br /><small>(भगवा)</small>
| spelling=colour
| hex=FF9933
| source=
| isccname=स्ट्रौंग ऑरेंज
}}
'''केसरिया रंग''' ({{Lang|en|saffron}}) [[पीयर]] चाहे संतरहवा रंग के एगो किसिम हवे। ई गहिरा पीयर (डार्क पीला) होखे ला। रंग के नाँव [[केसर]] से लिहल गइल हवे जे एक किसिम के मसाला हवे आ [[केसर के पौधा]] से बनावल जाला। भारत के झंडा में तीन गो पट्टी में से सभसे ऊपरी पट्टी एही केसरिया रंग के होखे ला।
[[अंग्रेजी]] में एकरा के सैफ्रौन कलर आ [[उर्दू]] में ज़ाफ़रानी रंग कहल जाला।
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:रंग]]
82g7qge6jg57xgctqpvy8781szzgw6x
वैष्णो देवी मंदिर
0
84745
790098
772365
2026-04-03T05:56:17Z
SM7
3953
बिस्तार कइल गइल
790098
wikitext
text/x-wiki
'''वैष्णो देवी मंदिर''', जेकरा के '''श्री माता वैष्णो देवी मंदिर''' चाहे '''वैष्णो देवी भवन''' नाँव से भी जानल जाला, भारत के कटरा ([[रियासी जिला|जिला रियासी]], [[जम्मू अउरी काश्मीर|जम्मू-कश्मीर]]) में स्थित एगो प्रसिद्ध हिंदू मंदिर हवे। ई मंदिर [[वैष्णो देवी]] के समर्पित बा, जे देवी हिंदू लोगन के मान्यता अनुसार महाकाली, महालक्ष्मी आ महासरस्वती के संयुक्त रूप मानी जाली।
ई मंदिर त्रिकुटा पर्वत पर लगभग 5,200 फीट (1,500 मीटर) के ऊँचाई पर बाटे। ई [[जम्मू]] शहर से करीब 43 किमी आ जिला मुख्यालय [[रियासी]] कस्बा से करीब 29 किमी दूर बा। मंदिर के देखरेख आ संचालन श्री माता वैष्णो देवी श्राइन बोर्ड द्वारा कइल जाला, आ 1986 से जम्मू-कश्मीर के राज्यपाल एह बोर्ड के अध्यक्ष होखे लें। ई भारत के सबसे पॉपुलर तीरथ सब में से हवे, जहाँ हर साल लाखन के गिनती में श्रद्धालु दर्शन करे आवेलें। एगो आँकड़ा के हिसाब से 2023 में करीब 95.2 लाख तीर्थयात्री एह मंदिर में आइल रहलें।
{{clear}}
[[श्रेणी:हिंदू मंदिर]]
la1qmsznbu8gbhwddk5971osm5r8on7
790099
790098
2026-04-03T05:56:34Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:जम्मू काश्मीर में पर्यटन]] जोड़ल गइल
790099
wikitext
text/x-wiki
'''वैष्णो देवी मंदिर''', जेकरा के '''श्री माता वैष्णो देवी मंदिर''' चाहे '''वैष्णो देवी भवन''' नाँव से भी जानल जाला, भारत के कटरा ([[रियासी जिला|जिला रियासी]], [[जम्मू अउरी काश्मीर|जम्मू-कश्मीर]]) में स्थित एगो प्रसिद्ध हिंदू मंदिर हवे। ई मंदिर [[वैष्णो देवी]] के समर्पित बा, जे देवी हिंदू लोगन के मान्यता अनुसार महाकाली, महालक्ष्मी आ महासरस्वती के संयुक्त रूप मानी जाली।
ई मंदिर त्रिकुटा पर्वत पर लगभग 5,200 फीट (1,500 मीटर) के ऊँचाई पर बाटे। ई [[जम्मू]] शहर से करीब 43 किमी आ जिला मुख्यालय [[रियासी]] कस्बा से करीब 29 किमी दूर बा। मंदिर के देखरेख आ संचालन श्री माता वैष्णो देवी श्राइन बोर्ड द्वारा कइल जाला, आ 1986 से जम्मू-कश्मीर के राज्यपाल एह बोर्ड के अध्यक्ष होखे लें। ई भारत के सबसे पॉपुलर तीरथ सब में से हवे, जहाँ हर साल लाखन के गिनती में श्रद्धालु दर्शन करे आवेलें। एगो आँकड़ा के हिसाब से 2023 में करीब 95.2 लाख तीर्थयात्री एह मंदिर में आइल रहलें।
{{clear}}
[[श्रेणी:हिंदू मंदिर]]
[[श्रेणी:जम्मू काश्मीर में पर्यटन]]
p2wjs7gk9co6n9mkg7gr187mg89tcy7
790100
790099
2026-04-03T05:58:32Z
SM7
3953
[[User:SM7/stubsorter|Stubsorter]] के मदद से {{Hinduism-stub}} जोड़ल गइल।
790100
wikitext
text/x-wiki
'''वैष्णो देवी मंदिर''', जेकरा के '''श्री माता वैष्णो देवी मंदिर''' चाहे '''वैष्णो देवी भवन''' नाँव से भी जानल जाला, भारत के कटरा ([[रियासी जिला|जिला रियासी]], [[जम्मू अउरी काश्मीर|जम्मू-कश्मीर]]) में स्थित एगो प्रसिद्ध हिंदू मंदिर हवे। ई मंदिर [[वैष्णो देवी]] के समर्पित बा, जे देवी हिंदू लोगन के मान्यता अनुसार महाकाली, महालक्ष्मी आ महासरस्वती के संयुक्त रूप मानी जाली।
ई मंदिर त्रिकुटा पर्वत पर लगभग 5,200 फीट (1,500 मीटर) के ऊँचाई पर बाटे। ई [[जम्मू]] शहर से करीब 43 किमी आ जिला मुख्यालय [[रियासी]] कस्बा से करीब 29 किमी दूर बा। मंदिर के देखरेख आ संचालन श्री माता वैष्णो देवी श्राइन बोर्ड द्वारा कइल जाला, आ 1986 से जम्मू-कश्मीर के राज्यपाल एह बोर्ड के अध्यक्ष होखे लें। ई भारत के सबसे पॉपुलर तीरथ सब में से हवे, जहाँ हर साल लाखन के गिनती में श्रद्धालु दर्शन करे आवेलें। एगो आँकड़ा के हिसाब से 2023 में करीब 95.2 लाख तीर्थयात्री एह मंदिर में आइल रहलें।
{{clear}}
[[श्रेणी:हिंदू मंदिर]]
[[श्रेणी:जम्मू काश्मीर में पर्यटन]]
{{Hinduism-stub}}
qo0q25hmaii34coxmdqy5vw1ry647v0
790101
790100
2026-04-03T06:02:18Z
SM7
3953
ज्ञानसंदूक जोड़ल गइल
790101
wikitext
text/x-wiki
{{Infobox Hindu temple
| name = वैष्णो देवी मंदिर
| image = Mata Vaishno Devi Bhawan.jpg
| alt =
| caption = त्रिकुटा पहाड़ी पर मंदिर के सीन
| map_type = India Jammu and Kashmir#India
| map_relief = y
| map_caption = जम्मू-काश्मीर में लोकेशन
| coordinates = {{coord|33.0299|74.9482|type:landmark_region:IN|display=inline,title}}
| country = {{flag|भारत}}
| location = कटरा, जम्मू-काश्मीर
| district = [[रियासी जिला|रियासी]]
| locale =
| elevation_m = 1584.96
| deity = [[वैष्णो देवी]]
| festivals = [[नवरातर]], [[दिवाली]], [[नया साल]]
| architecture = गुफा में मंदिर
| temple_quantity = 4
| monument_quantity =
| inscriptions =
| temple_board = श्री माता वैष्णो देवी श्राइन बोर्ड
| year_completed = 0028 विक्रम संवत
| website = {{URL|https://www.maavaishnodevi.org/|maavaishnodevi.org}}
| mapframe = yes
| mapframe-zoom = 12
| mapframe-wikidata = yes
| state={{flagicon image|Government of Jammu and Kashmir.svg}} [[Jammu and Kashmir (union territory)|Jammu and Kashmir]]
}}
'''वैष्णो देवी मंदिर''', जेकरा के '''श्री माता वैष्णो देवी मंदिर''' चाहे '''वैष्णो देवी भवन''' नाँव से भी जानल जाला, भारत के कटरा ([[रियासी जिला|जिला रियासी]], [[जम्मू अउरी काश्मीर|जम्मू-कश्मीर]]) में स्थित एगो प्रसिद्ध हिंदू मंदिर हवे। ई मंदिर [[वैष्णो देवी]] के समर्पित बा, जे देवी हिंदू लोगन के मान्यता अनुसार महाकाली, महालक्ष्मी आ महासरस्वती के संयुक्त रूप मानी जाली।
ई मंदिर त्रिकुटा पर्वत पर लगभग 5,200 फीट (1,500 मीटर) के ऊँचाई पर बाटे। ई [[जम्मू]] शहर से करीब 43 किमी आ जिला मुख्यालय [[रियासी]] कस्बा से करीब 29 किमी दूर बा। मंदिर के देखरेख आ संचालन श्री माता वैष्णो देवी श्राइन बोर्ड द्वारा कइल जाला, आ 1986 से जम्मू-कश्मीर के राज्यपाल एह बोर्ड के अध्यक्ष होखे लें। ई भारत के सबसे पॉपुलर तीरथ सब में से हवे, जहाँ हर साल लाखन के गिनती में श्रद्धालु दर्शन करे आवेलें। एगो आँकड़ा के हिसाब से 2023 में करीब 95.2 लाख तीर्थयात्री एह मंदिर में आइल रहलें।
{{clear}}
[[श्रेणी:हिंदू मंदिर]]
[[श्रेणी:जम्मू काश्मीर में पर्यटन]]
{{Hinduism-stub}}
0n2t8a7t40agolupjyr41vadg4owavh
2022 के भोजपुरी फिलिम सभ के लिस्ट
0
87344
790077
776985
2026-04-02T20:59:51Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790077
wikitext
text/x-wiki
{{Incomplete list|date=March 2022}}
ई ओह [[भोजपुरी सिनेमा|भोजपूरी फिलिम]] सभ के लिस्ट हटे जे 2022 मे आइल चाहे आवे के बा।
== जनवरी–मार्च ==
{| class="wikitable sortable"
! colspan="2" style="width:6%;" |कहिया आइल
! style="width:20%;" |नांव
! style="width:15%;" |निर्देशक
! style="width:25%;" |अभिनेता लोग
! style="width:20%;" |बनावे वला कंपनी
! style="width:4%;" |संदर्भ
|-
! rowspan="1" style="text-align:center; background:#f7bf87; text color:#000;" |मा<br />र्च
| rowspan="1" style="text-align:center; background:#f7dfc7" |'''4'''
|''आशिक़ी''
|पराग पाटिल
|[[खेसारी लाल यादव]]
|
|<ref>{{Cite web|url=https://www.jagran.com/entertainment/bollywood-bhojpuri-film-khesari-lal-yadav-and-amrapali-dubey-romantic-movie-aashiqui-will-released-on-4th-march-22503133.html|title=इस तारीख को रिलीज होगी खेसारी लाल यादव और आम्रपाली दुबे की 'आशिकी', फिल्म में दिखेगा रोमांटिक अंदाज|website=Dainik Jagran|language=hi|access-date=2022-03-11}}</ref>
|}
== अप्रिल–जून ==
{| class="wikitable sortable"
! colspan="2" style="width:6%;" |कहिया आइल
! style="width:20%;" |नांव
! style="width:15%;" |निर्देशक
! style="width:25%;" |अभिनेता लोग
! style="width:20%;" |बनावे वला कंपनी
! style="width:4%;" |संदर्भ
|-
! rowspan="6" style="text-align:center; background:#f7bf87; text color:#000;" |म<br />ई
| rowspan="2" style="text-align:center; background:#f7dfc7" |'''6'''
|शादी हो तो ऐसी
|लाल बाबू पंडित
|{{hlist|[[खेसारी लाल यादव]]|पूजा गांगुली}}
|B4U मोशन पिक्चर्स
|
|-
|ससुरा बड़ा सतावेला
|राजकुमार आर. पांडे
|{{hlist|[[काजल राघवानी]]|गोपाल राय}}
| rowspan="2" |इंटर10 रंगीला
|<ref>{{Cite web|url=https://timesofindia.indiatimes.com/entertainment/bhojpuri/movies/news/pradeep-pandey-chintu-and-kajal-raghwanis-sasura-bada-satawela-to-release-on-this-date/articleshow/91337316.cms|title=Pradeep Pandey Chintu and Kajal Raghwani's 'Sasura Bada Satawela' to release on THIS date - Times of India|website=The Times of India|language=en|access-date=2022-05-06}}</ref>
|-
| rowspan="3" style="text-align:center; background:#f7dfc7" |'''13'''
|दुल्हनिया लंदन से लाएंगे
|रजनीश मिश्रा
|{{hlist|[[खेसारी लाल यादव]]|[[आम्रपाली दुबे]]|ग्रेस रोड्स}}
|<ref>{{Cite web|url=https://www.aajtak.in/entertainment/news/story/khesari-lal-yadav-movie-dulhaniya-london-se-layenge-release-date-13th-may-tmov-1462333-2022-05-12|title=Khesari Lal Yadav की फिल्म दुल्हनिया लंदन से लाएंगे 13 मई को होगी रिलीज|website=Aaj Tak|language=hi|access-date=2022-05-12}}</ref>
|-
|लवविवाह डॉट कॉम
|अनंजय रघुराज
|[[आम्रपाली दुबे]]
| rowspan="3" |वर्ल्डवाइड रिकॉर्ड्स भोजपुरी
| rowspan="2" |<ref>{{Cite news|url=https://www.bhaskar.com/amp/local/bihar/patna/news/box-office-clash-between-khesari-lal-yadav-chintu-pandey-and-kajal-raghavani-129800760.html|title=भोजपुरी की तीन ब्लॉकबस्टर फिल्म रिलीज:खेसारी लाल यादव, चिंटू पांडे और काजल राघवानी के बीच बॉक्स ऑफिस में टक्कर|work=Dainik Bhaskar}}</ref>
|-
|रण
|चंद्रा पंत
|[[काजल राघवानी]]
|-
| style="text-align:center; background:#f7dfc7" |'''28'''
|मेरा भारत महान
|देवेन्द्र तिवारी
|[[रवि किशन]][[पवन सिंह]]अंजना सिंह
|
|-
! rowspan="2" style="text-align:center; background:#bf87f7; text color:#000;" |जू<br />न
| style="text-align:center; background:#dfc7f7" |'''10'''
|सौदागर
|अनिल काबरा
|ऋषव कश्यप गोलू
|
|<ref>{{Cite web|url=https://www.patrika.com/lucknow-news/bhojpuri-film-saudagar-release-first-show-7587045/|title=भोजपुरी फिल्म सौदागर ने जीता दर्शकों का दिल,देखने पहुंचे अभिनेता {{!}} Bhojpuri Film Saudagar Release First Show|date=2022-06-11|website=Patrika News|language=hi-IN|access-date=2022-09-20}}</ref>
|-
| style="text-align:center; background:#dfc7f7" |'''17'''
|नरसिम्हा
|सुजीत कुमार
|प्रिंस सिंह राजपूत
निधि झा
|
|
|}
== जुलाई–सितंबर ==
{| class="wikitable sortable"
! colspan="2" style="width:6%;" |कहिया आइल
! style="width:20%;" |नांव
! style="width:15%;" |निर्देशक
! style="width:25%;" |अभिनेता लोग
! style="width:20%;" |बनावे वला कंपनी
! style="width:4%;" |संदर्भ
|-
! rowspan="1" style="text-align:center; background:#f7bf87; text color:#000;" |अ<br />ग<br />स्त
| rowspan="1" style="text-align:center; background:#f7dfc7" |'''5'''
|''राउडी इंस्पेक्टर''
|शंकर
|[[खेसारी लाल यादव]], मेघाश्री
|महानकाली मूवीज
|
|-
! rowspan="4" style="text-align:center; background:#bf87f7; text color:#000;" |सि<br />तं<br />ब<br />र
| rowspan="1" style="text-align:center; background:#dfc7f7" |'''2'''
|''डोली सजा के रखना''
|रजनीश मिश्रा
|[[खेसारी लाल यादव]], आम्रपाली दुबे
|
|<ref>{{Cite web|url=https://hindi.news18.com/news/entertainment/bhojpuri-khesari-lal-and-amrapali-dubey-dubey-starrer-doli-saja-ke-rakhna-movie-release-bhojpuri-mogi-4540397.html|title=खेसारी लाल- आम्रपाली दुबे की 'डोली सजा के रखना' हुई देशभर में रिलीज, 25 मल्टीप्लेक्स के साथ मिली इतनी स्क्रीन|date=2022-09-03|website=News18 हिंदी|language=hi|access-date=2022-09-03|archive-date=2022-09-03|archive-url=https://web.archive.org/web/20220903094416/https://hindi.news18.com/news/entertainment/bhojpuri-khesari-lal-and-amrapali-dubey-dubey-starrer-doli-saja-ke-rakhna-movie-release-bhojpuri-mogi-4540397.html|url-status=dead}}</ref>
|-
| rowspan="1" style="text-align:center; background:#dfc7f7" |'''17'''
|''साजन''
|इश्ताक सेख बंटी
|परेश लाल यादव, आम्रपाली दुबे
|
|
|-
| rowspan="1" style="text-align:center; background:#dfc7f7" |
'''23'''
|''नाच बैजू नाच''
|लाल विजय शहदेव
|[[दिनेश लाल यादव|दिनेश लाल यादव "निरहुआ"]]
|
|<ref>{{Cite web|url=https://www.prabhatkhabar.com/state/bihar/patna/bhojpuri-film-nirhua-film-nach-baiju-naach-based-on-bhikhari-thakur-launda-naach-released-skm|title=Bhojpuri Film: भिखारी ठाकुर के 'लौंडा नाच' पर बना निरहुआ का फिल्म 'नाच बैजू नाच' कल होगी रिलीज, देखें|website=Prabhat Khabar|language=hi|access-date=2022-09-23}}</ref>
|-
| rowspan="1" style="text-align:center; background:#dfc7f7" |
'''30'''
|''धर्मा''
|अरविंद चौबे
|[[पवन सिंह]],काजल राघवानी, सयाजी शिंदे
|
|
|}
== अक्टूबर–दिसंबर ==
{| class="wikitable sortable"
! colspan="2" style="width:6%;" |कहिया आइल
! style="width:20%;" |नांव
! style="width:15%;" |निर्देशक
! style="width:25%;" |अभिनेता लोग
! style="width:20%;" |बनावे वला कंपनी
! style="width:4%;" |संदर्भ
|-
! rowspan="1" style="text-align:center; background:#f7bf87; text color:#000;" |अ<br />क्टु<br />ब<br />र
| rowspan="1" style="text-align:center; background:#f7dfc7" |'''28'''
|''हमार स्वाभिमान''
|चंद्र भूषण मणि
|{{hlist|[[पवन सिंह]]|अंजना सिंह}}
|
|<ref>{{Cite web|url=https://zeenews.india.com/hindi/india/bihar-jharkhand/bhojpuri/bhojpuri-superstar-pawan-singh-upcoming-film-hamaar-swabhiman-trailer-released/1390037|title=पवन सिंह की आगामी फिल्म 'हमार स्वाभिमान' का रिलीज हुआ ट्रेलर, पर्दे पर 28 अक्टूबर को लगेगी फिल्म|website=Zee News|language=hi|access-date=2022-10-17}}</ref>
|}
== संदर्भ ==
{{Reflist}}
{{s-start}}
{{succession box
| title = [[List of Bhojpuri films|Bhojpuri films]]
| years = '''2022'''
| before = [[List of Bhojpuri films of 2021|Bhojpuri films 2021]]
| after = [[List of Bhojpuri films of 2023|Bhojpuri films 2023]]|
}}
{{s-end}}
{{Authority control}}
[[श्रेणी:भोजपुरी सिनेमा|*2022]]
4x6nk3jejmuz0y3axyjyaa05h8zp48c
790078
790077
2026-04-02T20:59:54Z
KiranBOT
38109
removed AMP tracking from URLs ([[:m:User:KiranBOT/AMP|details]]) ([[User talk:Usernamekiran|report error]]) v2.2.9s
790078
wikitext
text/x-wiki
{{Incomplete list|date=March 2022}}
ई ओह [[भोजपुरी सिनेमा|भोजपूरी फिलिम]] सभ के लिस्ट हटे जे 2022 मे आइल चाहे आवे के बा।
== जनवरी–मार्च ==
{| class="wikitable sortable"
! colspan="2" style="width:6%;" |कहिया आइल
! style="width:20%;" |नांव
! style="width:15%;" |निर्देशक
! style="width:25%;" |अभिनेता लोग
! style="width:20%;" |बनावे वला कंपनी
! style="width:4%;" |संदर्भ
|-
! rowspan="1" style="text-align:center; background:#f7bf87; text color:#000;" |मा<br />र्च
| rowspan="1" style="text-align:center; background:#f7dfc7" |'''4'''
|''आशिक़ी''
|पराग पाटिल
|[[खेसारी लाल यादव]]
|
|<ref>{{Cite web|url=https://www.jagran.com/entertainment/bollywood-bhojpuri-film-khesari-lal-yadav-and-amrapali-dubey-romantic-movie-aashiqui-will-released-on-4th-march-22503133.html|title=इस तारीख को रिलीज होगी खेसारी लाल यादव और आम्रपाली दुबे की 'आशिकी', फिल्म में दिखेगा रोमांटिक अंदाज|website=Dainik Jagran|language=hi|access-date=2022-03-11}}</ref>
|}
== अप्रिल–जून ==
{| class="wikitable sortable"
! colspan="2" style="width:6%;" |कहिया आइल
! style="width:20%;" |नांव
! style="width:15%;" |निर्देशक
! style="width:25%;" |अभिनेता लोग
! style="width:20%;" |बनावे वला कंपनी
! style="width:4%;" |संदर्भ
|-
! rowspan="6" style="text-align:center; background:#f7bf87; text color:#000;" |म<br />ई
| rowspan="2" style="text-align:center; background:#f7dfc7" |'''6'''
|शादी हो तो ऐसी
|लाल बाबू पंडित
|{{hlist|[[खेसारी लाल यादव]]|पूजा गांगुली}}
|B4U मोशन पिक्चर्स
|
|-
|ससुरा बड़ा सतावेला
|राजकुमार आर. पांडे
|{{hlist|[[काजल राघवानी]]|गोपाल राय}}
| rowspan="2" |इंटर10 रंगीला
|<ref>{{Cite web|url=https://timesofindia.indiatimes.com/entertainment/bhojpuri/movies/news/pradeep-pandey-chintu-and-kajal-raghwanis-sasura-bada-satawela-to-release-on-this-date/articleshow/91337316.cms|title=Pradeep Pandey Chintu and Kajal Raghwani's 'Sasura Bada Satawela' to release on THIS date - Times of India|website=The Times of India|language=en|access-date=2022-05-06}}</ref>
|-
| rowspan="3" style="text-align:center; background:#f7dfc7" |'''13'''
|दुल्हनिया लंदन से लाएंगे
|रजनीश मिश्रा
|{{hlist|[[खेसारी लाल यादव]]|[[आम्रपाली दुबे]]|ग्रेस रोड्स}}
|<ref>{{Cite web|url=https://www.aajtak.in/entertainment/news/story/khesari-lal-yadav-movie-dulhaniya-london-se-layenge-release-date-13th-may-tmov-1462333-2022-05-12|title=Khesari Lal Yadav की फिल्म दुल्हनिया लंदन से लाएंगे 13 मई को होगी रिलीज|website=Aaj Tak|language=hi|access-date=2022-05-12}}</ref>
|-
|लवविवाह डॉट कॉम
|अनंजय रघुराज
|[[आम्रपाली दुबे]]
| rowspan="3" |वर्ल्डवाइड रिकॉर्ड्स भोजपुरी
| rowspan="2" |<ref>{{Cite news|url=https://www.bhaskar.com/local/bihar/patna/news/box-office-clash-between-khesari-lal-yadav-chintu-pandey-and-kajal-raghavani-129800760.html|title=भोजपुरी की तीन ब्लॉकबस्टर फिल्म रिलीज:खेसारी लाल यादव, चिंटू पांडे और काजल राघवानी के बीच बॉक्स ऑफिस में टक्कर|work=Dainik Bhaskar}}</ref>
|-
|रण
|चंद्रा पंत
|[[काजल राघवानी]]
|-
| style="text-align:center; background:#f7dfc7" |'''28'''
|मेरा भारत महान
|देवेन्द्र तिवारी
|[[रवि किशन]][[पवन सिंह]]अंजना सिंह
|
|-
! rowspan="2" style="text-align:center; background:#bf87f7; text color:#000;" |जू<br />न
| style="text-align:center; background:#dfc7f7" |'''10'''
|सौदागर
|अनिल काबरा
|ऋषव कश्यप गोलू
|
|<ref>{{Cite web|url=https://www.patrika.com/lucknow-news/bhojpuri-film-saudagar-release-first-show-7587045/|title=भोजपुरी फिल्म सौदागर ने जीता दर्शकों का दिल,देखने पहुंचे अभिनेता {{!}} Bhojpuri Film Saudagar Release First Show|date=2022-06-11|website=Patrika News|language=hi-IN|access-date=2022-09-20}}</ref>
|-
| style="text-align:center; background:#dfc7f7" |'''17'''
|नरसिम्हा
|सुजीत कुमार
|प्रिंस सिंह राजपूत
निधि झा
|
|
|}
== जुलाई–सितंबर ==
{| class="wikitable sortable"
! colspan="2" style="width:6%;" |कहिया आइल
! style="width:20%;" |नांव
! style="width:15%;" |निर्देशक
! style="width:25%;" |अभिनेता लोग
! style="width:20%;" |बनावे वला कंपनी
! style="width:4%;" |संदर्भ
|-
! rowspan="1" style="text-align:center; background:#f7bf87; text color:#000;" |अ<br />ग<br />स्त
| rowspan="1" style="text-align:center; background:#f7dfc7" |'''5'''
|''राउडी इंस्पेक्टर''
|शंकर
|[[खेसारी लाल यादव]], मेघाश्री
|महानकाली मूवीज
|
|-
! rowspan="4" style="text-align:center; background:#bf87f7; text color:#000;" |सि<br />तं<br />ब<br />र
| rowspan="1" style="text-align:center; background:#dfc7f7" |'''2'''
|''डोली सजा के रखना''
|रजनीश मिश्रा
|[[खेसारी लाल यादव]], आम्रपाली दुबे
|
|<ref>{{Cite web|url=https://hindi.news18.com/news/entertainment/bhojpuri-khesari-lal-and-amrapali-dubey-dubey-starrer-doli-saja-ke-rakhna-movie-release-bhojpuri-mogi-4540397.html|title=खेसारी लाल- आम्रपाली दुबे की 'डोली सजा के रखना' हुई देशभर में रिलीज, 25 मल्टीप्लेक्स के साथ मिली इतनी स्क्रीन|date=2022-09-03|website=News18 हिंदी|language=hi|access-date=2022-09-03|archive-date=2022-09-03|archive-url=https://web.archive.org/web/20220903094416/https://hindi.news18.com/news/entertainment/bhojpuri-khesari-lal-and-amrapali-dubey-dubey-starrer-doli-saja-ke-rakhna-movie-release-bhojpuri-mogi-4540397.html|url-status=dead}}</ref>
|-
| rowspan="1" style="text-align:center; background:#dfc7f7" |'''17'''
|''साजन''
|इश्ताक सेख बंटी
|परेश लाल यादव, आम्रपाली दुबे
|
|
|-
| rowspan="1" style="text-align:center; background:#dfc7f7" |
'''23'''
|''नाच बैजू नाच''
|लाल विजय शहदेव
|[[दिनेश लाल यादव|दिनेश लाल यादव "निरहुआ"]]
|
|<ref>{{Cite web|url=https://www.prabhatkhabar.com/state/bihar/patna/bhojpuri-film-nirhua-film-nach-baiju-naach-based-on-bhikhari-thakur-launda-naach-released-skm|title=Bhojpuri Film: भिखारी ठाकुर के 'लौंडा नाच' पर बना निरहुआ का फिल्म 'नाच बैजू नाच' कल होगी रिलीज, देखें|website=Prabhat Khabar|language=hi|access-date=2022-09-23}}</ref>
|-
| rowspan="1" style="text-align:center; background:#dfc7f7" |
'''30'''
|''धर्मा''
|अरविंद चौबे
|[[पवन सिंह]],काजल राघवानी, सयाजी शिंदे
|
|
|}
== अक्टूबर–दिसंबर ==
{| class="wikitable sortable"
! colspan="2" style="width:6%;" |कहिया आइल
! style="width:20%;" |नांव
! style="width:15%;" |निर्देशक
! style="width:25%;" |अभिनेता लोग
! style="width:20%;" |बनावे वला कंपनी
! style="width:4%;" |संदर्भ
|-
! rowspan="1" style="text-align:center; background:#f7bf87; text color:#000;" |अ<br />क्टु<br />ब<br />र
| rowspan="1" style="text-align:center; background:#f7dfc7" |'''28'''
|''हमार स्वाभिमान''
|चंद्र भूषण मणि
|{{hlist|[[पवन सिंह]]|अंजना सिंह}}
|
|<ref>{{Cite web|url=https://zeenews.india.com/hindi/india/bihar-jharkhand/bhojpuri/bhojpuri-superstar-pawan-singh-upcoming-film-hamaar-swabhiman-trailer-released/1390037|title=पवन सिंह की आगामी फिल्म 'हमार स्वाभिमान' का रिलीज हुआ ट्रेलर, पर्दे पर 28 अक्टूबर को लगेगी फिल्म|website=Zee News|language=hi|access-date=2022-10-17}}</ref>
|}
== संदर्भ ==
{{Reflist}}
{{s-start}}
{{succession box
| title = [[List of Bhojpuri films|Bhojpuri films]]
| years = '''2022'''
| before = [[List of Bhojpuri films of 2021|Bhojpuri films 2021]]
| after = [[List of Bhojpuri films of 2023|Bhojpuri films 2023]]|
}}
{{s-end}}
{{Authority control}}
[[श्रेणी:भोजपुरी सिनेमा|*2022]]
nipkl8i1nqfd4bw24voso51bngqae08
आरजु राणा देउवा
0
89222
790084
782364
2026-04-02T22:57:37Z
InternetArchiveBot
25596
Rescuing 0 sources and tagging 1 as dead.) #IABot (v2.0.9.5
790084
wikitext
text/x-wiki
{{Infobox officeholder
| honorific-prefix = [[माननीय]]
| name = आरजु राणा देउवा
| native_name =
| native_name_lang = ne
| honorific-suffix = [[PhD]]
| image =
| width =
| caption = डा.आरजु देउवा राणा
| office = प्रतिनिधि सभा के सदस्य (आनुपातिक)
| constituency = Party List ([[नेपाली कांग्रेस]])
| termstart = 22 December 2022
| birth_date = {{birth date and age|1962|1|26|df=y}}
| birth_place = [[ललितपुर, नेपाल|ललितपुर]], [[नेपाल]]
| death_date = <!-- {{Death date and age|df=yes|YYYY|MM|DD|YYYY|MM|DD}} or {{Death-date and age|Month DD, YYYY|Month DD, YYYY}} (death date then birth date) -->
| death_place =
| resting_place =
| resting_place_coordinates =
| birth_name =
| citizenship =
| nationality = [[नेपाली]]
| party = [[नेपाली कांग्रेस]]
| spouse = [[शेरबहादुर देउवा]]
| partner = <!--For those with a domestic partner and not married-->
| relations =
| children =
| parents =
| residence =
| alma_mater = [[हिमाचल प्रदेश विश्वविद्यालय]], [[पंजाब विश्वविद्यालय]]
| occupation =
| profession =
| cabinet =
| committees =
| portfolio =
| religion =
| signature =
| signature_alt =
| website =
| footnotes =
| office1 = Member of the [[Legislature Parliament of Nepal|Constituent Assembly of Nepal]]
| termstart1 = 2008
| termend1 = 2017
| title =
| office2 =
| termstart2 =
}}
'''आरजु राणा देउवा''' (जनम 26 जनवरी 1962) [http://arzuranadeuba.com/profile.php] {{Webarchive|url=https://web.archive.org/web/20091016110706/http://arzuranadeuba.com/profile.php |date=2009-10-16 }} 1996 से नेपाली कांग्रेस पार्टी के नेपाली कांग्रेस पार्टी [https://www.nepalicongress.org/]{{Dead link|date=October 2024 |bot=InternetArchiveBot |fix-attempted=yes }} के सदस्य बाड़ी आ दिसंबर 2021 से पार्टी के केंद्रीय समिति के सदस्य चुनल गइल बाड़ी।
देउबा 2000 से नेपाली कांग्रेस पार्टी के अधिवेशन आ केन्द्रीय नेतृत्व मतदान समिति के सदस्य बाड़ी। दस साल (2008-2017) ले नेपाल के संविधान सभा आ संसद के सदस्य रहली। [[नेपाल के संबिधान|नेपाल के संविधान]] लिखत घरी उ महिला के अधिकार, खासकर प्रजनन अधिकार, समान नागरिकता के अधिकार, समान संपत्ति के अधिकार, महिला के खिलाफ हिंसा, आ हर स्तर पर महिला के समान आ समान राजनीतिक प्रतिनिधित्व जइसन मुद्दा के आगे बढ़वली .
संविधान मसौदा बनावे वाली समिति के सदस्य रहली आ महिला संसद सदस्य समन्वय समिति के अध्यक्ष के रूप में काम कइली। देउबा एगो जेंडर एक्टिविस्ट आ समाजसेवी हई आ नेपाल में महिला आ बच्चा से जुड़ल कई गो गैर सरकारी संगठन सभ के स्थापना कइले बाड़ी जेह में RUWDUC, <ref>{{Cite web|url=http://ruwducktm.org.np/|title=RUWDUC Kathmandu – "Unity For Women's Empowerment"|language=en-US|access-date=2020-03-06|archive-date=2020-02-13|archive-url=https://web.archive.org/web/20200213184234/http://ruwducktm.org.np/|url-status=dead}}</ref> साथी, <ref>{{Cite web|url=http://saathi.org.np/|title=Saathi – Create violence free homes and society where women and children can live a life of dignity.|language=en-US|access-date=2020-03-06}}</ref> SMNF <ref>{{Cite web|url=http://www.safemotherhood.org.np/|title=Safe Motherhood Network Federation Nepal {{!}} A Network for Advocacy, Awareness and Social Mobilization|website=www.safemotherhood.org.np|access-date=2020-03-06}}{{Dead link|date=April 2026 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> सामिल बाड़ें आ सामाजिक आ जेंडर खातिर एगो रिसर्च आधारित संस्थान सामन्टा के स्थापना कइले बाड़ी समानता के बा। ऊ [[अंतर्राष्ट्रीय प्रकृति संरक्षण संघ|आईयूसीएन]] खातिर दक्खिन आ पूरबी एशिया खातिर चुनल क्षेत्रीय पार्षद के रूप में काम कइली आ वर्तमान में नई दिल्ली में स्थित इपास आ महात्मा गांधी इंस्टीट्यूट ऑफ एजुकेशन फॉर पीस एंड सस्टेनेबल डेवलपमेंट के बोर्ड के रूप में काम करत बाड़ी।
देउबा आईयूसीएन काउंसिल के जेंडर एंड बायोडायवर्सिटी टास्क फोर्स (GBTF) के अध्यक्ष के रूप में काम कइलें आ साथ ही साथ पर्यावरण, आर्थिक आ सामाजिक नीति आयोग (CEESP) के संचालन समिति के सदस्य आ पर्यावरण पर थीम, 2016 के सह-अध्यक्ष भी रहलें। संघर्ष, आ सुरक्षा (टीईसीएस) के बारे में बतावल गइल बा। इहाँ के आईयूसीएन काउंसिल के ब्यूरो में भी काम कइले बानी। ऊ 2009 में IUCN-PATA एशिया प्रशांत सम्मेलन में मुख्य वक्ता के रूप में IUCN के प्रतिनिधित्व कइली आ 2010 में ICIMOD आ एकरे साझेदार लोग द्वारा जर्मनी के म्यूनिख में आयोजित एगो पर्वत सम्मेलन में हिमालय पर मुख्य वक्ता के रूप में भी कइली। देउबा के IUCN वर्ल्ड कंजरवेशन कांग्रेस (WCC) में दक्खिन आ पूरबी एशिया से IUCN क्षेत्रीय पार्षद के रूप में दोबारा चुनल गइल। <ref>{{Cite web|url=https://www.iucn.org/content/dr-arzu-rana-deuba-re-elected-iucn-regional-councillor|title=Dr. Arzu Rana-Deuba re-elected as IUCN Regional Councillor|date=2012-09-13|website=IUCN|language=en|access-date=2020-03-06}}{{Dead link|date=September 2023 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> इनके बिबिध अंतर्राष्ट्रीय मंच सभ में स्पीकर के रूप में आमंत्रित कइल गइल जेह में जिनेवा में मानवाधिकार परिषद, मार्च 2017 में भी <ref>{{Cite web|url=https://www.ohchr.org/Documents/HRBodies/UPR/A_HRC_34_2_EN.docx|title=Report of the Human Rights Council on its thirty-fourth session|last=|first=|date=|website=|archive-url=https://web.archive.org/web/20210702080124/https://www.ohchr.org/Documents/HRBodies/UPR/A_HRC_34_2_EN.docx|archive-date=2 July 2021|access-date=2020-03-06}}</ref>
== पढ़ाई ==
देउबा हिमाचल प्रदेश विश्वविद्यालय के सेंट बेडेस कॉलेज से स्नातक कइले बाड़ी . पंजाब विश्वविद्यालय से स्नातकोत्तर के डिग्री लेले बानी . उहाँ के पीएचडी भी कइले बानी। पंजाब विश्वविद्यालय [[भारत]] से 1990 में संगठनात्मक मनोविज्ञान में डिग्री हासिल कइले बानी . <ref>[http://www.nepalnews.com/archive/2008/oct/oct14/news10.php Arzu Deuba elected IUCN councillor ] {{Webarchive|url=https://web.archive.org/web/20081121111001/http://www.nepalnews.com/archive/2008/oct/oct14/news10.php|date=21 November 2008}}</ref>
== राजनीतिक कैरियर ==
देउबा 1996 से नेपाल के नेपाली कांग्रेस पार्टी के सदस्य बाड़ी <ref name=":0">{{Cite web|url=https://www.nepalicongress.org/|title=NepaliCongress.org- Nepali Congress Official website {{!}} Political party of Nepal|website=www.nepalicongress.org|access-date=2020-03-06}}{{Dead link|date=October 2024 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> 2000 से नेपाली कांग्रेस पार्टी के अधिवेशन आ केन्द्रीय नेतृत्व मतदान समिति के सदस्य बानी। दस साल (2008-2017) ले नेपाल के संविधान सभा आ संसद के सदस्य रहली। नेपाल के संविधान लिखत घरी महिला के अधिकार, खास तौर प प्रजनन अधिकार, समान नागरिकता के अधिकार, समान संपत्ति के अधिकार, महिला के खिलाफ हिंसा, हर स्तर प महिला के समानता अउरी समान राजनीतिक प्रतिनिधित्व जईसन मुद्दा के आगे बढ़वली।
== सामाजिक काम ==
देउबा नेपाल में महिला आ बाल मुद्दा से जुड़ल कई गो गैर सरकारी संगठन (एनजीओ) के स्थापना कइले बाड़ी, जवना में शामिल बा- साथी (1992) जवन महिला के खिलाफ हिंसा के उन्मूलन पर काम करेले; ग्रामीण महिला बिकास आ एकता केंद्र (1995) जे अइसन इलाका सभ में काम करे ला जहाँ मानव बिकास के संकेतक सभसे कम होखे; सेफ मदरहुड नेटवर्क फेडरेशन (1996) जे प्रजनन स्वास्थ्य आ अधिकार के क्षेत्र में काम करे ला; आ समानता – इंस्टीट्यूट फॉर सोशल एंड जेंडर इक्वालिटी (1997) जवन एगो रिसर्च आधारित संगठन हवे। <ref>{{Cite web|url=http://www.onlinewomeninpolitics.org/nepal/nepaleads.htm|title=OnlineWomen: Nepal|website=www.onlinewomeninpolitics.org|access-date=2020-03-06|archive-date=2017-03-28|archive-url=https://web.archive.org/web/20170328010255/http://www.onlinewomeninpolitics.org/nepal/nepaleads.htm|url-status=dead}}</ref>
== पारिवारिक जीवन ==
इनके बियाह नेपाली कांग्रेस पार्टी के पूर्व प्रधानमंत्री आ अध्यक्ष <ref name=":0"/> [[शेरबहादुर देउवा|शेर बहादुर देउबा]] से भइल बा।
== संदर्भ ==
<references group="" responsive="1"></references>
{{Authority control}}
[[श्रेणी:1962 में जनम]]
q843gzvebhyki7upfexm93chjkg68i8
मास्टर अजीज
0
89755
790072
738609
2026-04-02T17:24:24Z
SM7
3953
बिस्तार कइल गइल, संदर्भ जोड़ल/सुधारल गइल
790072
wikitext
text/x-wiki
'''मास्टर अजीज''' (5 मार्च 1910 – 1973) बिहार के [[सारन जिला|सारण जिला]] (अमनौर) के प्रसिद्ध भोजपुरी लोकगीतकार, कीर्तनिया आ स्वतंत्रता सेनानी रहलें। ऊ “भोजपुरी के दूसरा कबीर” के नाम से जानल जालन।<ref>{{cite web |last1=द्विवेदी |first1=भगवती प्रसाद |title=भोजपुरी के दोसरका कबीर रहले मास्टर अजीज, हिंदू-मुस्लिम दूनों धर्म से भइल रहे अंतिम संस्कार |url=https://hindi.news18.com/news/bhojpuri-news/master-ajeez-interesting-facts-he-was-known-as-second-kabir-of-bhojpuri-read-full-story-3713278.html |website=hindi.news18.com |publisher=news18.com |access-date=2 अप्रैल 2026 |date=27 अगस्त 2021 |url-status=live}}</ref> ऊ आपन रचना में साम्प्रदायिक सौहार्द, राम–कृष्ण के भजन-कीर्तन आ देशभक्ति के भाव के खूब सुंदर तरीका से प्रस्तुत कइलें। 1942 के भारत छोड़ो आंदोलन के दौरान उनका गीत बहुत लोकप्रिय रहल। ऊ मूल रूप से कीर्तनिया रहलें, जे गाँव-गाँव घूम के राम, कृष्ण आ शिव के कथा के साथे देशभक्ति गीत गावल करेलें। ऊ निर्गुण आ सगुण दुनो धारा के साथे लेके चले वाला कवि रहलें, आ हिंदू–मुस्लिम दुनो समाज में बराबर सम्मान पावेलें। स्वतंत्रता संग्राम के समय ऊ अपना गीतन से लोग में देशभक्ति आ राष्ट्रवाद के भावना जगवलें। आजो उनका सम्मान में उनका गीत लोक कलाकार लोग—जइसे [[चंदन तिवारी]]—द्वारा गावल जाला, आ उनका भोजपुरी भाषा आ देस खातिर कइल योगदान के याद कइल जाला।
== जिनगी ==
मास्टर अजीज के जनम कंडकुना गाँव (अमनौर, छपरा, बिहार) में भइल। 1973 में उनकर निधन भइल।
== संदर्भ ==
{{Reflist|33em}}
== बाहरी कड़ी ==
* [https://kavitakosh.org/kk/मास्टर_अजीज मास्टर अजीज], कविता कोश प।
[[श्रेणी:भोजपुरी-भाषा के कवि]]
{{Poet-stub}}
4hr98du1lhw78xw20dbnwt5tf13fpti
790073
790072
2026-04-02T17:26:45Z
SM7
3953
बाहरी कड़ी जोड़ल गइल
790073
wikitext
text/x-wiki
'''मास्टर अजीज''' (5 मार्च 1910 – 1973) बिहार के [[सारन जिला|सारण जिला]] (अमनौर) के प्रसिद्ध भोजपुरी लोकगीतकार, कीर्तनिया आ स्वतंत्रता सेनानी रहलें। ऊ “भोजपुरी के दूसरा कबीर” के नाम से जानल जालन।<ref>{{cite web |last1=द्विवेदी |first1=भगवती प्रसाद |title=भोजपुरी के दोसरका कबीर रहले मास्टर अजीज, हिंदू-मुस्लिम दूनों धर्म से भइल रहे अंतिम संस्कार |url=https://hindi.news18.com/news/bhojpuri-news/master-ajeez-interesting-facts-he-was-known-as-second-kabir-of-bhojpuri-read-full-story-3713278.html |website=hindi.news18.com |publisher=news18.com |access-date=2 अप्रैल 2026 |date=27 अगस्त 2021 |url-status=live}}</ref> ऊ आपन रचना में साम्प्रदायिक सौहार्द, राम–कृष्ण के भजन-कीर्तन आ देशभक्ति के भाव के खूब सुंदर तरीका से प्रस्तुत कइलें। 1942 के भारत छोड़ो आंदोलन के दौरान उनका गीत बहुत लोकप्रिय रहल। ऊ मूल रूप से कीर्तनिया रहलें, जे गाँव-गाँव घूम के राम, कृष्ण आ शिव के कथा के साथे देशभक्ति गीत गावल करेलें। ऊ निर्गुण आ सगुण दुनो धारा के साथे लेके चले वाला कवि रहलें, आ हिंदू–मुस्लिम दुनो समाज में बराबर सम्मान पावेलें। स्वतंत्रता संग्राम के समय ऊ अपना गीतन से लोग में देशभक्ति आ राष्ट्रवाद के भावना जगवलें। आजो उनका सम्मान में उनका गीत लोक कलाकार लोग—जइसे [[चंदन तिवारी]]—द्वारा गावल जाला, आ उनका भोजपुरी भाषा आ देस खातिर कइल योगदान के याद कइल जाला।
== जिनगी ==
मास्टर अजीज के जनम कंडकुना गाँव (अमनौर, छपरा, बिहार) में भइल। 1973 में उनकर निधन भइल।
== संदर्भ ==
{{Reflist|33em}}
== बाहरी कड़ी ==
* [https://kavitakosh.org/kk/मास्टर_अजीज मास्टर अजीज], कविता कोश प।
* [https://bhojpurisahityangan.com/wp-content/uploads/2021/08/Master-Azij-Ke-Kirtan-Bhag-1.pdf मास्टर अजीज के कीर्तन, भाग-1], भोजपुरी साहित्यांगन प।
[[श्रेणी:भोजपुरी-भाषा के कवि]]
{{Poet-stub}}
iw2hmrj4jc0rf0tivhaggd45x94njh8
790074
790073
2026-04-02T17:27:47Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:1910 में जनम]] जोड़ल गइल
790074
wikitext
text/x-wiki
'''मास्टर अजीज''' (5 मार्च 1910 – 1973) बिहार के [[सारन जिला|सारण जिला]] (अमनौर) के प्रसिद्ध भोजपुरी लोकगीतकार, कीर्तनिया आ स्वतंत्रता सेनानी रहलें। ऊ “भोजपुरी के दूसरा कबीर” के नाम से जानल जालन।<ref>{{cite web |last1=द्विवेदी |first1=भगवती प्रसाद |title=भोजपुरी के दोसरका कबीर रहले मास्टर अजीज, हिंदू-मुस्लिम दूनों धर्म से भइल रहे अंतिम संस्कार |url=https://hindi.news18.com/news/bhojpuri-news/master-ajeez-interesting-facts-he-was-known-as-second-kabir-of-bhojpuri-read-full-story-3713278.html |website=hindi.news18.com |publisher=news18.com |access-date=2 अप्रैल 2026 |date=27 अगस्त 2021 |url-status=live}}</ref> ऊ आपन रचना में साम्प्रदायिक सौहार्द, राम–कृष्ण के भजन-कीर्तन आ देशभक्ति के भाव के खूब सुंदर तरीका से प्रस्तुत कइलें। 1942 के भारत छोड़ो आंदोलन के दौरान उनका गीत बहुत लोकप्रिय रहल। ऊ मूल रूप से कीर्तनिया रहलें, जे गाँव-गाँव घूम के राम, कृष्ण आ शिव के कथा के साथे देशभक्ति गीत गावल करेलें। ऊ निर्गुण आ सगुण दुनो धारा के साथे लेके चले वाला कवि रहलें, आ हिंदू–मुस्लिम दुनो समाज में बराबर सम्मान पावेलें। स्वतंत्रता संग्राम के समय ऊ अपना गीतन से लोग में देशभक्ति आ राष्ट्रवाद के भावना जगवलें। आजो उनका सम्मान में उनका गीत लोक कलाकार लोग—जइसे [[चंदन तिवारी]]—द्वारा गावल जाला, आ उनका भोजपुरी भाषा आ देस खातिर कइल योगदान के याद कइल जाला।
== जिनगी ==
मास्टर अजीज के जनम कंडकुना गाँव (अमनौर, छपरा, बिहार) में भइल। 1973 में उनकर निधन भइल।
== संदर्भ ==
{{Reflist|33em}}
== बाहरी कड़ी ==
* [https://kavitakosh.org/kk/मास्टर_अजीज मास्टर अजीज], कविता कोश प।
* [https://bhojpurisahityangan.com/wp-content/uploads/2021/08/Master-Azij-Ke-Kirtan-Bhag-1.pdf मास्टर अजीज के कीर्तन, भाग-1], भोजपुरी साहित्यांगन प।
[[श्रेणी:भोजपुरी-भाषा के कवि]]
[[श्रेणी:1910 में जनम]]
{{Poet-stub}}
0sdnegi7h3yh7ki9jm3igfms1f2wbsr
790075
790074
2026-04-02T17:28:06Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:1973 में निधन]] जोड़ल गइल
790075
wikitext
text/x-wiki
'''मास्टर अजीज''' (5 मार्च 1910 – 1973) बिहार के [[सारन जिला|सारण जिला]] (अमनौर) के प्रसिद्ध भोजपुरी लोकगीतकार, कीर्तनिया आ स्वतंत्रता सेनानी रहलें। ऊ “भोजपुरी के दूसरा कबीर” के नाम से जानल जालन।<ref>{{cite web |last1=द्विवेदी |first1=भगवती प्रसाद |title=भोजपुरी के दोसरका कबीर रहले मास्टर अजीज, हिंदू-मुस्लिम दूनों धर्म से भइल रहे अंतिम संस्कार |url=https://hindi.news18.com/news/bhojpuri-news/master-ajeez-interesting-facts-he-was-known-as-second-kabir-of-bhojpuri-read-full-story-3713278.html |website=hindi.news18.com |publisher=news18.com |access-date=2 अप्रैल 2026 |date=27 अगस्त 2021 |url-status=live}}</ref> ऊ आपन रचना में साम्प्रदायिक सौहार्द, राम–कृष्ण के भजन-कीर्तन आ देशभक्ति के भाव के खूब सुंदर तरीका से प्रस्तुत कइलें। 1942 के भारत छोड़ो आंदोलन के दौरान उनका गीत बहुत लोकप्रिय रहल। ऊ मूल रूप से कीर्तनिया रहलें, जे गाँव-गाँव घूम के राम, कृष्ण आ शिव के कथा के साथे देशभक्ति गीत गावल करेलें। ऊ निर्गुण आ सगुण दुनो धारा के साथे लेके चले वाला कवि रहलें, आ हिंदू–मुस्लिम दुनो समाज में बराबर सम्मान पावेलें। स्वतंत्रता संग्राम के समय ऊ अपना गीतन से लोग में देशभक्ति आ राष्ट्रवाद के भावना जगवलें। आजो उनका सम्मान में उनका गीत लोक कलाकार लोग—जइसे [[चंदन तिवारी]]—द्वारा गावल जाला, आ उनका भोजपुरी भाषा आ देस खातिर कइल योगदान के याद कइल जाला।
== जिनगी ==
मास्टर अजीज के जनम कंडकुना गाँव (अमनौर, छपरा, बिहार) में भइल। 1973 में उनकर निधन भइल।
== संदर्भ ==
{{Reflist|33em}}
== बाहरी कड़ी ==
* [https://kavitakosh.org/kk/मास्टर_अजीज मास्टर अजीज], कविता कोश प।
* [https://bhojpurisahityangan.com/wp-content/uploads/2021/08/Master-Azij-Ke-Kirtan-Bhag-1.pdf मास्टर अजीज के कीर्तन, भाग-1], भोजपुरी साहित्यांगन प।
[[श्रेणी:भोजपुरी-भाषा के कवि]]
[[श्रेणी:1910 में जनम]]
[[श्रेणी:1973 में निधन]]
{{Poet-stub}}
6u8ooddc0z3f5t2iqaz8a5n7rozx8mw
दिल्ली–मुंबई एक्सप्रेसवे
0
90607
790111
784428
2026-04-03T08:11:55Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790111
wikitext
text/x-wiki
{{Infobox road
| header_type = UC
| country = IND
| name = दिल्ली–मुंबई एक्सप्रेसवे
| alternate_name =
| map = {{Maplink|frame=yes|plain=yes|frame-width=290|frame-height=300|zoom=6|frame-align=center|type=line|stroke-width=3|id= Q55609320|title=दिल्ली–मुंबई एक्सप्रेसवे}}
| map_custom = yes
| map_notes = दिल्ली–मुंबई एक्सप्रेसवे लाल रंग से देखावल गइल बा
| maint = [[भारतीय नेशनल हाइवे अथॉरिटी]] (NHAI)
| length_km = 1350
| established = 12 फरवरी 2023 ([[सोहना]]–[[दौसा]]) <br> दिसंबर 2023 (पूरा तरीका से बन जाई)<ref name="auto1">{{cite news|title=Breaking News Live: PM Modi inaugurates 246-km first phase of Delhi-Mumbai Expressway|url=https://timesofindia.indiatimes.com/india/breaking-news-live-february-12/amp_liveblog/97832803.cms|work=The Times of India|date=12 February 2023|access-date=12 February 2023|language=en}}</ref><ref name="auto">{{cite news|title=Highlights: PM Modi inaugurates first stretch of Delhi-Mumbai Expressway, to bring Delhi and Jaipur closer by 1.30 hours|url=https://www.hindustantimes.com/india-news/pm-modi-to-inaugurate-dayanand-saraswati-s-200th-birth-anniversary-celebrations-101676167010753-amp.html|work=Hindustan Times|date=12 February 2023|access-date=12 February 2023|language=en}}</ref><ref name="auto2">{{cite news|author1=Mishra, Saumya|title=Delhi-Mumbai Expressway to cut travel time by half; Rs 98,000 crore project likely to be completed by 2023 end|url=https://www.timesnownews.com/delhi/delhi-mumbai-expressway-to-cut-travel-time-by-half-rs-98000-crore-project-likely-to-start-by-2023-end-article-96880738/amp|work=Times Now|date=10 January 2023|access-date=12 February 2023|language=en}}</ref>
| direction_a = उत्तरी
| direction_b = दक्खिनी
| terminus_a = 1. DND Flyway, [[दिल्ली]] <br> 2. सोहना इलेवेटेड कॉरिडोर, [[हरियाणा]]
| junctions =
| terminus_b = 1. JNPT, [[महाराष्ट्र]] <br> 2. [[विरार]], [[महाराष्ट्र]]
| states = [[दिल्ली]], [[हरियाणा]], [[राजस्थान]], [[मध्य प्रदेश]], [[गुजरात]] आ [[महाराष्ट्र]]
| cities = [[फरीदाबाद]], [[सोहना]], [[अलवर]], [[बाँदीकुई]], [[दौसा]], [[सवाई माधोपुर]], [[कोटा, राजस्थान|कोटा]], [[रतलाम]], [[Thandla]], [[Dahod]], [[गोधरा]], [[वड़ोदरा]], [[सूरत]], [[नवसारी]], [[वापी]]
| photo =
| photo_notes = राजस्थान में एह एक्सप्रेसवे के एगो हिस्सा
}}
'''दिल्ली-मुंबई एक्सप्रेसवे''' ({{Lang|en|Delhi–Mumbai Expressway}}) 1,386 किमी लमहर आ 8-लेन चाकर (12 लेन बिस्तार जोग) [[भारत]] के राष्ट्रीय राजधानी [[नई दिल्ली]] के ओकर वित्तीय राजधानी [[मुंबई]] से जोड़े वाला निर्माणाधीन कंट्रोल्ड-एक्सेस एक्सप्रेसवे होखी।<ref>{{Cite web |date=16 September 2021 |title=The importance of Delhi-Mumbai Expressway & how it will reduce travel time to just 12 hours |url=https://english.jagran.com/lite/india/jagran-explainer-the-importance-of-delhimumbai-expressway-and-how-it-will-reduce-travel-time-to-just-12-hours-10032194 |website=Dainik Jagran |access-date=2 May 2023 |archive-date=1 February 2023 |archive-url=https://web.archive.org/web/20230201142811/https://english.jagran.com/lite/india/jagran-explainer-the-importance-of-delhimumbai-expressway-and-how-it-will-reduce-travel-time-to-just-12-hours-10032194 |url-status=dead }}</ref><ref name="update1">{{Cite web |date=24 November 2018 |title=Land acquisition complete in Haryana for Delhi–Mumbai Expressway |url=https://timesofindia.indiatimes.com/city/gurgaon/land-acquisition-complete-in-haryana-for-delhi-mumbai-expressway/articleshow/66778508.cms |website=The Times of India}}</ref><ref>{{Cite web |date=17 April 2018 |title=Govt announces plans to build Delhi-Mumbai expressway for Rs 1 lakh crore |url=https://www.hindustantimes.com/india-news/soon-new-delhi-mumbai-expressway-project-to-cost-rs-1-lakh-crore-nitin-gadkari/story-9OUM2mNyhqKFFvSXlByoPJ.html |website=Hindustan Times}}</ref><ref>{{Cite news |date=17 April 2018 |title=Land acquisition cost for new Delhi-Mumbai expressway to be lower by Rs 20k crore |work=Economic Times |url=https://www.economictimes.com/news/economy/infrastructure/land-acquisition-cost-for-new-delhi-mumbai-expressway-to-be-lower-by-rs-20k-crore/articleshow/63801529.cms}}</ref> एह प्रोजेक्ट के शिलान्यास केंद्रीय मंत्री नितिन गडकरी द्वारा 8 मार्च 2019 के [[सुषमा स्वराज]] आ [[अरुण जेटली]] के मौजूदगी में कइल गइल रहे<ref>{{Cite web |date=8 March 2019 |title=Union ministers lay foundation stones for Rs 1 lakh crore Delhi-Mumbai, Dwarka expressways |url=https://economictimes.indiatimes.com/news/economy/infrastructure/union-ministers-lay-foundation-stones-for-rs-1-lakh-crore-delhi-mumbai-dwarka-expressways/articleshow/68321954.cms?from=mdr |website=The Economic Times}}</ref> जमीन के अधिग्रहण लागत सहित कुल प्रोजेक्ट मूल्य लगभग [[भारतीय रुपिया|₹]] 1,00,000 करोड़ (~13.1 अरब अमेरिकी डॉलर) बा।<ref>{{Cite news |date=17 April 2018 |title=From Delhi to Mumbai in 12 hours flat? Expressway to be ready in 3 years |work=Business Standard |url=http://www.business-standard.com/article/current-affairs/delhi-mumbai-expressway-to-be-completed-by-2021-says-nitin-gadkari-118041700161_1.html}}</ref> एगो अतिरिक्त 31 किमी लंबा स्पर के निर्माण भी एनएचएआई द्वारा जेवर के नोएडा अंतर्राष्ट्रीय हवाई अड्डा से सेक्टर-65, [[फरीदाबाद]] तक एह एक्सप्रेसवे पर कइल जाई।<ref>{{Cite web |date=16 September 2021 |title=Jewar International Airport will be linked to Delhi-Mumbai Expressway |url=https://hindi.news18.com/amp/news/delhi-ncr/jewar-airport-will-connect-with-delhi-mumbai-expressway-at-a-cost-of-rs-2100-crore-says-nitin-gadkari-nodark-3745508.html |website=News18 |access-date=2 May 2023 |archive-date=1 February 2023 |archive-url=https://web.archive.org/web/20230201144316/https://hindi.news18.com/amp/news/delhi-ncr/jewar-airport-will-connect-with-delhi-mumbai-expressway-at-a-cost-of-rs-2100-crore-says-nitin-gadkari-nodark-3745508.html |url-status=dead }}</ref>
{{clear}}
== संदर्भ ==
{{Reflist|33em}}
[[श्रेणी:भारत के एक्सप्रेसवे]]
{{India-road-stub}}
3e0ijdpa48pkhtms59hole9qgey1vr2
790112
790111
2026-04-03T08:11:58Z
KiranBOT
38109
removed AMP tracking from URLs ([[:m:User:KiranBOT/AMP|details]]) ([[User talk:Usernamekiran|report error]]) v2.2.9s
790112
wikitext
text/x-wiki
{{Infobox road
| header_type = UC
| country = IND
| name = दिल्ली–मुंबई एक्सप्रेसवे
| alternate_name =
| map = {{Maplink|frame=yes|plain=yes|frame-width=290|frame-height=300|zoom=6|frame-align=center|type=line|stroke-width=3|id= Q55609320|title=दिल्ली–मुंबई एक्सप्रेसवे}}
| map_custom = yes
| map_notes = दिल्ली–मुंबई एक्सप्रेसवे लाल रंग से देखावल गइल बा
| maint = [[भारतीय नेशनल हाइवे अथॉरिटी]] (NHAI)
| length_km = 1350
| established = 12 फरवरी 2023 ([[सोहना]]–[[दौसा]]) <br> दिसंबर 2023 (पूरा तरीका से बन जाई)<ref name="auto1">{{cite news|title=Breaking News Live: PM Modi inaugurates 246-km first phase of Delhi-Mumbai Expressway|url=https://timesofindia.indiatimes.com/india/breaking-news-live-february-12/amp_liveblog/97832803.cms|work=The Times of India|date=12 February 2023|access-date=12 February 2023|language=en}}</ref><ref name="auto">{{cite news|title=Highlights: PM Modi inaugurates first stretch of Delhi-Mumbai Expressway, to bring Delhi and Jaipur closer by 1.30 hours|url=https://www.hindustantimes.com/india-news/pm-modi-to-inaugurate-dayanand-saraswati-s-200th-birth-anniversary-celebrations-101676167010753-amp.html|work=Hindustan Times|date=12 February 2023|access-date=12 February 2023|language=en}}</ref><ref name="auto2">{{cite news|author1=Mishra, Saumya|title=Delhi-Mumbai Expressway to cut travel time by half; Rs 98,000 crore project likely to be completed by 2023 end|url=https://www.timesnownews.com/delhi/delhi-mumbai-expressway-to-cut-travel-time-by-half-rs-98000-crore-project-likely-to-start-by-2023-end-article-96880738/amp|work=Times Now|date=10 January 2023|access-date=12 February 2023|language=en}}</ref>
| direction_a = उत्तरी
| direction_b = दक्खिनी
| terminus_a = 1. DND Flyway, [[दिल्ली]] <br> 2. सोहना इलेवेटेड कॉरिडोर, [[हरियाणा]]
| junctions =
| terminus_b = 1. JNPT, [[महाराष्ट्र]] <br> 2. [[विरार]], [[महाराष्ट्र]]
| states = [[दिल्ली]], [[हरियाणा]], [[राजस्थान]], [[मध्य प्रदेश]], [[गुजरात]] आ [[महाराष्ट्र]]
| cities = [[फरीदाबाद]], [[सोहना]], [[अलवर]], [[बाँदीकुई]], [[दौसा]], [[सवाई माधोपुर]], [[कोटा, राजस्थान|कोटा]], [[रतलाम]], [[Thandla]], [[Dahod]], [[गोधरा]], [[वड़ोदरा]], [[सूरत]], [[नवसारी]], [[वापी]]
| photo =
| photo_notes = राजस्थान में एह एक्सप्रेसवे के एगो हिस्सा
}}
'''दिल्ली-मुंबई एक्सप्रेसवे''' ({{Lang|en|Delhi–Mumbai Expressway}}) 1,386 किमी लमहर आ 8-लेन चाकर (12 लेन बिस्तार जोग) [[भारत]] के राष्ट्रीय राजधानी [[नई दिल्ली]] के ओकर वित्तीय राजधानी [[मुंबई]] से जोड़े वाला निर्माणाधीन कंट्रोल्ड-एक्सेस एक्सप्रेसवे होखी।<ref>{{Cite web |date=16 September 2021 |title=The importance of Delhi-Mumbai Expressway & how it will reduce travel time to just 12 hours |url=https://english.jagran.com/lite/india/jagran-explainer-the-importance-of-delhimumbai-expressway-and-how-it-will-reduce-travel-time-to-just-12-hours-10032194 |website=Dainik Jagran |access-date=2 May 2023 |archive-date=1 February 2023 |archive-url=https://web.archive.org/web/20230201142811/https://english.jagran.com/lite/india/jagran-explainer-the-importance-of-delhimumbai-expressway-and-how-it-will-reduce-travel-time-to-just-12-hours-10032194 |url-status=dead }}</ref><ref name="update1">{{Cite web |date=24 November 2018 |title=Land acquisition complete in Haryana for Delhi–Mumbai Expressway |url=https://timesofindia.indiatimes.com/city/gurgaon/land-acquisition-complete-in-haryana-for-delhi-mumbai-expressway/articleshow/66778508.cms |website=The Times of India}}</ref><ref>{{Cite web |date=17 April 2018 |title=Govt announces plans to build Delhi-Mumbai expressway for Rs 1 lakh crore |url=https://www.hindustantimes.com/india-news/soon-new-delhi-mumbai-expressway-project-to-cost-rs-1-lakh-crore-nitin-gadkari/story-9OUM2mNyhqKFFvSXlByoPJ.html |website=Hindustan Times}}</ref><ref>{{Cite news |date=17 April 2018 |title=Land acquisition cost for new Delhi-Mumbai expressway to be lower by Rs 20k crore |work=Economic Times |url=https://www.economictimes.com/news/economy/infrastructure/land-acquisition-cost-for-new-delhi-mumbai-expressway-to-be-lower-by-rs-20k-crore/articleshow/63801529.cms}}</ref> एह प्रोजेक्ट के शिलान्यास केंद्रीय मंत्री नितिन गडकरी द्वारा 8 मार्च 2019 के [[सुषमा स्वराज]] आ [[अरुण जेटली]] के मौजूदगी में कइल गइल रहे<ref>{{Cite web |date=8 March 2019 |title=Union ministers lay foundation stones for Rs 1 lakh crore Delhi-Mumbai, Dwarka expressways |url=https://economictimes.indiatimes.com/news/economy/infrastructure/union-ministers-lay-foundation-stones-for-rs-1-lakh-crore-delhi-mumbai-dwarka-expressways/articleshow/68321954.cms?from=mdr |website=The Economic Times}}</ref> जमीन के अधिग्रहण लागत सहित कुल प्रोजेक्ट मूल्य लगभग [[भारतीय रुपिया|₹]] 1,00,000 करोड़ (~13.1 अरब अमेरिकी डॉलर) बा।<ref>{{Cite news |date=17 April 2018 |title=From Delhi to Mumbai in 12 hours flat? Expressway to be ready in 3 years |work=Business Standard |url=http://www.business-standard.com/article/current-affairs/delhi-mumbai-expressway-to-be-completed-by-2021-says-nitin-gadkari-118041700161_1.html}}</ref> एगो अतिरिक्त 31 किमी लंबा स्पर के निर्माण भी एनएचएआई द्वारा जेवर के नोएडा अंतर्राष्ट्रीय हवाई अड्डा से सेक्टर-65, [[फरीदाबाद]] तक एह एक्सप्रेसवे पर कइल जाई।<ref>{{Cite web |date=16 September 2021 |title=Jewar International Airport will be linked to Delhi-Mumbai Expressway |url=https://hindi.news18.com/news/delhi-ncr/jewar-airport-will-connect-with-delhi-mumbai-expressway-at-a-cost-of-rs-2100-crore-says-nitin-gadkari-nodark-3745508.html |website=News18 |access-date=2 May 2023 |archive-date=1 February 2023 |archive-url=https://web.archive.org/web/20230201144316/https://hindi.news18.com/amp/news/delhi-ncr/jewar-airport-will-connect-with-delhi-mumbai-expressway-at-a-cost-of-rs-2100-crore-says-nitin-gadkari-nodark-3745508.html |url-status=dead }}</ref>
{{clear}}
== संदर्भ ==
{{Reflist|33em}}
[[श्रेणी:भारत के एक्सप्रेसवे]]
{{India-road-stub}}
1rw3u8jlok9w16vguqiuu1jk42z9ikr
आलोक धन्वा
0
91728
790085
786538
2026-04-02T23:05:46Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790085
wikitext
text/x-wiki
'''आलोक धन्वा''' (जनम 2 जुलाई 1948) [[हिंदी भाषा]] के एगो [[कवी]] बाने। धन्वा के अबतक ले एकही काव्य-संग्रह छप के आइल बाटे - ''दुनिया रोज़ बनती है'' (1998), बाकी ऊ बिबिध माध्यम सभ पर छपल अपना कबिता सभ के चलते हिंदी भाषा के प्रमुख कबी लोगन में गिनल जालें।<ref>{{cite news |last1=निश्चल |first1=ओम |title=जन्मदिन विशेषः आलोक धन्वा, कविता में वाचिक विद्रोह व प्रेम का वैभव |url=https://www.aajtak.in/literature/profile/story/alok-dhanwa-birthday-special-life-and-poems-of-a-revolutionary-hindi-poet-1092394-2020-07-02 |access-date=2 जुलाई 2023 |work=आज तक |date=2 जुलाई 2020 |language=hi}}</ref>
धन्वा के पहिली कबिता ''जनता का आदमी'' (1972) में 'वाम पत्रिका' में छपल रहे। ओही साल उनुकर दूसर कबिता ''गोली दाग़ो पोस्टर'', 'फ़िलहाल' पत्रिका में छपल। उनुकर ई कबिता बामपंथी आंदोलन में महत्व के अस्थान रखे ले।<ref>{{cite news |title=आलोक धन्वा की मशहूर कविता- 'गोली दागो पोस्टर' |url=https://hindi.news18.com/news/literature/alok-dhanwa-famous-poetry-in-hindi-goli-dago-poster-alok-dhanwa-kavita-literature-and-sahitya-6733593.html |access-date=2 जुलाई 2023 |work=News18 हिंदी |date=2 जुलाई 2023 |language=hi |archive-date=2023-07-02 |archive-url=https://web.archive.org/web/20230702192516/https://hindi.news18.com/news/literature/alok-dhanwa-famous-poetry-in-hindi-goli-dago-poster-alok-dhanwa-kavita-literature-and-sahitya-6733593.html |url-status=dead }}</ref>
आलोक धन्वा हिंदी कबितई के प्रगतिशील आंदोलन आ नई कबिता आंदोलन के कबी के रूप में जानल जालें ।
== जिनगी ==
आलोक धन्वा के जनम भारतीय राज्य [[बिहार]] के [[मुँगेर]] में 2 जुलाई 1948 के भइल।
== रचना ==
* ''दुनिया रोज़ बनती है'' (1998),<ref>{{cite web |title=Alok Dhanwa |url=https://www.goodreads.com/author/show/16872164.Alok_Dhanwa |website=goodreads.com |access-date=2 जुलाई 2023}}</ref> राजकमल प्रकाशन, नई दिल्ली
== पुरस्कार आ सम्मान ==
* नागार्जुन सम्मान
* फ़िराक गोरखपुरी सम्मान
* गिरिजा कुमार माथुर सम्मान
* भवानी प्रसाद मिश्र स्मृति सम्मान
== संदर्भ ==
{{Reflist|33em}}
== बाहरी कड़ी ==
* [https://rajkamalprakashan.com/author/alok-dhanwa लेखक परिचय: आलोक धन्वा] {{Webarchive|url=https://web.archive.org/web/20230702192517/https://rajkamalprakashan.com/author/alok-dhanwa |date=2023-07-02 }}, राजकमल प्रकाशन के वेबसाइट प।
* [https://www.hindisamay.com/content/554/1/%E0%A4%86%E0%A4%B2%E0%A5%8B%E0%A4%95%E0%A4%A7%E0%A4%A8%E0%A5%8D%E0%A4%B5%E0%A4%BE-%E0%A4%95%E0%A4%B5%E0%A4%BF%E0%A4%A4%E0%A4%BE-%E0%A4%B8%E0%A4%82%E0%A4%97%E0%A5%8D%E0%A4%B0%E0%A4%B9-%E0%A4%A6%E0%A5%81%E0%A4%A8%E0%A4%BF%E0%A4%AF%E0%A4%BE-%E0%A4%B0%E0%A5%8B%E0%A5%9B-%E0%A4%AC%E0%A4%A8%E0%A4%A4%E0%A5%80-%E0%A4%B9%E0%A5%88.cspx दुनिया रोज़ बनती है] (कुछ बीछल कबिता), हिंदी समय के वेबसाइट प।
{{poet-stub}}
[[श्रेणी:हिंदी-भाषा के कवि]]
[[श्रेणी:बिहार के लेखक]]
[[श्रेणी:जियत लोग]]
lxku5qhy8u6cytrh0i9kpe63c1knmzg
इंडिया (गठबंधन)
0
92017
790086
783815
2026-04-02T23:13:13Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790086
wikitext
text/x-wiki
{{italic title}}{{Infobox Indian political party
| party_name = इंडियन नेशनल डेवलपमेंटल इंक्लूसिव अलायंस<br>Indian National Developmental Inclusive Alliance
| abbreviation = INDIA <sup>(ऑफिशियल)</sup><br> I.N.D.I.A <sup>(बिकल्प)</sup>
| logo = INDIA Bloc.png
| colorcode = {{party color|Indian National Developmental Inclusive Alliance}}
| eci = राष्ट्रीय गठबंधन
| foundation = {{start date and age|df=y|2023|07|18}}
| predecessor = संजुक्त बिपक्ष
| merger = * [[यूनाइटेड प्रोग्रेसिव अलायंस]]
* [[वाम मोर्चा (भारत)|लेफ्ट फ्रंट]]
| ideology = [[बिग टेंट]]
| colours = {{Color box|#FF7800|border=silver}}{{Color box|#FFFFFF|border=silver}}{{Color box|#008000|border=silver}} {{small|(Official)}}<br>
{{Color box|{{party color|Indian National Developmental Inclusive Alliance}}|border=silver}} {{small|(Alternative)}}
| loksabha_seats = {{Composition bar|234|543|hex={{party color|Indian National Developmental Inclusive Alliance}}}}<ref>{{Cite news |date=2024-06-06 |title=Congress gets a toehold in Bihar after 20 years|url=https://www.daijiworld.com/index.php/news/newsDisplay?newsID=1197693 |access-date=2024-06-06 |work=Daijiworld}}</ref><ref>{{Cite news |date=2024-06-06|title=Independent MP Vishal Patil meets Rahul Gandhi, extends support to Congress|url=https://indianexpress.com/article/cities/pune/independent-mp-vishal-patil-meets-rahul-gandhi-extends-support-to-congress-9376555/|access-date=2024-06-06 |work=The Indian Express}}</ref>
| rajyasabha_seats = {{Composition bar|91|245|hex={{party color|Indian National Developmental Inclusive Alliance}}}}
| state_seats_name = राज्य बिधान सभा
| state_seats = {{Composition bar|1621|4036|hex={{party color|Indian National Developmental Inclusive Alliance}}}}
| state2_seats_name = राज्य परिषद
| state2_seats = {{Composition bar|96|423|hex={{party color|Indian National Developmental Inclusive Alliance}}}}
| no_states = {{Composition bar|9|31|hex={{party color|Indian National Developmental Inclusive Alliance}}}}
| alliance = [[इंडियन नेशनल डेवलपमेंटल इंक्लूसिव अलायंस के सदस्य पार्टी सभ के लिस्ट|26 पार्टी]]
}}
{{update}}
'''''इंडियन नेशनल डेवलपमेंटल इंक्लूसिव अलायंस''''' ({{Lang|en|Indian National Developmental Inclusive Alliance}}<ref>{{cite news |title=Which are the 26 parties in the INDIA combine, the face of Opposition unity for the 2024 Lok Sabha polls? |url=https://www.thehindu.com/news/national/which-are-the-26-parties-in-the-india-combine-the-face-of-opposition-unity-for-the-2024-lok-sabha-polls/article67115171.ece |access-date=28 जुलाई 2023 |work=द हिंदू |date=26 जुलाई 2023 |language=en-IN}}</ref>, संछेप में '''इंडिया''' (INDIA भा I.N.D.I.A) एगो बड़हन भारतीय राजनीतिक गठबंधन बा जेकर अगुआई [[भारतीय राष्ट्रीय कांग्रेस]] क रहल बा आ एम्मे 26 ठे भारतीय राजनीतिक दल सामिल बाड़ें। एकर मकसद [[2024 के भारतीय आम चुनाव]]न में [[भारतीय जनता पार्टी]] (भाजपा) के अगुआई वाला सत्ताधारी गठबंधन [[नेशनल डेमोक्रेटिक अलायंस]] (एनडीए) के हरावल आ प्रधानमंत्री [[नरेंद्र मोदी]] के सत्ता से बाहर कइल रहल।
2024 के जनरल इलेक्शन में ई गठबंधन कुल 243 सीट प जीत दर्ज कइलस आ कई राज्य सभ में ई भाजपा के अगुआई वाला एनडीए गठबंधन से बेहतर प्रदर्शन कइलस। एकरा चलते रास्ट्रीय स्तर प भाजपा के अकेल बहुमत खतम भ गइल आ एनडीए के गठबंधन आधारित सरकार बनल।
== इतिहास ==
भारतीय बिपक्षी पार्टी सभ के पहिली बइठक पटना में 23 जून 2023 के [[नीतीश कुमार]] के अध्यक्षता में [[पटना]] में भइल जवना में एगो नया गठबंधन बनावे पर सहमती बनल आ दुसरी बइठक [[बंगलौर]] में [[सोनिया गांधी]] के अध्यक्षता में भइल जेह में ई नया नाँव एकमत हो के अंकार कइल गइल।
== बिबाद ==
एह गठबंधन के गठन के बादे एकरा नाँव के ले के बिपक्षी पार्टी सभ द्वारा भारी बिबाद कइल गइल। एकरा नाँव के कानूनी बैधता आ संबिधान के उलंघन के मुद्दा प बिबाद भइल।<ref>{{cite news |last1=Sharan |first1=Vikrant Rana, Managing Partner and Shilpi Saurav |title=Can “I.N.D.I.A.” Be Registered As Name Of Political Party/ Alliance? |url=https://www.livelaw.in/law-firms/law-firm-articles-/indian-national-developmental-inclusive-alliance-the-emblems-and-names-act-india-trademark-act-representation-of-people-act-ss-rana-co-233984 |access-date=12 जून 2024 |work=www.livelaw.in |date=31 जुलाई 2023 |language=en}}</ref>
{{clear}}
== सदस्य पार्टी सभ ==
इंडिया गठबंधन में मय भारत से बिबिध किसिम के पार्टी शामिल बाड़ी स। एह गठबंधन में कुल 26 पार्टी बाड़ीं जिनहन के लिस्ट नीचे दिहल बा:<ref name="s959">{{cite news |date=22 February 2019 |title=The 26 Opposition Parties That Have Formed Mega Alliance For 2024 Polls |url=https://www.ndtv.com/india-news/the-26-opposition-parties-that-have-formed-mega-alliance-for-2024-lok-sabha-election-4217778 |url-status=live |archive-url=https://web.archive.org/web/20230720164807/https://www.ndtv.com/india-news/the-26-opposition-parties-that-have-formed-mega-alliance-for-2024-lok-sabha-election-4217778 |archive-date=20 July 2023 |access-date=18 July 2023 |publisher=NDTV}}</ref>
{|class="wikitable sortable" style="text-align:center;"
|-
!
! colspan="3" style="width:30px;" |पार्टी
! लोगो/झंडा
! style="width:170px;" |आधार
! colspan="2" style="width:30px;" |नेता
!संदर्भ
|-
! colspan="8" |'''राष्ट्रीय दल'''
!
|-
!1
|{{party color cell|Indian National Congress}}
| '''कांग्रेस'''
| [[भारतीय राष्ट्रीय कांग्रेस]]
| [[File:Indian National Congress Flag.svg|75px|centre]]
| rowspan="3" style="text-align:center;" |राष्ट्रीय दल
| [[File:The Lok Sabha Mallikarjun Kharge (cropped).jpg|90px]]
| [[मल्लिकार्जुन खड़गे]]
|<ref name=":1" /><ref name=":2" />
|-
!2
|{{party color cell|Communist Party of India (Marxist)}}
| '''माकपा'''
|[[भारतीय कम्युनिस्ट पार्टी (मार्क्सवादी)]]
|[[File:CPI-M-flag.svg|80x80px|centre]]
| [[File:Yechuri 1.JPG|90px]]
| [[सीताराम येचुरी]]
|<ref name=":6" />
|-
!3
|{{party color cell|Aam Aadmi Party}}
|'''आप'''
|[[आम आदमी पार्टी]]
|[[File:Aam Aadmi Party logo (English).svg|75px|centre]]
|[[File:Arvind Kejriwal September 02, 2017 crop.jpg|90px]]
|[[अरविंद केजरीवाल]]
|<ref name=":7" />
|-
! colspan="8" |'''क्षेत्रीय दल'''
!
|-
!4
| style="background-color:{{party color|Samajwadi Party}}; text-align: center;color:white;" |
| '''सपा'''
| [[समाजवादी पार्टी]]
| [[File:Samajwadi Party.png|75px|centre]]
| style="text-align: center;" | [[उत्तर प्रदेश]]
|
| [[अखिलेश यादव]]
|<ref name=":10" /><ref name=":11" />
|-
!5
!{{party color cell|All India Trinamool Congress}}
| '''तृणमूल'''
| [[सर्वभारतीय तृणमूल कांग्रेस|अखिल भारतीय तृणमूल कांग्रेस]]<ref name=":8">{{cite news|url=https://frontline.thehindu.com/politics/mamata-banerjee-quits-india-alliance-decides-to-go-solo/article67789273.ece|title=Mamata Banerjee’s INDIA split may be aimed at securing Trinamool’s future in West Bengal|work=Front line}}</ref><ref>{{Cite web |date=2024-02-23 |title=উত্তর প্রদেশের মতো শেষ পর্যন্ত বাংলায় হবে জোট? তৃণমূলের অবস্থান জানালেন ডেরেক |url=https://bengali.news18.com/news/kolkata/tmc-to-fight-alone-in-lok-sabha-elections-no-discussion-with-congress-announces-derek-o-brien-dmg-1521346.html |access-date=2024-04-14 |website=News18 বাংলা |language=bn |archive-date=2024-04-18 |archive-url=https://web.archive.org/web/20240418134200/https://bengali.news18.com/news/kolkata/tmc-to-fight-alone-in-lok-sabha-elections-no-discussion-with-congress-announces-derek-o-brien-dmg-1521346.html |url-status=dead }}</ref><ref>{{Cite web |title='তৃণমূল ইন্ডিয়া জোটেরই অংশ', দিল্লির মেগা মঞ্চে মমতার অবস্থান স্পষ্ট ডেরেকদের |url=https://eisamay.com/nation/trinamool-congress-is-part-of-india-alliance-derek-o-brien-says-at-india-mega-rally/articleshow/108916506.cms |access-date=2024-04-14 |website=Eisamay |language=bn}}</ref>
| [[File:All India Trinamool Congress flag (2).svg|75px|centre]]
|[[पश्चिम बंगाल]], [[मेघालय]]
| [[File:Mamata Banerjee Official Potrait.jpg|90px]]
| [[ममता बनर्जी]]
|<ref name=":12" /><ref name=":8" />
|-
!6
| style="background-color:{{party color|Dravida Munnetra Kazhagam}}; text-align: center;color:white;" |
| '''द्रमुक'''
| [[द्रविड़ मुन्नेत्र कड़गम|द्रविड़ मुनेत्र कड़गम]]
|[[File:Flag DMK.svg|75px|centre]]
| style="text-align:center;" |[[पुडुचेरी]], [[तमिल नाडु|तमिलनाडु]]
|
| [[एम॰ के॰ स्टालिन|मुथुवेल करुणानिधि स्टालिन]]
|<ref>{{Cite web |date=2024-04-12 |title=In battle for Tamil Nadu, why allies give Stalin and DMK the edge |url=https://indianexpress.com/article/political-pulse/tamil-nadu-lok-sabha-polls-stalin-dmk-9265333/ |access-date=2024-04-17 |website=The Indian Express |language=en}}</ref><ref name=":0" />
|-
!7
| style="background-color:{{party color|Shiv Sena}}; text-align: center;color:white;" |
|'''शिवसेना(यूबीटी''')
|शिव सेना (उद्धव बालासाहेब ठाकरे)
| [[File:SS(UBT) flag.png|75px|centre]]
| style="text-align: center;" |[[महाराष्ट्र]]
|[[File:The Chief Minister of Maharashtra, Shri Uddhav Thackeray calling on the Prime Minister, Shri Narendra Modi, in New Delhi on February 21, 2020 (Uddhav Thackeray) (cropped).jpg|90px]]
|[[उद्धव ठाकरे]]
|<ref name=":4" /><ref name=":3" />
|-
!8
| style="background-color:{{party color|Nationalist Congress Party (Sharadchandra Pawar)}}; text-align: center;color:white;" |
|'''राकांपा(शप)'''
|राष्ट्रवादी कांग्रेस पार्टी (शरदचंद्र पवार)
|
| style="text-align: center;" | [[महाराष्ट्र]], [[केरल]]
|[[File:The Union Minister for Agriculture and Food Processing Industries, Shri Sharad Pawar addressing at the launch of the Sahana Group’s New Marathi Channel “Jai Maharashtra”, in Mumbai on April 27, 2013 (cropped).jpg|90px]]
|[[शरद पवार]]
|<ref name=":9" />
|-
!9
| style="background:{{party color|Jharkhand Mukti Morcha}}; text-align:center; color:white;" |
|'''झामुमो'''
| [[झारखंड मुक्ति मोर्चा]]
|[[File:Jharkhand Mukti Morcha flag.svg|80x80px]]
| style="text-align: center;" | [[झारखंड]]
|[[File:The_Chief_Minister_of_Jharkhand,_Shri_Hemant_Soren_calling_on_the_Prime_Minister,_Shri_Narendra_Modi,_in_New_Delhi_on_January_11,_2020_(1)_(cropped).jpg|114x114px]]
|[[हेमंत सोरेन|हेमन्त सोरेन]]
|<ref>{{Cite web |date=2024-02-09 |title=Our party and alliance are very strong: CM Champai Soren on fight against BJP in Jharkhand |url=https://indianexpress.com/article/india/party-alliance-strong-cm-champai-soren-fight-bjp-jharkhand-9153758/ |access-date=2024-04-17 |website=The Indian Express |language=en}}</ref>
|-
!10
| style="background-color:{{party color|Rashtriya Janata Dal}}; text-align: center;color:white;" |
| '''राजद'''
|[[राष्ट्रीय जनता दल]]
|[[File:RJD Flag.svg|75px|centre]]
| style="text-align: center;" | [[बिहार]], [[झारखण्ड|झारखंड]]
|[[File:Lalu Prasad Yadav addressing the EEC - 2006 (cropped).jpg|90px]]
|[[लालू प्रसाद यादव]]
|<ref name="s959" /><ref name=":4" />
|-
!11
|{{party color cell|Communist Party of India}}
|'''भाकपा'''
|[[भारतीय कम्युनिस्ट पार्टी]]
|[[File:CPI-banner.svg|75px|centre]]
| style="text-align: center;" | [[केरल]], [[तमिल नाडु|तमिलनाडु]], [[मणिपुर]]
|[[File:D. RAJA DSC 0637.resized.JPG|90px]]
|दोरैसामी राजा
|<ref name=":8" />
|-
!12
| style="background-color:{{party color|Communist Party of India (Marxist–Leninist) Liberation}}; text-align: center;color:white;" |
|'''भाकपा-माले'''
|[[भारत की कम्युनिस्ट पार्टी (मार्क्सवादी-लेनिनवादी) लिबरेशन|भारतीय कम्युनिस्ट पार्टी (मार्क्सवादी-लेनिनवादी) लिबरेशन]]
|[[File:CPIML LIBERATION FLAG.png|75px|centre]]
| style="text-align: center;" |[[Bihar|बिहार]]
|
|[[दीपांकर भट्टाचार्य]]
|<ref name=":5" />
|-
!13
| style="background:{{party color|Jammu and Kashmir National Conference}}; text-align:center; color:white;" |
| '''जेकेएनसी'''
|जम्मू और कश्मीर नेशनल कॉन्फ्रेंस
|[[File:Flag of Jammu and Kashmir (1936-1953).svg|75px|centre]]
| style="text-align: center;" | [[जम्मू और कश्मीर]]
|[[File:Farooq Abdullah addressing at the presentation ceremony of the Cash Prizes to the best performing Regional Rural Banks and Certificates for extending loans for SPV home lighting systems during 2009-10, in New Delhi (cropped).jpg|90px]]
|[[फारूक अब्दुल्ला]]
|<ref>{{Cite web |date=2024-03-09 |title=NC will win 3 LS seats in Kashmir for INDIA bloc, alliance will grow: Farooq Abdullah |url=https://indianexpress.com/article/india/farooq-abdullah-nc-will-win-3-ls-seats-in-kashmir-for-india-bloc-9205203/ |access-date=2024-04-17 |website=The Indian Express |language=en}}</ref>
|-
!14
| style="background:#d10; text-align:center; color:white;" |
| '''वीसीके'''
|विदुथलाई चिरुथिगल काची
|[[File:Viduthalai Chiruthaigal Katchi banner.png|75px|centre]]
| style="text-align: center;" | [[तमिल नाडु|तमिलनाडु]]
|[[File:Thol Thirumavalavan.jpg|90px]]
|[[थोल. थिरुमावलवन]]
|<ref>{{Cite news |last=Bureau |first=The Hindu |date=2024-03-08 |title=Lok Sabha polls {{!}} After a slew of negotiations, VCK agrees to two seats in DMK alliance |url=https://www.thehindu.com/elections/lok-sabha/lok-sabha-polls-after-a-slew-of-negotiations-vck-agrees-to-two-seats-in-dmk-alliance/article67928318.ece |access-date=2024-04-17 |work=The Hindu |language=en-IN |issn=0971-751X}}</ref>
|-
!15
| style="background-color:{{party color|Indian Union Muslim League}}; text-align: center;color:white;" |
|'''आईयूएमएल'''
|[[इण्डियन यूनियन मुस्लिम लीग|इंडियन यूनियन मुस्लिम लीग]]
|[[File:Flag of the Indian Union Muslim League.svg|75px|centre]]
| style="text-align: center;" | [[केरल]]
|[[File:Shaik Mydeen with K. M. Kader Mohideen (cropped).jpg|90px]]
|के. एम. कादर मोहिदीन
|<ref>{{Cite news |last=Bureau |first=The Hindu |date=2023-12-10 |title=INDIA bloc is focusing only on Parliamentary elections, says IUML president Kader Mohideen |url=https://www.thehindu.com/news/cities/Coimbatore/india-bloc-is-focusing-only-on-parliamentary-elections-says-iuml-president-kader-mohideen/article67624161.ece |access-date=2024-04-17 |work=The Hindu |language=en-IN |issn=0971-751X}}</ref>
|-
!16
| style="background-color:{{party color|Revolutionary Socialist Party (India)}}; text-align: center;color:white;" |
|'''आरएसपी'''
|[[रिवोल्यूशनरी सोशलिस्ट पार्टी]]
|[[File:RSP-flag.svg|75px|centre]]
| style="text-align: center;" | [[केरल]]
|[[File:No_image_available.svg|80x80px]]
|मनोज भट्टाचार्य
|<ref name=":12" />
|-
!17
| style="background-color:{{party color|Marumalarchi Dravida Munnetra Kazhagam}}; text-align: center;color:white;" |
|'''मद्रमुक'''
|[[मरुमलार्ची द्रविड़ मुनेत्र कड़गम|मरुमलारची द्रविड़ मुनेत्र कड़गम]]
|[[File:MDMK.svg|75px|centre]]
| style="text-align: center;" | [[तमिल नाडु|तमिलनाडु]]
|[[File:Special screeing for Mr. Vaiko (cropped).JPG|90px]]
|वैयापुरी गोपालसामी
|<ref>{{Cite web |last=Livemint |date=2024-03-18 |title=INDIA seat-sharing pact finalised in TN, Congress loses Tiruchirappalli to MDMK |url=https://www.livemint.com/elections/lok-sabha-elections-2024-congress-fight-10-seats-dmk-22-tamil-nadu-puducherry-kdmk-tiruchirappalli-mdmk-11710751877998.html |access-date=2024-04-17 |website=mint |language=en}}</ref>
|-
!18
| style="background-color:{{party color|All India Forward Bloc}};" |
|'''एआईएफबी'''
|ऑल इंडिया फॉरवर्ड ब्लॉक
| [[File:AIFB Flag 2023.png|75px|centre]]
| style="text-align: center;" |[[पश्चिम बंगाल]]
|[[File:No_image_available.svg|80x80px]]
|जी देवराजन
|<ref name=":12" />
|-
!19
| style="background-color:{{party color|Kerala Congress (M)}}; text-align: center;color:white;" |
|'''केसी(एम)'''
|केरल कांग्रेस (एम)
|[[File:Kerala-Congress-flag.svg|75px|centre]]
| style="text-align: center;" | [[केरल]]
|[[File:Jose K Mani (cropped).jpg|90px]]
|[[जोस के॰ मणि|जोस के. मणि]]
|<ref>{{Cite web |date=2024-04-03 |title=Lok Sabha elections: Congress says ‘no friendly fight’ in Kerala after Rahul Gandhi's nomination from Wayanad |url=https://www.hindustantimes.com/india-news/lok-sabha-elections-congress-says-no-friendly-fight-in-kerala-after-rahul-gandhis-nomination-from-wayanad-101712151592872.html |access-date=2024-04-17 |website=Hindustan Times |language=en}}</ref>
|-
!20
|
|'''रालोपा'''
|[[राष्ट्रीय लोकतांत्रिक पार्टी]]
|[[File:Logo Rashtriya Loktantrik party.png|80x80px]]
|
|[[File:Hanuman Beniwal RLP.jpg|center|100x100px]]
|[[हनुमान बेनीवाल]]
|<ref>{{Cite news |last=Bureau |first=The Hindu |date=2024-03-16 |title=Senior RLP leader’s shift to Congress puts to rest alliance speculations in Rajasthan |url=https://www.thehindu.com/news/national/senior-rlp-leaders-shift-to-congress-puts-to-rest-alliance-speculations-in-rajasthan/article67958574.ece |access-date=2024-04-17 |work=The Hindu |language=en-IN |issn=0971-751X}}</ref><ref>{{Cite news |last=Bureau |first=The Hindu |date=2024-03-25 |title=RLP supremo Hanuman Beniwal is INDIA bloc candidate from Nagaur following alliance with Congress |url=https://www.thehindu.com/elections/lok-sabha/rlp-supremo-hanuman-beniwal-is-india-bloc-candidate-from-nagaur-following-alliance-with-congress/article67991393.ece |access-date=2024-04-17 |work=The Hindu |language=en-IN |issn=0971-751X}}</ref>
|-
!21
| style="background-color:{{party color|Kerala Congress (Jacob)}}; text-align: center;color:white;" |
|'''केसी'''
|केरल कांग्रेस
|[[File:Kerala-Congress-flag.svg|75px|centre]]
| style="text-align: center;" |[[केरल]]
|[[File:P.J Joseph (cropped).jpg|90px]]
|पी. जे. जोसेफ
|<ref>{{Cite news |last=Govind |first=Biju |date=2024-04-01 |title=With eye on vote share, mainstream parties in Kerala take lion’s share of seats |url=https://www.thehindu.com/elections/lok-sabha/with-eyes-on-vote-share-mainstream-parties-take-lions-share-of-seats/article68016572.ece |access-date=2024-04-17 |work=The Hindu |language=en-IN |issn=0971-751X}}</ref>
|-
!22
| style="background-color:{{party color|Peasants and Workers Party of India}}; text-align: center;color:white;" |
|'''पीडब्लूपीआई'''
|भारत की किसान एवं श्रमिक पार्टी
|[[File:PWPI.svg|80x80px]]
| style="text-align: center;" |[[महाराष्ट्र]]
|[[File:No_image_available.svg|80x80px]]
|जयन्त प्रभाकर पाटिल
|<ref>{{Cite web |last=Jaiswal |first=Arushi |last2=News |first2=India TV |date=2023-08-28 |title=Maharashtra: 12 parties including Raju Shetti's outfit, PWPI may join I.N.D.I.A. bloc, claim sources |url=https://www.indiatvnews.com/maharashtra/maharashtra-12-parties-including-raju-shetti-outfit-pwpi-may-join-india-bloc-opposition-alliance-mumbai-meeting-congress-shiv-sena-ncp-latest-updates-2023-08-28-889417 |access-date=2024-04-17 |website=www.indiatvnews.com |language=en}}</ref>
|-
!23
| style="background:{{party color|Jammu and Kashmir Peoples Democratic Party}}; text-align:center; color:white;" |
|'''पीडीपी'''
|[[जम्मू और कश्मीर पीपुल्स डेमोक्रेटिक पार्टी]]
|
| style="text-align: center;" |[[जम्मू और कश्मीर]]
|[[File:Mehbooba Mufti addressing a press conference in Srinagar.jpg|90px]]
|[[महबूबा मुफ़्ती|मेहबूबा मुफ्ती]]
|<ref>{{Cite news |last=Ashiq |first=Peerzada |date=2024-03-08 |title=Omar Abdullah rules out pre-poll alliance with INDIA bloc ally PDP; Mehbooba terms it ‘painful development’ |url=https://www.thehindu.com/elections/lok-sabha/omar-abdullah-rules-out-pre-poll-alliance-with-india-bloc-ally-pdp-mehbooba-terms-it-painful-development/article67928927.ece |access-date=2024-04-17 |work=The Hindu |language=en-IN |issn=0971-751X}}</ref>
|-
!24
| style="background-color:{{party color|Manithaneya Makkal Katchi}};" |
|'''एमएमके'''
|मनिथानेया मक्कल काची
|[[File:No_image_available.svg|center|80x80px]]
| style="text-align: center;" |[[तमिल नाडु|तमिलनाडु]]
|[[File:No_image_available.svg|80x80px]]
|एम. एच. जवाहिरुल्लाह
|<ref>{{Cite news |last=Bureau |first=The Hindu |date=2024-02-07 |title=MMK passes resolution to be a part of DMK alliance |url=https://www.thehindu.com/news/national/tamil-nadu/mmk-passes-resolution-to-be-a-part-of-dmk-alliance/article67822482.ece |access-date=2024-04-17 |work=The Hindu |language=en-IN |issn=0971-751X}}</ref>
|-
!25
| style="background-color:{{party color|Kongunadu Makkal Desia Katchi}}; text-align: center;color:black;" |
|'''केएमडीके'''
|कोंगुनाडु मक्कल देसिया काची
|[[File:Kmdkflag.gif|75px|centre]]
| style="text-align: center;" |[[तमिल नाडु|तमिलनाडु]]
|[[File:E R Eswaran.png|90px]]
|ई. आर. ईश्वरन
|<ref>{{Cite web |date=2024-03-23 |title=KDMK replaces Lok Sabha poll candidate over hate speech |url=https://www.hindustantimes.com/india-news/kdmk-replaces-lok-sabha-poll-candidate-over-hate-speech-101711136221680.html |access-date=2024-04-17 |website=Hindustan Times |language=en}}</ref>
|-
!26
|
|'''आर.डी.'''
|रायजोर दल
|[[File:Raijor Dal.svg|90px|centre]]
| rowspan="4" |[[असम]]
|[[File:Akhil Gogoi in Selenghat, Jorhat 2024.jpg|90px]]
|अखिल गोगोई
|<ref name=":13">{{Cite web |last=Joy |first=Shemin |title=At least 9 parties waiting to join I.N.D.I.A; 3 from Assam and 3 from UP |url=https://www.deccanherald.com/india/at-least-9-parties-waiting-to-join-india-3-from-assam-and-3-from-up-2668772 |access-date=2024-04-17 |website=Deccan Herald |language=en}}</ref>
|-
!27
|
|'''एजेपी'''
|असम जातीय परिषद
|[[File:AJP FLAG.jpg|90px|centre]]
|[[File:No_image_available.svg|80x80px]]
|लुरिनज्योति गोगोई
|<ref name=":13" />
|-
!28
|
|'''एजीएम'''
|आंचलिक गण मोर्चा
|[[File:No_image_available.svg|center|80x80px]]
|[[File:No_image_available.svg|80x80px]]
|अजीत कुमार भुइयां
|<ref name=":13" />
|-
!29
|
|'''एपीएचएलसी'''
|ऑल पार्टी हिल लीडर्स कॉन्फ्रेंस
|[[File:No_image_available.svg|center|80x80px]]
|[[File:No_image_available.svg|80x80px]]
|जोनास इंगती कथार (जेआई कथार)
|<ref name=":13" />
|-
!30
|
|'''वीबीए'''
|[[वंचित बहुजन आघाड़ी|वंचित बहुजन आघाडी]]
|[[File:VBA party.jpg|80px|centre]]
|[[महाराष्ट्र]]
|
|[[प्रकाश आम्बेडकर|प्रकाश यशवन्त अम्बेडकर]]
|<ref>{{Cite news |date=2024-01-06 |title=Including VBA in alliance will help prevent anti-NDA votes split: Cong |url=https://timesofindia.indiatimes.com/city/nashik/including-vba-in-alliance-will-help-prevent-anti-nda-votes-split-cong/articleshow/106587986.cms |access-date=2024-04-17 |work=The Times of India |issn=0971-8257}}</ref>
|-
!31
|
|'''जीएफपी'''
|गोवा फॉरवर्ड पार्टी
|[[File:Goa Forward Party Flag.jpg|80px|centre]]
|[[Goa|गोवा]]
|[[File:No_image_available.svg|80x80px]]
|[[विजय सरदेसाई]]
|<ref>{{Cite news |date=2024-03-07 |title=Cong meets allies, to finalise names for polls next week |url=https://timesofindia.indiatimes.com/city/goa/cong-meets-allies-to-finalise-names-for-polls-next-week/articleshow/108276920.cms |access-date=2024-04-17 |work=The Times of India |issn=0971-8257}}</ref>
|-
!32
|
|'''बीजीपीएम'''
|भारतीय गोरखा प्रजातांत्रिक मोर्चा
|[[File:No_image_available.svg|center|80x80px]]
|[[पश्चिम बंगाल]]
|[[File:No_image_available.svg|80x80px]]
|अनित थापा
|<ref>{{Cite web |date=2023-07-12 |title=In Hills, TMC ally BGPM steals a march over BJP-backed alliance |url=https://indianexpress.com/article/cities/kolkata/in-hills-tmc-ally-bgpm-steals-a-march-over-bjp-backed-alliance-8828683/ |access-date=2024-04-17 |website=The Indian Express |language=en}}</ref>
|-
!33
|
|'''हपा'''
|हाम्रो पार्टी
|[[File:Hamro_Party_Flag.jpg|center|80x80px]]
|[[पश्चिम बंगाल]]
|[[File:No_image_available.svg|80x80px]]
|अजॉय एडवर्ड्स
|<ref>{{Cite web |last=SNS |date=2024-03-29 |title=Darjeeling-based Hamro Party joins INDIA-alliance |url=https://www.thestatesman.com/bengal/darjeeling-based-hamro-party-joins-india-alliance-1503284724.html |access-date=2024-04-17 |website=The Statesman |language=en}}</ref>
|-
!34
|
|'''एमएनएम'''
|मक्कल नीधि मय्यम
|[[File:Makkal Needhi Maiam Party Logo.png|80px|centre]]
|[[तमिल नाडु|तमिलनाडु]]
|[[File:Kamal Haasan at Promotions of 'Vishwaroop' with Videocon (03).jpg|80px]]
|[[कमल हासन]]
|<ref>{{Cite web |date=2024-03-09 |title=Kamal Haasan announces alliance with MK Stalin's DMK, but there's a twist |url=https://www.hindustantimes.com/india-news/kamal-haasan-announces-alliance-with-mk-stalins-dmk-but-theres-a-twist-101709970681543.html |access-date=2024-04-17 |website=Hindustan Times |language=en}}</ref>
|-
!35
|
|'''जादअ'''
|जातीय दल असम
|[[File:No_image_available.svg|center|80x80px]]
|[[Assam|असम]]
|[[File:No_image_available.svg|80x80px]]
|एमजी हजारिका
|<ref>{{Cite news |last=Bureau |first=The Hindu |date=2023-12-28 |title=Assam Opposition alliance resolves to field consensus candidates for LS polls |url=https://www.thehindu.com/news/national/other-states/assam-opposition-alliance-resolves-to-field-consensus-candidates-for-ls-polls/article67683007.ece |access-date=2024-04-17 |work=The Hindu |language=en-IN |issn=0971-751X}}</ref>
|-
!36
|
|'''मद'''
|महान दल
|[[File:No_image_available.svg|center|80x80px]]
|[[उत्तर प्रदेश|उतार प्रदेश]]
|[[File:No_image_available.svg|center|80x80px]]
|केसव देव मौर्य
|<ref>{{Cite news |last=Bureau |first=The Hindu |date=2024-04-03 |title=Mahan Dal declares support to SP-led INDIA bloc in U.P., claims third front aims to help BJP |url=https://www.thehindu.com/elections/lok-sabha/mahan-dal-declares-support-to-sp-led-india-bloc-in-up-claims-third-front-aims-to-help-bjp/article68020819.ece |access-date=2024-04-17 |work=The Hindu |language=en-IN |issn=0971-751X}}</ref>
|-
!37
|
|'''विइंपा'''
|[[विकासशील इंसान पार्टी]]
|[[File:No_image_available.svg|80x80px]]
|[[बिहार]]
|
|[[मुकेश सहनी]]
|<ref>{{Cite web |date=2024-04-05 |title=Mukesh Sahni joins RJD-led alliance, VIP to contest 3 seats |url=https://www.hindustantimes.com/cities/patna-news/mukesh-sahni-joins-rjd-led-alliance-vip-to-contest-3-seats-101712331941512.html |access-date=2024-04-17 |website=Hindustan Times |language=en}}</ref>
|-
!38
|
|'''पूलोप'''
|पूर्वांचल लोक परिषद
|[[चित्र:No image available-th.svg|फ़्रेमहीन|80x80पिक्सेल]]
|[[असम]]
|[[चित्र:No image available-th.svg|फ़्रेमहीन|80x80पिक्सेल]]
|चरण चंद्र डेका
|<ref name=":13" />
|-
!'''39'''
|
|'''सगपा'''
|समाजवादी गणराज्य पार्टी
|[[File:No_image_available-th.svg|frameless|80x80px]]
|[[महाराष्ट्र]]
|[[File:No_image_available-th.svg|frameless|80x80px]]
|[[कपिल पाटिल (लोकभारती)]]
|<ref>{{Cite news |date=2024-03-04 |title=MLC Kapil Patil launches new party in Mumbai |url=https://timesofindia.indiatimes.com/city/mumbai/mlc-kapil-patil-launches-new-party-in-mumbai/articleshow/108205531.cms |access-date=2024-04-17 |work=The Times of India |issn=0971-8257}}</ref>
|-
| style="background-color:{{party color|Independent politician}}; text-align: center;color:white;" |
|
|[[निर्दलीय राजनेता|निर्दलीय]]
| colspan="6" |'''''निर्दलीय'''''
|-
! colspan="9" | कुल-38 दल
|}
== इहो देखल जाय ==
* [[एनडीए]] (NDA) - भाजपा के अगुआई वाला गठबंधन
== संदर्भ ==
{{Reflist|33em}}
[[श्रेणी:भारतीय राजनीति]]
[[श्रेणी:भारत के राजनीतिक दल]]
{{India-party-stub}}
{{India-stub}}
hdcxgqsjhwox3tqchygwxpt7ye15m07
पाण्डेय कपिल
0
92351
790265
760144
2026-04-03T11:04:07Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790265
wikitext
text/x-wiki
{{Infobox writer
| name = पाण्डेय कपिल
| image = Pandey Kapil.png
| image_size =
| image_upright =
| alt =
| caption = पाण्डेय कपिल के जवानी के समय के तस्वीर
| birth_name = पाण्डेय कपिलदेव नारायण सिन्हा
| birth_date = {{Birth date|1930|09|30}}
| birth_place =
| death_date = {{Death date and age|2017|11|02|1930|09|24}}
| death_place =
| occupation = अनुवादक, राजभाषा उपनिदेशक (राजभाषा बिभाग, बिहार सरकार)
| language = [[भोजपुरी]]
| nationality = <!-- use only when necessary per [[WP:INFONAT]] -->
| citizenship = <!-- use only when necessary per [[WP:INFONAT]] -->
| education =
| alma_mater = [[बनारस हिंदू विश्वविद्यालय|काशी विश्वविद्यालय]], [[बिहार विश्वविद्यालय]]
| period =
| genre = <!-- or: | genres = -->
| subject = <!-- or: | subjects = -->
| movement =
| notable_works = ''[[#फुलसुंघी|फुलसुंघी]]'' (उपन्यास)
| spouse = <!-- or: | spouses = -->
| partner = <!-- or: | partners = -->
| children =
| relatives =
| awards =
| signature =
| signature_alt =
| years_active =
}}
'''पाण्डेय कपिलदेव नारायण सिन्हा''' (24 सितंबर 1930 — 2 नवंबर 2017)<ref name="न्यूज़18" />, जिनका '''पाण्डेय कपिल''' नाँव से जानल जाला, [[भोजपुरी|भोजपुरी भाषा]] के एगो साहित्यकार रहलें। उनुका के [[भोजपुरी साहित्य]] के परसिद्ध रचना ''फुलसुंघी'' उपन्यास खाती आ ''भोजपुरी सम्मेलन पत्रिका'' के संपादक के रूप में जानल जाला। एकरा अलावे ऊ बिबिध बिधा सभ के रचना कइलें आ भोजपुरी साहित्य के समृद्ध बनावे में योगदान कइलें। पाण्डेय के ''भोजपुरी अकादमी पुरस्कार'' आ अउरी कई गो पुरस्कार मिलल रहलें।
== जिनगी ==
पाण्डेय कपिल के जनम [[बिहार]] के [[सारन जिला]] के शीतलपुर (वाया बरेजा) गाँव में 24 सितंबर 1930 के भइल।<ref name="न्यूज़18">{{cite web |last1=द्विवेदी |first1=भगवती प्रसाद |title=भोजपुरी के भगीरथ: पाण्डेय कपिल जिनिगी के जीयल हऽ बड़की लड़ाई |url=https://hindi.news18.com/news/bhojpuri-news/acharya-pandey-kapil-life-struggling-story-in-bhojpuri-3955269.html |website=न्यूज़18 हिंदी |access-date=23 अगस्त 2023 |language=hi |date=15 जनवरी 2022 |archive-date=2023-08-23 |archive-url=https://web.archive.org/web/20230823094109/https://hindi.news18.com/news/bhojpuri-news/acharya-pandey-kapil-life-struggling-story-in-bhojpuri-3955269.html |url-status=dead }}</ref> उनुके बाबूजी पाण्डेय जगन्नाथ प्रसाद सिंह खुद भोजपुरी के लेखक रहलें आ महतारी लालचुन्नी देवी एगो कुशल शिल्पी रहली। पाण्डेय के पढ़ाई-लिखाई [[बनारस हिंदू विश्वविद्यालय|काशी विश्वविद्यालय]] (बीए), [[बिहार विश्वविद्यालय]] (एमए, हिंदी साहित्य) में भइल आ बिहार सरकार के राजभाषा बिभाग में अनुवादक के रूप में नोकरी शुरू कइलें आ ओहिजे से राजभाषा उपनिदेशक के रूप में रिटायर भइलें।<ref name="न्यूज़18" />
2 नवंबर 2017 के पाण्डेय के [[पटना]] स्थित आवास पर, लमहर बेमारी आ इलाज के बाद, निधन भ गइल।<ref>{{cite news |title=भोजपुरी के शलका पुरुष कपिल पांडेय का हुआ निधन |url=https://www.livehindustan.com/jharkhand/jamshedpur/story-bhojpuri-man-s-man-is-not-kapil-pandey-1624174.html |access-date=23 अगस्त 2023 |work=हिंदुस्तान |date=2 नवंबर 2017 |language=hi}}</ref>
== रचना ==
=== मौलिक ===
[[चित्र:Phoolsunghi English version.jpg|thumb|alt=फूलसुंघी के अंग्रेजी संस्करण के कभर पन्ना|फूलसुंघी के अंग्रेजी संस्करण के कभर पन्ना]]
* ''आभास'' (हिंदी कविता संग्रह)
* ''फूल और कलियाँ'' (लड़िकन खातिर हिंदी कविता संग्रह)
* ''हीरे के टुकडे'' (बालोपयोगी हिंदी कविता संग्रह)
* ''हवा और पानी'' (बालोपयोगी हिंदी कविता संग्रह)
* ''नवीन सुबोध व्याकरण'' (हिंदी व्याकरण)
* ''भोर हो गइल'' (भोजपुरी कविता संग्रह)
* ''फुलसुंघी'' (भोजपुरी उपन्यास)
* ''कह ना सकलीं'' (भोजपुरी गजल संग्रह)
* ''जीभ बेचारी का कही'' (भोजपुरी दोहा संग्रह)
* ''परिन्दा उड़ान पर'' (भोजपुरी गजल संग्रह)
* ''दुनिया के शतरंज बिछल बा'' (कविता संग्रह)
=== अनुबाद ===
* ''आरा में दो मास'' (जान जेम्स हाल्स लिखित ' दू मंथ्स इन आरा इन 1857 ' के हिंदी अनुवाद)
=== संपादित ===
* ''नवांजलि'' (नौ गो युवा कवियन के हिंदी कविता संग्रह)
* ''सारण्यक'' (सारन जिला के बारह वयोवृद्ध कवियन के हिंदी कविता के प्रतिनिधि संकलन)
* ''आचार्य महेंद्र शास्त्री: कृतित्व एवँ व्यक्तित्व'' (आचार्य महेंद्र शास्त्री के कृतित्व आ व्यक्तित्व पर विविध लेखकन के 92 गो लेख के आउर महेंद्र शास्त्री के हिंदी आ भोजपुरी के 175 कवितन के संग्रह)
* ''दसरतन'' (विविध लेखकन के लिखल दस गो व्यक्तिपरक निबंधन के संग्रह)
* ''योग रामायण'' (योगी आत्माराम के लिखल योग-विवेचन)
* ''एक मुठ्ठी लाई'' (लघुकथा -संकलन)
* ''भोजपुरी कहानी हाल साल के'' (कहानी संकलन)
* ''भोजपुरी सतसई'' (दोहा संकलन)
* ''धार के खिलाफ'' (भोजपुरी गीत संकलन)
;पत्रिका
* ''भोजपुरी सम्मेलन पत्रिका'', अखिल भारतीय भोजपुरी साहित्य सम्मेलन
{{clear}}
== संदर्भ ==
{{Reflist|33em}}
== बाहरी कड़ी ==
* [https://penguin.co.in/book_author/pandey-kapil/ पाण्डेय कपिल], लेखक परिचय, पेंगुइन रैंडम हाउस इंडिया के वेबसाइट प।
* [https://vidhyathakkar.com/phoolsunghi-by-pandey-kapil-translated-by-gautam-choubey-book-review/ फुलसुंघी के समीक्षा]
* [https://www-firstpost-com.translate.goog/art-and-culture/the-world-of-pandey-kapils-phoolsunghi-gautam-choubey-on-translating-the-novel-bhojpuri-literary-culture-9113031.html?_x_tr_sl=en&_x_tr_tl=hi&_x_tr_hl=hi&_x_tr_pto=tc पांडे कपिल की फूलसुंघी की दुनिया], फस्टपोस्ट पर।
* [https://bhojpurisahityangan.com/category/writer/pandeykapil/ पाण्डेय कपिल], भोजपुरी साहित्यांगन प।
[[श्रेणी:1930 में जनम]]
[[श्रेणी:2017 में निधन]]
[[श्रेणी:बिहार के लोग]]
[[श्रेणी:सारन जिला के लोग]]
[[श्रेणी:भोजपुरी साहित्यकार]]
eklirzbldz8zgk60qyr22uanpqyfsmr
आम्रपाली दुबे
0
98005
790083
789511
2026-04-02T22:51:27Z
InternetArchiveBot
25596
Rescuing 0 sources and tagging 1 as dead.) #IABot (v2.0.9.5
790083
wikitext
text/x-wiki
{{Infobox person
| name = आम्रपाली दुबे
| image = Amrapali Dubey at Press Conference of Celebrity Cricket League 2016 (cropped).jpg
| imagesize =
| caption = दुबे 2016 में
| birth_date = {{Birth date and age|1987|1|11|df=yes}}
| birth_place = [[गोरखपुर जिला|गोरखपुर]], [[उत्तर प्रदेश]], भारत
| occupation = {{hlist|ऐक्ट्रेस|जजमान|मडेल}}
| years_active = 2009–वर्तमान
| known_for =
| partner =
| children =
| parents =
| relatives =
| height =
| website = {{URL|https://amrapalidubey.com/}}
}}
'''आम्रपाली दुबे''' (जनम 11 जनवरी 1987) एगो भारतीय ऐक्ट्रेस बाड़ी जे मुख्य रूप से भोजपुरी फिलिमन में काम करे लीं। भोजपुरी के सबसे अधिका वेतन पावे वाली ऐक्ट्रेस में गिनल जाए वाली दुबे के चार गो भोजपुरी फिल्म अवार्ड आ दू गो अंतर्राष्ट्रीय भोजपुरी फिल्म अवार्ड समेत कई गो पुरस्कार मिलल बा.
दुबे टेलीविजन सोप ओपेरा सात फेरे – सलोनी का सफर (2009) से अभिनय के शुरुआत कइली। रेहना है तेरी पालकोन की छओन में में सुमन के जानल-मानल किरदार के बाद ऊ निरहुआ हिंदुस्तानी (2014) के साथ भोजपुरी फिलिमन में उतरली।<ref>{{cite web |url=http://entertainment.in.msn.com/tv/article.aspx?cp-documentid=3073268 |title=TV – MSN India: Television News | TV Celebrity Gossip | Latest TV Stories |publisher=Entertainment.in.msn.com |date=22 January 2015 |access-date=27 March 2015 |archive-url=https://web.archive.org/web/20131012070944/http://entertainment.in.msn.com/tv/article.aspx?cp-documentid=3073268 |archive-date=12 October 2013 |url-status=dead}}</ref> दुबे सफल फिलिम निरहुआ हिंदुस्तानी 2 (2017), बॉर्डर (2018), निरहुआ हिंदुस्तानी 3 (2018), निरहुआ चलल [[लंदन]] (2019), शेर सिंह (2019), आशिकी (2022), लव विवाह डॉट कॉम (2022) आ डोली सजा के रखना (2022) के साथ अपना के एगो प्रमुख भोजपुरी ऐक्ट्रेस के रूप में स्थापित कइली ह।<ref>{{Cite web |title=Aamrapali to make her debut on Bhojpuri screen |work=The Times of India |date=30 April 2014 |access-date=17 April 2016 |url=http://timesofindia.indiatimes.com/entertainment/bhojpuri/movies/news/Aamrapali-to-make-her-debut-on-Bhojpuri-screen/articleshow/34422408.cms}}</ref><ref>{{cite web |url=http://fulfilmy.com/amrapali-dubey-future-of-bhojpuri-cinema/ |title=Amrapali Dubey : A hope of Bhojpuri Film Industry |publisher=fulfilmy.com |access-date=15 December 2015 |archive-url=https://web.archive.org/web/20151222085830/http://fulfilmy.com/amrapali-dubey-future-of-bhojpuri-cinema/ |archive-date=22 December 2015 |url-status=dead}}</ref>
== शुरुआती जिनगी ==
दुबे के जनम 11 जनवरी 1987 के उत्तर प्रदेश के गोरखपुर जिला में भइल। अंत में ऊ अपना दादा के साथे [[मुंबई]] चल गइली, आ ओहिजा भवन के कॉलेज में आपन पढ़ाई पूरा कइली।<ref name="bio">{{cite web |title=Amrapali Dubey Biography, Hot Photos, Movies |url=http://amrapalidubey.com/amrapali-dubey-biography-date-of-birth-age-movies-hometown/ |website=amrapalidubey.com |access-date=16 November 2016 |archive-date=29 April 2016 |archive-url=https://web.archive.org/web/20160429224010/http://amrapalidubey.com/amrapali-dubey-biography-date-of-birth-age-movies-hometown/ |url-status=dead }}</ref><ref name="Patrika">{{Cite news |date=5 March 2022 |title=फीस के मामले में कई अभिनेताओं से आगे हैं टॉप एक्ट्रेस आम्रपाली, जानिये एक फिल्म के कितने करती हैं चार्ज {{!}} Bhojpuri Actress Amrapali Dubey Films Fees Lifestyle |url=https://www.patrika.com/lucknow-news/bhojpuri-actress-amrapali-dubey-films-fees-lifestyle-7379572/ |access-date=18 June 2022 |work=Patrika News |language=hi}}</ref>
== करियर ==
दुबे आपन करियर के शुरुआत टेलीविजन से कइली, आ सात फेरे – सलोनी का सफर में श्वेता सिंह, मायक में टीना, रेहना है तेरी पलकोन की छओन में सुमन प्रतापसिंह आ मेरा नाम करेगी रोशन में रीत सिंह के भूमिका निभावे खातिर जानल जाली।<ref>{{cite web |title=रहना है तेरी पलकों की छांव में': आम्रपाली दुबे के साथ शोएब इब्राहिम ने किया था वो धमाकेदार सीरियल |url=https://navbharattimes.indiatimes.com/photomazza/tv-photogalleries/shoaib-ibrahim-tv-debut-with-bhojpuri-actress-amarpali-dubey-rehna-hai-teri-palkon-ki-chhaon-mein-then-and-now-photo/photoshow/msid-99311723,picid-99311756.cms |website=Navbharat Times |access-date=19 November 2023}}</ref>
दुबे अपना कैरियर के शुरुआत निरहुआ हिंदुस्तानी से भोजपुरी फिलिमन से कइली. आगे ऊ पटना से [[पाकिस्तान]],<ref>{{cite news|date=24 February 2015 |url=http://timesofindia.indiatimes.com/entertainment/bhojpuri/movies/news/Nirahua-back-with-Patna-Se-Pakistan/articleshow/46356370.cms |title=Nirahua back with 'Patna Se Pakistan'|work=[[The Times of India]]|accessdate=2 July 2015}}</ref> निरहुआ हिंदुस्तानी 2,<ref>{{Cite news|date=15 March 2020|title=निरहुआ हिंदुस्तानी 2: जोरदार है दिनेश लाल यादव की यह फिल्म|language=hi|work=[[Navbharat Times]]|url=https://navbharattimes.indiatimes.com/video/movie-masti/bhojpuri/watch-bhojpuri-full-hd-movie-of-dinesh-lal-yadav-nirahua-hindustani-2/videoshow/74633697.cms|access-date=3 May 2020}}</ref> बॉर्डर, निरहुआ हिंदुस्तानी 3, निरहुआ चलल लंदन,<ref>{{cite news|url=http://zeenews.india.com/bhojpuri/dinesh-lal-yadav-shares-a-glimpse-of-nirahua-chalal-london-co-starring-amrapali-dubey-watch-2130897.html|title=Dinesh Lal Yadav shares a glimpse of Nirahua Chalal London co-starring Amrapali Dubey|work=Zee News|accessdate=23 August 2018}}</ref> जय वीरू, शेर सिंह, आशिकी, लवविवाह डॉट कॉम आ डोली सजा के रखना जइसन सफल फिलिमन से अपना के एगो प्रमुख ऐक्ट्रेस का रूप में स्थापित कइली.<ref>{{Cite news|url=https://www.hindirush.com/bhojpuri-news/aamrapali-dubey-has-unveiled-the-first-poster-of-her-upcoming-film-with-pawan-singh-sher-singh-123061/|title=आम्रपाली दुबे-पवन सिंह की फिल्म शेर सिंह का फर्स्ट लुक आउट, पोस्टर में दिखी दोनों की खूबसूरत बॉन्डिंग|last=Tripti Sharma|date=7 September 2019|work=Hindi Rush|access-date=7 September 2019|language=hi|archive-date=12 August 2020|archive-url=https://web.archive.org/web/20200812114035/https://www.hindirush.com/bhojpuri-news/aamrapali-dubey-has-unveiled-the-first-poster-of-her-upcoming-film-with-pawan-singh-sher-singh-123061/|url-status=dead}}</ref><ref>{{Cite web |title=निरहुआ नहीं खेसारी लाल के साथ ठुमके लगाएंगी ब्यूटी क्वीन आम्रपाली दुबे, दोनों की 'आशिकी' के खूब हैं चर्चे |url=https://www.prabhatkhabar.com/entertainment/bhojpuri/superstar-khesari-lal-yadav-and-beauty-queen-amrapali-dubey-new-film-aashiqui-announced-read-full-details-about-upcoming-project-abk |access-date=13 October 2022 |website=Prabhat Khabar |date=2 March 2021 |language=hi}}</ref><ref>{{Cite web |title=रिलीज होने के लिए तैयार खेसारी लाल यादव फिल्म 'डोली सजा के रखना', आम्रपाली दुबे के साथ नजर आएंगे अलग अंदाज में |url=https://ndtv.in/bhojpuri-cinema/khesari-lal-yadav-film-doli-saja-ke-rakhna-will-release-at-2nd-septemper-will-be-seen-in-a-different-style-with-amrapali-dubey-3306777 |access-date=16 September 2022 |website=NDTVIndia }}{{Dead link|date=April 2026 |bot=InternetArchiveBot |fix-attempted=yes }}</ref>
उनुका के दिनेश लाल यादव का साथे ऑन स्क्रीन जोड़ी बनावे खातिर भी जानल जाला। उहाँ के फिल्म बॉर्डर, दुनिया भर में चउथा सबसे ज्यादा कमाई करे वाली भोजपुरी फिल्म के रूप में स्थान पर बा।<ref>{{cite news |title=भोजपुरी सिनेमा की सबसे ज्यादा कमाई करने वाली फिल्में |url=https://navbharattimes.indiatimes.com/movie-masti/news-from-bollywood/bhojpuri-movie-highest-box-office-collection/articleshow/66311325.cms |archive-url=https://web.archive.org/web/20220819095630/https://navbharattimes.indiatimes.com/movie-masti/news-from-bollywood/bhojpuri-movie-highest-box-office-collection/articleshow/66311325.cms |archive-date=19 August 2022 |access-date=17 February 2022 |website=[[Navbharat Times]] |language=hi}}</ref>
== संदर्भ ==
{{Reflist}}
[[श्रेणी:1987 में जनम]]
[[श्रेणी:जियत लोग]]
[[श्रेणी:भोजपुरी सिनेमा के ऐक्ट्रेस लोग]]
t66t85u8p8ky6405es4rf17a8e8ffh2
एक्स
0
98190
790262
789609
2026-04-03T09:03:09Z
SM7
3953
बिस्तार कइल गइल
790262
wikitext
text/x-wiki
{{for|एही नाँव के सोशल नेटवर्क सर्विस|एक्स (सोशल नेटवर्क)}}
'''एक्स''' ('''X''' चाहे '''x''') [[अंग्रेजी]] आ अउरी कई भाषा सभ के लिखे खातिर इस्तेमाल होखे वाला मॉडर्न [[लैटिन अल्फाबेट]] (चाहे रोमन अच्छर) सभ में 24वाँ अल्फाबेट हवे।
चीन्हा के रूप में ई अक्सर "नामौजूदगी" भा "ग़ायब चीज" के चिन्हित करे खातिर इस्तेमाल होला।
{{lang-stub}}
[[श्रेणी:लैटिन अच्छर]]
jdcfmgxr11d5b7ogoth4esiertjdh5b
अविमुक्तेश्वरानंद सरस्वती
0
100265
790082
789346
2026-04-02T22:12:30Z
InternetArchiveBot
25596
Rescuing 0 sources and tagging 2 as dead.) #IABot (v2.0.9.5
790082
wikitext
text/x-wiki
{{Infobox person
| name = स्वामी अविमुक्तेश्वरानंद सरस्वती
| image = Avimukteshwaranand.jpg
| caption =
| native_name_lang =
| other_names =
| birth_name = उमाशंकर पाण्डेय
| birth_date = 1969
| birth_place =
| death_date =
| nationality = भारतीय
| citizenship = <!-- use only when necessary per [[WP:INFONAT]] -->
| education =
| alma_mater =
| occupation = [[ज्योतिर्मठ (जोशीमठ)]] के वर्तमान और 46वें शंकराचार्य (विवादित)<ref name="m101" />
| years_active =
| known_for =
| awards =
| website = <!-- {{URL|example.com}} -->
| signature =
| footnotes =
}}
'''स्वामी अविमुक्तेश्वरानंद सरस्वती'''<ref>{{Cite news |last=PTI |date=2022-10-15 |title=SC stops coronation of Swami Avimukteshwaranand Saraswati as Shankaracharya of Jyotish Peeth |url=https://www.thehindu.com/news/national/sc-stops-coronation-of-swami-avimukteshwaranand-saraswati-as-shankaracharya-of-jyotish-peeth/article66014458.ece |access-date=2026-02-21 |work=The Hindu |language=en-IN |issn=0971-751X}}</ref><ref>{{Cite web |date=2022-10-15 |title=SC stops coronation of Swami Avimukteshwaranand Saraswati as Shankaracharya of Jyotish Peeth |url=https://indianexpress.com/article/india/sc-stops-coronation-of-swami-avimukteshwaranand-saraswati-as-shankaracharya-8210568/ |access-date=2026-02-21 |website=The Indian Express |language=en}}</ref> (जनम: 1969; मूल नाँव : उमाशंकर उपाध्याय) भारत के एगो हिंदू धार्मिक नेता हवें। उ उत्तराखंड के जोशीमठ में स्थित हिंदू धर्म के ज्योतिर्मठ के वर्तमान आ 46वां शंकराचार्य होखे के दावा करे लें, बाकी ई मुद्दा विवादित बाटे आ कोर्ट में बिचाराधीन बा।<ref name="m101">{{Cite web |date=23 February 2026 |title=Swami Avimukteshwaranand News Live: अविमुक्तेश्वरानंद सरस्वती क्या गिरफ्तार होंगे? जानिए केस से जुड़े सभी अपडेट |url=https://navbharattimes.indiatimes.com/state/uttar-pradesh/lucknow/swami-avimukteshwaranand-saraswati-news-today-live-up-court-pocso-case-up-police-latest-updates/liveblog/128702291.cms |access-date=1 March 2026 |website=Navbharat Times |language=hi}}</ref><ref name="y820">{{Cite web |last=ठाकुर |first=आलोक कुमार |date=25 February 2026 |title=राम मंदिर से लेकर माघ मेले तक... अविमुक्तेश्वरानंद को लेकर विवाद कुछ नया नहीं, जान लीजिए कब-कब रहे कंट्रोवर्सी में |url=https://ndtv.in/india/shankaracharya-avimukteshwarananda-controversy-allahabad-high-court-on-sexual-harassment-of-minor-and-pocso-act-11135948 |access-date=1 March 2026 |website=NDTV India |language=hi }}{{Dead link|date=April 2026 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> ज्योतिर्मठ [[आदि शंकर|आदि शंकराचार्य]] द्वारा स्थापित चार गो अद्वैत मठन में से एगो ह। इनके गुरु स्वामी स्वरूपानंद सरस्वती, मठ के 45वां शंकराचार्य रहलन जिनकर सितंबर 2022 में निधन हो गइल।<ref>{{Cite news |date=2022-09-13 |title=Uttarakhand: Swami Avimukteshwaranand new Jyotish Peethshankaracharya |url=https://timesofindia.indiatimes.com/city/dehradun/uttarakhand-swami-avimukteshwaranand-new-jyotish-peethshankaracharya/articleshow/94183259.cms |access-date=2023-06-03 |work=The Times of India |issn=0971-8257}}</ref><ref>{{Cite web |title=SC stops coronation of Swami Avimukteshwaranand Saraswati as Shankaracharya of Jyotish Peeth - The Economic Times |url=https://m.economictimes.com/news/india/sc-stops-coronation-of-swami-avimukteshwaranand-saraswati-as-shankaracharya-of-jyotish-peeth/amp_articleshow/94881298.cms |access-date=2026-02-21 |website=m.economictimes.com}}</ref>
== शुरुआती जीवन आ शिक्षा ==
अविमुक्तेश्वरानंद 15 अगस्त 1969 के [[उत्तर प्रदेश|उत्तर प्रदेश के]] [[प्रतापगढ़ जिला|प्रतापगढ़ जिला के]] ब्राह्मणपुर गाँव में जनमलें आ इनकर संन्यास लेवे से उमाशंकर पाण्डेय नाम रहल। [[बनारस|वाराणसी]] के [[संपूर्णानंद संस्कृत विश्वविद्यालय|सम्पूर्णानंद संस्कृत विश्वविद्यालय]] से शास्त्री आ आचार्य के डिग्री लिहलें। संस्कृत विश्वविद्यालय में पढ़ाई करत घरी छात्र राजनीति में भी सक्रिय रहलें।<ref name="m101" /><ref name="y820" />
== बिबाद==
अविमुक्तेश्वरानंद सरस्वती राम मंदिर उद्घाटन, अयोध्या राजनीति आ शंकराचार्य परंपरा के लेके पिछला कुछ साल में विवादन के बीच लगातार चर्चा में रहलन। मुख्य-मुख्य बिबाद कुछ एह प्रकार रहल:
===शंकराचार्य पद के दावेदारी===
अविमुक्तेश्वरानंद कहेलन कि ऊ ज्योतिर्मठ/ज्योतिष पीठ के वैध शंकराचार्य बाड़ें। दूसरा पक्ष कहेला कि ई पद स्वामी वासुदेवानंद सरस्वती के बा, आ नियुक्ति प्रक्रिया संविधान/परंपरा अनुसार ना भइल। एहसे, दोनु पक्ष आपन-आपन वैधता के दावा करत रहलें, जेकरा से विवाद बढ़ल।
===राम मंदिर कार्यक्रम से दूरी===
ऊ अयोध्या राम मंदिर प्राण-प्रतिष्ठा कार्यक्रम में ना गइलें। कारण बतावत कहलन कि “धार्मिक आयोजन के राजनीति से जोड़ल ठीक ना हवे।” सरकार पक्ष आ समर्थक लोग एह बात के विरोध कइलें, आ सोशल मीडिया पर बहस तेज हो गइल।
===धार्मिक-राजनीतिक टिप्पणी आ कोर्ट केस ===
अविमुक्तेश्वरानंद कई बेर केंद्र/राज्य सरकार पर साधु-समाज, गंगा सफाई, आ धर्मस्थल संरक्षण पर सवाल उठावत बयान देत रहलें। समर्थक कहलें कि ऊ “धर्म स्वायत्तता” के आवाज उठावत बाड़ें। विरोधी पक्ष कहलें कि ई टिप्पणी राजनीतिक झुकाव वाला बा।
कुछ मामले (जैसे—धार्मिक स्थल ढहावल, गंगा किनारा संरक्षण, तीर्थ-व्यवस्था) में ऊ कोर्ट तक गइलें। प्रशासन अक्सर उनुकर आरोप खारिज करत रहल, जेकरा से विवाद अउरी खुलल रूप ले लिहल।
== माघ मेला 2025-2026==
हाल के [[माघ मेला]] में अविमुक्तेश्वरानंद आ मेला प्रशासन के बीच जगह बंटवारा आ कैंप के लोकेशन लेके बड़ बिबाद भइल। प्रशासन कहलस कि उनका शिविर के हिस्सा नियम से बाहर बा, जबकि अविमुक्तेश्वरानंद एह बात के सख्ती से खारिज करत कहेलन कि ई राजनीतिक दबाव में कइल गइल कदम हवे। जगह हटावे के नोटिस, तोड़फोड़ के कार्रवाई आ धरना–विरोध के वजह से ई मामला पूरा मेला में सबसे चर्चित मुद्दा बनल रहल। साधु समाजो दू हिस्सन में बँट गइल—कवनो लोग प्रशासन के सही मानलस, कवनो लोग अविमुक्तेश्वरानंद के पक्ष ले लिहलस। माहौल तनातनी वाला बनल रहल आ मीडिया में लगातार ई विवाद बहस के विषय बनल।
एकरा पाहिले [[मौनी अमौसा]] के नहान के दौरान उनके प्रशासन द्वारा पालकी पर सवार हो के नहान घाट ले जाये से रोक दिहल गइल रहल जेकरा चलते ई सगरी बिबाद पैदा भइल।<ref name="g543">{{cite web |title='Leaving with heavy heart': Swami Avimuktshwaranad ends sit-in protest at Magh Mela; Akhilesh says BJP 'blinded by power' |website=The Times of India |date=28 January 2026 |url=https://timesofindia.indiatimes.com/india/leaving-with-heavy-heart-swami-avimuktshwaranad-ends-sit-in-protest-at-magh-mela-akhilesh-says-bjp-blinded-by-power/articleshow/127699822.cms |access-date=2 March 2026}}</ref>
== यौन शोषण के आरोप ==
माघ मेला के टकराव के कुछ दिन बाद अविमुक्तेश्वरानंद सरस्वती पर एक महिला साध्वी/सेविका द्वारा यौन शोषण के गंभीर आरोप लगावल गइल। शिकायत दर्ज होतें मामला सामाजिक–राजनीतिक लेवल पर गरम हो गइल काहे कि आरोप लगाने वाली के कहना बा कि वर्षों से दबाव आ उत्पीड़न सहत रहल, जबकि अविमुक्तेश्वरानंद जी ई आरोप के पूरी तरह ‘झूठ’ आ ‘साजिश’ बता रहल बानी। उहे साधु–समाज जे माघ मेला विवाद में बाँटल रहे, अब ई मामला परो बिखर गइल—कवनो लोग निष्पक्ष जांच के बात कर रहल बा, त कवनो लोग एकरा के राजनीतिक बदनामी के अभियान बता रहल बा। मामला पुलिस जांच में बा आ अंतिम तथ्य अभी बाहर ना आइल बा।<ref name="u319">{{cite web |title=Special POCSO Court Orders FIR Against Swami Avimukteshwaranand Saraswati |website=DD News On Air |date=1 June 2022 |url=https://www.newsonair.gov.in/special-pocso-court-orders-fir-against-swami-avimukteshwaranand-saraswati/ |access-date=2 March 2026}}</ref> एह मामिला में इलाहाबाद हाईकोर्ट से उनके फिलहाल गिरफ्तारी से राहत मिलल बाटे।<ref name="q738">{{cite web |last=मिश्रा |first=काव्या |title=अविमुक्तेश्वरानंद को हाईकोर्ट से बड़ी राहत, अभी नहीं होगी गिरफ्तारी, अब 15 मार्च को सुनवाई |website=News18 हिंदी |date=27 February 2026 |url=https://hindi.news18.com/news/uttar-pradesh/varanasi-aavimukteshwaranand-controversy-live-news-update-in-hindi-harassment-allegations-bail-plea-allahabad-high-court-10224667.html |language=hi |access-date=2 March 2026 }}{{Dead link|date=April 2026 |bot=InternetArchiveBot |fix-attempted=yes }}</ref>
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:1969 में जनम]]
[[श्रेणी:जियत लोग]]
[[श्रेणी:हिन्दू गुरु]]
odc8jz88d09s6xz25tst3yc853wnf4y
टिटिहिरी
0
100361
790108
789494
2026-04-03T06:13:31Z
InternetArchiveBot
25596
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5
790108
wikitext
text/x-wiki
{{Speciesbox
| image = Red-wattled lapwing (Vanellus indicus) Photograph by Shantanu Kuveskar.jpg
| image_caption = ''Vanellus indicus indicus''<br />[[File:Redwattled Lapwing.ogg|thumb|left|आवाज]]
| status = LC
| status_system = IUCN3.1
| status_ref = <ref>{{cite iucn |author=BirdLife International |date=2016 |title=''Vanellus indicus'' |article-number=e.T22694013A89569039 |doi=10.2305/IUCN.UK.2016-3.RLTS.T22694013A89569039.en}}</ref>
| genus = Vanellus
| species = indicus
| authority = ([[Pieter Boddaert]], 1783)
| synonyms =
''Hoplopterus indicus'' <br />
''Lobivanellus indicus''<br />
''Lobivanellus goensis''<br />
''Tringa indica''<br />
''Sarcogrammus indicus''
| range_map = Vanellus indicus map.svg
| range_map_caption = भूगोलीय क्षेत्र-बिस्तार
}}
'''टिटिहिरी''' ({{Langx|hi|टिटहिरी}}, {{Langx|en|red-wattled lapwing}}) ''(Vanellus indicus)'', एगो माझिल साइज के, पानी के नगीचे रहे वाली चिरई ह जे बैज्ञानिक बर्गीकरण में ''काराड्रिडाए'' (''Charadriidae'') [[जाति (जीव बिज्ञान)|फेमिली]] में आवे ले; जे एशियाई [[टिटिहिरी कुल]] (लैप्विंग) सभ के एगो [[प्रजाति]] हवे। ई जमीन पर रहे वाली चिरई हवे; चले ले, दउरे ले आ उड़े ले बाकी फेड़ा पर ना बइठे ले। आमतौर प पानी के कौनो स्रोत जइसे की ताल, तलाब, खाल नमभूमि, नद्दी इत्यादि के नगीचे के मैदानी इलाका में पावल जालीं। इनहन के नाँव इनहन के आवाज के चलते पड़ल ह "टि-टि-हुक" भा "हुटिटी टी , हुटिटी टी" नियन होखे ला आ एकरे बोली के कुछ लोग अशुभ माने ला<ref name="j527">{{cite web | last=Gotam | first=Anuj | title=खतरे की घंटी है इस पक्षी की 'आवाज', "हुटिटी टी , हुटिटी टी" सुनते ही घर में मच जाती है हलचल, जानें डरावना सच | website=News18 हिंदी | date=7 June 2025 | url=https://hindi.news18.com/news/madhya-pradesh/sagar-bundelkhand-dadi-aama-warning-say-titahari-pakshi-ashubh-sanket-ki-kahani-sound-of-sandpiper-indicate-something-bad-local18-ws-kl-9292136.html | language=hi | access-date=21 March 2026 | archive-date=8 June 2025 | archive-url=https://web.archive.org/web/20250608084926/https://hindi.news18.com/news/madhya-pradesh/sagar-bundelkhand-dadi-aama-warning-say-titahari-pakshi-ashubh-sanket-ki-kahani-sound-of-sandpiper-indicate-something-bad-local18-ws-kl-9292136.html | url-status=dead }}</ref>।
[[संस्कृत साहित्य]] में परसिद्ध कथा ग्रंथ [[पंचतंत्र]] में एक जगह एकरा आपन गोड़ा ऊपर क के सुते के बिबरन मिले ला आ ई बतावल गइल हा कि अइसन काम ई आसमान गिरे से रक्षा खातिर करे ला।{{efn|<poem>उत्क्षिप्य टिट्टिभः पादावास्ते भङ्गभयाद्दिवः।
स्वचित्तकल्पितो गर्वः कस्य नात्रापि विद्यते॥३४३॥<ref name="v862">{{cite web | title=पृष्ठम्:Birds in Sanskrit literature.djvu/२०६ | website=विकिस्रोतः | url=https://sa.wikisource.org/wiki/%E0%A4%AA%E0%A5%83%E0%A4%B7%E0%A5%8D%E0%A4%A0%E0%A4%AE%E0%A5%8D:Birds_in_Sanskrit_literature.djvu/%E0%A5%A8%E0%A5%A6%E0%A5%AC | language= | access-date=21 मार्च 2026}}</ref></poem>
}}
<gallery mode="packed" heights="160px">
Red-wattled lapwing-wings-spread-tail-hyderabad-India.jpg|''V. i. indicus''<br />showing the diagnostic white wing bar and a broad black band on the white tail
Vanellus indicus - Laem Phak Bia.jpg|''V. i. atronuchalis'' showing the white ear patch bounded by black, [[थाईलैंड]]
Vanellus indicus.jpg|''V. i. aigneri''<br />[[तुर्कीए]]
Red-wattled lapwing (Vanellus indicus lankae).jpg|''V. i. lankae''<br />[[श्री लंका]]
</gallery>
{{clear}}
== नोट ==
{{notelist}}
== संदर्भ ==
{{Reflist|29em}}
{{bird-stub}}
7emy0hy5s7bymethkl19zrqw9u5futl
लेखक
0
100480
790055
790043
2026-04-02T16:30:34Z
SM7
3953
बिस्तार कइल गइल
790055
wikitext
text/x-wiki
{{Infobox Occupation
| name= Writer
| image=
| caption=
| official_names=
<!------------Details------------------->
| type=
| activity_sector = [[साहित्य]]
| competencies = [[भाषा प्रवीणता]], [[ग्रामर]], [[लिटरेसी]]
| formation =
| employment_field = [[मास मीडिया]], [[सोशल मीडिया]]
| related_occupation = {{flatlist|
* [[जर्नलिस्ट]]
* [[उपन्यासकार]]
* [[कवि]]
* [[कॉलम लेखक]]
}}
| average_salary=
}}
'''लेखक''' ({{Langx|en|writer}}) ऊ ब्यक्ति होला, जे लिखल शब्दन के इस्तेमाल कइ के अलग-अलग लिखाई के तरीका (इस्टाइल), बिधा (जॉनर) आ टेकनीक के माध्यम से आपन बिचार व्यक्त करेला, भावना जगावेला, चाहे लोगन के मनोरंजन करेला। लेखक लोग कई तरह के रचना तइयार कर सकेला—जइसे [[उपन्यास]], छोट [[कहानी]], मोनोग्राफ, यात्रा-वृत्तांत, [[नाटक]], फिलिम स्क्रिप्ट, टीवी स्क्रिप्ट, गीत, [[निबंध]], आ साथे-साथ रिपोर्ट, शैक्षणिक सामग्री आ समाचार लेख, जवन आम लोग खातिर उपयोगी हो सकेला। आज के समय में लेखक लोग के रचना कई तरह के माध्यम (मीडिया) पर प्रकाशित होखे ला। जे लेखक भाषा के सही तरीका से इस्तेमाल करके अपना विचार साफ-साफ व्यक्त कर सकेला, ऊ समाज के सांस्कृतिक विकास में महत्वपूर्ण योगदान देला।<ref>{{cite book |last1=Magill |first1=Frank N.|title=Cyclopedia of World Authors|edition=revised |volume=I, II, III |year=1974 |publisher=Salem Press |location=Englewood Cliffs, New Jersey |pages=1–1973}} [A compilation of the bibliographies and short biographies of notable authors up to 1974.]</ref>
लेखक शब्द के इस्तेमाल कला आ संगीत में भी होला, जइसे गीतकार के अंग्रेजी में सॉंगराइटर, स्क्रिप्ट लेखक के स्क्रीनराइटर, बाकिर अकेले लेखक भर कहल जाए पर आमतौर पर लिखित भाषा में रचना करे वाला व्यक्ति बूझल जाला। कुछ लेखक मौखिक/वाचिक परंपरा (ओरल ट्रेडीशन) से भी काम करेलें। लेखक लोग कई तरह के विधा (जॉनर) में लिख सकेला—काल्पनिक (फिक्शन) आ गैर-काल्पनिक (नॉन-फिक्शन) दुनो में। कुछ लेखक अपना विचार के बेहतर ढंग से समझावे खातिर चित्र (ग्राफिक्स) या चित्रांकन (इलस्ट्रेशन) के भी इस्तेमाल करेलें। आजकल सरकारी आ सार्वजनिक क्षेत्र में टेक्निकल राइटर लोगन के भी डिमांड बढ़ गइल बा, जवन आसान भाषा में उपयोगी या वैज्ञानिक जानकारी वाला दस्तावेज तैयार करेलें। कुछ लेखक अपना लिखाई के साथे चित्र, पेंटिंग या मल्टीमीडिया के इस्तेमाल करके बात के अउरी साफ करेलें। कभी-कभी (हालाँकि, बहुते कम स्थिति में) रचनात्मक लेखक अपना विचार के अभिव्यक्ति संगीत के माध्यम से भी कर सकेलें, खाली शब्द से ना।
[[अंग्रेजी]] के में लेखक खातिर दू गो शब्द चलन में बाड़ें - आम शब्द 'राइटर' हवे आ दूसर शब्द 'ऑथर' ह। हालाँकि, ऑथर शब्द में कानूनी जिम्मेदारी के भाव निहित होला भले लिखे वाला बेनाम चाहे अनाम (एनोनिमस) रहे। ऑथर आमतौर प [[किताब]] के लेखक खातिर<ref>{{Cite web|url=https://www.merriam-webster.com/dictionary/author|title=Definition of AUTHOR|website=www.merriam-webster.com|date=12 October 2023 }}</ref> आ रिसर्च संबंधी चीज ([[रिसर्च पेपर|परचा]], थीसिस इत्यादि) के लिखे वाला खातिर इस्तेमाल होखे ला।
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:लेखक| ]]
[[श्रेणी:पेशा अनुसार लोग]]
[[श्रेणी:साहित्य के क्षेत्र के लोग]]
[[श्रेणी:साहित्यकार]]
0ujghh1juxt9h09x22jlhoh24ts6jox
विकिपीडिया:आँकड़ा सभ/२०२६/अप्रैल
4
100481
790076
790044
2026-04-02T19:21:32Z
NeechalBOT
7874
statistics
790076
wikitext
text/x-wiki
<!--- stats starts--->{{प्रयोगकर्ता:Neechalkaran/statnotice}}{| class="wikitable sortable" style="width:90%"
|-
! Date(Time)
! Pages
! Articles
! Edits
! Users
! Files
! Activeusers
{{User:Neechalkaran/template/daily
|Date =१-४-२०२६
|Pages = 81295
|dPages = 8
|Articles = 8958
|dArticles = 5
|Edits = 788919
|dEdits = 46
|Files = 54
|dFiles = 0
|Users = 39619
|dUsers = 4
|Ausers = 43
|dAusers = 0
}}
{{User:Neechalkaran/template/daily
|Date =२-४-२०२६
|Pages = 81297
|dPages = 2
|Articles = 8957
|dArticles = -1
|Edits = 788958
|dEdits = 39
|Files = 54
|dFiles = 0
|Users = 39626
|dUsers = 7
|Ausers = 43
|dAusers = 0
}}
<!---Place new stats here--->
|}
<!--- stats ends--->
4mc08vf6a213iu4f4pwg5rnltrro9eg
प्रयोगकर्ता वार्ता:Bubutisharidhi
3
100486
790054
2026-04-02T13:59:00Z
नया सदस्य स्वागतकर्ता
6624
Adding [[Welcome|welcome message]] to new user's talk page
790054
wikitext
text/x-wiki
{| id="GeoPort-upper" width="100%" cellpadding="5" cellspacing="6" style="background:#FFFAFF; text-align: justify; border-style:ridge; border-width:1px; border-color:#A9A9A9;"
|-
|<div style="display:inline-block;margin-top:.1em; text-align:right; margin-bottom:.2em; border-bottom:0; font-weight:bold;"><big>Welcome! स्वागतम्!</big> [[File:Crystal Clear app ksmiletris.png|25px]] </div>
राउर बहुत-बहुत स्वागत बा '''{{BASEPAGENAME}}''' जी ! {{#if: | {{{1}}} | }}<br/>
<div style="float:right; <!--background:#F5F5DC;--> width:30%">
<!-- दाहिना साइडबार -->
{| border="5" cellspacing="10" cellpadding="5" height="50" align=center border=0 style="background: transparent"
|-
| <big>'''ई जरूर पढ़ल जाय:'''</big>
|-
| style="background-color:#FFFFFF; border: solid 2px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:विकिपीडिया का ना हवे|विकिपीडिया का ना हवे?]]
|-
| style="background-color:#FFFFFF; border: solid 2px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:भोजपुरी में कइसे टाइप करब?|भोजपुरी में टाइपिंग]]
|-
| style="background-color:#FFFFFF; border: solid 1px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:सत्यापन जोग|प्रमाणित बात लिखीं]]
|-
| style="background-color:#FFFFFF; border: solid 1px #FFFFFF; padding:10px 20px;" | [[मदद:फुटनोट|संदर्भ कइसे जोड़ीं?]]
|-
| style="background-color:#FFFFFF; border: solid 1px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:नीति अउरी दिसानिर्देस|विकिनीति आ निर्देश]]
|}</div>
<!-- मुख्य पाठ -->
'''{{#if: | {{{1}}} | {{BASEPAGENAME}} }} जी''',
एह समय रउँआ [[विकिमीडिया फाउन्डेशन]] के परियोजना [[भोजपुरी]] [[विकिपीडिया]] पर बाड़ीं। भोजपुरी विकिपीडिया एगो मुक्त डिजिटल [[ज्ञानकोश]] हवे, जेवन अइसन भइया-बहिनी लोग मिल के लिखले बा जे ज्ञान बाँटे में बिस्वास करत बाटे। एह समय ए परियोजना में [[विशेष:ActiveUsers|{{NUMBEROFUSERS}} सदस्य]] लोग शामिल बाटे। ई बहुते खुशी क बाति बा कि रउँओं ए में शामिल हो गइल बाड़ीं।
* पहिले से बनल [[विकिपीडिया:लेख|लेखवन]] में कौनो संपादन खाली टेस्ट करे खातिर मत करीं। कौनों तरह के परीक्षण <small>(प्रयोग या टेस्टिंग)</small> [[विकिपीडिया:अभ्यास पन्ना|अभ्यास पन्ना]] या [[Special:MyPage/sandbox|अपना अभ्यास पन्ना]] पर करीं।
* [[विकिपीडिया:आपन परिचय कइसे देईं?|आपन परिचय]] आप संछेप में [[प्रयोगकर्ता:{{BASEPAGENAME}}|अपना सदस्य पन्ना]] पर दे सकत बानी। बहुत पर्सनल बात इहाँ मत लिखीं, न कौनों परचार वाली बात लिखीं। अपने खुद के बारे में लेख मत बनाईं।
* दुसरा [[विकिपीडिया:चौपाल |सदस्य लोगन से बात]] करत समय, [[मदद:वार्ता पन्ना|बातचीत पन्ना]] पर सनेसा लिखले की बाद आपन [[विकिपीडिया:दसखत|दसखत]] <small>(हस्ताक्षर)</small> जरूर करीं। एकरा खातिर अंत में चार गो टेढ़का डैश (<nowiki>~~~~</nowiki>) लिख देंईं या टूलबार में [[File:Insert-signature2.svg|link=|alt=]] पर क्लिक करीं।
* मदद चाहत होखीं त विकिपीडिया के [[विकिपीडिया:मदद|मदद पन्ना]] पर जाईं।
<!-- फुटर के कड़ी सभ -->
सीखे-समझे खातिर कुछ अउरी कड़ी नीचे दिहल जात बाटे:
{| border="5" cellspacing="1" cellpadding="0" height="50" align=center border=0 style="background: transparent"
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 10px;" | [[विकिपीडिया:स्वशिक्षा|शुरू से सीखीं]]
|
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[मदद:संपादन|संपादन सीखीं]]
|
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:नया लेख कइसे सुरू करीं?|नया लेख]]
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:अइसन लेख मना बाटे|लेख मनाहीं]]
|
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:पंचशील|पंचशील]]
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:समुदाय पोर्टल|सदस्य समाज पन्ना]]
|}
|}
-- [[प्रयोगकर्ता:नया सदस्य स्वागतकर्ता|नया सदस्य स्वागतकर्ता]] ([[प्रयोगकर्ता वार्ता:नया सदस्य स्वागतकर्ता|बात करीं]]) 13:59, 2 अप्रैल 2026 (UTC)
k8shx8eod32kzo6fv6o23h1jwmj2i38
आर्टेमिस 2
0
100487
790059
2026-04-02T16:45:21Z
SM7
3953
नया आधार लेख
790059
wikitext
text/x-wiki
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित आकासबिमान वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे।
{{clear}}
bw1wt2mju2hgal8c6kczjirzzhc2d30
790060
790059
2026-04-02T16:52:16Z
SM7
3953
ज्ञानसंदूक जोड़ल गइल
790060
wikitext
text/x-wiki
{{Infobox spaceflight
| name = Artemis II
| names_list = {{Unbulleted list | Artemis 2 | Exploration Mission-2 (EM-2)}}
| image = Artemis II Launch (NHQ202604010307, vertical crop).jpg
| image_caption = The [[Space Launch System]] (SLS) rocket for Artemis II lifts off from Launch Complex 39B at NASA's Kennedy Space Center in Florida on {{nowrap|April 1, 2026}}
| mission_type = मानव सहित चंद्रमा के पास से हो के उड़ान
| operator = [[नासा]]
| COSPAR_ID = <!-- Wikidata -->
| SATCAT = <!-- Wikidata -->
| mission_duration = {{time interval|1 April 2026 22:35:12||show=dhm}} ''(चल रहल बाटे)''<br />10 दिन (''प्लानिंग बाटे'')
| distance_travelled =
| spacecraft = {{ubli
| [[ओरियन (स्पेसक्राफ्ट)#व्हीकल सभ के लिस्ट|Orion CM-003]] ''Integrity''{{r |twitter1}}
| [[यूरोपियन सर्विस मॉड्यूल|ESM-2]]
}}
| manufacturer = {{ubli
| Orion: लॉकहीड मार्टिन
| ESM: एयरबस
}}
| landing_mass =
| dimensions =
| power = <!-- [[watt]]s -->
| crew_size = 4
| crew_members = {{Unbulleted list
| [[Reid Wiseman]]
| [[Victor Glover]]
| [[Christina Koch]]
| [[Jeremy Hansen]]
}}
| launch_date = April 1, 2026, 22:35:12 [[UTC]] (6:35:12 p.m. [[Eastern Daylight Time|EDT]])<ref name="Clark 2026-02-21">{{Cite news |last=Clark |first=Stephen |date=February 21, 2026 |title=NASA says it needs to haul the Artemis II rocket back to the hangar for repairs |url=https://arstechnica.com/space/2026/02/nasa-says-it-needs-to-haul-the-artemis-ii-rocket-back-to-the-hangar-for-repairs/ |access-date=February 22, 2026 |work=Ars Technica |language=en}}</ref><ref name="NASA Launch Time" />
| launch_rocket = [[स्पेस लॉन्च सिस्टम]]
| launch_site = [[केनेडी स्पेस सेंटर|केनेडी]], LC-39B<ref name="HEOC">{{Cite web |last=Hill |first=Bill |date=March 2012 |title=Exploration Systems Development Status |url=http://www.nasa.gov/pdf/630149main_5-Hill_SLS%20MPCV%20GSDO_508.pdf |url-status=live |archive-url=https://web.archive.org/web/20170211204753/https://www.nasa.gov/pdf/630149main_5-Hill_SLS |archive-date=February 11, 2017 |access-date=July 21, 2012 |publisher=NASA Advisory Council}} {{Source attribution}}</ref>
| recovery_by = [[अमेरिकी नेवी|U.S. Navy]] ({{sclass|San Antonio|amphibious transport dock|1}})
| landing_date = {{Abbr|NET|एकरा पहिले ना}} अप्रैल 11, 2026, 00:21 UTC (अप्रैल 10, 5:21 p.m. [[पैसिफिक डेलाईट टाइम|PDT]])<ref>{{Cite web |title=Next Spaceflight |url=https://nextspaceflight.com/ |access-date=April 1, 2026 |website=Next Spaceflight |language=en}}</ref>
| landing_site = [[प्रशांत महासागर]] (''प्लानिंग बाटे'')
}}
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित आकासबिमान वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे।
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
m61egymqar7ej4hagc1vrmfmdmnky6o
790061
790060
2026-04-02T16:52:51Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:अंतरिक्ष उड़ान]] जोड़ल गइल
790061
wikitext
text/x-wiki
{{Infobox spaceflight
| name = Artemis II
| names_list = {{Unbulleted list | Artemis 2 | Exploration Mission-2 (EM-2)}}
| image = Artemis II Launch (NHQ202604010307, vertical crop).jpg
| image_caption = The [[Space Launch System]] (SLS) rocket for Artemis II lifts off from Launch Complex 39B at NASA's Kennedy Space Center in Florida on {{nowrap|April 1, 2026}}
| mission_type = मानव सहित चंद्रमा के पास से हो के उड़ान
| operator = [[नासा]]
| COSPAR_ID = <!-- Wikidata -->
| SATCAT = <!-- Wikidata -->
| mission_duration = {{time interval|1 April 2026 22:35:12||show=dhm}} ''(चल रहल बाटे)''<br />10 दिन (''प्लानिंग बाटे'')
| distance_travelled =
| spacecraft = {{ubli
| [[ओरियन (स्पेसक्राफ्ट)#व्हीकल सभ के लिस्ट|Orion CM-003]] ''Integrity''{{r |twitter1}}
| [[यूरोपियन सर्विस मॉड्यूल|ESM-2]]
}}
| manufacturer = {{ubli
| Orion: लॉकहीड मार्टिन
| ESM: एयरबस
}}
| landing_mass =
| dimensions =
| power = <!-- [[watt]]s -->
| crew_size = 4
| crew_members = {{Unbulleted list
| [[Reid Wiseman]]
| [[Victor Glover]]
| [[Christina Koch]]
| [[Jeremy Hansen]]
}}
| launch_date = April 1, 2026, 22:35:12 [[UTC]] (6:35:12 p.m. [[Eastern Daylight Time|EDT]])<ref name="Clark 2026-02-21">{{Cite news |last=Clark |first=Stephen |date=February 21, 2026 |title=NASA says it needs to haul the Artemis II rocket back to the hangar for repairs |url=https://arstechnica.com/space/2026/02/nasa-says-it-needs-to-haul-the-artemis-ii-rocket-back-to-the-hangar-for-repairs/ |access-date=February 22, 2026 |work=Ars Technica |language=en}}</ref><ref name="NASA Launch Time" />
| launch_rocket = [[स्पेस लॉन्च सिस्टम]]
| launch_site = [[केनेडी स्पेस सेंटर|केनेडी]], LC-39B<ref name="HEOC">{{Cite web |last=Hill |first=Bill |date=March 2012 |title=Exploration Systems Development Status |url=http://www.nasa.gov/pdf/630149main_5-Hill_SLS%20MPCV%20GSDO_508.pdf |url-status=live |archive-url=https://web.archive.org/web/20170211204753/https://www.nasa.gov/pdf/630149main_5-Hill_SLS |archive-date=February 11, 2017 |access-date=July 21, 2012 |publisher=NASA Advisory Council}} {{Source attribution}}</ref>
| recovery_by = [[अमेरिकी नेवी|U.S. Navy]] ({{sclass|San Antonio|amphibious transport dock|1}})
| landing_date = {{Abbr|NET|एकरा पहिले ना}} अप्रैल 11, 2026, 00:21 UTC (अप्रैल 10, 5:21 p.m. [[पैसिफिक डेलाईट टाइम|PDT]])<ref>{{Cite web |title=Next Spaceflight |url=https://nextspaceflight.com/ |access-date=April 1, 2026 |website=Next Spaceflight |language=en}}</ref>
| landing_site = [[प्रशांत महासागर]] (''प्लानिंग बाटे'')
}}
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित आकासबिमान वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे।
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:अंतरिक्ष उड़ान]]
daw2pl1dphwtcew532fqrp1hqo5snil
790062
790061
2026-04-02T16:54:50Z
SM7
3953
+टैग
790062
wikitext
text/x-wiki
{{Current|date=April 2026}}{{Infobox spaceflight
| name = Artemis II
| names_list = {{Unbulleted list | Artemis 2 | Exploration Mission-2 (EM-2)}}
| image = Artemis II Launch (NHQ202604010307, vertical crop).jpg
| image_caption = The [[Space Launch System]] (SLS) rocket for Artemis II lifts off from Launch Complex 39B at NASA's Kennedy Space Center in Florida on {{nowrap|April 1, 2026}}
| mission_type = मानव सहित चंद्रमा के पास से हो के उड़ान
| operator = [[नासा]]
| COSPAR_ID = <!-- Wikidata -->
| SATCAT = <!-- Wikidata -->
| mission_duration = {{time interval|1 April 2026 22:35:12||show=dhm}} ''(चल रहल बाटे)''<br />10 दिन (''प्लानिंग बाटे'')
| distance_travelled =
| spacecraft = {{ubli
| [[ओरियन (स्पेसक्राफ्ट)#व्हीकल सभ के लिस्ट|Orion CM-003]] ''Integrity''{{r |twitter1}}
| [[यूरोपियन सर्विस मॉड्यूल|ESM-2]]
}}
| manufacturer = {{ubli
| Orion: लॉकहीड मार्टिन
| ESM: एयरबस
}}
| landing_mass =
| dimensions =
| power = <!-- [[watt]]s -->
| crew_size = 4
| crew_members = {{Unbulleted list
| [[Reid Wiseman]]
| [[Victor Glover]]
| [[Christina Koch]]
| [[Jeremy Hansen]]
}}
| launch_date = April 1, 2026, 22:35:12 [[UTC]] (6:35:12 p.m. [[Eastern Daylight Time|EDT]])<ref name="Clark 2026-02-21">{{Cite news |last=Clark |first=Stephen |date=February 21, 2026 |title=NASA says it needs to haul the Artemis II rocket back to the hangar for repairs |url=https://arstechnica.com/space/2026/02/nasa-says-it-needs-to-haul-the-artemis-ii-rocket-back-to-the-hangar-for-repairs/ |access-date=February 22, 2026 |work=Ars Technica |language=en}}</ref><ref name="NASA Launch Time" />
| launch_rocket = [[स्पेस लॉन्च सिस्टम]]
| launch_site = [[केनेडी स्पेस सेंटर|केनेडी]], LC-39B<ref name="HEOC">{{Cite web |last=Hill |first=Bill |date=March 2012 |title=Exploration Systems Development Status |url=http://www.nasa.gov/pdf/630149main_5-Hill_SLS%20MPCV%20GSDO_508.pdf |url-status=live |archive-url=https://web.archive.org/web/20170211204753/https://www.nasa.gov/pdf/630149main_5-Hill_SLS |archive-date=February 11, 2017 |access-date=July 21, 2012 |publisher=NASA Advisory Council}} {{Source attribution}}</ref>
| recovery_by = [[अमेरिकी नेवी|U.S. Navy]] ({{sclass|San Antonio|amphibious transport dock|1}})
| landing_date = {{Abbr|NET|एकरा पहिले ना}} अप्रैल 11, 2026, 00:21 UTC (अप्रैल 10, 5:21 p.m. [[पैसिफिक डेलाईट टाइम|PDT]])<ref>{{Cite web |title=Next Spaceflight |url=https://nextspaceflight.com/ |access-date=April 1, 2026 |website=Next Spaceflight |language=en}}</ref>
| landing_site = [[प्रशांत महासागर]] (''प्लानिंग बाटे'')
}}
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित आकासबिमान वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे।
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:अंतरिक्ष उड़ान]]
d6qf8a9yskl51riqrqt1jhh6rwr6rcm
790066
790062
2026-04-02T17:05:24Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:नासा के अंतरिक्ष बिमान]] जोड़ल गइल
790066
wikitext
text/x-wiki
{{Current|date=April 2026}}{{Infobox spaceflight
| name = Artemis II
| names_list = {{Unbulleted list | Artemis 2 | Exploration Mission-2 (EM-2)}}
| image = Artemis II Launch (NHQ202604010307, vertical crop).jpg
| image_caption = The [[Space Launch System]] (SLS) rocket for Artemis II lifts off from Launch Complex 39B at NASA's Kennedy Space Center in Florida on {{nowrap|April 1, 2026}}
| mission_type = मानव सहित चंद्रमा के पास से हो के उड़ान
| operator = [[नासा]]
| COSPAR_ID = <!-- Wikidata -->
| SATCAT = <!-- Wikidata -->
| mission_duration = {{time interval|1 April 2026 22:35:12||show=dhm}} ''(चल रहल बाटे)''<br />10 दिन (''प्लानिंग बाटे'')
| distance_travelled =
| spacecraft = {{ubli
| [[ओरियन (स्पेसक्राफ्ट)#व्हीकल सभ के लिस्ट|Orion CM-003]] ''Integrity''{{r |twitter1}}
| [[यूरोपियन सर्विस मॉड्यूल|ESM-2]]
}}
| manufacturer = {{ubli
| Orion: लॉकहीड मार्टिन
| ESM: एयरबस
}}
| landing_mass =
| dimensions =
| power = <!-- [[watt]]s -->
| crew_size = 4
| crew_members = {{Unbulleted list
| [[Reid Wiseman]]
| [[Victor Glover]]
| [[Christina Koch]]
| [[Jeremy Hansen]]
}}
| launch_date = April 1, 2026, 22:35:12 [[UTC]] (6:35:12 p.m. [[Eastern Daylight Time|EDT]])<ref name="Clark 2026-02-21">{{Cite news |last=Clark |first=Stephen |date=February 21, 2026 |title=NASA says it needs to haul the Artemis II rocket back to the hangar for repairs |url=https://arstechnica.com/space/2026/02/nasa-says-it-needs-to-haul-the-artemis-ii-rocket-back-to-the-hangar-for-repairs/ |access-date=February 22, 2026 |work=Ars Technica |language=en}}</ref><ref name="NASA Launch Time" />
| launch_rocket = [[स्पेस लॉन्च सिस्टम]]
| launch_site = [[केनेडी स्पेस सेंटर|केनेडी]], LC-39B<ref name="HEOC">{{Cite web |last=Hill |first=Bill |date=March 2012 |title=Exploration Systems Development Status |url=http://www.nasa.gov/pdf/630149main_5-Hill_SLS%20MPCV%20GSDO_508.pdf |url-status=live |archive-url=https://web.archive.org/web/20170211204753/https://www.nasa.gov/pdf/630149main_5-Hill_SLS |archive-date=February 11, 2017 |access-date=July 21, 2012 |publisher=NASA Advisory Council}} {{Source attribution}}</ref>
| recovery_by = [[अमेरिकी नेवी|U.S. Navy]] ({{sclass|San Antonio|amphibious transport dock|1}})
| landing_date = {{Abbr|NET|एकरा पहिले ना}} अप्रैल 11, 2026, 00:21 UTC (अप्रैल 10, 5:21 p.m. [[पैसिफिक डेलाईट टाइम|PDT]])<ref>{{Cite web |title=Next Spaceflight |url=https://nextspaceflight.com/ |access-date=April 1, 2026 |website=Next Spaceflight |language=en}}</ref>
| landing_site = [[प्रशांत महासागर]] (''प्लानिंग बाटे'')
}}
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित आकासबिमान वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे।
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:अंतरिक्ष उड़ान]]
[[श्रेणी:नासा के अंतरिक्ष बिमान]]
jc6bpihgtvwqhess317ezb39if1k7dh
790067
790066
2026-04-02T17:05:37Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:नासा]] जोड़ल गइल
790067
wikitext
text/x-wiki
{{Current|date=April 2026}}{{Infobox spaceflight
| name = Artemis II
| names_list = {{Unbulleted list | Artemis 2 | Exploration Mission-2 (EM-2)}}
| image = Artemis II Launch (NHQ202604010307, vertical crop).jpg
| image_caption = The [[Space Launch System]] (SLS) rocket for Artemis II lifts off from Launch Complex 39B at NASA's Kennedy Space Center in Florida on {{nowrap|April 1, 2026}}
| mission_type = मानव सहित चंद्रमा के पास से हो के उड़ान
| operator = [[नासा]]
| COSPAR_ID = <!-- Wikidata -->
| SATCAT = <!-- Wikidata -->
| mission_duration = {{time interval|1 April 2026 22:35:12||show=dhm}} ''(चल रहल बाटे)''<br />10 दिन (''प्लानिंग बाटे'')
| distance_travelled =
| spacecraft = {{ubli
| [[ओरियन (स्पेसक्राफ्ट)#व्हीकल सभ के लिस्ट|Orion CM-003]] ''Integrity''{{r |twitter1}}
| [[यूरोपियन सर्विस मॉड्यूल|ESM-2]]
}}
| manufacturer = {{ubli
| Orion: लॉकहीड मार्टिन
| ESM: एयरबस
}}
| landing_mass =
| dimensions =
| power = <!-- [[watt]]s -->
| crew_size = 4
| crew_members = {{Unbulleted list
| [[Reid Wiseman]]
| [[Victor Glover]]
| [[Christina Koch]]
| [[Jeremy Hansen]]
}}
| launch_date = April 1, 2026, 22:35:12 [[UTC]] (6:35:12 p.m. [[Eastern Daylight Time|EDT]])<ref name="Clark 2026-02-21">{{Cite news |last=Clark |first=Stephen |date=February 21, 2026 |title=NASA says it needs to haul the Artemis II rocket back to the hangar for repairs |url=https://arstechnica.com/space/2026/02/nasa-says-it-needs-to-haul-the-artemis-ii-rocket-back-to-the-hangar-for-repairs/ |access-date=February 22, 2026 |work=Ars Technica |language=en}}</ref><ref name="NASA Launch Time" />
| launch_rocket = [[स्पेस लॉन्च सिस्टम]]
| launch_site = [[केनेडी स्पेस सेंटर|केनेडी]], LC-39B<ref name="HEOC">{{Cite web |last=Hill |first=Bill |date=March 2012 |title=Exploration Systems Development Status |url=http://www.nasa.gov/pdf/630149main_5-Hill_SLS%20MPCV%20GSDO_508.pdf |url-status=live |archive-url=https://web.archive.org/web/20170211204753/https://www.nasa.gov/pdf/630149main_5-Hill_SLS |archive-date=February 11, 2017 |access-date=July 21, 2012 |publisher=NASA Advisory Council}} {{Source attribution}}</ref>
| recovery_by = [[अमेरिकी नेवी|U.S. Navy]] ({{sclass|San Antonio|amphibious transport dock|1}})
| landing_date = {{Abbr|NET|एकरा पहिले ना}} अप्रैल 11, 2026, 00:21 UTC (अप्रैल 10, 5:21 p.m. [[पैसिफिक डेलाईट टाइम|PDT]])<ref>{{Cite web |title=Next Spaceflight |url=https://nextspaceflight.com/ |access-date=April 1, 2026 |website=Next Spaceflight |language=en}}</ref>
| landing_site = [[प्रशांत महासागर]] (''प्लानिंग बाटे'')
}}
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित आकासबिमान वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे।
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:अंतरिक्ष उड़ान]]
[[श्रेणी:नासा के अंतरिक्ष बिमान]]
[[श्रेणी:नासा]]
jq75wi1x3crgjend1dnmrkxfloztnxp
790113
790067
2026-04-03T08:28:01Z
SM7
3953
अनुबाद कइल गइल
790113
wikitext
text/x-wiki
{{Current|date=अप्रैल 2026}}{{Infobox spaceflight
| name = आर्टेमिस 2
| names_list = {{Unbulleted list | Artemis II| Artemis 2 | Exploration Mission-2 (EM-2)| एक्सप्लोरेशन मिशन-2 (ईएम-2)}}
| image = Artemis II Launch (NHQ202604010307, vertical crop).jpg
| image_caption = The [[Space Launch System]] (SLS) rocket for Artemis II lifts off from Launch Complex 39B at NASA's Kennedy Space Center in Florida on {{nowrap|April 1, 2026}}
| mission_type = मानव सहित चंद्रमा के पास से हो के उड़ान
| operator = [[नासा]]
| COSPAR_ID = <!-- Wikidata -->
| SATCAT = <!-- Wikidata -->
| mission_duration = {{time interval|1 April 2026 22:35:12||show=dhm}} ''(चल रहल बाटे)''<br />10 दिन (''प्लानिंग बाटे'')
| distance_travelled =
| spacecraft = {{ubli
| [[ओरियन (स्पेसक्राफ्ट)#व्हीकल सभ के लिस्ट|Orion CM-003]] ''Integrity''{{r |twitter1}}
| [[यूरोपियन सर्विस मॉड्यूल|ESM-2]]
}}
| manufacturer = {{ubli
| Orion: लॉकहीड मार्टिन
| ESM: एयरबस
}}
| landing_mass =
| dimensions =
| power = <!-- [[watt]]s -->
| crew_size = 4
| crew_members = {{Unbulleted list
| [[Reid Wiseman]]
| [[Victor Glover]]
| [[Christina Koch]]
| [[Jeremy Hansen]]
}}
| launch_date = April 1, 2026, 22:35:12 [[UTC]] (6:35:12 p.m. [[Eastern Daylight Time|EDT]])<ref name="Clark 2026-02-21">{{Cite news |last=Clark |first=Stephen |date=February 21, 2026 |title=NASA says it needs to haul the Artemis II rocket back to the hangar for repairs |url=https://arstechnica.com/space/2026/02/nasa-says-it-needs-to-haul-the-artemis-ii-rocket-back-to-the-hangar-for-repairs/ |access-date=February 22, 2026 |work=Ars Technica |language=en}}</ref><ref name="NASA Launch Time" />
| launch_rocket = [[स्पेस लॉन्च सिस्टम]]
| launch_site = [[केनेडी स्पेस सेंटर|केनेडी]], LC-39B<ref name="HEOC">{{Cite web |last=Hill |first=Bill |date=March 2012 |title=Exploration Systems Development Status |url=http://www.nasa.gov/pdf/630149main_5-Hill_SLS%20MPCV%20GSDO_508.pdf |url-status=live |archive-url=https://web.archive.org/web/20170211204753/https://www.nasa.gov/pdf/630149main_5-Hill_SLS |archive-date=February 11, 2017 |access-date=July 21, 2012 |publisher=NASA Advisory Council}} {{Source attribution}}</ref>
| recovery_by = [[अमेरिकी नेवी|U.S. Navy]] ({{sclass|San Antonio|amphibious transport dock|1}})
| landing_date = {{Abbr|NET|एकरा पहिले ना}} अप्रैल 11, 2026, 00:21 UTC (अप्रैल 10, 5:21 p.m. [[पैसिफिक डेलाईट टाइम|PDT]])<ref>{{Cite web |title=Next Spaceflight |url=https://nextspaceflight.com/ |access-date=April 1, 2026 |website=Next Spaceflight |language=en}}</ref>
| landing_site = [[प्रशांत महासागर]] (''प्लानिंग बाटे'')
}}
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित आकासबिमान वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे।
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:अंतरिक्ष उड़ान]]
[[श्रेणी:नासा के अंतरिक्ष बिमान]]
[[श्रेणी:नासा]]
6xqvmntyeos8658bhy32c51a5t2nxl9
790114
790113
2026-04-03T08:32:07Z
SM7
3953
अनुबाद कइल गइल
790114
wikitext
text/x-wiki
{{Current|date=अप्रैल 2026}}{{Infobox spaceflight
| name = आर्टेमिस 2
| names_list = {{Unbulleted list | Artemis II| Artemis 2 | Exploration Mission-2 (EM-2)| एक्सप्लोरेशन मिशन-2 (ईएम-2)}}
| image = Artemis II Launch (NHQ202604010307, vertical crop).jpg
| image_caption = The [[Space Launch System]] (SLS) rocket for Artemis II lifts off from Launch Complex 39B at NASA's Kennedy Space Center in Florida on {{nowrap|April 1, 2026}}
| mission_type = मानव सहित चंद्रमा के पास से हो के उड़ान
| operator = [[नासा]]
| COSPAR_ID = <!-- Wikidata -->
| SATCAT = <!-- Wikidata -->
| mission_duration = {{time interval|1 April 2026 22:35:12||show=dhm}} ''(चल रहल बाटे)''<br />10 दिन (''प्लानिंग बाटे'')
| distance_travelled =
| spacecraft = {{ubli
| [[ओरियन (स्पेसक्राफ्ट)#व्हीकल सभ के लिस्ट|ओरियन सीएम-003]] ''इंटीग्रिटी''{{r |twitter1}}
| [[यूरोपियन सर्विस मॉड्यूल|ईएसएम-2]]
}}
| manufacturer = {{ubli
| ओरियन: लॉकहीड मार्टिन
| ईएसएम: एयरबस
}}
| landing_mass =
| dimensions =
| power = <!-- [[वाट]] -->
| crew_size = 4
| crew_members = {{Unbulleted list
| [[Reid Wiseman]]
| [[Victor Glover]]
| [[Christina Koch]]
| [[Jeremy Hansen]]
}}
| launch_date = 1 अप्रैल 2026, 22:35:12 [[UTC]] (6:35:12 p.m. [[ईस्टर्न डेलाईट टाइम|EDT]])<ref name="Clark 2026-02-21">{{Cite news |last=Clark |first=Stephen |date=February 21, 2026 |title=NASA says it needs to haul the Artemis II rocket back to the hangar for repairs |url=https://arstechnica.com/space/2026/02/nasa-says-it-needs-to-haul-the-artemis-ii-rocket-back-to-the-hangar-for-repairs/ |access-date=February 22, 2026 |work=Ars Technica |language=en}}</ref><ref name="NASA Launch Time" />
| launch_rocket = [[स्पेस लॉन्च सिस्टम]]
| launch_site = [[केनेडी स्पेस सेंटर|केनेडी]], LC-39B<ref name="HEOC">{{Cite web |last=Hill |first=Bill |date=March 2012 |title=Exploration Systems Development Status |url=http://www.nasa.gov/pdf/630149main_5-Hill_SLS%20MPCV%20GSDO_508.pdf |url-status=live |archive-url=https://web.archive.org/web/20170211204753/https://www.nasa.gov/pdf/630149main_5-Hill_SLS |archive-date=February 11, 2017 |access-date=July 21, 2012 |publisher=NASA Advisory Council}} {{Source attribution}}</ref>
| recovery_by = [[अमेरिकी नेवी|अमेरिकी नेवी]] ({{sclass|सैन एंटोनियो|एम्फीबियस ट्रांसपोर्ट डॉक|1}})
| landing_date = {{Abbr|NET|एकरा पहिले ना}} 11अप्रैल 2026, 00:21 UTC (10 अप्रैल 5:21 p.m. [[पैसिफिक डेलाईट टाइम|PDT]])<ref>{{Cite web |title=Next Spaceflight |url=https://nextspaceflight.com/ |access-date=April 1, 2026 |website=Next Spaceflight |language=en}}</ref>
| landing_site = [[प्रशांत महासागर]] (''प्लानिंग बाटे'')
}}
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित आकासबिमान वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे।
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:अंतरिक्ष उड़ान]]
[[श्रेणी:नासा के अंतरिक्ष बिमान]]
[[श्रेणी:नासा]]
98xs6b8c8gxpa7l5t5m5t6gilzx5ug0
790117
790114
2026-04-03T08:33:30Z
SM7
3953
[[User:SM7/stubsorter|Stubsorter]] के मदद से {{Astronomy-stub}} जोड़ल गइल।
790117
wikitext
text/x-wiki
{{Current|date=अप्रैल 2026}}{{Infobox spaceflight
| name = आर्टेमिस 2
| names_list = {{Unbulleted list | Artemis II| Artemis 2 | Exploration Mission-2 (EM-2)| एक्सप्लोरेशन मिशन-2 (ईएम-2)}}
| image = Artemis II Launch (NHQ202604010307, vertical crop).jpg
| image_caption = The [[Space Launch System]] (SLS) rocket for Artemis II lifts off from Launch Complex 39B at NASA's Kennedy Space Center in Florida on {{nowrap|April 1, 2026}}
| mission_type = मानव सहित चंद्रमा के पास से हो के उड़ान
| operator = [[नासा]]
| COSPAR_ID = <!-- Wikidata -->
| SATCAT = <!-- Wikidata -->
| mission_duration = {{time interval|1 April 2026 22:35:12||show=dhm}} ''(चल रहल बाटे)''<br />10 दिन (''प्लानिंग बाटे'')
| distance_travelled =
| spacecraft = {{ubli
| [[ओरियन (स्पेसक्राफ्ट)#व्हीकल सभ के लिस्ट|ओरियन सीएम-003]] ''इंटीग्रिटी''{{r |twitter1}}
| [[यूरोपियन सर्विस मॉड्यूल|ईएसएम-2]]
}}
| manufacturer = {{ubli
| ओरियन: लॉकहीड मार्टिन
| ईएसएम: एयरबस
}}
| landing_mass =
| dimensions =
| power = <!-- [[वाट]] -->
| crew_size = 4
| crew_members = {{Unbulleted list
| [[Reid Wiseman]]
| [[Victor Glover]]
| [[Christina Koch]]
| [[Jeremy Hansen]]
}}
| launch_date = 1 अप्रैल 2026, 22:35:12 [[UTC]] (6:35:12 p.m. [[ईस्टर्न डेलाईट टाइम|EDT]])<ref name="Clark 2026-02-21">{{Cite news |last=Clark |first=Stephen |date=February 21, 2026 |title=NASA says it needs to haul the Artemis II rocket back to the hangar for repairs |url=https://arstechnica.com/space/2026/02/nasa-says-it-needs-to-haul-the-artemis-ii-rocket-back-to-the-hangar-for-repairs/ |access-date=February 22, 2026 |work=Ars Technica |language=en}}</ref><ref name="NASA Launch Time" />
| launch_rocket = [[स्पेस लॉन्च सिस्टम]]
| launch_site = [[केनेडी स्पेस सेंटर|केनेडी]], LC-39B<ref name="HEOC">{{Cite web |last=Hill |first=Bill |date=March 2012 |title=Exploration Systems Development Status |url=http://www.nasa.gov/pdf/630149main_5-Hill_SLS%20MPCV%20GSDO_508.pdf |url-status=live |archive-url=https://web.archive.org/web/20170211204753/https://www.nasa.gov/pdf/630149main_5-Hill_SLS |archive-date=February 11, 2017 |access-date=July 21, 2012 |publisher=NASA Advisory Council}} {{Source attribution}}</ref>
| recovery_by = [[अमेरिकी नेवी|अमेरिकी नेवी]] ({{sclass|सैन एंटोनियो|एम्फीबियस ट्रांसपोर्ट डॉक|1}})
| landing_date = {{Abbr|NET|एकरा पहिले ना}} 11अप्रैल 2026, 00:21 UTC (10 अप्रैल 5:21 p.m. [[पैसिफिक डेलाईट टाइम|PDT]])<ref>{{Cite web |title=Next Spaceflight |url=https://nextspaceflight.com/ |access-date=April 1, 2026 |website=Next Spaceflight |language=en}}</ref>
| landing_site = [[प्रशांत महासागर]] (''प्लानिंग बाटे'')
}}
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित आकासबिमान वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे।
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:अंतरिक्ष उड़ान]]
[[श्रेणी:नासा के अंतरिक्ष बिमान]]
[[श्रेणी:नासा]]
{{Astronomy-stub}}
0y5q7pllyj9447u1v7iunw304kxb6q0
790250
790117
2026-04-03T08:37:14Z
SM7
3953
सुधार कइल गइल
790250
wikitext
text/x-wiki
{{Current|date=अप्रैल 2026}}{{Infobox spaceflight
| name = आर्टेमिस 2
| names_list = {{Unbulleted list | Artemis II| Artemis 2 | Exploration Mission-2 (EM-2)| एक्सप्लोरेशन मिशन-2 (ईएम-2)}}
| image = Artemis II Launch (NHQ202604010307, vertical crop).jpg
| image_caption = The [[Space Launch System]] (SLS) rocket for Artemis II lifts off from Launch Complex 39B at NASA's Kennedy Space Center in Florida on {{nowrap|April 1, 2026}}
| mission_type = मानव सहित चंद्रमा के पास से हो के उड़ान
| operator = [[नासा]]
| COSPAR_ID = <!-- Wikidata -->
| SATCAT = <!-- Wikidata -->
| mission_duration = {{time interval|1 April 2026 22:35:12||show=dhm}} ''(चल रहल बाटे)''<br />10 दिन (''प्लानिंग बाटे'')
| distance_travelled =
| spacecraft = {{ubli
| [[ओरियन (स्पेसक्राफ्ट)#व्हीकल सभ के लिस्ट|ओरियन सीएम-003]] ''इंटीग्रिटी''{{r |twitter1}}
| [[यूरोपियन सर्विस मॉड्यूल|ईएसएम-2]]
}}
| manufacturer = {{ubli
| ओरियन: लॉकहीड मार्टिन
| ईएसएम: एयरबस
}}
| landing_mass =
| dimensions =
| power = <!-- [[वाट]] -->
| crew_size = 4
| crew_members = {{Unbulleted list
| [[Reid Wiseman]]
| [[Victor Glover]]
| [[Christina Koch]]
| [[Jeremy Hansen]]
}}
| launch_date = 1 अप्रैल 2026, 22:35:12 [[UTC]] (6:35:12 p.m. [[ईस्टर्न डेलाईट टाइम|EDT]])<ref name="Clark 2026-02-21">{{Cite news |last=Clark |first=Stephen |date=February 21, 2026 |title=NASA says it needs to haul the Artemis II rocket back to the hangar for repairs |url=https://arstechnica.com/space/2026/02/nasa-says-it-needs-to-haul-the-artemis-ii-rocket-back-to-the-hangar-for-repairs/ |access-date=February 22, 2026 |work=Ars Technica |language=en}}</ref><ref name="NASA Launch Time" />
| launch_rocket = [[स्पेस लॉन्च सिस्टम]]
| launch_site = [[केनेडी स्पेस सेंटर|केनेडी]], LC-39B<ref name="HEOC">{{Cite web |last=Hill |first=Bill |date=March 2012 |title=Exploration Systems Development Status |url=http://www.nasa.gov/pdf/630149main_5-Hill_SLS%20MPCV%20GSDO_508.pdf |url-status=live |archive-url=https://web.archive.org/web/20170211204753/https://www.nasa.gov/pdf/630149main_5-Hill_SLS |archive-date=February 11, 2017 |access-date=July 21, 2012 |publisher=NASA Advisory Council}} {{Source attribution}}</ref>
| recovery_by = [[अमेरिकी नेवी|अमेरिकी नेवी]] ({{sclass|सैन एंटोनियो|एम्फीबियस ट्रांसपोर्ट डॉक|1}})
| landing_date = {{Abbr|NET|एकरा पहिले ना}} 11अप्रैल 2026, 00:21 UTC (10 अप्रैल 5:21 p.m. [[पैसिफिक डेलाईट टाइम|PDT]])<ref>{{Cite web |title=Next Spaceflight |url=https://nextspaceflight.com/ |access-date=April 1, 2026 |website=Next Spaceflight |language=en}}</ref>
| landing_site = [[प्रशांत महासागर]] (''प्लानिंग बाटे'')
}}
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित [[स्पेसक्राफ्ट]] वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला [[स्पेस्फ्लाईट]] मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे।
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:अंतरिक्ष उड़ान]]
[[श्रेणी:नासा के अंतरिक्ष बिमान]]
[[श्रेणी:नासा]]
{{Astronomy-stub}}
f4podm1fm2iuqio07mhi55cnh1kbtlx
790256
790250
2026-04-03T08:50:29Z
SM7
3953
सुधार कइल गइल, संदर्भ जोड़ल/सुधारल गइल
790256
wikitext
text/x-wiki
{{Current|date=अप्रैल 2026}}{{Infobox spaceflight
| name = आर्टेमिस 2
| names_list = {{Unbulleted list | Artemis II| Artemis 2 | Exploration Mission-2 (EM-2)| एक्सप्लोरेशन मिशन-2 (ईएम-2)}}
| image = Artemis II Launch (NHQ202604010307, vertical crop).jpg
| image_caption = The [[Space Launch System]] (SLS) rocket for Artemis II lifts off from Launch Complex 39B at NASA's Kennedy Space Center in Florida on {{nowrap|April 1, 2026}}
| mission_type = मानव सहित चंद्रमा के पास से हो के उड़ान
| operator = [[नासा]]
| COSPAR_ID = <!-- Wikidata -->
| SATCAT = <!-- Wikidata -->
| mission_duration = {{time interval|1 April 2026 22:35:12||show=dhm}} ''(चल रहल बाटे)''<br />10 दिन (''प्लानिंग बाटे'')
| distance_travelled =
| spacecraft = {{ubli
| [[ओरियन (स्पेसक्राफ्ट)#व्हीकल सभ के लिस्ट|ओरियन सीएम-003]] ''इंटीग्रिटी''{{r |twitter1}}
| [[यूरोपियन सर्विस मॉड्यूल|ईएसएम-2]]
}}
| manufacturer = {{ubli
| ओरियन: लॉकहीड मार्टिन
| ईएसएम: एयरबस
}}
| landing_mass =
| dimensions =
| power = <!-- [[वाट]] -->
| crew_size = 4
| crew_members = {{Unbulleted list
| [[Reid Wiseman]]
| [[Victor Glover]]
| [[Christina Koch]]
| [[Jeremy Hansen]]
}}
| launch_date = 1 अप्रैल 2026, 22:35:12 [[UTC]] (6:35:12 p.m. [[ईस्टर्न डेलाईट टाइम|EDT]])<ref name="Clark 2026-02-21">{{Cite news |last=Clark |first=Stephen |date=February 21, 2026 |title=NASA says it needs to haul the Artemis II rocket back to the hangar for repairs |url=https://arstechnica.com/space/2026/02/nasa-says-it-needs-to-haul-the-artemis-ii-rocket-back-to-the-hangar-for-repairs/ |access-date=February 22, 2026 |work=Ars Technica |language=en}}</ref><ref name="NASA Launch Time" />
| launch_rocket = [[स्पेस लॉन्च सिस्टम]]
| launch_site = [[केनेडी स्पेस सेंटर|केनेडी]], LC-39B<ref name="HEOC">{{Cite web |last=Hill |first=Bill |date=March 2012 |title=Exploration Systems Development Status |url=http://www.nasa.gov/pdf/630149main_5-Hill_SLS%20MPCV%20GSDO_508.pdf |url-status=live |archive-url=https://web.archive.org/web/20170211204753/https://www.nasa.gov/pdf/630149main_5-Hill_SLS |archive-date=February 11, 2017 |access-date=July 21, 2012 |publisher=NASA Advisory Council}} {{Source attribution}}</ref>
| recovery_by = [[अमेरिकी नेवी|अमेरिकी नेवी]] ({{sclass|सैन एंटोनियो|एम्फीबियस ट्रांसपोर्ट डॉक|1}})
| landing_date = {{Abbr|NET|एकरा पहिले ना}} 11अप्रैल 2026, 00:21 UTC (10 अप्रैल 5:21 p.m. [[पैसिफिक डेलाईट टाइम|PDT]])<ref>{{Cite web |title=Next Spaceflight |url=https://nextspaceflight.com/ |access-date=April 1, 2026 |website=Next Spaceflight |language=en}}</ref>
| landing_site = [[प्रशांत महासागर]] (''प्लानिंग बाटे'')
}}
'''आर्टेमिस 2''' ({{Langx|en|Artemis II}}) एगो मानव-सहित [[स्पेसक्राफ्ट]] वाला [[चंद्रमा]] के चारों ओर घूम के वापस लवट आवे वाला [[स्पेस्फ्लाईट]] मिशन हवे, जवन [[आर्टेमिस प्रोग्राम]] के हिस्सा बा। ई मिशन 1 अप्रैल 2026 के [[केनेडी स्पेस सेंटर]] से लॉन्च भइल, आ एकरा करीब 10 दिन तक चले के योजना बा। एह मिशन में [[नासा]] के अंतरिक्ष यात्री—रीड वाइज़मैन, विक्टर ग्लोवर, क्रिस्टीना कोच—आ साथे कनाडियन स्पेस एजेंसी के अंतरिक्ष यात्री जेरमी हैनसन शामिल बाड़ें। ई लोग चंद्रमा के चारों ओर फ्री-रिटर्न ट्रेजेक्टरी से घूम के फेर से वापिस धरती पर लउटी। ई मिशन [[स्पेस लॉन्च सिस्टम]] (SLS) के दूसरही उड़ान हवे, [[ओरियन स्पेसक्राफ्ट]] के पहिला मानव-सवार मिशन हवे, आ 1972 में [[अपोलो 17]] के बाद पहिला अइसन मिशन हवे जवन [[निचली अर्थ ऑर्बिट]] से बाहर गइल होखे। एह तरीका से, ई लगभग आधा सदी के बाद होखे वाली अइसन उड़ान बाटे।<ref>{{cite web |title=Artemis II |url=https://www.esa.int/Science_Exploration/Human_and_Robotic_Exploration/Orion/Artemis_II |website=www.esa.int |access-date=3 अप्रैल 2026 |language=en}}</ref>
{{clear}}
== संदर्भ ==
{{Reflist|29em}}
[[श्रेणी:अंतरिक्ष उड़ान]]
[[श्रेणी:नासा के अंतरिक्ष बिमान]]
[[श्रेणी:नासा]]
{{Astronomy-stub}}
gg4f7qakomulszrkwm4queldqigy3wk
आर्टेमिस प्रोग्राम
0
100488
790063
2026-04-02T17:00:33Z
SM7
3953
नया आधार लेख
790063
wikitext
text/x-wiki
'''आर्टेमिस प्रोग्राम''' ({{Langx|en|Artemis program}}) [[चंद्रमा]] के खोज (एक्प्लोरेशन) खातिर बनावल एगो अंतरिक्ष प्रोग्राम हवे, जवन [[नासा]] (अमेरिका के अंतरिक्ष एजेंसी) के अगुआई में चल रहल बा। ई प्रोग्राम 2017 में स्पेस प्रोग्राम डाइरेक्टिव 1 के तहत आधिकारिक रूप से शुरू कइल गइल। एह प्रोग्राम के टारगेट बा कि 2028 तक इंसान के फेर से चंद्रमा के सतह पर भेजल जाव, जवन 1972 में [[अपोलो 17]] के बाद पहिला बेर होखी। आगे चल के, 2030 के दशक में चंद्रमा पर एगो स्थायी बेस बनावे के योजना बा, जवन गहिरा अंतरिक्ष में अउरी आगे ले मानव मिशन खातिर एगो पड़ाव साबित होखी।
वर्तमान में, अप्रैल 2026 में एह प्रोग्राम के तहत [[आर्टेमिस 2]] अंतरिक्ष उड़ान प्रोग्रेस में बाटे। आर्टेमिस 2 के 1 अप्रैल 2026 के केनेडी स्पेस सेंटर से लॉन्च कइल गइल बाटे।
cthagxvxnh34r5o0r9dwblqxljfeww4
790064
790063
2026-04-02T17:04:56Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:अंतरिक्ष कार्यक्रम]] जोड़ल गइल
790064
wikitext
text/x-wiki
'''आर्टेमिस प्रोग्राम''' ({{Langx|en|Artemis program}}) [[चंद्रमा]] के खोज (एक्प्लोरेशन) खातिर बनावल एगो अंतरिक्ष प्रोग्राम हवे, जवन [[नासा]] (अमेरिका के अंतरिक्ष एजेंसी) के अगुआई में चल रहल बा। ई प्रोग्राम 2017 में स्पेस प्रोग्राम डाइरेक्टिव 1 के तहत आधिकारिक रूप से शुरू कइल गइल। एह प्रोग्राम के टारगेट बा कि 2028 तक इंसान के फेर से चंद्रमा के सतह पर भेजल जाव, जवन 1972 में [[अपोलो 17]] के बाद पहिला बेर होखी। आगे चल के, 2030 के दशक में चंद्रमा पर एगो स्थायी बेस बनावे के योजना बा, जवन गहिरा अंतरिक्ष में अउरी आगे ले मानव मिशन खातिर एगो पड़ाव साबित होखी।
वर्तमान में, अप्रैल 2026 में एह प्रोग्राम के तहत [[आर्टेमिस 2]] अंतरिक्ष उड़ान प्रोग्रेस में बाटे। आर्टेमिस 2 के 1 अप्रैल 2026 के केनेडी स्पेस सेंटर से लॉन्च कइल गइल बाटे।
[[श्रेणी:अंतरिक्ष कार्यक्रम]]
08mpu0fm1tvrcxxyg8yzrvfua1ju5ni
790065
790064
2026-04-02T17:05:08Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:नासा]] जोड़ल गइल
790065
wikitext
text/x-wiki
'''आर्टेमिस प्रोग्राम''' ({{Langx|en|Artemis program}}) [[चंद्रमा]] के खोज (एक्प्लोरेशन) खातिर बनावल एगो अंतरिक्ष प्रोग्राम हवे, जवन [[नासा]] (अमेरिका के अंतरिक्ष एजेंसी) के अगुआई में चल रहल बा। ई प्रोग्राम 2017 में स्पेस प्रोग्राम डाइरेक्टिव 1 के तहत आधिकारिक रूप से शुरू कइल गइल। एह प्रोग्राम के टारगेट बा कि 2028 तक इंसान के फेर से चंद्रमा के सतह पर भेजल जाव, जवन 1972 में [[अपोलो 17]] के बाद पहिला बेर होखी। आगे चल के, 2030 के दशक में चंद्रमा पर एगो स्थायी बेस बनावे के योजना बा, जवन गहिरा अंतरिक्ष में अउरी आगे ले मानव मिशन खातिर एगो पड़ाव साबित होखी।
वर्तमान में, अप्रैल 2026 में एह प्रोग्राम के तहत [[आर्टेमिस 2]] अंतरिक्ष उड़ान प्रोग्रेस में बाटे। आर्टेमिस 2 के 1 अप्रैल 2026 के केनेडी स्पेस सेंटर से लॉन्च कइल गइल बाटे।
[[श्रेणी:अंतरिक्ष कार्यक्रम]]
[[श्रेणी:नासा]]
8xqk1nnkfdo4jqzqvkbaejod4flayu6
पार्टन (कण भौतिकी)
0
100489
790071
2026-04-02T17:14:14Z
SM7
3953
SM7 पन्ना [[पार्टन (कण भौतिकी)]] के [[पार्टन (पार्टिकल फिजिक्स)]] पर स्थानांतरण कइलें
790071
wikitext
text/x-wiki
#REDIRECT [[पार्टन (पार्टिकल फिजिक्स)]]
r1ku6beg5cxjxqb1tzyleflxroj4o8v
प्रयोगकर्ता वार्ता:Vikas.1998
3
100490
790090
2026-04-03T01:37:07Z
नया सदस्य स्वागतकर्ता
6624
Adding [[Welcome|welcome message]] to new user's talk page
790090
wikitext
text/x-wiki
{| id="GeoPort-upper" width="100%" cellpadding="5" cellspacing="6" style="background:#FFFAFF; text-align: justify; border-style:ridge; border-width:1px; border-color:#A9A9A9;"
|-
|<div style="display:inline-block;margin-top:.1em; text-align:right; margin-bottom:.2em; border-bottom:0; font-weight:bold;"><big>Welcome! स्वागतम्!</big> [[File:Crystal Clear app ksmiletris.png|25px]] </div>
राउर बहुत-बहुत स्वागत बा '''{{BASEPAGENAME}}''' जी ! {{#if: | {{{1}}} | }}<br/>
<div style="float:right; <!--background:#F5F5DC;--> width:30%">
<!-- दाहिना साइडबार -->
{| border="5" cellspacing="10" cellpadding="5" height="50" align=center border=0 style="background: transparent"
|-
| <big>'''ई जरूर पढ़ल जाय:'''</big>
|-
| style="background-color:#FFFFFF; border: solid 2px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:विकिपीडिया का ना हवे|विकिपीडिया का ना हवे?]]
|-
| style="background-color:#FFFFFF; border: solid 2px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:भोजपुरी में कइसे टाइप करब?|भोजपुरी में टाइपिंग]]
|-
| style="background-color:#FFFFFF; border: solid 1px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:सत्यापन जोग|प्रमाणित बात लिखीं]]
|-
| style="background-color:#FFFFFF; border: solid 1px #FFFFFF; padding:10px 20px;" | [[मदद:फुटनोट|संदर्भ कइसे जोड़ीं?]]
|-
| style="background-color:#FFFFFF; border: solid 1px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:नीति अउरी दिसानिर्देस|विकिनीति आ निर्देश]]
|}</div>
<!-- मुख्य पाठ -->
'''{{#if: | {{{1}}} | {{BASEPAGENAME}} }} जी''',
एह समय रउँआ [[विकिमीडिया फाउन्डेशन]] के परियोजना [[भोजपुरी]] [[विकिपीडिया]] पर बाड़ीं। भोजपुरी विकिपीडिया एगो मुक्त डिजिटल [[ज्ञानकोश]] हवे, जेवन अइसन भइया-बहिनी लोग मिल के लिखले बा जे ज्ञान बाँटे में बिस्वास करत बाटे। एह समय ए परियोजना में [[विशेष:ActiveUsers|{{NUMBEROFUSERS}} सदस्य]] लोग शामिल बाटे। ई बहुते खुशी क बाति बा कि रउँओं ए में शामिल हो गइल बाड़ीं।
* पहिले से बनल [[विकिपीडिया:लेख|लेखवन]] में कौनो संपादन खाली टेस्ट करे खातिर मत करीं। कौनों तरह के परीक्षण <small>(प्रयोग या टेस्टिंग)</small> [[विकिपीडिया:अभ्यास पन्ना|अभ्यास पन्ना]] या [[Special:MyPage/sandbox|अपना अभ्यास पन्ना]] पर करीं।
* [[विकिपीडिया:आपन परिचय कइसे देईं?|आपन परिचय]] आप संछेप में [[प्रयोगकर्ता:{{BASEPAGENAME}}|अपना सदस्य पन्ना]] पर दे सकत बानी। बहुत पर्सनल बात इहाँ मत लिखीं, न कौनों परचार वाली बात लिखीं। अपने खुद के बारे में लेख मत बनाईं।
* दुसरा [[विकिपीडिया:चौपाल |सदस्य लोगन से बात]] करत समय, [[मदद:वार्ता पन्ना|बातचीत पन्ना]] पर सनेसा लिखले की बाद आपन [[विकिपीडिया:दसखत|दसखत]] <small>(हस्ताक्षर)</small> जरूर करीं। एकरा खातिर अंत में चार गो टेढ़का डैश (<nowiki>~~~~</nowiki>) लिख देंईं या टूलबार में [[File:Insert-signature2.svg|link=|alt=]] पर क्लिक करीं।
* मदद चाहत होखीं त विकिपीडिया के [[विकिपीडिया:मदद|मदद पन्ना]] पर जाईं।
<!-- फुटर के कड़ी सभ -->
सीखे-समझे खातिर कुछ अउरी कड़ी नीचे दिहल जात बाटे:
{| border="5" cellspacing="1" cellpadding="0" height="50" align=center border=0 style="background: transparent"
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 10px;" | [[विकिपीडिया:स्वशिक्षा|शुरू से सीखीं]]
|
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[मदद:संपादन|संपादन सीखीं]]
|
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:नया लेख कइसे सुरू करीं?|नया लेख]]
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:अइसन लेख मना बाटे|लेख मनाहीं]]
|
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:पंचशील|पंचशील]]
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:समुदाय पोर्टल|सदस्य समाज पन्ना]]
|}
|}
-- [[प्रयोगकर्ता:नया सदस्य स्वागतकर्ता|नया सदस्य स्वागतकर्ता]] ([[प्रयोगकर्ता वार्ता:नया सदस्य स्वागतकर्ता|बात करीं]]) 01:37, 3 अप्रैल 2026 (UTC)
8nql21duz1fc9newuffr7ch9r5y35ko
लेनिनवाद
0
100491
790091
2026-04-03T02:32:49Z
SM7
3953
नया आधार लेख; पुरनका मेटा के एक पैरागाराफ दोबारा से लिखल गइल
790091
wikitext
text/x-wiki
'''लेनिनवाद''' ({{Langx|en|Leninism}}) एगो राजनीतिक बिचारधारा हवे, जवन रूसी मार्क्सवादी क्रांतिकारी [[व्लादिमीर लेनिन]] द्वारा विकसित कइल गइल रहे। ई बिचारधारा एह बात के प्रस्ताव रखेला कि [[कम्युनिज्म]] स्थापित करे से पहिले एगो क्रांतिकारी अगुआ पार्टी (वैनगार्ड पार्टी) के अगुआई में मजूरा वर्ग (प्रोलितैरियेत) के तानाशाही अस्थापित होखे के पड़ी। लेनिन के योगदान मार्क्सवादी विचारधारा में खास तौर पर पार्टी, साम्राज्यवाद (इंपीरियलिज्म), राज्य (स्टेट) आ क्रांति (रिवोल्यूशन) से जुड़ल थियरी सभ में रहल। लेनिनवादी अगुआ पार्टी के काम हवे कि मजूरा वर्ग के राजनीतिक चेतना (शिक्षा आ संगठन) देवे, आ अइसन नेतृत्व प्रदान करे जवन रूसी साम्राज्य (1721–1917) में पूंजीवाद के खतम कर सके।
s0fbntkwu8c1ypoxk4t6d8nm0grm4i6
790092
790091
2026-04-03T02:33:52Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा +[[श्रेणी:राजनीतिक बिचारधारा]]; +[[श्रेणी:राजनीतिक कांसेप्ट]]; +[[श्रेणी:राजनीतिक आंदोलन]]; +[[श्रेणी:राजनीतिक शब्दावली]]
790092
wikitext
text/x-wiki
'''लेनिनवाद''' ({{Langx|en|Leninism}}) एगो राजनीतिक बिचारधारा हवे, जवन रूसी मार्क्सवादी क्रांतिकारी [[व्लादिमीर लेनिन]] द्वारा विकसित कइल गइल रहे। ई बिचारधारा एह बात के प्रस्ताव रखेला कि [[कम्युनिज्म]] स्थापित करे से पहिले एगो क्रांतिकारी अगुआ पार्टी (वैनगार्ड पार्टी) के अगुआई में मजूरा वर्ग (प्रोलितैरियेत) के तानाशाही अस्थापित होखे के पड़ी। लेनिन के योगदान मार्क्सवादी विचारधारा में खास तौर पर पार्टी, साम्राज्यवाद (इंपीरियलिज्म), राज्य (स्टेट) आ क्रांति (रिवोल्यूशन) से जुड़ल थियरी सभ में रहल। लेनिनवादी अगुआ पार्टी के काम हवे कि मजूरा वर्ग के राजनीतिक चेतना (शिक्षा आ संगठन) देवे, आ अइसन नेतृत्व प्रदान करे जवन रूसी साम्राज्य (1721–1917) में पूंजीवाद के खतम कर सके।
[[श्रेणी:राजनीतिक बिचारधारा]]
[[श्रेणी:राजनीतिक कांसेप्ट]]
[[श्रेणी:राजनीतिक आंदोलन]]
[[श्रेणी:राजनीतिक शब्दावली]]
hjp9lx5bkhk5exejckug9a0duwh0cz7
790093
790092
2026-04-03T02:34:30Z
SM7
3953
[[User:SM7/stubsorter|Stubsorter]] के मदद से {{Poli-stub}} जोड़ल गइल।
790093
wikitext
text/x-wiki
'''लेनिनवाद''' ({{Langx|en|Leninism}}) एगो राजनीतिक बिचारधारा हवे, जवन रूसी मार्क्सवादी क्रांतिकारी [[व्लादिमीर लेनिन]] द्वारा विकसित कइल गइल रहे। ई बिचारधारा एह बात के प्रस्ताव रखेला कि [[कम्युनिज्म]] स्थापित करे से पहिले एगो क्रांतिकारी अगुआ पार्टी (वैनगार्ड पार्टी) के अगुआई में मजूरा वर्ग (प्रोलितैरियेत) के तानाशाही अस्थापित होखे के पड़ी। लेनिन के योगदान मार्क्सवादी विचारधारा में खास तौर पर पार्टी, साम्राज्यवाद (इंपीरियलिज्म), राज्य (स्टेट) आ क्रांति (रिवोल्यूशन) से जुड़ल थियरी सभ में रहल। लेनिनवादी अगुआ पार्टी के काम हवे कि मजूरा वर्ग के राजनीतिक चेतना (शिक्षा आ संगठन) देवे, आ अइसन नेतृत्व प्रदान करे जवन रूसी साम्राज्य (1721–1917) में पूंजीवाद के खतम कर सके।
[[श्रेणी:राजनीतिक बिचारधारा]]
[[श्रेणी:राजनीतिक कांसेप्ट]]
[[श्रेणी:राजनीतिक आंदोलन]]
[[श्रेणी:राजनीतिक शब्दावली]]
{{Poli-stub}}
83u91bt0blxr7hlol9d20ci1mcijcun
790094
790093
2026-04-03T02:36:34Z
SM7
3953
फोटो जोड़ल गइल
790094
wikitext
text/x-wiki
[[File:Vladimir Lenin (1918).jpg|thumb|[[व्लादिमीर लेनिन]], जिनका नाँव प लेनिनवाद के नाँव रखल गइल।]]
'''लेनिनवाद''' ({{Langx|en|Leninism}}) एगो राजनीतिक बिचारधारा हवे, जवन रूसी [[मार्क्सवाद|मार्क्सवादी]] क्रांतिकारी [[व्लादिमीर लेनिन]] द्वारा विकसित कइल गइल रहे। ई बिचारधारा एह बात के प्रस्ताव रखेला कि [[कम्युनिज्म]] स्थापित करे से पहिले एगो क्रांतिकारी अगुआ पार्टी (वैनगार्ड पार्टी) के अगुआई में मजूरा वर्ग (प्रोलितैरियेत) के तानाशाही अस्थापित होखे के पड़ी। लेनिन के योगदान मार्क्सवादी विचारधारा में खास तौर पर पार्टी, साम्राज्यवाद (इंपीरियलिज्म), राज्य (स्टेट) आ क्रांति (रिवोल्यूशन) से जुड़ल थियरी सभ में रहल। लेनिनवादी अगुआ पार्टी के काम हवे कि मजूरा वर्ग के राजनीतिक चेतना (शिक्षा आ संगठन) देवे, आ अइसन नेतृत्व प्रदान करे जवन रूसी साम्राज्य (1721–1917) में पूंजीवाद के खतम कर सके।
{{clear}}
[[श्रेणी:राजनीतिक बिचारधारा]]
[[श्रेणी:राजनीतिक कांसेप्ट]]
[[श्रेणी:राजनीतिक आंदोलन]]
[[श्रेणी:राजनीतिक शब्दावली]]
{{Poli-stub}}
sre8aj8aw8z2ijx1fj401ty3iwufrf5
790095
790094
2026-04-03T02:37:30Z
SM7
3953
फोटो बदलाव
790095
wikitext
text/x-wiki
[[File:Lenin in 1920 (cropped).jpg|thumb|[[व्लादिमीर लेनिन]], जिनका नाँव प लेनिनवाद के नाँव रखल गइल।]]
'''लेनिनवाद''' ({{Langx|en|Leninism}}) एगो राजनीतिक बिचारधारा हवे, जवन रूसी [[मार्क्सवाद|मार्क्सवादी]] क्रांतिकारी [[व्लादिमीर लेनिन]] द्वारा विकसित कइल गइल रहे। ई बिचारधारा एह बात के प्रस्ताव रखेला कि [[कम्युनिज्म]] स्थापित करे से पहिले एगो क्रांतिकारी अगुआ पार्टी (वैनगार्ड पार्टी) के अगुआई में मजूरा वर्ग (प्रोलितैरियेत) के तानाशाही अस्थापित होखे के पड़ी। लेनिन के योगदान मार्क्सवादी विचारधारा में खास तौर पर पार्टी, साम्राज्यवाद (इंपीरियलिज्म), राज्य (स्टेट) आ क्रांति (रिवोल्यूशन) से जुड़ल थियरी सभ में रहल। लेनिनवादी अगुआ पार्टी के काम हवे कि मजूरा वर्ग के राजनीतिक चेतना (शिक्षा आ संगठन) देवे, आ अइसन नेतृत्व प्रदान करे जवन रूसी साम्राज्य (1721–1917) में पूंजीवाद के खतम कर सके।
{{clear}}
[[श्रेणी:राजनीतिक बिचारधारा]]
[[श्रेणी:राजनीतिक कांसेप्ट]]
[[श्रेणी:राजनीतिक आंदोलन]]
[[श्रेणी:राजनीतिक शब्दावली]]
{{Poli-stub}}
hxfeg2qwc7umptgqoi2khijlfxpx3hr
स्पेसक्राफ्ट
0
100492
790102
2026-04-03T06:07:33Z
SM7
3953
नया आधार लेख
790102
wikitext
text/x-wiki
'''स्पेसक्राफ्ट''' ({{Langx|en|spacecraft}}) अइसन वाहन होला, जवन [[अंतरिक्ष|बाहरी अंतरिक्ष]] (आउटर स्पेस) में उड़े आ काम करे खातिर बनावल जाला। स्पेसक्राफ्ट के कई तरह के काम खातिर इस्तेमाल कइल जाला—जइसे कम्युनिकेशन, धरती के निगरानी (अर्थ ऑब्जरवेशन), [[मौसम विज्ञान]], नेविगेशन, अंतरिक्ष में बसावट, ग्रहन के खोज (एक्सप्लोरेशन), आ आदमी आ सामान के ले बाहरी अंतरिक्ष तक ले ले जाए खातिर।
ज्यादातर स्पेसक्राफ्ट खुद से अंतरिक्ष में ना जा सकेला; एकरा खातिर [[लॉन्च व्हीकल]] (कैरियर रॉकेट) के जरूरत पड़ेला, जवन ओकरा के अंतरिक्ष तक पहुँचा देला। सिर्फ कुछ खास तरह के यान—जइसे सिंगल-स्टेज-टू-ऑर्बिट—ही खुद से अंतरिक्ष में जा सके लें।
h24ap2kqbsf97184gqkjugsu5i5ad49
790104
790102
2026-04-03T06:11:20Z
SM7
3953
सुधार कइल गइल
790104
wikitext
text/x-wiki
'''स्पेसक्राफ्ट''' ({{Langx|en|spacecraft}}) अइसन वाहन होला, जवन [[अंतरिक्ष|बाहरी अंतरिक्ष]] (आउटर स्पेस) में उड़े आ काम करे खातिर बनावल जाला। स्पेसक्राफ्ट के कई तरह के काम खातिर इस्तेमाल कइल जाला—जइसे कम्युनिकेशन, धरती के निगरानी (अर्थ ऑब्जरवेशन), [[मौसम विज्ञान]], नेविगेशन, अंतरिक्ष में बसावट, ग्रहन के खोज (एक्सप्लोरेशन), आ आदमी आ सामान के ले बाहरी अंतरिक्ष तक ले ले जाए खातिर।
ज्यादातर स्पेसक्राफ्ट खुद से अंतरिक्ष में ना जा सकेला; एकरा खातिर [[लॉन्च व्हीकल]] (कैरियर रॉकेट) के जरूरत पड़ेला, जवन ओकरा के अंतरिक्ष तक पहुँचा देला। सिर्फ कुछ खास तरह के यान—जइसे सिंगल-स्टेज-टू-ऑर्बिट—ही खुद से अंतरिक्ष में जा सके लें।
{{clear}}
[[श्रेणी:खगोलिकी]]
{{astronomy-stub}}
bz76zopqyrkzqlrwlkbezdvpq1rp198
790107
790104
2026-04-03T06:13:06Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:अंतरिक्ष बिज्ञान]] जोड़ल गइल
790107
wikitext
text/x-wiki
'''स्पेसक्राफ्ट''' ({{Langx|en|spacecraft}}) अइसन वाहन होला, जवन [[अंतरिक्ष|बाहरी अंतरिक्ष]] (आउटर स्पेस) में उड़े आ काम करे खातिर बनावल जाला। स्पेसक्राफ्ट के कई तरह के काम खातिर इस्तेमाल कइल जाला—जइसे कम्युनिकेशन, धरती के निगरानी (अर्थ ऑब्जरवेशन), [[मौसम विज्ञान]], नेविगेशन, अंतरिक्ष में बसावट, ग्रहन के खोज (एक्सप्लोरेशन), आ आदमी आ सामान के ले बाहरी अंतरिक्ष तक ले ले जाए खातिर।
ज्यादातर स्पेसक्राफ्ट खुद से अंतरिक्ष में ना जा सकेला; एकरा खातिर [[लॉन्च व्हीकल]] (कैरियर रॉकेट) के जरूरत पड़ेला, जवन ओकरा के अंतरिक्ष तक पहुँचा देला। सिर्फ कुछ खास तरह के यान—जइसे सिंगल-स्टेज-टू-ऑर्बिट—ही खुद से अंतरिक्ष में जा सके लें।
{{clear}}
[[श्रेणी:खगोलिकी]]
[[श्रेणी:अंतरिक्ष बिज्ञान]]
{{astronomy-stub}}
rpr1n7txk6oppkodokubnk7e8ioh0qx
मौसम विज्ञान
0
100493
790105
2026-04-03T06:12:04Z
SM7
3953
पन्ना [[मौसम बिज्ञान]] पर अनुप्रेषित कइल गइल
790105
wikitext
text/x-wiki
#REDIRECT [[मौसम बिज्ञान]]
q0aclj7dppsrl1m79mc165ykhxtcikj
790106
790105
2026-04-03T06:12:24Z
SM7
3953
Added {{[[:Template:R from alternative spelling|R from alternative spelling]]}} tag to redirect
790106
wikitext
text/x-wiki
#REDIRECT [[मौसम बिज्ञान]]
{{Redirect category shell|
{{R from alternative spelling}}
}}
lrxqxburjvs5vpfr4v2aglfg11480vx
टेम्पलेट:Ubli
10
100494
790115
2025-05-03T18:00:18Z
en>MusikBot II
0
Changed protection settings for "[[Template:Ubli]]": [[Wikipedia:High-risk templates|High-risk template or module]]: 2500 transclusions ([[User:MusikBot II/TemplateProtector|more info]]) ([Edit=Require extended confirmed access] (indefinite) [Move=Require extended confirmed access] (indefinite))
790115
wikitext
text/x-wiki
#redirect [[Template:Unbulleted indent list]]
{{rcat shell|{{r from template shortcut}}}}
h4afikxjf5w5pmmnytsfgsyyf1kn57c
790116
790115
2026-04-03T08:33:18Z
SM7
3953
1 revision imported from [[:en:Template:Ubli]]
790115
wikitext
text/x-wiki
#redirect [[Template:Unbulleted indent list]]
{{rcat shell|{{r from template shortcut}}}}
h4afikxjf5w5pmmnytsfgsyyf1kn57c
टेम्पलेट:Sclass
10
100495
790118
2007-06-26T23:44:50Z
en>J Clear
0
Move template from my sandbox
790118
wikitext
text/x-wiki
<includeonly>[[ {{{1}}} class {{{2}}}| ''{{{1}}}''-class
{{#switch:{{{3|3}}}
|0 = ]]
|1 = {{{2}}} ]]
|2 = ]] {{{2}}}
|3 = ]] [[ {{{2}}} ]]
|]] ERROR IN TEMPLATE PARAMETER
}}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
n3gtqlkuhg1ng0ez59zuixw4r90w1ma
790119
790118
2007-06-28T00:19:09Z
en>J Clear
0
remove extraneous spaces
790119
wikitext
text/x-wiki
<includeonly>[[ {{{1}}} class {{{2}}}| ''{{{1}}}''-class
{{#switch:{{{3|3}}}
|0 =]]
|1 = {{{2}}}]]
|2 =]] {{{2}}}
|3 =]] [[{{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
t90qcx97mvgozv6vwsrzfkah8lccd9w
790120
790119
2007-06-28T00:21:02Z
en>J Clear
0
remove another extraneous space
790120
wikitext
text/x-wiki
<includeonly>[[ {{{1}}} class {{{2}}}| ''{{{1}}}''-class
{{#switch:{{{3|3}}}
|0 =]]
|1 = {{{2}}}]]
|2 =]] {{{2}}}
|3 =]] [[{{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
h21fseldbewp1185oneayd1n8j22wuh
790121
790120
2007-06-28T00:23:15Z
en>J Clear
0
trying to hunt down a trailing space in fromat=0
790121
wikitext
text/x-wiki
<includeonly>[[ {{{1}}} class {{{2}}}| ''{{{1}}}''-class<!-- remove \n
-->{{#switch:{{{3|3}}}
|0 =]]
|1 = {{{2}}}]]
|2 =]] {{{2}}}
|3 =]] [[{{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
g1qv3fz8uziqyl5hx52jml4veqqkcst
790122
790121
2007-06-30T16:07:12Z
en>J Clear
0
fix spacing in format=1
790122
wikitext
text/x-wiki
<includeonly>[[ {{{1}}} class {{{2}}}| ''{{{1}}}''-class<!-- remove \n
-->{{#switch:{{{3|3}}}
|0 =]]
|1 = {{{2}}}]]
|2 =]] {{{2}}}
|3 =]] [[{{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
k4vgu2zsarb59lnng6cmrs90grje4e4
790123
790122
2007-11-06T11:41:37Z
en>Bellhalla
0
added option 4 for parameters (See discussion)
790123
wikitext
text/x-wiki
<includeonly>[[ {{{1}}} class {{{2}}}| ''{{{1}}}''<!-- remove \n
-->{{#switch:{{{3|3}}}
|0 =-class]]
|1 =-class {{{2}}}]]
|2 =-class]] {{{2}}}
|3 =-class]] [[{{{2}}}]]
|4 = class]]
|]] ERROR IN TEMPLATE PARAMETER
}}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
3s7yirravib9wvedmscpr48yrg2b6fm
790124
790123
2007-12-24T18:47:05Z
en>Bellhalla
0
added code for disambig link, undefined 3rd parameter (see talk page)
790124
wikitext
text/x-wiki
<includeonly>[[{{{1}}} class {{{2}}}| ''{{{1}}}''<!-- remove \n
-->{{#if: {{{3|}}} | {{#switch:{{{3|3}}}
|0 =-class]]
|1 =-class {{{2}}}]]
|2 =-class]] {{{2}}}
|3 =-class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]]
|4 = class]]
|]] ERROR IN TEMPLATE PARAMETER
}} | -class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]] }}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
m1n3pw7pyjf3pwk4m5jckb7y04ri0l0
790125
790124
2008-04-30T14:20:17Z
en>Bellhalla
0
add option 5
790125
wikitext
text/x-wiki
<includeonly>[[{{{1}}} class {{{2}}}| ''{{{1}}}''<!-- remove \n
-->{{#if: {{{3|}}} | {{#switch:{{{3|3}}}
|0 =-class]]
|1 =-class {{{2}}}]]
|2 =-class]] {{{2}}}
|3 =-class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]]
|4 = class]]
|5 =]]
|]] ERROR IN TEMPLATE PARAMETER
}} | -class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]] }}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
r6z6ha8fn4y3yphzmdmr8n7bwr0f5rc
790126
790125
2008-11-13T11:53:34Z
en>Bellhalla
0
add option 6
790126
wikitext
text/x-wiki
<includeonly>[[{{{1}}} class {{{2}}}| ''{{{1}}}''<!-- remove \n
-->{{#if: {{{3|}}} | {{#switch:{{{3|3}}}
|0 =-class]]
|1 =-class {{{2}}}]]
|2 =-class]] {{{2}}}
|3 =-class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]]
|4 = class]]
|5 =]]
|6 = class {{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}} | -class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]] }}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
jf22exeajn01ronboqrvcibetq1tzp7
790127
790126
2008-11-13T12:06:41Z
en>Bellhalla
0
add missing non-breaking space to option 6
790127
wikitext
text/x-wiki
<includeonly>[[{{{1}}} class {{{2}}}| ''{{{1}}}''<!-- remove \n
-->{{#if: {{{3|}}} | {{#switch:{{{3|3}}}
|0 =-class]]
|1 =-class {{{2}}}]]
|2 =-class]] {{{2}}}
|3 =-class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]]
|4 = class]]
|5 =]]
|6 = class {{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}} | -class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]] }}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
euotud54fmy6gtyzv1k7xrsvgj7w6ww
790128
790127
2008-12-01T14:28:05Z
en>Kralizec!
0
Protected Template:Sclass: [[WP:PPOL#indef|Highly visible template]] ([edit=sysop] (indefinite) [move=sysop] (indefinite))
790127
wikitext
text/x-wiki
<includeonly>[[{{{1}}} class {{{2}}}| ''{{{1}}}''<!-- remove \n
-->{{#if: {{{3|}}} | {{#switch:{{{3|3}}}
|0 =-class]]
|1 =-class {{{2}}}]]
|2 =-class]] {{{2}}}
|3 =-class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]]
|4 = class]]
|5 =]]
|6 = class {{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}} | -class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]] }}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
euotud54fmy6gtyzv1k7xrsvgj7w6ww
790129
790128
2008-12-01T14:35:46Z
en>Kralizec!
0
{{pp-template}}
790129
wikitext
text/x-wiki
<includeonly>[[{{{1}}} class {{{2}}}| ''{{{1}}}''<!-- remove \n
-->{{#if: {{{3|}}} | {{#switch:{{{3|3}}}
|0 =-class]]
|1 =-class {{{2}}}]]
|2 =-class]] {{{2}}}
|3 =-class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]]
|4 = class]]
|5 =]]
|6 = class {{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}} | -class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]] }}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
{{pp-template|small=yes}}
</noinclude>
ie3hqckjznq7oi3i273nfv4boxu6ncq
790130
790129
2009-06-04T17:41:26Z
en>Kralizec!
0
rm space as per request on talk page
790130
wikitext
text/x-wiki
<includeonly>[[{{{1}}} class {{{2}}}|''{{{1}}}''<!-- remove \n
-->{{#if: {{{3|}}} | {{#switch:{{{3|3}}}
|0 =-class]]
|1 =-class {{{2}}}]]
|2 =-class]] {{{2}}}
|3 =-class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]]
|4 = class]]
|5 =]]
|6 = class {{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}} | -class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]] }}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
{{pp-template|small=yes}}
</noinclude>
h2ieh7umkas270nt6t4m9hzvtuej45l
790131
790130
2010-10-01T18:57:53Z
en>WOSlinker
0
remove {{pp-template}}
790131
wikitext
text/x-wiki
<includeonly>[[{{{1}}} class {{{2}}}|''{{{1}}}''<!-- remove \n
-->{{#if: {{{3|}}} | {{#switch:{{{3|3}}}
|0 =-class]]
|1 =-class {{{2}}}]]
|2 =-class]] {{{2}}}
|3 =-class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]]
|4 = class]]
|5 =]]
|6 = class {{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}} | -class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]] }}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
fbiv49nm9mwtm5rpooyo1dtbou8irt2
790132
790131
2012-08-28T12:04:49Z
en>Redrose64
0
rm hyphens per [[Template talk:Sclass#Edit request on 26 August 2012]]
790132
wikitext
text/x-wiki
<includeonly>[[{{{1}}} class {{{2}}}|''{{{1}}}''<!-- remove \n
-->{{#if: {{{3|}}} | {{#switch:{{{3|3}}}
|0 = class]]
|1 = class {{{2}}}]]
|2 = class]] {{{2}}}
|3 = class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]]
|4 = class]]
|5 =]]
|6 = class {{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}} | class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]] }}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
s6w2t9rsmihs0xast8ej1hdvlm2ca50
790133
790132
2012-08-28T21:40:59Z
en>Redrose64
0
Undid revision 509590185 by [[Special:Contributions/Redrose64|Redrose64]] ([[User talk:Redrose64|talk]]) rv pending consensus
790133
wikitext
text/x-wiki
<includeonly>[[{{{1}}} class {{{2}}}|''{{{1}}}''<!-- remove \n
-->{{#if: {{{3|}}} | {{#switch:{{{3|3}}}
|0 =-class]]
|1 =-class {{{2}}}]]
|2 =-class]] {{{2}}}
|3 =-class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]]
|4 = class]]
|5 =]]
|6 = class {{{2}}}]]
|]] ERROR IN TEMPLATE PARAMETER
}} | -class]] [[{{#if:{{{4|}}}|{{{2}}} ({{{4}}}){{!}}{{{2}}}|{{{2}}}}}]] }}</includeonly><noinclude>
{{template doc}}
<!-- Add categories and interwikis to the /doc subpage, not here! -->
</noinclude>
fbiv49nm9mwtm5rpooyo1dtbou8irt2
790134
790133
2013-03-19T11:20:24Z
en>Thumperward
0
sync from sandbox, per editprotected
790134
wikitext
text/x-wiki
<includeonly>{{sclass/core|{{{1}}}|{{{2}}}|{{{3|}}}|{{{4|}}}|format=sclass}}</includeonly><noinclude>
{{documentation}}
</noinclude>
8gqdm94c2ywrpc77zlmeix0g8fn6uh7
790135
790134
2013-05-10T11:56:18Z
en>MSGJ
0
add extra parameter, per request of Trappist the monk
790135
wikitext
text/x-wiki
{{sclass/core|{{{1}}}|{{{2}}}|{{{3|}}}|{{{4|}}}|{{{5|}}}|format=sclass}}<noinclude>
{{documentation}}
</noinclude>
fq7g19ogfhcjdmewkjh7xqwzkg7w9hd
790136
790135
2013-10-19T20:44:57Z
en>WOSlinker
0
Changed protection level of Template:Sclass: allow template editors to modify ([Edit=Protected template] (indefinite) [Move=Protected template] (indefinite))
790135
wikitext
text/x-wiki
{{sclass/core|{{{1}}}|{{{2}}}|{{{3|}}}|{{{4|}}}|{{{5|}}}|format=sclass}}<noinclude>
{{documentation}}
</noinclude>
fq7g19ogfhcjdmewkjh7xqwzkg7w9hd
790137
790136
2018-03-21T21:52:59Z
en>DePiep
0
use dedicated code: sclass/core/deprecated. see [[Template_talk:Sclass#Further_deprecation_of_the_unhyphened_templates|Talk]]
790137
wikitext
text/x-wiki
{{sclass/core/deprecated|{{{1}}}|{{{2}}}|{{{3|}}}|{{{4|}}}|{{{5|}}}|format=sclass}}<noinclude>
{{documentation}}
</noinclude>
tp4ncxwt5dmfcgrs4iyxr2x2z4kh35t
790138
790137
2020-10-22T13:58:45Z
en>Trialpears
0
Listed for merging with [[:Template:Sclass-]]; see [[:Wikipedia:Templates for discussion/Log/2020 October 22#Template:Sclass]].
790138
wikitext
text/x-wiki
{{Tfm/dated|page=Sclass|otherpage=Sclass-|link=Wikipedia:Templates for discussion/Log/2020 October 22#Template:Sclass|type=tiny|help=off|bigbox={{#invoke:Noinclude|noinclude|text=yes}}}}{{sclass/core/deprecated|{{{1}}}|{{{2}}}|{{{3|}}}|{{{4|}}}|{{{5|}}}|format=sclass}}<noinclude>
{{documentation}}
</noinclude>
qi0g6s52kmpopmwbsc6d8jwskgyeyzl
790139
790138
2020-11-01T16:47:07Z
en>ProcrastinatingReader
0
Per [[Wikipedia:Templates for discussion/Log/2020 October 22#Template:Sclass]], added {{being deleted}} ([[WP:XFDC|XFDcloser]])
790139
wikitext
text/x-wiki
<noinclude>{{Being deleted|2020 October 22|Template:Sclass}}</noinclude>{{sclass/core/deprecated|{{{1}}}|{{{2}}}|{{{3|}}}|{{{4|}}}|{{{5|}}}|format=sclass}}<noinclude>
{{documentation}}
</noinclude>
8jl922r3w0d4n5gg6qc48f0drlo0tfw
790140
790139
2020-11-01T17:01:49Z
en>Trappist the monk
0
Undid revision 986561181 by [[Special:Contributions/ProcrastinatingReader|ProcrastinatingReader]] ([[User talk:ProcrastinatingReader|talk]]) not being deleted;
790140
wikitext
text/x-wiki
{{Tfm/dated|page=Sclass|otherpage=Sclass-|link=Wikipedia:Templates for discussion/Log/2020 October 22#Template:Sclass|type=tiny|help=off|bigbox={{#invoke:Noinclude|noinclude|text=yes}}}}{{sclass/core/deprecated|{{{1}}}|{{{2}}}|{{{3|}}}|{{{4|}}}|{{{5|}}}|format=sclass}}<noinclude>
{{documentation}}
</noinclude>
qi0g6s52kmpopmwbsc6d8jwskgyeyzl
790141
790140
2020-11-01T17:02:38Z
en>Trappist the monk
0
decision was to merge;
790141
wikitext
text/x-wiki
{{sclass/core/deprecated|{{{1}}}|{{{2}}}|{{{3|}}}|{{{4|}}}|{{{5|}}}|format=sclass}}<noinclude>
{{documentation}}
</noinclude>
tp4ncxwt5dmfcgrs4iyxr2x2z4kh35t
790142
790141
2020-12-12T18:05:45Z
en>Trappist the monk
0
mirror [[Template:sclass-]] per [[Wikipedia:Templates for discussion/Log/2020 October 22#Template:Sclass]]
790142
wikitext
text/x-wiki
<includeonly>{{sclass/core|1={{{1}}}|2={{{2}}}|3={{{3|}}}|4={{{4|}}}|5={{{5|}}}|format=sclass-}}</includeonly><!--
--><noinclude>{{documentation}}</noinclude>
gup7a2mhca9ddtmgoecomzsem6ouy2x
790143
790142
2021-07-02T16:02:05Z
en>Trappist the monk
0
format name change;
790143
wikitext
text/x-wiki
<includeonly>{{sclass/core|1={{{1}}}|2={{{2}}}|3={{{3|}}}|4={{{4|}}}|5={{{5|}}}|format=sclass}}</includeonly><!--
--><noinclude>{{documentation}}</noinclude>
ii7g865efo8xaw4d85eo1uruz6lzys2
790144
790143
2023-03-04T20:02:08Z
en>Trappist the monk
0
sync from sandbox;
790144
wikitext
text/x-wiki
<includeonly>{{#invoke:WPSHIPS utilities|sclass}}</includeonly><!--
--><noinclude>{{documentation}}</noinclude>
mku6496xrza5wsgi8ynmad8ikebxrr8
790145
790144
2026-04-03T08:33:56Z
SM7
3953
27 revisions imported from [[:en:Template:Sclass]]
790144
wikitext
text/x-wiki
<includeonly>{{#invoke:WPSHIPS utilities|sclass}}</includeonly><!--
--><noinclude>{{documentation}}</noinclude>
mku6496xrza5wsgi8ynmad8ikebxrr8
टेम्पलेट:Sclass/doc
10
100496
790146
2007-06-27T00:32:08Z
en>J Clear
0
create doc for new template
790146
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely
:1 - displays ''ship type'', but as part of the single link to the class article
:2 - displays ''ship type'', but unlinked
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
One of the first three options must be used if ''Ship type'' is not an article to avoid the dreaded [[red link]]. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
=== Examples ===
{|style="border-style:solid;border-width:1px;border-color:#000000;background-color:#EFEFEF" cellspacing="2" cellpadding="2" width="100%"
|- style="background-color:#FCFCFC" align="left"
! Template usage
! Equivalent wikicode
! Final result
|-
|<nowiki>{{sclass | Haskell | attack transport}}</nowiki>
|<nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki>
|{{sclass|Haskell|attack transport}}
|-
|<nowiki>{{sclass | Haskell | attack transport | 0}}</nowiki>
|<nowiki>[[Haskell class attack transport | ''Haskell''-class]]</nowiki>
|{{sclass|Haskell|attack transport|0}}
|-
|<nowiki>{{sclass | Haskell | attack transport | 1}}</nowiki>
|<nowiki>[[Haskell class attack transport | ''Haskell''-class attack transport]]</nowiki>
|{{sclass|Haskell|attack transport|1}}
|-
|<nowiki>{{sclass | Haskell | attack transport | 2}}</nowiki>
|<nowiki>[[Haskell class attack transport | ''Haskell''-class]] attack transport</nowiki>
|{{sclass|Haskell|attack transport|2}}
|-
|<nowiki>{{sclass | Haskell | attack transport | 3}}</nowiki>
|<nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki>
|{{sclass|Haskell|attack transport|3}}
|}
=== See also ===
Other [[WP:SHIPS]] shortcut templates:
*{{tl|HMS}} - Short cut for linking to Royal Navy ship articles
*{{tl|USS}} - Short cut for linking to US Navy ship articles
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
gpc8d15umlvldqvitnyxk6z1n6vxkqh
790147
790146
2007-09-27T23:00:45Z
en>Kralizec!
0
sharpened cat.
790147
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely
:1 - displays ''ship type'', but as part of the single link to the class article
:2 - displays ''ship type'', but unlinked
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
One of the first three options must be used if ''Ship type'' is not an article to avoid the dreaded [[red link]]. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
=== Examples ===
{|style="border-style:solid;border-width:1px;border-color:#000000;background-color:#EFEFEF" cellspacing="2" cellpadding="2" width="100%"
|- style="background-color:#FCFCFC" align="left"
! Template usage
! Equivalent wikicode
! Final result
|-
|<nowiki>{{sclass | Haskell | attack transport}}</nowiki>
|<nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki>
|{{sclass|Haskell|attack transport}}
|-
|<nowiki>{{sclass | Haskell | attack transport | 0}}</nowiki>
|<nowiki>[[Haskell class attack transport | ''Haskell''-class]]</nowiki>
|{{sclass|Haskell|attack transport|0}}
|-
|<nowiki>{{sclass | Haskell | attack transport | 1}}</nowiki>
|<nowiki>[[Haskell class attack transport | ''Haskell''-class attack transport]]</nowiki>
|{{sclass|Haskell|attack transport|1}}
|-
|<nowiki>{{sclass | Haskell | attack transport | 2}}</nowiki>
|<nowiki>[[Haskell class attack transport | ''Haskell''-class]] attack transport</nowiki>
|{{sclass|Haskell|attack transport|2}}
|-
|<nowiki>{{sclass | Haskell | attack transport | 3}}</nowiki>
|<nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki>
|{{sclass|Haskell|attack transport|3}}
|}
=== See also ===
Other [[WP:SHIPS]] shortcut templates:
*{{tl|HMS}} - Short cut for linking to Royal Navy ship articles
*{{tl|USS}} - Short cut for linking to US Navy ship articles
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
k4vhq4d75p8o7ree17p2wmb1oj5a8ql
790148
790147
2007-11-06T11:49:02Z
en>Bellhalla
0
/* Examples */ wikitable; added Notes; added example of parameter = 4
790148
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely
:1 - displays ''ship type'', but as part of the single link to the class article
:2 - displays ''ship type'', but unlinked
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
One of the first three options must be used if ''Ship type'' is not an article to avoid the dreaded [[red link]]. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
=== Examples ===
{|class=wikitable width="100%"
|-
! Parameter
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
=== See also ===
Other [[WP:SHIPS]] shortcut templates:
*{{tl|HMS}} - Short cut for linking to Royal Navy ship articles
*{{tl|USS}} - Short cut for linking to US Navy ship articles
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
46ulo09ue692c8gflem28bss7cj2f8x
790149
790148
2007-11-06T11:51:13Z
en>Bellhalla
0
/* Ship class link template usage */ added listing of parameter = 4
790149
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
One of the first three options must be used if ''Ship type'' is not an article to avoid the dreaded [[red link]]. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
=== Examples ===
{|class=wikitable width="100%"
|-
! Parameter
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
=== See also ===
Other [[WP:SHIPS]] shortcut templates:
*{{tl|HMS}} - Short cut for linking to Royal Navy ship articles
*{{tl|USS}} - Short cut for linking to US Navy ship articles
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
o3640eu456yf3rohh19rxu0rpb3inea
790150
790149
2007-11-06T11:52:51Z
en>Bellhalla
0
/* Examples */ heading fix for table
790150
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
One of the first three options must be used if ''Ship type'' is not an article to avoid the dreaded [[red link]]. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
=== Examples ===
{|class=wikitable width="100%"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
=== See also ===
Other [[WP:SHIPS]] shortcut templates:
*{{tl|HMS}} - Short cut for linking to Royal Navy ship articles
*{{tl|USS}} - Short cut for linking to US Navy ship articles
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
pqu25krspzuwd47jvdh1z2d3ngzn3rz
790151
790150
2007-12-24T17:20:47Z
en>Bellhalla
0
/* See also */ added add'l template links
790151
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
One of the first three options must be used if ''Ship type'' is not an article to avoid the dreaded [[red link]]. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
=== Examples ===
{|class=wikitable width="100%"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
=== See also ===
Other [[WP:SHIPS]] shortcut templates:
*{{tl|HMS}} - Short cut for linking to Royal Navy ship articles
*{{tl|USS}} - Short cut for linking to U.S. Navy ship articles
*{{tl|USNS}} - Short cut for linking to U.S. Naval Ship articles
*{{tl|USCGC}} - Short cut for linking to U.S. Coast Guard Cutter ship articles
*{{tl|SS}} - Short cut for linking to steamship articles
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
487bqjyof77q9mlpl1k35trkfwwnuov
790152
790151
2007-12-24T18:59:18Z
en>Bellhalla
0
added doc for disambiguation parameter
790152
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
One of the first three options must be used if ''Ship type'' is not an article to avoid the dreaded [[red link]]. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
=== Examples ===
{|class=wikitable width="100%"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3.
=== Examples ===
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
=== See also ===
Other [[WP:SHIPS]] shortcut templates:
*{{tl|HMS}} - Short cut for linking to Royal Navy ship articles
*{{tl|USS}} - Short cut for linking to U.S. Navy ship articles
*{{tl|USNS}} - Short cut for linking to U.S. Naval Ship articles
*{{tl|USCGC}} - Short cut for linking to U.S. Coast Guard Cutter ship articles
*{{tl|SS}} - Short cut for linking to steamship articles
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
e7zuint5ww3voddux5lplax9jnz6s2v
790153
790152
2007-12-24T19:18:43Z
en>Bellhalla
0
minor copyedits for clarity, explanation
790153
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
Other [[WP:SHIPS]] shortcut templates:
*{{tl|HMS}} - Short cut for linking to Royal Navy ship articles
*{{tl|USS}} - Short cut for linking to U.S. Navy ship articles
*{{tl|USNS}} - Short cut for linking to U.S. Naval Ship articles
*{{tl|USCGC}} - Short cut for linking to U.S. Coast Guard Cutter ship articles
*{{tl|SS}} - Short cut for linking to steamship articles
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
d6jrx1hcjow6g6if97ph3vpxv4batvt
790154
790153
2008-03-24T19:33:00Z
en>Bellhalla
0
/* See also */ {{WPSHIPS shortcut templates}}
790154
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
qhzh3w6fw5wyicti1q4cxschdl9p4ew
790155
790154
2008-03-24T19:55:52Z
en>Bellhalla
0
add note about {{sclass2}}
790155
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the [[Flower class corvette]], use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
o90zs960qfn0slqppberwezx1f12pd9
790156
790155
2008-03-24T19:56:48Z
en>Bellhalla
0
/* Ship class link template usage */ {{sclass2}}
790156
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
1tchc0yi8qqpzxf8zd0dtvuwgnty8pr
790157
790156
2008-03-24T19:57:30Z
en>Bellhalla
0
/* Ship class link template usage */ optional parameter, dangit!
790157
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
[[Category:Templates using ParserFunctions|{{PAGENAME}}]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
c6sbhb8lzoe9rlmnmv2ve1hgcxl5yqi
790158
790157
2008-08-28T14:14:51Z
en>Kbdank71
0
Remove category per per [[WP:CFD|CFD]] [[Wikipedia:Categories for discussion/Log/2008 August 21|2008 August 21]]
790158
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
fvydbwft4eglbtwgx01n8ptz9guo6cf
790159
790158
2008-11-13T11:59:02Z
en>Bellhalla
0
/* Optional parameter: "format" */ add options 5 & 6 to documentation
790159
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and resluts for ''format'' are:
:0 - supresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - supresses displaying ''ship type'' entirely. Noun form.
:5 - class name only. Suitable for tables
:6 - as article name, but properly italicized
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| Use to refer to article, but with proper italics
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
qi853oihec0oftc5uxw68d4ajjqxofl
790160
790159
2009-03-04T02:41:52Z
en>Art LaPella
0
/* Optional parameter: "format" */ spelling
790160
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0 - suppresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - suppresses displaying ''ship type'' entirely. Noun form.
:5 - class name only. Suitable for tables
:6 - as article name, but properly italicized
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| Use to refer to article, but with proper italics
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
oeac9s8juipbhk4jovmbihs9z5qcseb
790161
790160
2009-06-14T14:50:11Z
en>Davehi1
0
Disambiguate [[Minesweeper]] to [[Minesweeper (ship)]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]
790161
wikitext
text/x-wiki
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0 - suppresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - suppresses displaying ''ship type'' entirely. Noun form.
:5 - class name only. Suitable for tables
:6 - as article name, but properly italicized
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| Use to refer to article, but with proper italics
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
mom2h1io4xjlb7y8mejuzo509blai2r
790162
790161
2010-08-15T19:48:43Z
en>Droll
0
clean up documentation subpage templates using [[Project:AWB|AWB]]
790162
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0 - suppresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - suppresses displaying ''ship type'' entirely. Noun form.
:5 - class name only. Suitable for tables
:6 - as article name, but properly italicized
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| Use to refer to article, but with proper italics
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
</includeonly>
50dqu6jv9w1zk1wn3qnsj3lk5yng61u
790163
790162
2010-12-22T21:14:27Z
en>Quest for Truth
0
790163
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0 - suppresses displaying ''ship type'' entirely. Adjectival form.
:1 - displays ''ship type'', but as part of the single link to the class article.
:2 - displays ''ship type'', but unlinked.
:3 - displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4 - suppresses displaying ''ship type'' entirely. Noun form.
:5 - class name only. Suitable for tables
:6 - as article name, but properly italicized
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| Use to refer to article, but with proper italics
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[zh:Template:Sclass]]
</includeonly>
qm0dt8ezzqds28sjk4ym5wzoc1oxgsy
790164
790163
2011-10-11T06:12:11Z
en>DocWatson42
0
Performed minor clean up on punctuation.
790164
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses displaying ''ship type'' entirely. Adjectival form.
:1: displays ''ship type'', but as part of the single link to the class article.
:2: displays ''ship type'', but unlinked.
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4: suppresses displaying ''ship type'' entirely. Noun form.
:5: class name only. Suitable for tables
:6: as article name, but properly italicized
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| Use to refer to article, but with proper italics
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[zh:Template:Sclass]]
</includeonly>
6eizjne9qzplhl8u3nsoheeghb4ru9x
790165
790164
2012-05-02T18:42:22Z
en>Redrose64
0
/* See also */ +[[fr:Modèle:Classe]]
790165
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses displaying ''ship type'' entirely. Adjectival form.
:1: displays ''ship type'', but as part of the single link to the class article.
:2: displays ''ship type'', but unlinked.
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4: suppresses displaying ''ship type'' entirely. Noun form.
:5: class name only. Suitable for tables
:6: as article name, but properly italicized
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| Use to refer to article, but with proper italics
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:WikiProject Ships templates|Sclass]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[fr:Modèle:Classe]]
[[zh:Template:Sclass]]
</includeonly>
abiqx5c7rje9ezrdijjnccwqtxxsmr3
790166
790165
2012-05-26T11:27:07Z
en>WOSlinker
0
change cat
790166
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses displaying ''ship type'' entirely. Adjectival form.
:1: displays ''ship type'', but as part of the single link to the class article.
:2: displays ''ship type'', but unlinked.
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4: suppresses displaying ''ship type'' entirely. Noun form.
:5: class name only. Suitable for tables
:6: as article name, but properly italicized
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| Use to refer to article, but with proper italics
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[fr:Modèle:Classe]]
[[zh:Template:Sclass]]
</includeonly>
rof9n2i209jfujpd616n73dd4y5wce7
790167
790166
2012-09-27T19:02:31Z
en>Yahia.barie
0
[[bn:টেমপ্লেট:Sclass]]
790167
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses displaying ''ship type'' entirely. Adjectival form.
:1: displays ''ship type'', but as part of the single link to the class article.
:2: displays ''ship type'', but unlinked.
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4: suppresses displaying ''ship type'' entirely. Noun form.
:5: class name only. Suitable for tables
:6: as article name, but properly italicized
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| Use to refer to article, but with proper italics
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[bn:টেমপ্লেট:Sclass]]
[[fr:Modèle:Classe]]
[[zh:Template:Sclass]]
</includeonly>
rtx43hxbww9wg6abo8q8gbuwg7l6adu
790168
790167
2012-10-19T16:09:35Z
en>Trappist the monk
0
Deprecated option 6 because of improper grammar;
790168
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}}Use Option 1
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| rowspan=2 | Use when the ship type<br>article does not exist
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}}Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[bn:টেমপ্লেট:Sclass]]
[[fr:Modèle:Classe]]
[[zh:Template:Sclass]]
</includeonly>
o8lg6855l11una4qdk6j364esjlb02n
790169
790168
2012-10-19T16:44:18Z
en>Trappist the monk
0
Copyedit;
790169
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}}Use Option 1
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}}Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specifiy a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[bn:টেমপ্লেট:Sclass]]
[[fr:Modèle:Classe]]
[[zh:Template:Sclass]]
</includeonly>
rmuq3i1rosb557sacy7nhf4u1c3heqs
790170
790169
2013-07-12T16:25:29Z
en>Mogism
0
/* Optional parameter: "disambiguation" */Cleanup/[[WP:AWB/T|Typo fixing]], [[WP:AWB/T|typos fixed]]: specifiy → specify using [[Project:AWB|AWB]]
790170
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
== Ship class link template usage ==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first link is properly formatted with the ''Class name'' displayed in italics followed by "-class".
This template is for ship classes that are named after the [[lead ship]]. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} instead.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}}Use Option 1
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}}Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[bn:টেমপ্লেট:Sclass]]
[[fr:Modèle:Classe]]
[[zh:Template:Sclass]]
</includeonly>
4zu86i6js7o0wvegxxvnt3zln508ioa
790171
790170
2015-04-15T11:35:14Z
en>Techhead7890
0
Some clarification and comparison to sclass- and other similar templates.
790171
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}}Use Option 1
To avoid the dreaded [[red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}}Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[bn:টেমপ্লেট:Sclass]]
[[fr:Modèle:Classe]]
[[zh:Template:Sclass]]
</includeonly>
k21ldqs2v0h2qqhnh31yt5cz7r4ws26
790172
790171
2016-03-03T22:02:19Z
en>LittleWink
0
Disambiguate [[Red link]] to [[Wikipedia:Red link]] using [[:en:Wikipedia:Tools/Navigation_popups|popups]]
790172
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}}Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}}Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[bn:টেমপ্লেট:Sclass]]
[[fr:Modèle:Classe]]
[[zh:Template:Sclass]]
</includeonly>
qelqp5bfsvtx1d9b7cxgx5dnttte4rd
790173
790172
2017-05-01T09:49:24Z
en>Colonies Chris
0
removed example no longer appropriate
790173
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}}Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}}Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
[[bn:টেমপ্লেট:Sclass]]
[[fr:Modèle:Classe]]
[[zh:Template:Sclass]]
</includeonly>
2cg5xx6wke4lqokc8rf7gy2efadu5gb
790174
790173
2017-06-24T10:43:07Z
en>Trappist the monk
0
keep sandbox out of cats;
790174
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}}Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}}Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox||
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
}}
</includeonly>
k8qvzour5wpb0qnpzfccuufy8oxn44c
790175
790174
2017-10-12T12:02:56Z
en>Trappist the monk
0
/* Examples */ space;
790175
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}}Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}} Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox||
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
}}
</includeonly>
2ap5nnc7jarql44t626as4d1j3r82pf
790176
790175
2017-10-12T12:14:31Z
en>Trappist the monk
0
/* Usage */ space;
790176
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}} Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}} Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox||
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Ship templates]]
}}
</includeonly>
sbhd254mmasa40pf5o19rrwphc0w57x
790177
790176
2018-02-28T18:37:17Z
en>DePiep
0
/* See also */ add template data
790177
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}} Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}} Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
==Template data==
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates]]
}}</includeonly>
8fu5npdi5nc9v70u5pet279dw4ukl2l
790178
790177
2018-02-28T18:38:55Z
en>DePiep
0
/* Template data */
790178
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}} Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}} Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
==Template data==
{{TemplateDataHeader}}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates]]
}}</includeonly>
2ymyzw4yvnqt6zjpku2gi35i9pl11p9
790179
790178
2018-02-28T18:46:49Z
en>DePiep
0
/* Template data */
790179
wikitext
text/x-wiki
{{Documentation subpage}}
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}} Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}} Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "disambiguation"
},
"5": {
"label": "unknown",
"description": "(undocumented)"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates]]
}}</includeonly>
65zfuxvniincftr4yam23b9yfkoqt0r
790180
790179
2018-02-28T18:48:20Z
en>DePiep
0
Add TemplateData (via [[WP:JWB]])
790180
wikitext
text/x-wiki
{{Documentation subpage}}
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}} Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}} Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "disambiguation"
},
"5": {
"label": "unknown",
"description": "(undocumented)"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates]]
}}</includeonly>
k6j7q6e91yl85seovjgzdar6e5ba4hm
790181
790180
2018-03-11T17:04:58Z
en>DePiep
0
790181
wikitext
text/x-wiki
{{Documentation subpage}}
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki> or similar, this is for you. The previous is replaced by <nowiki>{{sclass | Haskell | attack transport}}</nowiki>, that's it.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}} Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}} Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "disambiguation"
},
"5": {
"label": "unknown",
"description": "(undocumented)"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
5ja7e668g676vjsunzxc39d6lgxn8xs
790182
790181
2018-03-17T12:34:14Z
en>DePiep
0
790182
wikitext
text/x-wiki
{{Documentation subpage}}
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <code><nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki></code>, this is for you. The previous can be replaced by <code><nowiki>{{sclass | Haskell | attack transport}}</nowiki></code>, showing {{sclass | Haskell | attack transport}}.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
==Usage==
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}} Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}} Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "disambiguation"
},
"5": {
"label": "unknown",
"description": "(undocumented)"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
daltg35nae8i3hg6jlpb5x5lvocc1xt
790183
790182
2018-03-18T02:41:49Z
en>DePiep
0
Deprecated template|Sclass|Sclass-|date=March 2018
790183
wikitext
text/x-wiki
{{Documentation subpage}}
{{Deprecated template|Sclass|Sclass-|date=March 2018}}
==Usage==
'''sclass''' is an editor's shortcut for creating properly formatted links to ship class articles that follow the standard naming format of '''''Class name'' class ''ship type'''''. In other words, this template should be used when the article title ''does not'' have a hyphen. If you are tired of typing <code><nowiki>[[Haskell class attack transport | ''Haskell''-class]] [[attack transport]]</nowiki></code>, this is for you. The previous can be replaced by <code><nowiki>{{sclass | Haskell | attack transport}}</nowiki></code>, showing {{sclass | Haskell | attack transport}}.
The most basic form is:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' <nowiki>}}</nowiki>'''
This form assumes that ''Ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship'' type article. The text in the first (class name) link is properly formatted with the ''Class name'' displayed in italics followed by "-class", '''regardless of the actual title of the article'''.
This template is for ship classes that are named after the [[lead ship]] or member of the class, for which the class name is italicized. For ship classes that are named for a common theme, such as the {{sclass2|Flower|corvette|1}}, use {{tl|sclass2}} without italics instead.
This is part of a set of templates, as per the ''See also'' section. This includes {{tlx|sclass}} for when the title is hyphenated, {{tlx|sclass-}} for when the title ''is hyphenated'' and {{tlx|sclass2}} for when the link displayed should not be italicised.
===Optional parameter: "format"===
An optional third parameter allows you to control the format and use the template if ''Ship type'' is not an article:
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' <nowiki>}}</nowiki>'''
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form
:1: displays ''ship type'' as part of the single link to the class article
:2: displays ''ship type'', but unlinked
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
:6: {{!xt |Deprecated}} Use Option 1
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
==== Examples ====
{|class="wikitable nowraplinks"
|-
! <small>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Haskell|attack transport}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport}}
| Default
|-
! 0
| <nowiki>{{sclass|Haskell|attack transport|0}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]]</nowiki>
| {{sclass|Haskell|attack transport|0}}
| Adjectival form
|-
! 1
| <nowiki>{{sclass|Haskell|attack transport|1}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|1}}
| Article title
|-
! 2
| <nowiki>{{sclass|Haskell|attack transport|2}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] attack transport</nowiki>
| {{sclass|Haskell|attack transport|2}}
| When the ship type article does not exist
|-
! 3
| <nowiki>{{sclass|Haskell|attack transport|3}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell''-class]] [[attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|3}}
| Same as default
|-
! 4
| <nowiki>{{sclass|Haskell|attack transport|4}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class]]</nowiki>
| {{sclass|Haskell|attack transport|4}}
| Noun form
|-
! 5
| <nowiki>{{sclass|Haskell|attack transport|5}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'']]</nowiki>
| {{sclass|Haskell|attack transport|5}}
| Table or chart form
|-
! 6
| <nowiki>{{sclass|Haskell|attack transport|6}}</nowiki>
| <nowiki>[[Haskell class attack transport|''Haskell'' class attack transport]]</nowiki>
| {{sclass|Haskell|attack transport|6}}
| {{!xt |Deprecated}} Use Option 1
|}
===Optional parameter: "disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page<!--- (i.e. [[Minesweeper (ship)|minesweeper]]<!-- please don't disambiguate this link -->):
'''<nowiki>{{</nowiki>sclass | ''Class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>'''
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
==== Examples ====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "disambiguation"
},
"5": {
"label": "unknown",
"description": "(undocumented)"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
ovcweodwpbgk8moh9bjb6iw0nd7fgvk
790184
790183
2018-03-18T02:47:47Z
en>DePiep
0
deprecated
790184
wikitext
text/x-wiki
{{Documentation subpage}}
{{Deprecated template|Sclass|Sclass-|date=March 2018}}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
8hffkzyiyxoxx6gi38ibtudmnc6whom
790185
790184
2018-03-21T20:14:12Z
en>DePiep
0
790185
wikitext
text/x-wiki
{{Documentation subpage}}
{{Deprecated template|Sclass|Sclass-|date=March 2018}}
This template is deprecated and should not be used in mainspace.
It is preserved here to serve non-mainspace pages.
:[[Template:Sclass/core/deprecated]]
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
n3tm7kmpumohowe4pok0sl8bvpa3y2s
790186
790185
2018-03-21T21:17:27Z
en>DePiep
0
790186
wikitext
text/x-wiki
{{Documentation subpage}}
{{Deprecated template|Sclass|Sclass-|date=March 2018}}
This template is deprecated and should not be used in mainspace.
It is preserved here to serve non-mainspace pages.
Code used: [[Template:Sclass/core/deprecated]]
==Template data==
{{collapse top}}
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "disambiguation"
},
"5": {
"label": "unknown",
"description": "(undocumented)"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
{{collapse bottom}}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship deprecated templates|Class]]
}}</includeonly>
er8uwdsqzrxjurypjuo7dqqpnkn7cn5
790187
790186
2018-03-21T21:20:13Z
en>DePiep
0
790187
wikitext
text/x-wiki
{{Documentation subpage}}
{{Deprecated template|Sclass|Sclass-|date=March 2018}}
This template is deprecated and should not be used in mainspace. It is preserved here to serve non-mainspace pages.
Code used: [[Template:Sclass/core/deprecated]]
==Template data==
{{collapse top}}
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "disambiguation"
},
"5": {
"label": "unknown",
"description": "(undocumented)"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
{{collapse bottom}}
== See also ==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship deprecated templates]]
}}</includeonly>
hhopexmd4dabbt7ew02r35agd9byqw5
790188
790187
2020-12-12T18:18:44Z
en>Trappist the monk
0
mirror [[Template:sclass-]] per [[Wikipedia:Templates for discussion/Log/2020 October 22#Template:Sclass]]
790188
wikitext
text/x-wiki
{{Documentation subpage}}
Ship class articles have titles that are hyphenated. A typical ship-class article name has the form:
:<class name>'''-'''class <ship type>
When a ship class is named for a member of the class, the class name is italicized. For these classes use {{tlx|sclass}}. Classes not named for a member of the class are not italicized, in which case use {{tlx|sclass2}}.
==Usage==
'''<code>sclass</code>''' is an editor's shortcut for creating properly formatted links to ship-class articles with hyphenated titles: ''class name''-class ship type.
The basic form:
::<code><nowiki>{{</nowiki>sclass | ''class name'' | ''ship type''<nowiki>}}</nowiki></code>
replaces:
::<code><nowiki>[[</nowiki>''class name''-class ''ship type'' | ''class name''-class<nowiki>]]</nowiki> <nowiki>[[</nowiki>''ship type''<nowiki>]]</nowiki></code>
This form assumes that ''ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship type'' article. The text in the first link is properly formatted with the ''class name'' displayed in italics followed by "-class". Note that if referring to the ship class as a noun, the hyphen may be removed with the formatting options below, even though is part of the article title.
===Optional unnamed format control parameter===
An optional third parameter allows you to control the format and use the template if ''ship type'' is not an article:
::<code>{{tlx|sclass| ''class name'' | ''ship type'' | ''format''}}</code>
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form.
:1: displays ''ship type'' as part of a single link to the class article.
:2: displays unlinked ''ship type''.
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
{|class="wikitable nowraplinks"
|+Examples
|-
! Format
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <code><nowiki>{{sclas- |Valiant |harbor tug }}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug }}
| Default
|-
! 0
| <code><nowiki>{{sclass |Valiant |harbor tug |0}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]]</nowiki></code>
| {{sclass |Valiant |harbor tug |0}}
| Adjectival form
|-
! 1
| <code><nowiki>{{sclass |Valiant |harbor tug |1}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |1}}
| Article titles
|-
! 2
| <code><nowiki>{{sclass |Valiant |harbor tug |2}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] harbor tug </nowiki></code>
| {{sclass |Valiant |harbor tug |2}}
| When the ship type article does not exist
|-
! 3
| <code><nowiki>{{sclass |Valiant |harbor tug |3}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |3}}
| Same as default
|-
! 4
| <code><nowiki>{{sclass |Valiant |harbor tug |4}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'' class]]</nowiki></code>
| {{sclass |Valiant| harbor tug |4}}
| Noun form
|-
! 5
| <code><nowiki>{{sclass |Valiant |harbor tug |5}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |5}}
| Table or chart form
|-
! {{red|6}}
| <code><nowiki>{{sclass |Valiant |harbor tug |6}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |6}}
| Unrecognized format value
|}
===Optional parameter: "ship-type disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page :
<nowiki>{{</nowiki>sclass | ''class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
====Examples====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
===Optional parameter: "class-name disambiguation"===
When there are separate ship classes that share the same name and that use parenthetical disambiguation, for example {{sclass|Königsberg|cruiser}}, use the optional fifth parameter to disambiguate the class-name:
:<code><nowiki>{{sclass|Königsberg|cruiser|||1905}}</nowiki></code> produces {{sclass|Königsberg|cruiser|||1905}} which is the same as:
:<code><nowiki>[[Königsberg-class cruiser (1905)|''Königsberg''-class]] [[cruiser]]</nowiki></code>
The class-name disambiguator is never displayed.
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "ship type disambiguation",
"description": "disambiguation for ship type",
"type": "string"
},
"5": {
"label": "class name disambiguation",
"description": "disambiguation for class name",
"type": "string"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
==See also==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
qxet13pv0vp0yv64pm39sme272e2q4o
790189
790188
2020-12-12T18:19:14Z
en>Trappist the monk
0
/* Optional unnamed format control parameter */
790189
wikitext
text/x-wiki
{{Documentation subpage}}
Ship class articles have titles that are hyphenated. A typical ship-class article name has the form:
:<class name>'''-'''class <ship type>
When a ship class is named for a member of the class, the class name is italicized. For these classes use {{tlx|sclass}}. Classes not named for a member of the class are not italicized, in which case use {{tlx|sclass2}}.
==Usage==
'''<code>sclass</code>''' is an editor's shortcut for creating properly formatted links to ship-class articles with hyphenated titles: ''class name''-class ship type.
The basic form:
::<code><nowiki>{{</nowiki>sclass | ''class name'' | ''ship type''<nowiki>}}</nowiki></code>
replaces:
::<code><nowiki>[[</nowiki>''class name''-class ''ship type'' | ''class name''-class<nowiki>]]</nowiki> <nowiki>[[</nowiki>''ship type''<nowiki>]]</nowiki></code>
This form assumes that ''ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship type'' article. The text in the first link is properly formatted with the ''class name'' displayed in italics followed by "-class". Note that if referring to the ship class as a noun, the hyphen may be removed with the formatting options below, even though is part of the article title.
===Optional unnamed format control parameter===
An optional third parameter allows you to control the format and use the template if ''ship type'' is not an article:
::<code>{{tlx|sclass| ''class name'' | ''ship type'' | ''format''}}</code>
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form.
:1: displays ''ship type'' as part of a single link to the class article.
:2: displays unlinked ''ship type''.
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
{|class="wikitable nowraplinks"
|+Examples
|-
! Format
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <code><nowiki>{{sclass |Valiant |harbor tug }}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug }}
| Default
|-
! 0
| <code><nowiki>{{sclass |Valiant |harbor tug |0}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]]</nowiki></code>
| {{sclass |Valiant |harbor tug |0}}
| Adjectival form
|-
! 1
| <code><nowiki>{{sclass |Valiant |harbor tug |1}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |1}}
| Article titles
|-
! 2
| <code><nowiki>{{sclass |Valiant |harbor tug |2}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] harbor tug </nowiki></code>
| {{sclass |Valiant |harbor tug |2}}
| When the ship type article does not exist
|-
! 3
| <code><nowiki>{{sclass |Valiant |harbor tug |3}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |3}}
| Same as default
|-
! 4
| <code><nowiki>{{sclass |Valiant |harbor tug |4}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'' class]]</nowiki></code>
| {{sclass |Valiant| harbor tug |4}}
| Noun form
|-
! 5
| <code><nowiki>{{sclass |Valiant |harbor tug |5}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |5}}
| Table or chart form
|-
! {{red|6}}
| <code><nowiki>{{sclass |Valiant |harbor tug |6}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |6}}
| Unrecognized format value
|}
===Optional parameter: "ship-type disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page :
<nowiki>{{</nowiki>sclass | ''class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
====Examples====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
===Optional parameter: "class-name disambiguation"===
When there are separate ship classes that share the same name and that use parenthetical disambiguation, for example {{sclass|Königsberg|cruiser}}, use the optional fifth parameter to disambiguate the class-name:
:<code><nowiki>{{sclass|Königsberg|cruiser|||1905}}</nowiki></code> produces {{sclass|Königsberg|cruiser|||1905}} which is the same as:
:<code><nowiki>[[Königsberg-class cruiser (1905)|''Königsberg''-class]] [[cruiser]]</nowiki></code>
The class-name disambiguator is never displayed.
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "ship type disambiguation",
"description": "disambiguation for ship type",
"type": "string"
},
"5": {
"label": "class name disambiguation",
"description": "disambiguation for class name",
"type": "string"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
==See also==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
c0tz0ly5brpramfcs2o6s2g28k0mqyi
790190
790189
2023-03-04T20:14:51Z
en>Trappist the monk
0
/* Optional unnamed format control parameter */ don't categorize demo error;
790190
wikitext
text/x-wiki
{{Documentation subpage}}
Ship class articles have titles that are hyphenated. A typical ship-class article name has the form:
:<class name>'''-'''class <ship type>
When a ship class is named for a member of the class, the class name is italicized. For these classes use {{tlx|sclass}}. Classes not named for a member of the class are not italicized, in which case use {{tlx|sclass2}}.
==Usage==
'''<code>sclass</code>''' is an editor's shortcut for creating properly formatted links to ship-class articles with hyphenated titles: ''class name''-class ship type.
The basic form:
::<code><nowiki>{{</nowiki>sclass | ''class name'' | ''ship type''<nowiki>}}</nowiki></code>
replaces:
::<code><nowiki>[[</nowiki>''class name''-class ''ship type'' | ''class name''-class<nowiki>]]</nowiki> <nowiki>[[</nowiki>''ship type''<nowiki>]]</nowiki></code>
This form assumes that ''ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship type'' article. The text in the first link is properly formatted with the ''class name'' displayed in italics followed by "-class". Note that if referring to the ship class as a noun, the hyphen may be removed with the formatting options below, even though is part of the article title.
===Optional unnamed format control parameter===
An optional third parameter allows you to control the format and use the template if ''ship type'' is not an article:
::<code>{{tlx|sclass| ''class name'' | ''ship type'' | ''format''}}</code>
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form.
:1: displays ''ship type'' as part of a single link to the class article.
:2: displays unlinked ''ship type''.
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
{|class="wikitable nowraplinks"
|+Examples
|-
! Format
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <code><nowiki>{{sclass |Valiant |harbor tug }}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug }}
| Default
|-
! 0
| <code><nowiki>{{sclass |Valiant |harbor tug |0}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]]</nowiki></code>
| {{sclass |Valiant |harbor tug |0}}
| Adjectival form
|-
! 1
| <code><nowiki>{{sclass |Valiant |harbor tug |1}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |1}}
| Article titles
|-
! 2
| <code><nowiki>{{sclass |Valiant |harbor tug |2}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] harbor tug </nowiki></code>
| {{sclass |Valiant |harbor tug |2}}
| When the ship type article does not exist
|-
! 3
| <code><nowiki>{{sclass |Valiant |harbor tug |3}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |3}}
| Same as default
|-
! 4
| <code><nowiki>{{sclass |Valiant |harbor tug |4}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'' class]]</nowiki></code>
| {{sclass |Valiant| harbor tug |4}}
| Noun form
|-
! 5
| <code><nowiki>{{sclass |Valiant |harbor tug |5}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |5}}
| Table or chart form
|-
! {{red|6}}
| <code><nowiki>{{sclass |Valiant |harbor tug |6}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |6 |no-cat=yes}}
| Unrecognized format value
|}
===Optional parameter: "ship-type disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page :
<nowiki>{{</nowiki>sclass | ''class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
====Examples====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
===Optional parameter: "class-name disambiguation"===
When there are separate ship classes that share the same name and that use parenthetical disambiguation, for example {{sclass|Königsberg|cruiser}}, use the optional fifth parameter to disambiguate the class-name:
:<code><nowiki>{{sclass|Königsberg|cruiser|||1905}}</nowiki></code> produces {{sclass|Königsberg|cruiser|||1905}} which is the same as:
:<code><nowiki>[[Königsberg-class cruiser (1905)|''Königsberg''-class]] [[cruiser]]</nowiki></code>
The class-name disambiguator is never displayed.
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "ship type disambiguation",
"description": "disambiguation for ship type",
"type": "string"
},
"5": {
"label": "class name disambiguation",
"description": "disambiguation for class name",
"type": "string"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
==See also==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
9btruq39l7w3q8lykxtqh1n1558yzah
790191
790190
2023-10-05T11:29:25Z
en>MSGJ
0
+lua
790191
wikitext
text/x-wiki
{{Documentation subpage}}
{{Lua|Module:WPSHIPS utilities}}
Ship class articles have titles that are hyphenated. A typical ship-class article name has the form:
:<class name>'''-'''class <ship type>
When a ship class is named for a member of the class, the class name is italicized. For these classes use {{tlx|sclass}}. Classes not named for a member of the class are not italicized, in which case use {{tlx|sclass2}}.
==Usage==
'''<code>sclass</code>''' is an editor's shortcut for creating properly formatted links to ship-class articles with hyphenated titles: ''class name''-class ship type.
The basic form:
::<code><nowiki>{{</nowiki>sclass | ''class name'' | ''ship type''<nowiki>}}</nowiki></code>
replaces:
::<code><nowiki>[[</nowiki>''class name''-class ''ship type'' | ''class name''-class<nowiki>]]</nowiki> <nowiki>[[</nowiki>''ship type''<nowiki>]]</nowiki></code>
This form assumes that ''ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship type'' article. The text in the first link is properly formatted with the ''class name'' displayed in italics followed by "-class". Note that if referring to the ship class as a noun, the hyphen may be removed with the formatting options below, even though is part of the article title.
===Optional unnamed format control parameter===
An optional third parameter allows you to control the format and use the template if ''ship type'' is not an article:
::<code>{{tlx|sclass| ''class name'' | ''ship type'' | ''format''}}</code>
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form.
:1: displays ''ship type'' as part of a single link to the class article.
:2: displays unlinked ''ship type''.
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
{|class="wikitable nowraplinks"
|+Examples
|-
! Format
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <code><nowiki>{{sclass |Valiant |harbor tug }}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug }}
| Default
|-
! 0
| <code><nowiki>{{sclass |Valiant |harbor tug |0}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]]</nowiki></code>
| {{sclass |Valiant |harbor tug |0}}
| Adjectival form
|-
! 1
| <code><nowiki>{{sclass |Valiant |harbor tug |1}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |1}}
| Article titles
|-
! 2
| <code><nowiki>{{sclass |Valiant |harbor tug |2}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] harbor tug </nowiki></code>
| {{sclass |Valiant |harbor tug |2}}
| When the ship type article does not exist
|-
! 3
| <code><nowiki>{{sclass |Valiant |harbor tug |3}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |3}}
| Same as default
|-
! 4
| <code><nowiki>{{sclass |Valiant |harbor tug |4}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'' class]]</nowiki></code>
| {{sclass |Valiant| harbor tug |4}}
| Noun form
|-
! 5
| <code><nowiki>{{sclass |Valiant |harbor tug |5}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |5}}
| Table or chart form
|-
! {{red|6}}
| <code><nowiki>{{sclass |Valiant |harbor tug |6}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |6 |no-cat=yes}}
| Unrecognized format value
|}
===Optional parameter: "ship-type disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page :
<nowiki>{{</nowiki>sclass | ''class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
====Examples====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
===Optional parameter: "class-name disambiguation"===
When there are separate ship classes that share the same name and that use parenthetical disambiguation, for example {{sclass|Königsberg|cruiser}}, use the optional fifth parameter to disambiguate the class-name:
:<code><nowiki>{{sclass|Königsberg|cruiser|||1905}}</nowiki></code> produces {{sclass|Königsberg|cruiser|||1905}} which is the same as:
:<code><nowiki>[[Königsberg-class cruiser (1905)|''Königsberg''-class]] [[cruiser]]</nowiki></code>
The class-name disambiguator is never displayed.
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "ship type disambiguation",
"description": "disambiguation for ship type",
"type": "string"
},
"5": {
"label": "class name disambiguation",
"description": "disambiguation for class name",
"type": "string"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
==See also==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
m66see6jl2hyr2oz5ygkcsie3ponund
790192
790191
2023-12-26T20:53:01Z
en>Tom.Reding
0
{{High-use}}
790192
wikitext
text/x-wiki
{{Documentation subpage}}
{{High-use}}
{{Lua|Module:WPSHIPS utilities}}
Ship class articles have titles that are hyphenated. A typical ship-class article name has the form:
:<class name>'''-'''class <ship type>
When a ship class is named for a member of the class, the class name is italicized. For these classes use {{tlx|sclass}}. Classes not named for a member of the class are not italicized, in which case use {{tlx|sclass2}}.
==Usage==
'''<code>sclass</code>''' is an editor's shortcut for creating properly formatted links to ship-class articles with hyphenated titles: ''class name''-class ship type.
The basic form:
::<code><nowiki>{{</nowiki>sclass | ''class name'' | ''ship type''<nowiki>}}</nowiki></code>
replaces:
::<code><nowiki>[[</nowiki>''class name''-class ''ship type'' | ''class name''-class<nowiki>]]</nowiki> <nowiki>[[</nowiki>''ship type''<nowiki>]]</nowiki></code>
This form assumes that ''ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship type'' article. The text in the first link is properly formatted with the ''class name'' displayed in italics followed by "-class". Note that if referring to the ship class as a noun, the hyphen may be removed with the formatting options below, even though is part of the article title.
===Optional unnamed format control parameter===
An optional third parameter allows you to control the format and use the template if ''ship type'' is not an article:
::<code>{{tlx|sclass| ''class name'' | ''ship type'' | ''format''}}</code>
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form.
:1: displays ''ship type'' as part of a single link to the class article.
:2: displays unlinked ''ship type''.
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
{|class="wikitable nowraplinks"
|+Examples
|-
! Format
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <code><nowiki>{{sclass |Valiant |harbor tug }}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug }}
| Default
|-
! 0
| <code><nowiki>{{sclass |Valiant |harbor tug |0}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]]</nowiki></code>
| {{sclass |Valiant |harbor tug |0}}
| Adjectival form
|-
! 1
| <code><nowiki>{{sclass |Valiant |harbor tug |1}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |1}}
| Article titles
|-
! 2
| <code><nowiki>{{sclass |Valiant |harbor tug |2}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] harbor tug </nowiki></code>
| {{sclass |Valiant |harbor tug |2}}
| When the ship type article does not exist
|-
! 3
| <code><nowiki>{{sclass |Valiant |harbor tug |3}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |3}}
| Same as default
|-
! 4
| <code><nowiki>{{sclass |Valiant |harbor tug |4}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'' class]]</nowiki></code>
| {{sclass |Valiant| harbor tug |4}}
| Noun form
|-
! 5
| <code><nowiki>{{sclass |Valiant |harbor tug |5}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |5}}
| Table or chart form
|-
! {{red|6}}
| <code><nowiki>{{sclass |Valiant |harbor tug |6}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |6 |no-cat=yes}}
| Unrecognized format value
|}
===Optional parameter: "ship-type disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page :
<nowiki>{{</nowiki>sclass | ''class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
====Examples====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
===Optional parameter: "class-name disambiguation"===
When there are separate ship classes that share the same name and that use parenthetical disambiguation, for example {{sclass|Königsberg|cruiser}}, use the optional fifth parameter to disambiguate the class-name:
:<code><nowiki>{{sclass|Königsberg|cruiser|||1905}}</nowiki></code> produces {{sclass|Königsberg|cruiser|||1905}} which is the same as:
:<code><nowiki>[[Königsberg-class cruiser (1905)|''Königsberg''-class]] [[cruiser]]</nowiki></code>
The class-name disambiguator is never displayed.
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "ship type disambiguation",
"description": "disambiguation for ship type",
"type": "string"
},
"5": {
"label": "class name disambiguation",
"description": "disambiguation for class name",
"type": "string"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
==See also==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
50lu75i6p95nohhattuuxld1qhmz2v7
790193
790192
2026-04-03T08:34:19Z
SM7
3953
47 revisions imported from [[:en:Template:Sclass/doc]]
790192
wikitext
text/x-wiki
{{Documentation subpage}}
{{High-use}}
{{Lua|Module:WPSHIPS utilities}}
Ship class articles have titles that are hyphenated. A typical ship-class article name has the form:
:<class name>'''-'''class <ship type>
When a ship class is named for a member of the class, the class name is italicized. For these classes use {{tlx|sclass}}. Classes not named for a member of the class are not italicized, in which case use {{tlx|sclass2}}.
==Usage==
'''<code>sclass</code>''' is an editor's shortcut for creating properly formatted links to ship-class articles with hyphenated titles: ''class name''-class ship type.
The basic form:
::<code><nowiki>{{</nowiki>sclass | ''class name'' | ''ship type''<nowiki>}}</nowiki></code>
replaces:
::<code><nowiki>[[</nowiki>''class name''-class ''ship type'' | ''class name''-class<nowiki>]]</nowiki> <nowiki>[[</nowiki>''ship type''<nowiki>]]</nowiki></code>
This form assumes that ''ship type'' is its own separate article so produces a link to the class article, followed by a link to the ''ship type'' article. The text in the first link is properly formatted with the ''class name'' displayed in italics followed by "-class". Note that if referring to the ship class as a noun, the hyphen may be removed with the formatting options below, even though is part of the article title.
===Optional unnamed format control parameter===
An optional third parameter allows you to control the format and use the template if ''ship type'' is not an article:
::<code>{{tlx|sclass| ''class name'' | ''ship type'' | ''format''}}</code>
The values and results for ''format'' are:
:0: suppresses ''ship type'' display entirely. Adjectival form.
:1: displays ''ship type'' as part of a single link to the class article.
:2: displays unlinked ''ship type''.
:3: displays ''ship type'' as a separate link. ''Ship type'' must be the name of an article.
:4: suppresses ''ship type'' display entirely. Noun form.
:5: class name only, suitable for tables
To avoid the dreaded [[Wikipedia:Red link|red link]], one of the first three options must be used if ''Ship type'' is not already an article. Note that option 3 is the default, so may be omitted. Other values of ''format'' will let you know the error of your ways.
{|class="wikitable nowraplinks"
|+Examples
|-
! Format
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <code><nowiki>{{sclass |Valiant |harbor tug }}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug }}
| Default
|-
! 0
| <code><nowiki>{{sclass |Valiant |harbor tug |0}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]]</nowiki></code>
| {{sclass |Valiant |harbor tug |0}}
| Adjectival form
|-
! 1
| <code><nowiki>{{sclass |Valiant |harbor tug |1}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |1}}
| Article titles
|-
! 2
| <code><nowiki>{{sclass |Valiant |harbor tug |2}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] harbor tug </nowiki></code>
| {{sclass |Valiant |harbor tug |2}}
| When the ship type article does not exist
|-
! 3
| <code><nowiki>{{sclass |Valiant |harbor tug |3}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant''-class]] [[harbor tug ]]</nowiki></code>
| {{sclass |Valiant |harbor tug |3}}
| Same as default
|-
! 4
| <code><nowiki>{{sclass |Valiant |harbor tug |4}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'' class]]</nowiki></code>
| {{sclass |Valiant| harbor tug |4}}
| Noun form
|-
! 5
| <code><nowiki>{{sclass |Valiant |harbor tug |5}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |5}}
| Table or chart form
|-
! {{red|6}}
| <code><nowiki>{{sclass |Valiant |harbor tug |6}}</nowiki></code>
| <code><nowiki>[[Valiant-class harbor tug |''Valiant'']]</nowiki></code>
| {{sclass |Valiant |harbor tug |6 |no-cat=yes}}
| Unrecognized format value
|}
===Optional parameter: "ship-type disambiguation"===
An optional fourth parameter allows you to disambiguate the ship type if it would ordinarily link to a disambiguation page :
<nowiki>{{</nowiki>sclass | ''class name'' | ''ship type'' | ''format'' | ''disambiguation'' <nowiki>}}</nowiki>
This would only be needed with either the default or with the "format" parameter set to 3. Note: to use the disambiguation parameter, you must specify a "format" parameter, or use "{{!}}{{!}}" (double pipe) between the "ship type" and "disambiguation" parameters.
<!--
====Examples====
{|class=wikitable width="100%"
|-
! <small>Format<br>Para-<br>meter</small>
! Template usage
! Equivalent wikicode
! Final result
! Notes
|-
! None
| <nowiki>{{sclass|Admirable|minesweeper||ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper|''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper||ship}}
| Default
|-
! 3
| <nowiki>{{sclass|Admirable|minesweeper|3|ship}}</nowiki>
| <nowiki>[[Admirable-class minesweeper |''Admirable''-class]] [[minesweeper (ship)|minesweeper]]</nowiki>
| {{sclass|Admirable|minesweeper|3|ship}}
| Same as default
|-
|} -->
===Optional parameter: "class-name disambiguation"===
When there are separate ship classes that share the same name and that use parenthetical disambiguation, for example {{sclass|Königsberg|cruiser}}, use the optional fifth parameter to disambiguate the class-name:
:<code><nowiki>{{sclass|Königsberg|cruiser|||1905}}</nowiki></code> produces {{sclass|Königsberg|cruiser|||1905}} which is the same as:
:<code><nowiki>[[Königsberg-class cruiser (1905)|''Königsberg''-class]] [[cruiser]]</nowiki></code>
The class-name disambiguator is never displayed.
==Template data==
{{TemplateDataHeader}}
<templatedata>
{
"params": {
"1": {
"label": "class name",
"type": "string"
},
"2": {
"label": "ship type"
},
"3": {
"label": "format",
"description": "Format options 1, 2, 3, 4, 5",
"type": "number"
},
"4": {
"label": "ship type disambiguation",
"description": "disambiguation for ship type",
"type": "string"
},
"5": {
"label": "class name disambiguation",
"description": "disambiguation for class name",
"type": "string"
}
},
"description": "Formats ship class name and ship type into article link. Italicises class name."
}
</templatedata>
==See also==
{{WPSHIPS shortcut templates}}
<includeonly>{{sandbox other||
[[Category:Ship templates|Class]]
}}</includeonly>
50lu75i6p95nohhattuuxld1qhmz2v7
Module:WPSHIPS utilities/data
828
100497
790238
2021-06-19T16:08:03Z
en>Trappist the monk
0
create;
790238
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship name'] = {2, 'Name'},
['Ship namesake'] = {3, 'Namesake'},
['Ship owner'] = {4, 'Owner'},
['Ship operator'] = {5, 'Operator'},
['Ship registry'] = {6, 'Port of registry'},
['Ship route'] = {7, 'Route'},
['Ship ordered'] = {8, 'Ordered'},
['Ship awarded'] = {9, 'Awarded'},
['Ship builder'] = {10, 'Builder'},
['Ship original cost'] = {11, 'Cost'},
['Ship yard number'] = {12, 'Yard number'},
['Ship way number'] = {13, 'Way number'},
['Ship laid down'] = {14, 'Laid down'},
['Ship launched'] = {15, 'Launched'},
['Ship sponsor'] = {16, 'Sponsored by'},
['Ship christened'] = {17, 'Christened'},
['Ship completed'] = {18, 'Completed'},
['Ship acquired'] = {19, 'Acquired'},
['Ship commissioned'] = {20, 'Commissioned'},
['Ship recommissioned'] = {21, 'Recommissioned'},
['Ship decommissioned'] = {22, 'Decommissioned'},
['Ship maiden voyage'] = {23, 'Maiden voyage'},
['Ship in service'] = {24, 'In service'},
['Ship out of service'] = {25, 'Out of service'},
['Ship renamed'] = {26, 'Renamed'},
['Ship reclassified'] = {27, 'Reclassified'},
['Ship refit'] = {28, 'Refit'},
['Ship struck'] = {29, 'Struck'},
['Ship reinstated'] = {30, 'Reinstated'},
['Ship homeport'] = {31, 'Homeport'},
['Ship identification'] = {32, 'Identification'},
['Ship motto'] = {33, 'Motto'},
['Ship nickname'] = {34, 'Nickname(s)'},
['Ship honours'] = {35, 'Honours and<br />awards'}, -- make these two the same index?
['Ship honors'] = {36, 'Honors and<br />awards'},
['Ship captured'] = {37, 'Captured'},
['Ship fate'] = {38, 'Fate'},
['Ship status'] = {39, 'Status'},
['Ship notes'] = {40, 'Notes'},
['Ship badge'] = {41, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing <br /> craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors and <br /> processing systems'},
['Ship EW'] = {31, 'Electronic warfare <br /> & decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships complete'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_list_t = nationality_list_t,
ship_prefix_list_t = ship_prefix_list_t,
ship_type_list_t = ship_type_list_t,
}
sdtun6kdz7hqfhw2qqo46i7t9zldfyy
790239
790238
2021-06-19T18:34:11Z
en>Trappist the monk
0
790239
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship name'] = {2, 'Name'},
['Ship namesake'] = {3, 'Namesake'},
['Ship owner'] = {4, 'Owner'},
['Ship operator'] = {5, 'Operator'},
['Ship registry'] = {6, 'Port of registry'},
['Ship route'] = {7, 'Route'},
['Ship ordered'] = {8, 'Ordered'},
['Ship awarded'] = {9, 'Awarded'},
['Ship builder'] = {10, 'Builder'},
['Ship original cost'] = {11, 'Cost'},
['Ship yard number'] = {12, 'Yard number'},
['Ship way number'] = {13, 'Way number'},
['Ship laid down'] = {14, 'Laid down'},
['Ship launched'] = {15, 'Launched'},
['Ship sponsor'] = {16, 'Sponsored by'},
['Ship christened'] = {17, 'Christened'},
['Ship completed'] = {18, 'Completed'},
['Ship acquired'] = {19, 'Acquired'},
['Ship commissioned'] = {20, 'Commissioned'},
['Ship recommissioned'] = {21, 'Recommissioned'},
['Ship decommissioned'] = {22, 'Decommissioned'},
['Ship maiden voyage'] = {23, 'Maiden voyage'},
['Ship in service'] = {24, 'In service'},
['Ship out of service'] = {25, 'Out of service'},
['Ship renamed'] = {26, 'Renamed'},
['Ship reclassified'] = {27, 'Reclassified'},
['Ship refit'] = {28, 'Refit'},
['Ship struck'] = {29, 'Struck'},
['Ship reinstated'] = {30, 'Reinstated'},
['Ship homeport'] = {31, 'Homeport'},
['Ship identification'] = {32, 'Identification'},
['Ship motto'] = {33, 'Motto'},
['Ship nickname'] = {34, 'Nickname(s)'},
['Ship honours'] = {35, 'Honours and<br />awards'}, -- make these two the same index?
['Ship honors'] = {36, 'Honors and<br />awards'},
['Ship captured'] = {37, 'Captured'},
['Ship fate'] = {38, 'Fate'},
['Ship status'] = {39, 'Status'},
['Ship notes'] = {40, 'Notes'},
['Ship badge'] = {41, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing <br /> craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors and <br /> processing systems'},
['Ship EW'] = {31, 'Electronic warfare <br /> & decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships complete'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
}
9amkx666bju7nd1wsxa40d5efvcu56l
790240
790239
2021-06-19T19:53:34Z
en>Trappist the monk
0
790240
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship name'] = {2, 'Name'},
['Ship namesake'] = {3, 'Namesake'},
['Ship owner'] = {4, 'Owner'},
['Ship operator'] = {5, 'Operator'},
['Ship registry'] = {6, 'Port of registry'},
['Ship route'] = {7, 'Route'},
['Ship ordered'] = {8, 'Ordered'},
['Ship awarded'] = {9, 'Awarded'},
['Ship builder'] = {10, 'Builder'},
['Ship original cost'] = {11, 'Cost'},
['Ship yard number'] = {12, 'Yard number'},
['Ship way number'] = {13, 'Way number'},
['Ship laid down'] = {14, 'Laid down'},
['Ship launched'] = {15, 'Launched'},
['Ship sponsor'] = {16, 'Sponsored by'},
['Ship christened'] = {17, 'Christened'},
['Ship completed'] = {18, 'Completed'},
['Ship acquired'] = {19, 'Acquired'},
['Ship commissioned'] = {20, 'Commissioned'},
['Ship recommissioned'] = {21, 'Recommissioned'},
['Ship decommissioned'] = {22, 'Decommissioned'},
['Ship maiden voyage'] = {23, 'Maiden voyage'},
['Ship in service'] = {24, 'In service'},
['Ship out of service'] = {25, 'Out of service'},
['Ship renamed'] = {26, 'Renamed'},
['Ship reclassified'] = {27, 'Reclassified'},
['Ship refit'] = {28, 'Refit'},
['Ship struck'] = {29, 'Struck'},
['Ship reinstated'] = {30, 'Reinstated'},
['Ship homeport'] = {31, 'Homeport'},
['Ship identification'] = {32, 'Identification'},
['Ship motto'] = {33, 'Motto'},
['Ship nickname'] = {34, 'Nickname(s)'},
['Ship honours'] = {35, 'Honours and<br />awards'}, -- make these two the same index?
['Ship honors'] = {36, 'Honors and<br />awards'},
['Ship captured'] = {37, 'Captured'},
['Ship fate'] = {38, 'Fate'},
['Ship status'] = {39, 'Status'},
['Ship notes'] = {40, 'Notes'},
['Ship badge'] = {41, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing <br /> craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors and <br /> processing systems'},
['Ship EW'] = {31, 'Electronic warfare <br /> & decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships completed'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
}
a03dbfhn2hslbqdpfz0jeptjd46tb9z
790241
790240
2021-06-19T22:33:19Z
en>Trappist the monk
0
790241
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship name'] = {2, 'Name'},
['Ship namesake'] = {3, 'Namesake'},
['Ship owner'] = {4, 'Owner'},
['Ship operator'] = {5, 'Operator'},
['Ship registry'] = {6, 'Port of registry'},
['Ship route'] = {7, 'Route'},
['Ship ordered'] = {8, 'Ordered'},
['Ship awarded'] = {9, 'Awarded'},
['Ship builder'] = {10, 'Builder'},
['Ship original cost'] = {11, 'Cost'},
['Ship yard number'] = {12, 'Yard number'},
['Ship way number'] = {13, 'Way number'},
['Ship laid down'] = {14, 'Laid down'},
['Ship launched'] = {15, 'Launched'},
['Ship sponsor'] = {16, 'Sponsored by'},
['Ship christened'] = {17, 'Christened'},
['Ship completed'] = {18, 'Completed'},
['Ship acquired'] = {19, 'Acquired'},
['Ship commissioned'] = {20, 'Commissioned'},
['Ship recommissioned'] = {21, 'Recommissioned'},
['Ship decommissioned'] = {22, 'Decommissioned'},
['Ship maiden voyage'] = {23, 'Maiden voyage'},
['Ship in service'] = {24, 'In service'},
['Ship out of service'] = {25, 'Out of service'},
['Ship renamed'] = {26, 'Renamed'},
['Ship reclassified'] = {27, 'Reclassified'},
['Ship refit'] = {28, 'Refit'},
['Ship struck'] = {29, 'Stricken'},
['Ship stricken'] = {29, 'Stricken'},
['Ship reinstated'] = {30, 'Reinstated'},
['Ship homeport'] = {31, 'Homeport'},
['Ship identification'] = {32, 'Identification'},
['Ship motto'] = {33, 'Motto'},
['Ship nickname'] = {34, 'Nickname(s)'},
['Ship honours'] = {35, 'Honours and<br />awards'}, -- make these two the same index?
['Ship honors'] = {36, 'Honors and<br />awards'},
['Ship captured'] = {37, 'Captured'},
['Ship fate'] = {38, 'Fate'},
['Ship status'] = {39, 'Status'},
['Ship notes'] = {40, 'Notes'},
['Ship badge'] = {41, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing <br /> craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors and <br /> processing systems'},
['Ship EW'] = {31, 'Electronic warfare <br /> & decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships completed'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
}
bh8dlcxqi5om4z8i8qqa3klbchkpnkf
790242
790241
2021-06-19T22:40:59Z
en>Trappist the monk
0
790242
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship name'] = {2, 'Name'},
['Ship namesake'] = {3, 'Namesake'},
['Ship owner'] = {4, 'Owner'},
['Ship operator'] = {5, 'Operator'},
['Ship registry'] = {6, 'Port of registry'},
['Ship route'] = {7, 'Route'},
['Ship ordered'] = {8, 'Ordered'},
['Ship awarded'] = {9, 'Awarded'},
['Ship builder'] = {10, 'Builder'},
['Ship original cost'] = {11, 'Cost'},
['Ship yard number'] = {12, 'Yard number'},
['Ship way number'] = {13, 'Way number'},
['Ship laid down'] = {14, 'Laid down'},
['Ship launched'] = {15, 'Launched'},
['Ship sponsor'] = {16, 'Sponsored by'},
['Ship christened'] = {17, 'Christened'},
['Ship completed'] = {18, 'Completed'},
['Ship acquired'] = {19, 'Acquired'},
['Ship commissioned'] = {20, 'Commissioned'},
['Ship recommissioned'] = {21, 'Recommissioned'},
['Ship decommissioned'] = {22, 'Decommissioned'},
['Ship maiden voyage'] = {23, 'Maiden voyage'},
['Ship in service'] = {24, 'In service'},
['Ship out of service'] = {25, 'Out of service'},
['Ship renamed'] = {26, 'Renamed'},
['Ship reclassified'] = {27, 'Reclassified'},
['Ship refit'] = {28, 'Refit'},
['Ship struck'] = {29, 'Stricken'},
['Ship stricken'] = {30, 'Stricken'},
['Ship reinstated'] = {31, 'Reinstated'},
['Ship homeport'] = {32, 'Homeport'},
['Ship identification'] = {33, 'Identification'},
['Ship motto'] = {34, 'Motto'},
['Ship nickname'] = {35, 'Nickname(s)'},
['Ship honours'] = {36, 'Honours and<br />awards'}, -- make these two the same index?
['Ship honors'] = {37, 'Honors and<br />awards'},
['Ship captured'] = {38, 'Captured'},
['Ship fate'] = {39, 'Fate'},
['Ship status'] = {40, 'Status'},
['Ship notes'] = {41, 'Notes'},
['Ship badge'] = {42, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing <br /> craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors and <br /> processing systems'},
['Ship EW'] = {31, 'Electronic warfare <br /> & decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships completed'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
}
1vqb4uqihtbyfmlxc4aeajwy4l8ziww
790243
790242
2021-06-23T17:59:54Z
en>MusikBot II
0
Protected "[[Module:WPSHIPS utilities/data]]": [[Wikipedia:High-risk templates|High-risk template or module]] ([[User:MusikBot II/TemplateProtector|more info]]) ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))
790242
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship name'] = {2, 'Name'},
['Ship namesake'] = {3, 'Namesake'},
['Ship owner'] = {4, 'Owner'},
['Ship operator'] = {5, 'Operator'},
['Ship registry'] = {6, 'Port of registry'},
['Ship route'] = {7, 'Route'},
['Ship ordered'] = {8, 'Ordered'},
['Ship awarded'] = {9, 'Awarded'},
['Ship builder'] = {10, 'Builder'},
['Ship original cost'] = {11, 'Cost'},
['Ship yard number'] = {12, 'Yard number'},
['Ship way number'] = {13, 'Way number'},
['Ship laid down'] = {14, 'Laid down'},
['Ship launched'] = {15, 'Launched'},
['Ship sponsor'] = {16, 'Sponsored by'},
['Ship christened'] = {17, 'Christened'},
['Ship completed'] = {18, 'Completed'},
['Ship acquired'] = {19, 'Acquired'},
['Ship commissioned'] = {20, 'Commissioned'},
['Ship recommissioned'] = {21, 'Recommissioned'},
['Ship decommissioned'] = {22, 'Decommissioned'},
['Ship maiden voyage'] = {23, 'Maiden voyage'},
['Ship in service'] = {24, 'In service'},
['Ship out of service'] = {25, 'Out of service'},
['Ship renamed'] = {26, 'Renamed'},
['Ship reclassified'] = {27, 'Reclassified'},
['Ship refit'] = {28, 'Refit'},
['Ship struck'] = {29, 'Stricken'},
['Ship stricken'] = {30, 'Stricken'},
['Ship reinstated'] = {31, 'Reinstated'},
['Ship homeport'] = {32, 'Homeport'},
['Ship identification'] = {33, 'Identification'},
['Ship motto'] = {34, 'Motto'},
['Ship nickname'] = {35, 'Nickname(s)'},
['Ship honours'] = {36, 'Honours and<br />awards'}, -- make these two the same index?
['Ship honors'] = {37, 'Honors and<br />awards'},
['Ship captured'] = {38, 'Captured'},
['Ship fate'] = {39, 'Fate'},
['Ship status'] = {40, 'Status'},
['Ship notes'] = {41, 'Notes'},
['Ship badge'] = {42, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing <br /> craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors and <br /> processing systems'},
['Ship EW'] = {31, 'Electronic warfare <br /> & decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships completed'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
}
1vqb4uqihtbyfmlxc4aeajwy4l8ziww
790244
790243
2021-07-02T23:43:11Z
en>Trappist the monk
0
790244
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship name'] = {2, 'Name'},
['Ship namesake'] = {3, 'Namesake'},
['Ship owner'] = {4, 'Owner'},
['Ship operator'] = {5, 'Operator'},
['Ship registry'] = {6, 'Port of registry'},
['Ship route'] = {7, 'Route'},
['Ship ordered'] = {8, 'Ordered'},
['Ship awarded'] = {9, 'Awarded'},
['Ship builder'] = {10, 'Builder'},
['Ship original cost'] = {11, 'Cost'},
['Ship yard number'] = {12, 'Yard number'},
['Ship way number'] = {13, 'Way number'},
['Ship laid down'] = {14, 'Laid down'},
['Ship launched'] = {15, 'Launched'},
['Ship sponsor'] = {16, 'Sponsored by'},
['Ship christened'] = {17, 'Christened'},
['Ship completed'] = {18, 'Completed'},
['Ship acquired'] = {19, 'Acquired'},
['Ship commissioned'] = {20, 'Commissioned'},
['Ship recommissioned'] = {21, 'Recommissioned'},
['Ship decommissioned'] = {22, 'Decommissioned'},
['Ship maiden voyage'] = {23, 'Maiden voyage'},
['Ship in service'] = {24, 'In service'},
['Ship out of service'] = {25, 'Out of service'},
['Ship renamed'] = {26, 'Renamed'},
['Ship reclassified'] = {27, 'Reclassified'},
['Ship refit'] = {28, 'Refit'},
['Ship struck'] = {29, 'Stricken'},
['Ship stricken'] = {30, 'Stricken'},
['Ship reinstated'] = {31, 'Reinstated'},
['Ship homeport'] = {32, 'Homeport'},
['Ship identification'] = {33, 'Identification'},
['Ship motto'] = {34, 'Motto'},
['Ship nickname'] = {35, 'Nickname(s)'},
['Ship honours'] = {36, 'Honours and<br />awards'}, -- make these two the same index?
['Ship honors'] = {37, 'Honors and<br />awards'},
['Ship captured'] = {38, 'Captured'},
['Ship fate'] = {39, 'Fate'},
['Ship status'] = {40, 'Status'},
['Ship notes'] = {41, 'Notes'},
['Ship badge'] = {42, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing <br /> craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors and <br /> processing systems'},
['Ship EW'] = {31, 'Electronic warfare <br /> & decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships completed'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< C I T E P L I M S O L L >----------------------------------------------------
]]
local subtitles_t = {
['C'] = 'Chalutiers &c.', -- French headings used as subtitles; these appear on even page numbers
['F'] = 'Liste des Navires Pourvus de Machines Frigorifiques',
['NV'] = 'Navires à Voiles',
['NVM'] = 'Navires à Vapeur et à Moteurs',
['R'] = 'List of Vessels Fitted with Refrigerating Appliances', -- English headings used as subtitles; these appear on odd page numbers
['SM'] = 'Steamers & Motorships',
['SV'] = 'Sailing Vessels',
['T'] = 'Trawlers &c.',
}
local subtitles_xlate_t = {
['odd'] = { -- |filename= <page_num> is odd (en) so use French subtitle
['C'] = 'T', -- map fr keyword to en keyword
['F'] = 'R',
['NV'] = 'SV',
['NVM'] = 'SM',
},
['even'] = { -- |filename= <page_num> is even (fr) so use English subtitle
['R'] = 'F', -- map en keyword to fr keyword
['SM'] = 'NVM',
['SV'] = 'NV',
['T'] = 'C',
}
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
subtitles_t = subtitles_t,
subtitles_xlate_t = subtitles_xlate_t,
}
k10seemfcmvfej5d56dyacccjd6pd8r
790245
790244
2022-05-18T17:08:42Z
en>Trappist the monk
0
790245
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship name'] = {1, 'Name'},
['Ship namesake'] = {2, 'Namesake'},
['Ship owner'] = {3, 'Owner'},
['Ship operator'] = {4, 'Operator'},
['Ship registry'] = {5, 'Port of registry'},
['Ship route'] = {6, 'Route'},
['Ship ordered'] = {7, 'Ordered'},
['Ship awarded'] = {8, 'Awarded'},
['Ship builder'] = {9, 'Builder'},
['Ship original cost'] = {10, 'Cost'},
['Ship yard number'] = {11, 'Yard number'},
['Ship way number'] = {12, 'Way number'},
['Ship laid down'] = {13, 'Laid down'},
['Ship launched'] = {14, 'Launched'},
['Ship sponsor'] = {15, 'Sponsored by'},
['Ship christened'] = {16, 'Christened'},
['Ship completed'] = {17, 'Completed'},
['Ship acquired'] = {18, 'Acquired'},
['Ship commissioned'] = {19, 'Commissioned'},
['Ship recommissioned'] = {20, 'Recommissioned'},
['Ship decommissioned'] = {21, 'Decommissioned'},
['Ship maiden voyage'] = {22, 'Maiden voyage'},
['Ship in service'] = {23, 'In service'},
['Ship out of service'] = {24, 'Out of service'},
['Ship renamed'] = {25, 'Renamed'},
['Ship reclassified'] = {26, 'Reclassified'},
['Ship refit'] = {27, 'Refit'},
['Ship struck'] = {28, 'Stricken'},
['Ship stricken'] = {29, 'Stricken'},
['Ship reinstated'] = {30, 'Reinstated'},
['Ship homeport'] = {31, 'Homeport'},
['Ship identification'] = {32, 'Identification'},
['Ship motto'] = {33, 'Motto'},
['Ship nickname'] = {34, 'Nickname(s)'},
['Ship honours'] = {35, 'Honours and<br />awards'}, -- make these two the same index?
['Ship honors'] = {36, 'Honors and<br />awards'},
['Ship captured'] = {37, 'Captured'},
['Ship fate'] = {38, 'Fate'},
['Ship status'] = {39, 'Status'},
['Ship notes'] = {40, 'Notes'},
['Ship badge'] = {41, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing <br /> craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors and <br /> processing systems'},
['Ship EW'] = {31, 'Electronic warfare <br /> & decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships completed'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< C I T E P L I M S O L L >----------------------------------------------------
]]
local subtitles_t = {
['C'] = 'Chalutiers &c.', -- French headings used as subtitles; these appear on even page numbers
['F'] = 'Liste des Navires Pourvus de Machines Frigorifiques',
['NV'] = 'Navires à Voiles',
['NVM'] = 'Navires à Vapeur et à Moteurs',
['R'] = 'List of Vessels Fitted with Refrigerating Appliances', -- English headings used as subtitles; these appear on odd page numbers
['SM'] = 'Steamers & Motorships',
['SV'] = 'Sailing Vessels',
['T'] = 'Trawlers &c.',
}
local subtitles_xlate_t = {
['odd'] = { -- |filename= <page_num> is odd (en) so use French subtitle
['C'] = 'T', -- map fr keyword to en keyword
['F'] = 'R',
['NV'] = 'SV',
['NVM'] = 'SM',
},
['even'] = { -- |filename= <page_num> is even (fr) so use English subtitle
['R'] = 'F', -- map en keyword to fr keyword
['SM'] = 'NVM',
['SV'] = 'NV',
['T'] = 'C',
}
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
subtitles_t = subtitles_t,
subtitles_xlate_t = subtitles_xlate_t,
}
l15axa197l9dnm1rfiztn9jefhptmip
790246
790245
2024-07-20T23:55:57Z
en>RP88
0
prevent dangling 'by' in {{Infobox ship career}}; see 'Class after' for similar use...
790246
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship name'] = {1, 'Name'},
['Ship namesake'] = {2, 'Namesake'},
['Ship owner'] = {3, 'Owner'},
['Ship operator'] = {4, 'Operator'},
['Ship registry'] = {5, 'Port of registry'},
['Ship route'] = {6, 'Route'},
['Ship ordered'] = {7, 'Ordered'},
['Ship awarded'] = {8, 'Awarded'},
['Ship builder'] = {9, 'Builder'},
['Ship original cost'] = {10, 'Cost'},
['Ship yard number'] = {11, 'Yard number'},
['Ship way number'] = {12, 'Way number'},
['Ship laid down'] = {13, 'Laid down'},
['Ship launched'] = {14, 'Launched'},
['Ship sponsor'] = {15, 'Sponsored by'},
['Ship christened'] = {16, 'Christened'},
['Ship completed'] = {17, 'Completed'},
['Ship acquired'] = {18, 'Acquired'},
['Ship commissioned'] = {19, 'Commissioned'},
['Ship recommissioned'] = {20, 'Recommissioned'},
['Ship decommissioned'] = {21, 'Decommissioned'},
['Ship maiden voyage'] = {22, 'Maiden voyage'},
['Ship in service'] = {23, 'In service'},
['Ship out of service'] = {24, 'Out of service'},
['Ship renamed'] = {25, 'Renamed'},
['Ship reclassified'] = {26, 'Reclassified'},
['Ship refit'] = {27, 'Refit'},
['Ship struck'] = {28, 'Stricken'},
['Ship stricken'] = {29, 'Stricken'},
['Ship reinstated'] = {30, 'Reinstated'},
['Ship homeport'] = {31, 'Homeport'},
['Ship identification'] = {32, 'Identification'},
['Ship motto'] = {33, 'Motto'},
['Ship nickname'] = {34, 'Nickname(s)'},
['Ship honours'] = {35, 'Honours and<br />awards'}, -- make these two the same index?
['Ship honors'] = {36, 'Honors and<br />awards'},
['Ship captured'] = {37, 'Captured'},
['Ship fate'] = {38, 'Fate'},
['Ship status'] = {39, 'Status'},
['Ship notes'] = {40, 'Notes'},
['Ship badge'] = {41, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class and type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing <br /> craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors and <br /> processing systems'},
['Ship EW'] = {31, 'Electronic warfare <br /> & decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships completed'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< C I T E P L I M S O L L >----------------------------------------------------
]]
local subtitles_t = {
['C'] = 'Chalutiers &c.', -- French headings used as subtitles; these appear on even page numbers
['F'] = 'Liste des Navires Pourvus de Machines Frigorifiques',
['NV'] = 'Navires à Voiles',
['NVM'] = 'Navires à Vapeur et à Moteurs',
['R'] = 'List of Vessels Fitted with Refrigerating Appliances', -- English headings used as subtitles; these appear on odd page numbers
['SM'] = 'Steamers & Motorships',
['SV'] = 'Sailing Vessels',
['T'] = 'Trawlers &c.',
}
local subtitles_xlate_t = {
['odd'] = { -- |filename= <page_num> is odd (en) so use French subtitle
['C'] = 'T', -- map fr keyword to en keyword
['F'] = 'R',
['NV'] = 'SV',
['NVM'] = 'SM',
},
['even'] = { -- |filename= <page_num> is even (fr) so use English subtitle
['R'] = 'F', -- map en keyword to fr keyword
['SM'] = 'NVM',
['SV'] = 'NV',
['T'] = 'C',
}
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
subtitles_t = subtitles_t,
subtitles_xlate_t = subtitles_xlate_t,
}
06x9ct5fjo6w1vtyyuuv6s8kblgxdlo
790247
790246
2025-06-15T18:13:00Z
en>Trappist the monk
0
per [[Template_talk:Infobox_ship_begin#Ampersand_standardization|talk]];
790247
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship name'] = {1, 'Name'},
['Ship namesake'] = {2, 'Namesake'},
['Ship owner'] = {3, 'Owner'},
['Ship operator'] = {4, 'Operator'},
['Ship registry'] = {5, 'Port of registry'},
['Ship route'] = {6, 'Route'},
['Ship ordered'] = {7, 'Ordered'},
['Ship awarded'] = {8, 'Awarded'},
['Ship builder'] = {9, 'Builder'},
['Ship original cost'] = {10, 'Cost'},
['Ship yard number'] = {11, 'Yard number'},
['Ship way number'] = {12, 'Way number'},
['Ship laid down'] = {13, 'Laid down'},
['Ship launched'] = {14, 'Launched'},
['Ship sponsor'] = {15, 'Sponsored by'},
['Ship christened'] = {16, 'Christened'},
['Ship completed'] = {17, 'Completed'},
['Ship acquired'] = {18, 'Acquired'},
['Ship commissioned'] = {19, 'Commissioned'},
['Ship recommissioned'] = {20, 'Recommissioned'},
['Ship decommissioned'] = {21, 'Decommissioned'},
['Ship maiden voyage'] = {22, 'Maiden voyage'},
['Ship in service'] = {23, 'In service'},
['Ship out of service'] = {24, 'Out of service'},
['Ship renamed'] = {25, 'Renamed'},
['Ship reclassified'] = {26, 'Reclassified'},
['Ship refit'] = {27, 'Refit'},
['Ship struck'] = {28, 'Stricken'},
['Ship stricken'] = {29, 'Stricken'},
['Ship reinstated'] = {30, 'Reinstated'},
['Ship homeport'] = {31, 'Homeport'},
['Ship identification'] = {32, 'Identification'},
['Ship motto'] = {33, 'Motto'},
['Ship nickname'] = {34, 'Nickname(s)'},
['Ship honours'] = {35, 'Honours &<br />awards'}, -- make these two the same index?
['Ship honors'] = {36, 'Honors &<br />awards'},
['Ship captured'] = {37, 'Captured'},
['Ship fate'] = {38, 'Fate'},
['Ship status'] = {39, 'Status'},
['Ship notes'] = {40, 'Notes'},
['Ship badge'] = {41, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class & type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing<br />craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors &<br />processing systems'},
['Ship EW'] = {31, 'Electronic warfare<br />& decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships completed'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< C I T E P L I M S O L L >----------------------------------------------------
]]
local subtitles_t = {
['C'] = 'Chalutiers &c.', -- French headings used as subtitles; these appear on even page numbers
['F'] = 'Liste des Navires Pourvus de Machines Frigorifiques',
['NV'] = 'Navires à Voiles',
['NVM'] = 'Navires à Vapeur et à Moteurs',
['R'] = 'List of Vessels Fitted with Refrigerating Appliances', -- English headings used as subtitles; these appear on odd page numbers
['SM'] = 'Steamers & Motorships',
['SV'] = 'Sailing Vessels',
['T'] = 'Trawlers &c.',
}
local subtitles_xlate_t = {
['odd'] = { -- |filename= <page_num> is odd (en) so use French subtitle
['C'] = 'T', -- map fr keyword to en keyword
['F'] = 'R',
['NV'] = 'SV',
['NVM'] = 'SM',
},
['even'] = { -- |filename= <page_num> is even (fr) so use English subtitle
['R'] = 'F', -- map en keyword to fr keyword
['SM'] = 'NVM',
['SV'] = 'NV',
['T'] = 'C',
}
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
subtitles_t = subtitles_t,
subtitles_xlate_t = subtitles_xlate_t,
}
n15x4f5liy1oncrekn1qfp63ha3x9h1
790248
790247
2026-01-04T01:42:26Z
en>Trappist the monk
0
+SV;
790248
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['SV'] = true, -- Sailing vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship name'] = {1, 'Name'},
['Ship namesake'] = {2, 'Namesake'},
['Ship owner'] = {3, 'Owner'},
['Ship operator'] = {4, 'Operator'},
['Ship registry'] = {5, 'Port of registry'},
['Ship route'] = {6, 'Route'},
['Ship ordered'] = {7, 'Ordered'},
['Ship awarded'] = {8, 'Awarded'},
['Ship builder'] = {9, 'Builder'},
['Ship original cost'] = {10, 'Cost'},
['Ship yard number'] = {11, 'Yard number'},
['Ship way number'] = {12, 'Way number'},
['Ship laid down'] = {13, 'Laid down'},
['Ship launched'] = {14, 'Launched'},
['Ship sponsor'] = {15, 'Sponsored by'},
['Ship christened'] = {16, 'Christened'},
['Ship completed'] = {17, 'Completed'},
['Ship acquired'] = {18, 'Acquired'},
['Ship commissioned'] = {19, 'Commissioned'},
['Ship recommissioned'] = {20, 'Recommissioned'},
['Ship decommissioned'] = {21, 'Decommissioned'},
['Ship maiden voyage'] = {22, 'Maiden voyage'},
['Ship in service'] = {23, 'In service'},
['Ship out of service'] = {24, 'Out of service'},
['Ship renamed'] = {25, 'Renamed'},
['Ship reclassified'] = {26, 'Reclassified'},
['Ship refit'] = {27, 'Refit'},
['Ship struck'] = {28, 'Stricken'},
['Ship stricken'] = {29, 'Stricken'},
['Ship reinstated'] = {30, 'Reinstated'},
['Ship homeport'] = {31, 'Homeport'},
['Ship identification'] = {32, 'Identification'},
['Ship motto'] = {33, 'Motto'},
['Ship nickname'] = {34, 'Nickname(s)'},
['Ship honours'] = {35, 'Honours &<br />awards'}, -- make these two the same index?
['Ship honors'] = {36, 'Honors &<br />awards'},
['Ship captured'] = {37, 'Captured'},
['Ship fate'] = {38, 'Fate'},
['Ship status'] = {39, 'Status'},
['Ship notes'] = {40, 'Notes'},
['Ship badge'] = {41, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class & type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing<br />craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors &<br />processing systems'},
['Ship EW'] = {31, 'Electronic warfare<br />& decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships completed'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< C I T E P L I M S O L L >----------------------------------------------------
]]
local subtitles_t = {
['C'] = 'Chalutiers &c.', -- French headings used as subtitles; these appear on even page numbers
['F'] = 'Liste des Navires Pourvus de Machines Frigorifiques',
['NV'] = 'Navires à Voiles',
['NVM'] = 'Navires à Vapeur et à Moteurs',
['R'] = 'List of Vessels Fitted with Refrigerating Appliances', -- English headings used as subtitles; these appear on odd page numbers
['SM'] = 'Steamers & Motorships',
['SV'] = 'Sailing Vessels',
['T'] = 'Trawlers &c.',
}
local subtitles_xlate_t = {
['odd'] = { -- |filename= <page_num> is odd (en) so use French subtitle
['C'] = 'T', -- map fr keyword to en keyword
['F'] = 'R',
['NV'] = 'SV',
['NVM'] = 'SM',
},
['even'] = { -- |filename= <page_num> is even (fr) so use English subtitle
['R'] = 'F', -- map en keyword to fr keyword
['SM'] = 'NVM',
['SV'] = 'NV',
['T'] = 'C',
}
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
subtitles_t = subtitles_t,
subtitles_xlate_t = subtitles_xlate_t,
}
0mow9ihw3vmpwbqbn8yg67zuoo4ts94
790249
790248
2026-04-03T08:36:04Z
SM7
3953
11 revisions imported from [[:en:Module:WPSHIPS_utilities/data]]
790248
Scribunto
text/plain
--[[-------------------------< S H I P P R E F I X L I S T >-----------------------------------------------
This is a list of currently supported ship prefixes.
To add to this list the form is:
['prefix'] = true,
the trailing comma is important.
]]
local ship_prefix_t =
{
['ARA'] = true, -- Armada de la República Argentina
['ARC'] = true, -- Armada Nacional de la República de Colombia
['ARM'] = true, -- Armada de la República Mexicana
['ARV'] = true, -- Armada Republica de Venezuela
['BAE'] = true, -- Buque de la Armada de Ecuador
['BAP'] = true, -- Peruvian Navy Ship
['BNS'] = true, -- Bangladesh Navy Ship
['BRP'] = true, -- Barko ng Republika ng Pilipinas
['CCGS'] = true, -- Canadian Coast Guard Ship
['CFAV'] = true, -- Canadian Forces Auxiliary Vessel
['CS'] = true, -- Cable Ship
['CSS'] = true, -- Confederate States Ship
['FGS'] = true, -- Federal German Ship
['GTS'] = true, -- Gas Turbine Ship
['HDMS'] = true, -- His/Her Danish Majesty's Ship
['HM'] = true, -- His/Her Majesty's, then used with the type of ship in military use (UK)
['HMAS'] = true, -- Her/His Majesty's Australian Ship
['HMBS'] = true, -- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
['HMC'] = true, -- Her/His Majesty's Cutter
['HMCS'] = true, -- Her/His Majesty's Canadian Ship (also Colonial)
['HMHS'] = true, -- His/Her Majesty's Hospital Ship
['HMIS'] = true, -- Her/His Majesty's Indian Ship (pre republic)
['HMNZS'] = true, -- Her/His Majesty's New Zealand Ship
['HMPNGS'] = true, -- His/Her Majesty's Papua New Guinea Ship
['HMQS'] = true, -- Her/His Majesty's Queensland Ship
['HMRC'] = true, -- His/Her Majesty's Revenue Cutter
['HMS'] = true, -- Her/His Majesty's Ship
['HMSAS'] = true, -- Her/His Majesty's South African Ship
['HMT'] = true, -- Her/His Majesty's Trawler
['HMVS'] = true, -- Her/His Majesty's Victorian Ship
['HMY'] = true, -- His/Her Majesty's Yacht
['HNLMS'] = true, -- His/Her Netherlands Majesty’s Ship
['HNoMS'] = true, -- His/Her Norwegian Majesty's Ship
['HSC'] = true, -- High-Speed Craft
['HSwMS'] = true, -- His/Her Swedish Majesty's Ship
['HTMS'] = true, -- His Thai Majesty's Ship
['ICGS'] = true, -- Indian Coast Guard Ship
['IIS'] = true, -- Imperial Iranian Ship
['INS'] = true, -- Indian Naval Ship, Israeli Naval Ship
['IRIS'] = true, -- Islamic Republic of Iran Ship
['JDS'] = true, -- Japanese Defence Ship
['JS'] = true, -- Japanese Ship (post 2008)
['KA'] = true, -- Kapal Auksiliari – Auxiliary Ship (Malaysia)
['KD'] = true, -- Kapal Di-Raja — His Majesty's Ship (Malaysia)
['KM'] = true, -- Kapal Motor (Motor Ship) (Indonesia)
['KDB'] = true, -- Kapal Diraja Brunei (Royal Brunei Ship) (in Malay)
['KDM'] = true, -- Kongelige Danske Marine
['KLD'] =true, -- Kapal Layar Diraja – His Majesty's Sailing Ship (Malaysia)
['KRI'] = true, -- Kapal Republik Indonesia
['LÉ'] = true, -- Long Éireannach – Irish ship
['MF'] = true, -- Motor Ferry
['LKL'] = true, -- Lietuvos Karinis Laivas – Lithuania
['MS'] = true, -- Motor Ship
['MT'] = true, -- Motor Tanker
['MV'] = true, -- Motor Vessel
['NLV'] = true, -- Northern Lighthouse Vessel
['NMS'] = true, -- Nava Majestăţii Sale (His/Her Majesty's Ship) - used before 1945 by the Royal Romanian Navy
['NoCGV'] = true, -- Norwegian Coast Guard Vessel
['NOAAS'] = true, -- National Oceanic and Atmospheric Administration Ship
['NRP'] = true, -- Navio da República Portuguesa
['ORP'] = true, -- Okręt Rzeczypospolitej Polskiej
['PNS'] = true, -- Pakistani Naval Ship
['PS'] = true, -- Paddle Steamer
['RFA'] = true, -- Royal Fleet Auxiliary
['RMAS'] = true, -- Royal Maritime Auxiliary Service
['RMS'] = true, -- Royal Mail Ship
['RNLB'] = true, -- Royal National Lifeboat
['ROCS'] = true, -- Republic of China Ship
['ROKS'] = true, -- Republic of Korea Ship
['RPS'] = true, -- Republic of the Philippines Ship
['RRS'] = true, -- Royal Research Ship
['RS'] = true, -- Rocket Ship
['RSS'] = true, -- Republic of Singapore Ship
['RV'] = true, -- Research Vessel
['SAS'] = true, -- South African Ship
['SLNS'] = true, -- Sri Lanka Naval Ship
['SM'] = true, -- Seiner Majestät Unterseeboot
['SMS'] = true, -- Seiner Majestät Schiff
['SS'] = true, -- Screw Steamer or Steamship
['STV'] = true, -- Sail training vessel
['SV'] = true, -- Sailing vessel
['TCG'] = true, -- Türkiye Cumhuriyeti Gemisi
['TS'] = true, -- Training ship
['TV'] = true, -- Training vessel
['UAM'] = true, -- Unidade Auxiliar da Marinha - Navy Auxiliary Unit (Portuguese Navy non-military ships)
['USAFS'] = true, -- United States Air Force ship
['USAHS'] = true, -- United States Army Hospital Ship
['USAS'] = true, -- United States Army Ship
['USAT'] = true, -- United States Army Transport
['USAV'] = true, -- United States Army Vessel
['USC&GS'] = true, -- United States Coast and Geodetic Survey
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GS'] = true, -- United States Coast and Geodetic Survey (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USC&GSS'] = true, -- United States Coast and Geodetic Survey Ship (crude work-around)
['USCGC'] = true, -- United States Coast Guard Cutter
['USLHT'] = true, -- United State Light House Tender
['USNS'] = true, -- United States Naval Ship
['USRC'] = true, -- United States Revenue Cutter
['USS'] = true, -- United States Ship
}
--[[--------------------------< N A T I O N A L I T Y >--------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
This is a list of nationalities.
To add to this list the form is:
['Nationality'] = true,
the trailing comma is important. Use the adjective form for nationality, always capitalize. Please insert nationalities in alphabetical order.
]]
local nationality_t =
{
['Albanian'] = true,
['American'] = true,
['Australian'] = true,
['Belgian'] = true,
['Brazilian'] = true,
['Bulgarian'] = true,
['Chilean'] = true,
['Chinese'] = true,
['Croatian'] = true,
['Danish'] = true,
['Dominican'] = true,
['Dutch'] = true,
['East Timorese'] = true,
['Egyptian'] = true,
['English'] = true,
['Finnish'] = true,
['French'] = true,
['German'] = true,
['Greek'] = true,
['Grenadan'] = true,
['Haitian'] = true,
['Iranian'] = true,
['Irish'] = true,
['Italian'] = true,
['Japanese'] = true,
['Latvian'] = true,
['Libyan'] = true,
['Lithuanian'] = true,
['Maltese'] = true,
['Mexican'] = true,
['Nigerian'] = true,
['Ottoman'] = true,
['Peruvian'] = true,
['Portuguese'] = true,
['Romanian'] = true,
['Russian'] = true,
['Scottish'] = true,
['Slovenian'] = true,
['Soviet'] = true,
['Spanish'] = true,
['Swedish'] = true,
['Texan'] = true,
['Ukrainian'] = true,
['United States'] = true,
['Vietnamese'] = true,
['Yugoslav'] = true,
}
--[[--------------------------< S H I P T Y P E >------------------------------------------------------------
Article titles for ships in navies that do not use a standardized prefix follow the title format:
<nationality> <ship type> <name> <(disambiguator)>
Article titles for ships may or may not be naval ships may follow the title format:
<name> <(disambiguator)>
where <(disambiguator)> may be some form of ship type, hull designator or pennant number, or year. This tool will
format ship names that contain a recognized ship type in <(disambiguator)>.
This list is used to <find ship> when the article title begins with a nationality. This is important because the tool
needs to know where the <ship type> ends and <name> begins so that it can properly place the italic markup. The search
will find an exact match (including case) for ship types that are 1 to 4 words long.
This list is also used to find ship type in <(disambiguator)>. The search is whole word; use the simplest form.
For example, because 'icebreaker' is defined, that ship type is sufficient to cause the tool to properly format:
Astrolabe (icebreaker)
Krassin (1917 icebreaker)
Taymyr (nuclear icebreaker)
Searches for ship type in <(disambiguator)> are whole word. When looking for 'ship', the tool will find
Auguste (ship)
Queen of Nations (clipper ship)
but will not find:
Sibir (steamship icebreaker) – the search for 'icebreaker' will
This is a list of ship types. When adding new ship types, do not be too specific: 'aircraft carrier' but not 'light aircraft carrier'
To add to this list the form is:
['ship type'] = true,
the trailing comma is important. At the time of this writing, a ship type may be one to four words, almost always lowercase.
Please insert ship types in alphabetical order.
]]
local ship_type_t =
{
['armoured cruiser'] = true,
['aircraft carrier'] = true,
['amphibious assault ship'] = true,
['Army ship'] = true, -- should be capitalized
['auxiliary cruiser'] = true,
['auxiliary raider'] = true,
['auxiliary'] = true,
['aviso'] = true,
['barge'] = true,
['barque'] = true,
['barquentine'] = true,
['battlecruiser'] = true,
['battleship'] = true,
['boat'] = true,
['brig sloop'] = true,
['brig-sloop'] = true,
['brig'] = true,
['brigantine'] = true,
['carrack'] = true,
['clipper'] = true,
['coast defense ship'] = true,
['coastal defence ship'] = true,
['coastal defense ship'] = true,
['communications ship'] = true,
['corvette'] = true,
['cruiser'] = true,
['cutter'] = true,
['deep submergence rescue vehicle'] = true,
['destroyer leader'] = true,
['destroyer'] = true,
['dragger'] = true,
['dredge'] = true,
['East Indiaman'] = true, -- should be capitalized
['escort ship'] = true,
['escort'] = true,
['ferry'] = true,
['ferryboat'] = true,
['fireboat'] = true,
['fleet oiler'] = true,
['floating battery'] = true,
['floating crane'] = true,
['fluyt'] = true,
['food supply ship'] = true,
['freighter'] = true,
['frigate'] = true,
['galleon'] = true,
['galley'] = true,
['gunboat'] = true,
['helicopter carrier'] = true,
['hospital ship'] = true,
['hovercraft'] = true,
['hydrofoil'] = true,
['icebreaker'] = true,
['Indiaman'] = true, -- should be capitalized
['ironclad'] = true,
['ketch'] = true,
['landing ship'] = true,
['landing ship medium'] = true,
['lifeboat'] = true,
['lightship'] = true,
['log canoe'] = true,
['lugger'] = true,
['merchant cruiser'] = true,
['minehunter'] = true,
['minelayer'] = true,
['minelaying cruiser'] = true,
['minesweeper'] = true,
['missile boat'] = true,
['monitor'] = true,
['munition ship'] = true,
['naval ship'] = true,
['night fighter direction vessel'] = true,
['ocean liner'] = true,
['oiler'] = true,
['paddle steamer'] = true,
['patrol boat'] = true,
['patrol gunboat'] = true,
['patrol vessel'] = true,
['pinnace'] = true,
['pollution control vessel'] = true,
['privateer'] = true,
['protected cruiser'] = true,
['pusher'] = true,
['rescue ship'] = true,
['riverboat'] = true,
['ROV'] = true,
['sailboat'] = true,
['schooner'] = true,
['seaplane carrier'] = true,
['seaplane tender'] = true,
['ship of the line'] = true,
['ship'] = true,
['shipwreck'] = true,
['shore establishment'] = true, -- use stone frigate instead?
['showboat'] = true,
['sidewheeler'] = true,
['skipjack'] = true,
['sloop-of-war'] = true,
['sloop'] = true,
['smack'] = true,
['snagboat'] = true,
['speedboat'] = true,
['steam frigate'] = true,
['steam warship'] = true,
['steamboat'] = true,
['steamer'] = true,
['steamship'] = true,
['sternwheeler'] = true,
['stores lighter'] = true,
['submarine chaser'] = true,
['submarine rescue vehicle'] = true,
['submarine tender'] = true,
['submarine'] = true,
['submersible'] = true,
['supertanker'] = true,
['support ship'] = true,
['survey ship'] = true,
['tanker'] = true,
['target ship'] = true,
['tender'] = true,
['torpedo boat'] = true,
['torpedo gunboat'] = true,
['towboat'] = true,
['training cruiser'] = true,
['training ship'] = true,
['transport'] = true,
['trawler'] = true,
['trireme'] = true,
['tug'] = true,
['tugboat'] = true,
['vessel'] = true,
['warship'] = true,
['weather ship'] = true,
['whaler'] = true,
['whaleship'] = true,
['wherry'] = true,
['yacht'] = true,
['yawl'] = true,
}
--[[--------------------------< I N F O B O X L I N E I T E M P A R A M E T E R S >----------------------
]]
local infobox_career_params_t = { -- table of parameters that are rendered in the same way
['Ship name'] = {1, 'Name'},
['Ship namesake'] = {2, 'Namesake'},
['Ship owner'] = {3, 'Owner'},
['Ship operator'] = {4, 'Operator'},
['Ship registry'] = {5, 'Port of registry'},
['Ship route'] = {6, 'Route'},
['Ship ordered'] = {7, 'Ordered'},
['Ship awarded'] = {8, 'Awarded'},
['Ship builder'] = {9, 'Builder'},
['Ship original cost'] = {10, 'Cost'},
['Ship yard number'] = {11, 'Yard number'},
['Ship way number'] = {12, 'Way number'},
['Ship laid down'] = {13, 'Laid down'},
['Ship launched'] = {14, 'Launched'},
['Ship sponsor'] = {15, 'Sponsored by'},
['Ship christened'] = {16, 'Christened'},
['Ship completed'] = {17, 'Completed'},
['Ship acquired'] = {18, 'Acquired'},
['Ship commissioned'] = {19, 'Commissioned'},
['Ship recommissioned'] = {20, 'Recommissioned'},
['Ship decommissioned'] = {21, 'Decommissioned'},
['Ship maiden voyage'] = {22, 'Maiden voyage'},
['Ship in service'] = {23, 'In service'},
['Ship out of service'] = {24, 'Out of service'},
['Ship renamed'] = {25, 'Renamed'},
['Ship reclassified'] = {26, 'Reclassified'},
['Ship refit'] = {27, 'Refit'},
['Ship struck'] = {28, 'Stricken'},
['Ship stricken'] = {29, 'Stricken'},
['Ship reinstated'] = {30, 'Reinstated'},
['Ship homeport'] = {31, 'Homeport'},
['Ship identification'] = {32, 'Identification'},
['Ship motto'] = {33, 'Motto'},
['Ship nickname'] = {34, 'Nickname(s)'},
['Ship honours'] = {35, 'Honours &<br />awards'}, -- make these two the same index?
['Ship honors'] = {36, 'Honors &<br />awards'},
['Ship captured'] = {37, 'Captured'},
['Ship fate'] = {38, 'Fate'},
['Ship status'] = {39, 'Status'},
['Ship notes'] = {40, 'Notes'},
['Ship badge'] = {41, 'Badge'},
}
local infobox_characteristics_params_t = { -- table of parameters that are rendered in the same way
['Ship class'] = {1, 'Class & type'},
['Ship type'] = {2, 'Type'},
['Ship tonnage'] = {3, 'Tonnage'},
['Ship displacement'] = {4, 'Displacement'},
['Ship tons burthen'] = {5, 'Tons burthen'},
['Ship length'] = {6, 'Length'},
['Ship beam'] = {7, 'Beam'},
['Ship height'] = {8, 'Height'},
['Ship draught'] = {9, 'Draught'}, -- make these two the same index?
['Ship draft'] = {10, 'Draft'},
['Ship depth'] = {11, 'Depth'},
['Ship hold depth'] = {12, 'Depth of hold'},
['Ship decks'] = {13, 'Decks'},
['Ship deck clearance'] = {14, 'Deck clearance'},
['Ship ramps'] = {15, 'Ramps'},
['Ship ice class'] = {16, 'Ice class'},
['Ship power'] = {17, 'Installed power'},
['Ship propulsion'] = {18, 'Propulsion'},
['Ship sail plan'] = {19, 'Sail plan'},
['Ship speed'] = {20, 'Speed'},
['Ship range'] = {21, 'Range'},
['Ship endurance'] = {22, 'Endurance'},
['Ship test depth'] = {23, 'Test depth'},
['Ship boats'] = {24, 'Boats & landing<br />craft carried'},
['Ship capacity'] = {25, 'Capacity'},
['Ship troops'] = {26, 'Troops'},
['Ship complement'] = {27, 'Complement'},
['Ship crew'] = {28, 'Crew'},
['Ship time to activate'] = {29, 'Time to activate'},
['Ship sensors'] = {30, 'Sensors &<br />processing systems'},
['Ship EW'] = {31, 'Electronic warfare<br />& decoys'},
['Ship armament'] = {32, 'Armament'},
['Ship armour'] = {33, 'Armour'}, -- make these two the same index?
['Ship armor'] = {34, 'Armor'},
['Ship aircraft'] = {35, 'Aircraft carried'},
['Ship aircraft facilities'] = {36, 'Aviation facilities'},
['Ship notes'] = {37, 'Notes'},
}
local infobox_class_overview_params_t = { -- table of parameters that are rendered in the same way
['Name'] = {1, 'Name'},
['Builders'] = {2, 'Builders'},
['Operators'] = {3, 'Operators'},
['Class before'] = {4, 'Preceded by'},
['Class after'] = {5, 'Succeeded by'},
['Subclasses'] = {6, 'Subclasses'},
['Cost'] = {7, 'Cost'},
['Built range'] = {8, 'Built'},
['In service range'] = {9, 'In service'},
['In commission range'] = {10, 'In commission'},
['Total ships planned'] = {11, 'Planned'},
['Total ships on order'] = {12, 'On order'},
['Total ships building'] = {13, 'Building'},
['Total ships completed'] = {14, 'Completed'},
['Total ships cancelled'] = {15, 'Cancelled'},
['Total ships active'] = {16, 'Active'},
['Total ships laid up'] = {17, 'Laid up'},
['Total ships lost'] = {18, 'Lost'},
['Total ships retired'] = {19, 'Retired'},
['Total ships scrapped'] = {20, 'Scrapped'},
['Total ships preserved'] = {21, 'Preserved'},
}
--[[--------------------------< C I T E P L I M S O L L >----------------------------------------------------
]]
local subtitles_t = {
['C'] = 'Chalutiers &c.', -- French headings used as subtitles; these appear on even page numbers
['F'] = 'Liste des Navires Pourvus de Machines Frigorifiques',
['NV'] = 'Navires à Voiles',
['NVM'] = 'Navires à Vapeur et à Moteurs',
['R'] = 'List of Vessels Fitted with Refrigerating Appliances', -- English headings used as subtitles; these appear on odd page numbers
['SM'] = 'Steamers & Motorships',
['SV'] = 'Sailing Vessels',
['T'] = 'Trawlers &c.',
}
local subtitles_xlate_t = {
['odd'] = { -- |filename= <page_num> is odd (en) so use French subtitle
['C'] = 'T', -- map fr keyword to en keyword
['F'] = 'R',
['NV'] = 'SV',
['NVM'] = 'SM',
},
['even'] = { -- |filename= <page_num> is even (fr) so use English subtitle
['R'] = 'F', -- map en keyword to fr keyword
['SM'] = 'NVM',
['SV'] = 'NV',
['T'] = 'C',
}
}
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
infobox_career_params_t = infobox_career_params_t,
infobox_characteristics_params_t = infobox_characteristics_params_t,
infobox_class_overview_params_t = infobox_class_overview_params_t,
nationality_t = nationality_t,
ship_prefix_t = ship_prefix_t,
ship_type_t = ship_type_t,
subtitles_t = subtitles_t,
subtitles_xlate_t = subtitles_xlate_t,
}
0mow9ihw3vmpwbqbn8yg67zuoo4ts94
स्पेसफ्लाइट
0
100498
790251
2026-04-03T08:46:46Z
SM7
3953
नया आधार लेख
790251
wikitext
text/x-wiki
'''स्पेसफ्लाइट''' भा '''स्पेसफ्लाईट''' ({{Langx|en|spaceflight}}) अंतरिक्ष विज्ञान के एगो एप्लीकेशन हवे, जेह में चीजन (आमतौर पर [[स्पेसक्राफ्ट]]) के [[अंतरिक्ष|बाहरी अंतरिक्ष]] में चाहे ओकरा भीतर उड़ावल जाला, चाहे ओहमें आदमी होखे या ना होखे। ज्यादातर स्पेसफ्लाइट बिना आदमी के होला, आ ई मुख्य रूप से सैटेलाइट जइसन स्पेसक्राफ्ट के जरिए कइल जाला, जवन धरती के चारों ओर कक्षा (ऑर्बिट) में घूमेला। एहमें धरती के बाहर जाए वाला स्पेस प्रोब सभ भी शामिल बाड़ें। एह तरह के उड़ान या त टेलीरोबोटिक (दूर से नियंत्रित) या खुद-ब-खुद चले वाला (ऑटोनॉमस) सिस्टम से चलावल जाला। सबसे पहिले स्पेसफ्लाइट 1950 के दशक में शुरू भइल, जब सोवियत संघ के स्पुतनिक उपग्रह उड़ावल गइल; बाद में अमेरिका के एक्स्प्लोरर आ वैनगार्ड मिशन लॉन्च भइलें जे एह कड़ी में आगे के हिस्सा बनलें। मनुष्य के ले जाये वाला स्पेसफ्लाइट कार्यक्रम में सोयुज, शेनझाऊ, पहिले के हो चुकल अपोलो लैंडिंग आ कई ठे स्पेस शटल प्रोग्राम शामिल बाड़ें। आजकाल्ह के स्पेसफ्लाइट [[इंटरनेशनल स्पेस स्टेशन]] (ISS) आ चीन के [[तियांगोंग स्पेस स्टेशन]] तक ले जाये-आवे खातिर भी कइल जा रहल बाड़ें।
hsoyq679hqoac7945mxemltxcv44qek
790252
790251
2026-04-03T08:47:12Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:अंतरिक्ष उड़ान]] जोड़ल गइल
790252
wikitext
text/x-wiki
'''स्पेसफ्लाइट''' भा '''स्पेसफ्लाईट''' ({{Langx|en|spaceflight}}) अंतरिक्ष विज्ञान के एगो एप्लीकेशन हवे, जेह में चीजन (आमतौर पर [[स्पेसक्राफ्ट]]) के [[अंतरिक्ष|बाहरी अंतरिक्ष]] में चाहे ओकरा भीतर उड़ावल जाला, चाहे ओहमें आदमी होखे या ना होखे। ज्यादातर स्पेसफ्लाइट बिना आदमी के होला, आ ई मुख्य रूप से सैटेलाइट जइसन स्पेसक्राफ्ट के जरिए कइल जाला, जवन धरती के चारों ओर कक्षा (ऑर्बिट) में घूमेला। एहमें धरती के बाहर जाए वाला स्पेस प्रोब सभ भी शामिल बाड़ें। एह तरह के उड़ान या त टेलीरोबोटिक (दूर से नियंत्रित) या खुद-ब-खुद चले वाला (ऑटोनॉमस) सिस्टम से चलावल जाला। सबसे पहिले स्पेसफ्लाइट 1950 के दशक में शुरू भइल, जब सोवियत संघ के स्पुतनिक उपग्रह उड़ावल गइल; बाद में अमेरिका के एक्स्प्लोरर आ वैनगार्ड मिशन लॉन्च भइलें जे एह कड़ी में आगे के हिस्सा बनलें। मनुष्य के ले जाये वाला स्पेसफ्लाइट कार्यक्रम में सोयुज, शेनझाऊ, पहिले के हो चुकल अपोलो लैंडिंग आ कई ठे स्पेस शटल प्रोग्राम शामिल बाड़ें। आजकाल्ह के स्पेसफ्लाइट [[इंटरनेशनल स्पेस स्टेशन]] (ISS) आ चीन के [[तियांगोंग स्पेस स्टेशन]] तक ले जाये-आवे खातिर भी कइल जा रहल बाड़ें।
[[श्रेणी:अंतरिक्ष उड़ान| ]]
noydqr1navgnxqz2e5ghckywkwhebpq
790253
790252
2026-04-03T08:48:00Z
SM7
3953
[[User:SM7/stubsorter|Stubsorter]] के मदद से {{Astronomy-stub}} जोड़ल गइल।
790253
wikitext
text/x-wiki
'''स्पेसफ्लाइट''' भा '''स्पेसफ्लाईट''' ({{Langx|en|spaceflight}}) अंतरिक्ष विज्ञान के एगो एप्लीकेशन हवे, जेह में चीजन (आमतौर पर [[स्पेसक्राफ्ट]]) के [[अंतरिक्ष|बाहरी अंतरिक्ष]] में चाहे ओकरा भीतर उड़ावल जाला, चाहे ओहमें आदमी होखे या ना होखे। ज्यादातर स्पेसफ्लाइट बिना आदमी के होला, आ ई मुख्य रूप से सैटेलाइट जइसन स्पेसक्राफ्ट के जरिए कइल जाला, जवन धरती के चारों ओर कक्षा (ऑर्बिट) में घूमेला। एहमें धरती के बाहर जाए वाला स्पेस प्रोब सभ भी शामिल बाड़ें। एह तरह के उड़ान या त टेलीरोबोटिक (दूर से नियंत्रित) या खुद-ब-खुद चले वाला (ऑटोनॉमस) सिस्टम से चलावल जाला। सबसे पहिले स्पेसफ्लाइट 1950 के दशक में शुरू भइल, जब सोवियत संघ के स्पुतनिक उपग्रह उड़ावल गइल; बाद में अमेरिका के एक्स्प्लोरर आ वैनगार्ड मिशन लॉन्च भइलें जे एह कड़ी में आगे के हिस्सा बनलें। मनुष्य के ले जाये वाला स्पेसफ्लाइट कार्यक्रम में सोयुज, शेनझाऊ, पहिले के हो चुकल अपोलो लैंडिंग आ कई ठे स्पेस शटल प्रोग्राम शामिल बाड़ें। आजकाल्ह के स्पेसफ्लाइट [[इंटरनेशनल स्पेस स्टेशन]] (ISS) आ चीन के [[तियांगोंग स्पेस स्टेशन]] तक ले जाये-आवे खातिर भी कइल जा रहल बाड़ें।
[[श्रेणी:अंतरिक्ष उड़ान| ]]
{{Astronomy-stub}}
16cjadbg4gqb3dxw4uluxoykqfugibp
790257
790253
2026-04-03T08:54:12Z
SM7
3953
सुधार कइल गइल
790257
wikitext
text/x-wiki
'''स्पेसफ्लाइट''' भा '''स्पेसफ्लाईट''' ({{Langx|en|spaceflight}}; अरथ: अंतरिक्ष उड़ान) [[अंतरिक्ष बिज्ञान|अंतरिक्ष विज्ञान]] के एगो एप्लीकेशन हवे, जेह में चीजन (आमतौर पर [[स्पेसक्राफ्ट]]) के [[अंतरिक्ष|बाहरी अंतरिक्ष]] में चाहे ओकरा भीतर उड़ावल जाला, चाहे ओहमें आदमी होखे या ना होखे। ज्यादातर स्पेसफ्लाइट बिना आदमी के होला, आ ई मुख्य रूप से [[सैटेलाइट]] जइसन स्पेसक्राफ्ट के जरिए कइल जाला, जवन धरती के चारों ओर कक्षा (ऑर्बिट) में घूमेला। एहमें धरती के बाहर जाए वाला [[स्पेस प्रोब]] सभ भी शामिल बाड़ें। एह तरह के उड़ान या त टेलीरोबोटिक (दूर से नियंत्रित) या खुद-ब-खुद चले वाला (ऑटोनॉमस) सिस्टम से चलावल जाला। सबसे पहिले स्पेसफ्लाइट 1950 के दशक में शुरू भइल, जब [[सोवियत संघ]] के [[स्पुतनिक]] उपग्रह उड़ावल गइल; बाद में अमेरिका के एक्स्प्लोरर आ वैनगार्ड मिशन लॉन्च भइलें जे एह कड़ी में आगे के हिस्सा बनलें। मनुष्य के ले जाये वाला स्पेसफ्लाइट कार्यक्रम में सोयुज, शेनझाऊ, पहिले के हो चुकल अपोलो लैंडिंग आ कई ठे स्पेस शटल प्रोग्राम शामिल बाड़ें। आजकाल्ह के स्पेसफ्लाइट [[इंटरनेशनल स्पेस स्टेशन]] (ISS) आ चीन के [[तियांगोंग स्पेस स्टेशन]] तक ले जाये-आवे खातिर भी कइल जा रहल बाड़ें।
[[श्रेणी:अंतरिक्ष उड़ान| ]]
{{Astronomy-stub}}
eg95q7o62nxdpecjzz3e31aumsi6t4r
790259
790257
2026-04-03T08:55:48Z
SM7
3953
फोटो जोड़ल गइल
790259
wikitext
text/x-wiki
[[File:Tracy Caldwell Dyson in Cupola ISS.jpg|thumb|upright=1.2|ट्रेसी क्लैड्वेल डायसन, इंटरनेशनल स्पेस स्टेशन के कपोला मॉड्यूल में।]]
'''स्पेसफ्लाइट''' भा '''स्पेसफ्लाईट''' ({{Langx|en|spaceflight}}; अरथ: अंतरिक्ष उड़ान) [[अंतरिक्ष बिज्ञान|अंतरिक्ष विज्ञान]] के एगो एप्लीकेशन हवे, जेह में चीजन (आमतौर पर [[स्पेसक्राफ्ट]]) के [[अंतरिक्ष|बाहरी अंतरिक्ष]] में चाहे ओकरा भीतर उड़ावल जाला, चाहे ओहमें आदमी होखे या ना होखे। ज्यादातर स्पेसफ्लाइट बिना आदमी के होला, आ ई मुख्य रूप से [[सैटेलाइट]] जइसन स्पेसक्राफ्ट के जरिए कइल जाला, जवन धरती के चारों ओर कक्षा (ऑर्बिट) में घूमेला। एहमें धरती के बाहर जाए वाला [[स्पेस प्रोब]] सभ भी शामिल बाड़ें। एह तरह के उड़ान या त टेलीरोबोटिक (दूर से नियंत्रित) या खुद-ब-खुद चले वाला (ऑटोनॉमस) सिस्टम से चलावल जाला। सबसे पहिले स्पेसफ्लाइट 1950 के दशक में शुरू भइल, जब [[सोवियत संघ]] के [[स्पुतनिक]] उपग्रह उड़ावल गइल; बाद में अमेरिका के एक्स्प्लोरर आ वैनगार्ड मिशन लॉन्च भइलें जे एह कड़ी में आगे के हिस्सा बनलें। मनुष्य के ले जाये वाला स्पेसफ्लाइट कार्यक्रम में सोयुज, शेनझाऊ, पहिले के हो चुकल अपोलो लैंडिंग आ कई ठे स्पेस शटल प्रोग्राम शामिल बाड़ें। आजकाल्ह के स्पेसफ्लाइट [[इंटरनेशनल स्पेस स्टेशन]] (ISS) आ चीन के [[तियांगोंग स्पेस स्टेशन]] तक ले जाये-आवे खातिर भी कइल जा रहल बाड़ें।
[[श्रेणी:अंतरिक्ष उड़ान| ]]
{{Astronomy-stub}}
779qfll8jtqhw9ypiwssjsylzq8inav
790261
790259
2026-04-03T08:57:20Z
SM7
3953
[[विकिपीडिया:हॉट-कैट|हॉट-कैट]] द्वारा [[श्रेणी:खगोलिकी]] जोड़ल गइल
790261
wikitext
text/x-wiki
[[File:Tracy Caldwell Dyson in Cupola ISS.jpg|thumb|upright=1.2|ट्रेसी क्लैड्वेल डायसन, इंटरनेशनल स्पेस स्टेशन के कपोला मॉड्यूल में।]]
'''स्पेसफ्लाइट''' भा '''स्पेसफ्लाईट''' ({{Langx|en|spaceflight}}; अरथ: अंतरिक्ष उड़ान) [[अंतरिक्ष बिज्ञान|अंतरिक्ष विज्ञान]] के एगो एप्लीकेशन हवे, जेह में चीजन (आमतौर पर [[स्पेसक्राफ्ट]]) के [[अंतरिक्ष|बाहरी अंतरिक्ष]] में चाहे ओकरा भीतर उड़ावल जाला, चाहे ओहमें आदमी होखे या ना होखे। ज्यादातर स्पेसफ्लाइट बिना आदमी के होला, आ ई मुख्य रूप से [[सैटेलाइट]] जइसन स्पेसक्राफ्ट के जरिए कइल जाला, जवन धरती के चारों ओर कक्षा (ऑर्बिट) में घूमेला। एहमें धरती के बाहर जाए वाला [[स्पेस प्रोब]] सभ भी शामिल बाड़ें। एह तरह के उड़ान या त टेलीरोबोटिक (दूर से नियंत्रित) या खुद-ब-खुद चले वाला (ऑटोनॉमस) सिस्टम से चलावल जाला। सबसे पहिले स्पेसफ्लाइट 1950 के दशक में शुरू भइल, जब [[सोवियत संघ]] के [[स्पुतनिक]] उपग्रह उड़ावल गइल; बाद में अमेरिका के एक्स्प्लोरर आ वैनगार्ड मिशन लॉन्च भइलें जे एह कड़ी में आगे के हिस्सा बनलें। मनुष्य के ले जाये वाला स्पेसफ्लाइट कार्यक्रम में सोयुज, शेनझाऊ, पहिले के हो चुकल अपोलो लैंडिंग आ कई ठे स्पेस शटल प्रोग्राम शामिल बाड़ें। आजकाल्ह के स्पेसफ्लाइट [[इंटरनेशनल स्पेस स्टेशन]] (ISS) आ चीन के [[तियांगोंग स्पेस स्टेशन]] तक ले जाये-आवे खातिर भी कइल जा रहल बाड़ें।
[[श्रेणी:अंतरिक्ष उड़ान| ]]
[[श्रेणी:खगोलिकी]]
{{Astronomy-stub}}
dnjz947insfclkrcwqljywmf0llfp6j
स्पेस्फ्लाईट
0
100499
790254
2026-04-03T08:48:17Z
SM7
3953
पन्ना [[स्पेसफ्लाइट]] पर अनुप्रेषित कइल गइल
790254
wikitext
text/x-wiki
#REDIRECT [[स्पेसफ्लाइट]]
b4lwxewh8xwrocya0d9rspnkp40vp14
790255
790254
2026-04-03T08:48:30Z
SM7
3953
Added {{[[:Template:R from alternative spelling|R from alternative spelling]]}} tag to redirect
790255
wikitext
text/x-wiki
#REDIRECT [[स्पेसफ्लाइट]]
{{Redirect category shell|
{{R from alternative spelling}}
}}
avcuqz06argdybr5x3p1c4y2jbkpyof
प्रयोगकर्ता वार्ता:Sultansin
3
100500
790258
2026-04-03T08:55:05Z
नया सदस्य स्वागतकर्ता
6624
Adding [[Welcome|welcome message]] to new user's talk page
790258
wikitext
text/x-wiki
{| id="GeoPort-upper" width="100%" cellpadding="5" cellspacing="6" style="background:#FFFAFF; text-align: justify; border-style:ridge; border-width:1px; border-color:#A9A9A9;"
|-
|<div style="display:inline-block;margin-top:.1em; text-align:right; margin-bottom:.2em; border-bottom:0; font-weight:bold;"><big>Welcome! स्वागतम्!</big> [[File:Crystal Clear app ksmiletris.png|25px]] </div>
राउर बहुत-बहुत स्वागत बा '''{{BASEPAGENAME}}''' जी ! {{#if: | {{{1}}} | }}<br/>
<div style="float:right; <!--background:#F5F5DC;--> width:30%">
<!-- दाहिना साइडबार -->
{| border="5" cellspacing="10" cellpadding="5" height="50" align=center border=0 style="background: transparent"
|-
| <big>'''ई जरूर पढ़ल जाय:'''</big>
|-
| style="background-color:#FFFFFF; border: solid 2px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:विकिपीडिया का ना हवे|विकिपीडिया का ना हवे?]]
|-
| style="background-color:#FFFFFF; border: solid 2px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:भोजपुरी में कइसे टाइप करब?|भोजपुरी में टाइपिंग]]
|-
| style="background-color:#FFFFFF; border: solid 1px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:सत्यापन जोग|प्रमाणित बात लिखीं]]
|-
| style="background-color:#FFFFFF; border: solid 1px #FFFFFF; padding:10px 20px;" | [[मदद:फुटनोट|संदर्भ कइसे जोड़ीं?]]
|-
| style="background-color:#FFFFFF; border: solid 1px #FFFFFF; padding:10px 20px;" | [[विकिपीडिया:नीति अउरी दिसानिर्देस|विकिनीति आ निर्देश]]
|}</div>
<!-- मुख्य पाठ -->
'''{{#if: | {{{1}}} | {{BASEPAGENAME}} }} जी''',
एह समय रउँआ [[विकिमीडिया फाउन्डेशन]] के परियोजना [[भोजपुरी]] [[विकिपीडिया]] पर बाड़ीं। भोजपुरी विकिपीडिया एगो मुक्त डिजिटल [[ज्ञानकोश]] हवे, जेवन अइसन भइया-बहिनी लोग मिल के लिखले बा जे ज्ञान बाँटे में बिस्वास करत बाटे। एह समय ए परियोजना में [[विशेष:ActiveUsers|{{NUMBEROFUSERS}} सदस्य]] लोग शामिल बाटे। ई बहुते खुशी क बाति बा कि रउँओं ए में शामिल हो गइल बाड़ीं।
* पहिले से बनल [[विकिपीडिया:लेख|लेखवन]] में कौनो संपादन खाली टेस्ट करे खातिर मत करीं। कौनों तरह के परीक्षण <small>(प्रयोग या टेस्टिंग)</small> [[विकिपीडिया:अभ्यास पन्ना|अभ्यास पन्ना]] या [[Special:MyPage/sandbox|अपना अभ्यास पन्ना]] पर करीं।
* [[विकिपीडिया:आपन परिचय कइसे देईं?|आपन परिचय]] आप संछेप में [[प्रयोगकर्ता:{{BASEPAGENAME}}|अपना सदस्य पन्ना]] पर दे सकत बानी। बहुत पर्सनल बात इहाँ मत लिखीं, न कौनों परचार वाली बात लिखीं। अपने खुद के बारे में लेख मत बनाईं।
* दुसरा [[विकिपीडिया:चौपाल |सदस्य लोगन से बात]] करत समय, [[मदद:वार्ता पन्ना|बातचीत पन्ना]] पर सनेसा लिखले की बाद आपन [[विकिपीडिया:दसखत|दसखत]] <small>(हस्ताक्षर)</small> जरूर करीं। एकरा खातिर अंत में चार गो टेढ़का डैश (<nowiki>~~~~</nowiki>) लिख देंईं या टूलबार में [[File:Insert-signature2.svg|link=|alt=]] पर क्लिक करीं।
* मदद चाहत होखीं त विकिपीडिया के [[विकिपीडिया:मदद|मदद पन्ना]] पर जाईं।
<!-- फुटर के कड़ी सभ -->
सीखे-समझे खातिर कुछ अउरी कड़ी नीचे दिहल जात बाटे:
{| border="5" cellspacing="1" cellpadding="0" height="50" align=center border=0 style="background: transparent"
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 10px;" | [[विकिपीडिया:स्वशिक्षा|शुरू से सीखीं]]
|
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[मदद:संपादन|संपादन सीखीं]]
|
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:नया लेख कइसे सुरू करीं?|नया लेख]]
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:अइसन लेख मना बाटे|लेख मनाहीं]]
|
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:पंचशील|पंचशील]]
| style="background-color:#FFFFFF; border: solid 2px #F2BDCD; padding:1px 20px;" | [[विकिपीडिया:समुदाय पोर्टल|सदस्य समाज पन्ना]]
|}
|}
-- [[प्रयोगकर्ता:नया सदस्य स्वागतकर्ता|नया सदस्य स्वागतकर्ता]] ([[प्रयोगकर्ता वार्ता:नया सदस्य स्वागतकर्ता|बात करीं]]) 08:55, 3 अप्रैल 2026 (UTC)
328dc2lbi6u37kh6glxgsnxnxjlnhzb
टेम्पलेट:Infobox colour
10
100501
790267
2005-06-29T20:58:19Z
24.224.153.40
#redirect [[template:infobox color]]
790267
wikitext
text/x-wiki
#redirect [[template:infobox color]]
czgg5jg4on6f51v2u15nnhnj1vnfc4g
790268
790267
2006-02-14T15:11:47Z
en>RussBot
0
Robot: Fixing [[Special:DoubleRedirects|double-redirect]] -"Template:infobox color" +"Template:Infobox Color"
790268
wikitext
text/x-wiki
#REDIRECT [[Template:Infobox Color]]
cdo363mglkia5nr286yniyqoz2dwvzx
790269
790268
2009-11-28T05:22:14Z
en>Fuhghettaboutit
0
Fix double redirect
790269
wikitext
text/x-wiki
#REDIRECT [[Template:Infobox color]]
09qf74uqa1gf7bw7oycc9nybijd5dzx
790270
790269
2010-02-18T02:08:38Z
en>Wknight94
0
Protected Template:Infobox colour: [[WP:HRT|Highly visible template]] ([edit=sysop] (indefinite) [move=sysop] (indefinite))
790269
wikitext
text/x-wiki
#REDIRECT [[Template:Infobox color]]
09qf74uqa1gf7bw7oycc9nybijd5dzx
790271
790270
2013-10-19T11:29:03Z
en>WOSlinker
0
Changed protection level of Template:Infobox colour: allow template editors to modify ([Edit=Protected template] (indefinite) [Move=Protected template] (indefinite))
790269
wikitext
text/x-wiki
#REDIRECT [[Template:Infobox color]]
09qf74uqa1gf7bw7oycc9nybijd5dzx
790272
790271
2026-04-03T11:31:40Z
SM7
3953
5 revisions imported from [[:en:Template:Infobox_colour]]
790269
wikitext
text/x-wiki
#REDIRECT [[Template:Infobox color]]
09qf74uqa1gf7bw7oycc9nybijd5dzx