Himeshi has uploaded a new change for review. https://gerrit.wikimedia.org/r/72051
Change subject: Added implementation of {{{section}}} tag to the form definition syntax. ...................................................................... Added implementation of {{{section}}} tag to the form definition syntax. Change-Id: I265f8ca9b9cf936447fe2a9ee827912239f3ff37 --- M includes/SF_FormPrinter.php M includes/SF_FormUtils.php 2 files changed, 73 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms refs/changes/51/72051/1 diff --git a/includes/SF_FormPrinter.php b/includes/SF_FormPrinter.php index a6e17e2..7c3eb95 100644 --- a/includes/SF_FormPrinter.php +++ b/includes/SF_FormPrinter.php @@ -1361,6 +1361,62 @@ } $section = substr_replace( $section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc ); // ===================================================== + // for section processing + // ===================================================== + } elseif ( $tag_title == 'section') { + //set defaults for section name and level + $section_name = ''; + $header_level = 2; + + $default_value = ''; + $section_text; + + //get section name and level + if ( count($tag_components) > 1 ){ + $section_name = $tag_components[1]; + + if ( count($tag_components) > 2 ) + $header_level = trim( $tag_components[2] ); + } + + //display the sections in wikitext on the created page + $header_string = ""; + for ( $level_count = 0; $level_count < $header_level; $level_count++ ) { + $header_string .= '='; + } + $header_text = $header_string.$section_name.$header_string."\n"; + $data_text .= $header_text; + + //split the existing page contents into the textareas in the form + if ( $source_is_page && $existing_page_content !== null ) { + $section_start_loc = strpos( $existing_page_content, $header_text ); + $existing_page_content = str_replace( $header_text, '', $existing_page_content ); + $section_end_loc = strpos( $existing_page_content, '=', $section_start_loc ); + + if ( $section_end_loc === FALSE ) { + $default_value = $existing_page_content; + $existing_page_content = ''; + } else { + $default_value = substr( $existing_page_content, $section_start_loc, $section_end_loc - $section_start_loc ); + $existing_page_content = substr( $existing_page_content, $section_end_loc); + } + } + + //if input is from the form + if ( ( ! $source_is_page ) && $wgRequest ) { + $section_text = $wgRequest->getArray( '_section' ); + $default_value = $section_text[trim( $section_name )]; + $data_text .= "\n".$section_text[trim( $section_name )]."\n"; + } + + //set input name for query string + $input_name = '_section' . '[' . trim( $section_name ) . ']'; + + $form_section_text = SFFormUtils::headerHTML( $section_name, $header_level ); + $form_section_text .= SFTextAreaInput::getHTML( $default_value, $input_name, false, ( $form_is_disabled || $is_restricted ), $other_args = array( 'rows' => 10)); + + $section = substr_replace( $section, $form_section_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc); + // ===================================================== // page info processing // ===================================================== } elseif ( $tag_title == 'info' ) { diff --git a/includes/SF_FormUtils.php b/includes/SF_FormUtils.php index 507c27e..58ba196 100644 --- a/includes/SF_FormUtils.php +++ b/includes/SF_FormUtils.php @@ -547,5 +547,22 @@ return wfMemcKey( 'ext.SemanticForms.formdefinition', $formId, $optionsHash ); } } + + /* + * Get section header HTML + */ + static function headerHTML( $header_name = null, $header_level = 2) { + + global $sfgTabIndex; + + $sfgTabIndex++; + $text = null; + + if ( $header_level > 6 || !is_numeric($header_level)){ + $header_level = 2; + } + $text = "<h".$header_level.">".$header_name."</h".$header_level.">"; + return $text; + } } -- To view, visit https://gerrit.wikimedia.org/r/72051 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I265f8ca9b9cf936447fe2a9ee827912239f3ff37 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/SemanticForms Gerrit-Branch: master Gerrit-Owner: Himeshi <himeshid...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits