Index: trunk/extensions/SemanticForms/includes/SF_AutoeditAPI.php |
— | — | @@ -320,7 +320,7 @@ |
321 | 321 | self::addToArray( $data, "wpSave", "Save" ); |
322 | 322 | } |
323 | 323 | // and modify as specified |
324 | | - $data = $this->array_merge_recursive_distinct( $data, $this->mOptions ); |
| 324 | + $data = SFUtils::array_merge_recursive_distinct( $data, $this->mOptions ); |
325 | 325 | |
326 | 326 | //////////////////////////////////////////////////////////////////////// |
327 | 327 | // Store the modified form |
— | — | @@ -518,40 +518,6 @@ |
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
522 | | - * array_merge_recursive merges arrays, but it converts values with duplicate |
523 | | - * keys to arrays rather than overwriting the value in the first array with the duplicate |
524 | | - * value in the second array, as array_merge does. |
525 | | - * |
526 | | - * array_merge_recursive_distinct does not change the datatypes of the values in the arrays. |
527 | | - * Matching keys' values in the second array overwrite those in the first array. |
528 | | - * |
529 | | - * Parameters are passed by reference, though only for performance reasons. They're not |
530 | | - * altered by this function. |
531 | | - * |
532 | | - * See http://www.php.net/manual/en/function.array-merge-recursive.php#92195 |
533 | | - * |
534 | | - * @param array $array1 |
535 | | - * @param array $array2 |
536 | | - * @return array |
537 | | - * @author Daniel <daniel (at) danielsmedegaardbuus (dot) dk> |
538 | | - * @author Gabriel Sobrinho <gabriel (dot) sobrinho (at) gmail (dot) com> |
539 | | - */ |
540 | | - private function array_merge_recursive_distinct( array &$array1, array &$array2 ) { |
541 | | - |
542 | | - $merged = $array1; |
543 | | - |
544 | | - foreach ( $array2 as $key => &$value ) { |
545 | | - if ( is_array( $value ) && isset( $merged[$key] ) && is_array( $merged[$key] ) ) { |
546 | | - $merged[$key] = $this->array_merge_recursive_distinct( $merged[$key], $value ); |
547 | | - } else { |
548 | | - $merged[$key] = $value; |
549 | | - } |
550 | | - } |
551 | | - |
552 | | - return $merged; |
553 | | - } |
554 | | - |
555 | | - /** |
556 | 522 | * Set HTTP error header and add error message to the ApiResult |
557 | 523 | * @param String $msg |
558 | 524 | */ |
Index: trunk/extensions/SemanticForms/includes/SF_FormUtils.php |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | } |
44 | 44 | |
45 | 45 | static function hiddenFieldHTML( $input_name, $cur_value ) { |
46 | | - return "\t" . Html::hidden( $input_name, $cur_value ) . "\n"; |
| 46 | + return Html::hidden( $input_name, $cur_value ); |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
Index: trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php |
— | — | @@ -172,6 +172,7 @@ |
173 | 173 | array_shift( $params ); // don't need the parser |
174 | 174 | // set defaults |
175 | 175 | $inFormName = $inValue = $inButtonStr = $inQueryStr = ''; |
| 176 | + $inQueryArr = array(); |
176 | 177 | $inAutocompletionSource = ''; |
177 | 178 | $inRemoteAutocompletion = false; |
178 | 179 | $inSize = 25; |
— | — | @@ -179,12 +180,20 @@ |
180 | 181 | // assign params - support unlabelled params, for backwards compatibility |
181 | 182 | foreach ( $params as $i => $param ) { |
182 | 183 | $elements = explode( '=', $param, 2 ); |
183 | | - $param_name = null; |
184 | | - $value = trim( $param ); |
| 184 | + |
| 185 | + // set param_name and value |
185 | 186 | if ( count( $elements ) > 1 ) { |
186 | 187 | $param_name = trim( $elements[0] ); |
| 188 | + |
| 189 | + // parse (and sanitize) parameter values |
187 | 190 | $value = trim( $parser->recursiveTagParse( $elements[1] ) ); |
| 191 | + } else { |
| 192 | + $param_name = null; |
| 193 | + |
| 194 | + // parse (and sanitize) parameter values |
| 195 | + $value = trim( $parser->recursiveTagParse( $param ) ); |
188 | 196 | } |
| 197 | + |
189 | 198 | if ( $param_name == 'form' ) |
190 | 199 | $inFormName = $value; |
191 | 200 | elseif ( $param_name == 'size' ) |
— | — | @@ -193,9 +202,15 @@ |
194 | 203 | $inValue = $value; |
195 | 204 | elseif ( $param_name == 'button text' ) |
196 | 205 | $inButtonStr = $value; |
197 | | - elseif ( $param_name == 'query string' ) |
198 | | - $inQueryStr = $value; |
199 | | - elseif ( $param_name == 'autocomplete on category' ) { |
| 206 | + elseif ( $param_name == 'query string' ) { |
| 207 | + // Change HTML-encoded ampersands directly to |
| 208 | + // URL-encoded ampersands, so that the string |
| 209 | + // doesn't get split up on the '&'. |
| 210 | + $inQueryStr = str_replace( '&', '%26', $value ); |
| 211 | + |
| 212 | + parse_str($inQueryStr, $arr); |
| 213 | + $inQueryArr = SFUtils::array_merge_recursive_distinct( $inQueryArr, $arr ); |
| 214 | + } elseif ( $param_name == 'autocomplete on category' ) { |
200 | 215 | $inAutocompletionSource = $value; |
201 | 216 | $autocompletion_type = 'category'; |
202 | 217 | } elseif ( $param_name == 'autocomplete on namespace' ) { |
— | — | @@ -206,17 +221,29 @@ |
207 | 222 | } elseif ( $param_name == null && $value == 'popup' ) { |
208 | 223 | self::loadScriptsForPopupForm( $parser ); |
209 | 224 | $classStr = 'popupforminput'; |
| 225 | + } elseif ( $param_name !== null ) { |
| 226 | + |
| 227 | + $value = urlencode($value); |
| 228 | + parse_str("$param_name=$value", $arr); |
| 229 | + $inQueryArr = SFUtils::array_merge_recursive_distinct( $inQueryArr, $arr ); |
| 230 | + |
| 231 | + } elseif ( $i == 0 ) { |
| 232 | + $inFormName = $value; |
| 233 | + } elseif ( $i == 1 ) { |
| 234 | + $inSize = $value; |
| 235 | + } elseif ( $i == 2 ) { |
| 236 | + $inValue = $value; |
| 237 | + } elseif ( $i == 3 ) { |
| 238 | + $inButtonStr = $value; |
| 239 | + } elseif ( $i == 4 ) { |
| 240 | + // Change HTML-encoded ampersands directly to |
| 241 | + // URL-encoded ampersands, so that the string |
| 242 | + // doesn't get split up on the '&'. |
| 243 | + $inQueryStr = str_replace( '&', '%26', $value ); |
| 244 | + |
| 245 | + parse_str($inQueryStr, $arr); |
| 246 | + $inQueryArr = SFUtils::array_merge_recursive_distinct( $inQueryArr, $arr ); |
210 | 247 | } |
211 | | - elseif ( $i == 0 ) |
212 | | - $inFormName = $param; |
213 | | - elseif ( $i == 1 ) |
214 | | - $inSize = $param; |
215 | | - elseif ( $i == 2 ) |
216 | | - $inValue = $param; |
217 | | - elseif ( $i == 3 ) |
218 | | - $inButtonStr = $param; |
219 | | - elseif ( $i == 4 ) |
220 | | - $inQueryStr = $param; |
221 | 248 | } |
222 | 249 | |
223 | 250 | $fs = SFUtils::getSpecialPage( 'FormStart' ); |
— | — | @@ -274,22 +301,21 @@ |
275 | 302 | } else { |
276 | 303 | $str .= SFFormUtils::hiddenFieldHTML( "form", $inFormName ); |
277 | 304 | } |
278 | | - // Recreate the passed-in query string as a set of hidden |
279 | | - // variables. |
280 | | - // Change HTML-encoded ampersands to URL-encoded ampersands, so |
281 | | - // that the string doesn't get split up on the '&'. |
282 | | - $inQueryStr = str_replace( '&', '%26', $inQueryStr ); |
283 | | - $query_components = explode( '&', $inQueryStr ); |
284 | | - foreach ( $query_components as $component ) { |
285 | | - // change URL-encoded ampersands back |
286 | | - $component = str_replace( '%26', '&', $component ); |
287 | | - $subcomponents = explode( '=', $component, 2 ); |
288 | | - $key = ( isset( $subcomponents[0] ) ) ? $subcomponents[0] : ''; |
289 | | - $val = ( isset( $subcomponents[1] ) ) ? $subcomponents[1] : ''; |
290 | | - if ( ! empty( $key ) ) { |
291 | | - $str .= "\t\t\t" . Html::hidden( $key, $val ) . "\n"; |
| 305 | + |
| 306 | + // Recreate the passed-in query string as a set of hidden variables. |
| 307 | + if ( !empty( $inQueryArr ) ) { |
| 308 | + // query string has to be turned into hidden inputs. |
| 309 | + |
| 310 | + $query_components = explode( '&', http_build_query( $inQueryArr, '', '&' ) ); |
| 311 | + |
| 312 | + foreach ( $query_components as $query_component ) { |
| 313 | + $var_and_val = explode( '=', $query_component, 2 ); |
| 314 | + if ( count( $var_and_val ) == 2 ) { |
| 315 | + $str .= SFFormUtils::hiddenFieldHTML( urldecode( $var_and_val[0] ), urldecode( $var_and_val[1] ) ); |
| 316 | + } |
292 | 317 | } |
293 | 318 | } |
| 319 | + |
294 | 320 | $button_str = ( $inButtonStr != '' ) ? $inButtonStr : wfMsg( 'sf_formstart_createoredit' ); |
295 | 321 | $str .= <<<END |
296 | 322 | <input type="submit" value="$button_str" /></p> |
— | — | @@ -461,6 +487,7 @@ |
462 | 488 | $linkType = 'span'; |
463 | 489 | $summary = null; |
464 | 490 | $classString = 'autoedit-trigger'; |
| 491 | + $inQueryArr = array(); |
465 | 492 | |
466 | 493 | // parse parameters |
467 | 494 | $params = func_get_args(); |
— | — | @@ -486,16 +513,38 @@ |
487 | 514 | case 'summary': |
488 | 515 | $summary = $parser->recursiveTagParse( $value ); |
489 | 516 | break; |
| 517 | + case 'query string' : |
| 518 | + |
| 519 | + // Change HTML-encoded ampersands directly to |
| 520 | + // URL-encoded ampersands, so that the string |
| 521 | + // doesn't get split up on the '&'. |
| 522 | + $inQueryStr = str_replace( '&', '%26', $value ); |
| 523 | + |
| 524 | + parse_str( $inQueryStr, $arr ); |
| 525 | + $inQueryArr = SFUtils::array_merge_recursive_distinct( $inQueryArr, $arr ); |
| 526 | + break; |
| 527 | + |
490 | 528 | default : |
491 | | - // The decode-encode sequence allows users to pass wikitext |
492 | | - // to the target form without having it parsed right away. |
493 | | - // To do that they need to use htmlentities instead of |
494 | | - // braces and brackets |
495 | | - $formcontent .= |
496 | | - Html::hidden( $key, Sanitizer::decodeCharReferences( $value ) ); |
| 529 | + |
| 530 | + $value = urlencode( $parser->recursiveTagParse( $value ) ); |
| 531 | + parse_str( "$key=$value", $arr ); |
| 532 | + $inQueryArr = SFUtils::array_merge_recursive_distinct( $inQueryArr, $arr ); |
497 | 533 | } |
498 | 534 | } |
499 | 535 | |
| 536 | + // query string has to be turned into hidden inputs. |
| 537 | + if ( !empty( $inQueryArr ) ) { |
| 538 | + |
| 539 | + $query_components = explode( '&', http_build_query( $inQueryArr, '', '&' ) ); |
| 540 | + |
| 541 | + foreach ( $query_components as $query_component ) { |
| 542 | + $var_and_val = explode( '=', $query_component, 2 ); |
| 543 | + if ( count( $var_and_val ) == 2 ) { |
| 544 | + $formcontent .= Html::hidden( urldecode( $var_and_val[0] ), urldecode( $var_and_val[1] ) ); |
| 545 | + } |
| 546 | + } |
| 547 | + } |
| 548 | + |
500 | 549 | if ( $linkString == null ) return null; |
501 | 550 | |
502 | 551 | if ( $linkType == 'button' ) { |
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -927,9 +927,8 @@ |
928 | 928 | // doesn't get split up on the '&'. |
929 | 929 | $inQueryStr = str_replace( '&', '%26', $value ); |
930 | 930 | |
931 | | - $inQueryStr = Sanitizer::decodeCharReferences( $inQueryStr ); |
932 | 931 | parse_str($inQueryStr, $arr); |
933 | | - $inQueryArr = array_merge_recursive( $inQueryArr, $arr ); |
| 932 | + $inQueryArr = self::array_merge_recursive_distinct( $inQueryArr, $arr ); |
934 | 933 | } elseif ( $param_name == 'tooltip' ) { |
935 | 934 | $inTooltip = Sanitizer::decodeCharReferences( $value ); |
936 | 935 | } elseif ( $param_name == 'target' ) { |
— | — | @@ -940,7 +939,7 @@ |
941 | 940 | } elseif ( $param_name !== null ) { |
942 | 941 | $value = urlencode($value); |
943 | 942 | parse_str("$param_name=$value", $arr); |
944 | | - $inQueryArr = array_merge_recursive( $inQueryArr, $arr ); |
| 943 | + $inQueryArr = self::array_merge_recursive_distinct( $inQueryArr, $arr ); |
945 | 944 | }elseif ( $i == 0 ) { |
946 | 945 | $inFormName = $value; |
947 | 946 | } elseif ( $i == 1 ) { |
— | — | @@ -953,9 +952,8 @@ |
954 | 953 | // doesn't get split up on the '&'. |
955 | 954 | $inQueryStr = str_replace( '&', '%26', $value ); |
956 | 955 | |
957 | | - $inQueryStr = Sanitizer::decodeCharReferences( $inQueryStr ); |
958 | 956 | parse_str($inQueryStr, $arr); |
959 | | - $inQueryArr = array_merge_recursive( $inQueryArr, $arr ); |
| 957 | + $inQueryArr = self::array_merge_recursive_distinct( $inQueryArr, $arr ); |
960 | 958 | } |
961 | 959 | } |
962 | 960 | |
— | — | @@ -974,10 +972,9 @@ |
975 | 973 | $query_components = explode( '&', http_build_query( $inQueryArr, '', '&' ) ); |
976 | 974 | |
977 | 975 | foreach ( $query_components as $query_component ) { |
978 | | - $query_component = urldecode( $query_component ); |
979 | 976 | $var_and_val = explode( '=', $query_component, 2 ); |
980 | 977 | if ( count( $var_and_val ) == 2 ) { |
981 | | - $hidden_inputs .= SFFormUtils::hiddenFieldHTML( $var_and_val[0], $var_and_val[1] ); |
| 978 | + $hidden_inputs .= SFFormUtils::hiddenFieldHTML( urldecode( $var_and_val[0] ), urldecode( $var_and_val[1] ) ); |
982 | 979 | } |
983 | 980 | } |
984 | 981 | } else { |
— | — | @@ -1044,4 +1041,40 @@ |
1045 | 1042 | |
1046 | 1043 | return true; |
1047 | 1044 | } |
| 1045 | + |
| 1046 | + /** |
| 1047 | + * array_merge_recursive merges arrays, but it converts values with duplicate |
| 1048 | + * keys to arrays rather than overwriting the value in the first array with the duplicate |
| 1049 | + * value in the second array, as array_merge does. |
| 1050 | + * |
| 1051 | + * array_merge_recursive_distinct does not change the datatypes of the values in the arrays. |
| 1052 | + * Matching keys' values in the second array overwrite those in the first array. |
| 1053 | + * |
| 1054 | + * Parameters are passed by reference, though only for performance reasons. They're not |
| 1055 | + * altered by this function. |
| 1056 | + * |
| 1057 | + * See http://www.php.net/manual/en/function.array-merge-recursive.php#92195 |
| 1058 | + * |
| 1059 | + * @param array $array1 |
| 1060 | + * @param array $array2 |
| 1061 | + * @return array |
| 1062 | + * @author Daniel <daniel (at) danielsmedegaardbuus (dot) dk> |
| 1063 | + * @author Gabriel Sobrinho <gabriel (dot) sobrinho (at) gmail (dot) com> |
| 1064 | + */ |
| 1065 | + public static function array_merge_recursive_distinct( array &$array1, array &$array2 ) { |
| 1066 | + |
| 1067 | + $merged = $array1; |
| 1068 | + |
| 1069 | + foreach ( $array2 as $key => &$value ) { |
| 1070 | + if ( is_array( $value ) && isset( $merged[$key] ) && is_array( $merged[$key] ) ) { |
| 1071 | + $merged[$key] = self::array_merge_recursive_distinct( $merged[$key], $value ); |
| 1072 | + } else { |
| 1073 | + $merged[$key] = $value; |
| 1074 | + } |
| 1075 | + } |
| 1076 | + |
| 1077 | + return $merged; |
| 1078 | + } |
| 1079 | + |
| 1080 | + |
1048 | 1081 | } |