Yaron Koren has uploaded a new change for review.

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


Change subject: Fixes for partial form handling, thanks to patch from Sebastian 
Richter
......................................................................

Fixes for partial form handling, thanks to patch from Sebastian Richter

Change-Id: I500ab303e50575c8b44cca08b158d0bff7a01665
---
M includes/SF_AutoeditAPI.php
M includes/SF_FormPrinter.php
M specials/SF_FormEdit.php
3 files changed, 25 insertions(+), 11 deletions(-)


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

diff --git a/includes/SF_AutoeditAPI.php b/includes/SF_AutoeditAPI.php
index 921986a..6faa350 100644
--- a/includes/SF_AutoeditAPI.php
+++ b/includes/SF_AutoeditAPI.php
@@ -830,16 +830,17 @@
                        }
                }
 
-               // we already preloaded stuff for saving/previewing, do not do 
it again
-               if ( $isFormSubmitted ) {
+               // We already preloaded stuff for saving/previewing -
+               // do not do this again.
+               if ( $isFormSubmitted && !$wgRequest->getCheck( 'partial' ) ) {
                        $preloadContent = '';
                        $pageExists = false;
                } else {
-                       // source of the data is a page
+                       // Source of the data is a page.
                        $pageExists = ( is_a( $targetTitle, 'Title') && 
$targetTitle->exists() );
                }
 
-               // spoof wgRequest for SFFormPrinter::formHTML
+               // Spoof $wgRequest for SFFormPrinter::formHTML().
                $wgRequest = new FauxRequest( $this->mOptions, true );
 
                // if necessary spoof wgOut; if we took the general $wgOut 
again some JS
diff --git a/includes/SF_FormPrinter.php b/includes/SF_FormPrinter.php
index 9bd3162..a6e17e2 100644
--- a/includes/SF_FormPrinter.php
+++ b/includes/SF_FormPrinter.php
@@ -365,7 +365,9 @@
                } else {
                        $original_page_content = null;
                        if ( $wgRequest->getCheck( 'sf_free_text' ) ) {
-                               $existing_page_content = $wgRequest->getVal( 
'sf_free_text' );
+                               if ( !isset( $existing_page_content ) || 
$existing_page_content == '' ) {
+                                       $existing_page_content = 
$wgRequest->getVal( 'sf_free_text' );
+                               }
                                $form_is_partial = true;
                        }
                }
@@ -971,7 +973,9 @@
                                        // from the template call
                                        if ( $source_is_page && ( ! empty( 
$existing_template_text ) ) ) {
                                                if ( isset( 
$template_contents[$field_name] ) ) {
-                                                       $cur_value = 
$template_contents[$field_name];
+                                                       if ( !isset( $cur_value 
) ) {
+                                                               $cur_value = 
$template_contents[$field_name];
+                                                       }
 
                                                        // If the field is a 
placeholder, the contents of this template
                                                        // parameter should be 
treated as elements parsed by an another
@@ -989,6 +993,8 @@
                                                        // the fields that 
weren't
                                                        // handled by the form.
                                                        unset( 
$template_contents[$field_name] );
+                                               } elseif ( isset( $cur_value ) 
&& !empty( $cur_value ) ) {
+                                                       // Do nothing.
                                                } else {
                                                        $cur_value = '';
                                                }
@@ -1522,7 +1528,6 @@
                if ( $form_is_partial ) {
                        if ( !$wgRequest->getCheck( 'partial' ) ) {
                                $free_text = $original_page_content;
-                               $form_text .= Html::hidden( 'partial', 1 );
                        } else {
                                $free_text = null;
                                $existing_page_content = preg_replace( array( 
'/�\{/m', '/\}�/m' ),
@@ -1530,6 +1535,7 @@
                                        $existing_page_content );
                                $existing_page_content = preg_replace( 
'/\{\{\{insertionpoint\}\}\}/', '', $existing_page_content );
                        }
+                       $form_text .= Html::hidden( 'partial', 1 );
                } elseif ( $source_is_page ) {
                        // if the page is the source, free_text will just be 
whatever in the
                        // page hasn't already been inserted into the form
diff --git a/specials/SF_FormEdit.php b/specials/SF_FormEdit.php
index cbef163..49e62c2 100644
--- a/specials/SF_FormEdit.php
+++ b/specials/SF_FormEdit.php
@@ -74,10 +74,17 @@
                $module->setOption( 'target', $targetName );
 
                if ( $wgRequest->getCheck( 'wpSave' ) || $wgRequest->getCheck( 
'wpPreview' ) || $wgRequest->getCheck( 'wpDiff' ) ) {
-                       // if the page was submitted, formdata should be 
complete => do not preload
-                       $module->setOption( 'preload', false );
-               } else if ( !empty($targetName) && Title::newFromText( 
$targetName )->exists ( ) ) {
-                       // if target page exists do not overwrite it with 
preload data, just preload the page's data
+                       // If the page was submitted, form data should be
+                       // complete => do not preload (unless it's a partial
+                       // form).
+                       if ( $wgRequest->getCheck( 'partial' ) ) {
+                               $module->setOption( 'preload', true );
+                       } else {
+                               $module->setOption( 'preload', false );
+                       }
+               } else if ( !empty( $targetName ) && Title::newFromText( 
$targetName )->exists ( ) ) {
+                       // If target page exists, do not overwrite it with
+                       // preload data; just preload the page's data.
                        $module->setOption( 'preload', true );
                } else if ( $wgRequest->getCheck( 'preload' ) ) {
                        // if page does not exist and preload parameter is set, 
pass that on

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I500ab303e50575c8b44cca08b158d0bff7a01665
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