r41194 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41193‎ | r41194 | r41195 >
Date:14:32, 23 September 2008
Author:yaron
Status:old
Tags:
Comment:
'new_value' renamed to 'formula', sfRenderArrayMapObj() parsing of arguments fixed
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php
@@ -50,12 +50,12 @@
5151 *
5252 * 'arraymap' is called as:
5353 *
54 - * {{#arraymap:value|delimiter|var|new_value|new_delimiter}}
 54+ * {{#arraymap:value|delimiter|var|formula|new_delimiter}}
5555 *
5656 * This function applies the same transformation to every section of a
5757 * delimited string; each such section, as dictated by the 'delimiter'
5858 * value, is given the same transformation that the 'var' string is
59 - * given in 'new_value'. Finally, the transformed strings are joined
 59+ * given in 'formula'. Finally, the transformed strings are joined
6060 * together using the 'new_delimiter' string. Both 'delimiter' and
6161 * 'new_delimiter' default to commas.
6262 *
@@ -86,6 +86,7 @@
8787 * @author Yaron Koren
8888 * @author Sergey Chernyshev
8989 * @author Daniel Friesen
 90+ * @author Barry Welch
9091 */
9192
9293
@@ -178,9 +179,9 @@
179180 }
180181
181182 /**
182 - * {{#arraymap:value|delimiter|var|new_value|new_delimiter}}
 183+ * {{#arraymap:value|delimiter|var|formula|new_delimiter}}
183184 */
184 -function sfRenderArrayMap( &$parser, $value = '', $delimiter = ',', $var = 'x', $new_value = 'x', $new_delimiter = ', ' ) {
 185+function sfRenderArrayMap( &$parser, $value = '', $delimiter = ',', $var = 'x', $formula = 'x', $new_delimiter = ', ' ) {
185186 $values_array = explode($parser->mStripState->unstripNoWiki($delimiter), $value);
186187 $results = array();
187188 foreach ($values_array as $cur_value) {
@@ -188,7 +189,7 @@
189190 // ignore a value if it's null
190191 if ('' != $cur_value) {
191192 // remove whitespaces
192 - $results[] = str_replace($var, $cur_value, $new_value);
 193+ $results[] = str_replace($var, $cur_value, $formula);
193194 }
194195 }
195196 return implode($new_delimiter, $results);
@@ -196,20 +197,15 @@
197198
198199 /**
199200 * SFH_OBJ_ARGS
200 - * {{#arraymap:value|delimiter|var|new_value|new_delimiter}}
 201+ * {{#arraymap:value|delimiter|var|formula|new_delimiter}}
201202 */
202203 function sfRenderArrayMapObj( &$parser, $frame, $args ) {
203204 # Set variables
204 - $value = isset($args[0]) ? $args[0] : '';
205 - $delimiter = isset($args[1]) ? $args[1] : ',';
206 - $var = isset($args[2]) ? $args[2] : 'x';
207 - $new_value = isset($args[3]) ? $args[3] : 'x';
208 - $new_delimiter = isset($args[4]) ? $args[4] : ', ';
209 - # Expand some
210 - $value = trim($frame->expand($value));
211 - $delimiter = trim($frame->expand($delimiter));
212 - $var = trim($frame->expand($var, PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES));
213 - $new_delimiter = trim($frame->expand($new_delimiter));
 205+ $value = isset($args[0]) ? trim($frame->expand($args[0])) : '';
 206+ $delimiter = isset($args[1]) ? trim($frame->expand($args[1])) : ',';
 207+ $var = isset($args[2]) ? trim($frame->expand($args[2])) : 'x';
 208+ $formula = isset($args[3]) ? trim($frame->expand($args[3])) : 'x';
 209+ $new_delimiter = isset($args[4]) ? trim($frame->expand($args[4])) : ', ';
214210 # Unstrip some
215211 $delimiter = $parser->mStripState->unstripNoWiki($delimiter);
216212
@@ -218,7 +214,7 @@
219215 foreach( $values_array as $old_value ) {
220216 $old_value = trim($old_value);
221217 if( $old_value == '' ) continue;
222 - $result_value = $frame->expand($new_value, PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES);
 218+ $result_value = $frame->expand($formula, PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES);
223219 $result_value = str_replace($var, $old_value, $result_value);
224220 $result_value = $parser->preprocessToDom($result_value, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0);
225221 $results_array[] = trim($frame->expand($result_value));

Status & tagging log