r96899 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96898‎ | r96899 | r96900 >
Date:20:40, 12 September 2011
Author:yaron
Status:deferred
Tags:
Comment:
Rewrote some of the Page Schemas-interfacing code: names and structure of the hooks changed
Modified paths:
  • /trunk/extensions/SemanticForms/SemanticForms.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_Utils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/SemanticForms.php
@@ -91,15 +91,16 @@
9292 $wgHooks['ParserFirstCallInit'][] = 'SFParserFunctions::registerFunctions';
9393 $wgHooks['MakeGlobalVariablesScript'][] = 'SFFormUtils::setGlobalJSVariables';
9494
95 -//PSSchema Hooks
96 -$wgHooks['PageSchemasGetObject'][] = 'SFUtils::createPageSchemasObject' ; //Hook for returning PageSchema(extension) object from a given xml
97 -$wgHooks['PageSchemasGeneratePages'][] = 'SFUtils::generatePages' ; //Hook for creating Pages
98 -$wgHooks['PSParseFieldElements'][] = 'SFUtils::parseFieldElements' ; //Hook for creating Pages
99 -$wgHooks['PageSchemasGetPageList'][] = 'SFUtils::getPageList' ; //Hook for creating Pages
100 -$wgHooks['getHtmlTextForFieldInputs'][] = 'SFUtils::getHtmlTextForPS' ; //Hook for retuning html text to PS schema
 95+// Page Schemas extension hooks
 96+$wgHooks['PageSchemasGetObject'][] = 'SFUtils::createPageSchemasObject' ;
 97+$wgHooks['PageSchemasGeneratePages'][] = 'SFUtils::generatePages' ;
 98+$wgHooks['PSParseFieldElements'][] = 'SFUtils::parseFieldElements' ;
 99+$wgHooks['PageSchemasGetPageList'][] = 'SFUtils::getPageList' ;
 100+$wgHooks['PageSchemasGetSchemaHTML'][] = 'SFUtils::getSchemaHTMLForPS' ;
 101+$wgHooks['PageSchemasGetFieldHTML'][] = 'SFUtils::getFieldHTMLForPS' ;
101102 $wgHooks['PageSchemasGetSchemaXML'][] = 'SFUtils::getSchemaXMLForPS';
102103 $wgHooks['PageSchemasGetFieldXML'][] = 'SFUtils::getFieldXMLForPS';
103 -$wgHooks['getFilledHtmlTextForFieldInputs'][] = 'SFUtils::getFilledHtmlTextForPS' ; //Hook for retuning html text to PS schema
 104+//$wgHooks['getFilledHtmlTextForFieldInputs'][] = 'SFUtils::getFilledHtmlTextForPS' ;
104105
105106 $wgAPIModules['sfautocomplete'] = 'SFAutocompleteAPI';
106107 $wgAPIModules['sfautoedit'] = 'SFAutoeditAPI';
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php
@@ -3,6 +3,7 @@
44 * Helper functions for the Semantic Forms extension.
55 *
66 * @author Yaron Koren
 7+ * @author Ankit Garg
78 * @file
89 * @ingroup SF
910 */
@@ -193,13 +194,13 @@
194195
195196 public static function getSchemaXMLForPS( $request, &$xmlArray ) {
196197 foreach ( $request->getValues() as $var => $val ) {
197 - if ( substr( $var, 0, 13) == 'sf_form_name_' ) {
 198+ if ( $var == 'sf_form_name' ) {
198199 $xml = '<semanticforms_Form name="'.$val.'" >';
199 - } elseif ( substr( $var, 0, 21 ) == 'sf_page_name_formula_') {
 200+ } elseif ( $var == 'sf_page_name_formula' ) {
200201 $xml .= '<PageNameFormula>'.$val.'</PageNameFormula>';
201 - } elseif ( substr( $var, 0, 16 ) == 'sf_create_title_' ) {
 202+ } elseif ( $var == 'sf_create_title' ) {
202203 $xml .= '<CreateTitle>'.$val.'</CreateTitle>';
203 - } elseif ( substr( $var, 0, 14 ) == 'sf_edit_title_' ) {
 204+ } elseif ( $var == 'sf_edit_title' ) {
204205 $xml .= '<EditTitle>'.$val.'</EditTitle>';
205206 $xml .= '</semanticforms_Form>';
206207 }
@@ -244,68 +245,79 @@
245246 return true;
246247 }
247248
248 - public static function getFilledHtmlTextForPS( $pageSchemaObj, &$text_extensions ) {
249 - $html_text = "";
250 - $template_all = $pageSchemaObj->getTemplates();
251 - $html_text_array = array();
252 - $form_html_text = "";
253 - $obj = $pageSchemaObj->getObject('semanticforms_Form');
 249+ public static function getSchemaHTMLForPS( $pageSchemaObj, &$text_extensions ) {
 250+ if ( is_null( $pageSchemaObj ) ) {
 251+ $form_array = array();
 252+ } else {
 253+ $obj = $pageSchemaObj->getObject('semanticforms_Form');
 254+ $form_array = $obj['sf'];
 255+ }
 256+ if ( array_key_exists( 'name', $form_array ) ) {
 257+ $formName = $form_array['name'];
 258+ } else {
 259+ $formName = '';
 260+ }
 261+ $text = "\t<p>" . 'Name:' . ' ' . Html::input( 'sf_form_name', $formName, 'text', array( 'size' => 15 ) ) . "</p>\n";
 262+ if ( array_key_exists( 'PageNameFormula', $form_array ) ) {
 263+ $pageNameFormula = $form_array['PageNameFormula'];
 264+ } else {
 265+ $pageNameFormula = '';
 266+ }
 267+ $text .= "\t<p>" . 'Page name formula:' . ' ' . Html::input( 'sf_page_name_formula', $pageNameFormula, 'text', array( 'size' => 20 ) ) . "</p>\n";
 268+ if ( array_key_exists( 'CreateTitle', $form_array ) ) {
 269+ $createTitle = $form_array['CreateTitle'];
 270+ } else {
 271+ $createTitle = '';
 272+ }
 273+ $text .= "\t<p>" . 'Title of form for new pages:' . ' ' . Html::input( 'sf_create_title', $createTitle, 'text', array( 'size' => 25 ) ) . "</p>\n";
 274+ if ( array_key_exists( 'EditTitle', $form_array ) ) {
 275+ $editTitle = $form_array['EditTitle'];
 276+ } else {
 277+ $editTitle = '';
 278+ }
 279+ $text .= "\t<p>" . 'Title of form for existing pages:' . ' ' . Html::input( 'sf_edit_title', $editTitle, 'text', array( 'size' => 25 ) ) . "</p>\n";
 280+ $text_extensions['sf'] = array( 'Form', '#CF9', $text );
254281
255 - $form_array = $obj['sf'];
 282+ return true;
 283+ }
256284
257 - $form_html_text .= '<fieldset style="background: #CF9;"><legend>Form</legend>
258 - <p> Name: <input size="15" name="sf_form_name_starter" value= "'.$form_array['name'].'" ></p>
259 - <p> Page name formula: <input size="20" name="sf_page_name_formula_starter" value="'.$form_array['PageNameFormula'].'" ></p>
260 - <p> Title of form for new pages: <input size="25" name="sf_create_title_starter" value="'.$form_array['CreateTitle'].'" ></p>
261 - <p> Title of form for existing pages: <input size="25" name="sf_edit_title_starter" value="'.$form_array['EditTitle'].'" ></p>
262 - </fieldset>';
263 - foreach ( $template_all as $template ) {
264 - $field_all = $template->getFields();
265 - $field_count = 0; //counts the number of fields
 285+ public static function getFieldHTMLForPS( $field, &$text_extensions ) {
 286+ if ( is_null( $field ) ) {
 287+ $fieldValues = array();
 288+ } else {
 289+ $sf_array = $field->getObject('semanticforms_FormInput'); //this returns an array with property values filled
 290+ if ( array_key_exists( 'sf', $sf_array ) ) {
 291+ $fieldValues = $sf_array['sf'];
 292+ } else {
 293+ $fieldValues = array();
 294+ }
 295+ }
266296
267 - foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type
268 - $field_count++;
269 - $sf_array = $field->getObject('semanticforms_FormInput');//this returns an array with property values filled
270 - $form_input_array = $sf_array['sf'];
271 - $html_text = '<fieldset style="background: #CF9;"><legend>Form input</legend>
272 - <p> Input type: <input size="15" name="sf_input_type_starter" value='.$form_input_array['InputType'].'></p>
273 - <p>Parameter name and its value as a key=value pair,seperated by comma (if a value contains a comma, replace it with "\,"): For eg. Size=20,mandatory=true</p>';
274 - $param_value_str= "";
275 - foreach($form_input_array as $param => $value) {
276 - if ( $param != 'InputType' ) {
277 - if ( $value != null ) {
278 - $param_value_str .= $param.'='.$value.', ';
279 - } else {
280 - $param_value_str .= $param.'=true, ';
281 - }
282 - }
 297+ if ( array_key_exists( 'InputType', $fieldValues ) ) {
 298+ $inputType = $fieldValues['InputType'];
 299+ } else {
 300+ $inputType = '';
 301+ }
 302+ $inputTypeAttrs = array( 'size' => 15 );
 303+ $inputTypeInput = Html::input( 'sf_input_type_num', $inputType, 'text', $inputTypeAttrs );
 304+ $text = '<p>Input type: ' . $inputTypeInput . '</p>';
 305+ $text .= "\t" . '<p>Parameter name and its value as a key=value pair, separated by commas (if a value contains a comma, replace it with "\,"): For example: size=20,mandatory</p>' . "\n";
 306+ $paramValues = array();
 307+ foreach ( $fieldValues as $param => $value ) {
 308+ if ( !empty( $param ) && $param != 'InputType' ) {
 309+ if ( !empty( $value ) ) {
 310+ $paramValues[] = $param . '=' . $value;
 311+ } else {
 312+ $paramValues[] = $param;
283313 }
284 - $html_text .= '<p><input name="sf_key_values_starter" size="80" value="'.$param_value_str.'" ></fieldset></p>';
285 - $html_text_array[] = $html_text;
286314 }
287315 }
288 - $text_extensions['sf'] = $html_text_array;
289 - $text_extensions['sf_form']= $form_html_text;
290 - return true;
291 - }
 316+ $param_value_str = implode( ', ', $paramValues );
 317+ $inputParamsAttrs = array( 'size' => 80 );
 318+ $inputParamsInput = Html::input( 'sf_key_values_num', $param_value_str, 'text', $inputParamsAttrs );
 319+ $text .= "\t<p>$inputParamsInput</p>\n";
 320+ $text_extensions['sf'] = array( 'Form input', '#CF9', $text );
292321
293 - public static function getHtmlTextForPS( &$js_extensions ,&$text_extensions ) {
294 - $html_text = "";
295 - $form_text = "" ;
296 - $form_text .= '<fieldset style="background: #CF9;"><legend>Form</legend>
297 - <p> Name: <input size="15" name="sf_form_name_starter"></p>
298 - <p> Page name formula: <input size="20" name="sf_page_name_formula_starter"></p>
299 - <p> Title of form for new pages: <input size="25" name="sf_create_title_starter"></p>
300 - <p> Title of form for existing pages: <input size="25" name="sf_edit_title_starter"></p>
301 - </fieldset>';
302 -
303 - $html_text .= '<fieldset style="background: #CF9;"> <legend>Form input</legend>
304 - <p> Input type: <input size="15" name="sf_input_type_starter"></p>
305 - <p>Parameter name and its value as a key=value pair,seperated by comma (if a value contains a comma, replace it with "\,"): For eg. Size=20,mandatory=true</p>
306 - <p><input value="" name="sf_key_values_starter" size="80"></p></fieldset>';
307 -
308 - $text_extensions['sf'] = $html_text;
309 - $text_extensions['sf_form'] = $form_text;
310322 return true;
311323 }
312324
@@ -713,8 +725,8 @@
714726 }
715727
716728 /**
717 - * Return an array of all form names on this wiki
718 - */
 729+ * Returns an array of all form names on this wiki.
 730+ */
719731 public static function getAllForms() {
720732 $dbr = wfGetDB( DB_SLAVE );
721733 $res = $dbr->select( 'page',