Modiwl:IncrementParams

Oddi ar Wicipedia
Jump to navigation Jump to search

Documentation for this module may be created at Modiwl:IncrementParams/doc

-- STEP 1: Click on the "edit" tab at the top of the page to edit this module.

-- STEP 2: if you want to increment by a number other than 1, put that number below, after the equals sign. 
local increment = 10

-- STEP 3: Replace the example template text with the template text that you wish to increment.
local templatetext = [==========[
| label17  = Estil de telescopi
| data17   = {{{estil|}}}

| label18 = [[Longitud d'ona]]
| data18  = {{#invoke:Wikidata | claim | property=P2808 |value={{{longitud d'ona|{{{longitud_ona|}}}}}} |item={{{item|}}}  }}

| label19 = Diàmetre
| data19  = {{#invoke:Wikidata | claim | property=P2386 |value={{{diametre|{{{diàmetre|}}}}}}  | formatting=unitcode |item={{{item|}}}  }}

| label20 = Àrea de recol·lecció
| data20  = {{#invoke:Wikidata | claim | property=P2046 |value={{{superficie|{{{àrea|}}}}}} | formatting=unitcode |item={{{item|}}}  }}

| label21 = [[Distància focal]]
| data21  = {{#invoke:Wikidata | claim | property=P2151 |value={{{distancia_focal|{{{distància_focal|}}}}}} | formatting=unitcode |item={{{item|}}}  }}

| header22 = {{#if:{{{instrument_1_nom|}}}|Instruments}}

| label23  = {{{instrument_1_nom|}}}
| data23   = {{{instrument_1_characteristiques|}}}
| label24  = {{{instrument_2_nom|}}}
| data24   = {{{instrument_2_characteristiques|}}}
| label25  = {{{instrument_3_nom|}}}
| data25   = {{{instrument_3_characteristiques|}}}
| label26  = {{{instrument_4_nom|}}}
| data26   = {{{instrument_4_characteristiques|}}}
| label27  = {{{instrument_5_nom|}}}
| data27   = {{{instrument_5_characteristiques|}}}
| label28  = {{{instrument_6_nom|}}}
| data28   = {{{instrument_6_characteristiques|}}}
| label29  = {{{instrument_7_nom|}}}
| data29   = {{{instrument_7_characteristiques|}}}
| label30  = {{{instrument_8_nom|}}}
| data30   = {{{instrument_8_characteristiques|}}}
| label31  = {{{instrument_9_nom|}}}
| data31   = {{{instrument_9_characteristiques|}}}
| label32  = {{{instrument_10_nom|}}}
| data32   = {{{instrument_10_characteristiques|}}}
| label33  = {{{instrument_11_nom|}}}
| data33   = {{{instrument_11_characteristiques|}}}
| label34  = {{{instrument_12_nom|}}}
| data34   = {{{instrument_12_characteristiques|}}}


]==========]

-- STEP 4: Save this module.

-- STEP 5: You can now output the incremented text with the following code:
--                {{subst:#invoke:IncrementParams|main}}
-- Or you can simply copy and paste the text from this module's documentation.

-- STEP 6: Check the output! In rare cases this module might produce false positives.
-- For example, it will change the text "[[Some link|foo3=bar]]" to "[[Some link|foo4=bar]]".
-- You can use the "show changes" function in the edit window of the template you are editing
-- to find any false positives.

-- STEP 7: When you are finished, undo your changes to this page, so that the next person
-- won't be confused by seeing any non-default values. Thanks for using this module!

local p = {}
 
local function replace(prefix, num, suffix)
    return '|' .. prefix .. tostring(tonumber(num) + increment) .. suffix .. '='
end
 
function p.main(frame)
    -- Increment the template text.
    templatetext = mw.ustring.gsub(templatetext, '|(%s*%a?[%a_%-]-%s*)([1-9]%d*)(%s*[%a_%-]-%a?%s*)=', replace)
    -- Add pre tags and escape html etc. if the pre option is set.
    if frame and frame.args and frame.args.pre and frame.args.pre ~= '' then
        templatetext = mw.text.nowiki(templatetext)
        templatetext = '<pre style="white-space:-moz-pre-wrap; white-space:-pre-wrap; '
            .. 'white-space:-o-pre-wrap; white-space:pre-wrap; word-wrap:break-word;">' 
            .. templatetext .. '</pre>'
    end
    return templatetext
end
 
return p