r36263 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36262‎ | r36263 | r36264 >
Date:15:36, 13 June 2008
Author:yaron
Status:old
Tags:
Comment:
Fixes for autocompletion, added handling for uploading for fields that contain
a list of files instead of just one
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormInputs.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.inc
@@ -14,12 +14,11 @@
1515 // the query depends on whether this field is a relation (property of type
1616 // Page), attribute (property of any other type), category or namespace
1717 if ($autocomplete_field_type == 'relation' || $autocomplete_field_type == 'attribute' || $autocomplete_field_type == 'property') {
18 - $smw_version = SMW_VERSION;
19 - if ($smw_version{0} == '0') {
 18+ if (version_compare(SMW_VERSION, '1.2', '>=' )) {
 19+ $names_array = sffGetAllPagesForProperty_1_2($field_name);
 20+ } else {
2021 $is_relation = ($autocomplete_field_type == 'relation');
2122 $names_array = sffGetAllPagesForProperty_0_7($is_relation, $field_name);
22 - } else {
23 - $names_array = sffGetAllPagesForProperty_1_0($field_name);
2423 }
2524 } elseif ($autocomplete_field_type == 'category') {
2625 $names_array = sffGetAllPagesForCategory($field_name, 10);
@@ -29,19 +28,32 @@
3029 return $names_array;
3130 }
3231
 32+ function uploadLinkHTML($input_id, $delimiter = null) {
 33+ $upload_window_page = SpecialPage::getPage('UploadWindow');
 34+ $query_string = "sfInputID=$input_id";
 35+ if ($delimiter != null)
 36+ $query_string .= "&sfDelimiter=$delimiter";
 37+ $upload_window_url = $upload_window_page->getTitle()->getFullURL($query_string);
 38+ $upload_label = wfMsg('upload');
 39+ $text = " <a href=\"$upload_window_url\" title=\"$upload_label\" rel=\"iframe\" rev=\"width:550 height:380\">$upload_label</a>";
 40+ return $text;
 41+ }
 42+
3343 function textEntryHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
3444 // if it's an autocomplete, call the with-autocomplete function instead
3545 // we test to make sure that autocompletion hasn't been disabled, and
3646 // that either the property is a relation (i.e. it's of type Page) or
37 - // autocompletion has been specifified in the form
38 - $autocompletion_disabled = array_key_exists('autocomplete on', $other_args) && $other_args['autocomplete on'] == "";
 47+ // autocompletion has been specified in the form
 48+ $autocompletion_disabled = (array_key_exists('autocomplete on', $other_args) && $other_args['autocomplete on'] == "") ||
 49+ (array_key_exists('no autocomplete', $other_args) && $other_args['no autocomplete'] == true);
3950 if (! $autocompletion_disabled) {
4051 if ((array_key_exists('is_relation', $other_args) && $other_args['is_relation'] == true) ||
4152 array_key_exists('autocomplete', $other_args) ||
4253 array_key_exists('autocomplete on property', $other_args) ||
4354 array_key_exists('autocomplete on category', $other_args) ||
4455 array_key_exists('autocomplete on', $other_args) ||
45 - array_key_exists('autocomplete on namespace', $other_args)) {
 56+ array_key_exists('autocomplete on namespace', $other_args) ||
 57+ array_key_exists('remote autocompletion', $other_args)) {
4658 return SFFormInputs::textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
4759 }
4860 }
@@ -103,10 +115,16 @@
104116
105117 END;
106118 if (array_key_exists('is_uploadable', $other_args) && $other_args['is_uploadable'] == true) {
107 - $upload_window_page = SpecialPage::getPage('UploadWindow');
108 - $upload_window_url = $upload_window_page->getTitle()->getFullURL("wpInputID=$input_id");
109 - $upload_label = wfMsg('upload');
110 - $text .= " <a href=\"$upload_window_url\" title=\"$upload_label\" rel=\"iframe\" rev=\"width:550 height:380\">$upload_label</a>";
 119+ if (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true) {
 120+ if (array_key_exists('delimiter', $other_args)) {
 121+ $delimiter = $other_args['delimiter'];
 122+ } else {
 123+ $delimiter = ",";
 124+ }
 125+ } else {
 126+ $delimiter = null;
 127+ }
 128+ $text .= SFFormInputs::uploadLinkHTML($input_id, $delimiter);
111129 }
112130 return array($text, null);
113131 }
@@ -304,11 +322,19 @@
305323 $text .= ' maxlength="' . $other_args['maxlength'] . '"';
306324 $text .= "/>\n";
307325 }
 326+ // is_list and delimiter variables - needed later
 327+ $is_list = (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true);
 328+ if ($is_list) {
 329+ if (array_key_exists('delimiter', $other_args)) {
 330+ $delimiter = $other_args['delimiter'];
 331+ } else {
 332+ $delimiter = ",";
 333+ }
 334+ } else {
 335+ $delimiter = null;
 336+ }
308337 if (array_key_exists('is_uploadable', $other_args) && $other_args['is_uploadable'] == true) {
309 - $upload_window_page = SpecialPage::getPage('UploadWindow');
310 - $upload_window_url = $upload_window_page->getTitle()->getFullURL("wpInputID=$input_id");
311 - $upload_label = wfMsg('upload');
312 - $text .= " <a href=\"$upload_window_url\" title=\"$upload_label\" rel=\"iframe\" rev=\"width:550 height:380\">$upload_label</a>";
 338+ $text .= SFFormInputs::uploadLinkHTML($input_id, $delimiter);
313339 }
314340 $text .=<<<END
315341 <span id="$info_id" class="errorMessage"></span>
@@ -317,10 +343,10 @@
318344
319345 END;
320346 $options_str_key = str_replace("'", "\'", $semantic_field_name);
321 - if (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true) {
 347+ if ($is_list) {
322348 $options_str_key .= ",list";
323 - if (array_key_exists('delimiter', $other_args) && $other_args['delimiter'] != ",") {
324 - $options_str_key .= "," . $other_args['delimiter'];
 349+ if ($delimiter != ",") {
 350+ $options_str_key .= "," . $delimiter;
325351 }
326352 }
327353 $javascript_text = "autocompletemappings[$sfgFieldNum] = '$options_str_key';\n";
@@ -352,7 +378,8 @@
353379 if ((array_key_exists('is_relation', $other_args) && $other_args['is_relation'] == true) ||
354380 array_key_exists('autocomplete', $other_args) ||
355381 array_key_exists('autocomplete on', $other_args) ||
356 - array_key_exists('autocomplete on namespace', $other_args)) {
 382+ array_key_exists('autocomplete on namespace', $other_args) ||
 383+ array_key_exists('remote autocompletion', $other_args)) {
357384 $other_args['input_type'] = "textarea";
358385 return SFFormInputs::textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
359386 }

Status & tagging log