r78976 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78975‎ | r78976 | r78977 >
Date:19:51, 24 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Attempt to fix bug 25917
Modified paths:
  • /trunk/extensions/SemanticFormsInputs/SFI_Inputs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticFormsInputs/SFI_Inputs.php
@@ -343,24 +343,23 @@
344344 * @return array of arrays of DateTimes
345345 */
346346 static private function createRangesArray ( $rangesAsStrings ) {
347 -
348347 // transform array of strings into array of array of dates
349348 return array_map(
350 - function( $range ) {
351 -
352 - if ( strpos ( $range, '-' ) === FALSE ) { // single date
353 - $date = date_create( $range );
354 - return ( $date ) ? array( $date, clone $date ):null;
355 - } else { // date range
356 - $dates = array_map( "date_create", explode( '-', $range ) );
357 - return ( $dates[0] && $dates[1] ) ? $dates:null;
358 - }
359 -
360 - } ,
361 - $rangesAsStrings
 349+ self::createRange(),
 350+ $rangesAsStrings
362351 );
363352
364353 }
 354+
 355+ private static function createRange( $range ) {
 356+ if ( strpos ( $range, '-' ) === FALSE ) { // single date
 357+ $date = date_create( $range );
 358+ return ( $date ) ? array( $date, clone $date ):null;
 359+ } else { // date range
 360+ $dates = array_map( "date_create", explode( '-', $range ) );
 361+ return ( $dates[0] && $dates[1] ) ? $dates:null;
 362+ }
 363+ }
365364
366365 /**
367366 * Takes an array of date ranges and returns an array containing the gaps
@@ -767,19 +766,8 @@
768767 // register disabled dates with datepicker
769768 if ( count( $disabledDates ) ) {
770769
771 - $disabledDatesString = '[' . implode( ',', array_map( function ( $range ) {
 770+ $disabledDatesString = '[' . implode( ',', array_map( self::createDateString(), $disabledDates ) ) . ']';
772771
773 - $y0 = $range[0]->format( "Y" );
774 - $m0 = $range[0]->format( "m" ) - 1;
775 - $d0 = $range[0]->format( "d" );
776 -
777 - $y1 = $range[1]->format( "Y" );
778 - $m1 = $range[1]->format( "m" ) - 1;
779 - $d1 = $range[1]->format( "d" );
780 -
781 - return "[new Date({$y0}, {$m0}, {$d0}), new Date({$y1}, {$m1}, {$d1})]";
782 - } , $disabledDates ) ) . ']';
783 -
784772 $jstext .= " jQuery(\"#input_{$sfgFieldNum}_show\").datepicker(\"option\", \"disabledDates\", $disabledDatesString);\n";
785773
786774 }
@@ -787,19 +775,8 @@
788776 // register highlighted dates with datepicker
789777 if ( count( $highlightedDates ) ) {
790778
791 - $highlightedDatesString = '[' . implode( ',', array_map( function ( $range ) {
 779+ $highlightedDatesString = '[' . implode( ',', array_map( self::createDateString(), $highlightedDates ) ) . ']';
792780
793 - $y0 = $range[0]->format( "Y" );
794 - $m0 = $range[0]->format( "m" ) - 1;
795 - $d0 = $range[0]->format( "d" );
796 -
797 - $y1 = $range[1]->format( "Y" );
798 - $m1 = $range[1]->format( "m" ) - 1;
799 - $d1 = $range[1]->format( "d" );
800 -
801 - return "[new Date({$y0}, {$m0}, {$d0}), new Date({$y1}, {$m1}, {$d1})]";
802 - } , $highlightedDates ) ) . ']';
803 -
804781 $jstext .= " jQuery(\"#input_{$sfgFieldNum}_show\").datepicker(\"option\", \"highlightedDates\", $highlightedDatesString);\n";
805782
806783 }
@@ -832,13 +809,25 @@
833810
834811
835812 }
836 -
 813+
837814 // add span for error messages (e.g. used for mandatory inputs)
838815 $html .= Html::element( "span", array( "id" => "info_$sfgFieldNum", "class" => "errorMessage" ) );
839816
840817 $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' );
841818
842819 return array( $html, "" );
 820+ }
 821+
 822+ private static function createDateString( $range ) {
 823+ $y0 = $range[0]->format( "Y" );
 824+ $m0 = $range[0]->format( "m" ) - 1;
 825+ $d0 = $range[0]->format( "d" );
843826
 827+ $y1 = $range[1]->format( "Y" );
 828+ $m1 = $range[1]->format( "m" ) - 1;
 829+ $d1 = $range[1]->format( "d" );
 830+
 831+ return "[new Date({$y0}, {$m0}, {$d0}), new Date({$y1}, {$m1}, {$d1})]";
844832 }
 833+
845834 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r79270major rework of extension...foxtrott17:28, 30 December 2010

Status & tagging log