logo       

[MediaWiki-CVS] SVN: [54104] tags/extensions/DataTransfer: msg#01482

mediawiki-cvs

Subject: [MediaWiki-CVS] SVN: [54104] tags/extensions/DataTransfer

http://www.mediawiki.org/wiki/Special:Code/MediaWiki/54104

Revision: 54104
Author: yaron
Date: 2009-07-31 15:22:37 +0000 (Fri, 31 Jul 2009)

Log Message:
-----------
Tag for version 0.3.4

Added Paths:
-----------
tags/extensions/DataTransfer/REL_0_3_4/
tags/extensions/DataTransfer/REL_0_3_4/INSTALL
tags/extensions/DataTransfer/REL_0_3_4/includes/DT_GlobalFunctions.php
tags/extensions/DataTransfer/REL_0_3_4/specials/DT_ImportCSV.php

Removed Paths:
-------------
tags/extensions/DataTransfer/REL_0_3_4/INSTALL
tags/extensions/DataTransfer/REL_0_3_4/includes/DT_GlobalFunctions.php
tags/extensions/DataTransfer/REL_0_3_4/specials/DT_ImportCSV.php

Deleted: tags/extensions/DataTransfer/REL_0_3_4/INSTALL
===================================================================
--- trunk/extensions/DataTransfer/INSTALL 2009-07-31 14:30:14 UTC (rev
54099)
+++ tags/extensions/DataTransfer/REL_0_3_4/INSTALL 2009-07-31 15:22:37 UTC
(rev 54104)
@@ -1,31 +0,0 @@
-[[Data Transfer 0.3.3]]
-
-Contents:
-* Disclaimer
-* Requirements
-* Installation
-* Contact
-
-== Disclaimer ==
-
-For a proper legal disclaimer, see the file "COPYING".
-
-== Requirements ==
-
-The extension can make use of, but does not require, an install of
-Semantic MediaWiki. If Semantic MediaWiki is used, it must be of
-version 0.6 or greater. For more details, see Semantic MediaWiki's
-own installation requirements.
-
-== Installation ==
-
-(1) Extract the archive to obtain the directory "DataTransfer"
- that contains all relevant files. Copy this directory (or
- extract/download it) to "[wikipath]/extensions/".
-(2) Insert the following line into the file "[wikipath]/LocalSettings.php":
- include_once('extensions/DataTransfer/includes/DT_Settings.php');
-
-== Contact ==
-
-If you have any issues or questions, please send them to
-yaron57@xxxxxxxxxx

Copied: tags/extensions/DataTransfer/REL_0_3_4/INSTALL (from rev 54103,
trunk/extensions/DataTransfer/INSTALL)
===================================================================
--- tags/extensions/DataTransfer/REL_0_3_4/INSTALL
(rev 0)
+++ tags/extensions/DataTransfer/REL_0_3_4/INSTALL 2009-07-31 15:22:37 UTC
(rev 54104)
@@ -0,0 +1,31 @@
+[[Data Transfer 0.3.4]]
+
+Contents:
+* Disclaimer
+* Requirements
+* Installation
+* Contact
+
+== Disclaimer ==
+
+For a proper legal disclaimer, see the file "COPYING".
+
+== Requirements ==
+
+The extension can make use of, but does not require, an install of
+Semantic MediaWiki. If Semantic MediaWiki is used, it must be of
+version 0.6 or greater. For more details, see Semantic MediaWiki's
+own installation requirements.
+
+== Installation ==
+
+(1) Extract the archive to obtain the directory "DataTransfer"
+ that contains all relevant files. Copy this directory (or
+ extract/download it) to "[wikipath]/extensions/".
+(2) Insert the following line into the file "[wikipath]/LocalSettings.php":
+ include_once('extensions/DataTransfer/includes/DT_Settings.php');
+
+== Contact ==
+
+If you have any issues or questions, please send them to
+yaron57@xxxxxxxxxx

Deleted: tags/extensions/DataTransfer/REL_0_3_4/includes/DT_GlobalFunctions.php
===================================================================
--- trunk/extensions/DataTransfer/includes/DT_GlobalFunctions.php
2009-07-31 14:30:14 UTC (rev 54099)
+++ tags/extensions/DataTransfer/REL_0_3_4/includes/DT_GlobalFunctions.php
2009-07-31 15:22:37 UTC (rev 54104)
@@ -1,124 +0,0 @@
-<?php
-/**
- * Global functions and constants for the Data Transfer extension.
- *
- * @author Yaron Koren
- */
-
-if (!defined('MEDIAWIKI')) die();
-
-define('DT_VERSION','0.3.3');
-
-// constants for special properties
-define('DT_SP_HAS_XML_GROUPING', 1);
-define('DT_SP_IS_EXCLUDED_FROM_XML', 2);
-
-$wgExtensionCredits['specialpage'][]= array(
- 'path' => __FILE__,
- 'name' => 'Data Transfer',
- 'version' => DT_VERSION,
- 'author' => 'Yaron Koren',
- 'url' =>
'http://www.mediawiki.org/wiki/Extension:Data_Transfer',
- 'description' => 'Allows for importing and exporting data contained
in template calls',
- 'descriptionmsg' => 'dt-desc',
-);
-
-$dtgIP = $IP . '/extensions/DataTransfer';
-
-// register all special pages and other classes
-$wgSpecialPages['ViewXML'] = 'DTViewXML';
-$wgAutoloadClasses['DTViewXML'] = $dtgIP . '/specials/DT_ViewXML.php';
-$wgSpecialPages['ImportXML'] = 'DTImportXML';
-$wgAutoloadClasses['DTImportXML'] = $dtgIP . '/specials/DT_ImportXML.php';
-$wgSpecialPages['ImportCSV'] = 'DTImportCSV';
-$wgAutoloadClasses['DTImportCSV'] = $dtgIP . '/specials/DT_ImportCSV.php';
-$wgJobClasses['dtImport'] = 'DTImportJob';
-$wgAutoloadClasses['DTImportJob'] = $dtgIP . '/includes/DT_ImportJob.php';
-$wgAutoloadClasses['DTXMLParser'] = $dtgIP . '/includes/DT_XMLParser.php';
-$wgHooks['AdminLinks'][] = 'dtfAddToAdminLinks';
-$wgHooks['smwInitProperties'][] = 'dtfInitProperties';
-
-require_once($dtgIP . '/languages/DT_Language.php');
-$wgExtensionMessagesFiles['DataTransfer'] = $dtgIP .
'/languages/DT_Messages.php';
-$wgExtensionAliasesFiles['DataTransfer'] = $dtgIP .
'/languages/DT_Aliases.php';
-
-/**********************************************/
-/***** language settings *****/
-/**********************************************/
-
-/**
- * Initialise a global language object for content language. This
- * must happen early on, even before user language is known, to
- * determine labels for additional namespaces. In contrast, messages
- * can be initialised much later when they are actually needed.
- */
-function dtfInitContentLanguage($langcode) {
- global $dtgIP, $dtgContLang;
-
- if (!empty($dtgContLang)) { return; }
-
- $dtContLangClass = 'DT_Language' . str_replace( '-', '_', ucfirst(
$langcode ) );
-
- if (file_exists($dtgIP . '/languages/'. $dtContLangClass . '.php')) {
- include_once( $dtgIP . '/languages/'. $dtContLangClass . '.php'
);
- }
-
- // fallback if language not supported
- if ( !class_exists($dtContLangClass)) {
- include_once($dtgIP . '/languages/DT_LanguageEn.php');
- $dtContLangClass = 'DT_LanguageEn';
- }
-
- $dtgContLang = new $dtContLangClass();
-}
-
-/**
- * Initialise the global language object for user language. This
- * must happen after the content language was initialised, since
- * this language is used as a fallback.
- */
-function dtfInitUserLanguage($langcode) {
- global $dtgIP, $dtgLang;
-
- if (!empty($dtgLang)) { return; }
-
- $dtLangClass = 'DT_Language' . str_replace( '-', '_', ucfirst(
$langcode ) );
-
- if (file_exists($dtgIP . '/languages/'. $dtLangClass . '.php')) {
- include_once( $dtgIP . '/languages/'. $dtLangClass . '.php' );
- }
-
- // fallback if language not supported
- if ( !class_exists($dtLangClass)) {
- global $dtgContLang;
- $dtgLang = $dtgContLang;
- } else {
- $dtgLang = new $dtLangClass();
- }
-}
-
-/**********************************************/
-/***** other global helpers *****/
-/**********************************************/
-
-function dtfInitProperties() {
- global $dtgContLang;
- $dt_props = $dtgContLang->getPropertyLabels();
- SMWPropertyValue::registerProperty('_DT_XG', '_str',
$dt_props[DT_SP_HAS_XML_GROUPING], true);
- // TODO - this should set a "backup" English value as well,
- // so that the phrase "Has XML grouping" works in all languages
- return true;
-}
-
-/**
- * Add links to the 'AdminLinks' special page, defined by the Admin Links
- * extension
- */
-function dtfAddToAdminLinks($admin_links_tree) {
- $import_export_section =
$admin_links_tree->getSection(wfMsg('adminlinks_importexport'));
- $main_row = $import_export_section->getRow('main');
- $main_row->addItem(ALItem::newFromSpecialPage('ViewXML'));
- $main_row->addItem(ALItem::newFromSpecialPage('ImportXML'));
- $main_row->addItem(ALItem::newFromSpecialPage('ImportCSV'));
- return true;
-}

Copied: tags/extensions/DataTransfer/REL_0_3_4/includes/DT_GlobalFunctions.php
(from rev 54103, trunk/extensions/DataTransfer/includes/DT_GlobalFunctions.php)
===================================================================
--- tags/extensions/DataTransfer/REL_0_3_4/includes/DT_GlobalFunctions.php
(rev 0)
+++ tags/extensions/DataTransfer/REL_0_3_4/includes/DT_GlobalFunctions.php
2009-07-31 15:22:37 UTC (rev 54104)
@@ -0,0 +1,124 @@
+<?php
+/**
+ * Global functions and constants for the Data Transfer extension.
+ *
+ * @author Yaron Koren
+ */
+
+if (!defined('MEDIAWIKI')) die();
+
+define('DT_VERSION','0.3.4');
+
+// constants for special properties
+define('DT_SP_HAS_XML_GROUPING', 1);
+define('DT_SP_IS_EXCLUDED_FROM_XML', 2);
+
+$wgExtensionCredits['specialpage'][]= array(
+ 'path' => __FILE__,
+ 'name' => 'Data Transfer',
+ 'version' => DT_VERSION,
+ 'author' => 'Yaron Koren',
+ 'url' =>
'http://www.mediawiki.org/wiki/Extension:Data_Transfer',
+ 'description' => 'Allows for importing and exporting data contained
in template calls',
+ 'descriptionmsg' => 'dt-desc',
+);
+
+$dtgIP = $IP . '/extensions/DataTransfer';
+
+// register all special pages and other classes
+$wgSpecialPages['ViewXML'] = 'DTViewXML';
+$wgAutoloadClasses['DTViewXML'] = $dtgIP . '/specials/DT_ViewXML.php';
+$wgSpecialPages['ImportXML'] = 'DTImportXML';
+$wgAutoloadClasses['DTImportXML'] = $dtgIP . '/specials/DT_ImportXML.php';
+$wgSpecialPages['ImportCSV'] = 'DTImportCSV';
+$wgAutoloadClasses['DTImportCSV'] = $dtgIP . '/specials/DT_ImportCSV.php';
+$wgJobClasses['dtImport'] = 'DTImportJob';
+$wgAutoloadClasses['DTImportJob'] = $dtgIP . '/includes/DT_ImportJob.php';
+$wgAutoloadClasses['DTXMLParser'] = $dtgIP . '/includes/DT_XMLParser.php';
+$wgHooks['AdminLinks'][] = 'dtfAddToAdminLinks';
+$wgHooks['smwInitProperties'][] = 'dtfInitProperties';
+
+require_once($dtgIP . '/languages/DT_Language.php');
+$wgExtensionMessagesFiles['DataTransfer'] = $dtgIP .
'/languages/DT_Messages.php';
+$wgExtensionAliasesFiles['DataTransfer'] = $dtgIP .
'/languages/DT_Aliases.php';
+
+/**********************************************/
+/***** language settings *****/
+/**********************************************/
+
+/**
+ * Initialise a global language object for content language. This
+ * must happen early on, even before user language is known, to
+ * determine labels for additional namespaces. In contrast, messages
+ * can be initialised much later when they are actually needed.
+ */
+function dtfInitContentLanguage($langcode) {
+ global $dtgIP, $dtgContLang;
+
+ if (!empty($dtgContLang)) { return; }
+
+ $dtContLangClass = 'DT_Language' . str_replace( '-', '_', ucfirst(
$langcode ) );
+
+ if (file_exists($dtgIP . '/languages/'. $dtContLangClass . '.php')) {
+ include_once( $dtgIP . '/languages/'. $dtContLangClass . '.php'
);
+ }
+
+ // fallback if language not supported
+ if ( !class_exists($dtContLangClass)) {
+ include_once($dtgIP . '/languages/DT_LanguageEn.php');
+ $dtContLangClass = 'DT_LanguageEn';
+ }
+
+ $dtgContLang = new $dtContLangClass();
+}
+
+/**
+ * Initialise the global language object for user language. This
+ * must happen after the content language was initialised, since
+ * this language is used as a fallback.
+ */
+function dtfInitUserLanguage($langcode) {
+ global $dtgIP, $dtgLang;
+
+ if (!empty($dtgLang)) { return; }
+
+ $dtLangClass = 'DT_Language' . str_replace( '-', '_', ucfirst(
$langcode ) );
+
+ if (file_exists($dtgIP . '/languages/'. $dtLangClass . '.php')) {
+ include_once( $dtgIP . '/languages/'. $dtLangClass . '.php' );
+ }
+
+ // fallback if language not supported
+ if ( !class_exists($dtLangClass)) {
+ global $dtgContLang;
+ $dtgLang = $dtgContLang;
+ } else {
+ $dtgLang = new $dtLangClass();
+ }
+}
+
+/**********************************************/
+/***** other global helpers *****/
+/**********************************************/
+
+function dtfInitProperties() {
+ global $dtgContLang;
+ $dt_props = $dtgContLang->getPropertyLabels();
+ SMWPropertyValue::registerProperty('_DT_XG', '_str',
$dt_props[DT_SP_HAS_XML_GROUPING], true);
+ // TODO - this should set a "backup" English value as well,
+ // so that the phrase "Has XML grouping" works in all languages
+ return true;
+}
+
+/**
+ * Add links to the 'AdminLinks' special page, defined by the Admin Links
+ * extension
+ */
+function dtfAddToAdminLinks($admin_links_tree) {
+ $import_export_section =
$admin_links_tree->getSection(wfMsg('adminlinks_importexport'));
+ $main_row = $import_export_section->getRow('main');
+ $main_row->addItem(ALItem::newFromSpecialPage('ViewXML'));
+ $main_row->addItem(ALItem::newFromSpecialPage('ImportXML'));
+ $main_row->addItem(ALItem::newFromSpecialPage('ImportCSV'));
+ return true;
+}

