r38978 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38977‎ | r38978 | r38979 >
Date:01:58, 9 August 2008
Author:dantman
Status:old
Tags:
Comment:
Whitespace fixes for Semantic Forms.
Half the extension uses tabs, the other uses two spaces. Standardizing the extension to use tabs and removing trailing ?>'s.
((My next commit would be filled with bad whitespace if this isn't fixed))
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormClasses.inc (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormEditTab.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormInputs.inc (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_Settings.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_TemplateField.inc (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateForm.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_Templates.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_CreateForm.php
@@ -25,163 +25,163 @@
2626 }
2727
2828 function doSpecialCreateForm() {
29 - global $wgOut, $wgRequest, $wgUser, $sfgScriptPath, $wgContLang;
30 - $db = wfGetDB( DB_SLAVE );
 29+ global $wgOut, $wgRequest, $wgUser, $sfgScriptPath, $wgContLang;
 30+ $db = wfGetDB( DB_SLAVE );
3131
32 - # get the names of all templates on this site
33 - $all_templates = array();
34 - $sql = "SELECT page_title FROM {$db->tableName( 'page' )} WHERE page_namespace=" . NS_TEMPLATE . " AND page_is_redirect = 0 ORDER BY page_title";
35 - $res = $db->query( $sql );
36 - if ($db->numRows( $res ) > 0) {
37 - while ($row = $db->fetchRow($res)) {
38 - $template_name = str_replace('_', ' ', $row[0]);
39 - $all_templates[] = $template_name;
40 - }
41 - }
 32+ # get the names of all templates on this site
 33+ $all_templates = array();
 34+ $sql = "SELECT page_title FROM {$db->tableName( 'page' )} WHERE page_namespace=" . NS_TEMPLATE . " AND page_is_redirect = 0 ORDER BY page_title";
 35+ $res = $db->query( $sql );
 36+ if ($db->numRows( $res ) > 0) {
 37+ while ($row = $db->fetchRow($res)) {
 38+ $template_name = str_replace('_', ' ', $row[0]);
 39+ $all_templates[] = $template_name;
 40+ }
 41+ }
4242
43 - $form_templates = array();
44 - $i = 1;
45 - $deleted_template_loc = null;
 43+ $form_templates = array();
 44+ $i = 1;
 45+ $deleted_template_loc = null;
4646
47 - # handle inputs
48 - $form_name = $wgRequest->getVal('form_name');
49 - foreach ($wgRequest->getValues() as $var => $val) {
50 - # ignore variables that are not of the right form
51 - if (strpos($var, "_") != false) {
52 - # get the template declarations and work from there
53 - list ($action, $id) = explode("_", $var, 2);
54 - if ($action == "template") {
55 - # if the button was pressed to remove this template, just don't
56 - # add it to the array
57 - if ($wgRequest->getVal("del_$id") != null) {
58 - $deleted_template_loc = $id;
59 - } else {
60 - $form_template = SFTemplateInForm::create($val,
61 - $wgRequest->getVal("label_$id"),
62 - $wgRequest->getVal("allow_multiple_$id"));
63 - $form_templates[] = $form_template;
64 - }
65 - }
66 - }
67 - }
68 - if ($wgRequest->getVal('add_field') != null) {
69 - $form_template = SFTemplateInForm::create($wgRequest->getVal('new_template'), "", false);
70 - $new_template_loc = $wgRequest->getVal('before_template');
71 - if ($new_template_loc === null) { $new_template_loc = 0; }
72 - # hack - array_splice() doesn't work for objects, so we have to
73 - # first insert a stub element into the array, then replace that with
74 - # the actual object
75 - array_splice($form_templates, $new_template_loc, 0, "stub");
76 - $form_templates[$new_template_loc] = $form_template;
77 - } else {
78 - $new_template_loc = null;
79 - }
 47+ # handle inputs
 48+ $form_name = $wgRequest->getVal('form_name');
 49+ foreach ($wgRequest->getValues() as $var => $val) {
 50+ # ignore variables that are not of the right form
 51+ if (strpos($var, "_") != false) {
 52+ # get the template declarations and work from there
 53+ list ($action, $id) = explode("_", $var, 2);
 54+ if ($action == "template") {
 55+ # if the button was pressed to remove this template, just don't
 56+ # add it to the array
 57+ if ($wgRequest->getVal("del_$id") != null) {
 58+ $deleted_template_loc = $id;
 59+ } else {
 60+ $form_template = SFTemplateInForm::create($val,
 61+ $wgRequest->getVal("label_$id"),
 62+ $wgRequest->getVal("allow_multiple_$id"));
 63+ $form_templates[] = $form_template;
 64+ }
 65+ }
 66+ }
 67+ }
 68+ if ($wgRequest->getVal('add_field') != null) {
 69+ $form_template = SFTemplateInForm::create($wgRequest->getVal('new_template'), "", false);
 70+ $new_template_loc = $wgRequest->getVal('before_template');
 71+ if ($new_template_loc === null) { $new_template_loc = 0; }
 72+ # hack - array_splice() doesn't work for objects, so we have to
 73+ # first insert a stub element into the array, then replace that with
 74+ # the actual object
 75+ array_splice($form_templates, $new_template_loc, 0, "stub");
 76+ $form_templates[$new_template_loc] = $form_template;
 77+ } else {
 78+ $new_template_loc = null;
 79+ }
8080
81 - # now cycle through the templates and fields, modifying each one
82 - # per the query variables
83 - foreach ($form_templates as $i => $ft) {
84 - foreach ($ft->fields as $j => $field) {
85 - // handle the change in indexing if a new template was inserted
86 - // before the end, or one was deleted
87 - $old_i = $i;
88 - if ($new_template_loc != null) {
89 - if ($i > $new_template_loc) {
90 - $old_i = $i - 1;
91 - } elseif ($i == $new_template_loc) {
92 - // it's the new template; it shouldn't get any query string data
93 - $old_i = -1;
94 - }
95 - } elseif ($deleted_template_loc != null) {
96 - if ($i >= $deleted_template_loc) {
97 - $old_i = $i + 1;
98 - }
99 - }
100 - $new_label = $wgRequest->getVal("label_" . $old_i . "_" . $j);
101 - if ($new_label)
102 - $field->template_field->label = $new_label;
103 - $input_type = $wgRequest->getVal("input_type_" . $old_i . "_" . $j);
104 - $field->template_field->input_type = $input_type;
105 - if ($wgRequest->getVal("hidden_" . $old_i . "_" . $j) == "hidden") {
106 - $field->is_hidden = true;
107 - }
108 - if ($wgRequest->getVal("restricted_" . $old_i . "_" . $j) == "restricted") {
109 - $field->is_restricted = true;
110 - }
111 - if ($wgRequest->getVal("mandatory_" . $old_i . "_" . $j) == "mandatory") {
112 - $field->is_mandatory = true;
113 - }
114 - }
115 - }
116 - $form = SFForm::create($form_name, $form_templates);
 81+ # now cycle through the templates and fields, modifying each one
 82+ # per the query variables
 83+ foreach ($form_templates as $i => $ft) {
 84+ foreach ($ft->fields as $j => $field) {
 85+ // handle the change in indexing if a new template was inserted
 86+ // before the end, or one was deleted
 87+ $old_i = $i;
 88+ if ($new_template_loc != null) {
 89+ if ($i > $new_template_loc) {
 90+ $old_i = $i - 1;
 91+ } elseif ($i == $new_template_loc) {
 92+ // it's the new template; it shouldn't get any query string data
 93+ $old_i = -1;
 94+ }
 95+ } elseif ($deleted_template_loc != null) {
 96+ if ($i >= $deleted_template_loc) {
 97+ $old_i = $i + 1;
 98+ }
 99+ }
 100+ $new_label = $wgRequest->getVal("label_" . $old_i . "_" . $j);
 101+ if ($new_label)
 102+ $field->template_field->label = $new_label;
 103+ $input_type = $wgRequest->getVal("input_type_" . $old_i . "_" . $j);
 104+ $field->template_field->input_type = $input_type;
 105+ if ($wgRequest->getVal("hidden_" . $old_i . "_" . $j) == "hidden") {
 106+ $field->is_hidden = true;
 107+ }
 108+ if ($wgRequest->getVal("restricted_" . $old_i . "_" . $j) == "restricted") {
 109+ $field->is_restricted = true;
 110+ }
 111+ if ($wgRequest->getVal("mandatory_" . $old_i . "_" . $j) == "mandatory") {
 112+ $field->is_mandatory = true;
 113+ }
 114+ }
 115+ }
 116+ $form = SFForm::create($form_name, $form_templates);
117117
118 - # if submit button was pressed, create the form definitions file, then redirect
119 - $save_page = $wgRequest->getCheck('wpSave');
120 - $preview_page = $wgRequest->getCheck('wpPreview');
121 - if ($save_page || $preview_page) {
122 - # validate form name
123 - if ($form->form_name == "") {
124 - $form_name_error_str = wfMsg('sf_blank_error');
125 - } else {
126 - $title = Title::newFromText($form->form_name, SF_NS_FORM);
127 - $full_text = str_replace('"', '"', $form->createMarkup());
128 - # redirect to wiki interface
129 - $text = sffPrintRedirectForm($title, $full_text, "", $save_page, $preview_page, false, false, false, null, null);
130 - $wgOut->addHTML($text);
131 - return;
132 - }
133 - }
 118+ # if submit button was pressed, create the form definitions file, then redirect
 119+ $save_page = $wgRequest->getCheck('wpSave');
 120+ $preview_page = $wgRequest->getCheck('wpPreview');
 121+ if ($save_page || $preview_page) {
 122+ # validate form name
 123+ if ($form->form_name == "") {
 124+ $form_name_error_str = wfMsg('sf_blank_error');
 125+ } else {
 126+ $title = Title::newFromText($form->form_name, SF_NS_FORM);
 127+ $full_text = str_replace('"', '"', $form->createMarkup());
 128+ # redirect to wiki interface
 129+ $text = sffPrintRedirectForm($title, $full_text, "", $save_page, $preview_page, false, false, false, null, null);
 130+ $wgOut->addHTML($text);
 131+ return;
 132+ }
 133+ }
134134
135 - $text = ' <form action="" method="post">' . "\n";
136 - // set 'title' field, in case there's no URL niceness
137 - $mw_namespace_labels = $wgContLang->getNamespaces();
138 - $special_namespace = $mw_namespace_labels[NS_SPECIAL];
139 - $text .= ' <input type="hidden" name="title" value="' . $special_namespace . ':CreateForm">' . "\n";
140 - $text .= ' <p>' . wfMsg('sf_createform_nameinput') . ' <input size=25 name="form_name" value="' . $form_name . '">';
141 - if (! empty($form_name_error_str))
142 - $text .= ' <font color="red">' . $form_name_error_str . '</font>';
143 - $text .= "</p>\n";
 135+ $text = ' <form action="" method="post">' . "\n";
 136+ // set 'title' field, in case there's no URL niceness
 137+ $mw_namespace_labels = $wgContLang->getNamespaces();
 138+ $special_namespace = $mw_namespace_labels[NS_SPECIAL];
 139+ $text .= ' <input type="hidden" name="title" value="' . $special_namespace . ':CreateForm">' . "\n";
 140+ $text .= ' <p>' . wfMsg('sf_createform_nameinput') . ' <input size=25 name="form_name" value="' . $form_name . '">';
 141+ if (! empty($form_name_error_str))
 142+ $text .= ' <font color="red">' . $form_name_error_str . '</font>';
 143+ $text .= "</p>\n";
144144
145 - $text .= $form->creationHTML();
 145+ $text .= $form->creationHTML();
146146
147 - $text .= ' <p>' . wfMsg('sf_createform_addtemplate') . "\n";
148 - $text .= ' <select name="new_template">' . "\n";
 147+ $text .= ' <p>' . wfMsg('sf_createform_addtemplate') . "\n";
 148+ $text .= ' <select name="new_template">' . "\n";
149149
150 - foreach ($all_templates as $template) {
151 - $text .= " <option value=\"$template\">$template</option>\n";
152 - }
 150+ foreach ($all_templates as $template) {
 151+ $text .= " <option value=\"$template\">$template</option>\n";
 152+ }
153153
154 - $text .= " </select>\n";
155 - // if a template has already been added, show a dropdown letting the
156 - // user choose where in the list to add a new dropdown
157 - if (count($form_templates) > 0) {
158 - $before_template_msg = wfMsg('sf_createform_beforetemplate');
159 - $at_end_msg = wfMsg('sf_createform_atend');
160 - $text .=<<<END
 154+ $text .= " </select>\n";
 155+ // if a template has already been added, show a dropdown letting the
 156+ // user choose where in the list to add a new dropdown
 157+ if (count($form_templates) > 0) {
 158+ $before_template_msg = wfMsg('sf_createform_beforetemplate');
 159+ $at_end_msg = wfMsg('sf_createform_atend');
 160+ $text .=<<<END
161161 $before_template_msg
162162 <select name="before_template">
163163
164164 END;
165 - foreach ($form_templates as $i => $ft) {
166 - $text .= " <option value=\"$i\">{$ft->template_name}</option>\n";
167 - }
168 - $final_index = count($form_templates);
169 - $text .=<<<END
 165+ foreach ($form_templates as $i => $ft) {
 166+ $text .= " <option value=\"$i\">{$ft->template_name}</option>\n";
 167+ }
 168+ $final_index = count($form_templates);
 169+ $text .=<<<END
170170 <option value="$final_index" selected="selected">$at_end_msg</option>
171171 </select>
172172
173173 END;
174 - }
 174+ }
175175
176 - // disable 'save' and 'preview' buttons if user has not yet added any
177 - // templates
178 - $disabled_text = (count($form_templates) == 0) ? "disabled" : "";
179 - $save_button_text = wfMsg('savearticle');
180 - $preview_button_text = wfMsg('preview');
181 - $add_button_text = wfMsg('sf_createform_add');
182 - $sk = $wgUser->getSkin();
183 - $ct = SpecialPage::getPage('CreateTemplate');
184 - $create_template_link = $sk->makeKnownLinkObj($ct->getTitle(), $ct->getDescription());
185 - $text .=<<<END
 176+ // disable 'save' and 'preview' buttons if user has not yet added any
 177+ // templates
 178+ $disabled_text = (count($form_templates) == 0) ? "disabled" : "";
 179+ $save_button_text = wfMsg('savearticle');
 180+ $preview_button_text = wfMsg('preview');
 181+ $add_button_text = wfMsg('sf_createform_add');
 182+ $sk = $wgUser->getSkin();
 183+ $ct = SpecialPage::getPage('CreateTemplate');
 184+ $create_template_link = $sk->makeKnownLinkObj($ct->getTitle(), $ct->getDescription());
 185+ $text .=<<<END
186186 <input type="submit" name="add_field" value="$add_button_text"></p>
187187 <br />
188188 <div class="editButtons">
@@ -192,12 +192,12 @@
193193 </div>
194194
195195 END;
196 - // explanatory message if buttons are disabled because no templates
197 - // have been added
198 - if (count($form_templates) == 0) {
199 - $text .= " <p>(" . wfMsg('sf_createtemplate_addtemplatebeforesave') . ")</p>";
200 - }
201 - $text .=<<<END
 196+ // explanatory message if buttons are disabled because no templates
 197+ // have been added
 198+ if (count($form_templates) == 0) {
 199+ $text .= " <p>(" . wfMsg('sf_createtemplate_addtemplatebeforesave') . ")</p>";
 200+ }
 201+ $text .=<<<END
202202 </form>
203203 <hr /><br />
204204 <p>$create_template_link.</p>
@@ -205,11 +205,11 @@
206206 END;
207207
208208
209 - $wgOut->addLink( array(
210 - 'rel' => 'stylesheet',
211 - 'type' => 'text/css',
212 - 'media' => "screen, projection",
213 - 'href' => $sfgScriptPath . "/skins/SF_main.css"
214 - ));
215 - $wgOut->addHTML($text);
 209+ $wgOut->addLink( array(
 210+ 'rel' => 'stylesheet',
 211+ 'type' => 'text/css',
 212+ 'media' => "screen, projection",
 213+ 'href' => $sfgScriptPath . "/skins/SF_main.css"
 214+ ));
 215+ $wgOut->addHTML($text);
216216 }
Index: trunk/extensions/SemanticForms/specials/SF_Templates.php
@@ -58,7 +58,7 @@
5959 page_title as value
6060 FROM $page
6161 WHERE page_namespace = {$NStemp}";
62 - }
 62+ }
6363
6464 function sortDescending() {
6565 return false;
Index: trunk/extensions/SemanticForms/specials/SF_CreateTemplate.php
@@ -60,87 +60,87 @@
6161 }
6262
6363 function doSpecialCreateTemplate() {
64 - global $wgOut, $wgRequest, $wgUser, $sfgScriptPath, $wgContLang;
 64+ global $wgOut, $wgRequest, $wgUser, $sfgScriptPath, $wgContLang;
6565
66 - $all_properties = sffGetAllProperties();
 66+ $all_properties = sffGetAllProperties();
 67+
 68+ $template_name = $wgRequest->getVal('template_name');
 69+ $template_name_error_str = "";
 70+ $category = $wgRequest->getVal('category');
 71+ $cur_id = 1;
 72+ $fields = array();
 73+ # cycle through the query values, setting the appropriate local variables
 74+ foreach ($wgRequest->getValues() as $var => $val) {
 75+ $var_elements = explode("_", $var);
 76+ // we only care about query variables of the form "a_b"
 77+ if (count($var_elements) != 2)
 78+ continue;
 79+ list ($field_field, $old_id) = $var_elements;
 80+ if ($field_field == "name") {
 81+ if ($old_id != "new" || ($old_id == "new" && $val != "")) {
 82+ if ($wgRequest->getVal('del_' . $old_id) != '') {
 83+ # do nothing - this field won't get added to the new list
 84+ } else {
 85+ $field = SFTemplateField::newWithValues($val, $wgRequest->getVal('label_' . $old_id));
 86+ $field->semantic_field_call = $wgRequest->getVal('semantic_field_call_' . $old_id);
 87+ $field->is_list = $wgRequest->getCheck('is_list_' . $old_id);
 88+ $fields[] = $field;
 89+ }
 90+ }
 91+ }
 92+ }
 93+ $aggregating_property = $wgRequest->getVal('semantic_field_call_aggregation');
 94+ $aggregation_label = $wgRequest->getVal('aggregation_label');
 95+ $template_format = $wgRequest->getVal('template_format');
6796
68 - $template_name = $wgRequest->getVal('template_name');
69 - $template_name_error_str = "";
70 - $category = $wgRequest->getVal('category');
71 - $cur_id = 1;
72 - $fields = array();
73 - # cycle through the query values, setting the appropriate local variables
74 - foreach ($wgRequest->getValues() as $var => $val) {
75 - $var_elements = explode("_", $var);
76 - // we only care about query variables of the form "a_b"
77 - if (count($var_elements) != 2)
78 - continue;
79 - list ($field_field, $old_id) = $var_elements;
80 - if ($field_field == "name") {
81 - if ($old_id != "new" || ($old_id == "new" && $val != "")) {
82 - if ($wgRequest->getVal('del_' . $old_id) != '') {
83 - # do nothing - this field won't get added to the new list
84 - } else {
85 - $field = SFTemplateField::newWithValues($val, $wgRequest->getVal('label_' . $old_id));
86 - $field->semantic_field_call = $wgRequest->getVal('semantic_field_call_' . $old_id);
87 - $field->is_list = $wgRequest->getCheck('is_list_' . $old_id);
88 - $fields[] = $field;
89 - }
90 - }
91 - }
92 - }
93 - $aggregating_property = $wgRequest->getVal('semantic_field_call_aggregation');
94 - $aggregation_label = $wgRequest->getVal('aggregation_label');
95 - $template_format = $wgRequest->getVal('template_format');
 97+ $text = "";
 98+ $save_button_text = wfMsg('savearticle');
 99+ $preview_button_text = wfMsg('preview');
 100+ $save_page = $wgRequest->getCheck('wpSave');
 101+ $preview_page = $wgRequest->getCheck('wpPreview');
 102+ if ($save_page || $preview_page) {
 103+ # validate template name
 104+ if ($template_name == '') {
 105+ $template_name_error_str = wfMsg('sf_blank_error');
 106+ } else {
 107+ # redirect to wiki interface
 108+ $title = Title::newFromText($template_name, NS_TEMPLATE);
 109+ $full_text = createTemplateText($template_name, $fields, $category, $aggregating_property, $aggregation_label, $template_format);
 110+ // HTML-encode
 111+ $full_text = str_replace('"', '&quot;', $full_text);
 112+ $text .= sffPrintRedirectForm($title, $full_text, "", $save_page, $preview_page, false, false, false, null, null);
 113+ }
 114+ }
96115
97 - $text = "";
98 - $save_button_text = wfMsg('savearticle');
99 - $preview_button_text = wfMsg('preview');
100 - $save_page = $wgRequest->getCheck('wpSave');
101 - $preview_page = $wgRequest->getCheck('wpPreview');
102 - if ($save_page || $preview_page) {
103 - # validate template name
104 - if ($template_name == '') {
105 - $template_name_error_str = wfMsg('sf_blank_error');
106 - } else {
107 - # redirect to wiki interface
108 - $title = Title::newFromText($template_name, NS_TEMPLATE);
109 - $full_text = createTemplateText($template_name, $fields, $category, $aggregating_property, $aggregation_label, $template_format);
110 - // HTML-encode
111 - $full_text = str_replace('"', '&quot;', $full_text);
112 - $text .= sffPrintRedirectForm($title, $full_text, "", $save_page, $preview_page, false, false, false, null, null);
113 - }
114 - }
 116+ $text .= ' <form action="" method="post">' . "\n";
 117+ // set 'title' field, in case there's no URL niceness
 118+ $mw_namespace_labels = $wgContLang->getNamespaces();
 119+ $special_namespace = $mw_namespace_labels[NS_SPECIAL];
 120+ $text .= ' <input type="hidden" name="title" value="' . $special_namespace . ':CreateTemplate">' . "\n";
 121+ $text .= ' <p>' . wfMsg('sf_createtemplate_namelabel') . ' <input size="25" name="template_name" value="' . $template_name . '"> <font color="red">' . $template_name_error_str . '</font></p>' . "\n";
 122+ $text .= ' <p>' . wfMsg('sf_createtemplate_categorylabel') . ' <input size="25" name="category" value="' . $category . '"></p>' . "\n";
 123+ $text .= " <fieldset>\n";
 124+ $text .= ' <legend>' . wfMsg('sf_createtemplate_templatefields') . "</legend>\n";
 125+ $text .= ' <p>' . wfMsg('sf_createtemplate_fieldsdesc') . "</p>\n";
115126
116 - $text .= ' <form action="" method="post">' . "\n";
117 - // set 'title' field, in case there's no URL niceness
118 - $mw_namespace_labels = $wgContLang->getNamespaces();
119 - $special_namespace = $mw_namespace_labels[NS_SPECIAL];
120 - $text .= ' <input type="hidden" name="title" value="' . $special_namespace . ':CreateTemplate">' . "\n";
121 - $text .= ' <p>' . wfMsg('sf_createtemplate_namelabel') . ' <input size="25" name="template_name" value="' . $template_name . '"> <font color="red">' . $template_name_error_str . '</font></p>' . "\n";
122 - $text .= ' <p>' . wfMsg('sf_createtemplate_categorylabel') . ' <input size="25" name="category" value="' . $category . '"></p>' . "\n";
123 - $text .= " <fieldset>\n";
124 - $text .= ' <legend>' . wfMsg('sf_createtemplate_templatefields') . "</legend>\n";
125 - $text .= ' <p>' . wfMsg('sf_createtemplate_fieldsdesc') . "</p>\n";
 127+ foreach ($fields as $i => $field) {
 128+ $text .= printFieldEntryBox($i + 1, $field, $all_properties);
 129+ }
 130+ $new_field = new SFTemplateField();
 131+ $text .= printFieldEntryBox("new", $new_field, $all_properties);
126132
127 - foreach ($fields as $i => $field) {
128 - $text .= printFieldEntryBox($i + 1, $field, $all_properties);
129 - }
130 - $new_field = new SFTemplateField();
131 - $text .= printFieldEntryBox("new", $new_field, $all_properties);
132 -
133 - $text .= ' <p><input type="submit" value="' . wfMsg('sf_createtemplate_addfield') . '"></p>' . "\n";
134 - $text .= " </fieldset>\n";
135 - $text .= " <fieldset>\n";
136 - $text .= ' <legend>' . wfMsg('sf_createtemplate_aggregation') . "</legend>\n";
137 - $text .= ' <p>' . wfMsg('sf_createtemplate_aggregationdesc') . "</p>\n";
138 - $text .= ' <p>' . wfMsg('sf_createtemplate_semanticproperty') . " " . printPropertiesDropdown($all_properties, "aggregation", $aggregating_property). "</p>\n";
139 - $text .= ' <p>' . wfMsg('sf_createtemplate_aggregationlabel') . ' <input size="25" name="aggregation_label" value="' . $aggregation_label . '"></p>' . "\n";
140 - $text .= " </fieldset>\n";
141 - $text .= ' <p>' . wfMsg('sf_createtemplate_outputformat') . "\n";
142 - $text .= ' <input type="radio" name="template_format" checked value="standard">' . wfMsg('sf_createtemplate_standardformat') . "\n";
143 - $text .= ' <input type="radio" name="template_format" value="infobox">' . wfMsg('sf_createtemplate_infoboxformat') . "</p>\n";
144 - $text .=<<<END
 133+ $text .= ' <p><input type="submit" value="' . wfMsg('sf_createtemplate_addfield') . '"></p>' . "\n";
 134+ $text .= " </fieldset>\n";
 135+ $text .= " <fieldset>\n";
 136+ $text .= ' <legend>' . wfMsg('sf_createtemplate_aggregation') . "</legend>\n";
 137+ $text .= ' <p>' . wfMsg('sf_createtemplate_aggregationdesc') . "</p>\n";
 138+ $text .= ' <p>' . wfMsg('sf_createtemplate_semanticproperty') . " " . printPropertiesDropdown($all_properties, "aggregation", $aggregating_property). "</p>\n";
 139+ $text .= ' <p>' . wfMsg('sf_createtemplate_aggregationlabel') . ' <input size="25" name="aggregation_label" value="' . $aggregation_label . '"></p>' . "\n";
 140+ $text .= " </fieldset>\n";
 141+ $text .= ' <p>' . wfMsg('sf_createtemplate_outputformat') . "\n";
 142+ $text .= ' <input type="radio" name="template_format" checked value="standard">' . wfMsg('sf_createtemplate_standardformat') . "\n";
 143+ $text .= ' <input type="radio" name="template_format" value="infobox">' . wfMsg('sf_createtemplate_infoboxformat') . "</p>\n";
 144+ $text .=<<<END
145145 <div class="editButtons">
146146 <input type="submit" id="wpSave" name="wpSave" value="$save_button_text">
147147 <input type="submit" id="wpPreview" name="wpPreview" value="$preview_button_text">
@@ -148,17 +148,17 @@
149149 </form>
150150
151151 END;
152 - $sk = $wgUser->getSkin();
153 - $cp = SpecialPage::getPage('CreateProperty');
154 - $create_property_link = $sk->makeKnownLinkObj($cp->getTitle(), $cp->getDescription());
155 - $text .= " <br /><hr /><br />\n";
156 - $text .= " <p>$create_property_link.</p>\n";
 152+ $sk = $wgUser->getSkin();
 153+ $cp = SpecialPage::getPage('CreateProperty');
 154+ $create_property_link = $sk->makeKnownLinkObj($cp->getTitle(), $cp->getDescription());
 155+ $text .= " <br /><hr /><br />\n";
 156+ $text .= " <p>$create_property_link.</p>\n";
157157
158 - $wgOut->addLink( array(
159 - 'rel' => 'stylesheet',
160 - 'type' => 'text/css',
161 - 'media' => "screen, projection",
162 - 'href' => $sfgScriptPath . "/skins/SF_main.css"
163 - ));
164 - $wgOut->addHTML($text);
 158+ $wgOut->addLink( array(
 159+ 'rel' => 'stylesheet',
 160+ 'type' => 'text/css',
 161+ 'media' => "screen, projection",
 162+ 'href' => $sfgScriptPath . "/skins/SF_main.css"
 163+ ));
 164+ $wgOut->addHTML($text);
165165 }
Index: trunk/extensions/SemanticForms/includes/SF_TemplateField.inc
@@ -59,97 +59,95 @@
6060 }
6161
6262 function createTemplateText($template_name, $template_fields, $category, $aggregating_property, $aggregating_label, $template_format) {
63 - $text = "<noinclude>\n";
64 - $text .= wfMsgForContent('sf_template_docu', $template_name) . "\n";
65 - $text .= "<pre>\n";
66 - $text .= "{{" . $template_name . "\n";
67 - foreach ($template_fields as $field) {
68 - $text .= "|" . $field->field_name . "=\n";
69 - }
70 - $text .= "}}\n";
71 - $text .= "</pre>\n";
72 - $text .= wfMsgForContent('sf_template_docufooter') . "\n";
73 - $text .=<<<END
 63+ $text = "<noinclude>\n";
 64+ $text .= wfMsgForContent('sf_template_docu', $template_name) . "\n";
 65+ $text .= "<pre>\n";
 66+ $text .= "{{" . $template_name . "\n";
 67+ foreach ($template_fields as $field) {
 68+ $text .= "|" . $field->field_name . "=\n";
 69+ }
 70+ $text .= "}}\n";
 71+ $text .= "</pre>\n";
 72+ $text .= wfMsgForContent('sf_template_docufooter') . "\n";
 73+ $text .=<<<END
7474 </noinclude><includeonly>
7575
7676 END;
77 - // topmost part depends on format
78 - if ($template_format == 'infobox') {
79 - // CSS style can't be used, unfortunately, since most MediaWiki setups
80 - // don't have an 'infobox' or comparable CSS class
81 - $text .=<<<END
 77+ // topmost part depends on format
 78+ if ($template_format == 'infobox') {
 79+ // CSS style can't be used, unfortunately, since most MediaWiki setups
 80+ // don't have an 'infobox' or comparable CSS class
 81+ $text .=<<<END
8282 {| style="width: 30em; font-size: 90%; border: 1px solid #aaaaaa; background-color: #f9f9f9; color: black; margin-bottom: 0.5em; margin-left: 1em; padding: 0.2em; float: right; clear: right; text-align:left;"
8383 ! style="text-align: center; background-color:#ccccff;" colspan="2" |<big>{{PAGENAME}}</big>
8484 |-
8585
8686 END;
87 - } else {
88 - $text .= '{| class="wikitable"' . "\n";
89 - }
 87+ } else {
 88+ $text .= '{| class="wikitable"' . "\n";
 89+ }
9090
91 - foreach ($template_fields as $i => $field) {
92 - if ($i > 0) {
93 - $text .= "|-\n";
94 - }
95 - $text .= "! " . $field->label . "\n";
96 - if ($field->semantic_field_call == null || $field->semantic_field_call == '') {
97 - $text .= "| {{{" . $field->field_name . "|}}}\n";
98 - // if this field is meant to contain a list, add on an 'arraymap' function,
99 - // that will call this semantic markup tag on every element in the list
100 - } elseif ($field->is_list) {
101 - // find a string that's not in the semantic field call, to be used as
102 - // the variable
103 - $var = "x"; // default - use this even if all the attempts fail
104 - if (strstr($field->semantic_field_call, $var)) {
105 - $var_options = array('y', 'z', 'xx', 'yy', 'zz', 'aa', 'bb', 'cc');
106 - foreach ($var_options as $option) {
107 - if (! strstr($field->semantic_field_call, $option)) {
108 - $var = $option;
109 - break;
110 - }
111 - }
112 - }
113 - $text .= "| {{#arraymap:{{{" . $field->field_name . "|}}}|,|$var|[[" . $field->semantic_field_call . "$var]]}}\n";
114 - } else {
115 - $text .= "| [[" . $field->semantic_field_call . "{{{" . $field->field_name . "|}}}]]\n";
116 - }
117 - }
 91+ foreach ($template_fields as $i => $field) {
 92+ if ($i > 0) {
 93+ $text .= "|-\n";
 94+ }
 95+ $text .= "! " . $field->label . "\n";
 96+ if ($field->semantic_field_call == null || $field->semantic_field_call == '') {
 97+ $text .= "| {{{" . $field->field_name . "|}}}\n";
 98+ // if this field is meant to contain a list, add on an 'arraymap' function,
 99+ // that will call this semantic markup tag on every element in the list
 100+ } elseif ($field->is_list) {
 101+ // find a string that's not in the semantic field call, to be used as
 102+ // the variable
 103+ $var = "x"; // default - use this even if all the attempts fail
 104+ if (strstr($field->semantic_field_call, $var)) {
 105+ $var_options = array('y', 'z', 'xx', 'yy', 'zz', 'aa', 'bb', 'cc');
 106+ foreach ($var_options as $option) {
 107+ if (! strstr($field->semantic_field_call, $option)) {
 108+ $var = $option;
 109+ break;
 110+ }
 111+ }
 112+ }
 113+ $text .= "| {{#arraymap:{{{" . $field->field_name . "|}}}|,|$var|[[" . $field->semantic_field_call . "$var]]}}\n";
 114+ } else {
 115+ $text .= "| [[" . $field->semantic_field_call . "{{{" . $field->field_name . "|}}}]]\n";
 116+ }
 117+ }
118118
119 - // add a row with an inline query to this table, for aggregation, if
120 - // a property was specified
121 - if ($aggregating_property != '') {
122 - if (count($template_fields) > 0) {
123 - $text .= "|-\n";
124 - }
125 - $text .=<<<END
 119+ // add a row with an inline query to this table, for aggregation, if
 120+ // a property was specified
 121+ if ($aggregating_property != '') {
 122+ if (count($template_fields) > 0) {
 123+ $text .= "|-\n";
 124+ }
 125+ $text .=<<<END
126126 ! $aggregating_label
127127 |
128128 END;
129 - // make the actual inline query an #ask function, if that's supported
130 - // by this version of SMW; otherwise use the old <ask> tag
131 - // HACK - to find this out, create a new parser and call SMW's 'register'
132 - // function on it
133 - $parser = new Parser();
134 - $dummy_text = "";
135 - $dummy_state = null;
136 - smwfRegisterInlineQueries($parser, $dummy_text, $dummy_state);
137 - if (in_array("ask", $parser->getFunctionHooks())) {
138 - $text .= "{{#ask:format=\"list\"|[[$aggregating_property{{SUBJECTPAGENAME}}]]}}\n";
139 - } else {
140 - $text .= "<ask format=\"list\">[[$aggregating_property{{SUBJECTPAGENAME}}]]</ask>\n";
141 - }
142 - }
143 - $text .= "|}\n";
144 - if ($category != '') {
145 - global $wgContLang;
146 - $namespace_labels = $wgContLang->getNamespaces();
147 - $category_namespace = $namespace_labels[NS_CATEGORY];
148 - $text .= "\n[[$category_namespace:$category]]\n";
 129+ // make the actual inline query an #ask function, if that's supported
 130+ // by this version of SMW; otherwise use the old <ask> tag
 131+ // HACK - to find this out, create a new parser and call SMW's 'register'
 132+ // function on it
 133+ $parser = new Parser();
 134+ $dummy_text = "";
 135+ $dummy_state = null;
 136+ smwfRegisterInlineQueries($parser, $dummy_text, $dummy_state);
 137+ if (in_array("ask", $parser->getFunctionHooks())) {
 138+ $text .= "{{#ask:format=\"list\"|[[$aggregating_property{{SUBJECTPAGENAME}}]]}}\n";
 139+ } else {
 140+ $text .= "<ask format=\"list\">[[$aggregating_property{{SUBJECTPAGENAME}}]]</ask>\n";
 141+ }
 142+ }
 143+ $text .= "|}\n";
 144+ if ($category != '') {
 145+ global $wgContLang;
 146+ $namespace_labels = $wgContLang->getNamespaces();
 147+ $category_namespace = $namespace_labels[NS_CATEGORY];
 148+ $text .= "\n[[$category_namespace:$category]]\n";
149149
150 - }
151 - $text .= "</includeonly>\n";
 150+ }
 151+ $text .= "</includeonly>\n";
152152
153 - return $text;
 153+ return $text;
154154 }
155 -
156 -?>
Index: trunk/extensions/SemanticForms/includes/SF_FormClasses.inc
@@ -8,31 +8,31 @@
99 */
1010
1111 class SFForm {
12 - var $form_name;
13 - var $templates;
 12+ var $form_name;
 13+ var $templates;
1414
15 - function create($form_name, $templates) {
16 - $form = new SFForm();
17 - $form->form_name = ucfirst(str_replace('_', ' ', $form_name));
18 - $form->templates = $templates;
19 - return $form;
20 - }
 15+ function create($form_name, $templates) {
 16+ $form = new SFForm();
 17+ $form->form_name = ucfirst(str_replace('_', ' ', $form_name));
 18+ $form->templates = $templates;
 19+ return $form;
 20+ }
2121
22 - function creationHTML() {
23 - $text = "";
24 - foreach ($this->templates as $i => $ft) {
25 - $text .= $ft->creationHTML($i);
26 - }
27 - return $text;
28 - }
 22+ function creationHTML() {
 23+ $text = "";
 24+ foreach ($this->templates as $i => $ft) {
 25+ $text .= $ft->creationHTML($i);
 26+ }
 27+ return $text;
 28+ }
2929
30 - function createMarkup() {
31 - $title = Title::makeTitle( SF_NS_FORM, $this->form_name );
32 - $ad = SpecialPage::getPage('AddPage');
33 - $add_data_url = sffTitleURLString($ad->getTitle()) . "/" . $title->getPartialURL();
34 - $form_description = wfMsgForContent('sf_form_docu', $this->form_name, $add_data_url);
35 - $form_input = "{{#forminput:" . $this->form_name . "}}\n";
36 - $text =<<<END
 30+ function createMarkup() {
 31+ $title = Title::makeTitle( SF_NS_FORM, $this->form_name );
 32+ $ad = SpecialPage::getPage('AddPage');
 33+ $add_data_url = sffTitleURLString($ad->getTitle()) . "/" . $title->getPartialURL();
 34+ $form_description = wfMsgForContent('sf_form_docu', $this->form_name, $add_data_url);
 35+ $form_input = "{{#forminput:" . $this->form_name . "}}\n";
 36+ $text =<<<END
3737 <noinclude>
3838 $form_description
3939
@@ -40,11 +40,11 @@
4141 </noinclude><includeonly>
4242
4343 END;
44 - foreach ($this->templates as $template) {
45 - $text .= $template->createMarkup() . "\n";
46 - }
47 - $free_text_label = wfMsgForContent('sf_form_freetextlabel');
48 - $text .=<<<END
 44+ foreach ($this->templates as $template) {
 45+ $text .= $template->createMarkup() . "\n";
 46+ }
 47+ $free_text_label = wfMsgForContent('sf_form_freetextlabel');
 48+ $text .=<<<END
4949 '''$free_text_label:'''
5050
5151 {{{field|free text}}}
@@ -59,116 +59,116 @@
6060
6161 END;
6262
63 - return $text;
64 - }
 63+ return $text;
 64+ }
6565
6666 }
6767
6868 class SFTemplateInForm {
69 - var $template_name;
70 - var $label;
71 - var $allow_multiple;
72 - var $max_allowed;
73 - var $fields;
 69+ var $template_name;
 70+ var $label;
 71+ var $allow_multiple;
 72+ var $max_allowed;
 73+ var $fields;
7474
75 - function getAllFields() {
76 - $template_fields = array();
77 - $field_names_array = array();
 75+ function getAllFields() {
 76+ $template_fields = array();
 77+ $field_names_array = array();
7878
79 - // Get the fields of the template, both semantic and otherwise, by parsing
80 - // the text of the template.
81 - // The way this works is that fields are found and then stored in an
82 - // array based on their location in the template text, so that they
83 - // can be returned in the order in which they appear in the template, even
84 - // though they were found in a different order.
85 - // Some fields can be found more than once (especially if they're part
86 - // of an "#if" statement, so they're only recorded the first time they're
87 - // found. Also, every field gets replaced with a string of x's after
88 - // being found, so it doesn't interfere with future parsing.
89 - $template_title = Title::newFromText($this->template_name, NS_TEMPLATE);
90 - $template_article = new Article($template_title);
91 - $template_text = $template_article->getContent();
92 - // ignore 'noinclude' sections and 'includeonly' tags
93 - $template_text = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $template_text);
94 - $template_text = strtr($template_text, array('<includeonly>' => '', '</includeonly>' => ''));
 79+ // Get the fields of the template, both semantic and otherwise, by parsing
 80+ // the text of the template.
 81+ // The way this works is that fields are found and then stored in an
 82+ // array based on their location in the template text, so that they
 83+ // can be returned in the order in which they appear in the template, even
 84+ // though they were found in a different order.
 85+ // Some fields can be found more than once (especially if they're part
 86+ // of an "#if" statement, so they're only recorded the first time they're
 87+ // found. Also, every field gets replaced with a string of x's after
 88+ // being found, so it doesn't interfere with future parsing.
 89+ $template_title = Title::newFromText($this->template_name, NS_TEMPLATE);
 90+ $template_article = new Article($template_title);
 91+ $template_text = $template_article->getContent();
 92+ // ignore 'noinclude' sections and 'includeonly' tags
 93+ $template_text = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $template_text);
 94+ $template_text = strtr($template_text, array('<includeonly>' => '', '</includeonly>' => ''));
9595
96 - // first, look for "arraymap" parser function calls that map a
97 - // relation or attribute onto a list
98 - if (preg_match_all('/{{#arraymap:{{{([^|}]*:?[^|}]*)[^\[]*\[\[([^:=]*:?[^:=]*)(:[:=])/mis', $template_text, $matches)) {
99 - // this is a two-dimensional array; we need the last three of the four
100 - // sub-arrays; we also have to remove redundant values
101 - foreach ($matches[1] as $i => $field_name) {
102 - $is_relation = false;
103 - $semantic_field_name = $matches[2][$i];
104 - $full_field_text = $matches[0][$i];
105 - if (! in_array($field_name, $field_names_array)) {
106 - $template_field = SFTemplateField::newWithValues($field_name, ucfirst($field_name));
107 - $template_field->setSemanticData($semantic_field_name, $is_relation, true);
108 - $cur_pos = stripos($template_text, $full_field_text);
109 - $template_fields[$cur_pos] = $template_field;
110 - $field_names_array[] = $field_name;
111 - $replacement = str_repeat("x", strlen($full_field_text));
112 - $template_text = str_replace($full_field_text, $replacement, $template_text);
113 - }
114 - }
115 - }
 96+ // first, look for "arraymap" parser function calls that map a
 97+ // relation or attribute onto a list
 98+ if (preg_match_all('/{{#arraymap:{{{([^|}]*:?[^|}]*)[^\[]*\[\[([^:=]*:?[^:=]*)(:[:=])/mis', $template_text, $matches)) {
 99+ // this is a two-dimensional array; we need the last three of the four
 100+ // sub-arrays; we also have to remove redundant values
 101+ foreach ($matches[1] as $i => $field_name) {
 102+ $is_relation = false;
 103+ $semantic_field_name = $matches[2][$i];
 104+ $full_field_text = $matches[0][$i];
 105+ if (! in_array($field_name, $field_names_array)) {
 106+ $template_field = SFTemplateField::newWithValues($field_name, ucfirst($field_name));
 107+ $template_field->setSemanticData($semantic_field_name, $is_relation, true);
 108+ $cur_pos = stripos($template_text, $full_field_text);
 109+ $template_fields[$cur_pos] = $template_field;
 110+ $field_names_array[] = $field_name;
 111+ $replacement = str_repeat("x", strlen($full_field_text));
 112+ $template_text = str_replace($full_field_text, $replacement, $template_text);
 113+ }
 114+ }
 115+ }
116116
117 - // second, look for normal relation/attribute calls
118 - if (preg_match_all('/\[\[([^:=]*:*?[^:=]*)(:[:=]){{{([^\]\|}]*).*?\]\]/mis', $template_text, $matches)) {
119 - // this is a two-dimensional array; we need the last three of the four
120 - // sub-arrays; we also have to remove redundant values
121 - foreach ($matches[1] as $i => $semantic_field_name) {
122 - $is_relation = false;
123 - $field_name = $matches[3][$i];
124 - $full_field_text = $matches[0][$i];
125 - if (! in_array($field_name, $field_names_array)) {
126 - $template_field = SFTemplateField::newWithValues($field_name, ucfirst($field_name));
127 - $template_field->setSemanticData($semantic_field_name, $is_relation, false);
128 - $cur_pos = stripos($template_text, $full_field_text);
129 - $template_fields[$cur_pos] = $template_field;
130 - $field_names_array[] = $field_name;
131 - $replacement = str_repeat("x", strlen($full_field_text));
132 - $template_text = str_replace($full_field_text, $replacement, $template_text);
133 - }
134 - }
135 - }
 117+ // second, look for normal relation/attribute calls
 118+ if (preg_match_all('/\[\[([^:=]*:*?[^:=]*)(:[:=]){{{([^\]\|}]*).*?\]\]/mis', $template_text, $matches)) {
 119+ // this is a two-dimensional array; we need the last three of the four
 120+ // sub-arrays; we also have to remove redundant values
 121+ foreach ($matches[1] as $i => $semantic_field_name) {
 122+ $is_relation = false;
 123+ $field_name = $matches[3][$i];
 124+ $full_field_text = $matches[0][$i];
 125+ if (! in_array($field_name, $field_names_array)) {
 126+ $template_field = SFTemplateField::newWithValues($field_name, ucfirst($field_name));
 127+ $template_field->setSemanticData($semantic_field_name, $is_relation, false);
 128+ $cur_pos = stripos($template_text, $full_field_text);
 129+ $template_fields[$cur_pos] = $template_field;
 130+ $field_names_array[] = $field_name;
 131+ $replacement = str_repeat("x", strlen($full_field_text));
 132+ $template_text = str_replace($full_field_text, $replacement, $template_text);
 133+ }
 134+ }
 135+ }
136136
137 - // finally, get any non-semantic fields defined
138 - if (preg_match_all('/{{{([^|}]*)/mis', $template_text, $matches)) {
139 - foreach ($matches[1] as $i => $field_name) {
140 - $full_field_text = $matches[0][$i];
141 - if (($full_field_text != '') && (! in_array($field_name, $field_names_array))) {
142 - $cur_pos = stripos($template_text, $full_field_text);
143 - $template_fields[$cur_pos] = SFTemplateField::newWithValues($field_name, ucfirst($field_name));
144 - $field_names_array[] = $field_name;
145 - }
146 - }
147 - }
148 - ksort($template_fields);
149 - return $template_fields;
150 - }
 137+ // finally, get any non-semantic fields defined
 138+ if (preg_match_all('/{{{([^|}]*)/mis', $template_text, $matches)) {
 139+ foreach ($matches[1] as $i => $field_name) {
 140+ $full_field_text = $matches[0][$i];
 141+ if (($full_field_text != '') && (! in_array($field_name, $field_names_array))) {
 142+ $cur_pos = stripos($template_text, $full_field_text);
 143+ $template_fields[$cur_pos] = SFTemplateField::newWithValues($field_name, ucfirst($field_name));
 144+ $field_names_array[] = $field_name;
 145+ }
 146+ }
 147+ }
 148+ ksort($template_fields);
 149+ return $template_fields;
 150+ }
151151
152 - function create($name, $label, $allow_multiple, $max_allowed = null) {
153 - $tif = new SFTemplateInForm();
154 - $tif->template_name = str_replace('_', ' ', $name);
155 - $tif->fields = array();
156 - $fields = $tif->getAllFields();
157 - $field_num = 0;
158 - foreach ($fields as $field) {
159 - $tif->fields[] = SFFormTemplateField::create($field_num++, $field);
160 - }
161 - $tif->label = $label;
162 - $tif->allow_multiple = $allow_multiple;
163 - $tif->max_allowed = $max_allowed;
164 - return $tif;
165 - }
 152+ function create($name, $label, $allow_multiple, $max_allowed = null) {
 153+ $tif = new SFTemplateInForm();
 154+ $tif->template_name = str_replace('_', ' ', $name);
 155+ $tif->fields = array();
 156+ $fields = $tif->getAllFields();
 157+ $field_num = 0;
 158+ foreach ($fields as $field) {
 159+ $tif->fields[] = SFFormTemplateField::create($field_num++, $field);
 160+ }
 161+ $tif->label = $label;
 162+ $tif->allow_multiple = $allow_multiple;
 163+ $tif->max_allowed = $max_allowed;
 164+ return $tif;
 165+ }
166166
167 - function creationHTML($template_num) {
168 - $checked_str = ($this->allow_multiple) ? "checked" : "";
169 - $template_str = wfMsg('sf_createform_template');
170 - $template_label_input = wfMsg('sf_createform_templatelabelinput');
171 - $allow_multiple_text = wfMsg('sf_createform_allowmultiple');
172 - $text =<<<END
 167+ function creationHTML($template_num) {
 168+ $checked_str = ($this->allow_multiple) ? "checked" : "";
 169+ $template_str = wfMsg('sf_createform_template');
 170+ $template_label_input = wfMsg('sf_createform_templatelabelinput');
 171+ $allow_multiple_text = wfMsg('sf_createform_allowmultiple');
 172+ $text =<<<END
173173 <input type="hidden" name="template_$template_num" value="$this->template_name">
174174 <div class="templateForm">
175175 <h2>$template_str '$this->template_name'</h2>
@@ -177,34 +177,34 @@
178178 <hr>
179179
180180 END;
181 - foreach ($this->fields as $field) {
182 - $text .= $field->creationHTML($template_num);
183 - }
184 - $text .= ' <p><input type="submit" name="del_' . $template_num .
185 - '" value="' . wfMsg('sf_createform_removetemplate') . '"></p>' . "\n";
186 - $text .= " </div>\n";
187 - return $text;
188 - }
 181+ foreach ($this->fields as $field) {
 182+ $text .= $field->creationHTML($template_num);
 183+ }
 184+ $text .= ' <p><input type="submit" name="del_' . $template_num .
 185+ '" value="' . wfMsg('sf_createform_removetemplate') . '"></p>' . "\n";
 186+ $text .= " </div>\n";
 187+ return $text;
 188+ }
189189
190 - function createMarkup() {
191 - $text = "";
192 - $text .= "{{{for template|" . $this->template_name;
193 - if ($this->allow_multiple)
194 - $text .= "|multiple";
195 - if ($this->label != '')
196 - $text .= "|label=" . $this->label;
197 - $text .= "}}}\n";
198 - // for now, HTML for templates differs for multiple-instance templates;
199 - // this may change if handling of form definitions gets more sophisticated
200 - if (! $this->allow_multiple) { $text .= "{| class=\"formtable\"\n"; }
201 - foreach ($this->fields as $i => $field) {
202 - $is_last_field = ($i == count($this->fields) - 1);
203 - $text .= $field->createMarkup($this->allow_multiple, $is_last_field);
204 - }
205 - if (! $this->allow_multiple) { $text .= "|}\n"; }
206 - $text .= "{{{end template}}}\n";
207 - return $text;
208 - }
 190+ function createMarkup() {
 191+ $text = "";
 192+ $text .= "{{{for template|" . $this->template_name;
 193+ if ($this->allow_multiple)
 194+ $text .= "|multiple";
 195+ if ($this->label != '')
 196+ $text .= "|label=" . $this->label;
 197+ $text .= "}}}\n";
 198+ // for now, HTML for templates differs for multiple-instance templates;
 199+ // this may change if handling of form definitions gets more sophisticated
 200+ if (! $this->allow_multiple) { $text .= "{| class=\"formtable\"\n"; }
 201+ foreach ($this->fields as $i => $field) {
 202+ $is_last_field = ($i == count($this->fields) - 1);
 203+ $text .= $field->createMarkup($this->allow_multiple, $is_last_field);
 204+ }
 205+ if (! $this->allow_multiple) { $text .= "|}\n"; }
 206+ $text .= "{{{end template}}}\n";
 207+ return $text;
 208+ }
209209 }
210210
211211 /*
@@ -214,184 +214,182 @@
215215 * for that field that are set within the form
216216 */
217217 class SFFormTemplateField {
218 - var $num;
219 - var $template_field;
220 - var $input_type;
221 - var $is_mandatory;
222 - var $is_hidden;
223 - var $is_restricted;
224 - var $possible_values;
225 - // the following fields are not set by the form-creation page
226 - // (though they could be)
227 - var $is_uploadable;
228 - var $field_args;
229 - var $autocomplete_category;
230 - var $no_autocomplete;
231 - var $part_of_multiple;
232 - // somewhat of a hack - these two fields are for a field in a specific
233 - // representation of a form, not the form definition; ideally these
234 - // should be contained in a third 'field' class, called something like
235 - // SFFormInstanceField, that holds these fields plus an instance of
236 - // SFFormTemplateField. Too much work?
237 - var $input_name;
238 - var $is_disabled;
 218+ var $num;
 219+ var $template_field;
 220+ var $input_type;
 221+ var $is_mandatory;
 222+ var $is_hidden;
 223+ var $is_restricted;
 224+ var $possible_values;
 225+ // the following fields are not set by the form-creation page
 226+ // (though they could be)
 227+ var $is_uploadable;
 228+ var $field_args;
 229+ var $autocomplete_category;
 230+ var $no_autocomplete;
 231+ var $part_of_multiple;
 232+ // somewhat of a hack - these two fields are for a field in a specific
 233+ // representation of a form, not the form definition; ideally these
 234+ // should be contained in a third 'field' class, called something like
 235+ // SFFormInstanceField, that holds these fields plus an instance of
 236+ // SFFormTemplateField. Too much work?
 237+ var $input_name;
 238+ var $is_disabled;
239239
240 - function create($num, $template_field) {
241 - $f = new SFFormTemplateField();
242 - $f->num = $num;
243 - $f->template_field = $template_field;
244 - $f->input_type = "";
245 - $f->is_mandatory = false;
246 - $f->is_hidden = false;
247 - $f->is_restricted = false;
248 - $f->is_uploadable = false;
249 - $f->possible_values = null;
250 - return $f;
251 - }
 240+ function create($num, $template_field) {
 241+ $f = new SFFormTemplateField();
 242+ $f->num = $num;
 243+ $f->template_field = $template_field;
 244+ $f->input_type = "";
 245+ $f->is_mandatory = false;
 246+ $f->is_hidden = false;
 247+ $f->is_restricted = false;
 248+ $f->is_uploadable = false;
 249+ $f->possible_values = null;
 250+ return $f;
 251+ }
252252
253 - function createFromDefinition($field_name, $input_name, $is_mandatory, $is_hidden, $is_uploadable, $possible_values, $is_disabled, $is_list, $input_type, $field_args, $all_fields, $strict_parsing) {
254 - // see if this field matches one of the fields defined for this template -
255 - // if it is, use all available information about that field; if it's not,
256 - // either include it in the form or not, depending on whether the
257 - // template has a 'strict' setting in the form definition
258 - $the_field = null;
259 - foreach ($all_fields as $cur_field) {
260 - if ($field_name == $cur_field->field_name) {
261 - $the_field = $cur_field;
262 - break;
263 - }
264 - }
265 - if ($the_field == null) {
266 - if ($strict_parsing)
267 - return null;
268 - $the_field = new SFTemplateField();
269 - }
 253+ function createFromDefinition($field_name, $input_name, $is_mandatory, $is_hidden, $is_uploadable, $possible_values, $is_disabled, $is_list, $input_type, $field_args, $all_fields, $strict_parsing) {
 254+ // see if this field matches one of the fields defined for this template -
 255+ // if it is, use all available information about that field; if it's not,
 256+ // either include it in the form or not, depending on whether the
 257+ // template has a 'strict' setting in the form definition
 258+ $the_field = null;
 259+ foreach ($all_fields as $cur_field) {
 260+ if ($field_name == $cur_field->field_name) {
 261+ $the_field = $cur_field;
 262+ break;
 263+ }
 264+ }
 265+ if ($the_field == null) {
 266+ if ($strict_parsing)
 267+ return null;
 268+ $the_field = new SFTemplateField();
 269+ }
270270
271 - // create an SFFormTemplateField object, containing this field as well
272 - // as settings from the form definition file
273 - $f = new SFFormTemplateField();
274 - $f->template_field = $the_field;
275 - $f->is_mandatory = $is_mandatory;
276 - $f->is_hidden = $is_hidden;
277 - $f->is_uploadable = $is_uploadable;
278 - $f->possible_values = $possible_values;
279 - $f->input_type = $input_type;
280 - $f->field_args = $field_args;
281 - $f->input_name = $input_name;
282 - $f->is_disabled = $is_disabled;
283 - $f->is_list = $is_list;
284 - return $f;
285 - }
 271+ // create an SFFormTemplateField object, containing this field as well
 272+ // as settings from the form definition file
 273+ $f = new SFFormTemplateField();
 274+ $f->template_field = $the_field;
 275+ $f->is_mandatory = $is_mandatory;
 276+ $f->is_hidden = $is_hidden;
 277+ $f->is_uploadable = $is_uploadable;
 278+ $f->possible_values = $possible_values;
 279+ $f->input_type = $input_type;
 280+ $f->field_args = $field_args;
 281+ $f->input_name = $input_name;
 282+ $f->is_disabled = $is_disabled;
 283+ $f->is_list = $is_list;
 284+ return $f;
 285+ }
286286
287 - function possibleInputTypes($semantic_field_type, $is_list) {
288 - // first, get the list of field types, to determine which one this is
289 - global $smwgContLang;
290 - $datatypeLabels = $smwgContLang->getDatatypeLabels();
291 - $string_type = $datatypeLabels['_str'];
292 - $text_type = $datatypeLabels['_txt'];
293 - // type introduced in SMW 1.2
294 - if (array_key_exists('_cod', $datatypeLabels))
295 - $code_type = $datatypeLabels['_cod'];
296 - else
297 - $code_type = 'code';
298 - $url_type = $datatypeLabels['_uri'];
299 - $email_type = $datatypeLabels['_ema'];
300 - $float_type = $datatypeLabels['_num'];
301 - $int_type = $datatypeLabels['_num'];
302 - $bool_type = $datatypeLabels['_boo'];
303 - $date_type = $datatypeLabels['_dat'];
304 - $enum_type = 'enumeration'; // not a real type
305 - $page_type = $datatypeLabels['_wpg'];
 287+ function possibleInputTypes($semantic_field_type, $is_list) {
 288+ // first, get the list of field types, to determine which one this is
 289+ global $smwgContLang;
 290+ $datatypeLabels = $smwgContLang->getDatatypeLabels();
 291+ $string_type = $datatypeLabels['_str'];
 292+ $text_type = $datatypeLabels['_txt'];
 293+ // type introduced in SMW 1.2
 294+ $code_type = array_key_exists('_cod', $datatypeLabels) ? $datatypeLabels['_cod'] : 'code';
 295+ $url_type = $datatypeLabels['_uri'];
 296+ $email_type = $datatypeLabels['_ema'];
 297+ $float_type = $datatypeLabels['_num'];
 298+ $int_type = $datatypeLabels['_num'];
 299+ $bool_type = $datatypeLabels['_boo'];
 300+ $date_type = $datatypeLabels['_dat'];
 301+ $enum_type = 'enumeration'; // not a real type
 302+ $page_type = $datatypeLabels['_wpg'];
306303
307 - // then, return the array of possible input types, depending on the
308 - // field type and whether this field will contain multiple values
309 - if ($semantic_field_type == $string_type ||
310 - $semantic_field_type == $float_type ||
311 - $semantic_field_type == $int_type ||
312 - $semantic_field_type == $url_type ||
313 - $semantic_field_type == $email_type) {
314 - if ($is_list) {
315 - return array('text', 'textarea');
316 - } else {
317 - return array('text');
318 - }
319 - } elseif ($semantic_field_type == $text_type || $semantic_field_type == $code_type) {
320 - return array('textarea');
321 - } elseif ($semantic_field_type == $bool_type) {
322 - return array('checkbox');
323 - } elseif ($semantic_field_type == $date_type) {
324 - return array('date', 'datetime', 'datetime with timezone');
325 - } elseif ($semantic_field_type == $enum_type) {
326 - if ($is_list) {
327 - return array('checkboxes', 'listbox');
328 - } else {
329 - return array('dropdown', 'radiobutton');
330 - }
331 - } elseif ($semantic_field_type == $page_type) {
332 - if ($is_list) {
333 - return array('text', 'textarea');
334 - } else {
335 - return array('text');
336 - }
337 - } else { // blank or an unknown type
338 - return array('text', 'textarea', 'checkbox', 'date', 'datetime', 'datetime with timezone');
339 - }
340 - }
 304+ // then, return the array of possible input types, depending on the
 305+ // field type and whether this field will contain multiple values
 306+ if ($semantic_field_type == $string_type ||
 307+ $semantic_field_type == $float_type ||
 308+ $semantic_field_type == $int_type ||
 309+ $semantic_field_type == $url_type ||
 310+ $semantic_field_type == $email_type) {
 311+ if ($is_list) {
 312+ return array('text', 'textarea');
 313+ } else {
 314+ return array('text');
 315+ }
 316+ } elseif ($semantic_field_type == $text_type || $semantic_field_type == $code_type) {
 317+ return array('textarea');
 318+ } elseif ($semantic_field_type == $bool_type) {
 319+ return array('checkbox');
 320+ } elseif ($semantic_field_type == $date_type) {
 321+ return array('date', 'datetime', 'datetime with timezone');
 322+ } elseif ($semantic_field_type == $enum_type) {
 323+ if ($is_list) {
 324+ return array('checkboxes', 'listbox');
 325+ } else {
 326+ return array('dropdown', 'radiobutton');
 327+ }
 328+ } elseif ($semantic_field_type == $page_type) {
 329+ if ($is_list) {
 330+ return array('text', 'textarea');
 331+ } else {
 332+ return array('text');
 333+ }
 334+ } else { // blank or an unknown type
 335+ return array('text', 'textarea', 'checkbox', 'date', 'datetime', 'datetime with timezone');
 336+ }
 337+ }
341338
342 - function inputTypeDropdownHTML($dropdown_name, $possible_input_types, $cur_input_type) {
343 - // create the dropdown HTML for a list of possible input types
344 - $text = " <select name=\"$dropdown_name\">\n";
345 - foreach ($possible_input_types as $i => $input_type) {
346 - if ($i == 0) {
347 - $text .= " <option value=\"\">$input_type " .
348 - wfMsg('sf_createform_inputtypedefault') . "</option>\n";
349 - } else {
350 - $selected_str = ($cur_input_type == $input_type) ? "selected" : "";
351 - $text .= " <option value=\"$input_type\" $selected_str>$input_type</option>\n";
352 - }
353 - }
354 - $text .= " </select>\n";
355 - return $text;
356 - }
 339+ function inputTypeDropdownHTML($dropdown_name, $possible_input_types, $cur_input_type) {
 340+ // create the dropdown HTML for a list of possible input types
 341+ $text = " <select name=\"$dropdown_name\">\n";
 342+ foreach ($possible_input_types as $i => $input_type) {
 343+ if ($i == 0) {
 344+ $text .= " <option value=\"\">$input_type " .
 345+ wfMsg('sf_createform_inputtypedefault') . "</option>\n";
 346+ } else {
 347+ $selected_str = ($cur_input_type == $input_type) ? "selected" : "";
 348+ $text .= " <option value=\"$input_type\" $selected_str>$input_type</option>\n";
 349+ }
 350+ }
 351+ $text .= " </select>\n";
 352+ return $text;
 353+ }
357354
358 - function creationHTML($template_num) {
359 - $field_form_text = $template_num . "_" . $this->num;
360 - $template_field = $this->template_field;
361 - $text = '<h3>' . wfMsg('sf_createform_field') . " '" . $template_field->field_name . "'</h3>\n";
362 - $prop_link_text = sffLinkText(SMW_NS_PROPERTY, $template_field->semantic_field);
363 - // TODO - remove this probably-unnecessary check?
364 - if ($template_field->semantic_field == "") {
365 - // print nothing if there's no semantic field
366 - } elseif ($template_field->field_type == "")
367 - $text .= '<p>' . wfMsg('sf_createform_fieldpropunknowntype', $prop_link_text) . "</p>\n";
368 - elseif ($template_field->is_list)
369 - $text .= '<p>' . wfMsg('sf_createform_fieldproplist', $prop_link_text,
370 - sffLinkText(SMW_NS_TYPE, $template_field->field_type)) . "</p>\n";
371 - else
372 - $text .= '<p>' . wfMsg('sf_createform_fieldprop', $prop_link_text,
373 - sffLinkText(SMW_NS_TYPE, $template_field->field_type)) . "</p>\n";
374 - // if it's not a semantic field - don't add any text
375 - $form_label_text = wfMsg('sf_createform_formlabel');
376 - $field_label = $template_field->label;
377 - $input_type_text = wfMsg('sf_createform_inputtype');
378 - $text .=<<<END
 355+ function creationHTML($template_num) {
 356+ $field_form_text = $template_num . "_" . $this->num;
 357+ $template_field = $this->template_field;
 358+ $text = '<h3>' . wfMsg('sf_createform_field') . " '" . $template_field->field_name . "'</h3>\n";
 359+ $prop_link_text = sffLinkText(SMW_NS_PROPERTY, $template_field->semantic_field);
 360+ // TODO - remove this probably-unnecessary check?
 361+ if ($template_field->semantic_field == "") {
 362+ // print nothing if there's no semantic field
 363+ } elseif ($template_field->field_type == "") {
 364+ $text .= '<p>' . wfMsg('sf_createform_fieldpropunknowntype', $prop_link_text) . "</p>\n";
 365+ } elseif ($template_field->is_list) {
 366+ $text .= '<p>' . wfMsg('sf_createform_fieldproplist', $prop_link_text,
 367+ sffLinkText(SMW_NS_TYPE, $template_field->field_type)) . "</p>\n";
 368+ } else {
 369+ $text .= '<p>' . wfMsg('sf_createform_fieldprop', $prop_link_text,
 370+ sffLinkText(SMW_NS_TYPE, $template_field->field_type)) . "</p>\n";
 371+ }
 372+ // if it's not a semantic field - don't add any text
 373+ $form_label_text = wfMsg('sf_createform_formlabel');
 374+ $field_label = $template_field->label;
 375+ $input_type_text = wfMsg('sf_createform_inputtype');
 376+ $text .=<<<END
379377 <p>$form_label_text <input type="text" name="label_$field_form_text" size=20 value="$field_label" />
380378 &nbsp; $input_type_text
381379
382380 END;
383 - $possible_input_types = $this->possibleInputTypes($template_field->field_type, $template_field->is_list);
384 - if (count($possible_input_types) > 1) {
385 - $text .= $this->inputTypeDropdownHTML("input_type_$field_form_text", $possible_input_types, $template_field->input_type);
386 - } else {
387 - $text .= $possible_input_types[0];
388 - }
389 - $mandatory_checked_str = ($this->is_mandatory) ? "checked" : "";
390 - $mandatory_text = wfMsg('sf_createform_mandatory');
391 - $hidden_checked_str = ($this->is_hidden) ? "checked" : "";
392 - $hidden_text = wfMsg('sf_createform_hidden');
393 - $restricted_checked_str = ($this->is_restricted) ? "checked" : "";
394 - $restricted_text = wfMsg('sf_createform_restricted');
395 - $text .=<<<END
 381+ $possible_input_types = $this->possibleInputTypes($template_field->field_type, $template_field->is_list);
 382+ if (count($possible_input_types) > 1) {
 383+ $text .= $this->inputTypeDropdownHTML("input_type_$field_form_text", $possible_input_types, $template_field->input_type);
 384+ } else {
 385+ $text .= $possible_input_types[0];
 386+ }
 387+ $mandatory_checked_str = ($this->is_mandatory) ? "checked" : "";
 388+ $mandatory_text = wfMsg('sf_createform_mandatory');
 389+ $hidden_checked_str = ($this->is_hidden) ? "checked" : "";
 390+ $hidden_text = wfMsg('sf_createform_hidden');
 391+ $restricted_checked_str = ($this->is_restricted) ? "checked" : "";
 392+ $restricted_text = wfMsg('sf_createform_restricted');
 393+ $text .=<<<END
396394 </p>
397395 <p>
398396 <input type="checkbox" name="mandatory_$field_form_text" value="mandatory" $mandatory_checked_str /> $mandatory_text
@@ -400,41 +398,39 @@
401399 <hr>
402400
403401 END;
404 - return $text;
405 - }
 402+ return $text;
 403+ }
406404
407 - // for now, HTML of an individual field depends on whether or not it's
408 - // part of multiple-instance template; this may change if handling of
409 - // such templates in form definitions gets more sophisticated
410 - function createMarkup($part_of_multiple, $is_last_field_in_template) {
411 - $text = "";
412 - if ($this->template_field->label != "") {
413 - if ($part_of_multiple) {
414 - $text .= "'''" . $this->template_field->label . ":''' ";
415 - } else {
416 - $text .= "! " . $this->template_field->label . ":\n";
417 - }
418 - }
419 - if (! $part_of_multiple) { $text .= "| "; }
420 - $text .= "{{{field|" . $this->template_field->field_name;
421 - if ($this->template_field->input_type != '') {
422 - $text .= "|input type=" . $this->template_field->input_type;
423 - }
424 - if ($this->is_mandatory) {
425 - $text .= "|mandatory";
426 - } elseif ($this->is_hidden) {
427 - $text .= "|hidden";
428 - } elseif ($this->is_restricted) {
429 - $text .= "|restricted";
430 - }
431 - $text .= "}}}\n";
432 - if ($part_of_multiple) {
433 - $text .= "\n";
434 - } elseif (! $is_last_field_in_template) {
435 - $text .= "|-\n";
436 - }
437 - return $text;
438 - }
 405+ // for now, HTML of an individual field depends on whether or not it's
 406+ // part of multiple-instance template; this may change if handling of
 407+ // such templates in form definitions gets more sophisticated
 408+ function createMarkup($part_of_multiple, $is_last_field_in_template) {
 409+ $text = "";
 410+ if ($this->template_field->label != "") {
 411+ if ($part_of_multiple) {
 412+ $text .= "'''" . $this->template_field->label . ":''' ";
 413+ } else {
 414+ $text .= "! " . $this->template_field->label . ":\n";
 415+ }
 416+ }
 417+ if (! $part_of_multiple) { $text .= "| "; }
 418+ $text .= "{{{field|" . $this->template_field->field_name;
 419+ if ($this->template_field->input_type != '') {
 420+ $text .= "|input type=" . $this->template_field->input_type;
 421+ }
 422+ if ($this->is_mandatory) {
 423+ $text .= "|mandatory";
 424+ } elseif ($this->is_hidden) {
 425+ $text .= "|hidden";
 426+ } elseif ($this->is_restricted) {
 427+ $text .= "|restricted";
 428+ }
 429+ $text .= "}}}\n";
 430+ if ($part_of_multiple) {
 431+ $text .= "\n";
 432+ } elseif (! $is_last_field_in_template) {
 433+ $text .= "|-\n";
 434+ }
 435+ return $text;
 436+ }
439437 }
440 -
441 -?>
Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.inc
@@ -9,592 +9,591 @@
1010
1111 class SFFormInputs {
1212
13 - function createAutocompleteValuesArray($field_name, $autocomplete_field_type) {
14 - $names_array = array();
15 - // the query depends on whether this field is a relation (property of type
16 - // Page), attribute (property of any other type), category or namespace
17 - if ($autocomplete_field_type == 'relation' || $autocomplete_field_type == 'attribute' || $autocomplete_field_type == 'property') {
18 - $smw_version = SMW_VERSION;
19 - if (version_compare(SMW_VERSION, '1.2', '>=' ) ||
20 - substr($smw_version, 0, 3) == '1.2') { // temporary hack
21 - $names_array = sffGetAllPagesForProperty_1_2($field_name);
22 - } else {
23 - $is_relation = ($autocomplete_field_type == 'relation');
24 - $names_array = sffGetAllPagesForProperty_orig($is_relation, $field_name);
25 - }
26 - } elseif ($autocomplete_field_type == 'category') {
27 - $names_array = sffGetAllPagesForCategory($field_name, 10);
28 - } elseif ($autocomplete_field_type == 'concept') {
29 - $names_array = sffGetAllPagesForConcept($field_name);
30 - } else { // i.e., $autocomplete_field_type == 'namespace'
31 - // switch back to blank for main namespace
32 - if ($field_name == "main")
33 - $field_name = "";
34 - $names_array = sffGetAllPagesForNamespace($field_name);
35 - }
36 - return $names_array;
37 - }
 13+ function createAutocompleteValuesArray($field_name, $autocomplete_field_type) {
 14+ $names_array = array();
 15+ // the query depends on whether this field is a relation (property of type
 16+ // Page), attribute (property of any other type), category or namespace
 17+ if ($autocomplete_field_type == 'relation' || $autocomplete_field_type == 'attribute' || $autocomplete_field_type == 'property') {
 18+ $smw_version = SMW_VERSION;
 19+ if (version_compare(SMW_VERSION, '1.2', '>=' ) ||
 20+ substr($smw_version, 0, 3) == '1.2') { // temporary hack
 21+ $names_array = sffGetAllPagesForProperty_1_2($field_name);
 22+ } else {
 23+ $is_relation = ($autocomplete_field_type == 'relation');
 24+ $names_array = sffGetAllPagesForProperty_orig($is_relation, $field_name);
 25+ }
 26+ } elseif ($autocomplete_field_type == 'category') {
 27+ $names_array = sffGetAllPagesForCategory($field_name, 10);
 28+ } elseif ($autocomplete_field_type == 'concept') {
 29+ $names_array = sffGetAllPagesForConcept($field_name);
 30+ } else { // i.e., $autocomplete_field_type == 'namespace'
 31+ // switch back to blank for main namespace
 32+ if ($field_name == "main")
 33+ $field_name = "";
 34+ $names_array = sffGetAllPagesForNamespace($field_name);
 35+ }
 36+ return $names_array;
 37+ }
3838
39 - function uploadLinkHTML($input_id, $delimiter = null) {
40 - $upload_window_page = SpecialPage::getPage('UploadWindow');
41 - $query_string = "sfInputID=$input_id";
42 - if ($delimiter != null)
43 - $query_string .= "&sfDelimiter=$delimiter";
44 - $upload_window_url = $upload_window_page->getTitle()->getFullURL($query_string);
45 - $upload_label = wfMsg('upload');
46 - $text = " <a href=\"$upload_window_url\" title=\"$upload_label\" rel=\"iframe\" rev=\"width:550 height:380\">$upload_label</a>";
47 - return $text;
48 - }
 39+ function uploadLinkHTML($input_id, $delimiter = null) {
 40+ $upload_window_page = SpecialPage::getPage('UploadWindow');
 41+ $query_string = "sfInputID=$input_id";
 42+ if ($delimiter != null)
 43+ $query_string .= "&sfDelimiter=$delimiter";
 44+ $upload_window_url = $upload_window_page->getTitle()->getFullURL($query_string);
 45+ $upload_label = wfMsg('upload');
 46+ $text = " <a href=\"$upload_window_url\" title=\"$upload_label\" rel=\"iframe\" rev=\"width:550 height:380\">$upload_label</a>";
 47+ return $text;
 48+ }
4949
50 - function textEntryHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
51 - // if it's an autocomplete, call the with-autocomplete function instead
52 - // we test to make sure that autocompletion hasn't been disabled, and
53 - // that either the property is a relation (i.e. it's of type Page) or
54 - // autocompletion has been specified in the form
55 - $autocompletion_disabled = (array_key_exists('autocomplete on', $other_args) && $other_args['autocomplete on'] == "") ||
56 - (array_key_exists('no autocomplete', $other_args) && $other_args['no autocomplete'] == true);
57 - if (! $autocompletion_disabled) {
58 - if ((array_key_exists('is_relation', $other_args) && $other_args['is_relation'] == true) ||
59 - array_key_exists('autocomplete', $other_args) ||
60 - array_key_exists('autocomplete on property', $other_args) ||
61 - array_key_exists('autocomplete on category', $other_args) ||
62 - array_key_exists('autocomplete on concept', $other_args) ||
63 - array_key_exists('autocomplete on', $other_args) ||
64 - array_key_exists('autocomplete on namespace', $other_args) ||
65 - array_key_exists('remote autocompletion', $other_args)) {
66 - return SFFormInputs::textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
67 - }
68 - }
 50+ function textEntryHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
 51+ // if it's an autocomplete, call the with-autocomplete function instead
 52+ // we test to make sure that autocompletion hasn't been disabled, and
 53+ // that either the property is a relation (i.e. it's of type Page) or
 54+ // autocompletion has been specified in the form
 55+ $autocompletion_disabled = (array_key_exists('autocomplete on', $other_args) && $other_args['autocomplete on'] == "") ||
 56+ (array_key_exists('no autocomplete', $other_args) && $other_args['no autocomplete'] == true);
 57+ if (! $autocompletion_disabled) {
 58+ if ((array_key_exists('is_relation', $other_args) && $other_args['is_relation'] == true) ||
 59+ array_key_exists('autocomplete', $other_args) ||
 60+ array_key_exists('autocomplete on property', $other_args) ||
 61+ array_key_exists('autocomplete on category', $other_args) ||
 62+ array_key_exists('autocomplete on concept', $other_args) ||
 63+ array_key_exists('autocomplete on', $other_args) ||
 64+ array_key_exists('autocomplete on namespace', $other_args) ||
 65+ array_key_exists('remote autocompletion', $other_args)) {
 66+ return SFFormInputs::textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
 67+ }
 68+ }
6969
70 - // if there are possible values specified, call the dropdown function
71 - if (array_key_exists('possible_values', $other_args) && $other_args['possible_values'] != null)
72 - return SFFormInputs::dropdownHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
 70+ // if there are possible values specified, call the dropdown function
 71+ if (array_key_exists('possible_values', $other_args) && $other_args['possible_values'] != null)
 72+ return SFFormInputs::dropdownHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
7373
74 - global $sfgTabIndex, $sfgFieldNum, $sfgJSValidationCalls;
 74+ global $sfgTabIndex, $sfgFieldNum, $sfgJSValidationCalls;
7575
76 - $className = ($is_mandatory) ? "createboxInput mandatoryField" : "createboxInput";
77 - if (array_key_exists('class', $other_args))
78 - $className .= " " . $other_args['class'];
79 - $input_id = "input_$sfgFieldNum";
80 - $info_id = "info_$sfgFieldNum";
81 - // set size based on pre-set size, or field type - if field type is set,
82 - // possibly add validation too
83 - if (array_key_exists('size', $other_args)) {
84 - $size = $other_args['size'];
85 - } elseif (array_key_exists('field_type', $other_args)) {
86 - $validation_type_str = "";
87 - if ($other_args['field_type'] == 'integer') {
88 - $size = 10;
89 - $validation_type_str = 'integer';
90 - } elseif ($other_args['field_type'] == 'float') {
91 - $size = 10;
92 - $validation_type_str = 'float';
93 - } elseif ($other_args['field_type'] == 'URL') {
94 - $size = 100;
95 - $validation_type_str = 'URL';
96 - } elseif ($other_args['field_type'] == 'email') {
97 - $size = 45;
98 - $validation_type_str = 'email';
99 - } else {
100 - $size = 35;
101 - }
102 - if ($validation_type_str != '') {
103 - if ($other_args['part_of_multiple']) {
104 - $sfgJSValidationCalls[] = "validate_type_of_multiple_fields($sfgFieldNum, '$validation_type_str')";
105 - } else {
106 - $sfgJSValidationCalls[] = "validate_field_type('$input_id', '$validation_type_str', '$info_id')";
107 - }
108 - }
109 - } else {
110 - $size = 35;
111 - }
 76+ $className = ($is_mandatory) ? "createboxInput mandatoryField" : "createboxInput";
 77+ if (array_key_exists('class', $other_args))
 78+ $className .= " " . $other_args['class'];
 79+ $input_id = "input_$sfgFieldNum";
 80+ $info_id = "info_$sfgFieldNum";
 81+ // set size based on pre-set size, or field type - if field type is set,
 82+ // possibly add validation too
 83+ if (array_key_exists('size', $other_args)) {
 84+ $size = $other_args['size'];
 85+ } elseif (array_key_exists('field_type', $other_args)) {
 86+ $validation_type_str = "";
 87+ if ($other_args['field_type'] == 'integer') {
 88+ $size = 10;
 89+ $validation_type_str = 'integer';
 90+ } elseif ($other_args['field_type'] == 'float') {
 91+ $size = 10;
 92+ $validation_type_str = 'float';
 93+ } elseif ($other_args['field_type'] == 'URL') {
 94+ $size = 100;
 95+ $validation_type_str = 'URL';
 96+ } elseif ($other_args['field_type'] == 'email') {
 97+ $size = 45;
 98+ $validation_type_str = 'email';
 99+ } else {
 100+ $size = 35;
 101+ }
 102+ if ($validation_type_str != '') {
 103+ if ($other_args['part_of_multiple']) {
 104+ $sfgJSValidationCalls[] = "validate_type_of_multiple_fields($sfgFieldNum, '$validation_type_str')";
 105+ } else {
 106+ $sfgJSValidationCalls[] = "validate_field_type('$input_id', '$validation_type_str', '$info_id')";
 107+ }
 108+ }
 109+ } else {
 110+ $size = 35;
 111+ }
112112
113 - $text =<<<END
 113+ $text =<<<END
114114 <input id="$input_id" tabindex="$sfgTabIndex" class="$className" name="$input_name" type="text"
115 - value="$cur_value" size="$size"
 115+ value="$cur_value" size="$size"
116116 END;
117 - if ($is_disabled)
118 - $text .= " disabled";
119 - if (array_key_exists('maxlength', $other_args))
120 - $text .= ' maxlength="' . $other_args['maxlength'] . '"';
121 - $text .=<<<END
 117+ if ($is_disabled)
 118+ $text .= " disabled";
 119+ if (array_key_exists('maxlength', $other_args))
 120+ $text .= ' maxlength="' . $other_args['maxlength'] . '"';
 121+ $text .=<<<END
122122 />
123123 <span id="$info_id" class="errorMessage"></span>
124124
125125 END;
126 - if (array_key_exists('is_uploadable', $other_args) && $other_args['is_uploadable'] == true) {
127 - if (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true) {
128 - if (array_key_exists('delimiter', $other_args)) {
129 - $delimiter = $other_args['delimiter'];
130 - } else {
131 - $delimiter = ",";
132 - }
133 - } else {
134 - $delimiter = null;
135 - }
136 - $text .= SFFormInputs::uploadLinkHTML($input_id, $delimiter);
137 - }
138 - return array($text, null);
139 - }
 126+ if (array_key_exists('is_uploadable', $other_args) && $other_args['is_uploadable'] == true) {
 127+ if (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true) {
 128+ if (array_key_exists('delimiter', $other_args)) {
 129+ $delimiter = $other_args['delimiter'];
 130+ } else {
 131+ $delimiter = ",";
 132+ }
 133+ } else {
 134+ $delimiter = null;
 135+ }
 136+ $text .= SFFormInputs::uploadLinkHTML($input_id, $delimiter);
 137+ }
 138+ return array($text, null);
 139+ }
