Index: trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php |
— | — | @@ -97,6 +97,7 @@ |
98 | 98 | * @author Sergey Chernyshev |
99 | 99 | * @author Daniel Friesen |
100 | 100 | * @author Barry Welch |
| 101 | + * @author Christoph Burgmer |
101 | 102 | */ |
102 | 103 | |
103 | 104 | class SFParserFunctions { |
— | — | @@ -192,7 +193,7 @@ |
193 | 194 | $link_url = str_replace( "'", "\'", $link_url ); |
194 | 195 | $str = "<form><input type=\"button\" value=\"$inLinkStr\" onclick=\"window.location.href='$link_url'\"></form>"; |
195 | 196 | } elseif ( $inLinkType == 'post button' ) { |
196 | | - $str = "<form action=\"$link_url\" method=\"post\"><input type=\"submit\" value=\"$inLinkStr\">$hidden_inputs</form>"; |
| 197 | + $str = "<form action=\"$link_url\" method=\"post\"><input type=\"submit\" value=\"$inLinkStr\" />$hidden_inputs</form>"; |
197 | 198 | } else { |
198 | 199 | $str = "<a href=\"$link_url\">$inLinkStr</a>"; |
199 | 200 | } |
— | — | @@ -283,20 +284,13 @@ |
284 | 285 | |
285 | 286 | END; |
286 | 287 | } else { |
287 | | - // if there's autocompletion, we need to place it in |
288 | | - // a table so that the autocompletion <div> won't lead |
289 | | - // to the button being on a separate line (this can |
290 | | - // probably be done just with CSS instead, but I don't |
291 | | - // know how) |
292 | 288 | $str = <<<END |
293 | 289 | <form name="createbox" action="$fs_url" method="get"> |
294 | | - <table><tr><td><input type="text" name="page_name" id="input_$input_num" size="$inSize" value="$inValue" class="autocompleteInput createboxInput" /> |
295 | | - <div class="page_name_auto_complete" id="div_$input_num"></div> |
296 | | - </td> |
| 290 | + <p><input type="text" name="page_name" id="input_$input_num" size="$inSize" value="$inValue" class="autocompleteInput createboxInput" /> |
297 | 291 | |
298 | 292 | END; |
299 | 293 | } |
300 | | - // if the add page URL looks like "index.php?title=Special:AddPage" |
| 294 | + // if the form start URL looks like "index.php?title=Special:FormStart" |
301 | 295 | // (i.e., it's in the default URL style), add in the title as a |
302 | 296 | // hidden value |
303 | 297 | if ( ( $pos = strpos( $fs_url, "title=" ) ) > - 1 ) { |
— | — | @@ -306,7 +300,6 @@ |
307 | 301 | $str .= SFUtils::formDropdownHTML(); |
308 | 302 | } else { |
309 | 303 | $str .= ' <input type="hidden" name="form" value="' . $inFormName . '">' . "\n"; |
310 | | - $str .= ' <input type="hidden" name="form2" value="' . $inFormName . '">' . "\n"; |
311 | 304 | } |
312 | 305 | // recreate the passed-in query string as a set of hidden variables |
313 | 306 | $query_components = explode( '&', $inQueryStr ); |
— | — | @@ -314,23 +307,36 @@ |
315 | 308 | $subcomponents = explode( '=', $component, 2 ); |
316 | 309 | $key = ( isset( $subcomponents[0] ) ) ? $subcomponents[0] : ''; |
317 | 310 | $val = ( isset( $subcomponents[1] ) ) ? $subcomponents[1] : ''; |
318 | | - if ( ! empty( $key ) ) |
319 | | - $str .= ' <input type="hidden" name="' . $key . '" value="' . $val . '">' . "\n"; |
| 311 | + if ( ! empty( $key ) ){ |
| 312 | + $str .= ' ' . |
| 313 | + Xml::element( 'input', |
| 314 | + array( |
| 315 | + 'type' => 'hidden', |
| 316 | + 'name' => $key, |
| 317 | + 'value' => $val, |
| 318 | + ) |
| 319 | + ) . "\n"; |
| 320 | + } |
320 | 321 | } |
321 | 322 | wfLoadExtensionMessages( 'SemanticForms' ); |
322 | 323 | $button_str = ( $inButtonStr != '' ) ? $inButtonStr : wfMsg( 'sf_formstart_createoredit' ); |
323 | | - if ( empty( $inAutocompletionSource ) ) { |
324 | | - $str .= <<<END |
325 | | - <input type="submit" value="$button_str"></p> |
| 324 | + $str .= <<<END |
| 325 | + <input type="submit" value="$button_str" /></p> |
326 | 326 | </form> |
327 | 327 | |
328 | 328 | END; |
329 | | - } else { |
330 | | - $str .= <<<END |
331 | | - <td><input type="submit" value="$button_str"></td></tr></table> |
332 | | - </form> |
333 | | - |
334 | | -END; |
| 329 | + if ( ! empty( $inAutocompletionSource ) ) { |
| 330 | + $str .= ' ' . |
| 331 | + Xml::element( 'div', |
| 332 | + array( |
| 333 | + 'class' => 'page_name_auto_complete', |
| 334 | + 'id' => "div_$input_num", |
| 335 | + ), |
| 336 | + // it has to be <div></div>, not |
| 337 | + // <div />, to work properly - stick |
| 338 | + // in a space as the content |
| 339 | + ' ' |
| 340 | + ) . "\n"; |
335 | 341 | } |
336 | 342 | |
337 | 343 | // hack to remove newline from beginning of output, thanks to |
— | — | @@ -345,8 +351,15 @@ |
346 | 352 | // let '\n' represent newlines - chances that anyone will |
347 | 353 | // actually need the '\n' literal are small |
348 | 354 | $delimiter = str_replace( '\n', "\n", $delimiter ); |
| 355 | + $actual_delimiter = $parser->mStripState->unstripNoWiki( $delimiter ); |
349 | 356 | $new_delimiter = str_replace( '\n', "\n", $new_delimiter ); |
350 | | - $values_array = explode( $parser->mStripState->unstripNoWiki( $delimiter ), $value ); |
| 357 | + |
| 358 | + if ( $actual_delimiter == '' ) { |
| 359 | + $values_array = preg_split( '/(.)/u', $value, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); |
| 360 | + } else { |
| 361 | + $values_array = explode( $actual_delimiter, $value ); |
| 362 | + } |
| 363 | + |
351 | 364 | $results = array(); |
352 | 365 | foreach ( $values_array as $cur_value ) { |
353 | 366 | $cur_value = trim( $cur_value ); |
— | — | @@ -376,15 +389,24 @@ |
377 | 390 | $delimiter = str_replace( '\n', "\n", $delimiter ); |
378 | 391 | $new_delimiter = str_replace( '\n', "\n", $new_delimiter ); |
379 | 392 | |
380 | | - $values_array = explode( $delimiter, $value ); |
| 393 | + if ( $delimiter == '' ) { |
| 394 | + $values_array = preg_split( '/(.)/u', $value, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); |
| 395 | + } else { |
| 396 | + $values_array = explode( $delimiter, $value ); |
| 397 | + } |
| 398 | + |
381 | 399 | $results_array = array(); |
| 400 | + // add results to the results array only if the old value was |
| 401 | + // non-null, and the new, mapped value is non-null as well. |
382 | 402 | foreach ( $values_array as $old_value ) { |
383 | 403 | $old_value = trim( $old_value ); |
384 | 404 | if ( $old_value == '' ) continue; |
385 | 405 | $result_value = $frame->expand( $formula, PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ); |
386 | 406 | $result_value = str_replace( $var, $old_value, $result_value ); |
387 | 407 | $result_value = $parser->preprocessToDom( $result_value, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); |
388 | | - $results_array[] = trim( $frame->expand( $result_value ) ); |
| 408 | + $result_value = trim( $frame->expand( $result_value ) ); |
| 409 | + if ( $result_value == '' ) continue; |
| 410 | + $results_array[] = $result_value; |
389 | 411 | } |
390 | 412 | return implode( $new_delimiter, $results_array ); |
391 | 413 | } |
— | — | @@ -395,8 +417,15 @@ |
396 | 418 | static function renderArrayMapTemplate( &$parser, $value = '', $template = '', $delimiter = ',', $new_delimiter = ', ' ) { |
397 | 419 | # let '\n' represent newlines |
398 | 420 | $delimiter = str_replace( '\n', "\n", $delimiter ); |
| 421 | + $actual_delimiter = $parser->mStripState->unstripNoWiki( $delimiter ); |
399 | 422 | $new_delimiter = str_replace( '\n', "\n", $new_delimiter ); |
400 | | - $values_array = explode( $parser->mStripState->unstripNoWiki( $delimiter ), $value ); |
| 423 | + |
| 424 | + if ( $actual_delimiter == '' ) { |
| 425 | + $values_array = preg_split( '/(.)/u', $value, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); |
| 426 | + } else { |
| 427 | + $values_array = explode( $actual_delimiter, $value ); |
| 428 | + } |
| 429 | + |
401 | 430 | $results = array(); |
402 | 431 | $template = trim( $template ); |
403 | 432 | |
— | — | @@ -428,7 +457,12 @@ |
429 | 458 | $delimiter = str_replace( '\n', "\n", $delimiter ); |
430 | 459 | $new_delimiter = str_replace( '\n', "\n", $new_delimiter ); |
431 | 460 | |
432 | | - $values_array = explode( $delimiter, $value ); |
| 461 | + if ( $delimiter == '' ) { |
| 462 | + $values_array = preg_split( '/(.)/u', $value, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); |
| 463 | + } else { |
| 464 | + $values_array = explode( $delimiter, $value ); |
| 465 | + } |
| 466 | + |
433 | 467 | $results_array = array(); |
434 | 468 | foreach ( $values_array as $old_value ) { |
435 | 469 | $old_value = trim( $old_value ); |