Index: trunk/extensions/SemanticFormsInputs/SFI_Settings.php |
— | — | @@ -1,155 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Settings for the Semantic Forms Inputs extension. |
5 | | - * |
6 | | - * @author Stephan Gambke |
7 | | - * |
8 | | - * To change the default settings you can uncomment (or copy) the |
9 | | - * examples here and adjust them to your needs. You may as well |
10 | | - * include them in your LocalSettings.php. |
11 | | - */ |
12 | | - |
13 | | -## |
14 | | -# This is the path to your installation of Semantic Forms Inputs as |
15 | | -# seen from the web. No final slash. |
16 | | -# |
17 | | -$sfigSettings->scriptPath = $wgScriptPath . '/extensions/SemanticFormsInputs'; |
18 | | - |
19 | | -## Date Picker Settings |
20 | | - |
21 | | -## |
22 | | -# This is the first selectable date (format yyyy/mm/dd) |
23 | | -# Sample value: '2005/01/01' |
24 | | -# |
25 | | -$sfigSettings->datePickerFirstDate = null; |
26 | | - |
27 | | -## |
28 | | -# This is the last selectable date (format yyyy/mm/dd) |
29 | | -# Sample value: '2015/31/12' |
30 | | -# |
31 | | -$sfigSettings->datePickerLastDate = null; |
32 | | - |
33 | | -## |
34 | | -# The date format string used for the user input. |
35 | | -# The date sent back to the form is fixed to yyyy/mm/dd |
36 | | -# (that is, yy/mm/dd in the format code below). |
37 | | -# |
38 | | -# The format can be combinations of the following: |
39 | | -# |
40 | | -# d - day of month (no leading zero) |
41 | | -# dd - day of month (two digit) |
42 | | -# o - day of the year (no leading zeros) |
43 | | -# oo - day of the year (three digit) |
44 | | -# D - day name short |
45 | | -# DD - day name long |
46 | | -# m - month of year (no leading zero) |
47 | | -# mm - month of year (two digit) |
48 | | -# M - month name short |
49 | | -# MM - month name long |
50 | | -# y - year (two digit) |
51 | | -# yy - year (four digit) |
52 | | -# @ - Unix timestamp (ms since 01/01/1970) |
53 | | -# ! - Windows ticks (100ns since 01/01/0001) |
54 | | -# '...' - literal text |
55 | | -# '' - single quote |
56 | | -# anything else - literal text |
57 | | -# |
58 | | -# There are also two predefined standard date formats available: |
59 | | -# |
60 | | -# SHORT - short date format localized to the wiki user language |
61 | | -# LONG - long date format localized to the wiki user language |
62 | | -# |
63 | | -$sfigSettings->datePickerDateFormat = 'SHORT'; |
64 | | - |
65 | | -## |
66 | | -# This determines the start of the week in the display. |
67 | | -# Set it to: 0 (Zero) for Sunday, 1 (One) for Monday etc. |
68 | | -# If set to null the day is localized to the wiki user language |
69 | | -# Sample value: 1 |
70 | | -# |
71 | | -$sfigSettings->datePickerWeekStart = null; |
72 | | - |
73 | | -## |
74 | | -# This determines if the number of the week shall be shown. |
75 | | -# |
76 | | -$sfigSettings->datePickerShowWeekNumbers = false; |
77 | | - |
78 | | -## |
79 | | -# This determines if the input field shall be disabled. The user can |
80 | | -# only set the date via the datepicker in this case. |
81 | | -# |
82 | | -$sfigSettings->datePickerDisableInputField = false; |
83 | | - |
84 | | -## |
85 | | -# This determines if a reset button shall be shown. This is the only |
86 | | -# way to erase the input field if it is disabled for direct input. |
87 | | -# |
88 | | -$sfigSettings->datePickerShowResetButton = false; |
89 | | - |
90 | | -## |
91 | | -# This is a string of disabled days of the week, i.e. days the user can not |
92 | | -# pick. The days must be given as comma-separated list of numbers starting |
93 | | -# with 0 for Sunday. |
94 | | -# Sample value: "6,0" |
95 | | -# |
96 | | -$sfigSettings->datePickerDisabledDaysOfWeek = null; |
97 | | - |
98 | | -## |
99 | | -# This is a string of highlighted days of the week. The days must be given as |
100 | | -# comma-separated list of numbers starting with 0 for Sunday. |
101 | | -# Sample value: "6,0" |
102 | | -# |
103 | | -$sfigSettings->datePickerHighlightedDaysOfWeek = null; |
104 | | - |
105 | | -## |
106 | | -# This is a string of disabled dates, i.e. days the user cannot pick. The |
107 | | -# days must be given as comma-separated list of dates or date ranges. The |
108 | | -# format for days is yyyy/mm/dd, for date ranges use yyyy/mm/dd-yyyy/mm/dd. |
109 | | -# Spaces are permissible. |
110 | | -# Sample value: "2010/12/25 - 2011/01/06, 2011/05/01" |
111 | | -# |
112 | | -$sfigSettings->datePickerDisabledDates = null; |
113 | | - |
114 | | -## |
115 | | -# This is a string of highlighted dates. The days must be given as |
116 | | -# comma-separated list of dates or date ranges. The format for days is |
117 | | -# yyyy/mm/dd, for date ranges use yyyy/mm/dd-yyyy/mm/dd. Spaces are |
118 | | -# permissible. |
119 | | -# Sample value: "2010/12/25 - 2011/01/06, 2011/05/01" |
120 | | -# |
121 | | -$sfigSettings->datePickerHighlightedDates = null; |
122 | | - |
123 | | - |
124 | | -## Time Picker Settings |
125 | | - |
126 | | -## |
127 | | -# This is the first selectable time (format hh:mm) |
128 | | -# Sample value: '00:00' |
129 | | -# |
130 | | -$sfigSettings->timePickerMinTime = null; |
131 | | - |
132 | | -## |
133 | | -# This is the last selectable time (format hh:mm) |
134 | | -# Sample value: '24:00' |
135 | | -# |
136 | | -$sfigSettings->timePickerMaxTime = null; |
137 | | - |
138 | | -## |
139 | | -# This determines if the input field shall be disabled. The user can |
140 | | -# only set the time via the timepicker in this case. |
141 | | -# |
142 | | -$sfigSettings->timePickerDisableInputField = false; |
143 | | - |
144 | | -## |
145 | | -# This determines if a reset button shall be shown. This is the only |
146 | | -# way to erase the input field if it is disabled for direct input. |
147 | | -# |
148 | | -$sfigSettings->timePickerShowResetButton = false; |
149 | | - |
150 | | - |
151 | | -## |
152 | | -# This determines if a reset button shall be shown. This is the only |
153 | | -# way to erase the input field if it is disabled for direct input. |
154 | | -# |
155 | | -$sfigSettings->datetimePickerShowResetButton = false; |
156 | | - |
Index: trunk/extensions/SemanticFormsInputs/SFI_Inputs.php |
— | — | @@ -1,1320 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Input definitions for the Semantic Forms Inputs extension. |
5 | | - * |
6 | | - * @author Stephan Gambke |
7 | | - * @author Sanyam Goyal |
8 | | - * @author Yaron Koren |
9 | | - * |
10 | | - */ |
11 | | - |
12 | | -if ( !defined( 'SFI_VERSION' ) ) { |
13 | | - die( 'This file is part of a MediaWiki extension, it is not a valid entry point.' ); |
14 | | -} |
15 | | - |
16 | | -class SFIInputs { |
17 | | - |
18 | | - /** |
19 | | - * Creates the html text for an input. |
20 | | - * |
21 | | - * Common attributes for input types are set according to the parameters. |
22 | | - * The parameters are the standard parameters set by Semantic Forms' |
23 | | - * InputTypeHook plus some optional. |
24 | | - * |
25 | | - * @param string $cur_value |
26 | | - * @param string $input_name |
27 | | - * @param boolean $is_mandatory |
28 | | - * @param boolean $is_disabled |
29 | | - * @param array $other_args |
30 | | - * @param string $input_id (optional) |
31 | | - * @param int $tabindex (optional) |
32 | | - * @param string $class |
33 | | - * @return string the html text of an input element |
34 | | - */ |
35 | | - static private function textHTML ( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args, $input_id = null, $tabindex = null, $class = "" ) { |
36 | | - |
37 | | - global $sfgFieldNum, $sfgTabIndex; |
38 | | - |
39 | | - // array of attributes to pass to the input field |
40 | | - $attribs = array( |
41 | | - "name" => $input_name, |
42 | | - "class" => $class, |
43 | | - "value" => $cur_value, |
44 | | - "type" => "text" |
45 | | - ); |
46 | | - |
47 | | - // set size attrib |
48 | | - if ( array_key_exists( 'size', $other_args ) ) { |
49 | | - $attribs['size'] = $other_args['size']; |
50 | | - } |
51 | | - |
52 | | - // set maxlength attrib |
53 | | - if ( array_key_exists( 'maxlength', $other_args ) ) { |
54 | | - $attribs['maxlength'] = $other_args['maxlength']; |
55 | | - } |
56 | | - |
57 | | - // modify class attribute for mandatory form fields |
58 | | - if ( $is_mandatory ) { |
59 | | - $attribs["class"] .= ' mandatoryField'; |
60 | | - } |
61 | | - |
62 | | - // add user class(es) to class attribute of input field |
63 | | - if ( array_key_exists( 'class', $other_args ) ) { |
64 | | - $attribs["class"] .= ' ' . $other_args['class']; |
65 | | - } |
66 | | - |
67 | | - // set readonly attrib |
68 | | - if ( $is_disabled ) { |
69 | | - $attribs["readonly"] = "1"; |
70 | | - } |
71 | | - |
72 | | - // if no special input id is specified set the Semantic Forms standard |
73 | | - if ( $input_id == null ) { |
74 | | - $attribs[ 'id' ] = "input_" . $sfgFieldNum; |
75 | | - } else { |
76 | | - $attribs[ 'id' ] = $input_id; |
77 | | - } |
78 | | - |
79 | | - |
80 | | - if ( $tabindex == null ) $attribs[ 'tabindex' ] = $sfgTabIndex; |
81 | | - else $attribs[ 'tabindex' ] = $tabindex; |
82 | | - |
83 | | - // $html = Html::element( "input", $attribs ); |
84 | | - $html = Xml::element( "input", $attribs ); |
85 | | - |
86 | | - return $html; |
87 | | - |
88 | | - } |
89 | | - |
90 | | - /** |
91 | | - * Setup function for input type regexp. |
92 | | - * |
93 | | - * Loads the Javascript code used by all regexp filters. |
94 | | - */ |
95 | | - static private function regexpSetup() { |
96 | | - |
97 | | - global $wgOut; |
98 | | - global $sfigSettings; |
99 | | - |
100 | | - static $hasRun = false; |
101 | | - |
102 | | - if ( !$hasRun ) { |
103 | | - $hasRun = true; |
104 | | - |
105 | | - $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/regexp.js"></script> ' ); |
106 | | - |
107 | | - } |
108 | | - } |
109 | | - |
110 | | - |
111 | | - /** |
112 | | - * Definition of input type "regexp" |
113 | | - * |
114 | | - * Returns the html code to be included in the page and registers the |
115 | | - * input's JS initialisation method |
116 | | - * |
117 | | - * @param string $cur_value current value of this field (which is sometimes null) |
118 | | - * @param string $input_name HTML name that this input should have |
119 | | - * @param boolean $is_mandatory indicates whether this field is mandatory for the user |
120 | | - * @param boolean $is_disabled indicates whether this field is disabled (meaning, the user can't edit) |
121 | | - * @param array $other_args hash representing all the other properties defined for this input in the form definition |
122 | | - * @return string html code of input |
123 | | - */ |
124 | | - static function regexpHTML ( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
125 | | - |
126 | | - global $wgOut; |
127 | | - global $sfgFieldNum; // used for setting various HTML IDs |
128 | | - global $sfgJSValidationCalls; // array of Javascript calls to determine if page can be saved |
129 | | - global $sfgFormPrinter; |
130 | | - |
131 | | - self::regexpSetup(); |
132 | | - |
133 | | - // set base input type |
134 | | - if ( array_key_exists( 'base type', $other_args ) ) { |
135 | | - |
136 | | - $baseType = trim( $other_args['base type'] ); |
137 | | - unset( $other_args['base type'] ); |
138 | | - |
139 | | - // if unknown set default base input type |
140 | | - if ( ! array_key_exists( $baseType, $sfgFormPrinter->mInputTypeHooks ) ) |
141 | | - $baseType = 'text'; |
142 | | - } |
143 | | - else $baseType = 'text'; |
144 | | - |
145 | | - // set base prefix string |
146 | | - if ( array_key_exists( 'base prefix', $other_args ) ) { |
147 | | - $basePrefix = trim( $other_args['base prefix'] ) . "."; |
148 | | - unset( $other_args['base prefix'] ); |
149 | | - } |
150 | | - else $basePrefix = ''; |
151 | | - |
152 | | - // set OR character |
153 | | - if ( array_key_exists( 'or char', $other_args ) ) { |
154 | | - $orChar = trim( $other_args['or char'] ); |
155 | | - unset( $other_args['or char'] ); |
156 | | - } |
157 | | - else $orChar = '!'; |
158 | | - |
159 | | - // set inverse string |
160 | | - if ( array_key_exists( 'inverse', $other_args ) ) { |
161 | | - $inverseString = 'true'; |
162 | | - unset( $other_args['inverse'] ); |
163 | | - } |
164 | | - else $inverseString = 'false'; |
165 | | - |
166 | | - // set regexp string |
167 | | - if ( array_key_exists( 'regexp', $other_args ) ) { |
168 | | - |
169 | | - $regexp = str_replace( $orChar, '|', trim( $other_args['regexp'] ) ); |
170 | | - unset( $other_args['regexp'] ); |
171 | | - |
172 | | - // check for leading/trailing delimiter and remove it (else reset regexp) |
173 | | - if ( preg_match ( "/^\/.*\/\$/", $regexp ) ) { |
174 | | - |
175 | | - $regexp = substr( $regexp, 1, strlen( $regexp ) - 2 ); |
176 | | - |
177 | | - } |
178 | | - else $regexp = '.*'; |
179 | | - |
180 | | - } |
181 | | - else $regexp = '.*'; |
182 | | - |
183 | | - // set failure message string |
184 | | - if ( array_key_exists( 'message', $other_args ) ) { |
185 | | - $message = trim( $other_args['message'] ); |
186 | | - unset( $other_args['message'] ); |
187 | | - } |
188 | | - else $message = wfMsg( 'semanticformsinputs-wrongformat' ); |
189 | | - |
190 | | - // sanitize error message and regexp for JS |
191 | | - $message = Xml::encodeJsVar( $message ); |
192 | | - $regexp = Xml::encodeJsVar( $regexp ); |
193 | | - |
194 | | - // register event to validate regexp on submit/preview |
195 | | - $jstext = <<<JAVASCRIPT |
196 | | -jQuery(function(){ jQuery('#input_$sfgFieldNum').SemanticForms_registerInputValidation( SFI_RE_validate, {retext: {$regexp}, inverse: {$inverseString}, message: {$message} }); }); |
197 | | -JAVASCRIPT; |
198 | | - |
199 | | - $wgOut->addScript( Html::inlineScript( $jstext ) ); |
200 | | - |
201 | | - // create other_args for base input type |
202 | | - $new_other_args = array(); |
203 | | - |
204 | | - foreach ( $other_args as $key => $value ) |
205 | | - if ( $basePrefix && strpos( $key, $basePrefix ) === 0 ) { |
206 | | - $new_other_args[substr( $key, strlen( $basePrefix ) )] = $value; |
207 | | - } else |
208 | | - $new_other_args[$key] = $value; |
209 | | - |
210 | | - // setup parameters for base input type |
211 | | - $funcArgs = array(); |
212 | | - $funcArgs[] = $cur_value; |
213 | | - $funcArgs[] = $input_name; |
214 | | - $funcArgs[] = $is_mandatory; |
215 | | - $funcArgs[] = $is_disabled; |
216 | | - $funcArgs[] = $new_other_args; |
217 | | - |
218 | | - // get the input type hooks for the base input type |
219 | | - $hook_values = $sfgFormPrinter->mInputTypeHooks[$baseType]; |
220 | | - |
221 | | - // generate html and JS code for base input type and return it |
222 | | - return call_user_func_array( $hook_values[0], $funcArgs ); |
223 | | - |
224 | | -} |
225 | | - |
226 | | - |
227 | | - /** |
228 | | - * Setup for input type jqdatepicker. |
229 | | - * |
230 | | - * Adds the Javascript code used by all datepickers. |
231 | | - */ |
232 | | - static private function jqDatePickerSetup () { |
233 | | - global $wgOut, $wgLang, $sfgScriptPath; |
234 | | - global $sfigSettings; |
235 | | - |
236 | | - static $hasRun = false; |
237 | | - |
238 | | - if ( !$hasRun ) { |
239 | | - $hasRun = true; |
240 | | - |
241 | | - $wgOut->addScript( '<script type="text/javascript" src="' . $sfgScriptPath . '/libs/jquery-ui/jquery.ui.datepicker.min.js"></script> ' ); |
242 | | - $wgOut->addExtensionStyle( $sfgScriptPath . '/skins/jquery-ui/base/jquery.ui.datepicker.css' ); |
243 | | - $wgOut->addExtensionStyle( $sfgScriptPath . '/skins/jquery-ui/base/jquery.ui.theme.css' ); |
244 | | - $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/datepicker.js"></script> ' ); |
245 | | - |
246 | | - // set localized messages (use MW i18n, not jQuery i18n) |
247 | | - $jstext = |
248 | | - "jQuery(function(){\n" |
249 | | - . " jQuery.datepicker.regional['wiki'] = {\n" |
250 | | - . " closeText: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-close' ) ) . "',\n" |
251 | | - . " prevText: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-prev' ) ) . "',\n" |
252 | | - . " nextText: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-next' ) ) . "',\n" |
253 | | - . " currentText: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-today' ) ) . "',\n" |
254 | | - . " monthNames: ['" |
255 | | - . Xml::escapeJsString( wfMsg( 'january' ) ) . "','" |
256 | | - . Xml::escapeJsString( wfMsg( 'february' ) ) . "','" |
257 | | - . Xml::escapeJsString( wfMsg( 'march' ) ) . "','" |
258 | | - . Xml::escapeJsString( wfMsg( 'april' ) ) . "','" |
259 | | - . Xml::escapeJsString( wfMsg( 'may_long' ) ) . "','" |
260 | | - . Xml::escapeJsString( wfMsg( 'june' ) ) . "','" |
261 | | - . Xml::escapeJsString( wfMsg( 'july' ) ) . "','" |
262 | | - . Xml::escapeJsString( wfMsg( 'august' ) ) . "','" |
263 | | - . Xml::escapeJsString( wfMsg( 'september' ) ) . "','" |
264 | | - . Xml::escapeJsString( wfMsg( 'october' ) ) . "','" |
265 | | - . Xml::escapeJsString( wfMsg( 'november' ) ) . "','" |
266 | | - . Xml::escapeJsString( wfMsg( 'december' ) ) . "'],\n" |
267 | | - . " monthNamesShort: ['" |
268 | | - . Xml::escapeJsString( wfMsg( 'jan' ) ) . "','" |
269 | | - . Xml::escapeJsString( wfMsg( 'feb' ) ) . "','" |
270 | | - . Xml::escapeJsString( wfMsg( 'mar' ) ) . "','" |
271 | | - . Xml::escapeJsString( wfMsg( 'apr' ) ) . "','" |
272 | | - . Xml::escapeJsString( wfMsg( 'may' ) ) . "','" |
273 | | - . Xml::escapeJsString( wfMsg( 'jun' ) ) . "','" |
274 | | - . Xml::escapeJsString( wfMsg( 'jul' ) ) . "','" |
275 | | - . Xml::escapeJsString( wfMsg( 'aug' ) ) . "','" |
276 | | - . Xml::escapeJsString( wfMsg( 'sep' ) ) . "','" |
277 | | - . Xml::escapeJsString( wfMsg( 'oct' ) ) . "','" |
278 | | - . Xml::escapeJsString( wfMsg( 'nov' ) ) . "','" |
279 | | - . Xml::escapeJsString( wfMsg( 'dec' ) ) . "'],\n" |
280 | | - . " dayNames: ['" |
281 | | - . Xml::escapeJsString( wfMsg( 'sunday' ) ) . "','" |
282 | | - . Xml::escapeJsString( wfMsg( 'monday' ) ) . "','" |
283 | | - . Xml::escapeJsString( wfMsg( 'tuesday' ) ) . "','" |
284 | | - . Xml::escapeJsString( wfMsg( 'wednesday' ) ) . "','" |
285 | | - . Xml::escapeJsString( wfMsg( 'thursday' ) ) . "','" |
286 | | - . Xml::escapeJsString( wfMsg( 'friday' ) ) . "','" |
287 | | - . Xml::escapeJsString( wfMsg( 'saturday' ) ) . "'],\n" |
288 | | - . " dayNamesShort: ['" |
289 | | - . Xml::escapeJsString( wfMsg( 'sun' ) ) . "','" |
290 | | - . Xml::escapeJsString( wfMsg( 'mon' ) ) . "','" |
291 | | - . Xml::escapeJsString( wfMsg( 'tue' ) ) . "','" |
292 | | - . Xml::escapeJsString( wfMsg( 'wed' ) ) . "','" |
293 | | - . Xml::escapeJsString( wfMsg( 'thu' ) ) . "','" |
294 | | - . Xml::escapeJsString( wfMsg( 'fri' ) ) . "','" |
295 | | - . Xml::escapeJsString( wfMsg( 'sat' ) ) . "'],\n" |
296 | | - . " dayNamesMin: ['" |
297 | | - . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'sun' ) ) ) . "','" |
298 | | - . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'mon' ) ) ) . "','" |
299 | | - . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'tue' ) ) ) . "','" |
300 | | - . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'wed' ) ) ) . "','" |
301 | | - . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'thu' ) ) ) . "','" |
302 | | - . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'fri' ) ) ) . "','" |
303 | | - . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'sat' ) ) ) . "'],\n" |
304 | | - . " weekHeader: '',\n" |
305 | | - . " dateFormat: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-dateformatshort' ) ) . "',\n" |
306 | | - . " firstDay: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-firstdayofweek' ) ) . "',\n" |
307 | | - . " isRTL: " . ( $wgLang->isRTL() ? "true" : "false" ) . ",\n" |
308 | | - . " showMonthAfterYear: false,\n" |
309 | | - . " yearSuffix: ''};\n" |
310 | | - . " jQuery.datepicker.setDefaults(jQuery.datepicker.regional['wiki']);\n" |
311 | | - . "});\n"; |
312 | | - |
313 | | - |
314 | | - $wgOut->addInlineScript( $jstext ); |
315 | | - |
316 | | - } |
317 | | - } |
318 | | - |
319 | | - /** |
320 | | - * Sort and merge time ranges in an array |
321 | | - * |
322 | | - * expects an array of arrays |
323 | | - * the inner arrays must contain two dates representing the start and end |
324 | | - * date of a time range |
325 | | - * |
326 | | - * returns an array of arrays with the date ranges sorted and overlapping |
327 | | - * ranges merged |
328 | | - * |
329 | | - * @param array $ranges array of arrays of DateTimes |
330 | | - * @return array of arrays of DateTimes |
331 | | - */ |
332 | | - static private function sortAndMergeRanges ( $ranges ) { |
333 | | - |
334 | | - // sort ranges, earliest date first |
335 | | - sort( $ranges ); |
336 | | - |
337 | | - // stores the start of the current date range |
338 | | - $currmin = FALSE; |
339 | | - |
340 | | - // stores the date the next ranges start date has to top to not overlap |
341 | | - $nextmin = FALSE; |
342 | | - |
343 | | - // result array |
344 | | - $mergedRanges = array(); |
345 | | - |
346 | | - foreach ( $ranges as $range ) { |
347 | | - |
348 | | - // ignore empty date ranges |
349 | | - if ( !$range ) continue; |
350 | | - |
351 | | - if ( !$currmin ) { // found first valid range |
352 | | - |
353 | | - $currmin = $range[0]; |
354 | | - $nextmin = $range[1]; |
355 | | - $nextmin->modify( '+1 day' ); |
356 | | - |
357 | | - } elseif ( $range[0] <= $nextmin ) { // overlap detected |
358 | | - |
359 | | - $currmin = min( $currmin, $range[0] ); |
360 | | - |
361 | | - $range[1]->modify( '+1 day' ); |
362 | | - $nextmin = max( $nextmin, $range[1] ); |
363 | | - |
364 | | - } else { // no overlap, store current range and continue with next |
365 | | - |
366 | | - $nextmin->modify( '-1 day' ); |
367 | | - $mergedRanges[] = array( $currmin, $nextmin ); |
368 | | - |
369 | | - $currmin = $range[0]; |
370 | | - $nextmin = $range[1]; |
371 | | - $nextmin->modify( '+1 day' ); |
372 | | - |
373 | | - } |
374 | | - |
375 | | - } |
376 | | - |
377 | | - // store last range |
378 | | - if ( $currmin ) { |
379 | | - $nextmin->modify( '-1 day' ); |
380 | | - $mergedRanges[] = array( $currmin, $nextmin ); |
381 | | - } |
382 | | - |
383 | | - return $mergedRanges; |
384 | | - |
385 | | - } |
386 | | - |
387 | | - /** |
388 | | - * Creates an array of arrays of dates from an array of strings |
389 | | - * |
390 | | - * expects an array of strings containing dates or date ranges in the format |
391 | | - * "yyyy/mm/dd" or "yyyy/mm/dd-yyyy/mm/dd" |
392 | | - * |
393 | | - * returns an array of arrays, each of the latter consisting of two dates |
394 | | - * representing the start and end date of the range |
395 | | - * |
396 | | - * The result array will contain null values for unparseable date strings |
397 | | - * |
398 | | - * @param array $rangesAsStrings array of strings with dates and date ranges |
399 | | - * @return array of arrays of DateTimes |
400 | | - */ |
401 | | - static private function createRangesArray ( $rangesAsStrings ) { |
402 | | - |
403 | | - // transform array of strings into array of array of dates |
404 | | - // have to use create_function to be PHP pre5.3 compatible |
405 | | - return array_map( create_function( '$range', ' |
406 | | - |
407 | | - if ( strpos ( $range, "-" ) === FALSE ) { // single date |
408 | | - $date = date_create( $range ); |
409 | | - return ( $date ) ? array( $date, clone $date ):null; |
410 | | - } else { // date range |
411 | | - $dates = array_map( "date_create", explode( "-", $range ) ); |
412 | | - return ( $dates[0] && $dates[1] ) ? $dates:null; |
413 | | - } |
414 | | - |
415 | | - ' ), $rangesAsStrings ); |
416 | | - |
417 | | - } |
418 | | - |
419 | | - /** |
420 | | - * Takes an array of date ranges and returns an array containing the gaps |
421 | | - * |
422 | | - * The very first and the very last date of the original string are lost in |
423 | | - * the process, of course, as they do not delimit a gap. This means, after |
424 | | - * repeated inversion the result would eventually be empty. |
425 | | - * |
426 | | - * @param array $ranges of arrays of DateTimes |
427 | | - * @return array of arrays of DateTimes |
428 | | - */ |
429 | | - static private function invertRangesArray( $ranges ) { |
430 | | - |
431 | | - // the result (initially empty) |
432 | | - $invRanges = null; |
433 | | - |
434 | | - // the minimum of the current gap (initially none) |
435 | | - $min = null; |
436 | | - |
437 | | - foreach ( $ranges as $range ) { |
438 | | - |
439 | | - if ( $min ) { // if min date of current gap is known store gap |
440 | | - $min->modify( "+1day " ); |
441 | | - $range[0]->modify( "-1day " ); |
442 | | - $invRanges[] = array( $min, $range[0] ); |
443 | | - } |
444 | | - |
445 | | - $min = $range[1]; // store min date of next gap |
446 | | - |
447 | | - } |
448 | | - |
449 | | - return $invRanges; |
450 | | - } |
451 | | - |
452 | | - |
453 | | - /** |
454 | | - * Definition of input type "datepicker". |
455 | | - * |
456 | | - * Returns the html code to be included in the page and registers the |
457 | | - * input's JS initialisation method |
458 | | - * |
459 | | - * @param string $cur_value current value of this field (which is sometimes null) |
460 | | - * @param string $input_name HTML name that this input should have |
461 | | - * @param boolean $is_mandatory indicates whether this field is mandatory for the user |
462 | | - * @param boolean $is_disabled indicates whether this field is disabled (meaning, the user can't edit) |
463 | | - * @param array $other_args hash representing all the other properties defined for this input in the form definition |
464 | | - * @return string html code of input |
465 | | - */ |
466 | | - static function jqDatePickerHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
467 | | - |
468 | | - global $wgOut, $wgLang, $wgAmericanDates; // MW variables |
469 | | - global $sfgFieldNum, $sfgScriptPath, $sfgTabIndex; // SF variables |
470 | | - global $sfigSettings; // SFI variables |
471 | | - |
472 | | - // call common setup for all jqdatepickers |
473 | | - self::jqDatePickerSetup(); |
474 | | - |
475 | | - // The datepicker is created in three steps: |
476 | | - // first: set up HTML attributes |
477 | | - // second: set up JS attributes |
478 | | - // third: assemble HTML and JS code |
479 | | - |
480 | | - |
481 | | - // first: set up HTML attributes |
482 | | - // nothing much to do here, self::textHTML will take care od the standard stuff |
483 | | - |
484 | | - // store user class(es) for use with buttons |
485 | | - if ( array_key_exists( 'class', $other_args ) ) { |
486 | | - $userClasses = $other_args['class']; |
487 | | - } else $userClasses = ""; |
488 | | - |
489 | | - // should the input field be disabled? |
490 | | - $inputFieldDisabled = |
491 | | - array_key_exists( 'disable input field', $other_args ) |
492 | | - || ( !array_key_exists( 'enable input field', $other_args ) && $sfigSettings->datePickerDisableInputField ) |
493 | | - || $is_disabled ; |
494 | | - |
495 | | - // second: set up JS attributes |
496 | | - |
497 | | - // set up attributes required for both enabled and disabled datepickers |
498 | | - $jsattribs = array( |
499 | | - 'currValue' => $cur_value, |
500 | | - 'disabled' => $is_disabled, |
501 | | - 'userClasses' => $userClasses |
502 | | - ); |
503 | | - |
504 | | - if ( array_key_exists( 'part of dtp', $other_args ) ) { |
505 | | - $jsattribs['partOfDTP'] = $other_args['part of dtp']; |
506 | | - } |
507 | | - |
508 | | - // set date format |
509 | | - // SHORT and LONG are SFI specific acronyms and are translated here |
510 | | - // into format strings, anything else is passed to the jQuery date picker |
511 | | - // Americans need special treatment |
512 | | - if ( $wgAmericanDates && $wgLang->getCode() == "en" ) { |
513 | | - |
514 | | - if ( array_key_exists( 'date format', $other_args ) ) { |
515 | | - |
516 | | - if ( $other_args['date format'] == 'SHORT' ) { |
517 | | - $jsattribs['dateFormat'] = 'mm/dd/yy'; |
518 | | - } elseif ( $other_args['date format'] == 'LONG' ) { |
519 | | - $jsattribs['dateFormat'] = 'MM d, yy'; |
520 | | - } else { |
521 | | - $jsattribs['dateFormat'] = $other_args['date format']; |
522 | | - } |
523 | | - |
524 | | - } elseif ( $sfigSettings->datePickerDateFormat ) { |
525 | | - |
526 | | - if ( $sfigSettings->datePickerDateFormat == 'SHORT' ) { |
527 | | - $jsattribs['dateFormat'] = 'mm/dd/yy'; |
528 | | - } elseif ( $sfigSettings->datePickerDateFormat == 'LONG' ) { |
529 | | - $jsattribs['dateFormat'] = 'MM d, yy'; |
530 | | - } else { |
531 | | - $jsattribs['dateFormat'] = $sfigSettings->datePickerDateFormat; |
532 | | - } |
533 | | - |
534 | | - } else $jsattribs['dateFormat'] = 'yy/mm/dd'; |
535 | | - |
536 | | - } else { |
537 | | - |
538 | | - if ( array_key_exists( 'date format', $other_args ) ) { |
539 | | - |
540 | | - if ( $other_args['date format'] == 'SHORT' ) { |
541 | | - $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatshort' ); |
542 | | - } elseif ( $other_args['date format'] == 'LONG' ) { |
543 | | - $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatlong' ); |
544 | | - } else { |
545 | | - $jsattribs['dateFormat'] = $other_args['date format']; |
546 | | - } |
547 | | - |
548 | | - } elseif ( $sfigSettings->datePickerDateFormat ) { |
549 | | - |
550 | | - if ( $sfigSettings->datePickerDateFormat == 'SHORT' ) { |
551 | | - $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatshort' ); |
552 | | - } elseif ( $sfigSettings->datePickerDateFormat == 'LONG' ) { |
553 | | - $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatlong' ); |
554 | | - } else { |
555 | | - $jsattribs['dateFormat'] = $sfigSettings->datePickerDateFormat; |
556 | | - } |
557 | | - |
558 | | - } else $jsattribs['dateFormat'] = 'yy/mm/dd'; |
559 | | - |
560 | | - } |
561 | | - |
562 | | - // setup attributes required only for either disabled or enabled datepickers |
563 | | - if ( $is_disabled ) { |
564 | | - |
565 | | - $jsattribs['buttonImage'] = $sfigSettings->scriptPath . '/images/DatePickerButtonDisabled.gif'; |
566 | | - |
567 | | - if ( array_key_exists( 'show reset button', $other_args ) || |
568 | | - ( !array_key_exists( 'hide reset button', $other_args ) && $sfigSettings->datePickerShowResetButton ) ) { |
569 | | - |
570 | | - $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DatePickerResetButtonDisabled.gif'; |
571 | | - |
572 | | - } |
573 | | - |
574 | | - } else { |
575 | | - |
576 | | - $jsattribs['buttonImage'] = $sfigSettings->scriptPath . '/images/DatePickerButton.gif'; |
577 | | - |
578 | | - if ( array_key_exists( 'show reset button', $other_args ) || |
579 | | - ( !array_key_exists( 'hide reset button', $other_args ) && $sfigSettings->datePickerShowResetButton ) ) { |
580 | | - |
581 | | - $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DatePickerResetButton.gif'; |
582 | | - |
583 | | - } |
584 | | - |
585 | | - // find min date, max date and disabled dates |
586 | | - |
587 | | - // set first date |
588 | | - if ( array_key_exists( 'first date', $other_args ) ) { |
589 | | - $minDate = date_create( $other_args['first date'] ); |
590 | | - } elseif ( $sfigSettings->datePickerFirstDate ) { |
591 | | - $minDate = date_create( $sfigSettings->datePickerFirstDate ); |
592 | | - } else { |
593 | | - $minDate = null; |
594 | | - } |
595 | | - |
596 | | - // set last date |
597 | | - if ( array_key_exists( 'last date', $other_args ) ) { |
598 | | - $maxDate = date_create( $other_args['last date'] ); |
599 | | - } elseif ( $sfigSettings->datePickerLastDate ) { |
600 | | - $maxDate = date_create( $sfigSettings->datePickerLastDate ); |
601 | | - } else { |
602 | | - $maxDate = null; |
603 | | - } |
604 | | - |
605 | | - // find allowed values and invert them to get disabled values |
606 | | - if ( array_key_exists( 'possible_values', $other_args ) && count( $other_args['possible_values'] ) ) { |
607 | | - |
608 | | - $enabledDates = self::sortAndMergeRanges( self::createRangesArray( $other_args['possible_values'] ) ); |
609 | | - |
610 | | - // correct min/max date to the first/last allowed value |
611 | | - if ( !$minDate || $minDate < $enabledDates[0][0] ) { |
612 | | - $minDate = $enabledDates[0][0]; |
613 | | - } |
614 | | - |
615 | | - if ( !$maxDate || $maxDate > $enabledDates[count( $enabledDates ) - 1][1] ) { |
616 | | - $maxDate = $enabledDates[count( $enabledDates ) - 1][1]; |
617 | | - } |
618 | | - |
619 | | - $disabledDates = self::invertRangesArray( $enabledDates ); |
620 | | - |
621 | | - } else $disabledDates = array(); |
622 | | - |
623 | | - // add user-defined or default disabled values |
624 | | - if ( array_key_exists( 'disable dates', $other_args ) ) { |
625 | | - |
626 | | - $disabledDates = |
627 | | - self::sortAndMergeRanges( |
628 | | - array_merge( $disabledDates, self::createRangesArray( explode( ',' , $other_args['disable dates'] ) ) ) ); |
629 | | - |
630 | | - } elseif ( $sfigSettings->datePickerDisabledDates ) { |
631 | | - |
632 | | - $disabledDates = |
633 | | - self::sortAndMergeRanges( |
634 | | - array_merge( $disabledDates, self::createRangesArray( explode( ',' , $sfigSettings->datePickerDisabledDates ) ) ) ); |
635 | | - |
636 | | - } |
637 | | - |
638 | | - // if a minDate is set, discard all disabled dates below the min date |
639 | | - if ( $minDate ) { |
640 | | - |
641 | | - // discard all ranges of disabled dates that are entirely below the min date |
642 | | - while ( $minDate && count( $disabledDates ) && $disabledDates[0][1] < $minDate ) array_shift( $disabledDates ); |
643 | | - |
644 | | - // if min date is in first disabled date range, discard that range and adjust min date |
645 | | - if ( count( $disabledDates ) && $disabledDates[0][0] <= $minDate && $disabledDates[0][1] >= $minDate ) { |
646 | | - $minDate = $disabledDates[0][1]; |
647 | | - array_shift( $disabledDates ); |
648 | | - $minDate->modify( "+1 day" ); |
649 | | - } |
650 | | - } |
651 | | - |
652 | | - // if a maxDate is set, discard all disabled dates above the max date |
653 | | - if ( $maxDate ) { |
654 | | - |
655 | | - // discard all ranges of disabled dates that are entirely above the max date |
656 | | - while ( count( $disabledDates ) && $disabledDates[count( $disabledDates ) - 1][0] > $maxDate ) array_pop( $disabledDates ); |
657 | | - |
658 | | - // if max date is in last disabled date range, discard that range and adjust max date |
659 | | - if ( count( $disabledDates ) && $disabledDates[count( $disabledDates ) - 1][0] <= $maxDate && $disabledDates[count( $disabledDates ) - 1][1] >= $maxDate ) { |
660 | | - $maxDate = $disabledDates[count( $disabledDates ) - 1][0]; |
661 | | - array_pop( $disabledDates ); |
662 | | - $maxDate->modify( "-1 day" ); |
663 | | - } |
664 | | - } |
665 | | - // finished with disabled dates |
666 | | - |
667 | | - // find highlighted dates |
668 | | - if ( array_key_exists( "highlight dates", $other_args ) ) { |
669 | | - $highlightedDates = self::sortAndMergeRanges ( self::createRangesArray( explode( ',' , $other_args["highlight dates"] ) ) ) ; |
670 | | - } elseif ( $sfigSettings->datePickerHighlightedDates ) { |
671 | | - $highlightedDates = self::sortAndMergeRanges ( self::createRangesArray( explode( ',' , $sfigSettings->datePickerHighlightedDates ) ) ) ; |
672 | | - } else { |
673 | | - $highlightedDates = null; |
674 | | - } |
675 | | - |
676 | | - |
677 | | - // find disabled week days and mark them in an array |
678 | | - if ( array_key_exists( "disable days of week", $other_args ) ) { |
679 | | - $disabledDaysString = $other_args['disable days of week']; |
680 | | - } else { |
681 | | - $disabledDaysString = $sfigSettings->datePickerDisabledDaysOfWeek; |
682 | | - } |
683 | | - |
684 | | - if ( $disabledDaysString != null ) { |
685 | | - |
686 | | - $disabledDays = array( false, false, false, false, false, false, false ); |
687 | | - |
688 | | - foreach ( explode( ',', $disabledDaysString ) as $day ) { |
689 | | - |
690 | | - if ( is_numeric( $day ) && $day >= 0 && $day <= 6 ) { |
691 | | - $disabledDays[$day] = true; |
692 | | - } |
693 | | - |
694 | | - } |
695 | | - |
696 | | - } else { |
697 | | - $disabledDays = null; |
698 | | - } |
699 | | - |
700 | | - // find highlighted week days and mark them in an array |
701 | | - if ( array_key_exists( "highlight days of week", $other_args ) ) { |
702 | | - $highlightedDaysString = $other_args['highlight days of week']; |
703 | | - } else { |
704 | | - $highlightedDaysString = $sfigSettings->datePickerHighlightedDaysOfWeek; |
705 | | - } |
706 | | - |
707 | | - if ( $highlightedDaysString != null ) { |
708 | | - |
709 | | - $highlightedDays = array( false, false, false, false, false, false, false ); |
710 | | - |
711 | | - foreach ( explode( ',', $highlightedDaysString ) as $day ) { |
712 | | - |
713 | | - if ( is_numeric( $day ) && $day >= 0 && $day <= 6 ) { |
714 | | - $highlightedDays[$day] = true; |
715 | | - } |
716 | | - |
717 | | - } |
718 | | - |
719 | | - } else { |
720 | | - $highlightedDays = null; |
721 | | - } |
722 | | - |
723 | | - // set first day of the week |
724 | | - if ( array_key_exists( 'week start', $other_args ) ) { |
725 | | - $jsattribs['firstDay'] = $other_args['week start']; |
726 | | - } elseif ( $sfigSettings->datePickerWeekStart != null ) { |
727 | | - $jsattribs['firstDay'] = $sfigSettings->datePickerWeekStart; |
728 | | - } else { |
729 | | - $jsattribs['firstDay'] = wfMsg( 'semanticformsinputs-firstdayofweek' ); |
730 | | - } |
731 | | - |
732 | | - // set show week number |
733 | | - if ( array_key_exists( 'show week numbers', $other_args ) |
734 | | - || ( !array_key_exists( 'hide week numbers', $other_args ) && $sfigSettings->datePickerShowWeekNumbers ) ) { |
735 | | - |
736 | | - $jsattribs['showWeek'] = true; |
737 | | - } else { |
738 | | - $jsattribs['showWeek'] = false; |
739 | | - } |
740 | | - |
741 | | - // store min date as JS attrib |
742 | | - if ( $minDate ) { |
743 | | - $jsattribs['minDate'] = $minDate->format( 'Y/m/d' ); |
744 | | - } |
745 | | - |
746 | | - // store max date as JS attrib |
747 | | - if ( $maxDate ) { |
748 | | - $jsattribs['maxDate'] = $maxDate->format( 'Y/m/d' ); |
749 | | - } |
750 | | - |
751 | | - // register disabled dates with datepicker |
752 | | - if ( count( $disabledDates ) > 0 ) { |
753 | | - |
754 | | - // convert the PHP array of date ranges into an array of numbers |
755 | | - $jsattribs["disabledDates"] = array_map( create_function ( '$range', ' |
756 | | - |
757 | | - $y0 = $range[0]->format( "Y" ); |
758 | | - $m0 = $range[0]->format( "m" ) - 1; |
759 | | - $d0 = $range[0]->format( "d" ); |
760 | | - |
761 | | - $y1 = $range[1]->format( "Y" ); |
762 | | - $m1 = $range[1]->format( "m" ) - 1; |
763 | | - $d1 = $range[1]->format( "d" ); |
764 | | - |
765 | | - return array($y0, $m0, $d0, $y1, $m1, $d1); |
766 | | - ' ) , $disabledDates ); |
767 | | - } |
768 | | - |
769 | | - // register highlighted dates with datepicker |
770 | | - if ( count( $highlightedDates ) > 0 ) { |
771 | | - |
772 | | - // convert the PHP array of date ranges into an array of numbers |
773 | | - $jsattribs["highlightedDates"] = array_map( create_function ( '$range', ' |
774 | | - |
775 | | - $y0 = $range[0]->format( "Y" ); |
776 | | - $m0 = $range[0]->format( "m" ) - 1; |
777 | | - $d0 = $range[0]->format( "d" ); |
778 | | - |
779 | | - $y1 = $range[1]->format( "Y" ); |
780 | | - $m1 = $range[1]->format( "m" ) - 1; |
781 | | - $d1 = $range[1]->format( "d" ); |
782 | | - |
783 | | - return array($y0, $m0, $d0, $y1, $m1, $d1); |
784 | | - ' ) , $highlightedDates ); |
785 | | - } |
786 | | - |
787 | | - // register disabled days of week with datepicker |
788 | | - if ( count( $disabledDays ) > 0 ) { |
789 | | - $jsattribs["disabledDays"] = $disabledDays; |
790 | | - } |
791 | | - |
792 | | - // register highlighted days of week with datepicker |
793 | | - if ( count( $highlightedDays ) > 0 ) { |
794 | | - $jsattribs["highlightedDays"] = $highlightedDays; |
795 | | - } |
796 | | - } |
797 | | - |
798 | | - |
799 | | - // third: assemble HTML and JS code |
800 | | - |
801 | | - // start with the displayed input and append the real, but hidden |
802 | | - // input that gets sent to SF; it will be filled by the datepicker |
803 | | - $html = self::textHTML( $cur_value, "", $is_mandatory, $inputFieldDisabled, |
804 | | - $other_args, "input_{$sfgFieldNum}_dp_show", null, "createboxInput" ); |
805 | | - |
806 | | - if ( ! array_key_exists( 'part of dtp', $other_args ) ) { |
807 | | - |
808 | | - $html .= Xml::element( "input", |
809 | | - array( |
810 | | - "id" => "input_{$sfgFieldNum}", |
811 | | - "name" => $input_name, |
812 | | - "type" => "hidden", |
813 | | - "value" => $cur_value |
814 | | - ) ); |
815 | | - |
816 | | - // wrap in span (e.g. used for mandatory inputs) |
817 | | - $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>'; |
818 | | - } |
819 | | - |
820 | | - // build JS code from attributes array |
821 | | - $jsattribsString = Xml::encodeJsVar( $jsattribs ); |
822 | | - |
823 | | - // wrap the JS code fragment in a function for deferred init |
824 | | -// $jstext = <<<JAVASCRIPT |
825 | | -//jQuery(function(){ jQuery('#input_{$sfgFieldNum}_dp_show').SemanticForms_registerInputInit(SFI_DP_init, $jsattribsString ); }); |
826 | | -//JAVASCRIPT; |
827 | | -// |
828 | | - $jstext = <<<JAVASCRIPT |
829 | | -jQuery(function(){ jQuery('#input_{$sfgFieldNum}').SemanticForms_registerInputInit(SFI_DP_init, $jsattribsString ); }); |
830 | | -JAVASCRIPT; |
831 | | - |
832 | | - // insert the code of the JS init function into the pages code |
833 | | - $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' ); |
834 | | - |
835 | | - //return array( $html, "", "initInput$sfgFieldNum" ); |
836 | | - return $html; |
837 | | - |
838 | | - } |
839 | | - |
840 | | - /** |
841 | | - * Setup for input type jqdatepicker. |
842 | | - * |
843 | | - * Adds the Javascript code used by all datetimepickers. |
844 | | - */ |
845 | | - static private function datetimePickerSetup () { |
846 | | - |
847 | | - global $wgOut, $sfigSettings; |
848 | | - |
849 | | - static $hasRun = false; |
850 | | - |
851 | | - if ( !$hasRun ) { |
852 | | - $hasRun = true; |
853 | | - |
854 | | - $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/datetimepicker.js"></script> ' ); |
855 | | - |
856 | | - } |
857 | | - } |
858 | | - |
859 | | - /** |
860 | | - * Definition of input type "datetimepicker". |
861 | | - * |
862 | | - * Returns the html code to be included in the page and registers the |
863 | | - * input's JS initialisation method |
864 | | - * |
865 | | - * @param string $cur_value current value of this field (which is sometimes null) |
866 | | - * @param string $input_name HTML name that this input should have |
867 | | - * @param boolean $is_mandatory indicates whether this field is mandatory for the user |
868 | | - * @param boolean $is_disabled indicates whether this field is disabled (meaning, the user can't edit) |
869 | | - * @param array $other_args hash representing all the other properties defined for this input in the form definition |
870 | | - * @return string html code of input |
871 | | - */ |
872 | | - static function datetimepickerHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { |
873 | | - |
874 | | - global $wgOut, $sfgFieldNum, $sfigSettings; |
875 | | - |
876 | | - self::datetimePickerSetup(); |
877 | | - |
878 | | - $other_args["part of dtp"] = true; |
879 | | - |
880 | | - $jsattribs = array(); |
881 | | - |
882 | | - // if we have to show a reset button |
883 | | - if ( array_key_exists( 'show reset button', $other_args ) || |
884 | | - ( !array_key_exists( 'hide reset button', $other_args ) && $sfigSettings->datetimePickerShowResetButton ) ) { |
885 | | - |
886 | | - // some values must be available to the init function |
887 | | - |
888 | | - // is the button disabled? |
889 | | - $jsattribs['disabled'] = $is_disabled; |
890 | | - |
891 | | - // set the button image |
892 | | - if ( $is_disabled ) { |
893 | | - $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DateTimePickerResetButtonDisabled.gif'; |
894 | | - } else { |
895 | | - $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DateTimePickerResetButton.gif'; |
896 | | - } |
897 | | - |
898 | | - // set user classes |
899 | | - if ( array_key_exists( 'class', $other_args ) ) $jsattribs[ "userClasses" ] = $other_args['class']; |
900 | | - else $jsattribs[ "userClasses" ] = ""; |
901 | | - |
902 | | - } |
903 | | - |
904 | | - // find allowed values and keep only the date portion |
905 | | - if ( array_key_exists( 'possible_values', $other_args ) && |
906 | | - count( $other_args[ 'possible_values' ] ) ) { |
907 | | - |
908 | | - $other_args[ 'possible_values' ] = preg_replace( |
909 | | - '/^\s*(\d{4}\/\d{2}\/\d{2}).*/', |
910 | | - '$1', |
911 | | - $other_args[ 'possible_values' ] |
912 | | - ); |
913 | | - } |
914 | | - |
915 | | - $dateTimeString = trim( $cur_value ); |
916 | | - $dateString = ''; |
917 | | - $timeString = ''; |
918 | | - |
919 | | - $separatorPos = strpos($dateTimeString, " "); |
920 | | - |
921 | | - // does it have a separating whitespace? assume it's a date & time |
922 | | - if ( $separatorPos ) { |
923 | | - $dateString = substr( $dateTimeString, 0, $separatorPos ); |
924 | | - $timeString = substr( $dateTimeString, $separatorPos + 1 ); |
925 | | - |
926 | | - // does it start with a time of some kind? |
927 | | - } elseif ( preg_match( '/^\d?\d:\d\d/', $dateTimeString ) ) { |
928 | | - $timeString = $dateTimeString; |
929 | | - |
930 | | - // if all else fails assume it's a date |
931 | | - } else { |
932 | | - $dateString = $dateTimeString; |
933 | | - } |
934 | | - |
935 | | - $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' . |
936 | | - self::jqDatePickerHTML( $dateString, $input_name, $is_mandatory, $is_disabled, $other_args) . " " . |
937 | | - self::timepickerHTML( $timeString, $input_name, $is_mandatory, $is_disabled, $other_args) . |
938 | | - Xml::element("input", |
939 | | - array( |
940 | | - "id" => "input_{$sfgFieldNum}", |
941 | | - "name" => $input_name, |
942 | | - "type" => "hidden", |
943 | | - "value" => $cur_value |
944 | | - )) |
945 | | - . '</span>'; |
946 | | - |
947 | | - // build JS code from attributes array |
948 | | - $jsattribsString = Xml::encodeJsVar( $jsattribs ); |
949 | | - |
950 | | - $jstext = <<<JAVASCRIPT |
951 | | -jQuery(function(){ jQuery('#input_$sfgFieldNum').SemanticForms_registerInputInit(SFI_DTP_init, $jsattribsString ); }); |
952 | | -JAVASCRIPT; |
953 | | - |
954 | | - // insert the code of the JS init function into the pages code |
955 | | - $wgOut->addScript('<script type="text/javascript">' . $jstext . '</script>'); |
956 | | - |
957 | | - return $html; |
958 | | - } |
959 | | - |
960 | | -// |
961 | | -// static function wysiwygSetup() { |
962 | | -// |
963 | | -// } |
964 | | -// |
965 | | -// |
966 | | -// static function wysiwygHTML ( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
967 | | -// |
968 | | -// global $wgOut, $wgLang, $wgAmericanDates, $wgScriptPath, $wgFCKEditorDir; |
969 | | -// global $sfgFieldNum, $sfgScriptPath, $sfigSettings; |
970 | | -// global $sfgTabIndex, $sfgJSValidationCalls; // used to represent the current tab index in the form |
971 | | -// |
972 | | -// $htmltext = Html::element('textarea', array( |
973 | | -// 'id' => "input_$sfgFieldNum", |
974 | | -// 'class' => 'createboxInput', |
975 | | -// 'name' => $input_name, |
976 | | -// 'tabindex' => $sfgTabIndex, |
977 | | -// 'rows' => 25, |
978 | | -// 'cols' => 80 |
979 | | -// )); |
980 | | -// |
981 | | -// $jstext = <<<JAVASCRIPT |
982 | | -// addOnloadHook(function() |
983 | | -// { |
984 | | -// var oFCKeditor = new FCKeditor( 'input_$sfgFieldNum', '100%', '100%') ; |
985 | | -// oFCKeditor.BasePath = "$wgScriptPath/$wgFCKEditorDir/" ; |
986 | | -// oFCKeditor.ReplaceTextarea() ; |
987 | | -// }); |
988 | | -// |
989 | | -// JAVASCRIPT; |
990 | | -// |
991 | | -// $sfgJSValidationCalls[] = "function() {document.getElementById('input_$sfgFieldNum').value = FCKeditorAPI.GetInstance('input_$sfgFieldNum').GetHtml();return true;}"; |
992 | | -// |
993 | | -// $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' ); |
994 | | -// return array( $htmltext, "" ); |
995 | | -// } |
996 | | -// |
997 | | - |
998 | | - |
999 | | - /** |
1000 | | - * Setup for input type "timepicker". |
1001 | | - * |
1002 | | - * Adds the Javascript code and css used by all timepickers. |
1003 | | - */ |
1004 | | - static private function timepickerSetup() { |
1005 | | - |
1006 | | - global $sfigSettings, $wgOut; |
1007 | | - |
1008 | | - static $hasRun = false; |
1009 | | - |
1010 | | - if ( !$hasRun ) { |
1011 | | - |
1012 | | - $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/timepicker.js"></script> ' ); |
1013 | | - $wgOut->addExtensionStyle( $sfigSettings->scriptPath . '/skins/SFI_Timepicker.css' ); |
1014 | | - |
1015 | | - } |
1016 | | - |
1017 | | - } |
1018 | | - |
1019 | | - /** |
1020 | | - * Definition of input type "timepicker" |
1021 | | - * |
1022 | | - * Returns the html code to be included in the page and registers the |
1023 | | - * input's JS initialisation method |
1024 | | - * |
1025 | | - * @param string $cur_value current value of this field (which is sometimes null) |
1026 | | - * @param string $input_name HTML name that this input should have |
1027 | | - * @param boolean $is_mandatory indicates whether this field is mandatory for the user |
1028 | | - * @param boolean $is_disabled indicates whether this field is disabled (meaning, the user can't edit) |
1029 | | - * @param array $other_args hash representing all the other properties defined for this input in the form definition |
1030 | | - * @return string html code of input |
1031 | | - */ |
1032 | | - static function timepickerHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
1033 | | - |
1034 | | - global $wgOut; |
1035 | | - global $sfgFieldNum; |
1036 | | - global $sfigSettings; |
1037 | | - |
1038 | | - // The timepicker is created in four steps: |
1039 | | - // first: set up HTML attributes |
1040 | | - // second: assemble HTML |
1041 | | - // third: set up JS attributes |
1042 | | - // fourth: assemble JS call |
1043 | | - |
1044 | | - |
1045 | | - // first: set up HTML attributes |
1046 | | - $inputFieldDisabled = |
1047 | | - array_key_exists( 'disable input field', $other_args ) |
1048 | | - || ( !array_key_exists( 'enable input field', $other_args ) && $sfigSettings->timePickerDisableInputField ) |
1049 | | - || $is_disabled ; |
1050 | | - |
1051 | | - if ( array_key_exists( 'class', $other_args ) ) $userClasses = $other_args['class']; |
1052 | | - else $userClasses = ""; |
1053 | | - |
1054 | | - // second: assemble HTML |
1055 | | - // create visible input field (for display) and invisible field (for data) |
1056 | | - $html = self::textHTML( $cur_value, '', $is_mandatory, $inputFieldDisabled, $other_args, "input_{$sfgFieldNum}_tp_show", null, "createboxInput" ); |
1057 | | - |
1058 | | - if ( ! array_key_exists( 'part of dtp', $other_args ) ) { |
1059 | | - $html .= Xml::element( "input", array( |
1060 | | - 'id' => "input_{$sfgFieldNum}", |
1061 | | - 'type' => 'hidden', |
1062 | | - 'name' => $input_name, |
1063 | | - 'value' => $cur_value |
1064 | | - ) ); |
1065 | | - } |
1066 | | - |
1067 | | - // append time picker button |
1068 | | - if ( $is_disabled ) { |
1069 | | - |
1070 | | - $html .= Xml::openElement( |
1071 | | - "button", |
1072 | | - array( |
1073 | | - 'type' => 'button', |
1074 | | - 'class' => 'createboxInput ' . $userClasses, |
1075 | | - 'disabled' => '1', |
1076 | | - 'id' => "input_{$sfgFieldNum}_button" |
1077 | | - ) ) |
1078 | | - |
1079 | | - . Xml::element( |
1080 | | - "image", |
1081 | | - array( 'src' => $sfigSettings->scriptPath . '/images/TimePickerButtonDisabled.gif' ) |
1082 | | - ) |
1083 | | - |
1084 | | - . Xml::closeElement( "button" ); |
1085 | | - |
1086 | | - } else { |
1087 | | - |
1088 | | - $html .= "<button " |
1089 | | - . Xml::expandAttributes ( array( |
1090 | | - 'type' => 'button', |
1091 | | - 'class' => 'createboxInput ' . $userClasses, |
1092 | | - 'name' => "button", |
1093 | | - ) ) |
1094 | | - . " onclick=\"document.getElementById(this.id.replace('_button','_tp_show')).focus();\"" |
1095 | | - . ">" |
1096 | | - |
1097 | | - . Xml::element( |
1098 | | - "image", |
1099 | | - array( 'src' => $sfigSettings->scriptPath . '/images/TimePickerButton.gif' ) |
1100 | | - ) |
1101 | | - |
1102 | | - . Xml::closeElement( "button" ); |
1103 | | - |
1104 | | - } |
1105 | | - |
1106 | | - // append reset button (if selected) |
1107 | | - if ( ! array_key_exists( 'part of dtp', $other_args ) && |
1108 | | - ( array_key_exists( 'show reset button', $other_args ) || |
1109 | | - $sfigSettings->timePickerShowResetButton && !array_key_exists( 'hide reset button', $other_args ) |
1110 | | - ) |
1111 | | - ) { |
1112 | | - |
1113 | | - if ( $is_disabled ) { |
1114 | | - |
1115 | | - $html .= Xml::openElement( |
1116 | | - "button", |
1117 | | - array( |
1118 | | - 'type' => 'button', |
1119 | | - 'class' => 'createboxInput ' . $userClasses, |
1120 | | - 'disabled' => '1', |
1121 | | - 'id' => "input_{$sfgFieldNum}_resetbutton" |
1122 | | - ) ) |
1123 | | - |
1124 | | - . Xml::element( |
1125 | | - "image", |
1126 | | - array( 'src' => $sfigSettings->scriptPath . '/images/TimePickerResetButtonDisabled.gif' ) |
1127 | | - |
1128 | | - ) |
1129 | | - . Xml::closeElement( "button" ); |
1130 | | - |
1131 | | - } else { |
1132 | | - |
1133 | | - $html .= "<button " |
1134 | | - . Xml::expandAttributes ( array( |
1135 | | - 'type' => 'button', |
1136 | | - 'class' => 'createboxInput ' . $userClasses, |
1137 | | - 'name' => "resetbutton", |
1138 | | - ) ) |
1139 | | - . " onclick=\"document.getElementById(this.id.replace('_resetbutton','')).value='';" |
1140 | | - . "document.getElementById(this.id.replace('_resetbutton','_tp_show')).value='';\"" |
1141 | | - . ">" |
1142 | | - |
1143 | | - . Xml::element( |
1144 | | - "image", |
1145 | | - array( 'src' => $sfigSettings->scriptPath . '/images/TimePickerResetButton.gif' ) |
1146 | | - |
1147 | | - ) |
1148 | | - . Xml::closeElement( "button" ); |
1149 | | - |
1150 | | - } |
1151 | | - } |
1152 | | - |
1153 | | - // wrap in span (e.g. used for mandatory inputs) |
1154 | | - if ( ! array_key_exists( 'part of dtp', $other_args ) ) { |
1155 | | - $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>'; |
1156 | | - } |
1157 | | - |
1158 | | - // third: if the timepicker is not disabled set up JS attributes ans assemble JS call |
1159 | | - if ( !$is_disabled ) { |
1160 | | - |
1161 | | - self::timepickerSetup(); |
1162 | | - |
1163 | | - // set min time if valid, else use default |
1164 | | - if ( array_key_exists( 'mintime', $other_args ) |
1165 | | - && ( preg_match( '/^\d+:\d\d$/', trim( $other_args['mintime'] ) ) == 1 ) ) { |
1166 | | - $minTime = trim( $other_args[ 'mintime' ] ); |
1167 | | - } elseif ( $sfigSettings->timePickerMinTime != null ) { |
1168 | | - $minTime = $sfigSettings->timePickerMinTime ; |
1169 | | - } else { |
1170 | | - $minTime = '00:00'; |
1171 | | - } |
1172 | | - |
1173 | | - // set max time if valid, else use default |
1174 | | - if ( array_key_exists( 'maxtime', $other_args ) |
1175 | | - && ( preg_match( '/^\d+:\d\d$/', trim( $other_args['maxtime'] ) ) == 1 ) ) { |
1176 | | - $maxTime = trim( $other_args[ 'maxtime' ] ); |
1177 | | - } elseif ( $sfigSettings->timePickerMaxTime != null ) { |
1178 | | - $maxTime = $sfigSettings->timePickerMaxTime ; |
1179 | | - } else { |
1180 | | - $maxTime = '23:59'; |
1181 | | - } |
1182 | | - |
1183 | | - // set interval if valid, else use default |
1184 | | - if ( array_key_exists( 'interval', $other_args ) |
1185 | | - && preg_match( '/^\d+$/', trim( $other_args['interval'] ) ) == 1 ) { |
1186 | | - $interval = trim( $other_args[ 'interval' ] ); |
1187 | | - } else { |
1188 | | - $interval = '15'; |
1189 | | - } |
1190 | | - |
1191 | | - // build JS code from attributes array |
1192 | | - $jsattribs = array( |
1193 | | - "minTime" => $minTime, |
1194 | | - "maxTime" => $maxTime, |
1195 | | - "interval" => $interval, |
1196 | | - "format" => "hh:mm" |
1197 | | - ); |
1198 | | - |
1199 | | - if ( array_key_exists( 'part of dtp', $other_args ) ) { |
1200 | | - $jsattribs['partOfDTP'] = $other_args['part of dtp']; |
1201 | | - } |
1202 | | - |
1203 | | - $jstext = Xml::encodeJsVar( $jsattribs ); |
1204 | | - |
1205 | | - $jstext = <<<JAVASCRIPT |
1206 | | -jQuery(function(){ jQuery('#input_{$sfgFieldNum}_tp_show').SemanticForms_registerInputInit(SFI_TP_init, $jstext ); }); |
1207 | | -JAVASCRIPT; |
1208 | | - |
1209 | | - // write JS code directly to the page's code |
1210 | | - $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' ); |
1211 | | - |
1212 | | - // return HTML and name of JS init function |
1213 | | - |
1214 | | - } |
1215 | | - |
1216 | | - return $html; |
1217 | | - |
1218 | | - } |
1219 | | - |
1220 | | - static function menuselectSetGlobalVars(&$vars) { |
1221 | | - global $sfigSettings; |
1222 | | - $vars['sfigScriptPath'] = $sfigSettings->scriptPath; |
1223 | | - return true; |
1224 | | - } |
1225 | | - |
1226 | | - /** |
1227 | | - * Setup for input type "menuselect". |
1228 | | - * Adds the Javascript code and css used by all menuselects. |
1229 | | - */ |
1230 | | - static private function menuselectSetup() { |
1231 | | - |
1232 | | - global $wgOut, $wgHooks; |
1233 | | - global $sfigSettings; |
1234 | | - |
1235 | | - static $hasRun = false; |
1236 | | - |
1237 | | - if ( !$hasRun ) { |
1238 | | - |
1239 | | - $hasRun = true; |
1240 | | - |
1241 | | - $wgHooks['MakeGlobalVariablesScript'][] = 'SFIInputs::menuselectSetGlobalVars'; |
1242 | | - |
1243 | | - $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/menuselect.js"></script> ' ); |
1244 | | - $wgOut->addExtensionStyle( $sfigSettings->scriptPath . '/skins/SFI_Menuselect.css' ); |
1245 | | - |
1246 | | - } |
1247 | | - |
1248 | | - } |
1249 | | - |
1250 | | - /** |
1251 | | - * Definition of input type "menuselect" |
1252 | | - * |
1253 | | - * Returns the html code to be included in the page and registers the |
1254 | | - * input's JS initialisation method |
1255 | | - * |
1256 | | - * @param string $cur_value current value of this field (which is sometimes null) |
1257 | | - * @param string $input_name HTML name that this input should have |
1258 | | - * @param boolean $is_mandatory indicates whether this field is mandatory for the user |
1259 | | - * @param boolean $is_disabled indicates whether this field is disabled (meaning, the user can't edit) |
1260 | | - * @param array $other_args hash representing all the other properties defined for this input in the form definition |
1261 | | - * @return string html code of input |
1262 | | - */ |
1263 | | - static function menuselectHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
1264 | | - global $wgParser, $wgUser, $wgTitle, $wgOut; |
1265 | | - global $sfgFieldNum; |
1266 | | - global $sfigSettings; |
1267 | | - |
1268 | | - self::menuselectSetup(); |
1269 | | - |
1270 | | - // first: set up HTML attributes |
1271 | | - $inputFieldDisabled = |
1272 | | - array_key_exists( 'disable input field', $other_args ) |
1273 | | - || ( !array_key_exists( 'enable input field', $other_args ) && $sfigSettings->timePickerDisableInputField ) |
1274 | | - || $is_disabled ; |
1275 | | - |
1276 | | - // second: assemble HTML |
1277 | | - // create visible input field (for display) and invisible field (for data) |
1278 | | - $html = self::textHTML( $cur_value, '', $is_mandatory, $inputFieldDisabled, $other_args, "input_{$sfgFieldNum}_show", null, "createboxInput" ) |
1279 | | - . Xml::element( "input", array( |
1280 | | - 'id' => "input_{$sfgFieldNum}", |
1281 | | - 'type' => 'hidden', |
1282 | | - 'name' => $input_name, |
1283 | | - 'value' => $cur_value |
1284 | | - ) ); |
1285 | | - |
1286 | | - |
1287 | | - $html .= "<span class='SFI_menuselect' id='span_{$sfgFieldNum}_tree'>"; |
1288 | | - |
1289 | | - |
1290 | | - // parse menu structure |
1291 | | - |
1292 | | - $parser = new Parser(); |
1293 | | - |
1294 | | - // FIXME: SF does not parse options correctly. Users have to replace | by {{!}} |
1295 | | - $structure = str_replace( '{{!}}', '|', $other_args["structure"] ); |
1296 | | - $options = ParserOptions::newFromUser( $wgUser ); |
1297 | | - |
1298 | | - $structure = $parser->parse( $structure, $wgTitle, $options )->getText(); |
1299 | | - |
1300 | | -// $wgParser->mStripState = $oldStripState; |
1301 | | - |
1302 | | - |
1303 | | - $html .= str_replace( '<li', '<li class=\'ui-state-default\'', $structure ); |
1304 | | - |
1305 | | - $html .= "</span>"; |
1306 | | - |
1307 | | - // wrap in span (e.g. used for mandatory inputs) |
1308 | | - $html = '<span class="inputSpan' . ($is_mandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>'; |
1309 | | - |
1310 | | - $jstext = <<<JAVASCRIPT |
1311 | | -jQuery(function(){ jQuery('#input_$sfgFieldNum').SemanticForms_registerInputInit(SFI_MS_init, null ); }); |
1312 | | -JAVASCRIPT; |
1313 | | - |
1314 | | - // write JS code directly to the page's code |
1315 | | - $wgOut->addScript( '<script type="text/javascript">' . $jstext . '</script>' ); |
1316 | | - |
1317 | | -// return array( $html, "", "SFI_MS_init" ); |
1318 | | - |
1319 | | - return $html; |
1320 | | - } |
1321 | | -} |
Index: trunk/extensions/SemanticFormsInputs/SemanticFormsInputs.i18n.php |
— | — | @@ -14,9 +14,37 @@ |
15 | 15 | 'semanticformsinputs-today' => 'Today', |
16 | 16 | 'semanticformsinputs-dateformatlong' => 'd MM yy', // see http://docs.jquery.com/UI/Datepicker/formatDate |
17 | 17 | 'semanticformsinputs-dateformatshort' => 'dd/mm/yy', // see http://docs.jquery.com/UI/Datepicker/formatDate |
18 | | - 'semanticformsinputs-firstdayofweek' => '0' // 0 - sunday, 1 - monday... |
19 | | -); |
| 18 | + 'semanticformsinputs-firstdayofweek' => '0', // 0 - sunday, 1 - monday... |
20 | 19 | |
| 20 | + 'semanticformsinputs-datepicker-dateformat' => 'The date format string. See the [http://www.mediawiki.org/w/index.php?title=Extension:Semantic_Forms_Inputs&fromsection=Date_picker#Parameters online documentation] for more information.', |
| 21 | + 'semanticformsinputs-datepicker-weekstart' => 'The first day of the week (0 - Sunday, 1 - Monday, ...).', |
| 22 | + 'semanticformsinputs-datepicker-firstdate' => 'The first date that can be chosen (in yyyy/mm/dd format).', |
| 23 | + 'semanticformsinputs-datepicker-lastdate' => 'The last date that can be chosen (in yyyy/mm/dd format).', |
| 24 | + 'semanticformsinputs-datepicker-disabledaysofweek' => 'A list of days that can not be selected (e.g. weekend: 6, 0).', |
| 25 | + 'semanticformsinputs-datepicker-highlightdaysofweek' => 'A list of days that shall appear highlighted (e.g. weekend: 6, 0).', |
| 26 | + 'semanticformsinputs-datepicker-disabledates' => 'A comma-separated list of disabled dates/date ranges (dates in yyyy/mm/dd format, ranges in yyyy/mm/dd-yyyy/mm/dd format).', |
| 27 | + 'semanticformsinputs-datepicker-highlightdates' => 'A comma-separated list of dates/date ranges that shall appear highlighted (dates in yyyy/mm/dd format, ranges in yyyy/mm/dd-yyyy/mm/dd format).', |
| 28 | + 'semanticformsinputs-datepicker-showweeknumbers' => 'Should week numbers be shown left of the week?', |
| 29 | + 'semanticformsinputs-datepicker-enableinputfield' => 'Should the user be able to fill the input field directly or only via the date picker?', |
| 30 | + 'semanticformsinputs-datepicker-showresetbutton' => 'Should a reset button be shown? This is the only way for the user to erase the input field if it is disabled for direct input.', |
| 31 | + |
| 32 | + 'semanticformsinputs-timepicker-mintime' => 'The earliest time to show. Format: hh:mm', |
| 33 | + 'semanticformsinputs-timepicker-maxtime' => 'The latest time to show. Format: hh:mm', |
| 34 | + 'semanticformsinputs-timepicker-interval' => 'Interval between minutes. Number between 1 and 60.', |
| 35 | + 'semanticformsinputs-timepicker-enableinputfield' => 'Should the user be able to fill the input field directly or only via the date picker?', |
| 36 | + 'semanticformsinputs-timepicker-showresetbutton' => 'Should a reset button be shown? This is the only way for the user to erase the input field if it is disabled for direct input.', |
| 37 | + |
| 38 | + 'semanticformsinputs-regexp-regexp' => 'The regular expression the input has to match to be valid. This must be given including the slashes! Defaults to "/.*/", i.e. any value.', |
| 39 | + 'semanticformsinputs-regexp-basetype' => 'The base type to be used. May be any input type that generates an html form element of type input or select (e.g. text, listbox, datepicker) or another regexp. Defaults to "text".', |
| 40 | + 'semanticformsinputs-regexp-baseprefix' => 'Prefix for the parameters of the base type.', |
| 41 | + 'semanticformsinputs-regexp-orchar' => 'The OR-character to be used in the regular expression instead of |. Defaults to "!"', |
| 42 | + 'semanticformsinputs-regexp-inverse' => 'If set, the input must NOT match the regular expression to be valid. I.e. the regular expression is inverted.', |
| 43 | + 'semanticformsinputs-regexp-message' => 'The error message to be displayed if the match fails. Defaults to "Wrong format!" (or equivalent in the current locale)', |
| 44 | + |
| 45 | + 'semanticformsinputs-menuselect-structure' => 'The menu structure as an unordered list.', |
| 46 | + 'semanticformsinputs-menuselect-enableinputfield' => 'Should the user be able to fill the input field directly?', |
| 47 | + ); |
| 48 | + |
21 | 49 | /** Message documentation (Message documentation) |
22 | 50 | * @author EugeneZelenko |
23 | 51 | * @author F.trott |
Index: trunk/extensions/SemanticFormsInputs/SemanticFormsInputs.php |
— | — | @@ -16,13 +16,17 @@ |
17 | 17 | */ |
18 | 18 | |
19 | 19 | if ( !defined( 'MEDIAWIKI' ) ) { |
20 | | - die( 'This file is a MediaWiki extension, it is not a valid entry point.' ); |
| 20 | + die( 'This file is part of a MediaWiki extension, it is not a valid entry point.' ); |
21 | 21 | } |
22 | 22 | |
23 | 23 | if ( !defined( 'SF_VERSION' ) ) { |
24 | 24 | die( '<b>Error:</b> <a href="https://www.mediawiki.org/wiki/Extension:Semantic_Forms_Inputs">Semantic Forms Inputs</a> is a Semantic Forms extension. You need to install <a href="https://www.mediawiki.org/wiki/Extension:Semantic_Forms">Semantic Forms</a> first.' ); |
25 | 25 | } |
26 | 26 | |
| 27 | +if ( version_compare( '2.3', SF_VERSION ) != -1 ) { |
| 28 | + die( '<b>Error:</b> This version of <a href="https://www.mediawiki.org/wiki/Extension:Semantic_Forms_Inputs">Semantic Forms Inputs</a> is only compatible with Semantic Forms 2.4 or above. You need to upgrade <a href="https://www.mediawiki.org/wiki/Extension:Semantic_Forms">Semantic Forms</a> first.' ); |
| 29 | +} |
| 30 | + |
27 | 31 | define( 'SFI_VERSION', '0.4.2 alpha' ); |
28 | 32 | |
29 | 33 | // create and initialize settings |
— | — | @@ -41,12 +45,18 @@ |
42 | 46 | $dir = dirname( __FILE__ ); |
43 | 47 | |
44 | 48 | // load user settings |
45 | | -require_once( $dir . '/SFI_Settings.php' ); |
| 49 | +require_once( $dir . '/includes/SFI_Settings.php' ); |
46 | 50 | |
47 | 51 | $wgExtensionMessagesFiles['SemanticFormsInputs'] = $dir . '/SemanticFormsInputs.i18n.php'; |
48 | | -$wgExtensionFunctions[] = 'wfSFISetup'; |
49 | | -$wgAutoloadClasses['SFIInputs'] = $dir . '/SFI_Inputs.php'; |
| 52 | +$wgHooks['ParserFirstCallInit'][] = 'wfSFISetup'; |
50 | 53 | |
| 54 | +$wgAutoloadClasses['SFIUtils'] = $dir . '/includes/SFI_Utils.php'; |
| 55 | +$wgAutoloadClasses['SFIDatePicker'] = $dir . '/includes/SFI_DatePicker.php'; |
| 56 | +$wgAutoloadClasses['SFITimePicker'] = $dir . '/includes/SFI_TimePicker.php'; |
| 57 | +$wgAutoloadClasses['SFIDateTimePicker'] = $dir . '/includes/SFI_DateTimePicker.php'; |
| 58 | +$wgAutoloadClasses['SFIMenuSelect'] = $dir . '/includes/SFI_MenuSelect.php'; |
| 59 | +$wgAutoloadClasses['SFIRegExp'] = $dir . '/includes/SFI_RegExp.php'; |
| 60 | + |
51 | 61 | /** |
52 | 62 | * Class to encapsulate all settings |
53 | 63 | */ |
— | — | @@ -77,16 +87,16 @@ |
78 | 88 | function wfSFISetup() { |
79 | 89 | global $sfgFormPrinter, $wgVersion; |
80 | 90 | |
81 | | - $sfgFormPrinter->setInputTypeHook( 'regexp', array( 'SFIInputs', 'regexpHTML' ), array() ); |
82 | | - $sfgFormPrinter->setInputTypeHook( 'datepicker', array( 'SFIInputs', 'jqDatePickerHTML' ), array() ); |
83 | | - $sfgFormPrinter->setInputTypeHook( 'simpledatepicker', array( 'SFIInputs', 'jqDatePickerHTML' ), array() ); |
84 | | - $sfgFormPrinter->setInputTypeHook( 'timepicker', array( 'SFIInputs', 'timepickerHTML' ), array() ); |
85 | | - $sfgFormPrinter->setInputTypeHook( 'datetimepicker', array( 'SFIInputs', 'datetimepickerHTML' ), array() ); |
86 | | -// $sfgFormPrinter->setInputTypeHook( 'wysiwyg', array( 'SFIInputs', 'wysiwygHTML' ), array() ); |
87 | | - $sfgFormPrinter->setInputTypeHook( 'menuselect', array( 'SFIInputs', 'menuselectHTML' ), array() ); |
88 | | - |
| 91 | + $sfgFormPrinter->registerInputType( 'SFIDatePicker' ); |
| 92 | + $sfgFormPrinter->registerInputType( 'SFITimePicker' ); |
| 93 | + $sfgFormPrinter->registerInputType( 'SFIDateTimePicker' ); |
| 94 | + $sfgFormPrinter->registerInputType( 'SFIMenuSelect' ); |
| 95 | + $sfgFormPrinter->registerInputType( 'SFIRegExp' ); |
| 96 | + |
89 | 97 | // This function has been deprecated in 1.16, but needed for earlier versions. |
90 | 98 | if ( version_compare( $wgVersion, '1.16', '<' ) ) { |
91 | 99 | wfLoadExtensionMessages( 'SemanticFormsInputs' ); |
92 | 100 | } |
| 101 | + |
| 102 | + return true; |
93 | 103 | } |
Index: trunk/extensions/SemanticFormsInputs/includes/SFI_DateTimePicker.php |
— | — | @@ -0,0 +1,234 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SFI_DateTimePicker class |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticFormsInputs |
| 10 | + */ |
| 11 | +if ( !defined( 'SFI_VERSION' ) ) { |
| 12 | + die( 'This file is part of the SemanticFormsInputs extension, it is not a valid entry point.' ); |
| 13 | +} |
| 14 | + |
| 15 | +/** |
| 16 | + * The SFIDateTimePicker class. |
| 17 | + * |
| 18 | + * @ingroup SemanticFormsInputs |
| 19 | + */ |
| 20 | +class SFIDateTimePicker extends SFFormInput { |
| 21 | + |
| 22 | + protected $mDatePicker; |
| 23 | + protected $mTimePicker; |
| 24 | + |
| 25 | + /** |
| 26 | + * Constructor. |
| 27 | + * |
| 28 | + * @param String $input_number |
| 29 | + * The number of the input in the form. |
| 30 | + * @param String $cur_value |
| 31 | + * The current value of the input field. |
| 32 | + * @param String $input_name |
| 33 | + * The name of the input. |
| 34 | + * @param String $disabled |
| 35 | + * Is this input disabled? |
| 36 | + * @param Array $other_args |
| 37 | + * An associative array of other parameters that were present in the |
| 38 | + * input definition. |
| 39 | + */ |
| 40 | + public function __construct( $input_number, $cur_value, $input_name, $disabled, $other_args ) { |
| 41 | + |
| 42 | + parent::__construct( $input_number, $cur_value, $input_name, $disabled, $other_args ); |
| 43 | + |
| 44 | + self::setup(); |
| 45 | + |
| 46 | + // add JS data |
| 47 | + $this->addJsInitFunctionData( 'SFI_DTP_init', $this->setupJsInitAttribs() ); |
| 48 | + |
| 49 | + // prepare sub-inputs |
| 50 | + |
| 51 | + $this->mOtherArgs["part of dtp"] = true; |
| 52 | + |
| 53 | + // find allowed values and keep only the date portion |
| 54 | + if ( array_key_exists( 'possible_values', $this->mOtherArgs ) && |
| 55 | + count( $this->mOtherArgs[ 'possible_values' ] ) ) { |
| 56 | + |
| 57 | + $this->mOtherArgs[ 'possible_values' ] = preg_replace( |
| 58 | + '/^\s*(\d{4}\/\d{2}\/\d{2}).*/', |
| 59 | + '$1', |
| 60 | + $this->mOtherArgs[ 'possible_values' ] |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + $dateTimeString = trim( $this->mCurrentValue ); |
| 65 | + $dateString = ''; |
| 66 | + $timeString = ''; |
| 67 | + |
| 68 | + $separatorPos = strpos($dateTimeString, " "); |
| 69 | + |
| 70 | + // does it have a separating whitespace? assume it's a date & time |
| 71 | + if ( $separatorPos ) { |
| 72 | + $dateString = substr( $dateTimeString, 0, $separatorPos ); |
| 73 | + $timeString = substr( $dateTimeString, $separatorPos + 1 ); |
| 74 | + |
| 75 | + // does it start with a time of some kind? |
| 76 | + } elseif ( preg_match( '/^\d?\d:\d\d/', $dateTimeString ) ) { |
| 77 | + $timeString = $dateTimeString; |
| 78 | + |
| 79 | + // if all else fails assume it's a date |
| 80 | + } else { |
| 81 | + $dateString = $dateTimeString; |
| 82 | + } |
| 83 | + |
| 84 | + $this->mDatePicker = new SFIDatePicker( $this->mInputNumber, $dateString, $this->mInputName, $this->mIsDisabled, $this->mOtherArgs ); |
| 85 | + $this->mTimePicker = new SFITimePicker( $this->mInputNumber, $timeString, $this->mInputName, $this->mIsDisabled, $this->mOtherArgs ); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Returns the name of the input type this class handles: menuselect. |
| 90 | + * |
| 91 | + * This is the name to be used in the field definition for the "input type" |
| 92 | + * parameter. |
| 93 | + * |
| 94 | + * @return String The name of the input type this class handles. |
| 95 | + */ |
| 96 | + public static function getName() { |
| 97 | + return 'datetimepicker'; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Static setup method for input type "menuselect". |
| 102 | + * Adds the Javascript code and css used by all menuselects. |
| 103 | + */ |
| 104 | + static private function setup() { |
| 105 | + |
| 106 | + global $wgOut; |
| 107 | + global $sfigSettings; |
| 108 | + |
| 109 | + static $hasRun = false; |
| 110 | + |
| 111 | + if ( !$hasRun ) { |
| 112 | + $hasRun = true; |
| 113 | + |
| 114 | + $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/datetimepicker.js"></script> ' ); |
| 115 | + |
| 116 | + } |
| 117 | + |
| 118 | + } |
| 119 | + |
| 120 | + protected function setupJsInitAttribs() { |
| 121 | + |
| 122 | + global $sfigSettings; |
| 123 | + |
| 124 | + $jsattribs = array(); |
| 125 | + |
| 126 | + // if we have to show a reset button |
| 127 | + if ( array_key_exists( 'show reset button', $this->mOtherArgs ) || |
| 128 | + ( !array_key_exists( 'hide reset button', $this->mOtherArgs ) && $sfigSettings->datetimePickerShowResetButton ) ) { |
| 129 | + |
| 130 | + // some values must be available to the init function |
| 131 | + |
| 132 | + // is the button disabled? |
| 133 | + $jsattribs['disabled'] = $this->mIsDisabled; |
| 134 | + |
| 135 | + // set the button image |
| 136 | + if ( $this->mIsDisabled ) { |
| 137 | + $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DateTimePickerResetButtonDisabled.gif'; |
| 138 | + } else { |
| 139 | + $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DateTimePickerResetButton.gif'; |
| 140 | + } |
| 141 | + |
| 142 | + // set user classes |
| 143 | + if ( array_key_exists( 'class', $this->mOtherArgs ) ) $jsattribs[ 'userClasses' ] = $this->mOtherArgs['class']; |
| 144 | + else $jsattribs[ 'userClasses' ] = ''; |
| 145 | + |
| 146 | + } |
| 147 | + |
| 148 | + // build JS code from attributes array |
| 149 | + return Xml::encodeJsVar( $jsattribs ); |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Returns the HTML code to be included in the output page for this input. |
| 154 | + * |
| 155 | + * Ideally this HTML code should provide a basic functionality even if the |
| 156 | + * browser is not Javascript capable. I.e. even without Javascript the user |
| 157 | + * should be able to input values. |
| 158 | + * |
| 159 | + */ |
| 160 | + public function getHtmlText(){ |
| 161 | + |
| 162 | + global $wgOut, $sfgFieldNum, $sfigSettings; |
| 163 | + |
| 164 | + $html = '<span class="inputSpan' . ( array_key_exists( 'mandatory', $this->mOtherArgs) ? ' mandatoryFieldSpan' : '') . '">' . |
| 165 | + $this->mDatePicker->getHtmlText() . " " . |
| 166 | + $this->mTimePicker->getHtmlText() . |
| 167 | + Xml::element("input", |
| 168 | + array( |
| 169 | + "id" => "input_{$this->mInputNumber}", |
| 170 | + "name" => $this->mInputName, |
| 171 | + "type" => "hidden", |
| 172 | + "value" => $this->mCurrentValue |
| 173 | + )) |
| 174 | + . '</span>'; |
| 175 | + |
| 176 | + return $html; |
| 177 | + |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | + * Returns the set of SMW property types which this input can |
| 182 | + * handle, but for which it isn't the default input. |
| 183 | + */ |
| 184 | + public static function getOtherPropTypesHandled() { |
| 185 | + return array( '_str', '_dat' ); |
| 186 | + } |
| 187 | + |
| 188 | + /** |
| 189 | + * Returns the set of parameters for this form input. |
| 190 | + * |
| 191 | + * TODO: Specify parameters specific for menuselect. |
| 192 | + */ |
| 193 | + public static function getParameters() { |
| 194 | + $params = parent::getParameters(); |
| 195 | + |
| 196 | + $params[] = array( |
| 197 | + 'name' => 'structure', |
| 198 | + 'type' => 'text', |
| 199 | + 'description' => wfMsg( 'semanticformsinputs-menuselect-structure' ), |
| 200 | + 'default' => "* item 1\n** item 11\n** item 12\n* item 2\n** item 21\n** item 22" |
| 201 | + ); |
| 202 | + $params[] = array( |
| 203 | + 'name' => $sfigSettings->menuSelectDisableInputField?'enable input field':'disable input field', |
| 204 | + 'type' => 'boolean', |
| 205 | + 'description' => wfMsg( 'semanticformsinputs-menuselect-enableinputfield' ), |
| 206 | + ); |
| 207 | + return $params; |
| 208 | + } |
| 209 | + |
| 210 | + /** |
| 211 | + * Returns the name and parameters for the initialization JavaScript |
| 212 | + * function for this input type, if any. |
| 213 | + */ |
| 214 | + public function getJsInitFunctionData() { |
| 215 | + return array_merge( |
| 216 | + $this->mJsInitFunctionData, |
| 217 | + $this->mDatePicker->getJsInitFunctionData(), |
| 218 | + $this->mTimePicker->getJsInitFunctionData() |
| 219 | + ); |
| 220 | + } |
| 221 | + |
| 222 | + /** |
| 223 | + * Returns the name and parameters for the validation JavaScript |
| 224 | + * functions for this input type, if any. |
| 225 | + */ |
| 226 | + public function getJsValidationFunctionData() { |
| 227 | + return array_merge( |
| 228 | + $this->mJsValidationFunctionData, |
| 229 | + $this->mDatePicker->getJsValidationFunctionData(), |
| 230 | + $this->mTimePicker->getJsValidationFunctionData() |
| 231 | + ); |
| 232 | + |
| 233 | + } |
| 234 | + |
| 235 | +} |
Property changes on: trunk/extensions/SemanticFormsInputs/includes/SFI_DateTimePicker.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 236 | + native |
Index: trunk/extensions/SemanticFormsInputs/includes/SFI_RegExp.php |
— | — | @@ -0,0 +1,249 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SFIRegExp class |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticFormsInputs |
| 10 | + */ |
| 11 | +if ( !defined( 'SFI_VERSION' ) ) { |
| 12 | + die( 'This file is part of the SemanticFormsInputs extension, it is not a valid entry point.' ); |
| 13 | +} |
| 14 | + |
| 15 | +/** |
| 16 | + * This class represents the RegExp input. |
| 17 | + * |
| 18 | + * @ingroup SFI |
| 19 | + */ |
| 20 | +class SFIRegExp extends SFFormInput { |
| 21 | + |
| 22 | + /** @var SFFormInput */ |
| 23 | + protected $mBaseInput; |
| 24 | + |
| 25 | + /** |
| 26 | + * Constructor. |
| 27 | + * |
| 28 | + * @param String $input_number |
| 29 | + * The number of the input in the form. |
| 30 | + * @param String $cur_value |
| 31 | + * The current value of the input field. |
| 32 | + * @param String $input_name |
| 33 | + * The name of the input. |
| 34 | + * @param String $disabled |
| 35 | + * Is this input disabled? |
| 36 | + * @param Array $other_args |
| 37 | + * An associative array of other parameters that were present in the |
| 38 | + * input definition. |
| 39 | + */ |
| 40 | + public function __construct( $input_number, $cur_value, $input_name, $disabled, $other_args ) { |
| 41 | + |
| 42 | + global $sfgFormPrinter; |
| 43 | + |
| 44 | + parent::__construct( $input_number, $cur_value, $input_name, $disabled, $other_args ); |
| 45 | + |
| 46 | + // call static setup |
| 47 | + self::setup(); |
| 48 | + |
| 49 | + // set OR character |
| 50 | + if ( array_key_exists( 'or char', $this->mOtherArgs ) ) { |
| 51 | + $orChar = trim( $this->mOtherArgs['or char'] ); |
| 52 | + unset( $this->mOtherArgs['or char'] ); |
| 53 | + } else { |
| 54 | + $orChar = '!'; |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + // set regexp string |
| 59 | + if ( array_key_exists( 'regexp', $this->mOtherArgs ) ) { |
| 60 | + |
| 61 | + $this->mRegExp = str_replace( $orChar, '|', trim( $this->mOtherArgs['regexp'] ) ); |
| 62 | + unset( $this->mOtherArgs['regexp'] ); |
| 63 | + |
| 64 | + // check for leading/trailing delimiter and remove it (else reset regexp) |
| 65 | + if ( preg_match( "/^\/.*\/\$/", $this->mRegExp ) ) { |
| 66 | + |
| 67 | + $this->mRegExp = substr( $this->mRegExp, 1, strlen( $this->mRegExp ) - 2 ); |
| 68 | + } else { |
| 69 | + $this->mRegExp = '.*'; |
| 70 | + } |
| 71 | + } else { |
| 72 | + $this->mRegExp = '.*'; |
| 73 | + } |
| 74 | + |
| 75 | + // set inverse string |
| 76 | + if ( array_key_exists( 'inverse', $this->mOtherArgs ) ) { |
| 77 | + $invertRegexp = 'true'; |
| 78 | + unset( $this->mOtherArgs['inverse'] ); |
| 79 | + } else { |
| 80 | + $invertRegexp = 'false'; |
| 81 | + } |
| 82 | + |
| 83 | + // set failure message string |
| 84 | + if ( array_key_exists( 'message', $this->mOtherArgs ) ) { |
| 85 | + $this->mErrorMessage = trim( $this->mOtherArgs['message'] ); |
| 86 | + unset( $this->mOtherArgs['message'] ); |
| 87 | + } else { |
| 88 | + $this->mErrorMessage = wfMsg( 'semanticformsinputs-wrongformat' ); |
| 89 | + } |
| 90 | + |
| 91 | + // sanitize error message and regexp for JS |
| 92 | + $message = Xml::encodeJsVar( $this->mErrorMessage ); |
| 93 | + $regexp = Xml::encodeJsVar( $this->mRegExp ); |
| 94 | + |
| 95 | + // Finally set name and parameters for the validation function |
| 96 | + $this->addJsValidationFunctionData( 'SFI_RE_validate', "{retext: {$regexp}, inverse: {$invertRegexp}, message: {$message} }" ); |
| 97 | + |
| 98 | + |
| 99 | + // set base input type name |
| 100 | + if ( array_key_exists( 'base type', $this->mOtherArgs ) ) { |
| 101 | + |
| 102 | + $baseType = trim( $this->mOtherArgs['base type'] ); |
| 103 | + unset( $this->mOtherArgs['base type'] ); |
| 104 | + |
| 105 | + // if unknown set default base input type |
| 106 | + if ( !array_key_exists( $baseType, $sfgFormPrinter->mInputTypeClasses ) ) { |
| 107 | + $baseType = 'text'; |
| 108 | + } |
| 109 | + } else { |
| 110 | + $baseType = 'text'; |
| 111 | + } |
| 112 | + |
| 113 | + // create other_args array for base input type if base prefix was set |
| 114 | + if ( array_key_exists( 'base prefix', $this->mOtherArgs ) ) { |
| 115 | + |
| 116 | + // set base prefix |
| 117 | + $basePrefix = trim( $this->mOtherArgs['base prefix'] ) . "."; |
| 118 | + unset( $this->mOtherArgs['base prefix'] ); |
| 119 | + |
| 120 | + // create new other_args param |
| 121 | + $newOtherArgs = array(); |
| 122 | + |
| 123 | + foreach ( $this->mOtherArgs as $key => $value ) { |
| 124 | + if ( strpos( $key, $basePrefix ) === 0 ) { |
| 125 | + $newOtherArgs[substr( $key, strlen( $basePrefix ) )] = $value; |
| 126 | + } else { |
| 127 | + $newOtherArgs[$key] = $value; |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + } else { |
| 132 | + $newOtherArgs = $this->mOtherArgs; |
| 133 | + } |
| 134 | + |
| 135 | + // create base input |
| 136 | + $this->mBaseInput = new $sfgFormPrinter->mInputTypeClasses[ $baseType ] ( |
| 137 | + $this->mInputNumber, $this->mCurrentValue, $this->mInputName, $this->mIsDisabled, $newOtherArgs |
| 138 | + ); |
| 139 | + |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * Returns the name of the input type this class handles. |
| 144 | + * |
| 145 | + * This is the name to be used in the field definition for the "input type" |
| 146 | + * parameter. |
| 147 | + * |
| 148 | + * @return String The name of the input type this class handles. |
| 149 | + */ |
| 150 | + public static function getName() { |
| 151 | + return 'regexp'; |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * Static setup method for input type "menuselect". |
| 156 | + * Adds the Javascript code and css used by all menuselects. |
| 157 | + */ |
| 158 | + static private function setup() { |
| 159 | + |
| 160 | + global $wgOut; |
| 161 | + global $sfigSettings; |
| 162 | + |
| 163 | + static $hasRun = false; |
| 164 | + |
| 165 | + if ( !$hasRun ) { |
| 166 | + $hasRun = true; |
| 167 | + $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/regexp.js"></script> ' ); |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * Returns the set of parameters for this form input. |
| 173 | + */ |
| 174 | + public static function getParameters() { |
| 175 | + $params = parent::getParameters(); |
| 176 | + $params[] = array( |
| 177 | + 'name' => 'regexp', |
| 178 | + 'type' => 'string', |
| 179 | + 'description' => wfMsg( 'semanticformsinputs-regexp-regexp' ) |
| 180 | + ); |
| 181 | + $params[] = array( |
| 182 | + 'name' => 'base type', |
| 183 | + 'type' => 'string', |
| 184 | + 'description' => wfMsg( 'semanticformsinputs-regexp-basetype' ) |
| 185 | + ); |
| 186 | + $params[] = array( |
| 187 | + 'name' => 'base prefix', |
| 188 | + 'type' => 'string', |
| 189 | + 'description' => wfMsg( 'semanticformsinputs-regexp-baseprefix' ) |
| 190 | + ); |
| 191 | + $params[] = array( |
| 192 | + 'name' => 'or char', |
| 193 | + 'type' => 'string', |
| 194 | + 'description' => wfMsg( 'semanticformsinputs-regexp-orchar' ) |
| 195 | + ); |
| 196 | + $params[] = array( |
| 197 | + 'name' => 'inverse', |
| 198 | + 'type' => 'string', |
| 199 | + 'description' => wfMsg( 'semanticformsinputs-regexp-inverse' ) |
| 200 | + ); |
| 201 | + $params[] = array( |
| 202 | + 'name' => 'message', |
| 203 | + 'type' => 'string', |
| 204 | + 'description' => wfMsg( 'semanticformsinputs-regexp-message' ) |
| 205 | + ); |
| 206 | + |
| 207 | + |
| 208 | + return $params; |
| 209 | + } |
| 210 | + |
| 211 | + /** |
| 212 | + * Returns the HTML code to be included in the output page for this input. |
| 213 | + * |
| 214 | + * Ideally this HTML code should provide a basic functionality even if the |
| 215 | + * browser is not JavaScript capable. I.e. even without JavaScript the user |
| 216 | + * should be able to input values. |
| 217 | + * |
| 218 | + */ |
| 219 | + public function getHtmlText() { |
| 220 | + |
| 221 | + return $this->mBaseInput->getHtmlText(); |
| 222 | + } |
| 223 | + |
| 224 | + /** |
| 225 | + * Returns the set of SMW property types which this input can |
| 226 | + * handle, but for which it isn't the default input. |
| 227 | + * |
| 228 | + * @deprecated |
| 229 | + * @return Array of strings |
| 230 | + */ |
| 231 | + public static function getOtherPropTypesHandled() { |
| 232 | + return array('_str', '_num', '_dat', '_geo', '_ema', '_tel', '_wpg', '_tem', '_qty'); |
| 233 | + } |
| 234 | + |
| 235 | + /** |
| 236 | + * Returns the name and parameters for the initialization JavaScript |
| 237 | + * function for this input type, if any. |
| 238 | + */ |
| 239 | + public function getJsInitFunctionData() { |
| 240 | + return array_merge( $this->mJsInitFunctionData, $this->mBaseInput->getJsInitFunctionData() ); |
| 241 | + } |
| 242 | + |
| 243 | + /** |
| 244 | + * Returns the name and parameters for the validation JavaScript |
| 245 | + * functions for this input type, if any. |
| 246 | + */ |
| 247 | + public function getJsValidationFunctionData() { |
| 248 | + return array_merge( $this->mJsValidationFunctionData, $this->mBaseInput->getJsValidationFunctionData() ); |
| 249 | + } |
| 250 | +} |
Property changes on: trunk/extensions/SemanticFormsInputs/includes/SFI_RegExp.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 251 | + native |
Index: trunk/extensions/SemanticFormsInputs/includes/SFI_DatePicker.php |
— | — | @@ -0,0 +1,725 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SFIDatePicker class |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticFormsInputs |
| 10 | + */ |
| 11 | +if ( !defined( 'SFI_VERSION' ) ) { |
| 12 | + die( 'This file is part of the SemanticFormsInputs extension, it is not a valid entry point.' ); |
| 13 | +} |
| 14 | + |
| 15 | +/** |
| 16 | + * The SFIDatePicker class. |
| 17 | + * |
| 18 | + * @ingroup SemanticFormsInputs |
| 19 | + */ |
| 20 | +class SFIDatePicker extends SFFormInput { |
| 21 | + |
| 22 | + /** |
| 23 | + * Constructor. |
| 24 | + * |
| 25 | + * @param String $input_number |
| 26 | + * The number of the input in the form. |
| 27 | + * @param String $cur_value |
| 28 | + * The current value of the input field. |
| 29 | + * @param String $input_name |
| 30 | + * The name of the input. |
| 31 | + * @param String $disabled |
| 32 | + * Is this input disabled? |
| 33 | + * @param Array $other_args |
| 34 | + * An associative array of other parameters that were present in the |
| 35 | + * input definition. |
| 36 | + */ |
| 37 | + public function __construct( $input_number, $cur_value, $input_name, $disabled, $other_args ) { |
| 38 | + |
| 39 | + parent::__construct( $input_number, $cur_value, $input_name, $disabled, $other_args ); |
| 40 | + |
| 41 | + // call static setup |
| 42 | + self::setup(); |
| 43 | + |
| 44 | + $this->addJsInitFunctionData( 'SFI_DP_init', $this->setupJsInitAttribs() ); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Returns the name of the input type this class handles. |
| 49 | + * |
| 50 | + * This is the name to be used in the field definition for the "input type" |
| 51 | + * parameter. |
| 52 | + * |
| 53 | + * @return String The name of the input type this class handles. |
| 54 | + */ |
| 55 | + public static function getName() { |
| 56 | + return 'datepicker'; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Static setup method for input type "menuselect". |
| 61 | + * Adds the Javascript code and css used by all menuselects. |
| 62 | + */ |
| 63 | + static private function setup() { |
| 64 | + |
| 65 | + global $wgOut, $wgLang; |
| 66 | + global $sfgScriptPath, $sfigSettings; |
| 67 | + |
| 68 | + static $hasRun = false; |
| 69 | + |
| 70 | + if ( !$hasRun ) { |
| 71 | + $hasRun = true; |
| 72 | + |
| 73 | + $wgOut->addExtensionStyle( $sfgScriptPath . '/skins/jquery-ui/base/jquery.ui.datepicker.css' ); |
| 74 | + $wgOut->addExtensionStyle( $sfgScriptPath . '/skins/jquery-ui/base/jquery.ui.theme.css' ); |
| 75 | + $wgOut->addScript( '<script type="text/javascript" src="' . $sfgScriptPath . '/libs/jquery-ui/jquery.ui.datepicker.min.js"></script> ' ); |
| 76 | + $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/datepicker.js"></script> ' ); |
| 77 | + |
| 78 | + // set localized messages (use MW i18n, not jQuery i18n) |
| 79 | + $jstext = |
| 80 | + "jQuery(function(){\n" |
| 81 | + . " jQuery.datepicker.regional['wiki'] = {\n" |
| 82 | + . " closeText: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-close' ) ) . "',\n" |
| 83 | + . " prevText: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-prev' ) ) . "',\n" |
| 84 | + . " nextText: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-next' ) ) . "',\n" |
| 85 | + . " currentText: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-today' ) ) . "',\n" |
| 86 | + . " monthNames: ['" |
| 87 | + . Xml::escapeJsString( wfMsg( 'january' ) ) . "','" |
| 88 | + . Xml::escapeJsString( wfMsg( 'february' ) ) . "','" |
| 89 | + . Xml::escapeJsString( wfMsg( 'march' ) ) . "','" |
| 90 | + . Xml::escapeJsString( wfMsg( 'april' ) ) . "','" |
| 91 | + . Xml::escapeJsString( wfMsg( 'may_long' ) ) . "','" |
| 92 | + . Xml::escapeJsString( wfMsg( 'june' ) ) . "','" |
| 93 | + . Xml::escapeJsString( wfMsg( 'july' ) ) . "','" |
| 94 | + . Xml::escapeJsString( wfMsg( 'august' ) ) . "','" |
| 95 | + . Xml::escapeJsString( wfMsg( 'september' ) ) . "','" |
| 96 | + . Xml::escapeJsString( wfMsg( 'october' ) ) . "','" |
| 97 | + . Xml::escapeJsString( wfMsg( 'november' ) ) . "','" |
| 98 | + . Xml::escapeJsString( wfMsg( 'december' ) ) . "'],\n" |
| 99 | + . " monthNamesShort: ['" |
| 100 | + . Xml::escapeJsString( wfMsg( 'jan' ) ) . "','" |
| 101 | + . Xml::escapeJsString( wfMsg( 'feb' ) ) . "','" |
| 102 | + . Xml::escapeJsString( wfMsg( 'mar' ) ) . "','" |
| 103 | + . Xml::escapeJsString( wfMsg( 'apr' ) ) . "','" |
| 104 | + . Xml::escapeJsString( wfMsg( 'may' ) ) . "','" |
| 105 | + . Xml::escapeJsString( wfMsg( 'jun' ) ) . "','" |
| 106 | + . Xml::escapeJsString( wfMsg( 'jul' ) ) . "','" |
| 107 | + . Xml::escapeJsString( wfMsg( 'aug' ) ) . "','" |
| 108 | + . Xml::escapeJsString( wfMsg( 'sep' ) ) . "','" |
| 109 | + . Xml::escapeJsString( wfMsg( 'oct' ) ) . "','" |
| 110 | + . Xml::escapeJsString( wfMsg( 'nov' ) ) . "','" |
| 111 | + . Xml::escapeJsString( wfMsg( 'dec' ) ) . "'],\n" |
| 112 | + . " dayNames: ['" |
| 113 | + . Xml::escapeJsString( wfMsg( 'sunday' ) ) . "','" |
| 114 | + . Xml::escapeJsString( wfMsg( 'monday' ) ) . "','" |
| 115 | + . Xml::escapeJsString( wfMsg( 'tuesday' ) ) . "','" |
| 116 | + . Xml::escapeJsString( wfMsg( 'wednesday' ) ) . "','" |
| 117 | + . Xml::escapeJsString( wfMsg( 'thursday' ) ) . "','" |
| 118 | + . Xml::escapeJsString( wfMsg( 'friday' ) ) . "','" |
| 119 | + . Xml::escapeJsString( wfMsg( 'saturday' ) ) . "'],\n" |
| 120 | + . " dayNamesShort: ['" |
| 121 | + . Xml::escapeJsString( wfMsg( 'sun' ) ) . "','" |
| 122 | + . Xml::escapeJsString( wfMsg( 'mon' ) ) . "','" |
| 123 | + . Xml::escapeJsString( wfMsg( 'tue' ) ) . "','" |
| 124 | + . Xml::escapeJsString( wfMsg( 'wed' ) ) . "','" |
| 125 | + . Xml::escapeJsString( wfMsg( 'thu' ) ) . "','" |
| 126 | + . Xml::escapeJsString( wfMsg( 'fri' ) ) . "','" |
| 127 | + . Xml::escapeJsString( wfMsg( 'sat' ) ) . "'],\n" |
| 128 | + . " dayNamesMin: ['" |
| 129 | + . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'sun' ) ) ) . "','" |
| 130 | + . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'mon' ) ) ) . "','" |
| 131 | + . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'tue' ) ) ) . "','" |
| 132 | + . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'wed' ) ) ) . "','" |
| 133 | + . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'thu' ) ) ) . "','" |
| 134 | + . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'fri' ) ) ) . "','" |
| 135 | + . Xml::escapeJsString( $wgLang->firstChar( wfMsg( 'sat' ) ) ) . "'],\n" |
| 136 | + . " weekHeader: '',\n" |
| 137 | + . " dateFormat: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-dateformatshort' ) ) . "',\n" |
| 138 | + . " firstDay: '" . Xml::escapeJsString( wfMsg( 'semanticformsinputs-firstdayofweek' ) ) . "',\n" |
| 139 | + . " isRTL: " . ( $wgLang->isRTL() ? "true" : "false" ) . ",\n" |
| 140 | + . " showMonthAfterYear: false,\n" |
| 141 | + . " yearSuffix: ''};\n" |
| 142 | + . " jQuery.datepicker.setDefaults(jQuery.datepicker.regional['wiki']);\n" |
| 143 | + . "});\n"; |
| 144 | + |
| 145 | + $wgOut->addScript( Html::inlineScript( $jstext ) ); |
| 146 | + |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Set up JS attributes |
| 152 | + * |
| 153 | + * @return String |
| 154 | + */ |
| 155 | + protected function setupJsInitAttribs() { |
| 156 | + |
| 157 | + global $sfgFormPrinter, $sfigSettings; |
| 158 | + global $wgAmericanDates; |
| 159 | + |
| 160 | + // store user class(es) for use with buttons |
| 161 | + if ( array_key_exists( 'class', $this->mOtherArgs ) ) { |
| 162 | + $userClasses = $this->mOtherArgs['class']; |
| 163 | + } else $userClasses = ""; |
| 164 | + |
| 165 | + // set up attributes required for both enabled and disabled datepickers |
| 166 | + $jsattribs = array( |
| 167 | + 'currValue' => $this->mCurrentValue, |
| 168 | + 'disabled' => $this->mIsDisabled, |
| 169 | + 'userClasses' => $userClasses |
| 170 | + ); |
| 171 | + |
| 172 | + if ( array_key_exists( 'part of dtp', $this->mOtherArgs ) ) { |
| 173 | + $jsattribs['partOfDTP'] = $this->mOtherArgs['part of dtp']; |
| 174 | + } |
| 175 | + |
| 176 | + // set date format |
| 177 | + // SHORT and LONG are SFI specific acronyms and are translated here |
| 178 | + // into format strings, anything else is passed to the jQuery date picker |
| 179 | + // Americans need special treatment |
| 180 | + if ( $wgAmericanDates && $wgLang->getCode() == "en" ) { |
| 181 | + |
| 182 | + if ( array_key_exists( 'date format', $this->mOtherArgs ) ) { |
| 183 | + |
| 184 | + if ( $this->mOtherArgs['date format'] == 'SHORT' ) { |
| 185 | + $jsattribs['dateFormat'] = 'mm/dd/yy'; |
| 186 | + } elseif ( $this->mOtherArgs['date format'] == 'LONG' ) { |
| 187 | + $jsattribs['dateFormat'] = 'MM d, yy'; |
| 188 | + } else { |
| 189 | + $jsattribs['dateFormat'] = $this->mOtherArgs['date format']; |
| 190 | + } |
| 191 | + |
| 192 | + } elseif ( $sfigSettings->datePickerDateFormat ) { |
| 193 | + |
| 194 | + if ( $sfigSettings->datePickerDateFormat == 'SHORT' ) { |
| 195 | + $jsattribs['dateFormat'] = 'mm/dd/yy'; |
| 196 | + } elseif ( $sfigSettings->datePickerDateFormat == 'LONG' ) { |
| 197 | + $jsattribs['dateFormat'] = 'MM d, yy'; |
| 198 | + } else { |
| 199 | + $jsattribs['dateFormat'] = $sfigSettings->datePickerDateFormat; |
| 200 | + } |
| 201 | + |
| 202 | + } else $jsattribs['dateFormat'] = 'yy/mm/dd'; |
| 203 | + |
| 204 | + } else { |
| 205 | + |
| 206 | + if ( array_key_exists( 'date format', $this->mOtherArgs ) ) { |
| 207 | + |
| 208 | + if ( $this->mOtherArgs['date format'] == 'SHORT' ) { |
| 209 | + $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatshort' ); |
| 210 | + } elseif ( $this->mOtherArgs['date format'] == 'LONG' ) { |
| 211 | + $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatlong' ); |
| 212 | + } else { |
| 213 | + $jsattribs['dateFormat'] = $this->mOtherArgs['date format']; |
| 214 | + } |
| 215 | + |
| 216 | + } elseif ( $sfigSettings->datePickerDateFormat ) { |
| 217 | + |
| 218 | + if ( $sfigSettings->datePickerDateFormat == 'SHORT' ) { |
| 219 | + $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatshort' ); |
| 220 | + } elseif ( $sfigSettings->datePickerDateFormat == 'LONG' ) { |
| 221 | + $jsattribs['dateFormat'] = wfMsg( 'semanticformsinputs-dateformatlong' ); |
| 222 | + } else { |
| 223 | + $jsattribs['dateFormat'] = $sfigSettings->datePickerDateFormat; |
| 224 | + } |
| 225 | + |
| 226 | + } else $jsattribs['dateFormat'] = 'yy/mm/dd'; |
| 227 | + |
| 228 | + } |
| 229 | + |
| 230 | + // setup attributes required only for either disabled or enabled datepickers |
| 231 | + if ( $this->mIsDisabled ) { |
| 232 | + |
| 233 | + $jsattribs['buttonImage'] = $sfigSettings->scriptPath . '/images/DatePickerButtonDisabled.gif'; |
| 234 | + |
| 235 | + if ( array_key_exists( 'show reset button', $this->mOtherArgs ) || |
| 236 | + ( !array_key_exists( 'hide reset button', $this->mOtherArgs ) && $sfigSettings->datePickerShowResetButton ) ) { |
| 237 | + |
| 238 | + $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DatePickerResetButtonDisabled.gif'; |
| 239 | + |
| 240 | + } |
| 241 | + |
| 242 | + } else { |
| 243 | + |
| 244 | + $jsattribs['buttonImage'] = $sfigSettings->scriptPath . '/images/DatePickerButton.gif'; |
| 245 | + |
| 246 | + if ( array_key_exists( 'show reset button', $this->mOtherArgs ) || |
| 247 | + ( !array_key_exists( 'hide reset button', $this->mOtherArgs ) && $sfigSettings->datePickerShowResetButton ) ) { |
| 248 | + |
| 249 | + $jsattribs['resetButtonImage'] = $sfigSettings->scriptPath . '/images/DatePickerResetButton.gif'; |
| 250 | + |
| 251 | + } |
| 252 | + |
| 253 | + // find min date, max date and disabled dates |
| 254 | + |
| 255 | + // set first date |
| 256 | + if ( array_key_exists( 'first date', $this->mOtherArgs ) ) { |
| 257 | + $minDate = date_create( $this->mOtherArgs['first date'] ); |
| 258 | + } elseif ( $sfigSettings->datePickerFirstDate ) { |
| 259 | + $minDate = date_create( $sfigSettings->datePickerFirstDate ); |
| 260 | + } else { |
| 261 | + $minDate = null; |
| 262 | + } |
| 263 | + |
| 264 | + // set last date |
| 265 | + if ( array_key_exists( 'last date', $this->mOtherArgs ) ) { |
| 266 | + $maxDate = date_create( $this->mOtherArgs['last date'] ); |
| 267 | + } elseif ( $sfigSettings->datePickerLastDate ) { |
| 268 | + $maxDate = date_create( $sfigSettings->datePickerLastDate ); |
| 269 | + } else { |
| 270 | + $maxDate = null; |
| 271 | + } |
| 272 | + |
| 273 | + // find allowed values and invert them to get disabled values |
| 274 | + if ( array_key_exists( 'possible_values', $this->mOtherArgs ) && count( $this->mOtherArgs['possible_values'] ) ) { |
| 275 | + |
| 276 | + $enabledDates = self::sortAndMergeRanges( self::createRangesArray( $this->mOtherArgs['possible_values'] ) ); |
| 277 | + |
| 278 | + // correct min/max date to the first/last allowed value |
| 279 | + if ( !$minDate || $minDate < $enabledDates[0][0] ) { |
| 280 | + $minDate = $enabledDates[0][0]; |
| 281 | + } |
| 282 | + |
| 283 | + if ( !$maxDate || $maxDate > $enabledDates[count( $enabledDates ) - 1][1] ) { |
| 284 | + $maxDate = $enabledDates[count( $enabledDates ) - 1][1]; |
| 285 | + } |
| 286 | + |
| 287 | + $disabledDates = self::invertRangesArray( $enabledDates ); |
| 288 | + |
| 289 | + } else $disabledDates = array(); |
| 290 | + |
| 291 | + // add user-defined or default disabled values |
| 292 | + if ( array_key_exists( 'disable dates', $this->mOtherArgs ) ) { |
| 293 | + |
| 294 | + $disabledDates = |
| 295 | + self::sortAndMergeRanges( |
| 296 | + array_merge( $disabledDates, self::createRangesArray( explode( ',' , $this->mOtherArgs['disable dates'] ) ) ) ); |
| 297 | + |
| 298 | + } elseif ( $sfigSettings->datePickerDisabledDates ) { |
| 299 | + |
| 300 | + $disabledDates = |
| 301 | + self::sortAndMergeRanges( |
| 302 | + array_merge( $disabledDates, self::createRangesArray( explode( ',' , $sfigSettings->datePickerDisabledDates ) ) ) ); |
| 303 | + |
| 304 | + } |
| 305 | + |
| 306 | + // if a minDate is set, discard all disabled dates below the min date |
| 307 | + if ( $minDate ) { |
| 308 | + |
| 309 | + // discard all ranges of disabled dates that are entirely below the min date |
| 310 | + while ( $minDate && count( $disabledDates ) && $disabledDates[0][1] < $minDate ) array_shift( $disabledDates ); |
| 311 | + |
| 312 | + // if min date is in first disabled date range, discard that range and adjust min date |
| 313 | + if ( count( $disabledDates ) && $disabledDates[0][0] <= $minDate && $disabledDates[0][1] >= $minDate ) { |
| 314 | + $minDate = $disabledDates[0][1]; |
| 315 | + array_shift( $disabledDates ); |
| 316 | + $minDate->modify( "+1 day" ); |
| 317 | + } |
| 318 | + } |
| 319 | + |
| 320 | + // if a maxDate is set, discard all disabled dates above the max date |
| 321 | + if ( $maxDate ) { |
| 322 | + |
| 323 | + // discard all ranges of disabled dates that are entirely above the max date |
| 324 | + while ( count( $disabledDates ) && $disabledDates[count( $disabledDates ) - 1][0] > $maxDate ) array_pop( $disabledDates ); |
| 325 | + |
| 326 | + // if max date is in last disabled date range, discard that range and adjust max date |
| 327 | + if ( count( $disabledDates ) && $disabledDates[count( $disabledDates ) - 1][0] <= $maxDate && $disabledDates[count( $disabledDates ) - 1][1] >= $maxDate ) { |
| 328 | + $maxDate = $disabledDates[count( $disabledDates ) - 1][0]; |
| 329 | + array_pop( $disabledDates ); |
| 330 | + $maxDate->modify( "-1 day" ); |
| 331 | + } |
| 332 | + } |
| 333 | + // finished with disabled dates |
| 334 | + |
| 335 | + // find highlighted dates |
| 336 | + if ( array_key_exists( "highlight dates", $this->mOtherArgs ) ) { |
| 337 | + $highlightedDates = self::sortAndMergeRanges ( self::createRangesArray( explode( ',' , $this->mOtherArgs["highlight dates"] ) ) ) ; |
| 338 | + } elseif ( $sfigSettings->datePickerHighlightedDates ) { |
| 339 | + $highlightedDates = self::sortAndMergeRanges ( self::createRangesArray( explode( ',' , $sfigSettings->datePickerHighlightedDates ) ) ) ; |
| 340 | + } else { |
| 341 | + $highlightedDates = null; |
| 342 | + } |
| 343 | + |
| 344 | + |
| 345 | + // find disabled week days and mark them in an array |
| 346 | + if ( array_key_exists( "disable days of week", $this->mOtherArgs ) ) { |
| 347 | + $disabledDaysString = $this->mOtherArgs['disable days of week']; |
| 348 | + } else { |
| 349 | + $disabledDaysString = $sfigSettings->datePickerDisabledDaysOfWeek; |
| 350 | + } |
| 351 | + |
| 352 | + if ( $disabledDaysString != null ) { |
| 353 | + |
| 354 | + $disabledDays = array( false, false, false, false, false, false, false ); |
| 355 | + |
| 356 | + foreach ( explode( ',', $disabledDaysString ) as $day ) { |
| 357 | + |
| 358 | + if ( is_numeric( $day ) && $day >= 0 && $day <= 6 ) { |
| 359 | + $disabledDays[$day] = true; |
| 360 | + } |
| 361 | + |
| 362 | + } |
| 363 | + |
| 364 | + } else { |
| 365 | + $disabledDays = null; |
| 366 | + } |
| 367 | + |
| 368 | + // find highlighted week days and mark them in an array |
| 369 | + if ( array_key_exists( "highlight days of week", $this->mOtherArgs ) ) { |
| 370 | + $highlightedDaysString = $this->mOtherArgs['highlight days of week']; |
| 371 | + } else { |
| 372 | + $highlightedDaysString = $sfigSettings->datePickerHighlightedDaysOfWeek; |
| 373 | + } |
| 374 | + |
| 375 | + if ( $highlightedDaysString != null ) { |
| 376 | + |
| 377 | + $highlightedDays = array( false, false, false, false, false, false, false ); |
| 378 | + |
| 379 | + foreach ( explode( ',', $highlightedDaysString ) as $day ) { |
| 380 | + |
| 381 | + if ( is_numeric( $day ) && $day >= 0 && $day <= 6 ) { |
| 382 | + $highlightedDays[$day] = true; |
| 383 | + } |
| 384 | + |
| 385 | + } |
| 386 | + |
| 387 | + } else { |
| 388 | + $highlightedDays = null; |
| 389 | + } |
| 390 | + |
| 391 | + // set first day of the week |
| 392 | + if ( array_key_exists( 'week start', $this->mOtherArgs ) ) { |
| 393 | + $jsattribs['firstDay'] = $this->mOtherArgs['week start']; |
| 394 | + } elseif ( $sfigSettings->datePickerWeekStart != null ) { |
| 395 | + $jsattribs['firstDay'] = $sfigSettings->datePickerWeekStart; |
| 396 | + } else { |
| 397 | + $jsattribs['firstDay'] = wfMsg( 'semanticformsinputs-firstdayofweek' ); |
| 398 | + } |
| 399 | + |
| 400 | + // set show week number |
| 401 | + if ( array_key_exists( 'show week numbers', $this->mOtherArgs ) |
| 402 | + || ( !array_key_exists( 'hide week numbers', $this->mOtherArgs ) && $sfigSettings->datePickerShowWeekNumbers ) ) { |
| 403 | + |
| 404 | + $jsattribs['showWeek'] = true; |
| 405 | + } else { |
| 406 | + $jsattribs['showWeek'] = false; |
| 407 | + } |
| 408 | + |
| 409 | + // store min date as JS attrib |
| 410 | + if ( $minDate ) { |
| 411 | + $jsattribs['minDate'] = $minDate->format( 'Y/m/d' ); |
| 412 | + } |
| 413 | + |
| 414 | + // store max date as JS attrib |
| 415 | + if ( $maxDate ) { |
| 416 | + $jsattribs['maxDate'] = $maxDate->format( 'Y/m/d' ); |
| 417 | + } |
| 418 | + |
| 419 | + // register disabled dates with datepicker |
| 420 | + if ( count( $disabledDates ) > 0 ) { |
| 421 | + |
| 422 | + // convert the PHP array of date ranges into an array of numbers |
| 423 | + $jsattribs["disabledDates"] = array_map( create_function ( '$range', ' |
| 424 | + |
| 425 | + $y0 = $range[0]->format( "Y" ); |
| 426 | + $m0 = $range[0]->format( "m" ) - 1; |
| 427 | + $d0 = $range[0]->format( "d" ); |
| 428 | + |
| 429 | + $y1 = $range[1]->format( "Y" ); |
| 430 | + $m1 = $range[1]->format( "m" ) - 1; |
| 431 | + $d1 = $range[1]->format( "d" ); |
| 432 | + |
| 433 | + return array($y0, $m0, $d0, $y1, $m1, $d1); |
| 434 | + ' ) , $disabledDates ); |
| 435 | + } |
| 436 | + |
| 437 | + // register highlighted dates with datepicker |
| 438 | + if ( count( $highlightedDates ) > 0 ) { |
| 439 | + |
| 440 | + // convert the PHP array of date ranges into an array of numbers |
| 441 | + $jsattribs["highlightedDates"] = array_map( create_function ( '$range', ' |
| 442 | + |
| 443 | + $y0 = $range[0]->format( "Y" ); |
| 444 | + $m0 = $range[0]->format( "m" ) - 1; |
| 445 | + $d0 = $range[0]->format( "d" ); |
| 446 | + |
| 447 | + $y1 = $range[1]->format( "Y" ); |
| 448 | + $m1 = $range[1]->format( "m" ) - 1; |
| 449 | + $d1 = $range[1]->format( "d" ); |
| 450 | + |
| 451 | + return array($y0, $m0, $d0, $y1, $m1, $d1); |
| 452 | + ' ) , $highlightedDates ); |
| 453 | + } |
| 454 | + |
| 455 | + // register disabled days of week with datepicker |
| 456 | + if ( count( $disabledDays ) > 0 ) { |
| 457 | + $jsattribs["disabledDays"] = $disabledDays; |
| 458 | + } |
| 459 | + |
| 460 | + // register highlighted days of week with datepicker |
| 461 | + if ( count( $highlightedDays ) > 0 ) { |
| 462 | + $jsattribs["highlightedDays"] = $highlightedDays; |
| 463 | + } |
| 464 | + } |
| 465 | + |
| 466 | + // build JS code from attributes array |
| 467 | + return Xml::encodeJsVar( $jsattribs ); |
| 468 | + |
| 469 | + } |
| 470 | + |
| 471 | + /** |
| 472 | + * Sort and merge time ranges in an array |
| 473 | + * |
| 474 | + * expects an array of arrays |
| 475 | + * the inner arrays must contain two dates representing the start and end |
| 476 | + * date of a time range |
| 477 | + * |
| 478 | + * returns an array of arrays with the date ranges sorted and overlapping |
| 479 | + * ranges merged |
| 480 | + * |
| 481 | + * @param array $ranges array of arrays of DateTimes |
| 482 | + * @return array of arrays of DateTimes |
| 483 | + */ |
| 484 | + static private function sortAndMergeRanges ( $ranges ) { |
| 485 | + |
| 486 | + // sort ranges, earliest date first |
| 487 | + sort( $ranges ); |
| 488 | + |
| 489 | + // stores the start of the current date range |
| 490 | + $currmin = FALSE; |
| 491 | + |
| 492 | + // stores the date the next ranges start date has to top to not overlap |
| 493 | + $nextmin = FALSE; |
| 494 | + |
| 495 | + // result array |
| 496 | + $mergedRanges = array(); |
| 497 | + |
| 498 | + foreach ( $ranges as $range ) { |
| 499 | + |
| 500 | + // ignore empty date ranges |
| 501 | + if ( !$range ) continue; |
| 502 | + |
| 503 | + if ( !$currmin ) { // found first valid range |
| 504 | + |
| 505 | + $currmin = $range[0]; |
| 506 | + $nextmin = $range[1]; |
| 507 | + $nextmin->modify( '+1 day' ); |
| 508 | + |
| 509 | + } elseif ( $range[0] <= $nextmin ) { // overlap detected |
| 510 | + |
| 511 | + $currmin = min( $currmin, $range[0] ); |
| 512 | + |
| 513 | + $range[1]->modify( '+1 day' ); |
| 514 | + $nextmin = max( $nextmin, $range[1] ); |
| 515 | + |
| 516 | + } else { // no overlap, store current range and continue with next |
| 517 | + |
| 518 | + $nextmin->modify( '-1 day' ); |
| 519 | + $mergedRanges[] = array( $currmin, $nextmin ); |
| 520 | + |
| 521 | + $currmin = $range[0]; |
| 522 | + $nextmin = $range[1]; |
| 523 | + $nextmin->modify( '+1 day' ); |
| 524 | + |
| 525 | + } |
| 526 | + |
| 527 | + } |
| 528 | + |
| 529 | + // store last range |
| 530 | + if ( $currmin ) { |
| 531 | + $nextmin->modify( '-1 day' ); |
| 532 | + $mergedRanges[] = array( $currmin, $nextmin ); |
| 533 | + } |
| 534 | + |
| 535 | + return $mergedRanges; |
| 536 | + |
| 537 | + } |
| 538 | + |
| 539 | + /** |
| 540 | + * Creates an array of arrays of dates from an array of strings |
| 541 | + * |
| 542 | + * expects an array of strings containing dates or date ranges in the format |
| 543 | + * "yyyy/mm/dd" or "yyyy/mm/dd-yyyy/mm/dd" |
| 544 | + * |
| 545 | + * returns an array of arrays, each of the latter consisting of two dates |
| 546 | + * representing the start and end date of the range |
| 547 | + * |
| 548 | + * The result array will contain null values for unparseable date strings |
| 549 | + * |
| 550 | + * @param array $rangesAsStrings array of strings with dates and date ranges |
| 551 | + * @return array of arrays of DateTimes |
| 552 | + */ |
| 553 | + static private function createRangesArray ( $rangesAsStrings ) { |
| 554 | + |
| 555 | + // transform array of strings into array of array of dates |
| 556 | + // have to use create_function to be PHP pre5.3 compatible |
| 557 | + return array_map( create_function( '$range', ' |
| 558 | + |
| 559 | + if ( strpos ( $range, "-" ) === FALSE ) { // single date |
| 560 | + $date = date_create( $range ); |
| 561 | + return ( $date ) ? array( $date, clone $date ):null; |
| 562 | + } else { // date range |
| 563 | + $dates = array_map( "date_create", explode( "-", $range ) ); |
| 564 | + return ( $dates[0] && $dates[1] ) ? $dates:null; |
| 565 | + } |
| 566 | + |
| 567 | + ' ), $rangesAsStrings ); |
| 568 | + |
| 569 | + } |
| 570 | + |
| 571 | + /** |
| 572 | + * Takes an array of date ranges and returns an array containing the gaps |
| 573 | + * |
| 574 | + * The very first and the very last date of the original string are lost in |
| 575 | + * the process, of course, as they do not delimit a gap. This means, after |
| 576 | + * repeated inversion the result will eventually be empty. |
| 577 | + * |
| 578 | + * @param array $ranges of arrays of DateTimes |
| 579 | + * @return array of arrays of DateTimes |
| 580 | + */ |
| 581 | + static private function invertRangesArray( $ranges ) { |
| 582 | + |
| 583 | + // the result (initially empty) |
| 584 | + $invRanges = null; |
| 585 | + |
| 586 | + // the minimum of the current gap (initially none) |
| 587 | + $min = null; |
| 588 | + |
| 589 | + foreach ( $ranges as $range ) { |
| 590 | + |
| 591 | + if ( $min ) { // if min date of current gap is known store gap |
| 592 | + $min->modify( "+1day " ); |
| 593 | + $range[0]->modify( "-1day " ); |
| 594 | + $invRanges[] = array( $min, $range[0] ); |
| 595 | + } |
| 596 | + |
| 597 | + $min = $range[1]; // store min date of next gap |
| 598 | + |
| 599 | + } |
| 600 | + |
| 601 | + return $invRanges; |
| 602 | + } |
| 603 | + |
| 604 | + /** |
| 605 | + * Returns the set of parameters for this form input. |
| 606 | + * |
| 607 | + * TODO: Add missing parameters |
| 608 | + */ |
| 609 | + public static function getParameters() { |
| 610 | + global $sfigSettings; |
| 611 | + |
| 612 | + $params = parent::getParameters(); |
| 613 | + $params[] = array( |
| 614 | + 'name' => 'date format', |
| 615 | + 'type' => 'string', |
| 616 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-dateformat' ) |
| 617 | + ); |
| 618 | + $params[] = array( |
| 619 | + 'name' => 'week start', |
| 620 | + 'type' => 'int', |
| 621 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-weekstart' ) |
| 622 | + ); |
| 623 | + $params[] = array( |
| 624 | + 'name' => 'first date', |
| 625 | + 'type' => 'string', |
| 626 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-firstdate' ) |
| 627 | + ); |
| 628 | + $params[] = array( |
| 629 | + 'name' => 'last date', |
| 630 | + 'type' => 'string', |
| 631 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-lastdate' ) |
| 632 | + ); |
| 633 | + $params[] = array( |
| 634 | + 'name' => 'disable days of week', |
| 635 | + 'type' => 'string', |
| 636 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-disabledaysofweek' ) |
| 637 | + ); |
| 638 | + $params[] = array( |
| 639 | + 'name' => 'highlight days of week', |
| 640 | + 'type' => 'string', |
| 641 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-highlightdaysofweek' ) |
| 642 | + ); |
| 643 | + $params[] = array( |
| 644 | + 'name' => 'disable dates', |
| 645 | + 'type' => 'string', |
| 646 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-disabledates' ) |
| 647 | + ); |
| 648 | + $params[] = array( |
| 649 | + 'name' => 'highlight days of week', |
| 650 | + 'type' => 'string', |
| 651 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-highlightdates' ) |
| 652 | + ); |
| 653 | + $params[] = array( |
| 654 | + 'name' => $sfigSettings->datePickerShowWeekNumbers?'hide week numbers':'show week numbers', |
| 655 | + 'type' => 'boolean', |
| 656 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-showweeknumbers' ) |
| 657 | + ); |
| 658 | + $params[] = array( |
| 659 | + 'name' => $sfigSettings->datePickerDisableInputField?'enable input field':'disable input field', |
| 660 | + 'type' => 'boolean', |
| 661 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-enableinputfield' ) |
| 662 | + ); |
| 663 | + $params[] = array( |
| 664 | + 'name' => $sfigSettings->datePickerShowResetButton?'hide reset button':'show reset button', |
| 665 | + 'type' => 'boolean', |
| 666 | + 'description' => wfMsg( 'semanticformsinputs-datepicker-showresetbutton' ) |
| 667 | + ); |
| 668 | + return $params; |
| 669 | + } |
| 670 | + |
| 671 | + /** |
| 672 | + * Returns the HTML code to be included in the output page for this input. |
| 673 | + * |
| 674 | + * Ideally this HTML code should provide a basic functionality even if the |
| 675 | + * browser is not JavaScript capable. I.e. even without JavaScript the user |
| 676 | + * should be able to input values. |
| 677 | + * |
| 678 | + */ |
| 679 | + public function getHtmlText() { |
| 680 | + global $wgOut, $wgLang, $wgAmericanDates; // MW variables |
| 681 | + global $sfgFieldNum, $sfgScriptPath, $sfgTabIndex; // SF variables |
| 682 | + global $sfigSettings; // SFI variables |
| 683 | + |
| 684 | + // should the input field be disabled? |
| 685 | + $inputFieldDisabled = |
| 686 | + array_key_exists( 'disable input field', $this->mOtherArgs ) |
| 687 | + || ( !array_key_exists( 'enable input field', $this->mOtherArgs ) && $sfigSettings->datePickerDisableInputField ) |
| 688 | + || $this->mIsDisabled ; |
| 689 | + |
| 690 | + |
| 691 | + // assemble HTML code |
| 692 | + |
| 693 | + // start with the displayed input and append the real, but hidden |
| 694 | + // input that gets sent to SF; it will be filled by the datepicker |
| 695 | + $html = SFIUtils::textHTML( $this->mCurrentValue, '', array_key_exists( 'mandatory', $this->mOtherArgs ), $inputFieldDisabled, |
| 696 | + $this->mOtherArgs, "input_{$sfgFieldNum}_dp_show", null, "createboxInput" ); |
| 697 | + |
| 698 | + if ( ! array_key_exists( 'part of dtp', $this->mOtherArgs ) ) { |
| 699 | + |
| 700 | + $html .= Xml::element( "input", |
| 701 | + array( |
| 702 | + "id" => "input_{$sfgFieldNum}", |
| 703 | + "name" => $this->mInputName, |
| 704 | + "type" => "hidden", |
| 705 | + "value" => $this->mCurrentValue |
| 706 | + ) ); |
| 707 | + |
| 708 | + // wrap in span (e.g. used for mandatory inputs) |
| 709 | + $html = '<span class="inputSpan' . ( array_key_exists( 'mandatory', $this->mOtherArgs ) ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>'; |
| 710 | + } |
| 711 | + |
| 712 | + //return array( $html, "", "initInput$sfgFieldNum" ); |
| 713 | + return $html; |
| 714 | + } |
| 715 | + |
| 716 | + /** |
| 717 | + * Returns the set of SMW property types which this input can |
| 718 | + * handle, but for which it isn't the default input. |
| 719 | + * |
| 720 | + * @return Array of strings |
| 721 | + */ |
| 722 | + public static function getOtherPropTypesHandled() { |
| 723 | + return array('_str', '_dat'); |
| 724 | + } |
| 725 | +} |
| 726 | + |
Property changes on: trunk/extensions/SemanticFormsInputs/includes/SFI_DatePicker.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 727 | + native |
Index: trunk/extensions/SemanticFormsInputs/includes/SFI_TimePicker.php |
— | — | @@ -0,0 +1,307 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SFI_TimePicker class |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticFormsInputs |
| 10 | + */ |
| 11 | +if ( !defined( 'SFI_VERSION' ) ) { |
| 12 | + die( 'This file is part of the SemanticFormsInputs extension, it is not a valid entry point.' ); |
| 13 | +} |
| 14 | + |
| 15 | +/** |
| 16 | + * The SFITimePicker class. |
| 17 | + * |
| 18 | + * @ingroup SemanticFormsInputs |
| 19 | + */ |
| 20 | +class SFITimePicker extends SFFormInput { |
| 21 | + |
| 22 | + /** |
| 23 | + * Constructor. |
| 24 | + * |
| 25 | + * @param String $input_number |
| 26 | + * The number of the input in the form. |
| 27 | + * @param String $cur_value |
| 28 | + * The current value of the input field. |
| 29 | + * @param String $input_name |
| 30 | + * The name of the input. |
| 31 | + * @param String $disabled |
| 32 | + * Is this input disabled? |
| 33 | + * @param Array $other_args |
| 34 | + * An associative array of other parameters that were present in the |
| 35 | + * input definition. |
| 36 | + */ |
| 37 | + public function __construct( $input_number, $cur_value, $input_name, $disabled, $other_args ) { |
| 38 | + |
| 39 | + global $sfigSettings; |
| 40 | + |
| 41 | + parent::__construct( $input_number, $cur_value, $input_name, $disabled, $other_args ); |
| 42 | + |
| 43 | + // third: if the timepicker is not disabled set up JS attributes ans assemble JS call |
| 44 | + if ( !$this->mIsDisabled ) { |
| 45 | + |
| 46 | + self::setup(); |
| 47 | + |
| 48 | + // set min time if valid, else use default |
| 49 | + if ( array_key_exists( 'mintime', $other_args ) |
| 50 | + && ( preg_match( '/^\d+:\d\d$/', trim( $other_args['mintime'] ) ) == 1 ) ) { |
| 51 | + $minTime = trim( $other_args[ 'mintime' ] ); |
| 52 | + } elseif ( $sfigSettings->timePickerMinTime != null ) { |
| 53 | + $minTime = $sfigSettings->timePickerMinTime ; |
| 54 | + } else { |
| 55 | + $minTime = '00:00'; |
| 56 | + } |
| 57 | + |
| 58 | + // set max time if valid, else use default |
| 59 | + if ( array_key_exists( 'maxtime', $other_args ) |
| 60 | + && ( preg_match( '/^\d+:\d\d$/', trim( $other_args['maxtime'] ) ) == 1 ) ) { |
| 61 | + $maxTime = trim( $other_args[ 'maxtime' ] ); |
| 62 | + } elseif ( $sfigSettings->timePickerMaxTime != null ) { |
| 63 | + $maxTime = $sfigSettings->timePickerMaxTime ; |
| 64 | + } else { |
| 65 | + $maxTime = '23:59'; |
| 66 | + } |
| 67 | + |
| 68 | + // set interval if valid, else use default |
| 69 | + if ( array_key_exists( 'interval', $other_args ) |
| 70 | + && preg_match( '/^\d+$/', trim( $other_args['interval'] ) ) == 1 ) { |
| 71 | + $interval = trim( $other_args[ 'interval' ] ); |
| 72 | + } else { |
| 73 | + $interval = '15'; |
| 74 | + } |
| 75 | + |
| 76 | + // build JS code from attributes array |
| 77 | + $jsattribs = array( |
| 78 | + "minTime" => $minTime, |
| 79 | + "maxTime" => $maxTime, |
| 80 | + "interval" => $interval, |
| 81 | + "format" => "hh:mm" |
| 82 | + ); |
| 83 | + |
| 84 | + if ( array_key_exists( 'part of dtp', $other_args ) ) { |
| 85 | + $jsattribs['partOfDTP'] = $other_args['part of dtp']; |
| 86 | + } |
| 87 | + |
| 88 | + $jstext = Xml::encodeJsVar( $jsattribs ); |
| 89 | + |
| 90 | + $this->addJsInitFunctionData( 'SFI_TP_init', $jstext ); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Returns the name of the input type this class handles: menuselect. |
| 96 | + * |
| 97 | + * This is the name to be used in the field definition for the "input type" |
| 98 | + * parameter. |
| 99 | + * |
| 100 | + * @return String The name of the input type this class handles. |
| 101 | + */ |
| 102 | + public static function getName() { |
| 103 | + return 'timepicker'; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Static setup method for input type "menuselect". |
| 108 | + * Adds the Javascript code and css used by all menuselects. |
| 109 | + */ |
| 110 | + static private function setup() { |
| 111 | + |
| 112 | + global $wgOut; |
| 113 | + global $sfigSettings; |
| 114 | + |
| 115 | + static $hasRun = false; |
| 116 | + |
| 117 | + if ( !$hasRun ) { |
| 118 | + $hasRun = true; |
| 119 | + |
| 120 | + $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/timepicker.js"></script> ' ); |
| 121 | + $wgOut->addExtensionStyle( $sfigSettings->scriptPath . '/skins/SFI_Timepicker.css' ); |
| 122 | + |
| 123 | + } |
| 124 | + |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Returns the HTML code to be included in the output page for this input. |
| 129 | + * |
| 130 | + * Ideally this HTML code should provide a basic functionality even if the |
| 131 | + * browser is not Javascript capable. I.e. even without Javascript the user |
| 132 | + * should be able to input values. |
| 133 | + * |
| 134 | + */ |
| 135 | + public function getHtmlText(){ |
| 136 | + |
| 137 | + global $sfigSettings; |
| 138 | + |
| 139 | + // The timepicker is created in four steps: |
| 140 | + // first: set up HTML attributes |
| 141 | + // second: assemble HTML |
| 142 | + |
| 143 | + |
| 144 | + // first: set up HTML attributes |
| 145 | + $inputFieldDisabled = |
| 146 | + array_key_exists( 'disable input field', $this->mOtherArgs ) |
| 147 | + || ( !array_key_exists( 'enable input field', $this->mOtherArgs ) && $sfigSettings->timePickerDisableInputField ) |
| 148 | + || $this->mIsDisabled ; |
| 149 | + |
| 150 | + if ( array_key_exists( 'class', $this->mOtherArgs ) ) $userClasses = $this->mOtherArgs['class']; |
| 151 | + else $userClasses = ""; |
| 152 | + |
| 153 | + // second: assemble HTML |
| 154 | + // create visible input field (for display) and invisible field (for data) |
| 155 | + $html = SFIUtils::textHTML( $this->mCurrentValue, '', array_key_exists('mandatory', $this->mOtherArgs ), $inputFieldDisabled, $this->mOtherArgs, "input_{$this->mInputNumber}_tp_show", null, "createboxInput" ); |
| 156 | + |
| 157 | + if ( ! array_key_exists( 'part of dtp', $this->mOtherArgs ) ) { |
| 158 | + $html .= Xml::element( "input", array( |
| 159 | + 'id' => "input_{$this->mInputNumber}", |
| 160 | + 'type' => 'hidden', |
| 161 | + 'name' => $input_name, |
| 162 | + 'value' => $this->mCurrentValue |
| 163 | + ) ); |
| 164 | + } |
| 165 | + |
| 166 | + // append time picker button |
| 167 | + if ( $this->mIsDisabled ) { |
| 168 | + |
| 169 | + $html .= Xml::openElement( |
| 170 | + "button", |
| 171 | + array( |
| 172 | + 'type' => 'button', |
| 173 | + 'class' => 'createboxInput ' . $userClasses, |
| 174 | + 'disabled' => '1', |
| 175 | + 'id' => "input_{$this->mInputNumber}_button" |
| 176 | + ) ) |
| 177 | + |
| 178 | + . Xml::element( |
| 179 | + "image", |
| 180 | + array( 'src' => $sfigSettings->scriptPath . '/images/TimePickerButtonDisabled.gif' ) |
| 181 | + ) |
| 182 | + |
| 183 | + . Xml::closeElement( "button" ); |
| 184 | + |
| 185 | + } else { |
| 186 | + |
| 187 | + $html .= "<button " |
| 188 | + . Xml::expandAttributes ( array( |
| 189 | + 'type' => 'button', |
| 190 | + 'class' => 'createboxInput ' . $userClasses, |
| 191 | + 'name' => "button", |
| 192 | + ) ) |
| 193 | + . " onclick=\"document.getElementById(this.id.replace('_button','_tp_show')).focus();\"" |
| 194 | + . ">" |
| 195 | + |
| 196 | + . Xml::element( |
| 197 | + "image", |
| 198 | + array( 'src' => $sfigSettings->scriptPath . '/images/TimePickerButton.gif' ) |
| 199 | + ) |
| 200 | + |
| 201 | + . Xml::closeElement( "button" ); |
| 202 | + |
| 203 | + } |
| 204 | + |
| 205 | + // append reset button (if selected) |
| 206 | + if ( ! array_key_exists( 'part of dtp', $this->mOtherArgs ) && |
| 207 | + ( array_key_exists( 'show reset button', $this->mOtherArgs ) || |
| 208 | + $sfigSettings->timePickerShowResetButton && !array_key_exists( 'hide reset button', $this->mOtherArgs ) |
| 209 | + ) |
| 210 | + ) { |
| 211 | + |
| 212 | + if ( $this->mIsDisabled ) { |
| 213 | + |
| 214 | + $html .= Xml::openElement( |
| 215 | + "button", |
| 216 | + array( |
| 217 | + 'type' => 'button', |
| 218 | + 'class' => 'createboxInput ' . $userClasses, |
| 219 | + 'disabled' => '1', |
| 220 | + 'id' => "input_{$this->mInputNumber}_resetbutton" |
| 221 | + ) ) |
| 222 | + |
| 223 | + . Xml::element( |
| 224 | + "image", |
| 225 | + array( 'src' => $sfigSettings->scriptPath . '/images/TimePickerResetButtonDisabled.gif' ) |
| 226 | + |
| 227 | + ) |
| 228 | + . Xml::closeElement( "button" ); |
| 229 | + |
| 230 | + } else { |
| 231 | + |
| 232 | + $html .= "<button " |
| 233 | + . Xml::expandAttributes ( array( |
| 234 | + 'type' => 'button', |
| 235 | + 'class' => 'createboxInput ' . $userClasses, |
| 236 | + 'name' => "resetbutton", |
| 237 | + ) ) |
| 238 | + . " onclick=\"document.getElementById(this.id.replace('_resetbutton','')).value='';" |
| 239 | + . "document.getElementById(this.id.replace('_resetbutton','_tp_show')).value='';\"" |
| 240 | + . ">" |
| 241 | + |
| 242 | + . Xml::element( |
| 243 | + "image", |
| 244 | + array( 'src' => $sfigSettings->scriptPath . '/images/TimePickerResetButton.gif' ) |
| 245 | + |
| 246 | + ) |
| 247 | + . Xml::closeElement( "button" ); |
| 248 | + |
| 249 | + } |
| 250 | + } |
| 251 | + |
| 252 | + // wrap in span (e.g. used for mandatory inputs) |
| 253 | + if ( ! array_key_exists( 'part of dtp', $this->mOtherArgs ) ) { |
| 254 | + $html = '<span class="inputSpan' . ( array_key_exists( 'mandatory', $this->mOtherArgs )? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>'; |
| 255 | + } |
| 256 | + |
| 257 | + |
| 258 | + return $html; |
| 259 | + |
| 260 | + } |
| 261 | + |
| 262 | + /** |
| 263 | + * Returns the set of SMW property types which this input can |
| 264 | + * handle, but for which it isn't the default input. |
| 265 | + */ |
| 266 | + public static function getOtherPropTypesHandled() { |
| 267 | + return array( '_str', '_dat' ); |
| 268 | + } |
| 269 | + |
| 270 | + /** |
| 271 | + * Returns the set of parameters for this form input. |
| 272 | + * |
| 273 | + * TODO: Specify parameters specific for menuselect. |
| 274 | + */ |
| 275 | + public static function getParameters() { |
| 276 | + |
| 277 | + global $sfigSettings; |
| 278 | + |
| 279 | + $params = parent::getParameters(); |
| 280 | + $params[] = array( |
| 281 | + 'name' => 'mintime', |
| 282 | + 'type' => 'string', |
| 283 | + 'description' => wfMsg( 'semanticformsinputs-timepicker-mintime' ), |
| 284 | + ); |
| 285 | + $params[] = array( |
| 286 | + 'name' => 'maxtime', |
| 287 | + 'type' => 'string', |
| 288 | + 'description' => wfMsg( 'semanticformsinputs-timepicker-maxtime' ), |
| 289 | + ); |
| 290 | + $params[] = array( |
| 291 | + 'name' => 'interval', |
| 292 | + 'type' => 'int', |
| 293 | + 'description' => wfMsg( 'semanticformsinputs-timepicker-interval' ), |
| 294 | + ); |
| 295 | + $params[] = array( |
| 296 | + 'name' => $sfigSettings->timePickerDisableInputField?'enable input field':'disable input field', |
| 297 | + 'type' => 'boolean', |
| 298 | + 'description' => wfMsg( 'semanticformsinputs-timepicker-enableinputfield' ), |
| 299 | + ); |
| 300 | + $params[] = array( |
| 301 | + 'name' => $sfigSettings->timePickerShowResetButton?'hide reset button':'show reset button', |
| 302 | + 'type' => 'boolean', |
| 303 | + 'description' => wfMsg( 'semanticformsinputs-timepicker-showresetbutton' ), |
| 304 | + ); |
| 305 | + |
| 306 | + return $params; |
| 307 | + } |
| 308 | +} |
Property changes on: trunk/extensions/SemanticFormsInputs/includes/SFI_TimePicker.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 309 | + native |
Index: trunk/extensions/SemanticFormsInputs/includes/SFI_Settings.php |
— | — | @@ -0,0 +1,165 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Settings for the Semantic Forms Inputs extension. |
| 5 | + * |
| 6 | + * @author Stephan Gambke |
| 7 | + * |
| 8 | + * To change the default settings you can uncomment (or copy) the |
| 9 | + * examples here and adjust them to your needs. You may as well |
| 10 | + * include them in your LocalSettings.php. |
| 11 | + */ |
| 12 | + |
| 13 | +if ( !defined( 'SFI_VERSION' ) ) { |
| 14 | + die( 'This file is part of the SemanticFormsInputs extension, it is not a valid entry point.' ); |
| 15 | +} |
| 16 | + |
| 17 | +## |
| 18 | +# This is the path to your installation of Semantic Forms Inputs as |
| 19 | +# seen from the web. No final slash. |
| 20 | +# |
| 21 | +$sfigSettings->scriptPath = $wgScriptPath . '/extensions/SemanticFormsInputs'; |
| 22 | + |
| 23 | +## Date Picker Settings |
| 24 | + |
| 25 | +## |
| 26 | +# This is the first selectable date (format yyyy/mm/dd) |
| 27 | +# Sample value: '2005/01/01' |
| 28 | +# |
| 29 | +$sfigSettings->datePickerFirstDate = null; |
| 30 | + |
| 31 | +## |
| 32 | +# This is the last selectable date (format yyyy/mm/dd) |
| 33 | +# Sample value: '2015/31/12' |
| 34 | +# |
| 35 | +$sfigSettings->datePickerLastDate = null; |
| 36 | + |
| 37 | +## |
| 38 | +# The date format string used for the user input. |
| 39 | +# The date sent back to the form is fixed to yyyy/mm/dd |
| 40 | +# (that is, yy/mm/dd in the format code below). |
| 41 | +# |
| 42 | +# The format can be combinations of the following: |
| 43 | +# |
| 44 | +# d - day of month (no leading zero) |
| 45 | +# dd - day of month (two digit) |
| 46 | +# o - day of the year (no leading zeros) |
| 47 | +# oo - day of the year (three digit) |
| 48 | +# D - day name short |
| 49 | +# DD - day name long |
| 50 | +# m - month of year (no leading zero) |
| 51 | +# mm - month of year (two digit) |
| 52 | +# M - month name short |
| 53 | +# MM - month name long |
| 54 | +# y - year (two digit) |
| 55 | +# yy - year (four digit) |
| 56 | +# @ - Unix timestamp (ms since 01/01/1970) |
| 57 | +# ! - Windows ticks (100ns since 01/01/0001) |
| 58 | +# '...' - literal text |
| 59 | +# '' - single quote |
| 60 | +# anything else - literal text |
| 61 | +# |
| 62 | +# There are also two predefined standard date formats available: |
| 63 | +# |
| 64 | +# SHORT - short date format localized to the wiki user language |
| 65 | +# LONG - long date format localized to the wiki user language |
| 66 | +# |
| 67 | +$sfigSettings->datePickerDateFormat = 'SHORT'; |
| 68 | + |
| 69 | +## |
| 70 | +# This determines the start of the week in the display. |
| 71 | +# Set it to: 0 (Zero) for Sunday, 1 (One) for Monday etc. |
| 72 | +# If set to null the day is localized to the wiki user language |
| 73 | +# Sample value: 1 |
| 74 | +# |
| 75 | +$sfigSettings->datePickerWeekStart = null; |
| 76 | + |
| 77 | +## |
| 78 | +# This determines if the number of the week shall be shown. |
| 79 | +# |
| 80 | +$sfigSettings->datePickerShowWeekNumbers = false; |
| 81 | + |
| 82 | +## |
| 83 | +# This determines if the input field shall be disabled. The user can |
| 84 | +# only set the date via the datepicker in this case. |
| 85 | +# |
| 86 | +$sfigSettings->datePickerDisableInputField = false; |
| 87 | + |
| 88 | +## |
| 89 | +# This determines if a reset button shall be shown. This is the only |
| 90 | +# way to erase the input field if it is disabled for direct input. |
| 91 | +# |
| 92 | +$sfigSettings->datePickerShowResetButton = false; |
| 93 | + |
| 94 | +## |
| 95 | +# This is a string of disabled days of the week, i.e. days the user can not |
| 96 | +# pick. The days must be given as comma-separated list of numbers starting |
| 97 | +# with 0 for Sunday. |
| 98 | +# Sample value: "6,0" |
| 99 | +# |
| 100 | +$sfigSettings->datePickerDisabledDaysOfWeek = null; |
| 101 | + |
| 102 | +## |
| 103 | +# This is a string of highlighted days of the week. The days must be given as |
| 104 | +# comma-separated list of numbers starting with 0 for Sunday. |
| 105 | +# Sample value: "6,0" |
| 106 | +# |
| 107 | +$sfigSettings->datePickerHighlightedDaysOfWeek = null; |
| 108 | + |
| 109 | +## |
| 110 | +# This is a string of disabled dates, i.e. days the user cannot pick. The |
| 111 | +# days must be given as comma-separated list of dates or date ranges. The |
| 112 | +# format for days is yyyy/mm/dd, for date ranges use yyyy/mm/dd-yyyy/mm/dd. |
| 113 | +# Spaces are permissible. |
| 114 | +# Sample value: "2010/12/25 - 2011/01/06, 2011/05/01" |
| 115 | +# |
| 116 | +$sfigSettings->datePickerDisabledDates = null; |
| 117 | + |
| 118 | +## |
| 119 | +# This is a string of highlighted dates. The days must be given as |
| 120 | +# comma-separated list of dates or date ranges. The format for days is |
| 121 | +# yyyy/mm/dd, for date ranges use yyyy/mm/dd-yyyy/mm/dd. Spaces are |
| 122 | +# permissible. |
| 123 | +# Sample value: "2010/12/25 - 2011/01/06, 2011/05/01" |
| 124 | +# |
| 125 | +$sfigSettings->datePickerHighlightedDates = null; |
| 126 | + |
| 127 | + |
| 128 | +## Time Picker Settings |
| 129 | + |
| 130 | +## |
| 131 | +# This is the first selectable time (format hh:mm) |
| 132 | +# Sample value: '00:00' |
| 133 | +# |
| 134 | +$sfigSettings->timePickerMinTime = null; |
| 135 | + |
| 136 | +## |
| 137 | +# This is the last selectable time (format hh:mm) |
| 138 | +# Sample value: '24:00' |
| 139 | +# |
| 140 | +$sfigSettings->timePickerMaxTime = null; |
| 141 | + |
| 142 | +## |
| 143 | +# This determines if the input field shall be disabled. The user can |
| 144 | +# only set the time via the timepicker in this case. |
| 145 | +# |
| 146 | +$sfigSettings->timePickerDisableInputField = false; |
| 147 | + |
| 148 | +## |
| 149 | +# This determines if a reset button shall be shown. This is the only |
| 150 | +# way to erase the input field if it is disabled for direct input. |
| 151 | +# |
| 152 | +$sfigSettings->timePickerShowResetButton = false; |
| 153 | + |
| 154 | + |
| 155 | +## |
| 156 | +# This determines if a reset button shall be shown. This is the only |
| 157 | +# way to erase the input field if it is disabled for direct input. |
| 158 | +# |
| 159 | +$sfigSettings->datetimePickerShowResetButton = false; |
| 160 | + |
| 161 | +## |
| 162 | +# This determines if the input field shall be disabled. The user can |
| 163 | +# only set the value via the menu in this case. |
| 164 | +# |
| 165 | +$sfigSettings->menuSelectDisableInputField = false; |
| 166 | + |
Property changes on: trunk/extensions/SemanticFormsInputs/includes/SFI_Settings.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 167 | + native |
Index: trunk/extensions/SemanticFormsInputs/includes/SFI_Utils.php |
— | — | @@ -0,0 +1,88 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Input definitions for the Semantic Forms Inputs extension. |
| 5 | + * |
| 6 | + * @author Stephan Gambke |
| 7 | + * @author Sanyam Goyal |
| 8 | + * @author Yaron Koren |
| 9 | + * |
| 10 | + */ |
| 11 | + |
| 12 | +if ( !defined( 'SFI_VERSION' ) ) { |
| 13 | + die( 'This file is part of a MediaWiki extension, it is not a valid entry point.' ); |
| 14 | +} |
| 15 | + |
| 16 | +class SFIUtils { |
| 17 | + |
| 18 | + /** |
| 19 | + * Creates the html text for an input. |
| 20 | + * |
| 21 | + * Common attributes for input types are set according to the parameters. |
| 22 | + * The parameters are the standard parameters set by Semantic Forms' |
| 23 | + * InputTypeHook plus some optional. |
| 24 | + * |
| 25 | + * @param string $cur_value |
| 26 | + * @param string $input_name |
| 27 | + * @param boolean $is_mandatory |
| 28 | + * @param boolean $is_disabled |
| 29 | + * @param array $other_args |
| 30 | + * @param string $input_id (optional) |
| 31 | + * @param int $tabindex (optional) |
| 32 | + * @param string $class |
| 33 | + * @return string the html text of an input element |
| 34 | + */ |
| 35 | + static function textHTML ( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args, $input_id = null, $tabindex = null, $class = "" ) { |
| 36 | + |
| 37 | + global $sfgFieldNum, $sfgTabIndex; |
| 38 | + |
| 39 | + // array of attributes to pass to the input field |
| 40 | + $attribs = array( |
| 41 | + "name" => $input_name, |
| 42 | + "class" => $class, |
| 43 | + "value" => $cur_value, |
| 44 | + "type" => "text" |
| 45 | + ); |
| 46 | + |
| 47 | + // set size attrib |
| 48 | + if ( array_key_exists( 'size', $other_args ) ) { |
| 49 | + $attribs['size'] = $other_args['size']; |
| 50 | + } |
| 51 | + |
| 52 | + // set maxlength attrib |
| 53 | + if ( array_key_exists( 'maxlength', $other_args ) ) { |
| 54 | + $attribs['maxlength'] = $other_args['maxlength']; |
| 55 | + } |
| 56 | + |
| 57 | + // modify class attribute for mandatory form fields |
| 58 | + if ( $is_mandatory ) { |
| 59 | + $attribs["class"] .= ' mandatoryField'; |
| 60 | + } |
| 61 | + |
| 62 | + // add user class(es) to class attribute of input field |
| 63 | + if ( array_key_exists( 'class', $other_args ) ) { |
| 64 | + $attribs["class"] .= ' ' . $other_args['class']; |
| 65 | + } |
| 66 | + |
| 67 | + // set readonly attrib |
| 68 | + if ( $is_disabled ) { |
| 69 | + $attribs["readonly"] = "1"; |
| 70 | + } |
| 71 | + |
| 72 | + // if no special input id is specified set the Semantic Forms standard |
| 73 | + if ( $input_id == null ) { |
| 74 | + $attribs[ 'id' ] = "input_" . $sfgFieldNum; |
| 75 | + } else { |
| 76 | + $attribs[ 'id' ] = $input_id; |
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | + if ( $tabindex == null ) $attribs[ 'tabindex' ] = $sfgTabIndex; |
| 81 | + else $attribs[ 'tabindex' ] = $tabindex; |
| 82 | + |
| 83 | + // $html = Html::element( "input", $attribs ); |
| 84 | + $html = Xml::element( "input", $attribs ); |
| 85 | + |
| 86 | + return $html; |
| 87 | + |
| 88 | + } |
| 89 | +} |
Property changes on: trunk/extensions/SemanticFormsInputs/includes/SFI_Utils.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 90 | + native |
Index: trunk/extensions/SemanticFormsInputs/includes/SFI_MenuSelect.php |
— | — | @@ -0,0 +1,164 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SFIMenuSelect class. |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * |
| 9 | + * @file |
| 10 | + * @ingroup SFI |
| 11 | + */ |
| 12 | +if ( !defined( 'SFI_VERSION' ) ) { |
| 13 | + die( 'This file is part of the Semantic Forms Inputs extension, it is not a valid entry point.' ); |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * This class represents the MenuSelect input. |
| 18 | + * |
| 19 | + * @ingroup SFI |
| 20 | + */ |
| 21 | +class SFIMenuSelect extends SFFormInput { |
| 22 | + |
| 23 | + |
| 24 | + /** |
| 25 | + * Constructor. |
| 26 | + * |
| 27 | + * @param String $input_number |
| 28 | + * The number of the input in the form. |
| 29 | + * @param String $cur_value |
| 30 | + * The current value of the input field. |
| 31 | + * @param String $input_name |
| 32 | + * The name of the input. |
| 33 | + * @param String $disabled |
| 34 | + * Is this input disabled? |
| 35 | + * @param Array $other_args |
| 36 | + * An associative array of other parameters that were present in the |
| 37 | + * input definition. |
| 38 | + */ |
| 39 | + public function __construct( $input_number, $cur_value, $input_name, $disabled, $other_args ) { |
| 40 | + |
| 41 | + parent::__construct( $input_number, $cur_value, $input_name, $disabled, $other_args ); |
| 42 | + |
| 43 | + self::setup(); |
| 44 | + |
| 45 | + $this->addJsInitFunctionData( 'SFI_MS_init', 'null' ); |
| 46 | + |
| 47 | + |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Returns the name of the input type this class handles: menuselect. |
| 52 | + * |
| 53 | + * This is the name to be used in the field definition for the "input type" |
| 54 | + * parameter. |
| 55 | + * |
| 56 | + * @return String The name of the input type this class handles. |
| 57 | + */ |
| 58 | + public static function getName() { |
| 59 | + return 'menuselect'; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Static setup method for input type "menuselect". |
| 64 | + * Adds the Javascript code and css used by all menuselects. |
| 65 | + */ |
| 66 | + static private function setup() { |
| 67 | + |
| 68 | + global $wgOut; |
| 69 | + global $sfigSettings; |
| 70 | + |
| 71 | + static $hasRun = false; |
| 72 | + |
| 73 | + if ( !$hasRun ) { |
| 74 | + $hasRun = true; |
| 75 | + $wgOut->addScript( '<script type="text/javascript">sfigScriptPath="' . $sfigSettings->scriptPath . '";</script> ' ); |
| 76 | + $wgOut->addScript( '<script type="text/javascript" src="' . $sfigSettings->scriptPath . '/libs/menuselect.js"></script> ' ); |
| 77 | + $wgOut->addExtensionStyle( $sfigSettings->scriptPath . '/skins/SFI_Menuselect.css' ); |
| 78 | + } |
| 79 | + |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Returns the HTML code to be included in the output page for this input. |
| 84 | + * |
| 85 | + * Ideally this HTML code should provide a basic functionality even if the |
| 86 | + * browser is not Javascript capable. I.e. even without Javascript the user |
| 87 | + * should be able to input values. |
| 88 | + * |
| 89 | + */ |
| 90 | + public function getHtmlText(){ |
| 91 | + |
| 92 | + global $wgUser, $wgTitle; |
| 93 | + global $sfigSettings; |
| 94 | + |
| 95 | + // first: set up HTML attributes |
| 96 | + $inputFieldDisabled = |
| 97 | + array_key_exists( 'disable input field', $this->mOtherArgs ) |
| 98 | + || $this->mIsDisabled |
| 99 | + || ( $sfigSettings->menuSelectDisableInputField && !array_key_exists( 'enable input field', $this->mOtherArgs ) ); |
| 100 | + |
| 101 | + // second: assemble HTML |
| 102 | + // create visible input field (for display) and invisible field (for data) |
| 103 | + $html = SFIUtils::textHTML( $this->mCurrentValue, '', array_key_exists( 'mandatory', $this->mOtherArgs ), $inputFieldDisabled, $this->mOtherArgs, "input_{$this->mInputNumber}_show", null, "createboxInput" ) |
| 104 | + . Xml::element( "input", array( |
| 105 | + 'id' => "input_{$this->mInputNumber}", |
| 106 | + 'type' => 'hidden', |
| 107 | + 'name' => $this->mInputName, |
| 108 | + 'value' => $this->mCurrentValue |
| 109 | + ) ); |
| 110 | + |
| 111 | + |
| 112 | + $html .= "<span class='SFI_menuselect' id='span_{$this->mInputNumber}_tree'>"; |
| 113 | + |
| 114 | + |
| 115 | + // parse menu structure |
| 116 | + |
| 117 | + $parser = new Parser(); |
| 118 | + |
| 119 | + // FIXME: SF does not parse options correctly. Users have to replace | by {{!}} |
| 120 | + $structure = str_replace( '{{!}}', '|', $this->mOtherArgs['structure'] ); |
| 121 | + $options = ParserOptions::newFromUser( $wgUser ); |
| 122 | + |
| 123 | + $structure = $parser->parse( $structure, $wgTitle, $options )->getText(); |
| 124 | + |
| 125 | + $html .= str_replace( '<li', '<li class=\'ui-state-default\'', $structure ); |
| 126 | + |
| 127 | + $html .= "</span>"; |
| 128 | + |
| 129 | + // wrap in span (e.g. used for mandatory inputs) |
| 130 | + $html = '<span class="inputSpan' . ($this->mIsMandatory ? ' mandatoryFieldSpan' : '') . '">' .$html . '</span>'; |
| 131 | + |
| 132 | + return $html; |
| 133 | + |
| 134 | + |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Returns the set of SMW property types which this input can |
| 139 | + * handle, but for which it isn't the default input. |
| 140 | + */ |
| 141 | + public static function getOtherPropTypesHandled() { |
| 142 | + return array( '_str', '_wpg' ); |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * Returns the set of parameters for this form input. |
| 147 | + * |
| 148 | + * TODO: Specify parameters specific for menuselect. |
| 149 | + */ |
| 150 | + public static function getParameters() { |
| 151 | + $params = parent::getParameters(); |
| 152 | + $params[] = array( |
| 153 | + 'name' => 'structure', |
| 154 | + 'type' => 'text', |
| 155 | + 'description' => wfMsg( 'semanticformsinputs-menuselect-structure' ), |
| 156 | + 'default' => "* item 1\n** item 11\n** item 12\n* item 2\n** item 21\n** item 22" |
| 157 | + ); |
| 158 | + $params[] = array( |
| 159 | + 'name' => $sfigSettings->menuSelectDisableInputField?'enable input field':'disable input field', |
| 160 | + 'type' => 'boolean', |
| 161 | + 'description' => wfMsg( 'semanticformsinputs-menuselect-enableinputfield' ), |
| 162 | + ); |
| 163 | + return $params; |
| 164 | + } |
| 165 | +} |
Property changes on: trunk/extensions/SemanticFormsInputs/includes/SFI_MenuSelect.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 166 | + native |
Index: trunk/extensions/SemanticFormsInputs/libs/timepicker.js |
— | — | @@ -16,9 +16,9 @@ |
17 | 17 | * format: (String) a format string (unused) (do we even need it?) |
18 | 18 | * |
19 | 19 | */ |
20 | | -function SFI_TP_init( inputIDshow, params ) { // minTime, maxTime, interval, format |
| 20 | +function SFI_TP_init( inputID, params ) { // minTime, maxTime, interval, format |
21 | 21 | |
22 | | - var inputID = inputIDshow.replace( "_tp_show", "" ); |
| 22 | + var inputIDshow = inputID + "_tp_show"; |
23 | 23 | |
24 | 24 | // sanitize inputs |
25 | 25 | var re = /^\d+:\d\d$/; |