jenkins-bot has submitted this change and it was merged.

Change subject: Add handling of other parameters for page sections
......................................................................


Add handling of other parameters for page sections

Included rows, cols, class, autogrow and editor parameters for page sections in 
SF_FormPrinter.php formHTML() and SF_CreateForm.php.

Bug: 46662
Change-Id: Icdffc44c8186a4271b83edecbc7c0f9fd68a8c69
---
M includes/SF_FormField.php
M includes/SF_FormPrinter.php
M includes/SF_PageSection.php
M languages/SF_Messages.php
M specials/SF_CreateForm.php
5 files changed, 96 insertions(+), 24 deletions(-)

Approvals:
  Yaron Koren: Checked; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/SF_FormField.php b/includes/SF_FormField.php
index 30982ea..9436131 100644
--- a/includes/SF_FormField.php
+++ b/includes/SF_FormField.php
@@ -246,7 +246,8 @@
                        }
                }
 
-               $text .= "<fieldset 
class=\"sfCollapsibleFieldset\"><legend>Other parameters</legend>\n";
+               $other_param_text = wfMessage( 'sf_createform_otherparameters' 
)->escaped();
+               $text .= "<fieldset 
class=\"sfCollapsibleFieldset\"><legend>$other_param_text</legend>\n";
                $text .= Html::rawElement( 'div', array( 'class' => 
'otherInputParams' ),
                        SFCreateForm::showInputTypeOptions( $cur_input_type, 
$field_form_text, $paramValues ) ) . "\n";
                $text .= "</fieldset>\n";
diff --git a/includes/SF_FormPrinter.php b/includes/SF_FormPrinter.php
index 9eb0f4e..7789073 100644
--- a/includes/SF_FormPrinter.php
+++ b/includes/SF_FormPrinter.php
@@ -1368,6 +1368,7 @@
                                        $is_hidden = false;
                                        $is_restricted = false;
                                        $header_level = 2;
+                                       $other_args = array ();
 
                                        for ( $i = 2; $i < count( 
$tag_components ); $i++ ) {
 
@@ -1379,6 +1380,8 @@
                                                        $is_hidden = true;
                                                } elseif ( $component == 
'restricted' ) {
                                                        $is_restricted = ( ! 
$wgUser || ! $wgUser->isAllowed( 'editrestrictedfields' ) );
+                                               } elseif ( $component == 
'autogrow' ) {
+                                                       $other_args['autogrow'] 
= true;
                                                }
 
                                                $sub_components = array_map( 
'trim', explode( '=', $component, 2 ) );
@@ -1386,6 +1389,14 @@
                                                if ( count( $sub_components ) 
== 2 ) {
                                                        if ( trim( 
$sub_components[0] ) == 'level' ) {
                                                                $header_level = 
$sub_components[1];
+                                                       } elseif ( trim( 
$sub_components[0] ) == 'rows' ) {
+                                                               
$other_args['rows'] = $sub_components[1];
+                                                       } elseif ( trim( 
$sub_components[0] ) == 'cols' ) {
+                                                               
$other_args['cols'] = $sub_components[1];
+                                                       } elseif ( trim( 
$sub_components[0] ) == 'class' ) {
+                                                               
$other_args['class'] = $sub_components[1];
+                                                       } elseif ( trim( 
$sub_components[0] ) == 'editor' ) {
+                                                               
$other_args['editor'] = $sub_components[1];
                                                        }
                                                }
                                        }
@@ -1435,8 +1446,6 @@
 
                                        //set input name for query string
                                        $input_name = '_section' . '[' . trim( 
$section_name ) . ']';
-                                       $other_args = array ();
-                                       $other_args['rows'] = 10;
                                        if ( $is_mandatory ) {
                                                $other_args['mandatory'] = true;
                                        }
diff --git a/includes/SF_PageSection.php b/includes/SF_PageSection.php
index 26fb842..0e02e72 100644
--- a/includes/SF_PageSection.php
+++ b/includes/SF_PageSection.php
@@ -11,6 +11,7 @@
        private $mIsMandatory;
        private $mIsHidden;
        private $mIsRestricted;
+       private $mSectionArgs;
 
        static function create( $section_name ) {
                $ps = new SFPageSection();
@@ -19,6 +20,7 @@
                $ps->mIsMandatory = false;
                $ps->mIsHidden = false;
                $ps->mIsRestricted = false;
+               $ps->mSectionArgs = array();
 
                return $ps;
        }
