Yaron Koren has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/266101

Change subject: Fix for handling of multi-instance templates wtih one-stop 
process
......................................................................

Fix for handling of multi-instance templates wtih one-stop process

Added new method: SFTemplateInForm::checkIfAllInstancesPrinted()

Change-Id: Iaacc4159fcee09524e9e479620b1ba677fc79e1e
---
M includes/SF_FormPrinter.php
M includes/SF_TemplateInForm.php
2 files changed, 29 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms 
refs/changes/01/266101/1

diff --git a/includes/SF_FormPrinter.php b/includes/SF_FormPrinter.php
index 02de464..3ea85e0 100644
--- a/includes/SF_FormPrinter.php
+++ b/includes/SF_FormPrinter.php
@@ -764,6 +764,8 @@
                                                
$tif->setFieldValuesFromSubmit();
                                        }
 
+                                       $tif->checkIfAllInstancesPrinted( 
$form_submitted, $source_is_page );
+
                                // 
=====================================================
                                // end template processing
                                // 
=====================================================
diff --git a/includes/SF_TemplateInForm.php b/includes/SF_TemplateInForm.php
index 546c33a..1b9c94d 100644
--- a/includes/SF_TemplateInForm.php
+++ b/includes/SF_TemplateInForm.php
@@ -492,8 +492,8 @@
        }
 
        /**
-        * Set some fields based on the current contents of the page being
-        * edited - or at least fields that only need to be set if there's
+        * Set some vars based on the current contents of the page being
+        * edited - or at least vars that only need to be set if there's
         * an existing page.
         */
        function setPageRelatedInfo( $existing_page_content ) {
@@ -505,25 +505,33 @@
                        array( '\/', '\(', '\)', '\^' ),
                        $this->mSearchTemplateStr );
                $this->mPageCallsThisTemplate = preg_match( '/{{' . 
$this->mPregMatchTemplateStr . '\s*[\|}]/i', str_replace( '_', ' ', 
$existing_page_content ) );
-               if ( $this->mAllowMultiple ) {
-                       // Find instances of this template in the page -
-                       // if there's at least one, re-parse this section of the
-                       // definition form for the subsequent template 
instances in
-                       // this page; if there's none, don't include fields at 
all.
-                       // There has to be a more efficient way to handle 
multiple
-                       // instances of templates, one that doesn't involve 
re-parsing
-                       // the same tags, but I don't know what it is.
-                       // (Also add additional, blank instances if there's a 
minimum
-                       // number required in this form, and we haven't reached 
it yet.)
-                       if ( $this->mPageCallsThisTemplate || 
$this->mInstanceNum < $this->mMinAllowed ) {
-                               // Print another instance until we reach the 
minimum
-                               // instances, which is also the starting number.
-                       } else {
-                               $this->mAllInstancesPrinted = true;
-                       }
-               }
        }
 
+       function checkIfAllInstancesPrinted( $form_submitted, $source_is_page ) 
{
+               // Find instances of this template in the page -
+               // if there's at least one, re-parse this section of the
+               // definition form for the subsequent template instances in
+               // this page; if there's none, don't include fields at all.
+               // @TODO - There has to be a more efficient way to handle
+               // multiple instances of templates, one that doesn't involve
+               // re-parsing the same tags, but I don't know what it is.
+               // (Also add additional, blank instances if there's a minimum
+               // number required in this form, and we haven't reached it yet.)
+               if ( !$this->mAllowMultiple ) {
+                       return;
+               }
+               if ( $this->mInstanceNum < $this->mMinAllowed ) {
+                       return;
+               }
+               if ( $form_submitted && $this->mInstanceNum < 
$this->mNumInstancesFromSubmit ) {
+                       return;
+               }
+               if ( !$form_submitted && $source_is_page && 
$this->mPageCallsThisTemplate ) {
+                       return;
+               }
+               $this->mAllInstancesPrinted = true;
+       }
+
        function creationHTML( $template_num ) {
                $checked_attribs = ( $this->mAllowMultiple ) ? array( 'checked' 
=> 'checked' ) : array();
                $template_str = wfMessage( 'sf_createform_template' 
)->escaped();

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaacc4159fcee09524e9e479620b1ba677fc79e1e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>

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

Reply via email to