Yaron Koren has uploaded a new change for review.

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

Change subject: Fixed handling for templates with all blank values in CSV import
......................................................................

Fixed handling for templates with all blank values in CSV import

Change-Id: I258c272130f0bd433937fa4b6ed5a3da0506751b
---
M includes/DT_Page.php
M specials/DT_ImportCSV.php
2 files changed, 17 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataTransfer 
refs/changes/39/320839/2

diff --git a/includes/DT_Page.php b/includes/DT_Page.php
index 0bcf8db..00d68e1 100644
--- a/includes/DT_Page.php
+++ b/includes/DT_Page.php
@@ -6,28 +6,23 @@
  */
 
 class DTPage {
-       var/**
-        * Lets the user import a CSV file to turn into wiki pages
-        *
-        * @author Yaron Koren
-        */
-               $mName;
+       var $mName;
        var $mTemplates;
        var $mFreeText;
 
-       public function DTPage () {
+       public function DTPage() {
                $this->mTemplates = array();
        }
 
-       function setName ( $name ) {
+       function setName( $name ) {
                $this->mName = $name;
        }
 
-       function getName () {
+       function getName() {
                return $this->mName;
        }
 
-       function addTemplateField ( $template_name, $field_name, $value ) {
+       function addTemplateField( $template_name, $field_name, $value ) {
 
                if ( !array_key_exists( $template_name, $this->mTemplates ) ) {
                        $this->mTemplates[$template_name] = array();
@@ -35,16 +30,23 @@
                $this->mTemplates[$template_name][$field_name] = $value;
        }
 
-       function setFreeText ( $free_text ) {
+       function setFreeText( $free_text ) {
                $this->mFreeText = $free_text;
        }
 
-       function createText () {
+       function createText() {
                $text = "";
                foreach ( $this->mTemplates as $template_name => $fields ) {
-                       $text .= '{{' . $template_name . "\n";
+                       $fieldsAdded = false;
+                       $text .= '{{' . $template_name;
                        foreach ( $fields as $field_name => $val ) {
-                               $text .= "|$field_name=$val\n";
+                               if ( $val != '' ) {
+                                       $text .= "\n|$field_name=$val";
+                                       $fieldsAdded = true;
+                               }
+                       }
+                       if ( $fieldsAdded ) {
+                               $text .= "\n";
                        }
                        $text .= '}}' . "\n";
                }
diff --git a/specials/DT_ImportCSV.php b/specials/DT_ImportCSV.php
index 555700a..074a893 100644
--- a/specials/DT_ImportCSV.php
+++ b/specials/DT_ImportCSV.php
@@ -162,7 +162,7 @@
                        if ( $i == 0 ) continue;
                        $page = new DTPage();
                        foreach ( $line as $j => $val ) {
-                               if ( $val === '' || $table[0][$j] === '' ) {
+                               if ( $table[0][$j] === '' ) {
                                        continue;
                                }
                                if ( $table[0][$j] == $title_label ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I258c272130f0bd433937fa4b6ed5a3da0506751b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DataTransfer
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <yaro...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to