140140
141 - function dropdownHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
142 - global $sfgTabIndex, $sfgFieldNum;
 141+ function dropdownHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
 142+ global $sfgTabIndex, $sfgFieldNum;
143143
144 - $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
145 - if (array_key_exists('class', $other_args))
146 - $className .= " " . $other_args['class'];
147 - $input_id = "input_$sfgFieldNum";
148 - $info_id = "info_$sfgFieldNum";
149 - $disabled_text = ($is_disabled) ? "disabled" : "";
150 - $text =<<<END
 144+ $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
 145+ if (array_key_exists('class', $other_args))
 146+ $className .= " " . $other_args['class'];
 147+ $input_id = "input_$sfgFieldNum";
 148+ $info_id = "info_$sfgFieldNum";
 149+ $disabled_text = ($is_disabled) ? "disabled" : "";
 150+ $text =<<<END
151151 <select id="$input_id" tabindex="$sfgTabIndex" name="$input_name" class="$className" $disabled_text>
152152
153153 END;
154 - // add a blank value at the beginning if it's a non-mandatory field
155 - if (! $is_mandatory)
156 - $text .= " <option value=\"\"></option>\n";
157 - if (($possible_values = $other_args['possible_values']) == null)
158 - $possible_values = array();
159 - foreach ($possible_values as $possible_value) {
160 - $text .= " <option value=\"$possible_value\"";
161 - if ($possible_value == $cur_value) {$text .= " selected=\"selected\""; }
162 - $text .= ">$possible_value</option>\n";
163 - }
164 - $text .=<<<END
 154+ // add a blank value at the beginning if it's a non-mandatory field
 155+ if (! $is_mandatory)
 156+ $text .= " <option value=\"\"></option>\n";
 157+ if (($possible_values = $other_args['possible_values']) == null)
 158+ $possible_values = array();
 159+ foreach ($possible_values as $possible_value) {
 160+ $text .= " <option value=\"$possible_value\"";
 161+ if ($possible_value == $cur_value) {$text .= " selected=\"selected\""; }
 162+ $text .= ">$possible_value</option>\n";
 163+ }
 164+ $text .=<<<END
165165 </select>
166166 <span id="$info_id" class="errorMessage"></span>
167167
168168 END;
169 - return array($text, null);
170 - }
 169+ return array($text, null);
 170+ }
171171
172 - /*
173 - * getValuesArray() - helper function to get an array of values out of
174 - * what may be either an array or a delimited string
175 - */
176 - function getValuesArray($value, $delimiter) {
177 - if (is_array($value)) {
178 - return $value;
179 - } else {
180 - // remove extra spaces
181 - return array_map('trim', explode($delimiter, $value));
182 - }
183 - }
 172+ /*
 173+ * getValuesArray() - helper function to get an array of values out of
 174+ * what may be either an array or a delimited string
 175+ */
 176+ function getValuesArray($value, $delimiter) {
 177+ if (is_array($value)) {
 178+ return $value;
 179+ } else {
 180+ // remove extra spaces
 181+ return array_map('trim', explode($delimiter, $value));
 182+ }
 183+ }
184184
185 - function listboxHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
186 - global $sfgTabIndex, $sfgFieldNum;
 185+ function listboxHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
 186+ global $sfgTabIndex, $sfgFieldNum;
187187
188 - $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
189 - if (array_key_exists('class', $other_args))
190 - $className .= " " . $other_args['class'];
191 - $input_id = "input_$sfgFieldNum";
192 - $info_id = "info_$sfgFieldNum";
193 - $hidden_input_name = $input_name . "[is_list]";
194 - $input_name .= "[]"; // needed so that this input will send an array
195 - $disabled_text = ($is_disabled) ? "disabled" : "";
196 - // get list delimiter - default is comma
197 - if (array_key_exists('delimiter', $other_args)) {
198 - $delimiter = $other_args['delimiter'];
199 - } else {
200 - $delimiter = ",";
201 - }
202 - $cur_values = SFFormInputs::getValuesArray($cur_value, $delimiter);
 188+ $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
 189+ if (array_key_exists('class', $other_args))
 190+ $className .= " " . $other_args['class'];
 191+ $input_id = "input_$sfgFieldNum";
 192+ $info_id = "info_$sfgFieldNum";
 193+ $hidden_input_name = $input_name . "[is_list]";
 194+ $input_name .= "[]"; // needed so that this input will send an array
 195+ $disabled_text = ($is_disabled) ? "disabled" : "";
 196+ // get list delimiter - default is comma
 197+ if (array_key_exists('delimiter', $other_args)) {
 198+ $delimiter = $other_args['delimiter'];
 199+ } else {
 200+ $delimiter = ",";
 201+ }
 202+ $cur_values = SFFormInputs::getValuesArray($cur_value, $delimiter);
203203
204 - $text =<<<END
 204+ $text =<<<END
205205 <select id="$input_id" tabindex="$sfgTabIndex" name="$input_name" class="$className" multiple $disabled_text>
206206
207207 END;
208 - if (($possible_values = $other_args['possible_values']) == null)
209 - $possible_values = array();
210 - foreach ($possible_values as $possible_value) {
211 - $text .= " <option value=\"$possible_value\"";
212 - if (in_array($possible_value, $cur_values)) {$text .= " selected"; }
213 - $text .= ">$possible_value</option>\n";
214 - }
215 - $text .=<<<END
 208+ if (($possible_values = $other_args['possible_values']) == null)
 209+ $possible_values = array();
 210+ foreach ($possible_values as $possible_value) {
 211+ $text .= " <option value=\"$possible_value\"";
 212+ if (in_array($possible_value, $cur_values)) {$text .= " selected"; }
 213+ $text .= ">$possible_value</option>\n";
 214+ }
 215+ $text .=<<<END
216216 </select>
217217 <span id="$info_id" class="errorMessage"></span>
218218 <input type="hidden" name="$hidden_input_name" value="1" />
219219
220220 END;
221 - return array($text, null);
222 - }
 221+ return array($text, null);
 222+ }
223223
224 - function checkboxesHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
225 - global $sfgTabIndex, $sfgFieldNum;
 224+ function checkboxesHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
 225+ global $sfgTabIndex, $sfgFieldNum;
226226
227 - $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
228 - if (array_key_exists('class', $other_args))
229 - $className .= " " . $other_args['class'];
230 - $input_id = "input_$sfgFieldNum";
231 - $info_id = "info_$sfgFieldNum";
232 - $hidden_input_name = $input_name . "[is_list]";
233 - $disabled_text = ($is_disabled) ? "disabled" : "";
234 - // get list delimiter - default is comma
235 - if (array_key_exists('delimiter', $other_args)) {
236 - $delimiter = $other_args['delimiter'];
237 - } else {
238 - $delimiter = ",";
239 - }
240 - $cur_values = SFFormInputs::getValuesArray($cur_value, $delimiter);
 227+ $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
 228+ if (array_key_exists('class', $other_args))
 229+ $className .= " " . $other_args['class'];
 230+ $input_id = "input_$sfgFieldNum";
 231+ $info_id = "info_$sfgFieldNum";
 232+ $hidden_input_name = $input_name . "[is_list]";
 233+ $disabled_text = ($is_disabled) ? "disabled" : "";
 234+ // get list delimiter - default is comma
 235+ if (array_key_exists('delimiter', $other_args)) {
 236+ $delimiter = $other_args['delimiter'];
 237+ } else {
 238+ $delimiter = ",";
 239+ }
 240+ $cur_values = SFFormInputs::getValuesArray($cur_value, $delimiter);
241241
242 - if (($possible_values = $other_args['possible_values']) == null)
243 - $possible_values = array();
244 - $text = "";
245 - // if it's mandatory, add a span around all the checkboxes, since
246 - // some browsers don't support formatting of checkboxes
247 - if ($is_mandatory)
248 - $text .= ' <span class="mandatoryFieldsSpan">' . "\n";
249 - foreach ($possible_values as $key => $possible_value) {
250 - $cur_input_name = $input_name . "[" . $key . "]";
251 - $checked_text = (in_array($possible_value, $cur_values)) ? 'checked="checked"' : "";
252 - $text .=<<<END
 242+ if (($possible_values = $other_args['possible_values']) == null)
 243+ $possible_values = array();
 244+ $text = "";
 245+ // if it's mandatory, add a span around all the checkboxes, since
 246+ // some browsers don't support formatting of checkboxes
 247+ if ($is_mandatory)
 248+ $text .= ' <span class="mandatoryFieldsSpan">' . "\n";
 249+ foreach ($possible_values as $key => $possible_value) {
 250+ $cur_input_name = $input_name . "[" . $key . "]";
 251+ $checked_text = (in_array($possible_value, $cur_values)) ? 'checked="checked"' : "";
 252+ $text .=<<<END
253253 <span class="checkboxSpan">
254254 <input type="checkbox" id="$input_id" tabindex="$sfgTabIndex" name="$cur_input_name" value="$possible_value" class="$className" $checked_text $disabled_text/> $possible_value
255255 </span>
256256
257257 END;
258 - $sfgTabIndex++;
259 - }
260 - // close span
261 - if ($is_mandatory)
262 - $text .= " </span>";
263 - $text .=<<<END
 258+ $sfgTabIndex++;
 259+ }
 260+ // close span
 261+ if ($is_mandatory)
 262+ $text .= " </span>";
 263+ $text .=<<<END
264264 <span id="$info_id" class="errorMessage"></span>
265265 <input type="hidden" name="$hidden_input_name" value="1" />
266266
267267 END;
268 - return array($text, null);
269 - }
 268+ return array($text, null);
 269+ }
270270
271 - function textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
272 - // if 'no autocomplete' was specified, call the regular text entry instead
273 - if (array_key_exists('no autocomplete', $other_args) &&
274 - $other_args['no autocomplete'] == true)
275 - return SFFormInputs::textEntryHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
 271+ function textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
 272+ // if 'no autocomplete' was specified, call the regular text entry instead
 273+ if (array_key_exists('no autocomplete', $other_args) &&
 274+ $other_args['no autocomplete'] == true)
 275+ return SFFormInputs::textEntryHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
276276
277 - global $sfgTabIndex, $sfgFieldNum;
 277+ global $sfgTabIndex, $sfgFieldNum;
278278
279 - $className = ($is_mandatory) ? "autocompleteInput mandatoryField" : "autocompleteInput";
280 - if (array_key_exists('class', $other_args))
281 - $className .= " " . $other_args['class'];
282 - $disabled_text = ($is_disabled) ? "disabled" : "";
283 - if (array_key_exists('autocomplete on property', $other_args)) {
284 - $autocomplete_field_type = 'property';
285 - $semantic_field_name = $other_args['autocomplete on property'];
286 - } elseif (array_key_exists('autocomplete on', $other_args)) { // for backwards-compatibility
287 - $autocomplete_field_type = 'category';
288 - $semantic_field_name = $other_args['autocomplete on'];
289 - } elseif (array_key_exists('autocomplete on category', $other_args)) {
290 - $autocomplete_field_type = 'category';
291 - $semantic_field_name = $other_args['autocomplete on category'];
292 - } elseif (array_key_exists('autocomplete on concept', $other_args)) {
293 - $autocomplete_field_type = 'concept';
294 - $semantic_field_name = $other_args['autocomplete on concept'];
295 - } elseif (array_key_exists('autocomplete on namespace', $other_args)) {
296 - $autocomplete_field_type = 'namespace';
297 - $semantic_field_name = $other_args['autocomplete on namespace'];
298 - // special handling for "main" (blank) namespace
299 - if ($semantic_field_name == "")
300 - $semantic_field_name = "main";
301 - } elseif (array_key_exists('is_relation', $other_args) ||
302 - (array_key_exists('field_type', $other_args) && $other_args['field_type'] == 'page')) {
303 - $autocomplete_field_type = 'relation';
304 - $semantic_field_name = $other_args['semantic_field_name'];
305 - } else {
306 - $autocomplete_field_type = 'attribute';
307 - if (array_key_exists('semantic_field_name', $other_args))
308 - $semantic_field_name = $other_args['semantic_field_name'];
309 - else
310 - // there's some discrepancy between the form and template calls and
311 - // the property for this field
312 - $semantic_field_name = "";
313 - }
314 - $input_id = "input_" . $sfgFieldNum;
315 - $info_id = "info_" . $sfgFieldNum;
316 - $div_name = "div_" . $sfgFieldNum;
317 - if (array_key_exists('input_type', $other_args) && $other_args['input_type'] == "textarea") {
318 - $rows = $other_args['rows'];
319 - $cols = $other_args['cols'];
320 - $text =<<<END
 279+ $className = ($is_mandatory) ? "autocompleteInput mandatoryField" : "autocompleteInput";
 280+ if (array_key_exists('class', $other_args))
 281+ $className .= " " . $other_args['class'];
 282+ $disabled_text = ($is_disabled) ? "disabled" : "";
 283+ if (array_key_exists('autocomplete on property', $other_args)) {
 284+ $autocomplete_field_type = 'property';
 285+ $semantic_field_name = $other_args['autocomplete on property'];
 286+ } elseif (array_key_exists('autocomplete on', $other_args)) { // for backwards-compatibility
 287+ $autocomplete_field_type = 'category';
 288+ $semantic_field_name = $other_args['autocomplete on'];
 289+ } elseif (array_key_exists('autocomplete on category', $other_args)) {
 290+ $autocomplete_field_type = 'category';
 291+ $semantic_field_name = $other_args['autocomplete on category'];
 292+ } elseif (array_key_exists('autocomplete on concept', $other_args)) {
 293+ $autocomplete_field_type = 'concept';
 294+ $semantic_field_name = $other_args['autocomplete on concept'];
 295+ } elseif (array_key_exists('autocomplete on namespace', $other_args)) {
 296+ $autocomplete_field_type = 'namespace';
 297+ $semantic_field_name = $other_args['autocomplete on namespace'];
 298+ // special handling for "main" (blank) namespace
 299+ if ($semantic_field_name == "")
 300+ $semantic_field_name = "main";
 301+ } elseif (array_key_exists('is_relation', $other_args) ||
 302+ (array_key_exists('field_type', $other_args) && $other_args['field_type'] == 'page')) {
 303+ $autocomplete_field_type = 'relation';
 304+ $semantic_field_name = $other_args['semantic_field_name'];
 305+ } else {
 306+ $autocomplete_field_type = 'attribute';
 307+ if (array_key_exists('semantic_field_name', $other_args)) {
 308+ $semantic_field_name = $other_args['semantic_field_name'];
 309+ } else {
 310+ // there's some discrepancy between the form and template calls and
 311+ // the property for this field
 312+ $semantic_field_name = "";
 313+ }
 314+ }
 315+ $input_id = "input_" . $sfgFieldNum;
 316+ $info_id = "info_" . $sfgFieldNum;
 317+ $div_name = "div_" . $sfgFieldNum;
 318+ if (array_key_exists('input_type', $other_args) && $other_args['input_type'] == "textarea") {
 319+ $rows = $other_args['rows'];
 320+ $cols = $other_args['cols'];
 321+ $text =<<<END
321322 <textarea tabindex="$sfgTabIndex" id="$input_id" name="$input_name" rows="$rows" cols="$cols" class="$className" $disabled_text></textarea>
322323
323324 END;
324 - } else {
325 - if (array_key_exists('size', $other_args))
326 - $size = $other_args['size'];
327 - else
328 - $size = "35";
 325+ } else {
 326+ if (array_key_exists('size', $other_args))
 327+ $size = $other_args['size'];
 328+ else
 329+ $size = "35";
329330
330 - $text =<<<END
331 - <input tabindex="$sfgTabIndex" id="$input_id" name="$input_name" type="text"
 331+ $text =<<<END
 332+ <input tabindex="$sfgTabIndex" id="$input_id" name="$input_name" type="text"
332333 value="" size="$size" class="$className"
333334 END;
334 - if ($is_disabled)
335 - $text .= " disabled";
336 - if (array_key_exists('maxlength', $other_args))
337 - $text .= ' maxlength="' . $other_args['maxlength'] . '"';
338 - $text .= "/>\n";
339 - }
340 - // is_list and delimiter variables - needed later
341 - $is_list = (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true);
342 - if ($is_list) {
343 - if (array_key_exists('delimiter', $other_args)) {
344 - $delimiter = $other_args['delimiter'];
345 - } else {
346 - $delimiter = ",";
347 - }
348 - } else {
349 - $delimiter = null;
350 - }
351 - if (array_key_exists('is_uploadable', $other_args) && $other_args['is_uploadable'] == true) {
352 - $text .= SFFormInputs::uploadLinkHTML($input_id, $delimiter);
353 - }
354 - $text .=<<<END
 335+ if ($is_disabled)
 336+ $text .= " disabled";
 337+ if (array_key_exists('maxlength', $other_args))
 338+ $text .= ' maxlength="' . $other_args['maxlength'] . '"';
 339+ $text .= "/>\n";
 340+ }
 341+ // is_list and delimiter variables - needed later
 342+ $is_list = (array_key_exists('is_list', $other_args) && $other_args['is_list'] == true);
 343+ if ($is_list) {
 344+ if (array_key_exists('delimiter', $other_args)) {
 345+ $delimiter = $other_args['delimiter'];
 346+ } else {
 347+ $delimiter = ",";
 348+ }
 349+ } else {
 350+ $delimiter = null;
 351+ }
 352+ if (array_key_exists('is_uploadable', $other_args) && $other_args['is_uploadable'] == true) {
 353+ $text .= SFFormInputs::uploadLinkHTML($input_id, $delimiter);
 354+ }
 355+ $text .=<<<END
355356 <span id="$info_id" class="errorMessage"></span>
356357 <div class="page_name_auto_complete" id="$div_name"></div>
357358 <script type="text/javascript">/* <![CDATA[ */
358359
359360 END;
360 - $options_str_key = str_replace("'", "\'", $semantic_field_name);
361 - if ($is_list) {
362 - $options_str_key .= ",list";
363 - if ($delimiter != ",") {
364 - $options_str_key .= "," . $delimiter;
365 - }
366 - }
367 - $javascript_text = "autocompletemappings[$sfgFieldNum] = '$options_str_key';\n";
368 - if (array_key_exists('remote_autocompletion', $other_args) &&
369 - $other_args['remote_autocompletion'] == true) {
370 - $javascript_text .= "autocompletedatatypes['$options_str_key'] = '$autocomplete_field_type';\n";
371 - } elseif ($semantic_field_name != '') {
372 - $autocomplete_values = SFFormInputs::createAutocompleteValuesArray(str_replace(' ', '_', $semantic_field_name), $autocomplete_field_type);
373 - $autocomplete_string = "[['" . implode("'], ['", $autocomplete_values) . "']]";
374 - $javascript_text .= "autocompletestrings['$options_str_key'] = $autocomplete_string;\n";
375 - }
376 - if ($cur_value) {
377 - $text .= "document.getElementById('$input_id').value = \"$cur_value\"\n";
378 - }
379 - $text .= "/* ]]> */</script>\n";
380 - return array($text, $javascript_text);
381 - }
 361+ $options_str_key = str_replace("'", "\'", $semantic_field_name);
 362+ if ($is_list) {
 363+ $options_str_key .= ",list";
 364+ if ($delimiter != ",") {
 365+ $options_str_key .= "," . $delimiter;
 366+ }
 367+ }
 368+ $javascript_text = "autocompletemappings[$sfgFieldNum] = '$options_str_key';\n";
 369+ if (array_key_exists('remote_autocompletion', $other_args) &&
 370+ $other_args['remote_autocompletion'] == true) {
 371+ $javascript_text .= "autocompletedatatypes['$options_str_key'] = '$autocomplete_field_type';\n";
 372+ } elseif ($semantic_field_name != '') {
 373+ $autocomplete_values = SFFormInputs::createAutocompleteValuesArray(str_replace(' ', '_', $semantic_field_name), $autocomplete_field_type);
 374+ $autocomplete_string = "[['" . implode("'], ['", $autocomplete_values) . "']]";
 375+ $javascript_text .= "autocompletestrings['$options_str_key'] = $autocomplete_string;\n";
 376+ }
 377+ if ($cur_value) {
 378+ $text .= "document.getElementById('$input_id').value = \"$cur_value\"\n";
 379+ }
 380+ $text .= "/* ]]> */</script>\n";
 381+ return array($text, $javascript_text);
 382+ }
382383
383 - function textAreaHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
384 - // set size values
385 - if (! array_key_exists('rows', $other_args))
386 - $other_args['rows'] = 5;
387 - if (! array_key_exists('cols', $other_args))
388 - $other_args['cols'] = 80;
 384+ function textAreaHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
 385+ // set size values
 386+ if (! array_key_exists('rows', $other_args))
 387+ $other_args['rows'] = 5;
 388+ if (! array_key_exists('cols', $other_args))
 389+ $other_args['cols'] = 80;
389390
390 - // if it's an autocomplete, call the with-autocomplete function instead
391 - $autocompletion_disabled = array_key_exists('autocomplete on', $other_args) && $other_args['autocomplete on'] == "";
392 - if (! $autocompletion_disabled) {
393 - if ((array_key_exists('is_relation', $other_args) && $other_args['is_relation'] == true) ||
394 - array_key_exists('autocomplete', $other_args) ||
395 - array_key_exists('autocomplete on', $other_args) ||
396 - array_key_exists('autocomplete on namespace', $other_args) ||
397 - array_key_exists('remote autocompletion', $other_args)) {
398 - $other_args['input_type'] = "textarea";
399 - return SFFormInputs::textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
400 - }
401 - }
 391+ // if it's an autocomplete, call the with-autocomplete function instead
 392+ $autocompletion_disabled = array_key_exists('autocomplete on', $other_args) && $other_args['autocomplete on'] == "";
 393+ if (! $autocompletion_disabled) {
 394+ if ((array_key_exists('is_relation', $other_args) && $other_args['is_relation'] == true) ||
 395+ array_key_exists('autocomplete', $other_args) ||
 396+ array_key_exists('autocomplete on', $other_args) ||
 397+ array_key_exists('autocomplete on namespace', $other_args) ||
 398+ array_key_exists('remote autocompletion', $other_args)) {
 399+ $other_args['input_type'] = "textarea";
 400+ return SFFormInputs::textInputWithAutocompleteHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args);
 401+ }
 402+ }
402403
403 - global $sfgTabIndex, $sfgFieldNum;
 404+ global $sfgTabIndex, $sfgFieldNum;
404405
405 - $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
406 - if (array_key_exists('class', $other_args))
407 - $className .= " " . $other_args['class'];
408 - $input_id = "input_$sfgFieldNum";
409 - $info_id = "info_$sfgFieldNum";
410 - $disabled_text = ($is_disabled) ? "disabled" : "";
 406+ $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
 407+ if (array_key_exists('class', $other_args))
 408+ $className .= " " . $other_args['class'];
 409+ $input_id = "input_$sfgFieldNum";
 410+ $info_id = "info_$sfgFieldNum";
 411+ $disabled_text = ($is_disabled) ? "disabled" : "";
411412
412 - $rows = $other_args['rows'];
413 - $cols = $other_args['cols'];
 413+ $rows = $other_args['rows'];
 414+ $cols = $other_args['cols'];
414415
415 - $text =<<<END
 416+ $text =<<<END
416417 <textarea tabindex="$sfgTabIndex" id="$input_id" name="$input_name" rows="$rows" cols="$cols" class="$className" $disabled_text>$cur_value</textarea>
417418 <span id="$info_id" class="errorMessage"></span>
418419
419420 END;
420 - return array($text, null);
421 - }
 421+ return array($text, null);
 422+ }
422423
423 - function monthDropdownHTML($cur_month, $input_name, $is_disabled) {
424 - global $sfgTabIndex, $sfgFieldNum, $wgAmericanDates;
 424+ function monthDropdownHTML($cur_month, $input_name, $is_disabled) {
 425+ global $sfgTabIndex, $sfgFieldNum, $wgAmericanDates;
425426
426 - $disabled_text = ($is_disabled) ? "disabled" : "";
427 - $text = ' <select tabindex="' . $sfgTabIndex . '" id="input_' . $sfgFieldNum . '_month" name="' . $input_name . "[month]\" $disabled_text>\n";
428 - $month_names = sffGetMonthNames();
429 - foreach ($month_names as $i => $name) {
430 - // pad out month to always be two digits
431 - $month_value = ($wgAmericanDates == true) ? $name : str_pad($i + 1, 2, "0", STR_PAD_LEFT);
432 - $text .= " <option value=\"$month_value\"";
433 - if ($name == $cur_month || ($i + 1) == $cur_month) {$text .= " selected=\"selected\""; }
434 - $text .= ">$name</option>\n";
435 - }
436 - $text .= " </select>\n";
437 - return $text;
438 - }
 427+ $disabled_text = ($is_disabled) ? "disabled" : "";
 428+ $text = ' <select tabindex="' . $sfgTabIndex . '" id="input_' . $sfgFieldNum . '_month" name="' . $input_name . "[month]\" $disabled_text>\n";
 429+ $month_names = sffGetMonthNames();
 430+ foreach ($month_names as $i => $name) {
 431+ // pad out month to always be two digits
 432+ $month_value = ($wgAmericanDates == true) ? $name : str_pad($i + 1, 2, "0", STR_PAD_LEFT);
 433+ $text .= " <option value=\"$month_value\"";
 434+ if ($name == $cur_month || ($i + 1) == $cur_month) {$text .= " selected=\"selected\""; }
 435+ $text .= ">$name</option>\n";
 436+ }
 437+ $text .= " </select>\n";
 438+ return $text;
 439+ }
439440
440 - function dateEntryHTML($date, $input_name, $is_mandatory, $is_disabled, $other_args) {
441 - global $sfgTabIndex, $sfgFieldNum, $sfgJSValidationCalls;
 441+ function dateEntryHTML($date, $input_name, $is_mandatory, $is_disabled, $other_args) {
 442+ global $sfgTabIndex, $sfgFieldNum, $sfgJSValidationCalls;
442443
443 - $input_id = "input_$sfgFieldNum";
444 - $info_id = "info_$sfgFieldNum";
445 - // add to validation calls
446 - if ($other_args['part_of_multiple']) {
447 - $sfgJSValidationCalls[] = "validate_type_of_multiple_fields($sfgFieldNum, 'date')";
448 - } else {
449 - $sfgJSValidationCalls[] = "validate_field_type('$input_id', 'date', '$info_id')";
450 - }
 444+ $input_id = "input_$sfgFieldNum";
 445+ $info_id = "info_$sfgFieldNum";
 446+ // add to validation calls
 447+ if ($other_args['part_of_multiple']) {
 448+ $sfgJSValidationCalls[] = "validate_type_of_multiple_fields($sfgFieldNum, 'date')";
 449+ } else {
 450+ $sfgJSValidationCalls[] = "validate_field_type('$input_id', 'date', '$info_id')";
 451+ }
451452
452 - if ($date) {
453 - // can show up here either as an array or a string, depending on
454 - // whether it came from user input or a wiki page
455 - if (is_array($date)) {
456 - $year = $date['year'];
457 - $month = $date['month'];
458 - $day = $date['day'];
459 - } else {
460 - $actual_date = strtotime($date);
461 - $year = date("Y", $actual_date);
462 - $month = date("n", $actual_date);
463 - $day = date("j", $actual_date);
464 - }
465 - } else {
466 - $cur_date = getdate();
467 - $year = $cur_date['year'];
468 - $month = $cur_date['month'];
469 - $day = null; // no need for day
470 - }
471 - $disabled_text = ($is_disabled) ? "disabled" : "";
472 - $text = SFFormInputs::monthDropdownHTML($month, $input_name, $is_disabled);
473 - $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_day" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>' . "\n";
474 - $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_year" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4" ' . $disabled_text . '/>' . "\n";
475 - $text .= " <span id=\"$info_id\" class=\"errorMessage\"></span>";
476 - return array($text, null);
477 - }
 453+ if ($date) {
 454+ // can show up here either as an array or a string, depending on
 455+ // whether it came from user input or a wiki page
 456+ if (is_array($date)) {
 457+ $year = $date['year'];
 458+ $month = $date['month'];
 459+ $day = $date['day'];
 460+ } else {
 461+ $actual_date = strtotime($date);
 462+ $year = date("Y", $actual_date);
 463+ $month = date("n", $actual_date);
 464+ $day = date("j", $actual_date);
 465+ }
 466+ } else {
 467+ $cur_date = getdate();
 468+ $year = $cur_date['year'];
 469+ $month = $cur_date['month'];
 470+ $day = null; // no need for day
 471+ }
 472+ $disabled_text = ($is_disabled) ? "disabled" : "";
 473+ $text = SFFormInputs::monthDropdownHTML($month, $input_name, $is_disabled);
 474+ $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_day" name="' . $input_name . '[day]" type="text" value="' . $day . '" size="2" ' . $disabled_text . '/>' . "\n";
 475+ $text .= ' <input tabindex="' . $sfgTabIndex . '" id="' . $input_id . '_year" name="' . $input_name . '[year]" type="text" value="' . $year . '" size="4" ' . $disabled_text . '/>' . "\n";
 476+ $text .= " <span id=\"$info_id\" class=\"errorMessage\"></span>";
 477+ return array($text, null);
 478+ }
478479
479 - function dateTimeEntryHTML($datetime, $input_name, $is_mandatory, $is_disabled, $other_args) {
480 - global $sfgTabIndex;
 480+ function dateTimeEntryHTML($datetime, $input_name, $is_mandatory, $is_disabled, $other_args) {
 481+ global $sfgTabIndex;
481482
482 - $include_timezone = $other_args['include_timezone'];
 483+ $include_timezone = $other_args['include_timezone'];
483484
484 - if ($datetime) {
485 - // can show up here either as an array or a string, depending on
486 - // whether it came from user input or a wiki page
487 - if (is_array($datetime)) {
488 - if (isset($datetime['hour'])) $hour = $cur_value['hour'];
489 - if (isset($datetime['minute'])) $minute = $cur_value['minute'];
490 - if (isset($datetime['second'])) $second = $cur_value['second'];
491 - if (isset($datetime['ampm24h'])) $ampm24h = $cur_value['ampm24h'];
492 - if (isset($datetime['timezone'])) $timezone = $cur_value['timezone'];
493 - } else {
494 - $actual_date = strtotime($datetime);
495 - $hour = date("g", $actual_date);
496 - $minute = date("i", $actual_date);
497 - $second = date("s", $actual_date);
498 - $ampm24h = date("A", $actual_date);
499 - $timezone = date("T", $actual_date);
500 - }
501 - } else {
502 - $cur_date = getdate();
503 - $hour = null;
504 - $minute = null;
505 - $second = "00"; // default at least this value
506 - $timezone = "";
507 - }
 485+ if ($datetime) {
 486+ // can show up here either as an array or a string, depending on
 487+ // whether it came from user input or a wiki page
 488+ if (is_array($datetime)) {
 489+ if (isset($datetime['hour'])) $hour = $cur_value['hour'];
 490+ if (isset($datetime['minute'])) $minute = $cur_value['minute'];
 491+ if (isset($datetime['second'])) $second = $cur_value['second'];
 492+ if (isset($datetime['ampm24h'])) $ampm24h = $cur_value['ampm24h'];
 493+ if (isset($datetime['timezone'])) $timezone = $cur_value['timezone'];
 494+ } else {
 495+ $actual_date = strtotime($datetime);
 496+ $hour = date("g", $actual_date);
 497+ $minute = date("i", $actual_date);
 498+ $second = date("s", $actual_date);
 499+ $ampm24h = date("A", $actual_date);
 500+ $timezone = date("T", $actual_date);
 501+ }
 502+ } else {
 503+ $cur_date = getdate();
 504+ $hour = null;
 505+ $minute = null;
 506+ $second = "00"; // default at least this value
 507+ $timezone = "";
 508+ }
508509
509 - list($text, $javascript_text) = SFFormInputs::dateEntryHTML($datetime, $input_name, $is_mandatory, $is_disabled, $other_args);
510 - $disabled_text = ($is_disabled) ? "disabled" : "";
511 - $text .= ' &nbsp;<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[hour]" type="text" value="' . $hour . '" size="2"/ ' . $disabled_text . '>';
512 - $sfgTabIndex++;
513 - $text .= ' :<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[minute]" type="text" value="' . $minute . '" size="2"/ ' . $disabled_text . '>';
514 - $sfgTabIndex++;
515 - $text .= ':<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[second]" type="text" value="' . $second . '" size="2"/ ' . $disabled_text . '>' . "\n";
 510+ list($text, $javascript_text) = SFFormInputs::dateEntryHTML($datetime, $input_name, $is_mandatory, $is_disabled, $other_args);
 511+ $disabled_text = ($is_disabled) ? "disabled" : "";
 512+ $text .= ' &nbsp;<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[hour]" type="text" value="' . $hour . '" size="2"/ ' . $disabled_text . '>';
 513+ $sfgTabIndex++;
 514+ $text .= ' :<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[minute]" type="text" value="' . $minute . '" size="2"/ ' . $disabled_text . '>';
 515+ $sfgTabIndex++;
 516+ $text .= ':<input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[second]" type="text" value="' . $second . '" size="2"/ ' . $disabled_text . '>' . "\n";
516517
517 - $sfgTabIndex++;
518 - $text .= ' <select tabindex="' . $sfgTabIndex . '" name="' . $input_name . "[ampm24h]\" $disabled_text>\n";
519 - $ampm24h_options = array('', 'AM', 'PM');
520 - foreach ($ampm24h_options as $value) {
521 - $text .= " <option value=\"$value\"";
522 - if ($value == $ampm24h) {$text .= " selected=\"selected\""; }
523 - $text .= ">$value</option>\n";
524 - }
525 - $text .= " </select>\n";
 518+ $sfgTabIndex++;
 519+ $text .= ' <select tabindex="' . $sfgTabIndex . '" name="' . $input_name . "[ampm24h]\" $disabled_text>\n";
 520+ $ampm24h_options = array('', 'AM', 'PM');
 521+ foreach ($ampm24h_options as $value) {
 522+ $text .= " <option value=\"$value\"";
 523+ if ($value == $ampm24h) {$text .= " selected=\"selected\""; }
 524+ $text .= ">$value</option>\n";
 525+ }
 526+ $text .= " </select>\n";
526527
527 - if ($include_timezone) {
528 - $sfgTabIndex++;
529 - $text .= ' <input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[timezone]" type="text" value="' . $timezone . '" size="2"/ ' . $disabled_text . '>' . "\n";
530 - }
 528+ if ($include_timezone) {
 529+ $sfgTabIndex++;
 530+ $text .= ' <input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[timezone]" type="text" value="' . $timezone . '" size="2"/ ' . $disabled_text . '>' . "\n";
 531+ }
531532
532 - return array($text, $javascript_text);
533 - }
 533+ return array($text, $javascript_text);
 534+ }
534535
535 - function radioButtonHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
536 - global $sfgTabIndex;
 536+ function radioButtonHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
 537+ global $sfgTabIndex;
537538
538 - $disabled_text = ($is_disabled) ? "disabled" : "";
539 - $check_set = false;
540 - if (! $is_mandatory) {
541 - $text = ' <input type="radio" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value=""';
542 - if (! $cur_value) {
543 - $text .= ' checked="checked"';
544 - $check_set = true;
545 - }
546 - $text .= " $disabled_text/> " . wfMsg('sf_editdata_none') . "\n";
547 - }
548 - // if it's mandatory, add a span around all the radiobuttons, since
549 - // some browsers don't support formatting of radiobuttons
550 - if ($is_mandatory)
551 - $text = ' <span class="mandatoryFieldsSpan">' . "\n";
552 - if (($possible_values = $other_args['possible_values']) == null)
553 - $possible_values = array();
554 - foreach ($possible_values as $i => $possible_value) {
555 - $text .= ' <input type="radio" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value="' . $possible_value . '"';
556 - if ($cur_value == $possible_value || (! $cur_value && ! $check_set)) {
557 - $text .= ' checked="checked"';
558 - $check_set = true;
559 - }
560 - $text .= " $disabled_text/> $possible_value\n";
561 - }
562 - // close span
563 - if ($is_mandatory)
564 - $text .= " </span>";
565 - return array($text, null);
566 - }
 539+ $disabled_text = ($is_disabled) ? "disabled" : "";
 540+ $check_set = false;
 541+ if (! $is_mandatory) {
 542+ $text = ' <input type="radio" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value=""';
 543+ if (! $cur_value) {
 544+ $text .= ' checked="checked"';
 545+ $check_set = true;
 546+ }
 547+ $text .= " $disabled_text/> " . wfMsg('sf_editdata_none') . "\n";
 548+ }
 549+ // if it's mandatory, add a span around all the radiobuttons, since
 550+ // some browsers don't support formatting of radiobuttons
 551+ if ($is_mandatory)
 552+ $text = ' <span class="mandatoryFieldsSpan">' . "\n";
 553+ if (($possible_values = $other_args['possible_values']) == null)
 554+ $possible_values = array();
 555+ foreach ($possible_values as $i => $possible_value) {
 556+ $text .= ' <input type="radio" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '" value="' . $possible_value . '"';
 557+ if ($cur_value == $possible_value || (! $cur_value && ! $check_set)) {
 558+ $text .= ' checked="checked"';
 559+ $check_set = true;
 560+ }
 561+ $text .= " $disabled_text/> $possible_value\n";
 562+ }
 563+ // close span
 564+ if ($is_mandatory)
 565+ $text .= " </span>";
 566+ return array($text, null);
 567+ }
567568
568 - function checkboxHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
569 - global $sfgTabIndex, $sfgFieldNum;
 569+ function checkboxHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) {
 570+ global $sfgTabIndex, $sfgFieldNum;
570571
571 - $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
572 - if (array_key_exists('class', $other_args))
573 - $className .= " " . $other_args['class'];
574 - $info_id = "info_$sfgFieldNum";
575 - $disabled_text = ($is_disabled) ? "disabled" : "";
 572+ $className = ($is_mandatory) ? "mandatoryField" : "createboxInput";
 573+ if (array_key_exists('class', $other_args))
 574+ $className .= " " . $other_args['class'];
 575+ $info_id = "info_$sfgFieldNum";
 576+ $disabled_text = ($is_disabled) ? "disabled" : "";
576577
577 - // can show up here either as an array or a string, depending on
578 - // whether it came from user input or a wiki page
579 - if (is_array($cur_value)) {
580 - $checked_str = (array_key_exists('value', $cur_value) && $cur_value['value'] == 'on') ? ' checked="checked"' : "";
581 - } else {
582 - // default to false - no need to check if it matches a 'false' word
583 - $vlc = strtolower(trim($cur_value));
584 - if (in_array($vlc, explode(',', wfMsgForContent('smw_true_words')), TRUE)) {
585 - $checked_str = ' checked="checked"';
586 - } else {
587 - $checked_str = "";
588 - }
589 - }
590 - $text =<<<END
 578+ // can show up here either as an array or a string, depending on
 579+ // whether it came from user input or a wiki page
 580+ if (is_array($cur_value)) {
 581+ $checked_str = (array_key_exists('value', $cur_value) && $cur_value['value'] == 'on') ? ' checked="checked"' : "";
 582+ } else {
 583+ // default to false - no need to check if it matches a 'false' word
 584+ $vlc = strtolower(trim($cur_value));
 585+ if (in_array($vlc, explode(',', wfMsgForContent('smw_true_words')), TRUE)) {
 586+ $checked_str = ' checked="checked"';
 587+ } else {
 588+ $checked_str = "";
 589+ }
 590+ }
 591+ $text =<<<END
591592 <input name="{$input_name}[is_checkbox]" type="hidden" value="true" />
592593 <input id="input_$sfgFieldNum" name="{$input_name}[value]" type="checkbox" class="$className" tabindex="$sfgTabIndex" $checked_str $disabled_text/>
593594 <span id="$info_id" class="errorMessage"></span>
594595
595596 END;
596 - return array($text, null);
597 - }
 597+ return array($text, null);
 598+ }
598599
599600 }
600 -
601 -?>
Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc
@@ -10,923 +10,923 @@
1111
1212 class SFFormPrinter {
1313
14 - var $mSemanticTypeHooks;
15 - var $mInputTypeHooks;
16 - var $standardInputsIncluded;
17 - var $mPageTitle;
 14+ var $mSemanticTypeHooks;
 15+ var $mInputTypeHooks;
 16+ var $standardInputsIncluded;
 17+ var $mPageTitle;
1818
19 - function SFFormPrinter() {
20 - global $smwgContLang;
 19+ function SFFormPrinter() {
 20+ global $smwgContLang;
2121
22 - // initialize the set of hooks for the entry-field functions to call for
23 - // fields of both a specific semantic "type" and a defined "input type"
24 - // in the form definition
25 - $this->mSemanticTypeHooks = array();
26 - if ($smwgContLang != null) {
27 - $datatypeLabels = $smwgContLang->getDatatypeLabels();
28 - $string_type = $datatypeLabels['_str'];
29 - $text_type = $datatypeLabels['_txt'];
30 - // type introduced in SMW 1.2
31 - if (array_key_exists('_cod', $datatypeLabels))
32 - $code_type = $datatypeLabels['_cod'];
33 - else
34 - $code_type = 'code';
35 - $url_type = $datatypeLabels['_uri'];
36 - $email_type = $datatypeLabels['_ema'];
37 - $float_type = $datatypeLabels['_num'];
38 - $bool_type = $datatypeLabels['_boo'];
39 - $date_type = $datatypeLabels['_dat'];
40 - $enum_type = 'enumeration'; // not a real type
41 - $page_type = $datatypeLabels['_wpg'];
42 - $this->setSemanticTypeHook($string_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'string'));
43 - $this->setSemanticTypeHook($string_type, true, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'string', 'is_list' => 'true'));
44 - $this->setSemanticTypeHook($text_type, false, array('SFFormInputs', 'textAreaHTML'), array());
45 - $this->setSemanticTypeHook($code_type, false, array('SFFormInputs', 'textAreaHTML'), array());
46 - $this->setSemanticTypeHook($url_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'URL'));
47 - $this->setSemanticTypeHook($email_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'email'));
48 - $this->setSemanticTypeHook($float_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'float'));
49 - $this->setSemanticTypeHook($bool_type, false, array('SFFormInputs', 'checkboxHTML'), array());
50 - $this->setSemanticTypeHook($date_type, false, array('SFFormInputs', 'dateEntryHTML'), array());
51 - $this->setSemanticTypeHook($enum_type, false, array('SFFormInputs', 'dropdownHTML'), array());
52 - $this->setSemanticTypeHook($enum_type, true, array('SFFormInputs', 'checkboxesHTML'), array());
53 - $this->setSemanticTypeHook($page_type, false, array('SFFormInputs', 'textInputWithAutocompleteHTML'), array('field_type' => 'page'));
54 - $this->setSemanticTypeHook($page_type, true, array('SFFormInputs', 'textInputWithAutocompleteHTML'), array('field_type' => 'page', 'size' => '100', 'is_list' => 'true'));
55 - }
56 - $this->mInputTypeHooks = array();
57 - $this->setInputTypeHook('text', array('SFFormInputs', 'textEntryHTML'), array());
58 - $this->setInputTypeHook('textarea', array('SFFormInputs', 'textAreaHTML'), array());
59 - $this->setInputTypeHook('date', array('SFFormInputs', 'dateEntryHTML'), array());
60 - $this->setInputTypeHook('datetime', array('SFFormInputs', 'dateTimeEntryHTML'), array('include_timezone' => false));
61 - $this->setInputTypeHook('datetime with timezone', array('SFFormInputs', 'dateTimeEntryHTML'), array('include_timezone' => true));
62 - $this->setInputTypeHook('checkbox', array('SFFormInputs', 'checkboxHTML'), array());
63 - $this->setInputTypeHook('radiobutton', array('SFFormInputs', 'radioButtonHTML'), array());
64 - $this->setInputTypeHook('checkboxes', array('SFFormInputs', 'checkboxesHTML'), array());
65 - $this->setInputTypeHook('listbox', array('SFFormInputs', 'listboxHTML'), array());
 22+ // initialize the set of hooks for the entry-field functions to call for
 23+ // fields of both a specific semantic "type" and a defined "input type"
 24+ // in the form definition
 25+ $this->mSemanticTypeHooks = array();
 26+ if ($smwgContLang != null) {
 27+ $datatypeLabels = $smwgContLang->getDatatypeLabels();
 28+ $string_type = $datatypeLabels['_str'];
 29+ $text_type = $datatypeLabels['_txt'];
 30+ // type introduced in SMW 1.2
 31+ if (array_key_exists('_cod', $datatypeLabels))
 32+ $code_type = $datatypeLabels['_cod'];
 33+ else
 34+ $code_type = 'code';
 35+ $url_type = $datatypeLabels['_uri'];
 36+ $email_type = $datatypeLabels['_ema'];
 37+ $float_type = $datatypeLabels['_num'];
 38+ $bool_type = $datatypeLabels['_boo'];
 39+ $date_type = $datatypeLabels['_dat'];
 40+ $enum_type = 'enumeration'; // not a real type
 41+ $page_type = $datatypeLabels['_wpg'];
 42+ $this->setSemanticTypeHook($string_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'string'));
 43+ $this->setSemanticTypeHook($string_type, true, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'string', 'is_list' => 'true'));
 44+ $this->setSemanticTypeHook($text_type, false, array('SFFormInputs', 'textAreaHTML'), array());
 45+ $this->setSemanticTypeHook($code_type, false, array('SFFormInputs', 'textAreaHTML'), array());
 46+ $this->setSemanticTypeHook($url_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'URL'));
 47+ $this->setSemanticTypeHook($email_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'email'));
 48+ $this->setSemanticTypeHook($float_type, false, array('SFFormInputs', 'textEntryHTML'), array('field_type' => 'float'));
 49+ $this->setSemanticTypeHook($bool_type, false, array('SFFormInputs', 'checkboxHTML'), array());
 50+ $this->setSemanticTypeHook($date_type, false, array('SFFormInputs', 'dateEntryHTML'), array());
 51+ $this->setSemanticTypeHook($enum_type, false, array('SFFormInputs', 'dropdownHTML'), array());
 52+ $this->setSemanticTypeHook($enum_type, true, array('SFFormInputs', 'checkboxesHTML'), array());
 53+ $this->setSemanticTypeHook($page_type, false, array('SFFormInputs', 'textInputWithAutocompleteHTML'), array('field_type' => 'page'));
 54+ $this->setSemanticTypeHook($page_type, true, array('SFFormInputs', 'textInputWithAutocompleteHTML'), array('field_type' => 'page', 'size' => '100', 'is_list' => 'true'));
 55+ }
 56+ $this->mInputTypeHooks = array();
 57+ $this->setInputTypeHook('text', array('SFFormInputs', 'textEntryHTML'), array());
 58+ $this->setInputTypeHook('textarea', array('SFFormInputs', 'textAreaHTML'), array());
 59+ $this->setInputTypeHook('date', array('SFFormInputs', 'dateEntryHTML'), array());
 60+ $this->setInputTypeHook('datetime', array('SFFormInputs', 'dateTimeEntryHTML'), array('include_timezone' => false));
 61+ $this->setInputTypeHook('datetime with timezone', array('SFFormInputs', 'dateTimeEntryHTML'), array('include_timezone' => true));
 62+ $this->setInputTypeHook('checkbox', array('SFFormInputs', 'checkboxHTML'), array());
 63+ $this->setInputTypeHook('radiobutton', array('SFFormInputs', 'radioButtonHTML'), array());
 64+ $this->setInputTypeHook('checkboxes', array('SFFormInputs', 'checkboxesHTML'), array());
 65+ $this->setInputTypeHook('listbox', array('SFFormInputs', 'listboxHTML'), array());
6666
67 - // initialize other variables
68 - $this->standardInputsIncluded = false;
69 - }
 67+ // initialize other variables
 68+ $this->standardInputsIncluded = false;
 69+ }
7070
71 - function setSemanticTypeHook($type, $is_list, $function_name, $default_args) {
72 - $this->mSemanticTypeHooks[$type][$is_list] = array($function_name, $default_args);
73 - }
 71+ function setSemanticTypeHook($type, $is_list, $function_name, $default_args) {
 72+ $this->mSemanticTypeHooks[$type][$is_list] = array($function_name, $default_args);
 73+ }
7474
75 - function setInputTypeHook($input_type, $function_name, $default_args) {
76 - $this->mInputTypeHooks[$input_type] = array($function_name, $default_args);
77 - }
 75+ function setInputTypeHook($input_type, $function_name, $default_args) {
 76+ $this->mInputTypeHooks[$input_type] = array($function_name, $default_args);
 77+ }
7878
79 - function formHTML($form_def, $form_submitted, $source_is_page, $existing_page_content = null, $page_title = null, $page_name_formula = null) {
80 - global $wgRequest, $wgUser, $wgParser, $wgScriptPath;
81 - global $sfgTabIndex; // used to represent the current tab index in the form
82 - global $sfgFieldNum; // used for setting various HTML IDs
83 - global $sfgJSValidationCalls; // array of Javascript calls to determine if page can be saved
 79+ function formHTML($form_def, $form_submitted, $source_is_page, $existing_page_content = null, $page_title = null, $page_name_formula = null) {
 80+ global $wgRequest, $wgUser, $wgParser, $wgScriptPath;
 81+ global $sfgTabIndex; // used to represent the current tab index in the form
 82+ global $sfgFieldNum; // used for setting various HTML IDs
 83+ global $sfgJSValidationCalls; // array of Javascript calls to determine if page can be saved
8484
85 - // initialize some variables
86 - $sfgTabIndex = 1;
87 - $sfgFieldNum = 1;
88 - $source_page_matches_this_form = false;
89 - $form_page_title = NULL;
90 - $generated_page_name = $page_name_formula;
91 - // $form_is_partial is true if:
92 - // (a) 'partial' == 1 in the arguments
93 - // (b) 'partial form' is found in the form definition
94 - // in the latter case, it may remain false until close to the end of
95 - // the parsing, so we have to assume that it will become a possibility
96 - $form_is_partial = false;
97 - $new_text = "";
98 -
99 - // if we have existing content and we're not in an active replacement
100 - // situation, preserve the original content. We do this because we want
101 - // to pass the original content on IF this is a partial form
102 - // TODO: A better approach here would be to pass the revision id of the
103 - // existing page content through the replace value, which would
104 - // minimize the html traffic and would allow us to do a concurrent
105 - // update check. For now, we pass it through the hidden text field...
 85+ // initialize some variables
 86+ $sfgTabIndex = 1;
 87+ $sfgFieldNum = 1;
 88+ $source_page_matches_this_form = false;
 89+ $form_page_title = NULL;
 90+ $generated_page_name = $page_name_formula;
 91+ // $form_is_partial is true if:
 92+ // (a) 'partial' == 1 in the arguments
 93+ // (b) 'partial form' is found in the form definition
 94+ // in the latter case, it may remain false until close to the end of
 95+ // the parsing, so we have to assume that it will become a possibility
 96+ $form_is_partial = false;
 97+ $new_text = "";
 98+
 99+ // if we have existing content and we're not in an active replacement
 100+ // situation, preserve the original content. We do this because we want
 101+ // to pass the original content on IF this is a partial form
 102+ // TODO: A better approach here would be to pass the revision id of the
 103+ // existing page content through the replace value, which would
 104+ // minimize the html traffic and would allow us to do a concurrent
 105+ // update check. For now, we pass it through the hidden text field...
106106
107 - if (! $wgRequest->getCheck('partial')) {
108 - $original_page_content = $existing_page_content;
109 - } else {
110 - $original_page_content = null;
111 - if($wgRequest->getCheck('free_text')) {
112 - $existing_page_content= $wgRequest->getVal('free_text');
113 - $form_is_partial = true;
114 - }
115 - }
 107+ if (! $wgRequest->getCheck('partial')) {
 108+ $original_page_content = $existing_page_content;
 109+ } else {
 110+ $original_page_content = null;
 111+ if($wgRequest->getCheck('free_text')) {
 112+ $existing_page_content= $wgRequest->getVal('free_text');
 113+ $form_is_partial = true;
 114+ }
 115+ }
116116
117 - // disable all form elements if user doesn't have edit permission -
118 - // two different checks are needed, because editing permissions can be
119 - // set in different ways
120 - // HACK - sometimes we don't know the page name in advance, but we still
121 - // need to set a title here for testing permissions
122 - if ($page_title == '')
123 - $this->mPageTitle = Title::newFromText("Semantic Forms permissions test");
124 - else
125 - $this->mPageTitle = Title::newFromText($page_title);
126 - if ($wgUser->isAllowed('edit') && $this->mPageTitle->userCanEdit()) {
127 - $form_is_disabled = false;
128 - $form_text = "";
129 - // show "Your IP address will be recorded" warning if user is
130 - // anonymous - wikitext for bolding has to be replaced with HTML
131 - if ($wgUser->isAnon()) {
132 - $anon_edit_warning = preg_replace("/'''(.*)'''/", "<strong>$1</strong>", wfMsg('anoneditwarning'));
133 - $form_text .= "<p>$anon_edit_warning</p>\n";
134 - }
135 - } else {
136 - $form_is_disabled = true;
137 - // display a message to the user explaining why they can't edit the
138 - // page - borrowed heavily from EditPage.php
139 - if ( $wgUser->isAnon() ) {
140 - $skin = $wgUser->getSkin();
141 - $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
142 - $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ) );
143 - $form_text = wfMsgWikiHtml( 'whitelistedittext', $loginLink );
144 - } else {
145 - $form_text = wfMsg( 'protectedpagetext' );
146 - }
147 - }
148 - $javascript_text = "";
149 - $sfgJSValidationCalls = array();
150 - $fields_javascript_text = "";
 117+ // disable all form elements if user doesn't have edit permission -
 118+ // two different checks are needed, because editing permissions can be
 119+ // set in different ways
 120+ // HACK - sometimes we don't know the page name in advance, but we still
 121+ // need to set a title here for testing permissions
 122+ if ($page_title == '')
 123+ $this->mPageTitle = Title::newFromText("Semantic Forms permissions test");
 124+ else
 125+ $this->mPageTitle = Title::newFromText($page_title);
 126+ if ($wgUser->isAllowed('edit') && $this->mPageTitle->userCanEdit()) {
 127+ $form_is_disabled = false;
 128+ $form_text = "";
 129+ // show "Your IP address will be recorded" warning if user is
 130+ // anonymous - wikitext for bolding has to be replaced with HTML
 131+ if ($wgUser->isAnon()) {
 132+ $anon_edit_warning = preg_replace("/'''(.*)'''/", "<strong>$1</strong>", wfMsg('anoneditwarning'));
 133+ $form_text .= "<p>$anon_edit_warning</p>\n";
 134+ }
 135+ } else {
 136+ $form_is_disabled = true;
 137+ // display a message to the user explaining why they can't edit the
 138+ // page - borrowed heavily from EditPage.php
 139+ if ( $wgUser->isAnon() ) {
 140+ $skin = $wgUser->getSkin();
 141+ $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
 142+ $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ) );
 143+ $form_text = wfMsgWikiHtml( 'whitelistedittext', $loginLink );
 144+ } else {
 145+ $form_text = wfMsg( 'protectedpagetext' );
 146+ }
 147+ }
 148+ $javascript_text = "";
 149+ $sfgJSValidationCalls = array();
 150+ $fields_javascript_text = "";
151151
152 - // Remove <noinclude> sections and <includeonly> tags from form definition
153 - $form_def = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $form_def);
154 - $form_def = strtr($form_def, array('<includeonly>' => '', '</includeonly>' => ''));
 152+ // Remove <noinclude> sections and <includeonly> tags from form definition
 153+ $form_def = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $form_def);
 154+ $form_def = strtr($form_def, array('<includeonly>' => '', '</includeonly>' => ''));
155155
156 - // parse wiki-text
157 - // add '<nowiki>' tags around every triple-bracketed form definition
158 - // element, so that the wiki parser won't touch it - the parser will
159 - // remove the '<nowiki>' tags, leaving us with what we need
160 - global $sfgDisableWikiTextParsing;
161 - if (! $sfgDisableWikiTextParsing) {
162 - $form_def = strtr($form_def, array('{{{' => '<nowiki>{{{', '}}}' => '}}}</nowiki>'));
163 - $wgParser->mOptions = new ParserOptions();
164 - $wgParser->mOptions->initialiseFromUser($wgUser);
165 - $form_def = $wgParser->parse($form_def, $this->mPageTitle, $wgParser->mOptions)->getText();
166 - }
 156+ // parse wiki-text
 157+ // add '<nowiki>' tags around every triple-bracketed form definition
 158+ // element, so that the wiki parser won't touch it - the parser will
 159+ // remove the '<nowiki>' tags, leaving us with what we need
 160+ global $sfgDisableWikiTextParsing;
 161+ if (! $sfgDisableWikiTextParsing) {
 162+ $form_def = strtr($form_def, array('{{{' => '<nowiki>{{{', '}}}' => '}}}</nowiki>'));
 163+ $wgParser->mOptions = new ParserOptions();
 164+ $wgParser->mOptions->initialiseFromUser($wgUser);
 165+ $form_def = $wgParser->parse($form_def, $this->mPageTitle, $wgParser->mOptions)->getText();
 166+ }
167167
168 - // turn form definition file into an array of sections, one for each
169 - // template definition (plus the first section)
170 - $form_def_sections = array();
171 - $start_position = 0;
172 - $section_start = 0;
173 - $free_text_was_included = false;
174 - $free_text_preload_page = null;
175 - $all_values_for_template = array();
176 - while ($brackets_loc = strpos($form_def, "{{{", $start_position)) {
177 - $brackets_end_loc = strpos($form_def, "}}}", $brackets_loc);
178 - $bracketed_string = substr($form_def, $brackets_loc + 3, $brackets_end_loc - ($brackets_loc + 3));
179 - $tag_components = explode('|', $bracketed_string);
180 - $tag_title = trim($tag_components[0]);
181 - if ($tag_title == 'for template' || $tag_title == 'end template') {
182 - // create a section for everything up to here
183 - $section = substr($form_def, $section_start, $brackets_loc - $section_start);
184 - $form_def_sections[] = $section;
185 - $section_start = $brackets_loc;
186 - }
187 - $start_position = $brackets_loc + 1;
188 - } // end while
189 - $form_def_sections[] = trim(substr($form_def, $section_start));
 168+ // turn form definition file into an array of sections, one for each
 169+ // template definition (plus the first section)
 170+ $form_def_sections = array();
 171+ $start_position = 0;
 172+ $section_start = 0;
 173+ $free_text_was_included = false;
 174+ $free_text_preload_page = null;
 175+ $all_values_for_template = array();
 176+ while ($brackets_loc = strpos($form_def, "{{{", $start_position)) {
 177+ $brackets_end_loc = strpos($form_def, "}}}", $brackets_loc);
 178+ $bracketed_string = substr($form_def, $brackets_loc + 3, $brackets_end_loc - ($brackets_loc + 3));
 179+ $tag_components = explode('|', $bracketed_string);
 180+ $tag_title = trim($tag_components[0]);
 181+ if ($tag_title == 'for template' || $tag_title == 'end template') {
 182+ // create a section for everything up to here
 183+ $section = substr($form_def, $section_start, $brackets_loc - $section_start);
 184+ $form_def_sections[] = $section;
 185+ $section_start = $brackets_loc;
 186+ }
 187+ $start_position = $brackets_loc + 1;
 188+ } // end while
 189+ $form_def_sections[] = trim(substr($form_def, $section_start));
190190
191 - // cycle through form definition file (and possibly an existing article
192 - // as well), finding template and field declarations and replacing them
193 - // with form elements, either blank or pre-populated, as appropriate
194 - $all_fields = array();
195 - $data_text = "";
196 - $template_name = "";
197 - $allow_multiple = false;
198 - $instance_num = 0;
199 - $all_instances_printed = false;
200 - $strict_parsing = false;
201 - // initialize list of choosers (dropdowns with available templates)
202 - $choosers = array();
203 - for ($section_num = 0; $section_num < count($form_def_sections); $section_num++) {
204 - $tif = new SFTemplateInForm();
205 - $start_position = 0;
206 - $template_text = "";
207 - // the append is there to ensure that the original array doesn't get
208 - // modified; is it necessary?
209 - $section = " " . $form_def_sections[$section_num];
 191+ // cycle through form definition file (and possibly an existing article
 192+ // as well), finding template and field declarations and replacing them
 193+ // with form elements, either blank or pre-populated, as appropriate
 194+ $all_fields = array();
 195+ $data_text = "";
 196+ $template_name = "";
 197+ $allow_multiple = false;
 198+ $instance_num = 0;
 199+ $all_instances_printed = false;
 200+ $strict_parsing = false;
 201+ // initialize list of choosers (dropdowns with available templates)
 202+ $choosers = array();
 203+ for ($section_num = 0; $section_num < count($form_def_sections); $section_num++) {
 204+ $tif = new SFTemplateInForm();
 205+ $start_position = 0;
 206+ $template_text = "";
 207+ // the append is there to ensure that the original array doesn't get
 208+ // modified; is it necessary?
 209+ $section = " " . $form_def_sections[$section_num];
210210
211 - while ($brackets_loc = strpos($section, '{{{', $start_position)) {
212 - $brackets_end_loc = strpos($section, "}}}", $brackets_loc);
213 - $bracketed_string = substr($section, $brackets_loc + 3, $brackets_end_loc - ($brackets_loc + 3));
214 - $tag_components = explode('|', $bracketed_string);
215 - $tag_title = trim($tag_components[0]);
216 - // =====================================================
217 - // for template processing
218 - // =====================================================
219 - if ($tag_title == 'for template') {
220 - $old_template_name = $template_name;
221 - $template_name = trim($tag_components[1]);
222 - $tif->template_name = $template_name;
223 - $query_template_name = str_replace(' ', '_', $template_name);
224 - // also replace periods with underlines, since that's what
225 - // POST does to strings anyway
226 - $query_template_name = str_replace('.', '_', $query_template_name);
227 - $chooser_name = false;
228 - $chooser_caption = false;
229 - // cycle through the other components
230 - for ($i = 2; $i < count($tag_components); $i++) {
231 - $component = $tag_components[$i];
232 - if ($component == 'multiple') $allow_multiple = true;
233 - if ($component == 'strict') $strict_parsing = true;
234 - $sub_components = explode('=', $component);
235 - if (count($sub_components) == 2) {
236 - if ($sub_components[0] == 'label') {
237 - $template_label = $sub_components[1];
238 - }
239 - if ($sub_components[0] == 'chooser') {
240 - $allow_multiple = true;
241 - $chooser_name = $sub_components[1];
242 - }
243 - if ($sub_components[0] == 'chooser caption') {
244 - $chooser_caption = $sub_components[1];
245 - }
246 - }
247 - }
248 - // if this is the first instance, add the label in the form
249 - if (($old_template_name != $template_name) && isset($template_label)) {
250 - // add a placeholder to the form text so the fieldset can be
251 - // hidden if chooser support demands it
252 - if ($chooser_name !== false)
253 - $form_text .= "<fieldset [[placeholder]] haschooser=true>\n";
254 - else
255 - $form_text .= "<fieldset>\n";
256 - $form_text .= "<legend>$template_label</legend>\n";
257 - }
258 - $template_text .= "{{" . $tif->template_name;
259 - $all_fields = $tif->getAllFields();
260 - // remove template tag
261 - $section = substr_replace($section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
262 - $template_instance_query_values = $wgRequest->getArray($query_template_name);
263 - // if we are editing a page, and this template can be found more than
264 - // once in that page, and multiple values are allowed, repeat this
265 - // section
266 - $existing_template_text = null;
267 - // special template string for preg_match calls - includes a
268 - // regular expression, to allow matching of either spaces or
269 - // underlines in name
270 - $search_template_str = str_replace('/', '\/', $tif->template_name);
271 - $search_template_str = preg_replace('/[_| ]/', '[_| ]', $search_template_str);
272 - if ($source_is_page || $form_is_partial) {
273 - $matches = array();
274 - if ($allow_multiple) {
275 - // find the number of instances of this template in the page -
276 - // if it's more than one, re-parse this section of the
277 - // definition form for the subsequent template instances in
278 - // this page; if there's none, don't include fields at all.
279 - // there has to be a more efficient way to handle multiple
280 - // instances of templates, one that doesn't involve re-parsing
281 - // the same tags, but I don't know what it is.
282 - if (preg_match_all('/\{\{' . $search_template_str . '\s*(?:(?:([\||:].*?)\}\})|()\}\})/mis', $existing_page_content, $matches)) {
283 - $instance_num++;
284 - } else {
285 - $all_instances_printed = true;
286 - }
287 - }
288 - // get the first instance of this template on the page being edited,
289 - // even if there are more
290 - if (preg_match('/\{\{' . $search_template_str . '\s*(?:(?:([\||:].*?)\}\})|()\}\})/mis', $existing_page_content, $matches)) {
291 - $existing_template_text = trim($matches[1]);
292 - $template_contents = array();
293 - // cycle through template call, splitting it up by pipes ('|'),
294 - // except when that pipe is part of a piped link
295 - $field = "";
296 - $uncompleted_square_brackets = 0;
297 - for ($i = 0; $i < strlen($existing_template_text); $i++) {
298 - $c = $existing_template_text[$i];
299 - if (($i == strlen($existing_template_text) - 1) ||
300 - ($c == '|' && $uncompleted_square_brackets == 0)) {
301 - // if this was the last character in the template, append
302 - // this character
303 - if ($i == strlen($existing_template_text) - 1 &&
304 - $c != '|') {
305 - $field .= $c;
306 - }
307 - // either there's an equals sign near the beginning or not -
308 - // handling is similar in either way; if there's no equals
309 - // sign, the index of this field becomes the key
310 - $sub_fields = explode('=', $field, 2);
311 - if (count($sub_fields) > 1) {
312 - $template_contents[trim($sub_fields[0])] = trim($sub_fields[1]);
313 - } else {
314 - $template_contents[] = trim($sub_fields[0]);
315 - }
316 - $field = '';
317 - } else {
318 - $field .= $c;
319 - if ($c == '[') {
320 - $uncompleted_square_brackets++;
321 - } elseif ($c == ']' && $uncompleted_square_brackets > 0) {
322 - $uncompleted_square_brackets--;
323 - }
324 - }
325 - }
326 - // now remove this template from the text being edited
327 - // if this is a partial form, establish a new insertion point
328 - if ($existing_page_content && $form_is_partial && $wgRequest->getCheck('partial')) {
329 - // if something already exists, set the new insertion point
330 - // to its position; otherwise just let it lie
331 - if (strpos($existing_page_content, $matches[0]) !== false) {
332 - $existing_page_content = str_replace('{{{insertionpoint}}}', '', $existing_page_content);
333 - $existing_page_content = str_replace($matches[0], '{{{insertionpoint}}}', $existing_page_content);
334 - }
335 - } else {
336 - $existing_page_content = str_replace($matches[0], '', $existing_page_content);
337 - }
338 - // if this is not a multiple-instance template, and we've found
339 - // a match in the source page, there's a good chance that this
340 - // page was created with this form - note that, so we don't
341 - // send the user a warning
342 - // (multiple-instance templates have a greater chance of
343 - // getting repeated from one form to the next)
344 - if (! $allow_multiple) {
345 - $source_page_matches_this_form = true;
346 - }
347 - }
348 - }
349 - // if the input is from the form (meaning the user has hit one
350 - // of the bottom row of buttons), and we're dealing with a
351 - // multiple template, get the values for this instance of this
352 - // template, then delete them from the array, so we can get the
353 - // next group next time - the next() command for arrays doesn't
354 - // seem to work here
355 - if ((! $source_is_page) && $allow_multiple && $wgRequest) {
356 - $all_instances_printed = true;
357 - if ($old_template_name != $template_name) {
358 - $all_values_for_template = $wgRequest->getArray($query_template_name);
359 - }
360 - if ($all_values_for_template) {
361 - $cur_key = key($all_values_for_template);
362 - // skip the input coming in from the "starter" div
363 - if ($cur_key == 'num') {
364 - unset($all_values_for_template[$cur_key]);
365 - $cur_key = key($all_values_for_template);
366 - }
367 - if ($template_instance_query_values = current($all_values_for_template)) {
368 - $all_instances_printed = false;
369 - unset($all_values_for_template[$cur_key]);
370 - }
371 - }
372 - }
373 - // =====================================================
374 - // end template processing
375 - // =====================================================
376 - } elseif ($tag_title == 'end template') {
377 - // remove this tag, reset some variables, and close off form HTML tag
378 - $section = substr_replace($section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
379 - $template_name = null;
380 - if (isset($template_label)) {
381 - $form_text .= "</fieldset>\n";
382 - unset ($template_label);
383 - }
384 - $allow_multiple = false;
385 - $all_instances_printed = false;
386 - $instance_num = 0;
387 - // if the hiding placeholder is still around, this fieldset should
388 - // be hidden because it is empty and choosers are being used. So,
389 - // hide it.
390 - $form_text = str_replace("[[placeholder]]", "style='display:none'", $form_text);
391 - // =====================================================
392 - // field processing
393 - // =====================================================
394 - } elseif ($tag_title == 'field') {
395 - $field_name = trim($tag_components[1]);
396 - // cycle through the other components
397 - $is_mandatory = false;
398 - $is_hidden = false;
399 - $is_restricted = false;
400 - $is_uploadable = false;
401 - $is_list = false;
402 - $input_type = null;
403 - $field_args = array();
404 - $default_value = "";
405 - $possible_values = null;
406 - $preload_page = null;
407 - for ($i = 2; $i < count($tag_components); $i++) {
408 - $component = trim($tag_components[$i]);
409 - if ($component == 'mandatory') {
410 - $is_mandatory = true;
411 - } elseif ($component == 'hidden') {
412 - $is_hidden = true;
413 - } elseif ($component == 'restricted') {
414 - $is_restricted = true;
415 - } elseif ($component == 'uploadable') {
416 - $field_args['is_uploadable'] = true;
417 - } elseif ($component == 'list') {
418 - $is_list = true;
419 - } elseif ($component == 'autocomplete') {
420 - $field_args['autocomplete'] = true;
421 - } elseif ($component == 'no autocomplete') {
422 - $field_args['no autocomplete'] = true;
423 - } elseif ($component == 'remote autocompletion') {
424 - $field_args['remote_autocompletion'] = true;
425 - } else {
426 - $sub_components = explode('=', $component);
427 - if (count($sub_components) == 2) {
428 - if ($sub_components[0] == 'input type') {
429 - $input_type = $sub_components[1];
430 - } elseif ($sub_components[0] == 'default') {
431 - $default_value = $sub_components[1];
432 - } elseif ($sub_components[0] == 'preload') {
433 - // free text field has special handling
434 - if ($field_name == 'free text') {
435 - $free_text_preload_page = $sub_components[1];
436 - } else {
437 - $preload_page = $sub_components[1];
438 - }
439 - } elseif ($sub_components[0] == 'values') {
440 - $possible_values = explode(',', $sub_components[1]);
441 - } else {
442 - $field_args[$sub_components[0]] = $sub_components[1];
443 - }
444 - // for backwards compatibility
445 - if ($sub_components[0] == 'autocomplete on' && $sub_components[1] == null) {
446 - $field_args['no autocomplete'] = true;
447 - }
448 - }
449 - }
450 - }
451 - $field_args['part_of_multiple'] = $allow_multiple;
452 - // get the value from the request, if it's there, and if it's not
453 - // an array
454 - if (isset($template_instance_query_values) &&
455 - $template_instance_query_values != null &&
456 - array_key_exists($field_name, $template_instance_query_values)) {
457 - $field_query_val = $template_instance_query_values[$field_name];
458 - if ($form_submitted || ($field_query_val && ! is_array($field_query_val))) {
459 - $cur_value = $field_query_val;
460 - }
461 - } else
462 - $cur_value = '';
463 - if ($cur_value && ! is_array($cur_value)) {
464 - $cur_value = Sanitizer::safeEncodeAttribute($cur_value);
465 - // ampersands don't need to be escaped - undo their encoding
466 - $cur_value = str_replace('&amp;', '&', $cur_value);
467 - }
 211+ while ($brackets_loc = strpos($section, '{{{', $start_position)) {
 212+ $brackets_end_loc = strpos($section, "}}}", $brackets_loc);
 213+ $bracketed_string = substr($section, $brackets_loc + 3, $brackets_end_loc - ($brackets_loc + 3));
 214+ $tag_components = explode('|', $bracketed_string);
 215+ $tag_title = trim($tag_components[0]);
 216+ // =====================================================
 217+ // for template processing
 218+ // =====================================================
 219+ if ($tag_title == 'for template') {
 220+ $old_template_name = $template_name;
 221+ $template_name = trim($tag_components[1]);
 222+ $tif->template_name = $template_name;
 223+ $query_template_name = str_replace(' ', '_', $template_name);
 224+ // also replace periods with underlines, since that's what
 225+ // POST does to strings anyway
 226+ $query_template_name = str_replace('.', '_', $query_template_name);
 227+ $chooser_name = false;
 228+ $chooser_caption = false;
 229+ // cycle through the other components
 230+ for ($i = 2; $i < count($tag_components); $i++) {
 231+ $component = $tag_components[$i];
 232+ if ($component == 'multiple') $allow_multiple = true;
 233+ if ($component == 'strict') $strict_parsing = true;
 234+ $sub_components = explode('=', $component);
 235+ if (count($sub_components) == 2) {
 236+ if ($sub_components[0] == 'label') {
 237+ $template_label = $sub_components[1];
 238+ }
 239+ if ($sub_components[0] == 'chooser') {
 240+ $allow_multiple = true;
 241+ $chooser_name = $sub_components[1];
 242+ }
 243+ if ($sub_components[0] == 'chooser caption') {
 244+ $chooser_caption = $sub_components[1];
 245+ }
 246+ }
 247+ }
 248+ // if this is the first instance, add the label in the form
 249+ if (($old_template_name != $template_name) && isset($template_label)) {
 250+ // add a placeholder to the form text so the fieldset can be
 251+ // hidden if chooser support demands it
 252+ if ($chooser_name !== false)
 253+ $form_text .= "<fieldset [[placeholder]] haschooser=true>\n";
 254+ else
 255+ $form_text .= "<fieldset>\n";
 256+ $form_text .= "<legend>$template_label</legend>\n";
 257+ }
 258+ $template_text .= "{{" . $tif->template_name;
 259+ $all_fields = $tif->getAllFields();
 260+ // remove template tag
 261+ $section = substr_replace($section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
 262+ $template_instance_query_values = $wgRequest->getArray($query_template_name);
 263+ // if we are editing a page, and this template can be found more than
 264+ // once in that page, and multiple values are allowed, repeat this
 265+ // section
 266+ $existing_template_text = null;
 267+ // special template string for preg_match calls - includes a
 268+ // regular expression, to allow matching of either spaces or
 269+ // underlines in name
 270+ $search_template_str = str_replace('/', '\/', $tif->template_name);
 271+ $search_template_str = preg_replace('/[_| ]/', '[_| ]', $search_template_str);
 272+ if ($source_is_page || $form_is_partial) {
 273+ $matches = array();
 274+ if ($allow_multiple) {
 275+ // find the number of instances of this template in the page -
 276+ // if it's more than one, re-parse this section of the
 277+ // definition form for the subsequent template instances in
 278+ // this page; if there's none, don't include fields at all.
 279+ // there has to be a more efficient way to handle multiple
 280+ // instances of templates, one that doesn't involve re-parsing
 281+ // the same tags, but I don't know what it is.
 282+ if (preg_match_all('/\{\{' . $search_template_str . '\s*(?:(?:([\||:].*?)\}\})|()\}\})/mis', $existing_page_content, $matches)) {
 283+ $instance_num++;
 284+ } else {
 285+ $all_instances_printed = true;
 286+ }
 287+ }
 288+ // get the first instance of this template on the page being edited,
 289+ // even if there are more
 290+ if (preg_match('/\{\{' . $search_template_str . '\s*(?:(?:([\||:].*?)\}\})|()\}\})/mis', $existing_page_content, $matches)) {
 291+ $existing_template_text = trim($matches[1]);
 292+ $template_contents = array();
 293+ // cycle through template call, splitting it up by pipes ('|'),
 294+ // except when that pipe is part of a piped link
 295+ $field = "";
 296+ $uncompleted_square_brackets = 0;
 297+ for ($i = 0; $i < strlen($existing_template_text); $i++) {
 298+ $c = $existing_template_text[$i];
 299+ if (($i == strlen($existing_template_text) - 1) ||
 300+ ($c == '|' && $uncompleted_square_brackets == 0)) {
 301+ // if this was the last character in the template, append
 302+ // this character
 303+ if ($i == strlen($existing_template_text) - 1 &&
 304+ $c != '|') {
 305+ $field .= $c;
 306+ }
 307+ // either there's an equals sign near the beginning or not -
 308+ // handling is similar in either way; if there's no equals
 309+ // sign, the index of this field becomes the key
 310+ $sub_fields = explode('=', $field, 2);
 311+ if (count($sub_fields) > 1) {
 312+ $template_contents[trim($sub_fields[0])] = trim($sub_fields[1]);
 313+ } else {
 314+ $template_contents[] = trim($sub_fields[0]);
 315+ }
 316+ $field = '';
 317+ } else {
 318+ $field .= $c;
 319+ if ($c == '[') {
 320+ $uncompleted_square_brackets++;
 321+ } elseif ($c == ']' && $uncompleted_square_brackets > 0) {
 322+ $uncompleted_square_brackets--;
 323+ }
 324+ }
 325+ }
 326+ // now remove this template from the text being edited
 327+ // if this is a partial form, establish a new insertion point
 328+ if ($existing_page_content && $form_is_partial && $wgRequest->getCheck('partial')) {
 329+ // if something already exists, set the new insertion point
 330+ // to its position; otherwise just let it lie
 331+ if (strpos($existing_page_content, $matches[0]) !== false) {
 332+ $existing_page_content = str_replace('{{{insertionpoint}}}', '', $existing_page_content);
 333+ $existing_page_content = str_replace($matches[0], '{{{insertionpoint}}}', $existing_page_content);
 334+ }
 335+ } else {
 336+ $existing_page_content = str_replace($matches[0], '', $existing_page_content);
 337+ }
 338+ // if this is not a multiple-instance template, and we've found
 339+ // a match in the source page, there's a good chance that this
 340+ // page was created with this form - note that, so we don't
 341+ // send the user a warning
 342+ // (multiple-instance templates have a greater chance of
 343+ // getting repeated from one form to the next)
 344+ if (! $allow_multiple) {
 345+ $source_page_matches_this_form = true;
 346+ }
 347+ }
 348+ }
 349+ // if the input is from the form (meaning the user has hit one
 350+ // of the bottom row of buttons), and we're dealing with a
 351+ // multiple template, get the values for this instance of this
 352+ // template, then delete them from the array, so we can get the
 353+ // next group next time - the next() command for arrays doesn't
 354+ // seem to work here
 355+ if ((! $source_is_page) && $allow_multiple && $wgRequest) {
 356+ $all_instances_printed = true;
 357+ if ($old_template_name != $template_name) {
 358+ $all_values_for_template = $wgRequest->getArray($query_template_name);
 359+ }
 360+ if ($all_values_for_template) {
 361+ $cur_key = key($all_values_for_template);
 362+ // skip the input coming in from the "starter" div
 363+ if ($cur_key == 'num') {
 364+ unset($all_values_for_template[$cur_key]);
 365+ $cur_key = key($all_values_for_template);
 366+ }
 367+ if ($template_instance_query_values = current($all_values_for_template)) {
 368+ $all_instances_printed = false;
 369+ unset($all_values_for_template[$cur_key]);
 370+ }
 371+ }
 372+ }
 373+ // =====================================================
 374+ // end template processing
 375+ // =====================================================
 376+ } elseif ($tag_title == 'end template') {
 377+ // remove this tag, reset some variables, and close off form HTML tag
 378+ $section = substr_replace($section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
 379+ $template_name = null;
 380+ if (isset($template_label)) {
 381+ $form_text .= "</fieldset>\n";
 382+ unset ($template_label);
 383+ }
 384+ $allow_multiple = false;
 385+ $all_instances_printed = false;
 386+ $instance_num = 0;
 387+ // if the hiding placeholder is still around, this fieldset should
 388+ // be hidden because it is empty and choosers are being used. So,
 389+ // hide it.
 390+ $form_text = str_replace("[[placeholder]]", "style='display:none'", $form_text);
 391+ // =====================================================
 392+ // field processing
 393+ // =====================================================
 394+ } elseif ($tag_title == 'field') {
 395+ $field_name = trim($tag_components[1]);
 396+ // cycle through the other components
 397+ $is_mandatory = false;
 398+ $is_hidden = false;
 399+ $is_restricted = false;
 400+ $is_uploadable = false;
 401+ $is_list = false;
 402+ $input_type = null;
 403+ $field_args = array();
 404+ $default_value = "";
 405+ $possible_values = null;
 406+ $preload_page = null;
 407+ for ($i = 2; $i < count($tag_components); $i++) {
 408+ $component = trim($tag_components[$i]);
 409+ if ($component == 'mandatory') {
 410+ $is_mandatory = true;
 411+ } elseif ($component == 'hidden') {
 412+ $is_hidden = true;
 413+ } elseif ($component == 'restricted') {
 414+ $is_restricted = true;
 415+ } elseif ($component == 'uploadable') {
 416+ $field_args['is_uploadable'] = true;
 417+ } elseif ($component == 'list') {
 418+ $is_list = true;
 419+ } elseif ($component == 'autocomplete') {
 420+ $field_args['autocomplete'] = true;
 421+ } elseif ($component == 'no autocomplete') {
 422+ $field_args['no autocomplete'] = true;
 423+ } elseif ($component == 'remote autocompletion') {
 424+ $field_args['remote_autocompletion'] = true;
 425+ } else {
 426+ $sub_components = explode('=', $component);
 427+ if (count($sub_components) == 2) {
 428+ if ($sub_components[0] == 'input type') {
 429+ $input_type = $sub_components[1];
 430+ } elseif ($sub_components[0] == 'default') {
 431+ $default_value = $sub_components[1];
 432+ } elseif ($sub_components[0] == 'preload') {
 433+ // free text field has special handling
 434+ if ($field_name == 'free text') {
 435+ $free_text_preload_page = $sub_components[1];
 436+ } else {
 437+ $preload_page = $sub_components[1];
 438+ }
 439+ } elseif ($sub_components[0] == 'values') {
 440+ $possible_values = explode(',', $sub_components[1]);
 441+ } else {
 442+ $field_args[$sub_components[0]] = $sub_components[1];
 443+ }
 444+ // for backwards compatibility
 445+ if ($sub_components[0] == 'autocomplete on' && $sub_components[1] == null) {
 446+ $field_args['no autocomplete'] = true;
 447+ }
 448+ }
 449+ }
 450+ }
 451+ $field_args['part_of_multiple'] = $allow_multiple;
 452+ // get the value from the request, if it's there, and if it's not
 453+ // an array
 454+ if (isset($template_instance_query_values) &&
 455+ $template_instance_query_values != null &&
 456+ array_key_exists($field_name, $template_instance_query_values)) {
 457+ $field_query_val = $template_instance_query_values[$field_name];
 458+ if ($form_submitted || ($field_query_val && ! is_array($field_query_val))) {
 459+ $cur_value = $field_query_val;
 460+ }
 461+ } else
 462+ $cur_value = '';
 463+ if ($cur_value && ! is_array($cur_value)) {
 464+ $cur_value = Sanitizer::safeEncodeAttribute($cur_value);
 465+ // ampersands don't need to be escaped - undo their encoding
 466+ $cur_value = str_replace('&amp;', '&', $cur_value);
 467+ }
468468
469 - if ($cur_value == null) {
470 - // set to default value specified in the form, if it's there
471 - $cur_value = $default_value;
472 - }
 469+ if ($cur_value == null) {
 470+ // set to default value specified in the form, if it's there
 471+ $cur_value = $default_value;
 472+ }
473473
474 - // if the user is starting to edit a page, and that page contains
475 - // the current template being processed, get the current template
476 - // field's value in the existing page
477 - if ($source_is_page && (! empty($existing_template_text))) {
478 - if (isset($template_contents[$field_name])) {
479 - $cur_value = $template_contents[$field_name];
480 - } else
481 - $cur_value = '';
482 - if ($cur_value) {
483 - $cur_value = Sanitizer::safeEncodeAttribute($cur_value);
484 - // ampersands don't need to be escaped - undo their encoding
485 - $cur_value = str_replace('&amp;', '&', $cur_value);
486 - }
487 - }
 474+ // if the user is starting to edit a page, and that page contains
 475+ // the current template being processed, get the current template
 476+ // field's value in the existing page
 477+ if ($source_is_page && (! empty($existing_template_text))) {
 478+ if (isset($template_contents[$field_name])) {
 479+ $cur_value = $template_contents[$field_name];
 480+ } else
 481+ $cur_value = '';
 482+ if ($cur_value) {
 483+ $cur_value = Sanitizer::safeEncodeAttribute($cur_value);
 484+ // ampersands don't need to be escaped - undo their encoding
 485+ $cur_value = str_replace('&amp;', '&', $cur_value);
 486+ }
 487+ }
488488
489 - // handle non-template fields - 'page title' and 'free text'
490 - if ($template_name == '') {
491 - if ($field_name == 'page title') {
492 - // the actual value should be non-null - stick it in
493 - $new_text = $page_title;
494 - } elseif ($field_name == 'free text') {
495 - // add placeholders for the free text in both the form and
496 - // the page, using <free_text> tags - once all the free text
497 - // is known (at the end), it will get substituted in
498 - if ($is_hidden) {
499 - $new_text = $this->hiddenFieldHTML('free_text', '<free_text>');
500 - } else {
501 - if (! array_key_exists('rows', $field_args))
502 - $field_args['rows'] = 5;
503 - if (! array_key_exists('cols', $field_args))
504 - $field_args['cols'] = 80;
505 - $sfgTabIndex++;
506 - $sfgFieldNum++;
507 - list($new_text, $new_javascript_text) = SFFormInputs::textAreaHTML('<free_text>', 'free_text', false, ($form_is_disabled || $is_restricted), $field_args);
508 - }
509 - $free_text_was_included = true;
510 - // add a similar placeholder to the data text
511 - $data_text .= "<free_text>\n";
512 - }
513 - $section = substr_replace($section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
514 - } else { // this field is part of a template
515 - if (is_array($cur_value)) {
516 - // first, check if it's a list
517 - if (array_key_exists('is_list', $cur_value) &&
518 - $cur_value['is_list'] == true) {
519 - $cur_value_in_template = "";
520 - if (array_key_exists('delimiter', $field_args)) {
521 - $delimiter = $field_args['delimiter'];
522 - } else {
523 - $delimiter = ",";
524 - }
525 - foreach ($cur_value as $key => $val) {
526 - if ($key !== "is_list") {
527 - if ($cur_value_in_template != "") {
528 - $cur_value_in_template .= $delimiter . " ";
529 - }
530 - $cur_value_in_template .= $val;
531 - }
532 - }
533 - } else {
534 - // otherwise:
535 - // if it has 1 or 2 elements, assume it's a checkbox; if it has
536 - // 3 elements, assume it's a date
537 - // - this handling will have to get more complex if other
538 - // possibilities get added
539 - if (count($cur_value) == 1) {
540 - $words_for_false = explode(',', wfMsgForContent('smw_false_words'));
541 - // for each language, there's a series of words that are
542 - // equal to false - get the word in the series that matches
543 - // "no"; generally, that's the third word
544 - $index_of_no = 2;
545 - if (count($words_for_false) > $index_of_no) {
546 - $no = ucwords($words_for_false[$index_of_no]);
547 - } elseif (count($words_for_false) == 0) {
548 - $no = "0"; // some safe value if no words are found
549 - } else {
550 - $no = ucwords($words_for_false[0]);
551 - }
552 - $cur_value_in_template = $no;
553 - } elseif (count($cur_value) == 2) {
554 - $words_for_true = explode(',', wfMsgForContent('smw_true_words'));
555 - // get the value in the 'true' series that tends to be "yes",
556 - // and go with that one - generally, that's the third word
557 - $index_of_yes = 2;
558 - if (count($words_for_true) > $index_of_yes) {
559 - $yes = ucwords($words_for_true[$index_of_yes]);
560 - } elseif (count($words_for_true) == 0) {
561 - $yes = "1"; // some safe value if no words are found
562 - } else {
563 - $yes = ucwords($words_for_true[0]);
564 - }
565 - $cur_value_in_template = $yes;
566 - // if it's 3 or greater, assume it's a date or datetime
567 - } elseif (count($cur_value) >= 3) {
568 - $month = $cur_value['month'];
569 - $day = $cur_value['day'];
570 - if ($day != '') {
571 - global $wgAmericanDates;
572 - if ($wgAmericanDates == false) {
573 - // pad out day to always be two digits
574 - $day = str_pad($day, 2, "0", STR_PAD_LEFT);
575 - }
576 - }
577 - $year = $cur_value['year'];
578 - if (isset($cur_value['hour'])) $hour = $cur_value['hour'];
579 - if (isset($cur_value['minute'])) $minute = $cur_value['minute'];
580 - if (isset($cur_value['second'])) $second = $cur_value['second'];
581 - if (isset($cur_value['ampm24h'])) $ampm24h = $cur_value['ampm24h'];
582 - if (isset($cur_value['timezone'])) $timezone = $cur_value['timezone'];
583 - if ($month != '' && $day != '' && $year != '') {
584 - // special handling for American dates - otherwise, just
585 - // the standard year/month/day (where month is a number)
586 - global $wgAmericanDates;
587 - if ($wgAmericanDates == true) {
588 - $cur_value_in_template = "$month $day, $year";
589 - } else {
590 - $cur_value_in_template = "$year/$month/$day";
591 - }
592 - // include whatever time information we have
593 - if(isset($hour)) $cur_value_in_template .= " " . str_pad(intval(substr($hour,0,2)),2,'0',STR_PAD_LEFT) . ":" . str_pad(intval(substr($minute,0,2)),2,'0',STR_PAD_LEFT);
594 - if(isset($second)) $cur_value_in_template .= ":" . str_pad(intval(substr($second,0,2)),2,'0',STR_PAD_LEFT);
595 - if(isset($ampm24h)) $cur_value_in_template .= " $ampm24h";
596 - if(isset($timezone)) $cur_value_in_template .= " $timezone";
597 - } else {
598 - $cur_value_in_template = "";
599 - }
600 - }
601 - }
602 - } else { // value is not an array
603 - $cur_value_in_template = $cur_value;
604 - }
605 - if ($query_template_name == null || $query_template_name == '')
606 - $input_name = $field_name;
607 - elseif ($allow_multiple)
608 - // 'num' will get replaced by an actual index, either in PHP
609 - // or in Javascript, later on
610 - $input_name = $query_template_name . '[num][' . $field_name . ']';
611 - else
612 - $input_name = $query_template_name . '[' . $field_name . ']';
 489+ // handle non-template fields - 'page title' and 'free text'
 490+ if ($template_name == '') {
 491+ if ($field_name == 'page title') {
 492+ // the actual value should be non-null - stick it in
 493+ $new_text = $page_title;
 494+ } elseif ($field_name == 'free text') {
 495+ // add placeholders for the free text in both the form and
 496+ // the page, using <free_text> tags - once all the free text
 497+ // is known (at the end), it will get substituted in
 498+ if ($is_hidden) {
 499+ $new_text = $this->hiddenFieldHTML('free_text', '<free_text>');
 500+ } else {
 501+ if (! array_key_exists('rows', $field_args))
 502+ $field_args['rows'] = 5;
 503+ if (! array_key_exists('cols', $field_args))
 504+ $field_args['cols'] = 80;
 505+ $sfgTabIndex++;
 506+ $sfgFieldNum++;
 507+ list($new_text, $new_javascript_text) = SFFormInputs::textAreaHTML('<free_text>', 'free_text', false, ($form_is_disabled || $is_restricted), $field_args);
 508+ }
 509+ $free_text_was_included = true;
 510+ // add a similar placeholder to the data text
 511+ $data_text .= "<free_text>\n";
 512+ }
 513+ $section = substr_replace($section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
 514+ } else { // this field is part of a template
 515+ if (is_array($cur_value)) {
 516+ // first, check if it's a list
 517+ if (array_key_exists('is_list', $cur_value) &&
 518+ $cur_value['is_list'] == true) {
 519+ $cur_value_in_template = "";
 520+ if (array_key_exists('delimiter', $field_args)) {
 521+ $delimiter = $field_args['delimiter'];
 522+ } else {
 523+ $delimiter = ",";
 524+ }
 525+ foreach ($cur_value as $key => $val) {
 526+ if ($key !== "is_list") {
 527+ if ($cur_value_in_template != "") {
 528+ $cur_value_in_template .= $delimiter . " ";
 529+ }
 530+ $cur_value_in_template .= $val;
 531+ }
 532+ }
 533+ } else {
 534+ // otherwise:
 535+ // if it has 1 or 2 elements, assume it's a checkbox; if it has
 536+ // 3 elements, assume it's a date
 537+ // - this handling will have to get more complex if other
 538+ // possibilities get added
 539+ if (count($cur_value) == 1) {
 540+ $words_for_false = explode(',', wfMsgForContent('smw_false_words'));
 541+ // for each language, there's a series of words that are
 542+ // equal to false - get the word in the series that matches
 543+ // "no"; generally, that's the third word
 544+ $index_of_no = 2;
 545+ if (count($words_for_false) > $index_of_no) {
 546+ $no = ucwords($words_for_false[$index_of_no]);
 547+ } elseif (count($words_for_false) == 0) {
 548+ $no = "0"; // some safe value if no words are found
 549+ } else {
 550+ $no = ucwords($words_for_false[0]);
 551+ }
 552+ $cur_value_in_template = $no;
 553+ } elseif (count($cur_value) == 2) {
 554+ $words_for_true = explode(',', wfMsgForContent('smw_true_words'));
 555+ // get the value in the 'true' series that tends to be "yes",
 556+ // and go with that one - generally, that's the third word
 557+ $index_of_yes = 2;
 558+ if (count($words_for_true) > $index_of_yes) {
 559+ $yes = ucwords($words_for_true[$index_of_yes]);
 560+ } elseif (count($words_for_true) == 0) {
 561+ $yes = "1"; // some safe value if no words are found
 562+ } else {
 563+ $yes = ucwords($words_for_true[0]);
 564+ }
 565+ $cur_value_in_template = $yes;
 566+ // if it's 3 or greater, assume it's a date or datetime
 567+ } elseif (count($cur_value) >= 3) {
 568+ $month = $cur_value['month'];
 569+ $day = $cur_value['day'];
 570+ if ($day != '') {
 571+ global $wgAmericanDates;
 572+ if ($wgAmericanDates == false) {
 573+ // pad out day to always be two digits
 574+ $day = str_pad($day, 2, "0", STR_PAD_LEFT);
 575+ }
 576+ }
 577+ $year = $cur_value['year'];
 578+ if (isset($cur_value['hour'])) $hour = $cur_value['hour'];
 579+ if (isset($cur_value['minute'])) $minute = $cur_value['minute'];
 580+ if (isset($cur_value['second'])) $second = $cur_value['second'];
 581+ if (isset($cur_value['ampm24h'])) $ampm24h = $cur_value['ampm24h'];
 582+ if (isset($cur_value['timezone'])) $timezone = $cur_value['timezone'];
 583+ if ($month != '' && $day != '' && $year != '') {
 584+ // special handling for American dates - otherwise, just
 585+ // the standard year/month/day (where month is a number)
 586+ global $wgAmericanDates;
 587+ if ($wgAmericanDates == true) {
 588+ $cur_value_in_template = "$month $day, $year";
 589+ } else {
 590+ $cur_value_in_template = "$year/$month/$day";
 591+ }
 592+ // include whatever time information we have
 593+ if(isset($hour)) $cur_value_in_template .= " " . str_pad(intval(substr($hour,0,2)),2,'0',STR_PAD_LEFT) . ":" . str_pad(intval(substr($minute,0,2)),2,'0',STR_PAD_LEFT);
 594+ if(isset($second)) $cur_value_in_template .= ":" . str_pad(intval(substr($second,0,2)),2,'0',STR_PAD_LEFT);
 595+ if(isset($ampm24h)) $cur_value_in_template .= " $ampm24h";
 596+ if(isset($timezone)) $cur_value_in_template .= " $timezone";
 597+ } else {
 598+ $cur_value_in_template = "";
 599+ }
 600+ }
 601+ }
 602+ } else { // value is not an array
 603+ $cur_value_in_template = $cur_value;
 604+ }
 605+ if ($query_template_name == null || $query_template_name == '')
 606+ $input_name = $field_name;
 607+ elseif ($allow_multiple)
 608+ // 'num' will get replaced by an actual index, either in PHP
 609+ // or in Javascript, later on
 610+ $input_name = $query_template_name . '[num][' . $field_name . ']';
 611+ else
 612+ $input_name = $query_template_name . '[' . $field_name . ']';
613613
614 - // if we're creating the page name from a formula based on
615 - // form values, see if the current input is part of that formula,
616 - // and if so, substitute in the actual value
617 - if ($form_submitted && $generated_page_name != '') {
618 - $true_input_name = str_replace('_', ' ', $input_name);
619 - $generated_page_name = str_ireplace("<$true_input_name>", $cur_value_in_template, $generated_page_name);
620 - }
621 - // disable this field if either the whole form is disabled, or
622 - // it's a restricted field and user doesn't have sysop privileges
623 - $is_disabled = ($form_is_disabled ||
624 - ($is_restricted && (! $wgUser || ! $wgUser->isAllowed('delete'))));
625 - // create an SFFormTemplateField instance based on all the
626 - // parameters in the form definition, and any information from
627 - // the template definition (contained in the $all_fields parameter)
628 - $form_field = SFFormTemplateField::createFromDefinition($field_name, $input_name,
629 - $is_mandatory, $is_hidden, $is_uploadable, $possible_values, $is_disabled,
630 - $is_list, $input_type, $field_args, $all_fields, $strict_parsing);
631 - // if this is not part of a 'multiple' template, incrememt the
632 - // global tab index (used for correct tabbing)
633 - if (! $field_args['part_of_multiple'])
634 - $sfgTabIndex++;
635 - // increment the global field number regardless
636 - $sfgFieldNum++;
637 - // if the field is a date field, and its default value was set
638 - // to 'now', and it has no current value, set $cur_value to be
639 - // the current date
640 - if ($default_value == 'now' &&
641 - // if the date is hidden, cur_value will already be set
642 - // to the default value
643 - ($cur_value == '' || $cur_value == 'now')) {
644 - if ($input_type == 'date' || $input_type == 'datetime' ||
645 - $input_type == 'datetime with timezone' ||
646 - ($input_type == '' && $form_field->template_field->field_type == 'Date')) {
647 - $cur_time = time();
648 - $year = date("Y", $cur_time);
649 - $month = date("n", $cur_time);
650 - $day = date("j", $cur_time);
651 - global $wgAmericanDates;
652 - if ($wgAmericanDates == true) {
653 - $month_names = sffGetMonthNames();
654 - $month_name = $month_names[$month - 1];
655 - $cur_value_in_template = "$month_name $day, $year";
656 - } else {
657 - $cur_value_in_template = "$year/$month/$day";
658 - }
659 - if ($input_type == 'datetime' || $input_type == 'datetime with timezone') {
660 - $hour = str_pad(intval(substr(date("g", $cur_time),0,2)),2,'0',STR_PAD_LEFT);
661 - $minute = str_pad(intval(substr(date("i", $cur_time),0,2)),2,'0',STR_PAD_LEFT);
662 - $second = str_pad(intval(substr(date("s", $cur_time),0,2)),2,'0',STR_PAD_LEFT);
663 - $ampm = date("A", $cur_time);
664 - $cur_value_in_template .= " $hour:$minute:$second $ampm";
665 - }
666 - if ($input_type == 'datetime with timezone') {
667 - $timezone = date("T", $cur_time);
668 - $cur_value_in_template .= " $timezone";
669 - }
670 - }
671 - }
672 - list($new_text, $new_javascript_text) = $this->formFieldHTML($form_field, $cur_value);
 614+ // if we're creating the page name from a formula based on
 615+ // form values, see if the current input is part of that formula,
 616+ // and if so, substitute in the actual value
 617+ if ($form_submitted && $generated_page_name != '') {
 618+ $true_input_name = str_replace('_', ' ', $input_name);
 619+ $generated_page_name = str_ireplace("<$true_input_name>", $cur_value_in_template, $generated_page_name);
 620+ }
 621+ // disable this field if either the whole form is disabled, or
 622+ // it's a restricted field and user doesn't have sysop privileges
 623+ $is_disabled = ($form_is_disabled ||
 624+ ($is_restricted && (! $wgUser || ! $wgUser->isAllowed('delete'))));
 625+ // create an SFFormTemplateField instance based on all the
 626+ // parameters in the form definition, and any information from
 627+ // the template definition (contained in the $all_fields parameter)
 628+ $form_field = SFFormTemplateField::createFromDefinition($field_name, $input_name,
 629+ $is_mandatory, $is_hidden, $is_uploadable, $possible_values, $is_disabled,
 630+ $is_list, $input_type, $field_args, $all_fields, $strict_parsing);
 631+ // if this is not part of a 'multiple' template, incrememt the
 632+ // global tab index (used for correct tabbing)
 633+ if (! $field_args['part_of_multiple'])
 634+ $sfgTabIndex++;
 635+ // increment the global field number regardless
 636+ $sfgFieldNum++;
 637+ // if the field is a date field, and its default value was set
 638+ // to 'now', and it has no current value, set $cur_value to be
 639+ // the current date
 640+ if ($default_value == 'now' &&
 641+ // if the date is hidden, cur_value will already be set
 642+ // to the default value
 643+ ($cur_value == '' || $cur_value == 'now')) {
 644+ if ($input_type == 'date' || $input_type == 'datetime' ||
 645+ $input_type == 'datetime with timezone' ||
 646+ ($input_type == '' && $form_field->template_field->field_type == 'Date')) {
 647+ $cur_time = time();
 648+ $year = date("Y", $cur_time);
 649+ $month = date("n", $cur_time);
 650+ $day = date("j", $cur_time);
 651+ global $wgAmericanDates;
 652+ if ($wgAmericanDates == true) {
 653+ $month_names = sffGetMonthNames();
 654+ $month_name = $month_names[$month - 1];
 655+ $cur_value_in_template = "$month_name $day, $year";
 656+ } else {
 657+ $cur_value_in_template = "$year/$month/$day";
 658+ }
 659+ if ($input_type == 'datetime' || $input_type == 'datetime with timezone') {
 660+ $hour = str_pad(intval(substr(date("g", $cur_time),0,2)),2,'0',STR_PAD_LEFT);
 661+ $minute = str_pad(intval(substr(date("i", $cur_time),0,2)),2,'0',STR_PAD_LEFT);
 662+ $second = str_pad(intval(substr(date("s", $cur_time),0,2)),2,'0',STR_PAD_LEFT);
 663+ $ampm = date("A", $cur_time);
 664+ $cur_value_in_template .= " $hour:$minute:$second $ampm";
 665+ }
 666+ if ($input_type == 'datetime with timezone') {
 667+ $timezone = date("T", $cur_time);
 668+ $cur_value_in_template .= " $timezone";
 669+ }
 670+ }
 671+ }
 672+ list($new_text, $new_javascript_text) = $this->formFieldHTML($form_field, $cur_value);
673673
674 - $fields_javascript_text .= $new_javascript_text;
 674+ $fields_javascript_text .= $new_javascript_text;
675675
676 - // if this was field was disabled due to being 'restricted',
677 - // add a hidden field holding the value of this field, because
678 - // disabled inputs for some reason don't submit their value
679 - if ($is_restricted && ! $wgUser->isAllowed('delete')) {
680 - if ($field_name == 'free text') {
681 - $new_text .= $this->hiddenFieldHTML('free_text', '<free_text>');
682 - } else {
683 - $new_text .= $this->hiddenFieldHTML($input_name, $cur_value);
684 - }
685 - }
 676+ // if this was field was disabled due to being 'restricted',
 677+ // add a hidden field holding the value of this field, because
 678+ // disabled inputs for some reason don't submit their value
 679+ if ($is_restricted && ! $wgUser->isAllowed('delete')) {
 680+ if ($field_name == 'free text') {
 681+ $new_text .= $this->hiddenFieldHTML('free_text', '<free_text>');
 682+ } else {
 683+ $new_text .= $this->hiddenFieldHTML($input_name, $cur_value);
 684+ }
 685+ }
686686
687 - if ($new_text) {
688 - // include the field name only for non-numeric field names
689 - if (is_numeric($field_name)) {
690 - $template_text .= "|$cur_value_in_template";
691 - } else {
692 - // if the value is null, don't include it at all
693 - if ($cur_value_in_template != '')
694 - $template_text .= "\n|$field_name=$cur_value_in_template";
695 - }
696 - $section = substr_replace($section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
697 - // also add to Javascript validation code
698 - $input_id = "input_" . $sfgFieldNum;
699 - $info_id = "info_" . $sfgFieldNum;
700 - if ($is_mandatory) {
701 - if ($input_type == 'date' || $input_type == 'datetime' || $input_type == 'datetime with timezone') {
702 - $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_month', '$info_id')";
703 - $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_day', '$info_id')";
704 - $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_year', '$info_id')";
705 - if ($input_type == 'datetime' || $input_type == 'datetime with timezone') {
706 - // TODO - validate the time fields
707 - if ($input_type == 'datetime with timezone') {
708 - // TODO - validate the timezone
709 - }
710 - }
711 - } else {
712 - if ($allow_multiple) {
713 - $sfgJSValidationCalls[] = "validate_multiple_mandatory_fields($sfgFieldNum)";
714 - } else {
715 - $sfgJSValidationCalls[] = "validate_mandatory_field('$input_id', '$info_id')";
716 - }
717 - }
718 - }
719 - } else {
720 - $start_position = $brackets_end_loc;
721 - }
722 - }
723 - // =====================================================
724 - // standard input processing
725 - // =====================================================
726 - } elseif ($tag_title == 'standard input') {
727 - // set a flag so that the standard 'form bottom' won't get displayed
728 - $this->standardInputsIncluded = true;
729 - // handle all the possible values
730 - $input_name = $tag_components[1];
731 - $input_label = null;
732 - // cycle through the other components
733 - for ($i = 2; $i < count($tag_components); $i++) {
734 - $component = $tag_components[$i];
735 - $sub_components = explode('=', $component);
736 - if (count($sub_components) == 2) {
737 - if ($sub_components[0] == 'label') {
738 - $input_label = $sub_components[1];
739 - }
740 - }
741 - }
742 - if ($input_name == 'summary') {
743 - $new_text = $this->summaryInputHTML($form_is_disabled, $input_label);
744 - } elseif ($input_name == 'minor edit') {
745 - $new_text = $this->minorEditInputHTML($form_is_disabled, $input_label);
746 - } elseif ($input_name == 'watch') {
747 - $new_text = $this->watchInputHTML($form_is_disabled, $input_label);
748 - } elseif ($input_name == 'save') {
749 - $new_text = $this->saveButtonHTML($form_is_disabled, $input_label);
750 - } elseif ($input_name == 'preview') {
751 - $new_text = $this->showPreviewButtonHTML($form_is_disabled, $input_label);
752 - } elseif ($input_name == 'changes') {
753 - $new_text = $this->showChangesButtonHTML($form_is_disabled, $input_label);
754 - } elseif ($input_name == 'cancel') {
755 - $new_text = $this->cancelLinkHTML($form_is_disabled, $input_label);
756 - }
757 - $section = substr_replace($section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
758 - // =====================================================
759 - // page info processing
760 - // =====================================================
761 - } elseif ($tag_title == 'info') {
762 - // TODO: Generate an error message if this is included more than once
763 - foreach(array_slice($tag_components, 1) as $component) {
764 - $sub_components = explode('=', $component, 2);
765 - $tag = $sub_components[0];
766 - if ($tag == 'add title') {
767 - // handle this only if we're adding a page
768 - if (! $this->mPageTitle->exists()) {
769 - $val = $sub_components[1];
770 - $form_page_title = $val;
771 - }
772 - }
773 - elseif($tag == 'edit title') {
774 - // handle this only if we're editing a page
775 - if ($this->mPageTitle->exists()) {
776 - $val = $sub_components[1];
777 - $form_page_title = $val;
778 - }
779 - }
780 - elseif($tag == 'partial form') {
781 - $form_is_partial = true;
782 - // replacement pages may have minimal matches...
783 - $source_page_matches_this_form = true;
784 - }
785 - }
786 - $section = substr_replace($section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
787 - // =====================================================
788 - // default outer level processing
789 - // =====================================================
790 - } else { // tag is not one of the three allowed values
791 - // ignore tag
792 - $start_position = $brackets_end_loc;
793 - } // end if
794 - } // end while
 687+ if ($new_text) {
 688+ // include the field name only for non-numeric field names
 689+ if (is_numeric($field_name)) {
 690+ $template_text .= "|$cur_value_in_template";
 691+ } else {
 692+ // if the value is null, don't include it at all
 693+ if ($cur_value_in_template != '')
 694+ $template_text .= "\n|$field_name=$cur_value_in_template";
 695+ }
 696+ $section = substr_replace($section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
 697+ // also add to Javascript validation code
 698+ $input_id = "input_" . $sfgFieldNum;
 699+ $info_id = "info_" . $sfgFieldNum;
 700+ if ($is_mandatory) {
 701+ if ($input_type == 'date' || $input_type == 'datetime' || $input_type == 'datetime with timezone') {
 702+ $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_month', '$info_id')";
 703+ $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_day', '$info_id')";
 704+ $sfgJSValidationCalls[] = "validate_mandatory_field ('$input_id" . "_year', '$info_id')";
 705+ if ($input_type == 'datetime' || $input_type == 'datetime with timezone') {
 706+ // TODO - validate the time fields
 707+ if ($input_type == 'datetime with timezone') {
 708+ // TODO - validate the timezone
 709+ }
 710+ }
 711+ } else {
 712+ if ($allow_multiple) {
 713+ $sfgJSValidationCalls[] = "validate_multiple_mandatory_fields($sfgFieldNum)";
 714+ } else {
 715+ $sfgJSValidationCalls[] = "validate_mandatory_field('$input_id', '$info_id')";
 716+ }
 717+ }
 718+ }
 719+ } else {
 720+ $start_position = $brackets_end_loc;
 721+ }
 722+ }
 723+ // =====================================================
 724+ // standard input processing
 725+ // =====================================================
 726+ } elseif ($tag_title == 'standard input') {
 727+ // set a flag so that the standard 'form bottom' won't get displayed
 728+ $this->standardInputsIncluded = true;
 729+ // handle all the possible values
 730+ $input_name = $tag_components[1];
 731+ $input_label = null;
 732+ // cycle through the other components
 733+ for ($i = 2; $i < count($tag_components); $i++) {
 734+ $component = $tag_components[$i];
 735+ $sub_components = explode('=', $component);
 736+ if (count($sub_components) == 2) {
 737+ if ($sub_components[0] == 'label') {
 738+ $input_label = $sub_components[1];
 739+ }
 740+ }
 741+ }
 742+ if ($input_name == 'summary') {
 743+ $new_text = $this->summaryInputHTML($form_is_disabled, $input_label);
 744+ } elseif ($input_name == 'minor edit') {
 745+ $new_text = $this->minorEditInputHTML($form_is_disabled, $input_label);
 746+ } elseif ($input_name == 'watch') {
 747+ $new_text = $this->watchInputHTML($form_is_disabled, $input_label);
 748+ } elseif ($input_name == 'save') {
 749+ $new_text = $this->saveButtonHTML($form_is_disabled, $input_label);
 750+ } elseif ($input_name == 'preview') {
 751+ $new_text = $this->showPreviewButtonHTML($form_is_disabled, $input_label);
 752+ } elseif ($input_name == 'changes') {
 753+ $new_text = $this->showChangesButtonHTML($form_is_disabled, $input_label);
 754+ } elseif ($input_name == 'cancel') {
 755+ $new_text = $this->cancelLinkHTML($form_is_disabled, $input_label);
 756+ }
 757+ $section = substr_replace($section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
 758+ // =====================================================
 759+ // page info processing
 760+ // =====================================================
 761+ } elseif ($tag_title == 'info') {
 762+ // TODO: Generate an error message if this is included more than once
 763+ foreach(array_slice($tag_components, 1) as $component) {
 764+ $sub_components = explode('=', $component, 2);
 765+ $tag = $sub_components[0];
 766+ if ($tag == 'add title') {
 767+ // handle this only if we're adding a page
 768+ if (! $this->mPageTitle->exists()) {
 769+ $val = $sub_components[1];
 770+ $form_page_title = $val;
 771+ }
 772+ }
 773+ elseif($tag == 'edit title') {
 774+ // handle this only if we're editing a page
 775+ if ($this->mPageTitle->exists()) {
 776+ $val = $sub_components[1];
 777+ $form_page_title = $val;
 778+ }
 779+ }
 780+ elseif($tag == 'partial form') {
 781+ $form_is_partial = true;
 782+ // replacement pages may have minimal matches...
 783+ $source_page_matches_this_form = true;
 784+ }
 785+ }
 786+ $section = substr_replace($section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc);
 787+ // =====================================================
 788+ // default outer level processing
 789+ // =====================================================
 790+ } else { // tag is not one of the three allowed values
 791+ // ignore tag
 792+ $start_position = $brackets_end_loc;
 793+ } // end if
 794+ } // end while
795795
796 - if (! $all_instances_printed ) {
797 - if ($template_text != '') {
798 - // for mostly aesthetic purposes, if the template call ends with
799 - // a bunch of pipes (i.e., it's an indexed template with unused
800 - // parameters at the end), remove the pipes
801 - $template_text = preg_replace('/\|*$/', '', $template_text);
802 - // add another newline before the final bracket, if this template
803 - // call is already more than one line
804 - if (strpos($template_text, "\n"))
805 - $template_text .= "\n";
806 - $template_text .= "}}";
807 - $data_text .= $template_text . "\n";
808 - // if there is a placeholder in the text, we know that we are
809 - // doing a replace
810 - if ($existing_page_content && strpos($existing_page_content, '{{{insertionpoint}}}', 0) !== false) {
811 - $existing_page_content = preg_replace('/\{\{\{insertionpoint\}\}\}(\r?\n?)/',
812 - preg_replace('/\}\}/m', '}�',
813 - preg_replace('/\{\{/m', '�{', $template_text)) .
814 - "\n{{{insertionpoint}}}",
815 - $existing_page_content);
816 - // otherwise, if it's a partial form, we have to add the new
817 - // text somewhere
818 - } elseif ($form_is_partial && $wgRequest->getCheck('partial') ) {
819 - $existing_page_content = preg_replace('/\}\}/m', '}�',
820 - preg_replace('/\{\{/m', '�{', $template_text)) .
821 - "\n{{{insertionpoint}}}\n" . $existing_page_content;
822 - }
823 - }
824 - }
 796+ if (! $all_instances_printed ) {
 797+ if ($template_text != '') {
 798+ // for mostly aesthetic purposes, if the template call ends with
 799+ // a bunch of pipes (i.e., it's an indexed template with unused
 800+ // parameters at the end), remove the pipes
 801+ $template_text = preg_replace('/\|*$/', '', $template_text);
 802+ // add another newline before the final bracket, if this template
 803+ // call is already more than one line
 804+ if (strpos($template_text, "\n"))
 805+ $template_text .= "\n";
 806+ $template_text .= "}}";
 807+ $data_text .= $template_text . "\n";
 808+ // if there is a placeholder in the text, we know that we are
 809+ // doing a replace
 810+ if ($existing_page_content && strpos($existing_page_content, '{{{insertionpoint}}}', 0) !== false) {
 811+ $existing_page_content = preg_replace('/\{\{\{insertionpoint\}\}\}(\r?\n?)/',
 812+ preg_replace('/\}\}/m', '}�',
 813+ preg_replace('/\{\{/m', '�{', $template_text)) .
 814+ "\n{{{insertionpoint}}}",
 815+ $existing_page_content);
 816+ // otherwise, if it's a partial form, we have to add the new
 817+ // text somewhere
 818+ } elseif ($form_is_partial && $wgRequest->getCheck('partial') ) {
 819+ $existing_page_content = preg_replace('/\}\}/m', '}�',
 820+ preg_replace('/\{\{/m', '�{', $template_text)) .
 821+ "\n{{{insertionpoint}}}\n" . $existing_page_content;
 822+ }
 823+ }
 824+ }
825825
826 - if ($allow_multiple) {
827 - if (! $all_instances_printed) {
828 - // add the character "a' onto the instance number of this input
829 - // in the form, to differentiate the inputs the form starts out
830 - // with from any inputs added by the Javascript
831 - $section = str_replace('[num]', "[{$instance_num}a]", $section);
832 - $remove_text = wfMsg('sf_editdata_remove');
833 - $form_text .=<<<END
 826+ if ($allow_multiple) {
 827+ if (! $all_instances_printed) {
 828+ // add the character "a' onto the instance number of this input
 829+ // in the form, to differentiate the inputs the form starts out
 830+ // with from any inputs added by the Javascript
 831+ $section = str_replace('[num]', "[{$instance_num}a]", $section);
 832+ $remove_text = wfMsg('sf_editdata_remove');
 833+ $form_text .=<<<END
834834 <div id="wrapper_$sfgFieldNum" class="multipleTemplate">
835 - $section
836 - <input type="button" onclick="removeInstance('wrapper_$sfgFieldNum');" value="$remove_text" tabindex="$sfgTabIndex" class="remove" />
837 - </div>
 835+ $section
 836+ <input type="button" onclick="removeInstance('wrapper_$sfgFieldNum');" value="$remove_text" tabindex="$sfgTabIndex" class="remove" />
 837+ </div>
838838
839839 END;
840 - // this will cause the section to be re-parsed on the next go
841 - $section_num--;
842 - // because there is an instance, the fieldset will never be hidden,
843 - // even if choosers are being used. So, do not hide the fieldset.
844 - $form_text = str_replace("[[placeholder]]", "", $form_text);
845 - } else {
846 - // this is the last instance of this template - stick an 'add'
847 - // button in the form
848 - $form_text .=<<<END
 840+ // this will cause the section to be re-parsed on the next go
 841+ $section_num--;
 842+ // because there is an instance, the fieldset will never be hidden,
 843+ // even if choosers are being used. So, do not hide the fieldset.
 844+ $form_text = str_replace("[[placeholder]]", "", $form_text);
 845+ } else {
 846+ // this is the last instance of this template - stick an 'add'
 847+ // button in the form
 848+ $form_text .=<<<END
849849 <div id="starter_$query_template_name" class="multipleTemplate" style="display: none;">
850 - $section
851 - </div>
852 - <div id="main_$query_template_name"></div>
 850+ $section
 851+ </div>
 852+ <div id="main_$query_template_name"></div>
853853
854854 END;
855 - $add_another = wfMsg('sf_editdata_addanother');
856 - $form_text .=<<<END
 855+ $add_another = wfMsg('sf_editdata_addanother');
 856+ $form_text .=<<<END
857857 <p style="margin-left:10px;">
858858 <p><input type="button" onclick="addInstance('starter_$query_template_name', 'main_$query_template_name', '$sfgFieldNum');" value="$add_another" tabindex="$sfgTabIndex" class="addAnother" /></p>
859859
860860 END;
861 - // if a chooser is being used for this template, add the template
862 - // to the chooser data array
863 - if ($chooser_name !== false)
864 - $choosers[$chooser_name][]= array($query_template_name, $sfgFieldNum, $chooser_caption);
865 - }
866 - } else {
867 - $form_text .= $section;
868 - }
 861+ // if a chooser is being used for this template, add the template
 862+ // to the chooser data array
 863+ if ($chooser_name !== false)
 864+ $choosers[$chooser_name][]= array($query_template_name, $sfgFieldNum, $chooser_caption);
 865+ }
 866+ } else {
 867+ $form_text .= $section;
 868+ }
869869
870 - } // end for
 870+ } // end for
871871
872 - // if it wasn't included in the form definition, add the
873 - // 'free text' input as a hidden field at the bottom
874 - if (! $free_text_was_included) {
875 - $form_text .= $this->hiddenFieldHTML('free_text', '<free_text>');
876 - }
877 - // get free text, and add to page data, as well as retroactively
878 - // inserting it into the form
 872+ // if it wasn't included in the form definition, add the
 873+ // 'free text' input as a hidden field at the bottom
 874+ if (! $free_text_was_included) {
 875+ $form_text .= $this->hiddenFieldHTML('free_text', '<free_text>');
 876+ }
 877+ // get free text, and add to page data, as well as retroactively
 878+ // inserting it into the form
879879
880 - // If $form_is_partial is true then either:
881 - // (a) we're processing a replacement (param 'partial' == 1)
882 - // (b) we're sending out something to be replaced (param 'partial' is missing)
883 - if ($form_is_partial) {
884 - if(!$wgRequest->getCheck('partial')) {
885 - $free_text = $original_page_content;
886 - $form_text .= $this->hiddenFieldHTML('partial', 1);
887 - } else {
888 - $free_text = null;
889 - $existing_page_content = preg_replace('/�\{(.*?)\}�/s', '{{\1}}', $existing_page_content);
890 - $existing_page_content = preg_replace('/\{\{\{insertionpoint\}\}\}/', '', $existing_page_content);
891 - $existing_page_content = Sanitizer::safeEncodeAttribute($existing_page_content);
892 - }
893 - } elseif ($source_is_page) {
894 - // if the page is the source, free_text will just be whatever in the
895 - // page hasn't already been inserted into the form
896 - $free_text = trim($existing_page_content);
897 - // or get it from a form submission
898 - } elseif ($wgRequest->getCheck('free_text')) {
899 - $free_text = $wgRequest->getVal('free_text');
900 - if (! $free_text_was_included) {
901 - $data_text .= "<free_text>";
902 - }
903 - // or get it from the form definition
904 - } elseif ($free_text_preload_page != null) {
905 - $free_text = $this->getPreloadedText($free_text_preload_page);
906 - } else {
907 - $free_text = null;
908 - }
909 - $free_text = Sanitizer::safeEncodeAttribute($free_text);
910 - // now that we have it, substitute free text into the form and page
911 - $form_text = str_replace('<free_text>', $free_text, $form_text);
912 - $data_text = str_replace('<free_text>', $free_text, $data_text);
 880+ // If $form_is_partial is true then either:
 881+ // (a) we're processing a replacement (param 'partial' == 1)
 882+ // (b) we're sending out something to be replaced (param 'partial' is missing)
 883+ if ($form_is_partial) {
 884+ if(!$wgRequest->getCheck('partial')) {
 885+ $free_text = $original_page_content;
 886+ $form_text .= $this->hiddenFieldHTML('partial', 1);
 887+ } else {
 888+ $free_text = null;
 889+ $existing_page_content = preg_replace('/�\{(.*?)\}�/s', '{{\1}}', $existing_page_content);
 890+ $existing_page_content = preg_replace('/\{\{\{insertionpoint\}\}\}/', '', $existing_page_content);
 891+ $existing_page_content = Sanitizer::safeEncodeAttribute($existing_page_content);
 892+ }
 893+ } elseif ($source_is_page) {
 894+ // if the page is the source, free_text will just be whatever in the
 895+ // page hasn't already been inserted into the form
 896+ $free_text = trim($existing_page_content);
 897+ // or get it from a form submission
 898+ } elseif ($wgRequest->getCheck('free_text')) {
 899+ $free_text = $wgRequest->getVal('free_text');
 900+ if (! $free_text_was_included) {
 901+ $data_text .= "<free_text>";
 902+ }
 903+ // or get it from the form definition
 904+ } elseif ($free_text_preload_page != null) {
 905+ $free_text = $this->getPreloadedText($free_text_preload_page);
 906+ } else {
 907+ $free_text = null;
 908+ }
 909+ $free_text = Sanitizer::safeEncodeAttribute($free_text);
 910+ // now that we have it, substitute free text into the form and page
 911+ $form_text = str_replace('<free_text>', $free_text, $form_text);
 912+ $data_text = str_replace('<free_text>', $free_text, $data_text);
913913
914 - // add a warning in, if we're editing an existing page and that page
915 - // appears to not have been created with this form
916 - if ($this->mPageTitle->exists() && ($existing_page_content != '') && ! $source_page_matches_this_form) {
917 - $form_text = ' <div class="warningMessage">' . wfMsg('sf_editdata_formwarning', $this->mPageTitle->getFullURL()) . "</div>\n" . $form_text;
918 - }
 914+ // add a warning in, if we're editing an existing page and that page
 915+ // appears to not have been created with this form
 916+ if ($this->mPageTitle->exists() && ($existing_page_content != '') && ! $source_page_matches_this_form) {
 917+ $form_text = ' <div class="warningMessage">' . wfMsg('sf_editdata_formwarning', $this->mPageTitle->getFullURL()) . "</div>\n" . $form_text;
 918+ }
919919
920 - //Substitute the choosers in here too.
921 - $chooser_count = 0;
922 - $chooser_text = "";
923 - $using_choosers = "false";
924 - foreach ($choosers as $choosername => $chooser) {
925 - if (count($chooser)!=0) {
926 - $chooser_count++;
927 - if ($chooser_count==1) {
928 - // emit the initial javascript code
929 - $using_choosers = "true";
930 - $chooser_text .= <<<END
 920+ //Substitute the choosers in here too.
 921+ $chooser_count = 0;
 922+ $chooser_text = "";
 923+ $using_choosers = "false";
 924+ foreach ($choosers as $choosername => $chooser) {
 925+ if (count($chooser)!=0) {
 926+ $chooser_count++;
 927+ if ($chooser_count==1) {
 928+ // emit the initial javascript code
 929+ $using_choosers = "true";
 930+ $chooser_text .= <<<END
931931 <script type="text/javascript">/* <![CDATA[ */
932932
933933 function updatechooserbutton(f,n)
@@ -975,32 +975,32 @@
976976 /* ]]> */ </script>
977977
978978 END;
979 - }
 979+ }
980980
981 - $chooser_text .= "<p>$choosername:<select id='chooserselect$chooser_count' size='1' onchange='updatechooserbutton(this,\"chooserbutton$chooser_count\")'>\n";
982 - $chooser_text .= "<option value='invalid'>" . wfMsg('sf_createform_choosefield') . "</option>\n";
983 - foreach ($chooser as $chooser_item) {
984 - $chooser_value = str_replace('"','\\"',$chooser_item[0]);
985 - $tabindex = $chooser_item[1];
986 - $chooser_caption = $chooser_item[2];
987 - if ($chooser_caption === false)
988 - $chooser_caption = str_replace('_', ' ', $chooser_value);
989 - $chooser_text .= "<option value=\"$tabindex ,$chooser_value\">$chooser_caption</option>\n";
990 - }
991 - $chooser_text .= "</select>\n";
992 - }
993 - $chooser_text .= "<input type='button' onclick=\"addInstanceFromChooser('chooserselect$chooser_count');\" value='" . wfMsg('sf_editdata_addanother') . "' disabled='true' id='chooserbutton$chooser_count'></p>";
994 - }
 981+ $chooser_text .= "<p>$choosername:<select id='chooserselect$chooser_count' size='1' onchange='updatechooserbutton(this,\"chooserbutton$chooser_count\")'>\n";
 982+ $chooser_text .= "<option value='invalid'>" . wfMsg('sf_createform_choosefield') . "</option>\n";
 983+ foreach ($chooser as $chooser_item) {
 984+ $chooser_value = str_replace('"','\\"',$chooser_item[0]);
 985+ $tabindex = $chooser_item[1];
 986+ $chooser_caption = $chooser_item[2];
 987+ if ($chooser_caption === false)
 988+ $chooser_caption = str_replace('_', ' ', $chooser_value);
 989+ $chooser_text .= "<option value=\"$tabindex ,$chooser_value\">$chooser_caption</option>\n";
 990+ }
 991+ $chooser_text .= "</select>\n";
 992+ }
 993+ $chooser_text .= "<input type='button' onclick=\"addInstanceFromChooser('chooserselect$chooser_count');\" value='" . wfMsg('sf_editdata_addanother') . "' disabled='true' id='chooserbutton$chooser_count'></p>";
 994+ }
995995
996 - $form_text = str_replace('{{{choosers}}}', $chooser_text, $form_text);
 996+ $form_text = str_replace('{{{choosers}}}', $chooser_text, $form_text);
997997
998 - // add form bottom, if no custom "standard inputs" have been defined
999 - if (! $this->standardInputsIncluded)
1000 - $form_text .= $this->formBottom($form_is_disabled);
1001 - $starttime = wfTimestampNow();
1002 - $page_article = new Article($this->mPageTitle);
1003 - $edittime = $page_article->getTimestamp();
1004 - $form_text .=<<<END
 998+ // add form bottom, if no custom "standard inputs" have been defined
 999+ if (! $this->standardInputsIncluded)
 1000+ $form_text .= $this->formBottom($form_is_disabled);
 1001+ $starttime = wfTimestampNow();
 1002+ $page_article = new Article($this->mPageTitle);
 1003+ $edittime = $page_article->getTimestamp();
 1004+ $form_text .=<<<END
10051005
10061006 <input type="hidden" value="$starttime" name="wpStarttime" />
10071007 <input type="hidden" value="$edittime" name="wpEdittime" />
@@ -1008,15 +1008,15 @@
10091009
10101010 END;
10111011
1012 - // add general Javascript code
1013 - $form_errors_header = wfMsg('sf_formerrors_header');
1014 - $blank_error_str = wfMsg('sf_blank_error');
1015 - $bad_url_error_str = wfMsg('sf_bad_url_error');
1016 - $bad_email_error_str = wfMsg('sf_bad_email_error');
1017 - $bad_number_error_str = wfMsg('sf_bad_number_error');
1018 - $bad_integer_error_str = wfMsg('sf_bad_integer_error');
1019 - $bad_date_error_str = wfMsg('sf_bad_date_error');
1020 - $javascript_text .=<<<END
 1012+ // add general Javascript code
 1013+ $form_errors_header = wfMsg('sf_formerrors_header');
 1014+ $blank_error_str = wfMsg('sf_blank_error');
 1015+ $bad_url_error_str = wfMsg('sf_bad_url_error');
 1016+ $bad_email_error_str = wfMsg('sf_bad_email_error');
 1017+ $bad_number_error_str = wfMsg('sf_bad_number_error');
 1018+ $bad_integer_error_str = wfMsg('sf_bad_integer_error');
 1019+ $bad_date_error_str = wfMsg('sf_bad_date_error');
 1020+ $javascript_text .=<<<END
10211021
10221022 function validate_mandatory_field(field_id, info_id) {
10231023 field = document.getElementById(field_id);
@@ -1099,8 +1099,8 @@
11001100 if (day_field.value == '' || year_field.value == '') {
11011101 return true;
11021102 } else if (day_field.value.match(/^\d+$/) &&
1103 - day_field.value <= 31 &&
1104 - year_field.value.match(/^\d+$/)) {
 1103+ day_field.value <= 31 &&
 1104+ year_field.value.match(/^\d+$/)) {
11051105 return true;
11061106 } else {
11071107 infobox = document.getElementById(info_id);
@@ -1137,12 +1137,12 @@
11381138 var num_errors = 0;
11391139
11401140 END;
1141 - foreach ($sfgJSValidationCalls as $function_call) {
1142 - $javascript_text .= " if (! $function_call) num_errors += 1;\n";
1143 - }
1144 - $remove_text = wfMsg('sf_editdata_remove');
1145 - $delimiter = '","';
1146 - $javascript_text .=<<<END
 1141+ foreach ($sfgJSValidationCalls as $function_call) {
 1142+ $javascript_text .= " if (! $function_call) num_errors += 1;\n";
 1143+ }
 1144+ $remove_text = wfMsg('sf_editdata_remove');
 1145+ $delimiter = '","';
 1146+ $javascript_text .=<<<END
11471147 if (num_errors > 0) {
11481148 // add error header, if it's not there already
11491149 if (! document.getElementById("form_error_header")) {
@@ -1229,7 +1229,7 @@
12301230 for (x = 0; x < forms.length; x++) {
12311231 if (forms[x].name == "createbox") {
12321232 attachAutocompleteToAllFields(forms[x]);
1233 - }
 1233+ }
12341234 }
12351235 }
12361236
@@ -1283,306 +1283,304 @@
12841284
12851285 END;
12861286
1287 - // send the autocomplete values to the browser, along with the mappings
1288 - // of which values should apply to which fields
1289 - // if doing a replace, the data text is actually the modified original page
1290 - if($wgRequest->getCheck('partial'))
1291 - $data_text = $existing_page_content;
1292 - $javascript_text .= $fields_javascript_text;
1293 - return array($form_text, "/*<![CDATA[*/ $javascript_text /*]]>*/",
1294 - $data_text, $form_page_title, $generated_page_name);
1295 - }
 1287+ // send the autocomplete values to the browser, along with the mappings
 1288+ // of which values should apply to which fields
 1289+ // if doing a replace, the data text is actually the modified original page
 1290+ if($wgRequest->getCheck('partial'))
 1291+ $data_text = $existing_page_content;
 1292+ $javascript_text .= $fields_javascript_text;
 1293+ return array($form_text, "/*<![CDATA[*/ $javascript_text /*]]>*/",
 1294+ $data_text, $form_page_title, $generated_page_name);
 1295+ }
12961296
1297 - function formFieldHTML($form_field, $cur_value) {
1298 - global $smwgContLang;
 1297+ function formFieldHTML($form_field, $cur_value) {
 1298+ global $smwgContLang;
12991299
1300 - // also get the actual field, with all the semantic information (type is
1301 - // SFTemplateField, instead of SFFormTemplateField)
1302 - $template_field = $form_field->template_field;
 1300+ // also get the actual field, with all the semantic information (type is
 1301+ // SFTemplateField, instead of SFFormTemplateField)
 1302+ $template_field = $form_field->template_field;
13031303
1304 - if ($form_field->is_hidden) {
1305 - $text = $this->hiddenFieldHTML($form_field->input_name, $cur_value);
1306 - $javascript_text = "";
1307 - } elseif ($form_field->input_type != '' &&
1308 - array_key_exists($form_field->input_type, $this->mInputTypeHooks) &&
1309 - $this->mInputTypeHooks[$form_field->input_type] != null) {
1310 - $funcArgs = array();
1311 - $funcArgs[] = $cur_value;
1312 - $funcArgs[] = $form_field->input_name;
1313 - $funcArgs[] = $form_field->is_mandatory;
1314 - $funcArgs[] = $form_field->is_disabled;
1315 - // last argument to function should be a hash, merging the default
1316 - // values for this input type with all other properties set in
1317 - // the form definition, plus some semantic-related arguments
1318 - $hook_values = $this->mInputTypeHooks[$form_field->input_type];
1319 - $default_args = $hook_values[1];
1320 - $other_args = $form_field->field_args;
1321 - // if the set of possible values were set in the form definition,
1322 - // go with that
1323 - if ($form_field->possible_values != null)
1324 - $other_args['possible_values'] = $form_field->possible_values;
1325 - else
1326 - $other_args['possible_values'] = $template_field->possible_values;
1327 - // the fact that this is a list can be specified in either the
1328 - // template or the form
1329 - $other_args['is_list'] = ($template_field->is_list || $form_field->is_list);
1330 - if ($template_field->is_relation)
1331 - $other_args['is_relation'] = true;
1332 - if ($template_field->semantic_field != '')
1333 - $other_args['semantic_field_name'] = $template_field->semantic_field;
1334 - // merge default values and values from form - put the default values
1335 - // first, so that if there's a conflict they'll be overridden
1336 - $funcArgs[] = array_merge($default_args, $other_args);
1337 - list($text, $javascript_text) = call_user_func_array($hook_values[0], $funcArgs);
1338 - // escape out here if user doesn't have SMW installed
1339 - } elseif ($smwgContLang == null) {
1340 - $size = $template_field->field_args['size'];
1341 - if ($size == null) $size = 35;
1342 - $field_args = array('size' => $size);
1343 - list($text, $javascript_text) = SFFormInputs::textEntryHTML($cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $field_args);
1344 - } else { // input type not defined in form
1345 - $field_type = $template_field->field_type;
1346 - $is_list = ($form_field->is_list || $template_field->is_list);
1347 - if ($field_type != '' &&
1348 - array_key_exists($field_type, $this->mSemanticTypeHooks) &&
1349 - isset($this->mSemanticTypeHooks[$field_type][$is_list])) {
1350 - $hook_values = $this->mSemanticTypeHooks[$field_type][$is_list];
1351 - $funcArgs = array();
1352 - $funcArgs[] = $cur_value;
1353 - $funcArgs[] = $form_field->input_name;
1354 - $funcArgs[] = $form_field->is_mandatory;
1355 - $funcArgs[] = $form_field->is_disabled;
1356 - // merge default values and values from form - put the default values
1357 - // first, so that if there's a conflict they'll be overridden
1358 - $other_args = array_merge($hook_values[1], $form_field->field_args);
1359 - if ($form_field->possible_values != null)
1360 - $other_args['possible_values'] = $form_field->possible_values;
1361 - else
1362 - $other_args['possible_values'] = $template_field->possible_values;
1363 - if ($template_field->is_relation)
1364 - $other_args['is_relation'] = true;
1365 - if ($template_field->semantic_field != '')
1366 - $other_args['semantic_field_name'] = $template_field->semantic_field;
1367 - $funcArgs[] = $other_args;
1368 - list($text, $javascript_text) = call_user_func_array($hook_values[0], $funcArgs);
1369 - } else { // anything else
1370 - $other_args = $form_field->field_args;
1371 - // set field to be a list if that was specified in the form definition
1372 - if ($form_field->is_list) {
1373 - $other_args['is_list'] = true;
1374 - $other_args['size'] = 100;
1375 - }
1376 - if ($form_field->possible_values != null)
1377 - $other_args['possible_values'] = $form_field->possible_values;
1378 - list($text, $javascript_text) = SFFormInputs::textEntryHTML($cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $other_args);
1379 - }
1380 - }
1381 - return array($text, $javascript_text);
1382 - }
 1304+ if ($form_field->is_hidden) {
 1305+ $text = $this->hiddenFieldHTML($form_field->input_name, $cur_value);
 1306+ $javascript_text = "";
 1307+ } elseif ($form_field->input_type != '' &&
 1308+ array_key_exists($form_field->input_type, $this->mInputTypeHooks) &&
 1309+ $this->mInputTypeHooks[$form_field->input_type] != null) {
 1310+ $funcArgs = array();
 1311+ $funcArgs[] = $cur_value;
 1312+ $funcArgs[] = $form_field->input_name;
 1313+ $funcArgs[] = $form_field->is_mandatory;
 1314+ $funcArgs[] = $form_field->is_disabled;
 1315+ // last argument to function should be a hash, merging the default
 1316+ // values for this input type with all other properties set in
 1317+ // the form definition, plus some semantic-related arguments
 1318+ $hook_values = $this->mInputTypeHooks[$form_field->input_type];
 1319+ $default_args = $hook_values[1];
 1320+ $other_args = $form_field->field_args;
 1321+ // if the set of possible values were set in the form definition,
 1322+ // go with that
 1323+ if ($form_field->possible_values != null)
 1324+ $other_args['possible_values'] = $form_field->possible_values;
 1325+ else
 1326+ $other_args['possible_values'] = $template_field->possible_values;
 1327+ // the fact that this is a list can be specified in either the
 1328+ // template or the form
 1329+ $other_args['is_list'] = ($template_field->is_list || $form_field->is_list);
 1330+ if ($template_field->is_relation)
 1331+ $other_args['is_relation'] = true;
 1332+ if ($template_field->semantic_field != '')
 1333+ $other_args['semantic_field_name'] = $template_field->semantic_field;
 1334+ // merge default values and values from form - put the default values
 1335+ // first, so that if there's a conflict they'll be overridden
 1336+ $funcArgs[] = array_merge($default_args, $other_args);
 1337+ list($text, $javascript_text) = call_user_func_array($hook_values[0], $funcArgs);
 1338+ // escape out here if user doesn't have SMW installed
 1339+ } elseif ($smwgContLang == null) {
 1340+ $size = $template_field->field_args['size'];
 1341+ if ($size == null) $size = 35;
 1342+ $field_args = array('size' => $size);
 1343+ list($text, $javascript_text) = SFFormInputs::textEntryHTML($cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $field_args);
 1344+ } else { // input type not defined in form
 1345+ $field_type = $template_field->field_type;
 1346+ $is_list = ($form_field->is_list || $template_field->is_list);
 1347+ if ($field_type != '' &&
 1348+ array_key_exists($field_type, $this->mSemanticTypeHooks) &&
 1349+ isset($this->mSemanticTypeHooks[$field_type][$is_list])) {
 1350+ $hook_values = $this->mSemanticTypeHooks[$field_type][$is_list];
 1351+ $funcArgs = array();
 1352+ $funcArgs[] = $cur_value;
 1353+ $funcArgs[] = $form_field->input_name;
 1354+ $funcArgs[] = $form_field->is_mandatory;
 1355+ $funcArgs[] = $form_field->is_disabled;
 1356+ // merge default values and values from form - put the default values
 1357+ // first, so that if there's a conflict they'll be overridden
 1358+ $other_args = array_merge($hook_values[1], $form_field->field_args);
 1359+ if ($form_field->possible_values != null)
 1360+ $other_args['possible_values'] = $form_field->possible_values;
 1361+ else
 1362+ $other_args['possible_values'] = $template_field->possible_values;
 1363+ if ($template_field->is_relation)
 1364+ $other_args['is_relation'] = true;
 1365+ if ($template_field->semantic_field != '')
 1366+ $other_args['semantic_field_name'] = $template_field->semantic_field;
 1367+ $funcArgs[] = $other_args;
 1368+ list($text, $javascript_text) = call_user_func_array($hook_values[0], $funcArgs);
 1369+ } else { // anything else
 1370+ $other_args = $form_field->field_args;
 1371+ // set field to be a list if that was specified in the form definition
 1372+ if ($form_field->is_list) {
 1373+ $other_args['is_list'] = true;
 1374+ $other_args['size'] = 100;
 1375+ }
 1376+ if ($form_field->possible_values != null)
 1377+ $other_args['possible_values'] = $form_field->possible_values;
 1378+ list($text, $javascript_text) = SFFormInputs::textEntryHTML($cur_value, $form_field->input_name, $form_field->is_mandatory, $form_field->is_disabled, $other_args);
 1379+ }
 1380+ }
 1381+ return array($text, $javascript_text);
 1382+ }
13831383
1384 - function hiddenFieldHTML($input_name, $cur_value) {
1385 - $text =<<<END
 1384+ function hiddenFieldHTML($input_name, $cur_value) {
 1385+ $text =<<<END
13861386 <input type="hidden" name="$input_name" value="$cur_value" />
13871387
13881388 END;
1389 - return $text;
1390 - }
 1389+ return $text;
 1390+ }
13911391
1392 - function summaryInputHTML($is_disabled, $label = null) {
1393 - global $sfgTabIndex;
 1392+ function summaryInputHTML($is_disabled, $label = null) {
 1393+ global $sfgTabIndex;
13941394
1395 - $sfgTabIndex++;
1396 - if ($label == null)
1397 - $label = wfMsg('summary');
1398 - $disabled_text = ($is_disabled) ? "disabled" : "";
1399 - $text =<<<END
 1395+ $sfgTabIndex++;
 1396+ if ($label == null)
 1397+ $label = wfMsg('summary');
 1398+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1399+ $text =<<<END
14001400 <span id='wpSummaryLabel'><label for='wpSummary'>$label:</label></span>
14011401 <input tabindex="$sfgTabIndex" type='text' value="" name='wpSummary' id='wpSummary' maxlength='200' size='60' $disabled_text/>
14021402
14031403 END;
1404 - return $text;
1405 - }
 1404+ return $text;
 1405+ }
14061406
1407 - function minorEditInputHTML($is_disabled, $label = null) {
1408 - global $sfgTabIndex;
 1407+ function minorEditInputHTML($is_disabled, $label = null) {
 1408+ global $sfgTabIndex;
14091409
1410 - $sfgTabIndex++;
1411 - $disabled_text = ($is_disabled) ? "disabled" : "";
1412 - if ($label == null)
1413 - $label = wfMsgExt('minoredit', array('parseinline'));
1414 - $accesskey = wfMsg('accesskey-minoredit');
1415 - $tooltip = wfMsg('tooltip-minoredit');
1416 - $text =<<<END
 1410+ $sfgTabIndex++;
 1411+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1412+ if ($label == null)
 1413+ $label = wfMsgExt('minoredit', array('parseinline'));
 1414+ $accesskey = wfMsg('accesskey-minoredit');
 1415+ $tooltip = wfMsg('tooltip-minoredit');
 1416+ $text =<<<END
14171417 <input tabindex="$sfgTabIndex" type="checkbox" value="1" name="wpMinoredit" accesskey="$accesskey" id="wpMinoredit" $disabled_text/>
14181418 <label for="wpMinoredit" title="$tooltip">$label</label>
14191419
14201420 END;
1421 - return $text;
1422 - }
 1421+ return $text;
 1422+ }
14231423
1424 - function watchInputHTML($is_disabled, $label = null) {
1425 - global $sfgTabIndex, $wgUser;
 1424+ function watchInputHTML($is_disabled, $label = null) {
 1425+ global $sfgTabIndex, $wgUser;
14261426
1427 - $sfgTabIndex++;
1428 - $checked_text = "";
1429 - $disabled_text = ($is_disabled) ? "disabled" : "";
1430 - // figure out if the checkbox should be checked -
1431 - // this code borrowed from /includes/EditPage.php
1432 - if ($wgUser->getOption('watchdefault')) {
1433 - # Watch all edits
1434 - $checked_text = "checked";
1435 - } elseif ($wgUser->getOption('watchcreations') && !$this->mPageTitle->exists() ) {
1436 - # Watch creations
1437 - $checked_text = "checked";
1438 - } elseif ($this->mPageTitle->userIsWatching()) {
1439 - # Already watched
1440 - $checked_text = "checked";
1441 - }
1442 - if ($label == null)
1443 - $label = wfMsgExt('watchthis', array('parseinline'));
1444 - $accesskey = htmlspecialchars(wfMsg('accesskey-watch'));
1445 - $tooltip = htmlspecialchars(wfMsg('tooltip-watch'));
1446 - $text =<<<END
 1427+ $sfgTabIndex++;
 1428+ $checked_text = "";
 1429+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1430+ // figure out if the checkbox should be checked -
 1431+ // this code borrowed from /includes/EditPage.php
 1432+ if ($wgUser->getOption('watchdefault')) {
 1433+ # Watch all edits
 1434+ $checked_text = "checked";
 1435+ } elseif ($wgUser->getOption('watchcreations') && !$this->mPageTitle->exists() ) {
 1436+ # Watch creations
 1437+ $checked_text = "checked";
 1438+ } elseif ($this->mPageTitle->userIsWatching()) {
 1439+ # Already watched
 1440+ $checked_text = "checked";
 1441+ }
 1442+ if ($label == null)
 1443+ $label = wfMsgExt('watchthis', array('parseinline'));
 1444+ $accesskey = htmlspecialchars(wfMsg('accesskey-watch'));
 1445+ $tooltip = htmlspecialchars(wfMsg('tooltip-watch'));
 1446+ $text =<<<END
14471447 <input tabindex="$sfgTabIndex" type="checkbox" name="wpWatchthis" accesskey="$accesskey" id='wpWatchthis' $checked_text $disabled_text/>
1448 - <label for="wpWatchthis" title="$tooltip">$label</label>
 1448+ <label for="wpWatchthis" title="$tooltip">$label</label>
14491449
14501450 END;
1451 - return $text;
1452 - }
 1451+ return $text;
 1452+ }
14531453
1454 - function saveButtonHTML($is_disabled, $label = null) {
1455 - global $sfgTabIndex;
 1454+ function saveButtonHTML($is_disabled, $label = null) {
 1455+ global $sfgTabIndex;
14561456
1457 - $sfgTabIndex++;
1458 - $disabled_text = ($is_disabled) ? "disabled" : "";
1459 - if ($label == null)
1460 - $label = wfMsg('savearticle');
1461 - $temp = array(
1462 - 'id' => 'wpSave',
1463 - 'name' => 'wpSave',
1464 - 'type' => 'submit',
1465 - 'tabindex' => $sfgTabIndex,
1466 - 'value' => $label,
1467 - 'accesskey' => wfMsg('accesskey-save'),
1468 - 'title' => wfMsg('tooltip-save'),
1469 - $disabled_text => '',
1470 - );
1471 - $text = " " . wfElement('input', $temp, '') . "\n";
1472 - return $text;
1473 - }
 1457+ $sfgTabIndex++;
 1458+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1459+ if ($label == null)
 1460+ $label = wfMsg('savearticle');
 1461+ $temp = array(
 1462+ 'id' => 'wpSave',
 1463+ 'name' => 'wpSave',
 1464+ 'type' => 'submit',
 1465+ 'tabindex' => $sfgTabIndex,
 1466+ 'value' => $label,
 1467+ 'accesskey' => wfMsg('accesskey-save'),
 1468+ 'title' => wfMsg('tooltip-save'),
 1469+ $disabled_text => '',
 1470+ );
 1471+ $text = " " . wfElement('input', $temp, '') . "\n";
 1472+ return $text;
 1473+ }
14741474
1475 - function showPreviewButtonHTML($is_disabled, $label = null) {
1476 - global $sfgTabIndex;
 1475+ function showPreviewButtonHTML($is_disabled, $label = null) {
 1476+ global $sfgTabIndex;
14771477
1478 - $sfgTabIndex++;
1479 - $disabled_text = ($is_disabled) ? "disabled" : "";
1480 - if ($label == null)
1481 - $label = wfMsg('showpreview');
1482 - $temp = array(
1483 - 'id' => 'wpPreview',
1484 - 'name' => 'wpPreview',
1485 - 'type' => 'submit',
1486 - 'tabindex' => $sfgTabIndex,
1487 - 'value' => $label,
1488 - 'accesskey' => wfMsg('accesskey-preview'),
1489 - 'title' => wfMsg('tooltip-preview'),
1490 - $disabled_text => '',
1491 - );
1492 - $text = " " . wfElement('input', $temp, '') . "\n";
1493 - return $text;
1494 - }
 1478+ $sfgTabIndex++;
 1479+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1480+ if ($label == null)
 1481+ $label = wfMsg('showpreview');
 1482+ $temp = array(
 1483+ 'id' => 'wpPreview',
 1484+ 'name' => 'wpPreview',
 1485+ 'type' => 'submit',
 1486+ 'tabindex' => $sfgTabIndex,
 1487+ 'value' => $label,
 1488+ 'accesskey' => wfMsg('accesskey-preview'),
 1489+ 'title' => wfMsg('tooltip-preview'),
 1490+ $disabled_text => '',
 1491+ );
 1492+ $text = " " . wfElement('input', $temp, '') . "\n";
 1493+ return $text;
 1494+ }
14951495
1496 - function showChangesButtonHTML($is_disabled, $label = null) {
1497 - global $sfgTabIndex;
 1496+ function showChangesButtonHTML($is_disabled, $label = null) {
 1497+ global $sfgTabIndex;
14981498
1499 - $sfgTabIndex++;
1500 - $disabled_text = ($is_disabled) ? "disabled" : "";
1501 - if ($label == null)
1502 - $label = wfMsg('showdiff');
1503 - $temp = array(
1504 - 'id' => 'wpDiff',
1505 - 'name' => 'wpDiff',
1506 - 'type' => 'submit',
1507 - 'tabindex' => $sfgTabIndex,
1508 - 'value' => $label,
1509 - 'accesskey' => wfMsg('accesskey-diff'),
1510 - 'title' => wfMsg('tooltip-diff'),
1511 - $disabled_text => '',
1512 - );
1513 - $text = " " . wfElement('input', $temp, '') . "\n";
1514 - return $text;
1515 - }
 1499+ $sfgTabIndex++;
 1500+ $disabled_text = ($is_disabled) ? "disabled" : "";
 1501+ if ($label == null)
 1502+ $label = wfMsg('showdiff');
 1503+ $temp = array(
 1504+ 'id' => 'wpDiff',
 1505+ 'name' => 'wpDiff',
 1506+ 'type' => 'submit',
 1507+ 'tabindex' => $sfgTabIndex,
 1508+ 'value' => $label,
 1509+ 'accesskey' => wfMsg('accesskey-diff'),
 1510+ 'title' => wfMsg('tooltip-diff'),
 1511+ $disabled_text => '',
 1512+ );
 1513+ $text = " " . wfElement('input', $temp, '') . "\n";
 1514+ return $text;
 1515+ }
15161516
1517 - function cancelLinkHTML($is_disabled, $label = null) {
1518 - global $wgUser;
 1517+ function cancelLinkHTML($is_disabled, $label = null) {
 1518+ global $wgUser;
15191519
1520 - $sk = $wgUser->getSkin();
1521 - if ($label == null)
1522 - $label = wfMsgExt('cancel', array('parseinline'));
1523 - if ($this->mPageTitle == null)
1524 - $cancel = '';
1525 - else
1526 - $cancel = $sk->makeKnownLink( $this->mPageTitle->getPrefixedText(), $label);
1527 - $text = " <span class='editHelp'>$cancel</span>\n";
1528 - return $text;
1529 - }
 1520+ $sk = $wgUser->getSkin();
 1521+ if ($label == null)
 1522+ $label = wfMsgExt('cancel', array('parseinline'));
 1523+ if ($this->mPageTitle == null)
 1524+ $cancel = '';
 1525+ else
 1526+ $cancel = $sk->makeKnownLink( $this->mPageTitle->getPrefixedText(), $label);
 1527+ $text = " <span class='editHelp'>$cancel</span>\n";
 1528+ return $text;
 1529+ }
15301530
1531 - // Much of this function is based on MediaWiki's EditPage::showEditForm()
1532 - function formBottom($is_disabled) {
1533 - global $wgUser;
1534 -
1535 - $summary_text = $this->summaryInputHTML($is_disabled);
1536 - $text =<<<END
 1531+ // Much of this function is based on MediaWiki's EditPage::showEditForm()
 1532+ function formBottom($is_disabled) {
 1533+ global $wgUser;
 1534+
 1535+ $summary_text = $this->summaryInputHTML($is_disabled);
 1536+ $text =<<<END
15371537 <br /><br />
15381538 <div class='editOptions'>
1539 -$summary_text <br />
 1539+$summary_text <br />
15401540
15411541 END;
1542 - if ( $wgUser->isAllowed('minoredit') ) {
1543 - $text .= $this->minorEditInputHTML($is_disabled);
1544 - }
 1542+ if ( $wgUser->isAllowed('minoredit') ) {
 1543+ $text .= $this->minorEditInputHTML($is_disabled);
 1544+ }
15451545
1546 - if ( $wgUser->isLoggedIn() ) {
1547 - $text .= $this->watchInputHTML($is_disabled);
1548 - }
 1546+ if ( $wgUser->isLoggedIn() ) {
 1547+ $text .= $this->watchInputHTML($is_disabled);
 1548+ }
15491549
1550 - $text .=<<<END
 1550+ $text .=<<<END
15511551 <br />
15521552 <div class='editButtons'>
15531553
15541554 END;
1555 - $text .= $this->saveButtonHTML($is_disabled);
1556 - $text .= $this->showPreviewButtonHTML($is_disabled);
1557 - $text .= $this->showChangesButtonHTML($is_disabled);
1558 - $text .= $this->cancelLinkHTML($is_disabled);
1559 - $text .=<<<END
 1555+ $text .= $this->saveButtonHTML($is_disabled);
 1556+ $text .= $this->showPreviewButtonHTML($is_disabled);
 1557+ $text .= $this->showChangesButtonHTML($is_disabled);
 1558+ $text .= $this->cancelLinkHTML($is_disabled);
 1559+ $text .=<<<END
15601560 </div><!-- editButtons -->
15611561 </div><!-- editOptions -->
15621562
15631563 END;
1564 - return $text;
1565 - }
 1564+ return $text;
 1565+ }
15661566
1567 - // based on MediaWiki's EditPage::getPreloadedText()
1568 - function getPreloadedText($preload) {
1569 - if ( $preload === '' ) {
1570 - return '';
1571 - } else {
1572 - $preloadTitle = Title::newFromText( $preload );
1573 - if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
1574 - $rev = Revision::newFromTitle($preloadTitle);
1575 - if ( is_object( $rev ) ) {
1576 - $text = $rev->getText();
1577 - // Remove <noinclude> sections and <includeonly> tags from text
1578 - $text = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $text);
1579 - $text = strtr($text, array('<includeonly>' => '', '</includeonly>' => ''));
1580 - return $text;
1581 - }
1582 - }
1583 - return '';
1584 - }
1585 - }
 1567+ // based on MediaWiki's EditPage::getPreloadedText()
 1568+ function getPreloadedText($preload) {
 1569+ if ( $preload === '' ) {
 1570+ return '';
 1571+ } else {
 1572+ $preloadTitle = Title::newFromText( $preload );
 1573+ if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
 1574+ $rev = Revision::newFromTitle($preloadTitle);
 1575+ if ( is_object( $rev ) ) {
 1576+ $text = $rev->getText();
 1577+ // Remove <noinclude> sections and <includeonly> tags from text
 1578+ $text = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $text);
 1579+ $text = strtr($text, array('<includeonly>' => '', '</includeonly>' => ''));
 1580+ return $text;
 1581+ }
 1582+ }
 1583+ return '';
 1584+ }
 1585+ }
15861586
15871587 }
1588 -
1589 -?>
Index: trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php
@@ -536,37 +536,37 @@
537537 }
538538
539539 function sffGetAllPagesForProperty_orig($is_relation, $property_name, $substring = null) {
540 - global $sfgMaxAutocompleteValues;
 540+ global $sfgMaxAutocompleteValues;
541541
542 - $fname = "sffGetAllPagesForProperty_orig";
543 - $pages = array();
544 - $db = wfGetDB( DB_SLAVE );
545 - $sql_options = array();
546 - $sql_options['LIMIT'] = $sfgMaxAutocompleteValues;
547 - $property_field = ($is_relation) ? 'relation_title' : 'attribute_title';
548 - $value_field = ($is_relation) ? 'object_title' : 'value_xsd';
549 - $property_table = ($is_relation) ? 'smw_relations' : 'smw_attributes';
550 - $conditions = "$property_field = '$property_name'";
551 - if ($substring != null) {
552 - $substring = str_replace(' ', '_', strtolower($substring));
553 - $substring = str_replace('_', '\_', $substring);
554 - $substring = str_replace("'", "\'", $substring);
555 - $conditions .= " AND (LOWER($value_field) LIKE '" . $substring . "%' OR LOWER($value_field) LIKE '%\_" . $substring . "%')";
556 - }
557 - $sql_options['ORDER BY'] = $value_field;
558 - $res = $db->select( $db->tableName($property_table),
559 - "DISTINCT $value_field",
560 - $conditions, $fname, $sql_options);
561 - while ($row = $db->fetchRow($res)) {
562 - if ($substring != null)
563 - $pages[] = array('title' => str_replace('_', ' ', $row[0]));
564 - else {
565 - $cur_value = str_replace("'", "\'", $row[0]);
566 - $pages[] = str_replace('_', ' ', $cur_value);
567 - }
568 - }
569 - $db->freeResult($res);
570 - return $pages;
 542+ $fname = "sffGetAllPagesForProperty_orig";
 543+ $pages = array();
 544+ $db = wfGetDB( DB_SLAVE );
 545+ $sql_options = array();
 546+ $sql_options['LIMIT'] = $sfgMaxAutocompleteValues;
 547+ $property_field = ($is_relation) ? 'relation_title' : 'attribute_title';
 548+ $value_field = ($is_relation) ? 'object_title' : 'value_xsd';
 549+ $property_table = ($is_relation) ? 'smw_relations' : 'smw_attributes';
 550+ $conditions = "$property_field = '$property_name'";
 551+ if ($substring != null) {
 552+ $substring = str_replace(' ', '_', strtolower($substring));
 553+ $substring = str_replace('_', '\_', $substring);
 554+ $substring = str_replace("'", "\'", $substring);
 555+ $conditions .= " AND (LOWER($value_field) LIKE '" . $substring . "%' OR LOWER($value_field) LIKE '%\_" . $substring . "%')";
 556+ }
 557+ $sql_options['ORDER BY'] = $value_field;
 558+ $res = $db->select( $db->tableName($property_table),
 559+ "DISTINCT $value_field",
 560+ $conditions, $fname, $sql_options);
 561+ while ($row = $db->fetchRow($res)) {
 562+ if ($substring != null) {
 563+ $pages[] = array('title' => str_replace('_', ' ', $row[0]));
 564+ } else {
 565+ $cur_value = str_replace("'", "\'", $row[0]);
 566+ $pages[] = str_replace('_', ' ', $cur_value);
 567+ }
 568+ }
 569+ $db->freeResult($res);
 570+ return $pages;
571571 }
572572
573573 function sffGetAllPagesForProperty_1_2($property_name, $substring = null) {
@@ -609,64 +609,64 @@
610610 * SMWInlineQuery::includeSubcategories()
611611 */
612612 function sffGetAllPagesForCategory($top_category, $num_levels, $substring = null) {
613 - if (0 == $num_levels) return $top_category;
614 - global $sfgMaxAutocompleteValues;
 613+ if (0 == $num_levels) return $top_category;
 614+ global $sfgMaxAutocompleteValues;
615615
616 - $db = wfGetDB( DB_SLAVE );
617 - $fname = "sffGetAllPagesForCategory";
618 - $categories = array($top_category);
619 - $checkcategories = array($top_category);
620 - $pages = array();
621 - for ($level = $num_levels; $level > 0; $level--) {
622 - $newcategories = array();
623 - foreach ($checkcategories as $category) {
624 - if ($substring != null) {
625 - $substring = str_replace(' ', '_', strtolower($substring));
626 - $substring = str_replace('_', '\_', $substring);
627 - $substring = str_replace("'", "\'", $substring);
628 - $conditions = 'cl_to = '. $db->addQuotes($category) . " AND (LOWER(page_title) LIKE '" . $substring . "%' OR LOWER(page_title) LIKE '%\_" . $substring . "%')";
629 - } else {
630 - $conditions = 'cl_to = '. $db->addQuotes($category);
631 - }
632 - $res = $db->select( // make the query
633 - array('categorylinks', 'page'),
634 - array('page_title', 'page_namespace'),
635 - array('cl_from = page_id', $conditions),
636 - $fname);
637 - if ($res) {
638 - while ($res && $row = $db->fetchRow($res)) {
639 - if (array_key_exists('page_title', $row)) {
640 - $page_namespace = $row['page_namespace'];
641 - if ($page_namespace == NS_CATEGORY) {
642 - $new_category = $row[ 'page_title' ];
643 - if (!in_array($new_category, $categories)) {
644 - $newcategories[] = $new_category;
645 - }
646 - } else {
647 - $cur_value = str_replace("_", " ", $row['page_title']);
648 - if ($substring == null)
649 - $pages[] = str_replace("'", "\'", $cur_value);
650 - else
651 - $pages[] = array('title' => $cur_value);
652 - // return if we've reached the maximum number of allowed values
653 - if (count($pages) > $sfgMaxAutocompleteValues)
654 - return $pages;
655 - }
656 - }
657 - }
658 - $db->freeResult( $res );
659 - }
660 - }
661 - if (count($newcategories) == 0) {
662 - sort($pages);
663 - return $pages;
664 - } else {
665 - $categories = array_merge($categories, $newcategories);
666 - }
667 - $checkcategories = array_diff($newcategories, array());
668 - }
669 - sort($pages);
670 - return $pages;
 616+ $db = wfGetDB( DB_SLAVE );
 617+ $fname = "sffGetAllPagesForCategory";
 618+ $categories = array($top_category);
 619+ $checkcategories = array($top_category);
 620+ $pages = array();
 621+ for ($level = $num_levels; $level > 0; $level--) {
 622+ $newcategories = array();
 623+ foreach ($checkcategories as $category) {
 624+ if ($substring != null) {
 625+ $substring = str_replace(' ', '_', strtolower($substring));
 626+ $substring = str_replace('_', '\_', $substring);
 627+ $substring = str_replace("'", "\'", $substring);
 628+ $conditions = 'cl_to = '. $db->addQuotes($category) . " AND (LOWER(page_title) LIKE '" . $substring . "%' OR LOWER(page_title) LIKE '%\_" . $substring . "%')";
 629+ } else {
 630+ $conditions = 'cl_to = '. $db->addQuotes($category);
 631+ }
 632+ $res = $db->select( // make the query
 633+ array('categorylinks', 'page'),
 634+ array('page_title', 'page_namespace'),
 635+ array('cl_from = page_id', $conditions),
 636+ $fname);
 637+ if ($res) {
 638+ while ($res && $row = $db->fetchRow($res)) {
 639+ if (array_key_exists('page_title', $row)) {
 640+ $page_namespace = $row['page_namespace'];
 641+ if ($page_namespace == NS_CATEGORY) {
 642+ $new_category = $row[ 'page_title' ];
 643+ if (!in_array($new_category, $categories)) {
 644+ $newcategories[] = $new_category;
 645+ }
 646+ } else {
 647+ $cur_value = str_replace("_", " ", $row['page_title']);
 648+ if ($substring == null)
 649+ $pages[] = str_replace("'", "\'", $cur_value);
 650+ else
 651+ $pages[] = array('title' => $cur_value);
 652+ // return if we've reached the maximum number of allowed values
 653+ if (count($pages) > $sfgMaxAutocompleteValues)
 654+ return $pages;
 655+ }
 656+ }
 657+ }
 658+ $db->freeResult( $res );
 659+ }
 660+ }
 661+ if (count($newcategories) == 0) {
 662+ sort($pages);
 663+ return $pages;
 664+ } else {
 665+ $categories = array_merge($categories, $newcategories);
 666+ }
 667+ $checkcategories = array_diff($newcategories, array());
 668+ }
 669+ sort($pages);
 670+ return $pages;
671671 }
672672
673673 function sffGetAllPagesForConcept($concept_name, $substring = null) {
@@ -697,39 +697,39 @@
698698 }
699699
700700 function sffGetAllPagesForNamespace($namespace_name, $substring = null) {
701 - // cycle through all the namespace names for this language, and if
702 - // one matches the namespace specified in the form, add the names
703 - // of all the pages in that namespace to $names_array
704 - global $wgContLang;
705 - $namespaces = $wgContLang->getNamespaces();
706 - $db = wfGetDB( DB_SLAVE );
707 - $fname = "sffGetAllPagesForNamespace";
708 - $pages = array();
709 - foreach ($namespaces as $ns_code => $ns_name) {
710 - if ($ns_name == $namespace_name) {
711 - $conditions = "page_namespace = $ns_code";
712 - if ($substring != null) {
713 - $substring = str_replace(' ', '_', strtolower($substring));
714 - $substring = str_replace('_', '\_', $substring);
715 - $substring = str_replace("'", "\'", $substring);
716 - $conditions .= " AND (LOWER(page_title) LIKE '$substring%' OR LOWER(page_title) LIKE '%\_$substring%')";
717 - }
718 - $sql_options['ORDER BY'] = 'page_title';
719 - $res = $db->select( $db->tableNames('page'),
720 - 'page_title',
721 - $conditions, $fname, $sql_options);
722 - while ($row = $db->fetchRow($res)) {
723 - $cur_value = str_replace('_', ' ', $row[0]);
724 - if ($substring == null) {
725 - $pages[] = str_replace("'", "\'", $cur_value);
726 - } else {
727 - $pages[] = array('title' => $cur_value);
728 - }
729 - }
730 - $db->freeResult($res);
731 - }
732 - }
733 - return $pages;
 701+ // cycle through all the namespace names for this language, and if
 702+ // one matches the namespace specified in the form, add the names
 703+ // of all the pages in that namespace to $names_array
 704+ global $wgContLang;
 705+ $namespaces = $wgContLang->getNamespaces();
 706+ $db = wfGetDB( DB_SLAVE );
 707+ $fname = "sffGetAllPagesForNamespace";
 708+ $pages = array();
 709+ foreach ($namespaces as $ns_code => $ns_name) {
 710+ if ($ns_name == $namespace_name) {
 711+ $conditions = "page_namespace = $ns_code";
 712+ if ($substring != null) {
 713+ $substring = str_replace(' ', '_', strtolower($substring));
 714+ $substring = str_replace('_', '\_', $substring);
 715+ $substring = str_replace("'", "\'", $substring);
 716+ $conditions .= " AND (LOWER(page_title) LIKE '$substring%' OR LOWER(page_title) LIKE '%\_$substring%')";
 717+ }
 718+ $sql_options['ORDER BY'] = 'page_title';
 719+ $res = $db->select( $db->tableNames('page'),
 720+ 'page_title',
 721+ $conditions, $fname, $sql_options);
 722+ while ($row = $db->fetchRow($res)) {
 723+ $cur_value = str_replace('_', ' ', $row[0]);
 724+ if ($substring == null) {
 725+ $pages[] = str_replace("'", "\'", $cur_value);
 726+ } else {
 727+ $pages[] = array('title' => $cur_value);
 728+ }
 729+ }
 730+ $db->freeResult($res);
 731+ }
 732+ }
 733+ return $pages;
734734 }
735735
736736 // Custom sort function, used in sffGetAllProperties()
Index: trunk/extensions/SemanticForms/includes/SF_FormEditTab.php
@@ -6,67 +6,65 @@
77 * Adds an "action" (i.e., a tab) to edit the current article with a form
88 */
99 function sffFormEditTab($obj, $content_actions) {
10 - $fname = 'SFFormEditTab';
11 - // make sure that this is not itself a category page, and that the user
12 - // is allowed to edit it
13 - if (isset($obj->mTitle) && ($obj->mTitle->getNamespace() != NS_CATEGORY)) {
14 - $form_name = sffGetFormForArticle($obj);
15 - if ($form_name) {
16 - global $wgRequest, $wgUser;
17 - global $sfgRenameEditTabs;
 10+ $fname = 'SFFormEditTab';
 11+ // make sure that this is not itself a category page, and that the user
 12+ // is allowed to edit it
 13+ if (isset($obj->mTitle) && ($obj->mTitle->getNamespace() != NS_CATEGORY)) {
 14+ $form_name = sffGetFormForArticle($obj);
 15+ if ($form_name) {
 16+ global $wgRequest, $wgUser;
 17+ global $sfgRenameEditTabs;
1818
19 - $user_can_edit = $wgUser->isAllowed('edit') && $obj->mTitle->userCanEdit();
20 - // create the form edit tab, and apply whatever changes are specified
21 - // by the edit-tab global variables
22 - if ($sfgRenameEditTabs) {
23 - $form_edit_tab_text = $user_can_edit ? wfMsg('edit') : wfMsg('sf_viewform');
24 - if (array_key_exists('edit', $content_actions)) {
25 - $content_actions['edit']['text'] = $user_can_edit ? wfMsg('sf_editsource') : wfMsg('viewsource');
26 - }
27 - } else {
28 - $form_edit_tab_text = $user_can_edit ? wfMsg('sf_formedit') : wfMsg('sf_viewform');
29 - }
 19+ $user_can_edit = $wgUser->isAllowed('edit') && $obj->mTitle->userCanEdit();
 20+ // create the form edit tab, and apply whatever changes are specified
 21+ // by the edit-tab global variables
 22+ if ($sfgRenameEditTabs) {
 23+ $form_edit_tab_text = $user_can_edit ? wfMsg('edit') : wfMsg('sf_viewform');
 24+ if (array_key_exists('edit', $content_actions)) {
 25+ $content_actions['edit']['text'] = $user_can_edit ? wfMsg('sf_editsource') : wfMsg('viewsource');
 26+ }
 27+ } else {
 28+ $form_edit_tab_text = $user_can_edit ? wfMsg('sf_formedit') : wfMsg('sf_viewform');
 29+ }
3030
31 - $class_name = ($wgRequest->getVal('action') == 'formedit') ? 'selected' : '';
32 - $form_edit_tab = array(
33 - 'class' => $class_name,
34 - 'text' => $form_edit_tab_text,
35 - 'href' => $obj->mTitle->getLocalURL('action=formedit')
36 - );
 31+ $class_name = ($wgRequest->getVal('action') == 'formedit') ? 'selected' : '';
 32+ $form_edit_tab = array(
 33+ 'class' => $class_name,
 34+ 'text' => $form_edit_tab_text,
 35+ 'href' => $obj->mTitle->getLocalURL('action=formedit')
 36+ );
3737
38 - // find the location of the 'edit' tab, and add 'edit with form'
39 - // right before it.
40 - // this is a "key-safe" splice - it preserves both the keys and
41 - // the values of the array, by editing them separately and then
42 - // rebuilding the array.
43 - // based on the example at http://us2.php.net/manual/en/function.array-splice.php#31234
44 - $tab_keys = array_keys($content_actions);
45 - $tab_values = array_values($content_actions);
46 - $edit_tab_location = array_search('edit', $tab_keys);
47 - // if there's no 'edit' tab, look for the 'view source' tab instead
48 - if ($edit_tab_location == NULL)
49 - $edit_tab_location = array_search('viewsource', $tab_keys);
50 - // this should rarely happen, but if there was no edit *or* view source
51 - // tab, set the location index to -1, so the tab shows up near the end
52 - if ($edit_tab_location == NULL)
53 - $edit_tab_location = -1;
54 - array_splice($tab_keys, $edit_tab_location, 0, 'form_edit');
55 - array_splice($tab_values, $edit_tab_location, 0, array($form_edit_tab));
56 - $content_actions = array();
57 - for ($i = 0; $i < count($tab_keys); $i++)
58 - $content_actions[$tab_keys[$i]] = $tab_values[$i];
 38+ // find the location of the 'edit' tab, and add 'edit with form'
 39+ // right before it.
 40+ // this is a "key-safe" splice - it preserves both the keys and
 41+ // the values of the array, by editing them separately and then
 42+ // rebuilding the array.
 43+ // based on the example at http://us2.php.net/manual/en/function.array-splice.php#31234
 44+ $tab_keys = array_keys($content_actions);
 45+ $tab_values = array_values($content_actions);
 46+ $edit_tab_location = array_search('edit', $tab_keys);
 47+ // if there's no 'edit' tab, look for the 'view source' tab instead
 48+ if ($edit_tab_location == NULL)
 49+ $edit_tab_location = array_search('viewsource', $tab_keys);
 50+ // this should rarely happen, but if there was no edit *or* view source
 51+ // tab, set the location index to -1, so the tab shows up near the end
 52+ if ($edit_tab_location == NULL)
 53+ $edit_tab_location = -1;
 54+ array_splice($tab_keys, $edit_tab_location, 0, 'form_edit');
 55+ array_splice($tab_values, $edit_tab_location, 0, array($form_edit_tab));
 56+ $content_actions = array();
 57+ for ($i = 0; $i < count($tab_keys); $i++)
 58+ $content_actions[$tab_keys[$i]] = $tab_values[$i];
5959
60 - global $wgUser;
61 - if (! $wgUser->isAllowed('viewedittab')) {
62 - // the tab can have either of those two actions
63 - unset($content_actions['edit']);
64 - unset($content_actions['viewsource']);
65 - }
 60+ global $wgUser;
 61+ if (! $wgUser->isAllowed('viewedittab')) {
 62+ // the tab can have either of those two actions
 63+ unset($content_actions['edit']);
 64+ unset($content_actions['viewsource']);
 65+ }
6666
67 - return true;
68 - }
69 - }
70 - return true; // always return true, in order not to stop MW's hook processing!
 67+ return true;
 68+ }
 69+ }
 70+ return true; // always return true, in order not to stop MW's hook processing!
7171 }
72 -
73 -?>
Index: trunk/extensions/SemanticForms/includes/SF_Settings.php
@@ -37,9 +37,9 @@
3838 # than 150.
3939 ##
4040 if (!isset($sfgNamespaceIndex)) {
41 - sffInitNamespaces(150);
 41+ sffInitNamespaces(150);
4242 } else {
43 - sffInitNamespaces();
 43+ sffInitNamespaces();
4444 }
4545
4646 ###
@@ -74,4 +74,3 @@
7575 ###
7676 $sfgYUIBase = "http://yui.yahooapis.com/2.5.1/build/";
7777
78 -?>

Status & tagging log