r97455 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97454‎ | r97455 | r97456 >
Date:06:37, 19 September 2011
Author:yaron
Status:deferred
Tags:
Comment:
Improved code and comments, including turning input-type input into a dropdown instead of a text input
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_PageSchemas.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_PageSchemas.php
@@ -1,6 +1,7 @@
22 <?php
33 /**
4 - * Static functions for Semantic Forms, for use by the Page Schemas extension.
 4+ * Static functions for Semantic Forms, for use by the Page Schemas
 5+ * extension.
56 *
67 * @author Yaron Koren
78 * @author Ankit Garg
@@ -11,11 +12,12 @@
1213 class SFPageSchemas {
1314
1415 /**
15 - * Function to return the property based on the XML passed from the Page Schemas extension
 16+ * Creates an object to hold form-wide information, based on an XML
 17+ * object from the Page Schemas extension.
1618 */
1719 public static function createPageSchemasObject( $objectName, $xmlForField, &$object ) {
1820 $sfarray = array();
19 - $formName="";
 21+ $formName = "";
2022 if ( $objectName == "semanticforms_Form" ) {
2123 foreach ( $xmlForField->children() as $tag => $child ) {
2224 if ( $tag == $objectName ) {
@@ -36,12 +38,9 @@
3739 if ( $prop->getName() == 'InputType' ) {
3840 $sfarray[$prop->getName()] = (string)$prop;
3941 } else {
40 - // Remember these values can be null also.
41 - // While polulating in the page text, take care of that.
4242 $sfarray[(string)$prop->attributes()->name] = (string)$prop;
4343 }
4444 }
45 - // Setting value specific to SF in 'sf' index.
4645 $object['sf'] = $sfarray;
4746 return true;
4847 }
@@ -50,6 +49,9 @@
5150 return true;
5251 }
5352
 53+ /**
 54+ * Creates Page Schemas XML for form-wide information.
 55+ */
5456 public static function getSchemaXML( $request, &$xmlArray ) {
5557 foreach ( $request->getValues() as $var => $val ) {
5658 if ( $var == 'sf_form_name' ) {
@@ -67,6 +69,9 @@
6870 return true;
6971 }
7072
 73+ /**
 74+ * Creates Page Schemas XML for a specific form field.
 75+ */
7176 public static function getFieldXML( $request, &$xmlArray ) {
7277 $xmlPerField = array();
7378 $fieldNum = -1;
@@ -126,19 +131,19 @@
127132 } else {
128133 $pageNameFormula = '';
129134 }
130 - $text .= "\t<p>" . 'Page name formula:' . ' ' . Html::input( 'sf_page_name_formula', $pageNameFormula, 'text', array( 'size' => 20 ) ) . "</p>\n";
 135+ $text .= "\t<p>" . wfMsg( 'sf-pageschemas-pagenameformula' ) . ' ' . Html::input( 'sf_page_name_formula', $pageNameFormula, 'text', array( 'size' => 20 ) ) . "</p>\n";
131136 if ( array_key_exists( 'CreateTitle', $form_array ) ) {
132137 $createTitle = $form_array['CreateTitle'];
133138 } else {
134139 $createTitle = '';
135140 }
136 - $text .= "\t<p>" . 'Title of form for new pages:' . ' ' . Html::input( 'sf_create_title', $createTitle, 'text', array( 'size' => 25 ) ) . "</p>\n";
 141+ $text .= "\t<p>" . wfMsg( 'sf-pageschemas-createtitle' ) . ' ' . Html::input( 'sf_create_title', $createTitle, 'text', array( 'size' => 25 ) ) . "</p>\n";
137142 if ( array_key_exists( 'EditTitle', $form_array ) ) {
138143 $editTitle = $form_array['EditTitle'];
139144 } else {
140145 $editTitle = '';
141146 }
142 - $text .= "\t<p>" . 'Title of form for existing pages:' . ' ' . Html::input( 'sf_edit_title', $editTitle, 'text', array( 'size' => 25 ) ) . "</p>\n";
 147+ $text .= "\t<p>" . wfMsg( 'sf-pageschemas-edittitle' ) . ' ' . Html::input( 'sf_edit_title', $editTitle, 'text', array( 'size' => 25 ) ) . "</p>\n";
143148 $text_extensions['sf'] = array( 'Form', '#CF9', $text, $hasExistingValues );
144149
145150 return true;
@@ -149,16 +154,13 @@
150155 * within the Page Schemas 'edit schema' page.
151156 */
152157 public static function getFieldHTML( $field, &$text_extensions ) {
153 - if ( is_null( $field ) ) {
154 - $fieldValues = array();
155 - } else {
156 - $sf_array = $field->getObject('semanticforms_FormInput'); //this returns an array with property values filled
 158+ $hasExistingValues = false;
 159+ $fieldValues = array();
 160+ if ( !is_null( $field ) ) {
 161+ $sf_array = $field->getObject('semanticforms_FormInput');
157162 if ( array_key_exists( 'sf', $sf_array ) ) {
158163 $fieldValues = $sf_array['sf'];
159164 $hasExistingValues = true;
160 - } else {
161 - $fieldValues = array();
162 - $hasExistingValues = false;
163165 }
164166 }
165167
@@ -167,10 +169,21 @@
168170 } else {
169171 $inputType = '';
170172 }
171 - $inputTypeAttrs = array( 'size' => 15 );
172 - $inputTypeInput = Html::input( 'sf_input_type_num', $inputType, 'text', $inputTypeAttrs );
173 - $text = '<p>Input type: ' . $inputTypeInput . '</p>';
174 - $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";
 173+
 174+ global $sfgFormPrinter;
 175+ $possibleInputTypes = $sfgFormPrinter->getAllInputTypes();
 176+ $inputTypeDropdownHTML = '';
 177+ foreach ( $possibleInputTypes as $possibleInputType ) {
 178+ $inputTypeOptionAttrs = array();
 179+ if ( $possibleInputType == $inputType ) {
 180+ $inputTypeOptionAttrs['selected'] = true;
 181+ }
 182+ $inputTypeDropdownHTML .= Html::element( 'option', $inputTypeOptionAttrs, $possibleInputType ) . "\n";
 183+ }
 184+ $inputTypeDropdown = Html::rawElement( 'select', array( 'name' => 'sf_input_type_num' ), $inputTypeDropdownHTML );
 185+ $text = '<p>' . wfMsg( 'sf_createform_inputtype' ) . ' ' . $inputTypeDropdown . '</p>';
 186+
 187+ $text .= "\t" . '<p>Enter parameter names and their values as key=value pairs, separated by commas (if a value contains a comma, replace it with "\,") For example: size=20, mandatory</p>' . "\n";
175188 $paramValues = array();
176189 foreach ( $fieldValues as $param => $value ) {
177190 if ( !empty( $param ) && $param != 'InputType' ) {
@@ -357,7 +370,7 @@
358371
359372 foreach ( $field_xml->children() as $tag => $child ) {
360373 if ( $tag == "semanticforms_FormInput" ) {
361 - $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticForms", (string)$tag );
 374+ $text = PageSchemas::tableMessageRowHTML( "paramAttr", wfMsg( 'specialpages-group-sf_group' ), (string)$tag );
362375 foreach ( $child->children() as $prop ) {
363376 if ( $prop->getName() == 'InputType' ) {
364377 $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop->getName(), $prop );