diff --git a/handlers/DuplicateHandler.php b/handlers/DuplicateHandler.php index 77fefbe42..4cb72252b 100644 --- a/handlers/DuplicateHandler.php +++ b/handlers/DuplicateHandler.php @@ -1,6 +1,5 @@ duplicationManager->checkPostData($_POST); $this->duplicationManager->duplicateLocally($data); if ($data['duplicate-action'] == 'edit') { - $this->wiki->Redirect($this->wiki->href('edit', $data['pageTag'])); + $this->wiki->Redirect($this->wiki->href('edit', $data['newTag'])); return; } elseif ($data['duplicate-action'] == 'return') { @@ -59,7 +58,7 @@ public function run() return; } - $this->wiki->Redirect($this->wiki->href('', $data['pageTag'])); + $this->wiki->Redirect($this->wiki->href('', $data['newTag'])); return; } catch (Throwable $th) { @@ -80,23 +79,23 @@ public function run() $pageTitle = ''; if ($isEntry) { $title = _t('TEMPLATE_DUPLICATE_ENTRY') . ' ' . $this->wiki->GetPageTag(); - $pageContent = $this->getService(EntryManager::class)->getOne($this->wiki->GetPageTag()); + $originalContent = $this->getService(EntryManager::class)->getOne($this->wiki->GetPageTag()); if ($toExternalWiki) { - $pageTitle = $pageContent['bf_titre']; + $pageTitle = $originalContent['bf_titre']; $proposedTag = $this->wiki->GetPageTag(); - $pageContent = $this->wiki->page['body']; + $originalContent = $this->wiki->page['body']; } else { - $pageTitle = $pageContent['bf_titre'] . ' (' . _t('DUPLICATE') . ')'; + $pageTitle = $originalContent['bf_titre'] . ' (' . _t('DUPLICATE') . ')'; $proposedTag = genere_nom_wiki($pageTitle); } } elseif ($isList) { $title = _t('TEMPLATE_DUPLICATE_LIST') . ' ' . $this->wiki->GetPageTag(); - $pageContent = $this->getService(ListManager::class)->getOne($this->wiki->GetPageTag()); + $originalContent = $this->getService(ListManager::class)->getOne($this->wiki->GetPageTag()); if ($toExternalWiki) { - $pageTitle = $pageContent['titre_liste']; + $pageTitle = $originalContent['titre_liste']; $proposedTag = $this->wiki->GetPageTag(); } else { - $pageTitle = $pageContent['titre_liste'] . ' (' . _t('DUPLICATE') . ')'; + $pageTitle = $originalContent['titre_liste'] . ' (' . _t('DUPLICATE') . ')'; $proposedTag = genere_nom_wiki('Liste ' . $pageTitle); } } else { // page @@ -106,7 +105,7 @@ public function run() } else { $proposedTag = genere_nom_wiki($this->wiki->GetPageTag() . ' ' . _t('DUPLICATE')); } - $pageContent = $this->wiki->page['body']; + $originalContent = $this->wiki->page['body']; } $attachments = $this->duplicationManager->findFiles($this->wiki->page['tag']); $totalSize = 0; @@ -131,7 +130,7 @@ public function run() 'proposedTag' => $proposedTag ?? '', 'attachments' => $attachments ?? [], 'pageTitle' => $pageTitle ?? '', - 'pageContent' => $pageContent ?? '', + 'originalContent' => $originalContent ?? '', 'totalSize' => $this->duplicationManager->humanFilesize($totalSize ?? 0), 'type' => $type ?? '', 'baseUrl' => preg_replace('/\?$/Ui', '', $this->wiki->config['base_url']), diff --git a/includes/services/DuplicationManager.php b/includes/services/DuplicationManager.php index 05cae2a23..eca8e5232 100644 --- a/includes/services/DuplicationManager.php +++ b/includes/services/DuplicationManager.php @@ -146,7 +146,7 @@ private function findFilesInWikiText($tag, $wikiText) } /** - * Get file attachements from pageTag. + * Get file attachements from newTag. * * @param string $tag page id * @@ -209,21 +209,21 @@ public function duplicateFiles($fromTag, $toTag) public function checkPostData($data) { - if (empty($data['type']) || !in_array($data['type'], ['page', 'list', 'entry'])) { + if (empty($data['type']) || !in_array($data['type'], ['form', 'page', 'list', 'entry'])) { throw new \Exception(_t('NO_VALID_DATA_TYPE')); } - if (empty($data['pageTag'])) { + if (empty($data['newTag'])) { throw new \Exception(_t('EMPTY_PAGE_TAG')); } - if ($data['type'] != 'page' && empty($data['pageTitle'])) { + if ($data['type'] != 'page' && empty($data['newTitle'])) { throw new \Exception(_t('EMPTY_PAGE_TITLE')); } if (!$this->wiki->UserIsAdmin()) { throw new \Exception(_t('ONLY_ADMINS_CAN_DUPLICATE') . '.'); } - $page = $this->wiki->services->get(PageManager::class)->getOne($data['pageTag']); + $page = $this->wiki->services->get(PageManager::class)->getOne($data['newTag']); if ($page) { - throw new \Exception($data['pageTag'] . ' ' . _t('ALREADY_EXISTING')); + throw new \Exception($data['newTag'] . ' ' . _t('ALREADY_EXISTING')); } if (empty($data['duplicate-action']) || !in_array($data['duplicate-action'], ['open', 'edit', 'return'])) { throw new \Exception(_t('NO_DUPLICATE_ACTION') . '.'); @@ -240,11 +240,11 @@ public function duplicateLocally($data) switch ($data['type']) { case 'list': $list = $this->wiki->services->get(ListManager::class)->getOne($data['originalTag']); - $this->wiki->services->get(ListManager::class)->create($data['pageTitle'], $list['label'], $data['pageTag']); + $this->wiki->services->get(ListManager::class)->create($data['newTitle'], $list['label'], $data['newTag']); break; case 'entry': - $files = $this->duplicateFiles($data['originalTag'], $data['pageTag']); + $files = $this->duplicateFiles($data['originalTag'], $data['newTag']); $entry = $this->wiki->services->get(EntryManager::class)->getOne($this->wiki->getPageTag()); $fields = $this->getUploadFieldsFromEntry($this->wiki->GetPageTag()); foreach ($fields as $f) { @@ -252,8 +252,8 @@ public function duplicateLocally($data) $entry[$f->getPropertyName()] = str_replace($fi['originalFile'], $fi['duplicatedFile'], $entry[$f->getPropertyName()]); } } - $entry['id_fiche'] = $data['pageTag']; - $entry['bf_titre'] = $data['pageTitle']; + $entry['id_fiche'] = $data['newTag']; + $entry['bf_titre'] = $data['newTitle']; $entry['antispam'] = 1; $this->wiki->services->get(EntryManager::class)->create($entry['id_typeannonce'], $entry); break; @@ -261,11 +261,11 @@ public function duplicateLocally($data) default: case 'page': $newBody = $this->wiki->page['body']; - $files = $this->duplicateFiles($data['originalTag'], $data['pageTag']); + $files = $this->duplicateFiles($data['originalTag'], $data['newTag']); foreach ($files as $f) { $newBody = str_replace($f['originalFile'], $f['duplicatedFile'], $newBody); } - $this->wiki->services->get(PageManager::class)->save($data['pageTag'], $newBody); + $this->wiki->services->get(PageManager::class)->save($data['newTag'], $newBody); break; } @@ -277,7 +277,7 @@ public function duplicateLocally($data) ); $this->wiki->services->get(AclService::class)->save( - $data['pageTag'], + $data['newTag'], $privilege, $values['list'] ); @@ -291,7 +291,7 @@ public function duplicateLocally($data) foreach ($properties as $prop) { $values = $this->wiki->services->get(TripleStore::class)->getAll($data['originalTag'], $prop, '', ''); foreach ($values as $val) { - $this->wiki->services->get(TripleStore::class)->create($data['pageTag'], $prop, $val['value'], '', ''); + $this->wiki->services->get(TripleStore::class)->create($data['newTag'], $prop, $val['value'], '', ''); } } } @@ -302,7 +302,7 @@ public function importDistantContent($tag, $request) throw new Exception(_t('ACEDITOR_LINK_PAGE_ALREADY_EXISTS')); } $req = $request->request->all(); - foreach (['pageContent', 'sourceUrl', 'originalTag', 'type'] as $key) { + foreach (['originalContent', 'sourceUrl', 'originalTag', 'type'] as $key) { if (empty($req[$key])) { throw new Exception(_t('NOT_FOUND_IN_REQUEST', $key)); } @@ -312,7 +312,7 @@ public function importDistantContent($tag, $request) } $newUrl = explode('/?', $this->wiki->config['base_url'])[0]; - $newBody = str_replace($req['sourceUrl'], $newUrl, $req['pageContent']); + $newBody = str_replace($req['sourceUrl'], $newUrl, $req['originalContent']); if ($req['type'] === 'page') { $this->wiki->services->get(PageManager::class)->save($tag, $newBody); } elseif ($req['type'] === 'entry') { diff --git a/javascripts/handlers/duplicate.js b/javascripts/handlers/duplicate.js index 318aeec1e..e6e0b3154 100644 --- a/javascripts/handlers/duplicate.js +++ b/javascripts/handlers/duplicate.js @@ -58,7 +58,7 @@ document.addEventListener('DOMContentLoaded', () => { e.stopPropagation() return false }) - $('#urlWiki').on('change', () => { + $('#url-wiki').on('change', () => { $('.login-fields, .duplication-fields').addClass('hide') $('#login-message').html('') }) @@ -89,14 +89,14 @@ document.addEventListener('DOMContentLoaded', () => { method: 'POST', url: `${shortUrl}/?api/pages/${$('#pageTag').val()}/duplicate`, data: $('#form-duplication').serialize() - }).done((data) => { - if (btnAction == 'open') { - location = `${shortUrl}/?${data.pageTag}` - } else if (btnAction == 'edit') { - location = `${shortUrl}/?${data.pageTag}/edit` + }).done((d) => { + if (btnAction === 'open') { + document.location = `${shortUrl}/?${d.pageTag}` + } else if (btnAction === 'edit') { + document.location = `${shortUrl}/?${d.pageTag}/edit` } else { - const url = location.href.replace(/\/duplicate.*/, '') - location = url + const url = document.location.href.replace(/\/duplicate.*/, '') + document.location = url } }).fail((jqXHR) => { toastMessage(`${_t('ERROR')} ${jqXHR.status}`, 3000, 'alert alert-danger') @@ -109,7 +109,7 @@ document.addEventListener('DOMContentLoaded', () => { }) $('.btn-verify-wiki').on('click', () => { - let url = $('#urlWiki').val() + let url = $('#url-wiki').val() if (isValidUrl(url)) { let taburl = [] @@ -119,7 +119,7 @@ document.addEventListener('DOMContentLoaded', () => { taburl = url.split('?') } shortUrl = taburl[0].replace(/\/+$/g, '') - $('#baseUrl').text(`${shortUrl}/?`) + $('#base-url').text(`${shortUrl}/?`) url = `${shortUrl}/?api/auth/me` $.ajax({ method: 'GET', @@ -138,4 +138,4 @@ document.addEventListener('DOMContentLoaded', () => { toastMessage(_t('NOT_VALID_URL', { url }), 3000, 'alert alert-danger') } }) -}) +}) \ No newline at end of file diff --git a/templates/handlers/duplicate.twig b/templates/handlers/duplicate.twig index 5ef2cb14e..4c43e2f98 100644 --- a/templates/handlers/duplicate.twig +++ b/templates/handlers/duplicate.twig @@ -7,9 +7,9 @@
{{ _t('WIKI_URL_RECENT') }}.
- +
- + @@ -41,17 +41,17 @@ {% if pageTitle %}
- +
- +
{% endif %}
- +
- {{ baseUrl }} - + {{ baseUrl }} + {% if toExternalWiki %} @@ -69,7 +69,7 @@ {% endfor %} {% endif %} - {% if toExternalWiki %}{% endif %} + {% if toExternalWiki %}{% endif %}