dNie podano opisu zmian |
(Gadżet=/=przestrzeń nazw widget) |
||
(Nie pokazano 8 wersji utworzonych przez 4 użytkowników) | |||
Linia 1: | Linia 1: | ||
local p = {} |
local p = {} |
||
+ | |||
+ | local defaultDocPage = 'opis' |
||
+ | |||
+ | local getType = function( namespace, page ) |
||
+ | local pageType = 'template' |
||
+ | if namespace == 'Moduł' or namespace == 'Module' then |
||
+ | pageType = 'module' |
||
+ | elseif namespace == 'Widget' then |
||
+ | pageType = 'widget' |
||
+ | elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.css$' ) then |
||
+ | pageType = 'stylesheet' |
||
+ | elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.js$' ) then |
||
+ | pageType = 'script' |
||
+ | elseif namespace == 'MediaWiki' then |
||
+ | pageType = 'message' |
||
+ | end |
||
+ | |||
+ | return pageType |
||
+ | end |
||
+ | |||
+ | local getTypeForms = function( pageType ) |
||
+ | if pageType == 'module' then |
||
+ | return {gen = 'tym module', acc = 'tego modułu', pronoun_gen = "его", nomP = 'Moduły'} |
||
+ | elseif pageType == 'widget' then |
||
+ | return {gen = 'tym widżecie', acc = 'tego widżetu', pronoun_gen = "его", nomP = 'Widżety'} |
||
+ | elseif pageType == 'stylesheet' then |
||
+ | return {gen = 'tym arkuszu stylów', acc = 'tego arkusza stylów', pronoun_gen = "еro", nomP = 'Arkusze stylów'} |
||
+ | elseif pageType == 'script' then |
||
+ | return {gen = 'tym skrypcie', acc = 'tego skryptu', pronoun_gen = "его", nomP = 'Skrypty'} |
||
+ | elseif pageType == 'message' then |
||
+ | return {gen = 'tej wiadomości systemowej', acc = 'tej wiadomości systemowej', pronoun_gen = "его", nomP = 'Wiadomości'} |
||
+ | else -- type == 'template' |
||
+ | return {gen = 'tym szablonie', acc = 'tego szablonu', pronoun_gen = "его", nomP = 'Szablony'} |
||
+ | end |
||
+ | end |
||
+ | |||
-- Creating a documentation page or transclution through {{subst:doc}} |
-- Creating a documentation page or transclution through {{subst:doc}} |
||
function p.create( f ) |
function p.create( f ) |
||
local args = require( 'Moduł:ProcessArgs' ).norm() |
local args = require( 'Moduł:ProcessArgs' ).norm() |
||
− | page = mw.title.getCurrentTitle() |
+ | local page = mw.title.getCurrentTitle() |
− | + | local docPage = args['strona'] or page.nsText .. ':' .. page.baseText .. '/' .. defaultDocPage |
|
− | docPage = args['strona'] or namespace .. ':' .. page.baseText .. '/opis' |
||
local out |
local out |
||
− | if page |
+ | if not args["treść"] and tostring( page ) == docPage then |
out = f:preprocess( '{{subst:Szablon:Dokumentacja/preload}}' ) |
out = f:preprocess( '{{subst:Szablon:Dokumentacja/preload}}' ) |
||
else |
else |
||
local templateArgs = {} |
local templateArgs = {} |
||
+ | for _, key in ipairs{ 'typ', 'strona', 'treść' } do |
||
− | if args['typ'] then |
||
− | + | local val = args[key] |
|
+ | if val then |
||
− | end |
||
− | if |
+ | if key == 'treść' then val = '\n' .. val .. '\n' end |
− | table.insert( templateArgs, ' |
+ | table.insert( templateArgs, key .. '=' .. val ) |
+ | end |
||
end |
end |
||
+ | |||
− | |||
− | out = '{{Dokumentacja|' .. table.concat( templateArgs, '|' ) .. '}} |
+ | out = '{{Dokumentacja|' .. table.concat( templateArgs, '|' ) .. '}}' |
out = out:gsub( '|}}', '}}' ) |
out = out:gsub( '|}}', '}}' ) |
||
+ | |||
+ | if not args["treść"] then |
||
+ | out = out .. '\n<!-- Kategorie i interwiki umieść na stronie dokumentacji. -->' |
||
+ | end |
||
end |
end |
||
if not mw.isSubsting() then |
if not mw.isSubsting() then |
||
out = f:preprocess( out ) |
out = f:preprocess( out ) |
||
− | if args['niekat'] |
+ | if not args['niekat'] then |
− | out = out .. '[[Kategoria: |
+ | out = out .. '[[Kategoria:Pages with templates requiring substitution]' |
end |
end |
||
end |
end |
||
Linia 33: | Linia 73: | ||
end |
end |
||
− | -- |
+ | -- Header2 on the documentation page |
− | function p.docPage(f) |
+ | function p.docPage( f ) |
local args = require( 'Moduł:ProcessArgs' ).merge( true ) |
local args = require( 'Moduł:ProcessArgs' ).merge( true ) |
||
− | local badDoc = args['zladok'] |
+ | local badDoc = args['zladok'] |
− | local |
+ | local forceNoDoc = args['brakdok'] |
+ | |||
− | if f:callParserFunction( '#dplvar:noheader' ) == '1' then |
||
+ | local docclass = "documentation-norm" |
||
− | if noDoc ~= '' then |
||
+ | if badDoc then |
||
− | f:callParserFunction( '#dplvar:set', 'notdoc', '1' ) |
||
+ | docclass = "documentation-bad" |
||
− | elseif badDoc ~= '' then |
||
+ | elseif forceNoDoc then |
||
− | f:callParserFunction( '#dplvar:set', 'baddoc', '1' ) |
||
+ | docclass = "documentation-no" |
||
+ | end |
||
+ | if forceNoDoc then |
||
+ | f:callParserFunction( '#dplvar:set', '$doc forced_none', '1' ) |
||
+ | end |
||
+ | |||
+ | if f:callParserFunction( '#dplvar', '$doc noheader' ) == '1' then |
||
+ | if badDoc then |
||
+ | f:callParserFunction( '#dplvar:set', '$doc bad', '1' ) |
||
end |
end |
||
− | return |
+ | return |
end |
end |
||
+ | |||
local page = mw.title.getCurrentTitle() |
local page = mw.title.getCurrentTitle() |
||
− | local namespace = |
+ | local namespace = page.nsText |
− | local pageType = |
+ | local pageType = mw.ustring.lower( args['typ'] or getType( namespace, page ) ) |
− | local |
+ | local typeForms = getTypeForms( pageType ) |
− | local pageType3 = 'Szablony' |
||
+ | local body = mw.html.create( 'div' ):addClass( 'documentation-header' ) |
||
− | |||
+ | body |
||
− | if namespace == 'Moduł' then |
||
+ | :css{ |
||
− | pageType = 'tym module' |
||
+ | ['margin-bottom'] = '0.8em', |
||
− | pageType2 = 'tego modułu' |
||
− | + | padding = '0.8em 1em 0.7em', |
|
+ | } |
||
− | elseif page.fullText:find( '.css$' ) then |
||
+ | :tag( 'div' ) |
||
− | pageType = 'tem arkuszu stylów' |
||
+ | :css( 'float', 'right' ) |
||
− | pageType2 = 'tego arkusza stylów' |
||
+ | :wikitext( '[[', page:fullUrl( 'action=purge' ), ' ' .. f:preprocess('{{lc:{{int:purge}}}}') .. ']]' ) |
||
− | pageType3 = 'Arkusze stylów' |
||
+ | :done() |
||
− | elseif page.fullText:find( '.js$' ) then |
||
+ | :wikitext( |
||
− | pageType = 'tym skrypcie' |
||
+ | 'To jest strona dokumentacji, ', |
||
− | pageType2 = 'tego skryptu' |
||
+ | pageType == 'module' and 'będzie ona dołączona' or 'powinna ona być dołączona', |
||
− | pageType3 = 'Skrypty' |
||
+ | ' na stronie głównej. ', |
||
− | elseif namespace == 'MediaWiki' then |
||
+ | 'Aby uzyskać więcej informacji sprawdź [[Szablon:Dokumentacja]].' |
||
− | pageType = 'tej wiadomości systemowej' |
||
+ | ) |
||
− | pageType2 = 'tej wiadomości systemowej' |
||
+ | if badDoc then |
||
− | pageType3 = 'Wiadomości' |
||
+ | body:wikitext( "<br>'''Dokumentacja " .. typeForms.gen .. " wymaga uzupełnienia lub ulepszenia.'''" ) |
||
+ | elseif forceNoDoc then |
||
+ | body:wikitext( "<br>'''W " .. typeForms.gen .. " nie ma dokumentacji. Jeśli wiesz jak używać " .. typeForms.acc .. ", udokumentuj to.'''" ) |
||
end |
end |
||
+ | if not ( args["niekat"] or namespace == 'Użytkownik' or namespace == 'Użytkowniczka' ) then |
||
− | local colour = 'EAF4F9' |
||
+ | body:wikitext( '[[Kategoria:Szablony dokumentacji]]' ) |
||
− | local message = '' |
||
− | local imageType = '' |
||
− | if badDoc ~= '' then |
||
− | colour = 'F9F2EA' |
||
− | imageType = 'bad' |
||
− | message = "'''Dokumentacja " .. pageType .. " została uznana za niepoprawną. Jeżeli chcesz, możesz ją poprawić!'''" |
||
end |
end |
||
− | if noDoc ~= '' then |
||
− | imageType = 'no' |
||
− | colour = 'F9EAEA' |
||
− | message = "'''У " .. pageType .. " nie posiada dokuentacji. Jeżeli wiesz jak używać " .. pageType2 .. ", dodaj więcej informacji do dokumentacji.'''" |
||
− | end |
||
− | |||
− | local certainty = 'powinna ona być dołączona' |
||
− | if pageType2 ~= 'tego szablonu' then |
||
− | certainty = 'będzie ona dołączona' |
||
− | end |
||
− | |||
− | local category = '' |
||
− | if args['niekat'] ~= '1' then |
||
− | category = '[[Kategoria:Szablony dokumentacji]]' |
||
− | end |
||
− | |||
− | local out = table.concat( { |
||
− | '<div style="margin-bottom: 0.8em; padding: 0.8em 1em 0.7em; background-color: #' .. colour .. '; border: 1px solid #AAA">', |
||
− | '<div class="doc-image">[[File:Template-' .. imageType .. 'info.png|60px]]</div>', |
||
− | |||
− | '<div style="float: right">[[' .. page:fullUrl( 'action=purge' ) .. ' ' .. f:preprocess( '{{lc:{{int:purge}}}}' ) .. ']]</div>', |
||
− | '<div style="margin: 0">To jest strona dokumentacji, ' .. certainty .. ' na stronie głównej ' .. pageType .. '. Aby uzyskać więcej informacji sprawdź [[Szablon:Dokumentacja]].</div>', |
||
− | message, |
||
− | '</div>', |
||
− | category |
||
− | }, '\n' ) |
||
− | return |
+ | return body |
end |
end |
||
-- Wrapper around the documentation on the main page |
-- Wrapper around the documentation on the main page |
||
function p.page( f ) |
function p.page( f ) |
||
+ | -- mw.text.trim uses mw.ustring.gsub, which silently fails on large strings |
||
− | local args = require( 'Moduł:ProcessArgs' ).merge( true ) |
||
− | local |
+ | local function trim( s ) |
+ | return (s:gsub( '^[\t\r\n\f ]+', '' ):gsub( '[\t\r\n\f ]+$', '' )) |
||
− | local namespace = args['typ'] or page.nsText |
||
− | local docPage = mw.title.new( args['strona'] or namespace .. ':' .. page.text .. '/opis' ) |
||
− | local noDoc = args['brakdok'] or '' |
||
− | if not docPage.exists or noDoc ~= '' then |
||
− | local noDoc = 1 |
||
− | local badDoc = nil |
||
− | elseif args['zladok'] ~= '' then |
||
− | local badDoc = 1 |
||
− | local noDoc = nil |
||
end |
end |
||
+ | local args = require( 'Moduł:ProcessArgs' ).merge( true ) |
||
− | local pageType = 'tym szablonie' |
||
− | local |
+ | local page = mw.title.getCurrentTitle() |
− | local |
+ | local namespace = page.nsText |
+ | local docText = trim( args["treść"] or '' ) |
||
− | |||
− | if |
+ | if docText == '' then docText = nil end |
+ | |||
− | pageType = 'tym module' |
||
+ | local docPage |
||
− | pageType2 = 'tego modułu' |
||
+ | local noDoc |
||
− | pageType3 = 'Moduły' |
||
+ | local forceNoDoc |
||
− | elseif page.fullText:find( '.css$' ) then |
||
+ | if docText then |
||
− | pageType = 'tem arkuszu stylów' |
||
+ | docPage = page |
||
− | pageType2 = 'tego arkusza stylów' |
||
+ | else |
||
− | pageType3 = 'Arkusze stylów' |
||
+ | docPage = mw.title.new( args["strona"] or namespace .. ':' .. page.text .. '/' .. defaultDocPage) |
||
− | elseif page.fullText:find( '.js$' ) then |
||
+ | noDoc = args["brakdok"] or not docPage.exists |
||
− | pageType = 'tym skrypcie' |
||
− | pageType2 = 'tego skryptu' |
||
− | pageType3 = 'Skrypty' |
||
− | elseif namespace == 'MediaWiki' then |
||
− | pageType = 'tej wiadomości systemowej' |
||
− | pageType2 = 'tej wiadomości systemowej' |
||
− | pageType3 = 'Wiadomości' |
||
− | |||
end |
end |
||
+ | local badDoc = args["zladok"] |
||
− | |||
+ | local pageType = mw.ustring.lower( args['typ'] or getType( namespace, page ) ) |
||
− | local docText = '' |
||
+ | local typeForms = getTypeForms( pageType ) |
||
− | |||
+ | |||
− | if docPage.exists then |
||
+ | if not docText and not noDoc then |
||
− | f:callParserFunction( '#dplvar:set', 'noheader', '1' ) |
||
+ | f:callParserFunction( '#dplvar:set', '$doc noheader', '1' ) |
||
− | docText = mw.text.trim( f:expandTemplate{ title = ':' .. docPage.fullText } ) |
||
+ | docText = trim( f:expandTemplate{ title = ':' .. docPage.fullText } ) |
||
− | if f:callParserFunction( '#dplvar:baddoc' ) == '1' then |
||
+ | if f:callParserFunction( '#dplvar', '$doc bad' ) == '1' then |
||
badDoc = 1 |
badDoc = 1 |
||
end |
end |
||
+ | forceNoDoc = f:callParserFunction( '#dplvar', '$doc forced_none' ) == '1' |
||
− | |||
+ | |||
− | if docText == '' then |
||
+ | if docText == '' and not forceNoDoc then |
||
− | noDoc = 1 |
||
+ | docText = nil |
||
− | else |
||
− | docText = '\n' .. docText .. '\n' |
||
− | end |
||
− | |||
− | if f:callParserFunction( '#dplvar:notdoc' ) == '1' then |
||
noDoc = 1 |
noDoc = 1 |
||
end |
end |
||
+ | end |
||
+ | if docText then |
||
+ | docText = '\n' .. docText .. '\n' |
||
end |
end |
||
− | local action = f:preprocess( |
+ | local action = f:preprocess('{{lc:{{int:edit}}}}') |
local preload = '' |
local preload = '' |
||
− | local |
+ | local docclass = "documentation-norm" |
− | local message |
+ | local message |
− | local category |
+ | local category |
+ | if noDoc then |
||
− | local imageType = '' |
||
+ | action = f:preprocess('{{lc:{{int:create}}}}') |
||
− | if not docPage.exists then |
||
− | action = f:preprocess( '{{lc:{{int:create}}}}' ) |
||
preload = '&preload=Szablon:Dokumentacja/preload' |
preload = '&preload=Szablon:Dokumentacja/preload' |
||
+ | docclass = "documentation-no" |
||
− | noDoc = 1 |
||
+ | message = "'''W " .. typeForms.gen .. " nie ma dokumentacji. " .. |
||
− | end |
||
+ | "Jeśli wiesz jak używać " .. typeForms.acc .. ", proszę, podaj odpowiednie informacje.'''" |
||
− | if noDoc == 1 then |
||
+ | if not ( args["niekat"] or namespace == 'Użytkownik' or namespace == 'Użytkowniczka' ) then |
||
− | imageType = 'no' |
||
+ | category = typeForms.nomP .. ' bez dokumentacji' |
||
− | colour = 'F9EAEA' |
||
+ | if not mw.title.new( 'Kategoria:' .. category ).exists then |
||
− | message = "'''W " .. pageType .. " nie ma dokumentacji. Jeśli wiesz jak używać " .. pageType2 .. ", dodaj odpowiednie informacje.'''" |
||
+ | category = 'Strony bez dokumentacji' |
||
− | if args['niekat'] ~= '1' then |
||
+ | end |
||
− | if mw.title.new( 'Kategoria:' .. pageType3 .. ' bez dokumentacji' ).exists then |
||
+ | end |
||
− | category = '[[Kategoria:' .. pageType3 .. ' bez dokumentacji]]' |
||
+ | elseif forceNoDoc then |
||
− | else |
||
+ | docclass = "documentation-no" |
||
− | category = '[[Kategoria:Strony bez dokumentacji]]' |
||
+ | message = "'''W " .. typeForms.gen .. " nie ma dokumentacji. " .. |
||
+ | "Jeśli wiesz jak używać " .. typeForms.acc .. ", proszę, podaj odpowiednie informacje.'''" |
||
+ | if not ( args["niekat"] or namespace == 'Użytkownik' or namespace == 'Użytkowniczka' ) then |
||
+ | category = typeForms.nomP .. ' bez dokumentacji' |
||
+ | if not mw.title.new( 'Kategoria:' .. category ).exists then |
||
+ | category = 'Strony bez dokumentacji' |
||
end |
end |
||
end |
end |
||
elseif badDoc then |
elseif badDoc then |
||
− | + | docclass = "documentation-bad" |
|
+ | message = "'''Dokumentacja " .. typeForms.gen .. " wymaga uzupełnienia lub ulepszenia.'''\n" |
||
− | colour = 'F9F2EA' |
||
+ | if not ( args["niekat"] or namespace == 'Użytkownik' or namespace == 'Użytkowniczka' ) then |
||
− | message = "'''Dokumentacja " .. pageType .. " została uznanana za niepoprawną. Jeżeli masz czas, uzupełnij ją!'''\n" |
||
+ | category = typeForms.nomP .. ' ze złą dokumentacją' |
||
− | if args['niekat'] ~= '1' then |
||
− | if mw.title.new( 'Kategoria:' .. |
+ | if not mw.title.new( 'Kategoria:' .. category ).exists then |
− | category = ' |
+ | category = 'Strony ze złą dokumentacją' |
− | else |
||
− | category = '[[Kategoria:Strony ze złą dokumentacją]]' |
||
end |
end |
||
end |
end |
||
end |
end |
||
+ | local historyLink = f:preprocess('{{lc:{{int:history short}}}}') |
||
+ | local purgeLink = f:preprocess('{{lc:{{int:purge}}}}') |
||
+ | local viewLink = f:preprocess('{{lc:{{int:view}}}}') |
||
+ | |||
local links = { |
local links = { |
||
'[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']', |
'[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']', |
||
− | '[' .. |
+ | '[' .. docPage:fullUrl( 'action=history' ) .. ' ' .. historyLink .. ']', |
+ | '[' .. page:fullUrl( 'action=purge' ) .. ' ' .. purgeLink .. ']' |
||
} |
} |
||
+ | if not noDoc and page ~= docPage then |
||
− | local footer = '' |
||
+ | table.insert( links, 1, '[[' .. docPage.fullText .. '|' .. viewLink .. ']]' ) |
||
− | if docPage.exists then |
||
− | table.insert( links, 1, '[[' .. docPage.fullText .. '|' .. f:preprocess( '{{lc:{{int:view}}}}' ) .. ']]' ) |
||
− | footer = table.concat( { |
||
− | '<div style="margin: 0.7em -1em -0.7em; background-color: #EAF4F9; border-top: 1px solid #AAA; padding: 0.8em 1em 0.7em; clear: both">\n', |
||
− | '<div style="float: right">' .. mw.text.nowiki( '[' ) .. table.concat( links, ' | ' ) .. ']</div>\n', |
||
− | '<p style="margin: 0">Powyższy opis jest dołączany ze strony [[' .. docPage.fullText .. ']].</p>\n', |
||
− | '</div>\n' |
||
− | } ) |
||
end |
end |
||
+ | links = mw.html.create( 'span' ) |
||
+ | :css( 'float', 'right' ) |
||
+ | :wikitext( mw.text.nowiki( '[ ' ), table.concat( links, ' | ' ), mw.text.nowiki( ' ]' ) ) |
||
+ | local body = mw.html.create( 'div' ):addClass( 'documentation ' .. docclass ) |
||
− | local out = { |
||
+ | body:css{ |
||
− | '<div style="background-color: #' .. colour .. '; border: 1px solid #AAA; padding: 0.8em 1em 0.7em; clear: both">\n', |
||
+ | padding = '0.8em 1em 0.7em', |
||
− | '<div style="margin: -0.8em -1em 0.8em; padding: 0.8em 1em 0.7em; background-color: #EAF4F9; border-bottom: 1px solid #AAA">\n', |
||
+ | ['margin-top'] = '1em', |
||
− | '<div class="doc-image">[[File:Template-' .. imageType .. 'info.png|60px]]</div>', |
||
+ | clear = 'both' |
||
− | '<div style="float: right">' .. mw.text.nowiki( '[' ) .. table.concat( links, ' | ' ) .. ']</div>\n', |
||
− | '<span style="font-weight: bold; font-size: 130%">Dokumentacja</span>', |
||
− | '</div>\n', |
||
− | message, |
||
− | docText, |
||
− | footer, |
||
− | '</div>\n', |
||
− | category |
||
} |
} |
||
+ | local header = mw.html.create( 'div' ) |
||
− | return mw.text.trim( table.concat( out ) ) |
||
+ | :addClass( 'documentation-header' ) |
||
+ | :css{ |
||
+ | margin = '-0.8em -1em 0.8em', |
||
+ | padding = '0.8em 1em 0.7em', |
||
+ | ['border-bottom'] = 'inherit' |
||
+ | } |
||
+ | |||
+ | header |
||
+ | :node( links ) |
||
+ | :tag( 'span' ) |
||
+ | :css{ |
||
+ | ['font-weight'] = 'bold', |
||
+ | ['font-size'] = '130%', |
||
+ | ['margin-right'] = '1em', |
||
+ | ['line-height'] = '1' |
||
+ | } |
||
+ | :wikitext( 'Dokumentacja' ) |
||
+ | |||
+ | if not noDoc and pageType ~= 'template' and pageType ~= 'message' then |
||
+ | header |
||
+ | :tag( 'span' ) |
||
+ | :css( 'white-space', 'nowrap' ) |
||
+ | :wikitext( '[[#the-code|Przejdź do kodu ↴]]' ) |
||
+ | end |
||
+ | |||
+ | body |
||
+ | :node( header ):done() |
||
+ | :wikitext( message ) |
||
+ | :wikitext( docText ) |
||
+ | |||
+ | if not noDoc and page ~= docPage then |
||
+ | body |
||
+ | :tag( 'div' ) |
||
+ | :addClass( 'documentation-footer' ) |
||
+ | :css{ |
||
+ | margin = '0.7em -1em -0.7em', |
||
+ | ['border-top'] = 'inherit', |
||
+ | padding = '0.8em 1em 0.7em', |
||
+ | clear = 'both' |
||
+ | } |
||
+ | :node( links ) |
||
+ | :wikitext( 'Powyższy opis jest dołączany ze strony [[' .. docPage.fullText .. ']].' ) |
||
+ | end |
||
+ | |||
+ | if category then |
||
+ | body:wikitext( "[[Kategoria:" .. category .. "]]" ) |
||
+ | end |
||
+ | |||
+ | local anchor = '' |
||
+ | if not noDoc and pageType ~= 'template' and pageType ~= 'message' then |
||
+ | anchor = mw.html.create( 'div' ):attr( 'id', 'the-code' ) |
||
+ | end |
||
+ | |||
+ | return tostring( body ) .. tostring( anchor ) |
||
end |
end |
||
+ | |||
return p |
return p |
Aktualna wersja na dzień 11:42, 31 sty 2023
Using in the {{Dokumentacja}}
and {{Dokumentacja/Nagłówek}}
Zależności
local p = {}
local defaultDocPage = 'opis'
local getType = function( namespace, page )
local pageType = 'template'
if namespace == 'Moduł' or namespace == 'Module' then
pageType = 'module'
elseif namespace == 'Widget' then
pageType = 'widget'
elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.css$' ) then
pageType = 'stylesheet'
elseif page.fullText:gsub( '/' .. defaultDocPage .. '$', '' ):find( '%.js$' ) then
pageType = 'script'
elseif namespace == 'MediaWiki' then
pageType = 'message'
end
return pageType
end
local getTypeForms = function( pageType )
if pageType == 'module' then
return {gen = 'tym module', acc = 'tego modułu', pronoun_gen = "его", nomP = 'Moduły'}
elseif pageType == 'widget' then
return {gen = 'tym widżecie', acc = 'tego widżetu', pronoun_gen = "его", nomP = 'Widżety'}
elseif pageType == 'stylesheet' then
return {gen = 'tym arkuszu stylów', acc = 'tego arkusza stylów', pronoun_gen = "еro", nomP = 'Arkusze stylów'}
elseif pageType == 'script' then
return {gen = 'tym skrypcie', acc = 'tego skryptu', pronoun_gen = "его", nomP = 'Skrypty'}
elseif pageType == 'message' then
return {gen = 'tej wiadomości systemowej', acc = 'tej wiadomości systemowej', pronoun_gen = "его", nomP = 'Wiadomości'}
else -- type == 'template'
return {gen = 'tym szablonie', acc = 'tego szablonu', pronoun_gen = "его", nomP = 'Szablony'}
end
end
-- Creating a documentation page or transclution through {{subst:doc}}
function p.create( f )
local args = require( 'Moduł:ProcessArgs' ).norm()
local page = mw.title.getCurrentTitle()
local docPage = args['strona'] or page.nsText .. ':' .. page.baseText .. '/' .. defaultDocPage
local out
if not args["treść"] and tostring( page ) == docPage then
out = f:preprocess( '{{subst:Szablon:Dokumentacja/preload}}' )
else
local templateArgs = {}
for _, key in ipairs{ 'typ', 'strona', 'treść' } do
local val = args[key]
if val then
if key == 'treść' then val = '\n' .. val .. '\n' end
table.insert( templateArgs, key .. '=' .. val )
end
end
out = '{{Dokumentacja|' .. table.concat( templateArgs, '|' ) .. '}}'
out = out:gsub( '|}}', '}}' )
if not args["treść"] then
out = out .. '\n<!-- Kategorie i interwiki umieść na stronie dokumentacji. -->'
end
end
if not mw.isSubsting() then
out = f:preprocess( out )
if not args['niekat'] then
out = out .. '[[Kategoria:Pages with templates requiring substitution]'
end
end
return out
end
-- Header2 on the documentation page
function p.docPage( f )
local args = require( 'Moduł:ProcessArgs' ).merge( true )
local badDoc = args['zladok']
local forceNoDoc = args['brakdok']
local docclass = "documentation-norm"
if badDoc then
docclass = "documentation-bad"
elseif forceNoDoc then
docclass = "documentation-no"
end
if forceNoDoc then
f:callParserFunction( '#dplvar:set', '$doc forced_none', '1' )
end
if f:callParserFunction( '#dplvar', '$doc noheader' ) == '1' then
if badDoc then
f:callParserFunction( '#dplvar:set', '$doc bad', '1' )
end
return
end
local page = mw.title.getCurrentTitle()
local namespace = page.nsText
local pageType = mw.ustring.lower( args['typ'] or getType( namespace, page ) )
local typeForms = getTypeForms( pageType )
local body = mw.html.create( 'div' ):addClass( 'documentation-header' )
body
:css{
['margin-bottom'] = '0.8em',
padding = '0.8em 1em 0.7em',
}
:tag( 'div' )
:css( 'float', 'right' )
:wikitext( '[[', page:fullUrl( 'action=purge' ), ' ' .. f:preprocess('{{lc:{{int:purge}}}}') .. ']]' )
:done()
:wikitext(
'To jest strona dokumentacji, ',
pageType == 'module' and 'będzie ona dołączona' or 'powinna ona być dołączona',
' na stronie głównej. ',
'Aby uzyskać więcej informacji sprawdź [[Szablon:Dokumentacja]].'
)
if badDoc then
body:wikitext( "<br>'''Dokumentacja " .. typeForms.gen .. " wymaga uzupełnienia lub ulepszenia.'''" )
elseif forceNoDoc then
body:wikitext( "<br>'''W " .. typeForms.gen .. " nie ma dokumentacji. Jeśli wiesz jak używać " .. typeForms.acc .. ", udokumentuj to.'''" )
end
if not ( args["niekat"] or namespace == 'Użytkownik' or namespace == 'Użytkowniczka' ) then
body:wikitext( '[[Kategoria:Szablony dokumentacji]]' )
end
return body
end
-- Wrapper around the documentation on the main page
function p.page( f )
-- mw.text.trim uses mw.ustring.gsub, which silently fails on large strings
local function trim( s )
return (s:gsub( '^[\t\r\n\f ]+', '' ):gsub( '[\t\r\n\f ]+$', '' ))
end
local args = require( 'Moduł:ProcessArgs' ).merge( true )
local page = mw.title.getCurrentTitle()
local namespace = page.nsText
local docText = trim( args["treść"] or '' )
if docText == '' then docText = nil end
local docPage
local noDoc
local forceNoDoc
if docText then
docPage = page
else
docPage = mw.title.new( args["strona"] or namespace .. ':' .. page.text .. '/' .. defaultDocPage)
noDoc = args["brakdok"] or not docPage.exists
end
local badDoc = args["zladok"]
local pageType = mw.ustring.lower( args['typ'] or getType( namespace, page ) )
local typeForms = getTypeForms( pageType )
if not docText and not noDoc then
f:callParserFunction( '#dplvar:set', '$doc noheader', '1' )
docText = trim( f:expandTemplate{ title = ':' .. docPage.fullText } )
if f:callParserFunction( '#dplvar', '$doc bad' ) == '1' then
badDoc = 1
end
forceNoDoc = f:callParserFunction( '#dplvar', '$doc forced_none' ) == '1'
if docText == '' and not forceNoDoc then
docText = nil
noDoc = 1
end
end
if docText then
docText = '\n' .. docText .. '\n'
end
local action = f:preprocess('{{lc:{{int:edit}}}}')
local preload = ''
local docclass = "documentation-norm"
local message
local category
if noDoc then
action = f:preprocess('{{lc:{{int:create}}}}')
preload = '&preload=Szablon:Dokumentacja/preload'
docclass = "documentation-no"
message = "'''W " .. typeForms.gen .. " nie ma dokumentacji. " ..
"Jeśli wiesz jak używać " .. typeForms.acc .. ", proszę, podaj odpowiednie informacje.'''"
if not ( args["niekat"] or namespace == 'Użytkownik' or namespace == 'Użytkowniczka' ) then
category = typeForms.nomP .. ' bez dokumentacji'
if not mw.title.new( 'Kategoria:' .. category ).exists then
category = 'Strony bez dokumentacji'
end
end
elseif forceNoDoc then
docclass = "documentation-no"
message = "'''W " .. typeForms.gen .. " nie ma dokumentacji. " ..
"Jeśli wiesz jak używać " .. typeForms.acc .. ", proszę, podaj odpowiednie informacje.'''"
if not ( args["niekat"] or namespace == 'Użytkownik' or namespace == 'Użytkowniczka' ) then
category = typeForms.nomP .. ' bez dokumentacji'
if not mw.title.new( 'Kategoria:' .. category ).exists then
category = 'Strony bez dokumentacji'
end
end
elseif badDoc then
docclass = "documentation-bad"
message = "'''Dokumentacja " .. typeForms.gen .. " wymaga uzupełnienia lub ulepszenia.'''\n"
if not ( args["niekat"] or namespace == 'Użytkownik' or namespace == 'Użytkowniczka' ) then
category = typeForms.nomP .. ' ze złą dokumentacją'
if not mw.title.new( 'Kategoria:' .. category ).exists then
category = 'Strony ze złą dokumentacją'
end
end
end
local historyLink = f:preprocess('{{lc:{{int:history short}}}}')
local purgeLink = f:preprocess('{{lc:{{int:purge}}}}')
local viewLink = f:preprocess('{{lc:{{int:view}}}}')
local links = {
'[' .. docPage:fullUrl( 'action=edit' .. preload ) .. ' ' .. action .. ']',
'[' .. docPage:fullUrl( 'action=history' ) .. ' ' .. historyLink .. ']',
'[' .. page:fullUrl( 'action=purge' ) .. ' ' .. purgeLink .. ']'
}
if not noDoc and page ~= docPage then
table.insert( links, 1, '[[' .. docPage.fullText .. '|' .. viewLink .. ']]' )
end
links = mw.html.create( 'span' )
:css( 'float', 'right' )
:wikitext( mw.text.nowiki( '[ ' ), table.concat( links, ' | ' ), mw.text.nowiki( ' ]' ) )
local body = mw.html.create( 'div' ):addClass( 'documentation ' .. docclass )
body:css{
padding = '0.8em 1em 0.7em',
['margin-top'] = '1em',
clear = 'both'
}
local header = mw.html.create( 'div' )
:addClass( 'documentation-header' )
:css{
margin = '-0.8em -1em 0.8em',
padding = '0.8em 1em 0.7em',
['border-bottom'] = 'inherit'
}
header
:node( links )
:tag( 'span' )
:css{
['font-weight'] = 'bold',
['font-size'] = '130%',
['margin-right'] = '1em',
['line-height'] = '1'
}
:wikitext( 'Dokumentacja' )
if not noDoc and pageType ~= 'template' and pageType ~= 'message' then
header
:tag( 'span' )
:css( 'white-space', 'nowrap' )
:wikitext( '[[#the-code|Przejdź do kodu ↴]]' )
end
body
:node( header ):done()
:wikitext( message )
:wikitext( docText )
if not noDoc and page ~= docPage then
body
:tag( 'div' )
:addClass( 'documentation-footer' )
:css{
margin = '0.7em -1em -0.7em',
['border-top'] = 'inherit',
padding = '0.8em 1em 0.7em',
clear = 'both'
}
:node( links )
:wikitext( 'Powyższy opis jest dołączany ze strony [[' .. docPage.fullText .. ']].' )
end
if category then
body:wikitext( "[[Kategoria:" .. category .. "]]" )
end
local anchor = ''
if not noDoc and pageType ~= 'template' and pageType ~= 'message' then
anchor = mw.html.create( 'div' ):attr( 'id', 'the-code' )
end
return tostring( body ) .. tostring( anchor )
end
return p