@@ -47,7 +49,13 @@
                $this->mIsRestricted = $isRestricted;
        }
 
+       public function setSectionArgs( $key, $value ) {
+               $this->mSectionArgs[$key] = $value;
+       }
+
        function creationHTML( $section_count ) {
+               global $wgRequest;
+               $paramValues = array();
                $section_name = $this->mSectionName;
                $section_level = $this->mSectionLevel;
 
@@ -58,7 +66,14 @@
        <h2>$section_str</h2>
 
 END;
-               $paramValues = $this->getParamValues();
+               foreach ( $wgRequest->getValues() as $key => $value ) {
+                       if ( ( $pos = strpos( $key, '_section_'.$section_count 
) ) != false ) {
+                               $paramName = substr( $key, 0, $pos );
+                               $paramName = str_replace( '_', ' ', $paramName 
);
+                               $paramValues[$paramName] = $value;
+                       }
+               }
+
                $header_options =  '';
                $text .= Html::rawElement( 'span', null, wfMessage( 
'sf_createform_sectionlevel' )->text() ) . "\n";
                for ( $i = 1; $i < 7; $i++ ) {
@@ -68,10 +83,12 @@
                                $header_options .= " " . Html::element( 
'option', array( 'value' => $i ), $i ) . "\n";
                        }
                }
-               $text .= Html::rawElement( 'select', array( 'name' => 
"sectionlevel_" . $section_count ), $header_options ) . "\n";
+               $text .= Html::rawElement( 'select', array( 'name' => 
"level_section_" . $section_count ), $header_options ) . "\n";
+               $other_param_text = wfMessage( 'sf_createform_otherparameters' 
)->escaped();
+               $text .= "<fieldset 
class=\"sfCollapsibleFieldset\"><legend>$other_param_text</legend>\n";
                $text .= Html::rawElement( 'div', array(),
                SFCreateForm::showSectionParameters( $section_count, 
$paramValues ) ) . "\n";
-
+               $text .= "</fieldset>\n";
                $removeSectionButton = Html::input( 'delsection_' . 
$section_count, wfMessage( 'sf_createform_removesection' )->text(), 'submit' ) 
. "\n";
                $text .= "</br>" . Html::rawElement( 'p', null, 
$removeSectionButton ) . "\n";
                $text .= "      </div>\n";
@@ -100,6 +117,13 @@
                } elseif ( $this->mIsHidden ) {
                        $text .= "|hidden";
                }
+               foreach ( $this->mSectionArgs as $arg => $value ) {
+                       if ( $value === true ) {
+                               $text .= "|$arg";
+                       } else {
+                               $text .= "|$arg=$value";
+                       }
+               }
                $text .= "}}}\n";
 
                return $text;
@@ -107,6 +131,7 @@
 
        public static function getParameters() {
                $params = array();
+
                $params['mandatory'] = array(
                        'name' => 'mandatory',
                        'type' => 'boolean',
@@ -122,6 +147,27 @@
                        'type' => 'boolean',
                        'description' => wfMessage( 
'sf_createform_hiddensection' )->text()
                );
+               $params['class'] = array(
+                       'name' => 'class',
+                       'type' => 'string',
+                       'description' => wfMessage( 'sf_forminputs_class' 
)->text()
+               );
+               $params['rows'] = array(
+                       'name' => 'rows',
+                       'type' => 'int',
+                       'description' => wfMessage( 'sf_forminputs_rows' 
)->text()
+               );
+               $params['cols'] = array(
+                       'name' => 'cols',
+                       'type' => 'int',
+                       'description' => wfMessage( 'sf_forminputs_cols' 
)->text()
+               );
+               $params['autogrow'] = array(
+                       'name' => 'autogrow',
+                       'type' => 'boolean',
+                       'description' => wfMessage( 'sf_forminputs_autogrow' 
)->text()
+               );
+
                return $params;
        }
 
diff --git a/languages/SF_Messages.php b/languages/SF_Messages.php
index 424e862..78fc1fa 100644
--- a/languages/SF_Messages.php
+++ b/languages/SF_Messages.php
@@ -109,6 +109,7 @@
        'sf_createform_sectionlevel'         => 'Section level:',
        'sf_createform_sectionname'          => 'Section name',
        'sf_createform_additembeforesave'    => 'You must add at least one 
