r71482 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71481‎ | r71482 | r71483 >
Date:13:45, 23 August 2010
Author:yaron
Status:deferred
Tags:
Comment:
Added Christoph Burgmer's patch for an 'empty' delimiter in #arraymap and #arraymaptemplate (i.e., separating into characters); improved display of autocompletion in #forminput (no more <table>); otherwise improved HTML
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php
@@ -97,6 +97,7 @@
9898 * @author Sergey Chernyshev
9999 * @author Daniel Friesen
100100 * @author Barry Welch
 101+ * @author Christoph Burgmer
101102 */
102103
103104 class SFParserFunctions {
@@ -192,7 +193,7 @@
193194 $link_url = str_replace( "'", "\'", $link_url );
194195 $str = "<form><input type=\"button\" value=\"$inLinkStr\" onclick=\"window.location.href='$link_url'\"></form>";
195196 } 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>";
197198 } else {
198199 $str = "<a href=\"$link_url\">$inLinkStr</a>";
199200 }
@@ -283,20 +284,13 @@
284285
285286 END;
286287 } 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)
292288 $str = <<<END
293289 <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" />
297291
298292 END;
299293 }
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"
301295 // (i.e., it's in the default URL style), add in the title as a
302296 // hidden value
303297 if ( ( $pos = strpos( $fs_url, "title=" ) ) > - 1 ) {
@@ -306,7 +300,6 @@
307301 $str .= SFUtils::formDropdownHTML();
308302 } else {
309303 $str .= ' <input type="hidden" name="form" value="' . $inFormName . '">' . "\n";
310 - $str .= ' <input type="hidden" name="form2" value="' . $inFormName . '">' . "\n";
311304 }
312305 // recreate the passed-in query string as a set of hidden variables
313306 $query_components = explode( '&', $inQueryStr );
@@ -314,23 +307,36 @@
315308 $subcomponents = explode( '=', $component, 2 );
316309 $key = ( isset( $subcomponents[0] ) ) ? $subcomponents[0] : '';
317310 $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+ }
320321 }
321322 wfLoadExtensionMessages( 'SemanticForms' );
322323 $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>
326326 </form>
327327
328328 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";
335341 }
336342
337343 // hack to remove newline from beginning of output, thanks to
@@ -345,8 +351,15 @@
346352 // let '\n' represent newlines - chances that anyone will
347353 // actually need the '\n' literal are small
348354 $delimiter = str_replace( '\n', "\n", $delimiter );
 355+ $actual_delimiter = $parser->mStripState->unstripNoWiki( $delimiter );
349356 $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+
351364 $results = array();
352365 foreach ( $values_array as $cur_value ) {
353366 $cur_value = trim( $cur_value );
@@ -376,15 +389,24 @@
377390 $delimiter = str_replace( '\n', "\n", $delimiter );
378391 $new_delimiter = str_replace( '\n', "\n", $new_delimiter );
379392
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+
381399 $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.
382402 foreach ( $values_array as $old_value ) {
383403 $old_value = trim( $old_value );
384404 if ( $old_value == '' ) continue;
385405 $result_value = $frame->expand( $formula, PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES );
386406 $result_value = str_replace( $var, $old_value, $result_value );
387407 $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;
389411 }
390412 return implode( $new_delimiter, $results_array );
391413 }
@@ -395,8 +417,15 @@
396418 static function renderArrayMapTemplate( &$parser, $value = '', $template = '', $delimiter = ',', $new_delimiter = ', ' ) {
397419 # let '\n' represent newlines
398420 $delimiter = str_replace( '\n', "\n", $delimiter );
 421+ $actual_delimiter = $parser->mStripState->unstripNoWiki( $delimiter );
399422 $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+
401430 $results = array();
402431 $template = trim( $template );
403432
@@ -428,7 +457,12 @@
429458 $delimiter = str_replace( '\n', "\n", $delimiter );
430459 $new_delimiter = str_replace( '\n', "\n", $new_delimiter );
431460
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+
433467 $results_array = array();
434468 foreach ( $values_array as $old_value ) {
435469 $old_value = trim( $old_value );

Status & tagging log