Модуль:Основная статья
Модуль, реализующий шаблон {{Основная статья}}. Отслеживающие категории: local p = {}
local get_args = require('Module:Arguments').getArgs
local mHatnote = require('Module:Hatnote')
local category_ns_number = 14
local templatestyles_page = 'Module:Основная статья/styles.css'
local function get_property(args)
local res = mw.getCurrentFrame():expandTemplate{title = 'wikidata', args = args}
return res ~= '' and res or nil
end
local function get_link_target(wikitext)
local target = wikitext:match('%[%[([^%]%|]+)%]') or wikitext:match('%[%[([^%|]+)%|')
return {
target = target or wikitext,
contains_link = target ~= nil
}
end
local function get_catmain_from_wikidata(properties)
local values = {}
for _, property in pairs(properties) do
values[#values + 1] = get_property{property}
values[#values + 1] = get_property{property, plain = true}
end
if #values > 0 then
for _, value in pairs(values) do
local link_target = get_link_target(value)
local title = mw.title.new(link_target.target)
if title and title.exists then
return {
title = value,
exists = true,
missed = not link_target.contains_link
}
end
end
return {title = values[1], exists = false}
end
return nil
end
function p.main(frame)
local args = get_args(frame)
local current_title = mw.title.getCurrentTitle()
local categories = mHatnote.define_categories{
by_wikidata = 'Википедия:Категории с основной статьёй из Викиданных',
by_pagename = 'Википедия:Категории c основной статьёй, которая не указана явно',
missed = 'Википедия:Категории с существующей основной статьёй, не указанной в Викиданных'
}
local hatnote_args = setmetatable({
extraclasses = 'ts-main',
prefix = 'Основная статья:',
prefix_plural = 'Основные статьи:'
}, { __index = args })
local overridden_categories = {}
local nocat = args.nocat
if current_title.namespace == category_ns_number then
hatnote_args.id = 'catmore'
overridden_categories.red_link = 'Википедия:Категории без основных статей'
local first_title_exists
if not hatnote_args[1] then
local catmain = get_catmain_from_wikidata{'p301', 'p1753'}
local title
if catmain then
title = catmain.title
first_title_exists = catmain.exists
categories:add('by_wikidata', nocat)
if catmain.missed then
categories:add('missed')
end
else
title = current_title.text
categories:add('by_pagename', nocat)
end
hatnote_args[1] = title
end
if first_title_exists == nil then
link = mHatnote.parse_link{hatnote_args[1]}
first_title_exists = not link or mw.title.new(link).exists
end
if not first_title_exists then
hatnote_args.prefix = 'У этой категории нет основной статьи —'
end
end
hatnote_args.prefix = frame:extensionTag{
name = 'templatestyles',
args = { src = templatestyles_page },
} .. hatnote_args.prefix
return mHatnote.main(hatnote_args, overridden_categories) .. categories
end
return p
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia