Амодуль:Settlement short description


--generates auto short description for use in infobox settlementlocal p = {}p.categories = ""local plain = require('Module:Plain text')._mainlocal getArgs = require('Module:Arguments').getArgslocal tableTools = require ('Module:TableTools')function p.reverseTable (init)init[1], init[3] = init[3], init[1]return initend--Display short description using {{short description}}function p.shortdesc(text, frame)return frame:expandTemplate{title = 'Short description', args = {text, 'noreplace'}}endfunction p.category (cattype)local category = string.format('[[Category:Infobox settlement pages with bad %s]]', cattype)if category then p.categories = p.categories..category end --categorizeend--sanity and other checksfunction p.validate (parameter, cat)if not parameter then return nil endparameter = parameter:gsub('%b()', '') --remove things in brackets as etxtraneous information   :gsub('%s+', ' ') --fix possible extra spaces from previous cleanup   :gsub('^%s+', '') --trim spaces from beginning   :gsub('%s+$', '') --trim spaces from endif parameter:match("[,;]") or not parameter:match("%a") then --must have some letters, ignore if multiple types/subdivionsif cat then p.category (cat) endreturn nilendif (parameter == "") then return nil endreturn parameterend--removes redundancy like "England, United Kingdom" and fixes issues like "Foo in United States" (to "Foo in the United States")--also used in Module:Type in locationfunction p.cleanupLoc (location)if location == "" then return nil endlocal replacements = {["England, United Kingdom"] =  "England",["Scotland, United Kingdom"] =  "Scotland",["Wales, United Kingdom"] =  "Wales",["New York City, New York, United States"] =  "New York City",["^United States$"] = "the United States",["London, United Kingdom"] = "London",["London, England"] = "London"}for i, v in pairs(replacements) do location = location:gsub(i, v) --series of replacementsendreturn locationendfunction p.main(frame)local categories = ""local subdivisions = {}local args = getArgs (frame, {frameOnly = true})local settlement_type = p.validate(plain(args[1]), "settlement type") or "Place"local short_description = plain(args[2])subdivisions[1] = p.validate(plain(args[3]))subdivisions[2] = p.validate(plain(args[4]))subdivisions[3] = p.validate(plain(args[5]))if short_description thenif (short_description == 'no') thenreturnelsereturn p.shortdesc(short_description, frame)endendif not(subdivisions[3] and(string.find(settlement_type, '[nN]eighbo[u]?rhood') or string.find(settlement_type, '[sS]uburb'))) thensubdivisions[3] = nil --only display the third subdivision_type if suburb or neighborhoodendfor x, y in ipairs (subdivisions) doif y thenif string.find(settlement_type, y, 1, true) then --if the subdivision is found within the settlement typesubdivisions[x] = nil --don't display redundancyp.category ("settlement type")endif y == mw.title.getCurrentTitle().text then --if the title is the same as one of the subdivisionssubdivisions[x] = nil --don't display redundancyendendendlocal location = table.concat(tableTools.compressSparseArray(p.reverseTable(subdivisions)), ', ')location = p.cleanupLoc (location)if location then location =  " in " .. location else location = "" endreturn p.shortdesc(settlement_type..location, frame)..p.categoriesendreturn p
🔥 Top keywords: Ихадоу адаҟьаАвикипедиа:АфорумАндорраМсырЕреван606Араб бызшәаАгеографиатә акоординатқәа1468Амаџьар бызшәаҲ. ҟ. 355ҞазахсҭанЦастәи:АԥшаараАвикипедиа:ОписаниеАнқәаб, Александр Золотинска-иԥаАвикипедиа:Бзиала шәаабеитБагаԥшь, Сергеи Уасил-иԥаАшаблон:Interwiki redirectАкатегориа:Ашаблонқәа:Аҭыԥ ахсаалақәаАвикипедиа:Aкатегориақәа алԥшаараАвикипедиа:Алфавиттә арбагаАшаблон:Участник SWMTАшаблон:Location mapАфаил:Bilgine-sor.jpgАмодуль:Location map/data/NepalАкатегориа:Ахада акатегориақәаYouTubeАвикипедиаАԥсны Аҳәынҭқарра АконституциаЦастәи:АрҽеираҾыцқәаАмраАмодуль:Location map/data/CroatiaАкатегориа:Ашаблонқәа:Location map - НепалУрыстәылаАлеқсандр Македонски20Афаил:Babalynn.jpgАҳәынҭқаррақәа рсиаҚапба, Енвер Ерасҭа-иԥаБагаԥшь (аҵакырацәара)Авикипедиа:Ацҳаражəҳəарҭа10Ҷанба, Самсон Иаков-иԥаАҟәаАнқәаб (аҵакырацәара)Авикипедиа:АдминистраторцәаАкатегориа:Қырҭтәыла атәылаҿацәқәаАкатегориа:Ашаблонқәа:Location map - ХорватиаАԥсуа бызшәаПицундаАнглыз бызшәаБританиадуҲаразиа (аҵакырацәара)19622021Аиспан бызшәа2005Аџьам бызшәаЛаҵарамза 4Урым 1960ФранциаАкатегориа:Ашаблонқәа:Location map - ЕвропаАкатегориа:Қырҭтәыла тәылаҿацәкАкатегориа:Ашаблонқәа:Location map - ЕААШәачаШьынқәба, Баграт Уасил-иԥаАлаҭын бызшәа6Польша5Аметрополитенқәа рыхьӡынҵаАмодуль:Location map/data/EuropeАмшынАԥара215УкраинаИапониаИԥсабаратәу ахыԥхьаӡараАмодуль:Location map/data/South Korea1117Цандрыԥшь1976УелсАмодуль:Location map/data/AustriaАсоветтә Социалисттә Республикақәа РеидгылаАдемократиатә Республика КонгоТогоҲаразиа, АлеқсандрЖьҭаарамза 24Даниа2014Берлин19752002Ашаблон:StackАмодуль:Location map/data/Podlaskie Voivodeship1966Намибиа