Deleted: tags/extensions/DataTransfer/REL_0_3_4/specials/DT_ImportCSV.php
===================================================================
--- trunk/extensions/DataTransfer/specials/DT_ImportCSV.php 2009-07-31
14:30:14 UTC (rev 54099)
+++ tags/extensions/DataTransfer/REL_0_3_4/specials/DT_ImportCSV.php
2009-07-31 15:22:37 UTC (rev 54104)
@@ -1,169 +0,0 @@
-<?php
-/**
- * Lets the user import a CSV file to turn into wiki pages
- *
- * @author Yaron Koren
- */
-
-if (!defined('MEDIAWIKI')) die();
-
-class DTPage {
- var $mName;
- var $mTemplates;
- var $mFreeText;
-
- public function DTPage() {
- $this->mTemplates = array();
- }
-
- function setName($name) {
- $this->mName = $name;
- }
-
- function getName() {
- return $this->mName;
- }
-
- function addTemplateField($template_name, $field_name, $value) {
- if (! array_key_exists($template_name, $this->mTemplates)) {
- $this->mTemplates[$template_name] = array();
- }
- $this->mTemplates[$template_name][$field_name] = $value;
- }
-
- function setFreeText($free_text) {
- $this->mFreeText = $free_text;
- }
-
- function createText() {
- $text = "";
- foreach ($this->mTemplates as $template_name => $fields) {
- $text .= '{{' . $template_name . "\n";
- foreach ($fields as $field_name => $val) {
- $text .= "|$field_name=$val\n";
- }
- $text .= '}}' . "\n";
- }
- $text .= $this->mFreeText;
- return $text;
- }
-}
-
-class DTImportCSV extends SpecialPage {
-
- /**
- * Constructor
- */
- public function DTImportCSV() {
- global $wgLanguageCode;
- SpecialPage::SpecialPage('ImportCSV');
- wfLoadExtensionMessages('DataTransfer');
- }
-
- function execute($query) {
- global $wgUser, $wgOut, $wgRequest;
- $this->setHeaders();
-
- if ( ! $wgUser->isAllowed('datatransferimport') ) {
- global $wgOut;
- $wgOut->permissionRequired('datatransferimport');
- return;
- }
-
- if ($wgRequest->getCheck('import_file')) {
- $text = "<p>" . wfMsg('dt_import_importing') . "</p>\n";
- $source = ImportStreamSource::newFromUpload( "csv_file"
);
- if ($source instanceof WikiErrorMsg) {
- $text .= $source->getMessage();
- } else {
- $encoding = $wgRequest->getVal('encoding');
- $pages = array();
- $error_msg = self::getCSVData($source->mHandle,
$encoding, $pages);
- if (! is_null($error_msg))
- $text .= $error_msg;
- else
- $text .= self::modifyPages($pages);
- }
- } else {
- $select_file_label = wfMsg('dt_import_selectfile',
'CSV');
- $encoding_type_label = wfMsg('dt_import_encodingtype');
- $import_button = wfMsg('import-interwiki-submit');
- $text =<<<END
- <p>$select_file_label</p>
- <form enctype="multipart/form-data" action="" method="post">
- <p><input type="file" name="csv_file" size="25" /></p>
- <p>$encoding_type_label: <select name="encoding">
- <option selected value="utf8">UTF-8</option>
- <option value="utf16">UTF-16</option>
- </select>
- <p><input type="Submit" name="import_file" value="$import_button"></p>
- </form>
-
-END;
- }
-
- $wgOut->addHTML($text);
- }
-
-
- static function getCSVData($csv_file, $encoding, &$pages) {
- if (is_null($csv_file))
- return wfMsg('emptyfile');
- $table = array();
- while ($line = fgetcsv($csv_file)) {
- // fix values if the file wasn't UTF-8 encoded -
- // hopefully the UTF-8 value will work across all
- // database encodings
- if ($encoding == 'utf16') {
- $line = array_map('utf8_encode', $line);
- }
- array_push($table, $line);
- }
- fclose($csv_file);
- // check header line to make sure every term is in the
- // correct format
- $title_label = wfMsgForContent('dt_xml_title');
- $free_text_label = wfMsgForContent('dt_xml_freetext');
- foreach ($table[0] as $i => $header_val) {
- if ($header_val !== $title_label && $header_val !==
$free_text_label &&
- ! preg_match('/^[^\[\]]+\[[^\[\]]+]$/',
$header_val)) {
- $error_msg = wfMsg('dt_importcsv_badheader',
$i, $header_val, $title_label, $free_text_label);
- return $error_msg;
- }
- }
- foreach ($table as $i => $line) {
- if ($i == 0) continue;
- $page = new DTPage();
- foreach ($line as $j => $val) {
- if ($val == '') continue;
- if ($table[0][$j] == $title_label) {
- $page->setName($val);
- } elseif ($table[0][$j] == $free_text_label) {
- $page->setFreeText($val);
- } else {
- list($template_name, $field_name) =
explode('[', str_replace(']', '', $table[0][$j]));
- $page->addTemplateField($template_name,
$field_name, $val);
- }
- }
- $pages[] = $page;
- }
- }
-
- function modifyPages($pages) {
- $text = "";
- $jobs = array();
- $job_params = array();
- global $wgUser;
- $job_params['user_id'] = $wgUser->getId();
- $job_params['edit_summary'] =
wfMsgForContent('dt_import_editsummary', 'CSV');
- foreach ($pages as $page) {
- $title = Title::newFromText($page->getName());
- $job_params['text'] = $page->createText();
- $jobs[] = new DTImportJob( $title, $job_params );
- }
- Job::batchInsert( $jobs );
- $text .= wfMsg('dt_import_success', count($jobs), 'CSV');
- return $text;
- }
-
-}

