r95702 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95701‎ | r95702 | r95703 >
Date:21:35, 29 August 2011
Author:yaron
Status:deferred
Tags:
Comment:
Cleanup of formatting, especially for Page Schemas hook code
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_Utils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_Utils.php
@@ -151,12 +151,13 @@
152152 SMWPropertyValue::registerProperty( $id, $typeid, $label, true );
153153 }
154154 }
155 - /**
156 - * Function to return the Property based on the xml passed from the PageSchema extension
157 - */
 155+
 156+ /**
 157+ * Function to return the property based on the XML passed from the Page Schemas extension
 158+ */
158159 public static function createPageSchemasObject( $objectName, $xmlForField, &$object ) {
159 - $sfarray = array();
160 - $formName="";
 160+ $sfarray = array();
 161+ $formName="";
161162 if ( $objectName == "semanticforms_Form" ) {
162163 foreach ( $xmlForField->children() as $tag => $child ) {
163164 if ( $tag == $objectName ) {
@@ -174,41 +175,41 @@
175176 foreach ( $xmlForField->children() as $tag => $child ) {
176177 if ( $tag == $objectName ) {
177178 foreach ( $child->children() as $prop ) {
178 - if($prop->getName() == 'InputType'){
 179+ if ( $prop->getName() == 'InputType' ) {
179180 $sfarray[$prop->getName()] = (string)$prop;
180 - }else{
181 - //Remember these values can be null also. While polulating in the page text, take care of that.
 181+ } else {
 182+ //Remember these values can be null also. While polulating in the page text, take care of that.
182183 $sfarray[(string)$prop->attributes()->name] = (string)$prop;
183184 }
184 - }
 185+ }
185186 }
186187 }
187 - //Setting value specific to SF in 'sf' index.
 188+ //Setting value specific to SF in 'sf' index.
188189 $object['sf'] = $sfarray;
189190 }
190191 return true;
191192 }
192 - public static function getXMLTextForPS( $wgRequest, &$text_extensions ){
193 -
 193+
 194+ public static function getXMLTextForPS( $wgRequest, &$text_extensions ) {
194195 $Xmltext = "";
195196 $form_xml_text = "";
196197 $templateNum = -1;
197198 $xml_text_array = array();
198199 foreach ( $wgRequest->getValues() as $var => $val ) {
199 - if(substr($var,0,13) == 'sf_form_name_'){
200 - $form_xml_text .= '<semanticforms_Form name="'.$val.'" >';
201 - }else if(substr($var,0,14) == 'sf_input_type_'){
202 - $templateNum = substr($var,14,1);
 200+ if ( substr( $var, 0, 13) == 'sf_form_name_' ) {
 201+ $form_xml_text .= '<semanticforms_Form name="'.$val.'" >';
 202+ } elseif ( substr( $var, 0, 14 ) == 'sf_input_type_') {
 203+ $templateNum = substr( $var, 14, 1 );
203204 $Xmltext .= '<semanticforms_FormInput>';
204205 $Xmltext .= '<InputType>'.$val.'</InputType>';
205 - }else if(substr($var,0,21) == 'sf_page_name_formula_'){
 206+ } elseif ( substr( $var, 0, 21 ) == 'sf_page_name_formula_') {
206207 $form_xml_text .= '<PageNameFormula>'.$val.'</PageNameFormula>';
207 - }else if(substr($var,0,16) == 'sf_create_title_'){
 208+ } elseif ( substr( $var, 0, 16 ) == 'sf_create_title_' ) {
208209 $form_xml_text .= '<CreateTitle>'.$val.'</CreateTitle>';
209 - }else if(substr($var,0,14) == 'sf_edit_title_'){
 210+ } elseif ( substr( $var, 0, 14 ) == 'sf_edit_title_' ) {
210211 $form_xml_text .= '<EditTitle>'.$val.'</EditTitle>';
211212 $form_xml_text .= '</semanticforms_Form>';
212 - }else if(substr($var,0,14) == 'sf_key_values_'){
 213+ } elseif ( substr( $var, 0, 14 ) == 'sf_key_values_' ) {
213214 if ( $val != '' ) {
214215 // replace the comma substitution character that has no chance of
215216 // being included in the values list - namely, the ASCII beep
@@ -219,58 +220,58 @@
220221 // replace beep back with comma, trim
221222 $value = str_replace( "\a", $listSeparator, trim( $value ) );
222223 $param_value = explode( "=", $value );
223 - if($param_value[1] != null ) {
224 - //handles Parameter name="size">20</Parameter>
 224+ if ( $param_value[1] != null ) {
 225+ //handles Parameter name="size">20</Parameter>
225226 $Xmltext .= '<Parameter name="'.$param_value[0].'">'.$param_value[1].'</Parameter>';
226 - }else{
227 - //handlers <Parameter name="mandatory" />
 227+ } else {
 228+ //handles <Parameter name="mandatory" />
228229 $Xmltext .= '<Parameter name="'.$param_value[0].'"/>';
229230 }
230231 }
231232 $Xmltext .= '</semanticforms_FormInput>';
232233 $xml_text_array[] = $Xmltext;
233234 $Xmltext = '';
234 - }
235 - }
236 - }
 235+ }
 236+ }
 237+ }
237238 $text_extensions['sf'] = $xml_text_array;
238239 $text_extensions['sf_form'] = $form_xml_text;
239240 return true;
240241 }
241 -
242 - public static function getFilledHtmlTextForPS( $pageSchemaObj, &$text_extensions ){
 242+
 243+ public static function getFilledHtmlTextForPS( $pageSchemaObj, &$text_extensions ) {
243244 $template_fields = array();
244 - $html_text = "";
 245+ $html_text = "";
245246 $template_all = $pageSchemaObj->getTemplates();
246247 $html_text_array = array();
247248 $form_html_text = "";
248249 $obj = $pageSchemaObj->getObject('semanticforms_Form');
249 -
 250+
250251 $form_array = $obj['sf'];
251 -
252 - $form_html_text .= '<fieldset style="background: #CF9;"><legend>Form</legend>
253 - <p> Name: <input size="15" name="sf_form_name_starter" value= "'.$form_array['name'].'" ></p>
 252+
 253+ $form_html_text .= '<fieldset style="background: #CF9;"><legend>Form</legend>
 254+ <p> Name: <input size="15" name="sf_form_name_starter" value= "'.$form_array['name'].'" ></p>
254255 <p> Page name formula: <input size="20" name="sf_page_name_formula_starter" value="'.$form_array['PageNameFormula'].'" ></p>
255 - <p> Title of form for new pages: <input size="25" name="sf_create_title_starter" value="'.$form_array['CreateTitle'].'" ></p>
256 - <p> Title of form for existing pages: <input size="25" name="sf_edit_title_starter" value="'.$form_array['EditTitle'].'" ></p>
257 - </fieldset>';
 256+ <p> Title of form for new pages: <input size="25" name="sf_create_title_starter" value="'.$form_array['CreateTitle'].'" ></p>
 257+ <p> Title of form for existing pages: <input size="25" name="sf_edit_title_starter" value="'.$form_array['EditTitle'].'" ></p>
 258+ </fieldset>';
258259 foreach ( $template_all as $template ) {
259 - $field_all = $template->getFields();
 260+ $field_all = $template->getFields();
260261 $field_count = 0; //counts the number of fields
261 -
262 - foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type
263 - $field_count++;
 262+
 263+ foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type
 264+ $field_count++;
264265 $sf_array = $field->getObject('semanticforms_FormInput');//this returns an array with property values filled
265 - $form_input_array = $sf_array['sf'];
 266+ $form_input_array = $sf_array['sf'];
266267 $html_text = '<fieldset style="background: #CF9;"><legend>Form input</legend>
267268 <p> Input type: <input size="15" name="sf_input_type_starter" value='.$form_input_array['InputType'].'></p>
268269 <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>';
269270 $param_value_str= "";
270 - foreach($form_input_array as $param => $value){
271 - if($param != 'InputType'){
272 - if( $value != null ){
 271+ foreach($form_input_array as $param => $value) {
 272+ if ( $param != 'InputType' ) {
 273+ if ( $value != null ) {
273274 $param_value_str .= $param.'='.$value.', ';
274 - }else{
 275+ } else {
275276 $param_value_str .= $param.'=true, ';
276277 }
277278 }
@@ -280,24 +281,24 @@
281282 }
282283 }
283284 $text_extensions['sf'] = $html_text_array;
284 - $text_extensions['sf_form']= $form_html_text;
 285+ $text_extensions['sf_form']= $form_html_text;
285286 return true;
286 - }
287 - public static function getHtmlTextForPS( &$js_extensions ,&$text_extensions ) {
 287+ }
 288+ public static function getHtmlTextForPS( &$js_extensions ,&$text_extensions ) {
288289 $html_text = "";
289 - $form_text = "" ;
290 - $form_text .= '<fieldset style="background: #CF9;"><legend>Form</legend>
291 - <p> Name: <input size="15" name="sf_form_name_starter"></p>
 290+ $form_text = "" ;
 291+ $form_text .= '<fieldset style="background: #CF9;"><legend>Form</legend>
 292+ <p> Name: <input size="15" name="sf_form_name_starter"></p>
292293 <p> Page name formula: <input size="20" name="sf_page_name_formula_starter"></p>
293 - <p> Title of form for new pages: <input size="25" name="sf_create_title_starter"></p>
294 - <p> Title of form for existing pages: <input size="25" name="sf_edit_title_starter"></p>
 294+ <p> Title of form for new pages: <input size="25" name="sf_create_title_starter"></p>
 295+ <p> Title of form for existing pages: <input size="25" name="sf_edit_title_starter"></p>
295296 </fieldset>';
296 -
 297+
297298 $html_text .= '<fieldset style="background: #CF9;"> <legend>Form input</legend>
298299 <p> Input type: <input size="15" name="sf_input_type_starter"></p>
299300 <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>
300301 <p><input value="" name="sf_key_values_starter" size="80"></p></fieldset>';
301 -
 302+
302303 $text_extensions['sf'] = $html_text;
303304 $text_extensions['sf_form'] = $form_text;
304305 return true;
@@ -306,13 +307,13 @@
307308 */
308309 public static function getPageList( $psSchemaObj, &$genPageList ) {
309310 global $wgOut, $wgUser;
310 - $template_all = $psSchemaObj->getTemplates();
 311+ $template_all = $psSchemaObj->getTemplates();
311312 foreach ( $template_all as $template ) {
312 - $title = Title::makeTitleSafe( NS_TEMPLATE, $template->getName() );
 313+ $title = Title::makeTitleSafe( NS_TEMPLATE, $template->getName() );
313314 $genPageList[] = $title;
314315 }
315316 $form_name = $psSchemaObj->getFormName();
316 - if( $form_name == null ){
 317+ if( $form_name == null ) {
317318 return true;
318319 }
319320 //$form = SFForm::create( $form_name, $form_templates );
@@ -324,42 +325,42 @@
325326 */
326327 public static function generatePages( $psSchemaObj, $toGenPageList ) {
327328 global $wgOut, $wgUser;
328 - $template_all = $psSchemaObj->getTemplates();
 329+ $template_all = $psSchemaObj->getTemplates();
329330 $form_templates = array();
330331 $jobs = array();
331332 foreach ( $template_all as $template ) {
332 - $template_array = array();
 333+ $template_array = array();
333334 $template_array['name'] = $template->getName();
334335 $template_array['category_name'] = $psSchemaObj->categoryName;
335 - $field_all = $template->getFields();
 336+ $field_all = $template->getFields();
336337 $field_count = 0; //counts the number of fields
337 - $template_fields = array();
338 - foreach( $field_all as $fieldObj ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type
339 - $field_count++;
 338+ $template_fields = array();
 339+ foreach( $field_all as $fieldObj ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type
 340+ $field_count++;
340341 $sf_array = $fieldObj->getObject('semanticforms_FormInput');//this returns an array with property values filled
341342 $form_input_array = $sf_array['sf'];
342 - $smw_array = $fieldObj->getObject('semanticmediawiki_Property'); //this returns an array with property values filled
 343+ $smw_array = $fieldObj->getObject('semanticmediawiki_Property'); //this returns an array with property values filled
343344 $prop_array = $smw_array['smw'];
344345 $field_t = SFTemplateField::create( $fieldObj->getName(), $fieldObj->getLabel(), $prop_array['name'], $fieldObj->isList() ,$fieldObj->getDelimiter());
345346 $template_fields[] = $field_t;
346347 }
347 - $template_text = SFTemplateField::createTemplateText( $template->getName(), $template_fields, null, $psSchemaObj->categoryName, null, null, null );
348 - $title = Title::makeTitleSafe( NS_TEMPLATE, $template->getName() );
 348+ $template_text = SFTemplateField::createTemplateText( $template->getName(), $template_fields, null, $psSchemaObj->categoryName, null, null, null );
 349+ $title = Title::makeTitleSafe( NS_TEMPLATE, $template->getName() );
349350 $key_title = PageSchemas::titleString( $title );
350 - if( in_array($key_title, $toGenPageList )){
 351+ if ( in_array( $key_title, $toGenPageList ) ) {
351352 $params = array();
352353 $params['user_id'] = $wgUser->getId();
353 - $params['page_text'] = $template_text;
 354+ $params['page_text'] = $template_text;
354355 $jobs[] = new PSCreatePageJob( $title, $params );
355356 }
356357 //Creating Form Templates at this time
357358 $form_template = SFTemplateInForm::create( $template->getName(), $template->getLabel(), $template->isMultiple() );
358359 $form_templates[] = $form_template;
359 - }
 360+ }
360361 Job::batchInsert( $jobs );
361362 $form_name = $psSchemaObj->getFormName();
362 - $form_array = $psSchemaObj->getFormArray();
363 - if( $form_name == null ){
 363+ $form_array = $psSchemaObj->getFormArray();
 364+ if ( $form_name == null ) {
364365 return true;
365366 }
366367 $form = SFForm::create( $form_name, $form_templates );
@@ -368,38 +369,40 @@
369370 $form->setEditTitle( $form_array['EditTitle'] );
370371 $title = Title::makeTitleSafe( SF_NS_FORM, $form->getFormName() );
371372 $key_title = PageSchemas::titleString( $title );
372 - if( in_array($key_title, $toGenPageList )){
373 - $full_text = $form->createMarkup();
 373+ if( in_array($key_title, $toGenPageList )) {
 374+ $full_text = $form->createMarkup();
374375 $params = array();
375376 $params['user_id'] = $wgUser->getId();
376 - $params['page_text'] = $full_text;
 377+ $params['page_text'] = $full_text;
377378 $jobs = array( new PSCreatePageJob( $title, $params ) );
378 - Job::batchInsert( $jobs );
 379+ Job::batchInsert( $jobs );
379380 }
380381 return true;
381382 }
 383+
382384 /**
383 - *Thi Function parses the Field elements in the xml of the pages. Hooks for PageSchemas extension
384 - */
 385+ * This function parses the field elements in the XML of the pages. Hooks for Page Schemas extension.
 386+ */
385387 public static function parseFieldElements( $field_xml, &$text_object ) {
386 -
 388+
387389 foreach ( $field_xml->children() as $tag => $child ) {
388 - if ( $tag == "semanticforms_FormInput" ) {
389 - $text = "";
390 - $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticForms", (string)$tag );
391 - foreach ( $child->children() as $prop ) {
392 - if( $prop->getName() == 'InputType' ){
393 - $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop->getName(), $prop );
394 - }else {
395 - $prop_name = (string)$prop->attributes()->name;
396 - $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop_name, (string)$prop );
397 - }
 390+ if ( $tag == "semanticforms_FormInput" ) {
 391+ $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticForms", (string)$tag );
 392+ foreach ( $child->children() as $prop ) {
 393+ if ( $prop->getName() == 'InputType' ) {
 394+ $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop->getName(), $prop );
 395+ } else {
 396+ $prop_name = (string)$prop->attributes()->name;
 397+ $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop_name, (string)$prop );
398398 }
399 - $text_object['sf']=$text;
400399 }
 400+ $text_object['sf'] = $text;
 401+ break;
401402 }
402 - return true;
 403+ }
 404+ return true;
403405 }
 406+
404407 public static function initProperties() {
405408 global $sfgContLang;
406409
@@ -468,14 +471,12 @@
469472 */
470473 public static function printRedirectForm( $title, $page_contents, $edit_summary, $is_save, $is_preview, $is_diff, $is_minor_edit, $watch_this, $start_time, $edit_time ) {
471474 global $wgUser, $sfgScriptPath;
472 -
 475+
473476 if ( $is_save ) {
474477 $action = "wpSave";
475 - }
476 - elseif ( $is_preview ) {
 478+ } elseif ( $is_preview ) {
477479 $action = "wpPreview";
478 - }
479 - else { // $is_diff
 480+ } else { // $is_diff
480481 $action = "wpDiff";
481482 }
482483
@@ -616,7 +617,7 @@
617618 $wgOut->addLink( $link );
618619 }
619620 }
620 -
 621+
621622 $scripts = array();
622623 if ( !$sfgUseFormEditPage )
623624 $scripts[] = "$sfgScriptPath/libs/SF_ajax_form_preview.js";