* `\wcf\form\AbstractCaptchaForm`: added parameter to force captcha usage for registered users.
* Added global disable switch for languages.
* Overhauled page tracking in sessions / user online locations
+* Overhauled language import form
#### CMS
<form enctype="multipart/form-data" method="post" action="{link controller='LanguageImport'}{/link}">
<div class="section">
- <dl{if $errorField == 'languageFile'} class="formError"{/if}>
- <dt><label for="languageFile">{lang}wcf.acp.language.import.source.file{/lang}</label></dt>
+ <dl{if $errorField == 'languageUpload'} class="formError"{/if}>
+ <dt><label for="languageUpload">{lang}wcf.acp.language.import.source.upload{/lang}</label></dt>
<dd>
- <input type="text" id="languageFile" name="languageFile" value="{$languageFile}" class="long" />
- {if $errorField == 'languageFile'}
+ <input type="file" id="languageUpload" name="languageUpload" />
+ {if $errorField == 'languageUpload'}
<small class="innerError">
{if $errorType == 'empty'}
{lang}wcf.global.form.error.empty{/lang}
{/if}
</small>
{/if}
- <small>{lang}wcf.acp.language.import.source.file.description{/lang}</small>
</dd>
</dl>
- <dl{if $errorField == 'languageUpload'} class="formError"{/if}>
- <dt><label for="languageUpload">{lang}wcf.acp.language.import.source.upload{/lang}</label></dt>
+ <dl{if $errorField == 'sourceLanguageID'} class="formError"{/if}>
+ <dt><label for="sourceLanguageID">{lang}wcf.acp.language.add.source{/lang}</label></dt>
<dd>
- <input type="file" id="languageUpload" name="languageUpload" />
- {if $errorField == 'languageUpload'}
+ <select id="sourceLanguageID" name="sourceLanguageID">
+ {foreach from=$languages item=language}
+ <option value="{@$language->languageID}"{if $language->languageID == $sourceLanguageID} selected="selected"{/if}>{$language->languageName} ({$language->languageCode})</option>
+ {/foreach}
+ </select>
+ {if $errorField == 'sourceLanguageID'}
<small class="innerError">
- {lang}wcf.acp.language.import.error{/lang} {$errorType}
+ {if $errorType == 'empty'}
+ {lang}wcf.global.form.error.empty{/lang}
+ {else}
+ {lang}wcf.acp.language.add.source.error.{@$errorType}{/lang}
+ {/if}
</small>
{/if}
+ <small>{lang}wcf.acp.language.add.source.description{/lang}</small>
</dd>
</dl>
public $filename = '';
/**
- * import field
- * @var string
+ * language object
+ * @var Language
*/
- public $importField = 'languageFile';
+ public $language;
/**
- * language object
- * @var \wcf\data\language\Language
+ * list of available languages
+ * @var Language[]
*/
- public $language = null;
+ public $languages = [];
/**
- * import language file
- * @var string
+ * source language object
+ * @var Language
*/
- public $languageFile = '';
+ public $sourceLanguage;
/**
- * list of available languages
- * @var Language[]
+ * source language id
+ * @var integer
*/
- public $languages = [];
+ public $sourceLanguageID = 0;
/**
* @inheritDoc
public function readFormParameters() {
parent::readFormParameters();
- // import
- if (isset($_POST['languageFile']) && !empty($_POST['languageFile'])) {
- $this->languageFile = $_POST['languageFile'];
- $this->filename = $_POST['languageFile'];
- }
if (isset($_FILES['languageUpload']) && !empty($_FILES['languageUpload']['tmp_name'])) {
- $this->importField = 'languageUpload';
$this->filename = $_FILES['languageUpload']['tmp_name'];
}
+ if (isset($_POST['sourceLanguageID'])) $this->sourceLanguageID = intval($_POST['sourceLanguageID']);
}
/**
// check file
if (!file_exists($this->filename)) {
- throw new UserInputException('languageFile');
+ throw new UserInputException('languageUpload');
+ }
+
+ if (empty($this->sourceLanguageID)) {
+ throw new UserInputException('sourceLanguageID');
+ }
+
+ // get language
+ $this->sourceLanguage = LanguageFactory::getInstance()->getLanguage($this->sourceLanguageID);
+ if (!$this->sourceLanguage->languageID) {
+ throw new UserInputException('sourceLanguageID');
}
// try to import
$xml->load($this->filename);
// import xml document
- $this->language = LanguageEditor::importFromXML($xml, -1);
+ $this->language = LanguageEditor::importFromXML($xml, -1, $this->sourceLanguage);
}
catch (SystemException $e) {
- throw new UserInputException($this->importField, $e->getMessage());
+ throw new UserInputException('languageUpload', $e->getMessage());
}
}
WCF::getTPL()->assign('success', true);
}
+ /**
+ * @inheritDoc
+ */
+ public function readData() {
+ parent::readData();
+
+ $this->languages = LanguageFactory::getInstance()->getLanguages();
+ }
+
/**
* @inheritDoc
*/
WCF::getTPL()->assign([
'languages' => $this->languages,
- 'languageFile' => $this->languageFile
+ 'sourceLanguageID' => $this->sourceLanguageID
]);
}
* Imports language items from an XML file into a new or a current language.
* Updates the relevant language files automatically.
*
- * @param XML $xml
+ * @param XML $xml
* @param integer $packageID
+ * @param Language $source
* @return LanguageEditor
*/
- public static function importFromXML(XML $xml, $packageID) {
+ public static function importFromXML(XML $xml, $packageID, Language $source = null) {
$languageCode = self::readLanguageCodeFromXML($xml);
// try to find an existing language with the given language code
'languageCode' => $languageCode,
'languageName' => $languageName
]);
+
+ if ($source) {
+ $sourceEditor = new LanguageEditor($source);
+ $sourceEditor->copy($language);
+ }
}
// import xml