Module:User:AnomieBOT/LanguageCategoryCreator
| This module depends on the following other modules: |
This module is used by AnomieBOT's LanguageCategoryCreator task as on-wiki configuration of categories to create and the wikitext for those categories, and to validate categories before creating them based on other module data.
It likely has no on-wiki transclusions, since the bot uses it via the action API action=parse.
Usage
{{#invoke:User:AnomieBOT/LanguageCategoryCreator|list_cat_likes}}
Returns SQL LIKE patterns for categories that may need creating, one per line.
{{#invoke:User:AnomieBOT/LanguageCategoryCreator|generate_cat_wikitext|cat=title}}
Returns the wikitext to use when creating the named category. title is the category name, without the Category: prefix, using spaces rather than underscores. If the category is invalid, returns an error message prefixed with ERROR:.
-- A module used by AnomieBOT's LanguageCategoryCreator task.
-- See [[Wikipedia:Bots/Requests for approval/AnomieBOT 84]]
local p = {}
-- Map of category patterns to handler types.
local cats = {
['Articles containing (.+)-language text'] = 'lang',
['Articles with text in (.+) languages'] = 'lang',
['Articles with (.+)-language sources %((.+)%)'] = 'in_lang',
['Articles with sources in (.+) languages %((.+)%)'] = 'in_lang',
['Pages with (.+) IPA'] = 'ipa',
['CS1 (.+)-language sources %((.+)%)'] = 'cs1_sources',
['CS1 uses (.+)-language script %((.+)%)'] = 'cs1_script',
}
-- List SQL LIKE syntax for supported categories.
function p.list_cat_likes()
local keys = {}
for k, v in pairs( cats ) do
-- Convert pattern to LIKE syntax.
k = k:gsub( '%%', '' ):gsub( ' ', '\\_' ):gsub( '%(%.%+%)', '%%' )
table.insert( keys, k )
end
return table.concat( keys, '\n' )
end
-- Generate the wikitext for a category page.
function p.generate_cat_wikitext( frame )
local cat = frame.args.cat
for k, v in pairs( cats ) do
local m = { cat:match( '^' .. k .. '$' ) }
if #m > 0 then
return p[ v ]( cat, unpack( m ) )
end
end
return 'ERROR: Unrecognized category'
end
-- Generate the wikitext for a {{lang}} category page
function p.lang( cat, name )
local mLang = require( 'Module:Lang' )
local tag = mLang._tag_from_name{ name }
if tag:find( '^<span' ) then
return 'ERROR: language name not recognized'
end
local cat2 = mLang._category_from_tag{ tag }
if cat2:find( '^<span' ) then
return 'ERROR: no category for code ' .. tag
end
if cat2 ~= 'Category:' .. cat then
return 'ERROR: category for code ' .. tag .. ' is ' .. cat2 .. ', not Category:' .. cat
end
return '{{Non-English-language text category}}'
end
-- Generate the wikitext for an {{in lang}} category page
function p.in_lang( cat, name, tag )
local mLang = require( 'Module:In lang' )
local cat2 = mLang._in_lang{ tag, ['list-cats'] = 'yes' }
if cat2 == '' then
return 'ERROR: no category for code ' .. tag
end
if cat2 ~= 'Category:' .. cat then
return 'ERROR: category for code ' .. tag .. ' is ' .. cat2 .. ', not Category:' .. cat
end
return '{{Non-English-language sources category}}'
end
-- Generate the wikitext for an {{IPA}} category page
function p.ipa( cat, name )
local mIpa = require( 'Module:IPA/category documentation' )
local code = mIpa.lookup_name( name )
if not code then
return 'ERROR: language name not recognized'
end
return '{{IPA language category}}'
end
-- Generate the wikitext for "sources" categories from CS1 templates
function p.cs1_sources( cat, name, tag )
local mCs1 = require( 'Module:Cs1 documentation support' )
if mCs1.code_name_pair_exists( { tag, name } ) == nil then
return 'ERROR: code/name pair does not exist'
end
return '{{CS1 language sources}}'
end
-- Generate the wikitext for "script" categories from CS1 templates
function p.cs1_script( cat, name, tag )
local mCs1 = require( 'Module:Cs1 documentation support' )
if mCs1.code_name_pair_exists( { tag, name } ) == nil then
return 'ERROR: code/name pair does not exist'
end
return '{{CS1 language script}}'
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.