template or page section to this form before you can save it.',
+       'sf_createform_otherparameters'      => 'Other parameters',
        'createcategory'                     => 'Create a category',
        'sf-createcategory-with-name'        => 'Create category: $1',
        'sf_createcategory_name'             => 'Category name:',
diff --git a/specials/SF_CreateForm.php b/specials/SF_CreateForm.php
index 565aaea..17794e5 100644
--- a/specials/SF_CreateForm.php
+++ b/specials/SF_CreateForm.php
@@ -249,24 +249,28 @@
                                $section = $fi['item'];
                                $old_i = SFFormUtils::getChangedIndex( 
$sections, $new_section_loc, $deleted_section_loc );
                                foreach ( $wgRequest->getValues() as $key => 
$value ) {
-                                       if ( ( $pos = strpos( $key, '_' . 
$old_i ) ) != false ) {
-                                                       $paramName = substr( 
$key, 0, $pos );
-                                               } else {
-                                                       continue;
-                                               }
+                                       if ( ( $pos = strpos( $key, '_section_' 
. $old_i ) ) != false ) {
+                                               $paramName = substr( $key, 0, 
$pos );
+                                               $paramName = str_replace( '_', 
' ', $paramName );
+                                       } else {
+                                               continue;
+                                       }
 
-                                               if ( $paramName == 
'sectionlevel' ) {
-                                                       
$section->setSectionLevel( $value );
-                                               }
-                                               if ( $value == 'on' ) {
+                                               if ( !empty( $value ) ) {
+                                                       if ( $value == 'on' ) {
                                                                $value = true;
-                                               }
-                                               if ( $paramName == 'hidden' ) {
-                                                       $section->setIsHidden( 
$value );
-                                               } elseif ( $paramName == 
'restricted' ) {
-                                                       
$section->setIsRestricted( $value );
-                                               } elseif ( $paramName == 
'mandatory' ) {
-                                                       
$section->setIsMandatory( $value );
+                                                       }
+                                                       if ( $paramName == 
'level' ) {
+                                                               
$section->setSectionLevel( $value );
+                                                       } elseif ( $paramName 
== 'hidden' ) {
+                                                               
$section->setIsHidden( $value );
+                                                       } elseif ( $paramName 
== 'restricted' ) {
+                                                               
$section->setIsRestricted( $value );
+                                                       } elseif ( $paramName 
== 'mandatory' ) {
+                                                               
$section->setIsMandatory( $value );
+                                                       } else {
+                                                               
$section->setSectionArgs( $paramName, $value );
+                                                       }
                                                }
                                }
                                $sections++;
@@ -515,10 +519,10 @@
 
                $text = '';
                $descriptiontext = '';
-               $section_text = $section_count;
+               $section_text = 'section_' . $section_count;
 
                $params = SFPageSection::getParameters();
-
+               $i = 0;
                foreach ( $params as $param ) {
                        $paramName = $param['name'];
                        $type = $param['type'];
@@ -531,10 +535,21 @@
                        } else {
                                $cur_value = '';
                        }
+
+                       // 3 values per row, with alternating colors for rows
+                       if ( $i % 3 == 0 ) {
+                               $bgcolor = ( $i % 6 ) == 0 ? '#ecf0f6' : 
'white';
+                               $text .= "<div style=\"background: 
$bgcolor;\">";
+                       }
+
                        $text .= "<div style=\"width: 30%; padding: 5px; float: 
left;\">$paramName:\n";
 
                        $text .= self::inputTypeParamInput( $type, $paramName, 
$cur_value, $param, array(), $section_text );
                        $text .= "\n<br />" . Html::rawElement( 'em', null, 
$desc ) . "\n</div>\n";
+                       if ( $i % 3 == 2 || $i == count( $params ) - 1 ) {
+                               $text .= "<div style=\"clear: 
both\";></div></div>\n";
+                       }
+                       ++$i;
                }
                return $text;
         }

-- 
To view, visit https://gerrit.wikimedia.org/r/77461
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Icdffc44c8186a4271b83edecbc7c0f9fd68a8c69
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Himeshi <[email protected]>
Gerrit-Reviewer: Nischayn22 <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to