Jump to content
Wikipedia The Free Encyclopedia

Module:IncrementParams

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
This module is rated as alpha. It is ready for limited use and third-party feedback. It may be used on a small number of pages, but should be monitored closely. Suggestions for new features or adjustments to input and output are welcome.

This module increments numbered template parameters. This is useful for inserting new rows into infobox templates, and for other similar tasks where renaming many parameters by hand would be tedious.

Usage

[edit ]

Due to the way templates work, you cannot pass template input to this module in the normal way. Instead, you have to edit the module page directly to get the desired result. Please follow the seven steps listed in the module code.

Once you have finished editing the module, you can use it on any page, with the code:

{{subst:#invoke:IncrementParams|main}}

You can also view it as pre-formatted text using the pre parameter. Warning - this doesn't work with subst.

{{#invoke:IncrementParams|main|pre=yes}}

Or you can simply copy and paste the code from the following section.

Output

[edit ]

The module currently outputs the following text:

|header4 = Section 1
|label6 = Label A
|data6 = Data A
|label8 = Label C
|data8 = Data C
|header11 = Section 2
|label13 = Label D
|data13 = Data D

See also

[edit ]
The above documentation is transcluded from Module:IncrementParams/doc. (edit | history)
Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.

 -- 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. 
 localincrement=1

 -- STEP 3: Replace the example template text with the template text that you wish to increment.
 localtemplatetext=[==========[
 |header3 = Section 1
 |label5 = Label A
 |data5 = Data A
 |label7 = Label C
 |data7 = Data C
 |header10 = Section 2
 |label12 = Label D
 |data12 = Data D
 ]==========]

 -- 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!

 localp={}

 localfunctionreplace(prefix,num,suffix)
 return'|'..prefix..tostring(tonumber(num)+increment)..suffix..'='
 end

 functionp.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.
 ifframeandframe.argsandframe.args.preandframe.args.pre~=''then
 templatetext=mw.text.nowiki(templatetext)
 templatetext='<pre style="white-space:pre-wrap; word-wrap:break-word;">'
 ..templatetext..'</pre>'
 end
 returntemplatetext
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /