Extension: লুপ ফাংশন
মুক্তির অবস্থা: স্থিতিশীল |
|
|---|---|
| বাস্তবায়ন | পার্সার ফাংশন |
| বিবরণ | উইকিটেক্সটে সীমিত লুপিং কার্যকারিতা প্রদান করে |
| লেখক(গণ) | |
| সর্বশেষ সংস্করণ | 2020-03-26 |
| MediaWiki | 1.35+ |
| PHP | 5.3+ |
| ডাটাবেজ পরিবর্তন | না |
| Licence | গ্নু জেনারেল পাবলিক লাইসেন্স ২.০ অথবা পরবর্তী |
| ডাউনলোড | |
| ট্রানশলেটউইকি.নেট-এ উপলভ্য থাকলে LoopFunctions বর্ধনাংশটি অনুবাদ করুন | |
LoopFunctions এক্সটেনশনটি উইকিটেক্সটে সীমিত লুপিং কার্যকারিতা সক্ষম করবে, যেখানে একটি পরিবর্তনশীল (ডিফল্ট 2 দ্বারা) লুপের বর্তমান পুনরাবৃত্তি নম্বর দ্বারা প্রতিস্থাপিত হয়। পরিবর্তনশীল একটি সাধারণ পাঠ্য বা লিঙ্কে ব্যবহার করা যেতে পারে। এছাড়াও পুরো লুপের ফলাফল একটি অভিব্যক্তিতে রাখা যেতে পারে, উদাহরণস্বরূপ একটি ফ্যাক্টোরিয়াল গণনা করতে। তবে, লুপের বডি বা মূল অংশটি ভেরিয়েবলটি প্রতিস্থাপনের আগেই মূল্যায়িত হয়ে যায়; ফলে লুপের ভেতরে ভেরিয়েবলের মানের ওপর ভিত্তি করে কোনো গণনা করা সম্ভব হয় না।
মূল ক্রিয়াকলাপ
#for
{{#for: n | text }}
যেখানে n হল পুনরাবৃত্তির গণনা এবং পাঠ্যটি হল পুনরাবৃত্তি করা পাঠ্য।
{{#for: n | text | প্রতিস্থাপন পরামিতি }}
If, after expansion of templates, parser functions, and variables, the text contains the text $n$ or what is defined by the third parameter, that will be replaced by the current iteration, starting with 1.
Watch out for gaps, because code {{#for: 3 |string}} generates stringstringstring
|
Using in templates
Calling the template {{foo | n=4 | list1=a | list3=c | list4=d }}, if template foo containing: {{#for: {{{n}}} | {{{list$n$}}}<br/>}}, will result in the wikitext: a<br/>b<br/>c<br/>d<br/>
Using for calculations
Sum of squares 1^2 through 5^2: {{#expr:{{#for:5|+$n$*$n$}}}} gives 55
Factorial 6 (6!): {{#expr:1{{#for:6|*$n$}}}} gives 720
{{#expr:{{for|call=plus square|pv=1|1|2|3|4|5}}}} gives 55; For a list of squares it seems that we can only use for, not #for.Limitation
In the loop body, templates, parser functions, and variables are expanded before replacing the index variable by its values, i.e.:
- Parameter of a parser function depending on the index variable
- Code
{{#for:3|{{lc:Ab$n$}}}}givesab1ab2ab3; the result is in this case the same as when the repetition was done first, and then the evaluation of each item.
- Code
- Code
{{#for:3|{{uc:Ab$n$}}}}givesAB$N$AB$N$AB$N$; the result is in this case not the same, because$n$is changed to$N$, and therefore not treated as index variable.
- Code
- Applying #expr to an expression containing the index variable does not work: expansion of #expr in e.g.
{{#expr:2*$n$}}gives the text so this text will be repeated:Expression error: Unrecognised punctuation character "$"
- Applying #expr to an expression containing the index variable does not work: expansion of #expr in e.g.
- Template name depending on the index variable
- Code
{{#for:3|{{a$n$}}}}gives:- if the template with the literal name
Template:a$n$does not exist: Template:a1 Template:a2 Template:a3 (the loop body is evaluated as Template:a$n$, after which the loop function repeats that, substituting$n$).
- if the template with the literal name
- Code
- if the template with the literal name
Template:a$n$does exist: the result of{{a*$n$}}{{a*$n$}}{{a*$n$}}, i.e., the content is repeated unchanged.
- if the template with the literal name
- Limitation in combination with Extension:Variables
- Within the loop a variable can be assigned a value depending on the loop variable, and the value of this variable can be retrieved.
- However, it seems that within the loop the variable cannot be assigned a new value depending on its own current value. Instead the value on entering the loop is taken.
#foreach
Function only for template use.
{{#foreach: mask | text }}
{{#foreach: mask | text | replacement parameter }}
The mask is a string in the format prefix$n$suffix where $n$ can be changed via the replacement parameter.
The function #foreach, called inside a template, will produce the text for $n$ = 1, 2, 3,... as long as prefix$n$suffix is a template parameter defined in the template call.
If the text contains the text $n$ or what is defined by the third parameter, that will be replaced by the current value of $n$.
It seems that the whole call of #foreach is ignored if the loop body contains a template call or a parser function call, or if the loop body does not contain {{{$n$}}}.
Example
Calling the template {{foo | foo2_bar=a | foo1_bar=b | a=12 | 6 | foo4_bar=c }} using the template foo, containing: {{#foreach: foo$n$_bar | foo$n$_bar = {{{foo$n$_bar}}}<br/>}} will result in the expanded wikitext foo1_bar = b<br/>foo2_bar = a<br/> and hence the output:
- foo1_bar = b
- foo2_bar = a
Since foo3_bar is not defined, foo4_bar is not listed either; neither are a and 1, the parameter names which exist but do not match the pattern.
Using without prefix or suffix
The code {{showpars | abc | de | w=fgh | ijk}} call Template:Showpars containing {{#foreach: $n$ | $n$ = {{{$n$}}}<br/>}} and gives:
- 1 = abc
- 2 = de
- 3 = ijk
Content of a template that links to the pages given by the values of the unnamed parameters:
{{#foreach:$n$|[[{{{$n$}}}]]<nowiki> </nowiki>}}
Installation
- ডাউনলোড করুন এবং আপনার
extensions/ফোল্ডারেরLoopFunctionsনামক ডিরেক্টরিতে ফাইল(গুলি) নিন।
Developers and code contributors should install the extension from Git instead, using:cd extensions/ git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/LoopFunctions
- আপনার LocalSettings.php-এর নিচের অংশে নিম্নলিখিত কোড যোগ করুন:
wfLoadExtension( 'LoopFunctions' );
করা হয়েছে – এক্সটেনশনটি সফলভাবে ইনস্টল করা হয়েছে কিনা তা যাচাই করতে আপনার উইকির Special:Version-এ যান।
