Yaron Koren has uploaded a new change for review.
https://gerrit.wikimedia.org/r/266247
Change subject: Fixes for "partial forms"
......................................................................
Fixes for "partial forms"
Change-Id: Id818f9d77016f3c052e6b860d53c96ff103a49cd
---
M includes/SF_FormPrinter.php
M includes/SF_TemplateInForm.php
2 files changed, 22 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms
refs/changes/47/266247/1
diff --git a/includes/SF_FormPrinter.php b/includes/SF_FormPrinter.php
index ee020dd..18366d8 100644
--- a/includes/SF_FormPrinter.php
+++ b/includes/SF_FormPrinter.php
@@ -747,7 +747,7 @@
// If something
already exists, set the new insertion point
// to its
position; otherwise just let it lie.
if ( strpos(
$existing_page_content, $existing_template_text ) !== false ) {
-
$existing_page_content = str_replace( '{{{insertionpoint}}}', '',
$existing_page_content );
+
$existing_page_content = str_replace( "\n" . '{{{insertionpoint}}}', '',
$existing_page_content );
$existing_page_content = str_replace( $existing_template_text,
'{{{insertionpoint}}}', $existing_page_content );
}
} else {
@@ -760,7 +760,7 @@
$source_page_matches_this_form = true;
}
}
- if ( !$source_is_page ) {
+ if ( $form_submitted ) {
$tif->setFieldValuesFromSubmit();
}
@@ -804,7 +804,7 @@
// If the user is editing a page, and
that page contains a call to
// the template being processed, get
the current field's value
// from the template call
- if ( $source_is_page && (
$tif->getFullTextInPage() != '' ) ) {
+ if ( $source_is_page && (
$tif->getFullTextInPage() != '' && !$form_submitted ) ) {
if (
$tif->hasValueFromPageForField( $field_name ) ) {
// Get value, and
remove it,
// so that at the end we
@@ -1263,7 +1263,7 @@
} elseif ( $form_is_partial &&
$wgRequest->getCheck( 'partial' ) ) {
$existing_page_content =
preg_replace( '/\}\}/m', '}�',
preg_replace(
'/\{\{/m', '�{', $template_text ) ) .
-
"\n{{{insertionpoint}}}\n" . $existing_page_content;
+
"{{{insertionpoint}}}" . $existing_page_content;
}
}
}
diff --git a/includes/SF_TemplateInForm.php b/includes/SF_TemplateInForm.php
index ee6557c..eab14fe 100644
--- a/includes/SF_TemplateInForm.php
+++ b/includes/SF_TemplateInForm.php
@@ -24,6 +24,7 @@
private $mFullTextInPage;
private $mValuesFromPage = array();
private $mValuesFromSubmit;
+ private $mNumInstancesFromSubmit = 0;
private $mPageCallsThisTemplate = false;
private $mInstanceNum = 0;
private $mAllInstancesPrinted = false;
@@ -395,22 +396,27 @@
//$query_template_name = str_replace( "'", "\'",
$query_template_name );
$allValuesFromSubmit = $wgRequest->getArray(
$query_template_name );
+ if ( is_null( $allValuesFromSubmit ) ) {
+ return;
+ }
// If this is a multiple-instance template, get the values for
// this instance of the template.
if ( $this->mAllowMultiple ) {
- if ( $this->mInstanceNum < $this->mMinAllowed ) {
- // Print another instance until we reach the
minimum
- // instances, which is also the starting number.
- } elseif ( $this->mInstanceNum < count(
$allValuesFromSubmit ) ) {
- // We're not done yet.
- } else {
- $this->mAllInstancesPrinted = true;
- return array();
+ // For some reason, sometimes duplicate information is
+ // submitted - getting rid of 'num' and everything
+ // after it seems to works.
+ $valuesFromSubmitKeys = array();
+ foreach ( array_keys( $allValuesFromSubmit ) as $key ) {
+ if ( $key == 'num' ) {
+ break;
+ }
+ $valuesFromSubmitKeys[] = $key;
}
-
- $valuesFromSubmitKeys = array_keys(
$allValuesFromSubmit );
- $instanceKey =
$valuesFromSubmitKeys[$this->mInstanceNum];
- $this->mValuesFromSubmit =
$allValuesFromSubmit[$instanceKey];
+ $this->mNumInstancesFromSubmit = count(
$valuesFromSubmitKeys );
+ if ( $this->mNumInstancesFromSubmit >
$this->mInstanceNum ) {
+ $instanceKey =
$valuesFromSubmitKeys[$this->mInstanceNum];
+ $this->mValuesFromSubmit =
$allValuesFromSubmit[$instanceKey];
+ }
} else {
$this->mValuesFromSubmit = $allValuesFromSubmit;
}
--
To view, visit https://gerrit.wikimedia.org/r/266247
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id818f9d77016f3c052e6b860d53c96ff103a49cd
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