Copied: tags/extensions/DataTransfer/REL_0_3_4/specials/DT_ImportCSV.php (from
rev 54102, trunk/extensions/DataTransfer/specials/DT_ImportCSV.php)
===================================================================
--- tags/extensions/DataTransfer/REL_0_3_4/specials/DT_ImportCSV.php
(rev 0)
+++ tags/extensions/DataTransfer/REL_0_3_4/specials/DT_ImportCSV.php
2009-07-31 15:22:37 UTC (rev 54104)
@@ -0,0 +1,180 @@
+<?php
+/**
+ * Lets the user import a CSV file to turn into wiki pages
+ *
+ * @author Yaron Koren
+ */
+
+if (!defined('MEDIAWIKI')) die();
+
+class DTPage {
+ var $mName;
+ var $mTemplates;
+ var $mFreeText;
+
+ public function DTPage() {
+ $this->mTemplates = array();
+ }
+
+ function setName($name) {
+ $this->mName = $name;
+ }
+
+ function getName() {
+ return $this->mName;
+ }
+
+ function addTemplateField($template_name, $field_name, $value) {
+ if (! array_key_exists($template_name, $this->mTemplates)) {
+ $this->mTemplates[$template_name] = array();
+ }
+ $this->mTemplates[$template_name][$field_name] = $value;
+ }
+
+ function setFreeText($free_text) {
+ $this->mFreeText = $free_text;
+ }
+
+ function createText() {
+ $text = "";
+ foreach ($this->mTemplates as $template_name => $fields) {
+ $text .= '{{' . $template_name . "\n";
+ foreach ($fields as $field_name => $val) {
+ $text .= "|$field_name=$val\n";
+ }
+ $text .= '}}' . "\n";
+ }
+ $text .= $this->mFreeText;
+ return $text;
+ }
+}
+
+class DTImportCSV extends SpecialPage {
+
+ /**
+ * Constructor
+ */
+ public function DTImportCSV() {
+ global $wgLanguageCode;
+ SpecialPage::SpecialPage('ImportCSV');
+ wfLoadExtensionMessages('DataTransfer');
+ }
+
+ function execute($query) {
+ global $wgUser, $wgOut, $wgRequest;
+ $this->setHeaders();
+
+ if ( ! $wgUser->isAllowed('datatransferimport') ) {
+ global $wgOut;
+ $wgOut->permissionRequired('datatransferimport');
+ return;
+ }
+
+ if ($wgRequest->getCheck('import_file')) {
+ $text = "<p>" . wfMsg('dt_import_importing') . "</p>\n";
+ $source = ImportStreamSource::newFromUpload( "csv_file"
);
+ if ($source instanceof WikiErrorMsg) {
+ $text .= $source->getMessage();
+ } else {
+ $encoding = $wgRequest->getVal('encoding');
+ $pages = array();
+ $error_msg = self::getCSVData($source->mHandle,
$encoding, $pages);
+ if (! is_null($error_msg))
+ $text .= $error_msg;
+ else
+ $text .= self::modifyPages($pages);
+ }
+ } else {
+ $select_file_label = wfMsg('dt_import_selectfile',
'CSV');
+ $encoding_type_label = wfMsg('dt_import_encodingtype');
+ $import_button = wfMsg('import-interwiki-submit');
+ $text =<<<END
+ <p>$select_file_label</p>
+ <form enctype="multipart/form-data" action="" method="post">
+ <p><input type="file" name="csv_file" size="25" /></p>
+ <p>$encoding_type_label: <select name="encoding">
+ <option selected value="utf8">UTF-8</option>
+ <option value="utf16">UTF-16</option>
+ </select>
+ <p><input type="Submit" name="import_file" value="$import_button"></p>
+ </form>
+
+END;
+ }
+
+ $wgOut->addHTML($text);
+ }
+
+
+ static function getCSVData($csv_file, $encoding, &$pages) {
+ if (is_null($csv_file))
+ return wfMsg('emptyfile');
+ $table = array();
+ if ($encoding == 'utf16') {
+ // change encoding to UTF-8
+ // Starting with PHP 5.3 we could use str_getcsv(),
+ // which would save the tempfile hassle
+ $tempfile = tmpfile();
+ $csv_string = '';
+ while (!feof($csv_file)) {
+ $csv_string .= fgets($csv_file, 65535);
+ }
+ fwrite($tempfile, iconv('UTF-16', 'UTF-8',
$csv_string));
+ fseek($tempfile, 0);
+ while ($line = fgetcsv($tempfile)) {
+ array_push($table, $line);
+ }
+ fclose($tempfile);
+ } else {
+ while ($line = fgetcsv($csv_file)) {
+ array_push($table, $line);
+ }
+ }
+ fclose($csv_file);
+ // check header line to make sure every term is in the
+ // correct format
+ $title_label = wfMsgForContent('dt_xml_title');
+ $free_text_label = wfMsgForContent('dt_xml_freetext');
+ foreach ($table[0] as $i => $header_val) {
+ if ($header_val !== $title_label && $header_val !==
$free_text_label &&
+ ! preg_match('/^[^\[\]]+\[[^\[\]]+]$/',
$header_val)) {
+ $error_msg = wfMsg('dt_importcsv_badheader',
$i, $header_val, $title_label, $free_text_label);
+ return $error_msg;
+ }
+ }
+ foreach ($table as $i => $line) {
+ if ($i == 0) continue;
+ $page = new DTPage();
+ foreach ($line as $j => $val) {
+ if ($val == '') continue;
+ if ($table[0][$j] == $title_label) {
+ $page->setName($val);
+ } elseif ($table[0][$j] == $free_text_label) {
+ $page->setFreeText($val);
+ } else {
+ list($template_name, $field_name) =
explode('[', str_replace(']', '', $table[0][$j]));
+ $page->addTemplateField($template_name,
$field_name, $val);
+ }
+ }
+ $pages[] = $page;
+ }
+ }
+
+ function modifyPages($pages) {
+ $text = "";
+ $jobs = array();
+ $job_params = array();
+ global $wgUser;
+ $job_params['user_id'] = $wgUser->getId();
+ $job_params['edit_summary'] =
wfMsgForContent('dt_import_editsummary', 'CSV');
+ foreach ($pages as $page) {
+ $title = Title::newFromText($page->getName());
+ $job_params['text'] = $page->createText();
+ $jobs[] = new DTImportJob( $title, $job_params );
+ }
+ Job::batchInsert( $jobs );
+ $text .= wfMsg('dt_import_success', count($jobs), 'CSV');
+ return $text;
+ }
+
+}



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

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise