Overview
Comment: | Séparation du javascript, et gestion complète des fichiers dans le wiki |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
37b834a9d6fead06913e5461a0a879ef |
User & Date: | bohwaz on 2015-04-08 05:20:13 |
Other Links: | manifest | tags |
Context
2015-04-08
| ||
07:01 | Galerie et liste des fichiers de la page wiki check-in: 71cc771f9e user: bohwaz tags: trunk | |
05:20 | Séparation du javascript, et gestion complète des fichiers dans le wiki check-in: 37b834a9d6 user: bohwaz tags: trunk | |
2015-04-01
| ||
06:09 | Icônes d'alignement des images check-in: c9250f642a user: bohwaz tags: trunk | |
Changes
Modified src/include/lib/Garradin/Fichiers.php from [99c5f5f1fe] to [1e13d85657].
︙ | ︙ | |||
209 210 211 212 213 214 215 | $db = DB::getInstance(); $db->exec('BEGIN;'); $db->simpleExec('DELETE FROM fichiers_compta_journal WHERE fichier = ?;', (int)$this->id); $db->simpleExec('DELETE FROM fichiers_wiki_pages WHERE fichier = ?;', (int)$this->id); $db->simpleExec('DELETE FROM fichiers_membres WHERE fichier = ?;', (int)$this->id); // Suppression du contenu s'il n'est pas utilisé par un autre fichier | | > > > | > | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | $db = DB::getInstance(); $db->exec('BEGIN;'); $db->simpleExec('DELETE FROM fichiers_compta_journal WHERE fichier = ?;', (int)$this->id); $db->simpleExec('DELETE FROM fichiers_wiki_pages WHERE fichier = ?;', (int)$this->id); $db->simpleExec('DELETE FROM fichiers_membres WHERE fichier = ?;', (int)$this->id); // Suppression du contenu s'il n'est pas utilisé par un autre fichier if (!($id_contenu = $db->simpleQuerySingle('SELECT f1.id_contenu FROM fichiers AS f1 INNER JOIN fichiers AS f2 ON f1.id_contenu = f2.id_contenu AND f1.id != f2.id WHERE f2.id = ?;', false, (int)$this->id))) { $db->simpleExec('DELETE FROM fichiers_contenu WHERE id = ?;', (int)$id_contenu); } $db->simpleExec('DELETE FROM fichiers WHERE id = ?;', (int)$this->id); $cache_id = 'fichiers.' . $this->id_contenu; Static_Cache::remove($cache_id); foreach (self::$allowed_thumb_sizes as $size) { Static_Cache::remove($cache_id . '.thumb.' . (int)$size); } return $db->exec('END;'); } /** * Renvoie le chemin vers le fichier local en cache, et le crée s'il n'existe pas * @return string Chemin local |
︙ | ︙ | |||
529 530 531 532 533 534 535 536 537 538 539 540 541 542 | { $file['url'] = self::_getURL($file['id'], $file['nom']); $file['thumb'] = $file['image'] ? self::_getURL($file['id'], $file['nom'], 200) : false; } return $files; } /** * Callback utilisé pour l'extension <<fichier>> dans le wiki-texte * @param array $args Arguments passés à l'extension * @param string $content Contenu éventuel (en mode bloc) * @param object $skriv Objet SkrivLite */ | > > > > > > > > > > > > > > > > > > > > | 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | { $file['url'] = self::_getURL($file['id'], $file['nom']); $file['thumb'] = $file['image'] ? self::_getURL($file['id'], $file['nom'], 200) : false; } return $files; } /** * Enlève d'une liste de fichiers ceux qui sont mentionnés dans un texte wiki * @param array $files Liste de fichiers * @param string $text texte wiki * @return array Un tableau qui ne contient pas les fichiers mentionnés dans $text */ static public function filterFilesUsedInText($files, $text) { preg_match_all('/<<?(?:fichier|image)\s*(?:\|\s*)?(\d+)/', $text, $match, PREG_PATTERN_ORDER); if (empty($match[1])) return $files; $used = $match[1]; return array_filter($files, function ($row) use ($used) { return !in_array($row['id'], $used); }); } /** * Callback utilisé pour l'extension <<fichier>> dans le wiki-texte * @param array $args Arguments passés à l'extension * @param string $content Contenu éventuel (en mode bloc) * @param object $skriv Objet SkrivLite */ |
︙ | ︙ |
Modified src/templates/admin/wiki/_fichiers.tpl from [1a0357459c] to [6ec0308947].
1 2 3 4 5 6 7 8 9 10 11 | {include file="admin/_head.tpl" title="Inclure un fichier" current="wiki" body_id="transparent" is_popup=true js=1} <form method="post" enctype="multipart/form-data" action="{$self_url|escape}" id="f_upload"> <fieldset> <legend>Téléverser un fichier</legend> <input type="hidden" name="MAX_FILE_SIZE" value="{$max_size|escape}" id="f_maxsize" /> <dl> <dd class="help">Taille maximale : {$max_size|format_bytes}</dd> <dd class="fileUpload"><input type="file" name="fichier" id="f_fichier" data-hash-check /></dd> </dl> <p class="submit"> | > > > > > > | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | {include file="admin/_head.tpl" title="Inclure un fichier" current="wiki" body_id="transparent" is_popup=true js=1} {if $error} <p class="error"> {$error|escape} </p> {/if} <form method="post" enctype="multipart/form-data" action="{$self_url|escape}" id="f_upload"> <fieldset> <legend>Téléverser un fichier</legend> <input type="hidden" name="MAX_FILE_SIZE" value="{$max_size|escape}" id="f_maxsize" /> <dl> <dd class="help">Taille maximale : {$max_size|format_bytes}</dd> <dd class="fileUpload"><input type="file" name="fichier" id="f_fichier" data-hash-check /></dd> </dl> <p class="submit"> <input type="hidden" name="{$csrf_field_name|escape}" value="{$csrf_value|escape}" /> <input type="submit" name="upload" id="f_submit" value="Envoyer le fichier" /> </p> </fieldset> </form> <form method="get" action="#" style="display: none;" id="insertImage"> <fieldset> <h3>Insérer une image dans le texte</h3> |
︙ | ︙ | |||
39 40 41 42 43 44 45 | {if !empty($images)} <ul class="gallery"> {foreach from=$images item="file"} <li> <figure> <a href="{$file.url|escape}" data-id="{$file.id}"><img src="{$file.thumb|escape}" alt="" title="{$file.nom|escape}" /></a> | | > | > | > | > | > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | {if !empty($images)} <ul class="gallery"> {foreach from=$images item="file"} <li> <figure> <a href="{$file.url|escape}" data-id="{$file.id}"><img src="{$file.thumb|escape}" alt="" title="{$file.nom|escape}" /></a> <form class="actions" method="post" action="{$self_url|escape}"> <a href="{$file.url|escape}" onclick="return !window.open(this.href);" class="icn" title="Télécharger">⇓</a> <input type="hidden" name="{$csrf_field_name|escape}" value="{$csrf_value|escape}" /> <input type="hidden" name="delete" value="{$file.id|escape}" /> <noscript><input type="submit" value="Supprimer" /></noscript> </form> </figure> </li> {/foreach} </ul> {/if} {if !empty($fichiers)} <table class="list"> <tbody> {foreach from=$fichiers item="file"} <tr> <th>{$file.nom|escape}</th> <td>{$file.type|escape}</td> <td class="actions"> <form class="actions" method="post" action="{$self_url|escape}"> <a href="{$file.url|escape}" onclick="return !window.open(this.href);" class="icn" title="Télécharger">⇓</a> <input type="hidden" name="{$csrf_field_name|escape}" value="{$csrf_value|escape}" /> <input type="hidden" name="delete" value="{$file.id|escape}" /> <noscript><input type="submit" value="Supprimer" /></noscript> </form> </td> </tr> {/foreach} </tbody> </table> {/if} {include file="admin/_foot.tpl"} |
Modified src/www/admin/static/admin.css from [15c2d8e99b] to [8189de5a0c].
︙ | ︙ | |||
619 620 621 622 623 624 625 626 627 628 629 630 631 632 | line-height: .8em; vertical-align: middle; padding: .2em; font-family: "gicon", sans-serif; color: #9c4f15; text-shadow: 1px 1px 1px #999; transition: all .2s; } .icn[title]:after { display: none; visibility: hidden; opacity: 0; position: absolute; | > > | 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | line-height: .8em; vertical-align: middle; padding: .2em; font-family: "gicon", sans-serif; color: #9c4f15; text-shadow: 1px 1px 1px #999; transition: all .2s; border: none; cursor: pointer; } .icn[title]:after { display: none; visibility: hidden; opacity: 0; position: absolute; |
︙ | ︙ | |||
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 | font-size: 0.8em; background: transparent; padding: 5px; border: 1px solid #ccc; border-radius: 5px; margin: .5em; color: #666; } form#insertImage .align input:hover, form#insertImage .cancel input:hover, { cursor: pointer; background-color: #eee; color: darkred; } | > | 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 | font-size: 0.8em; background: transparent; padding: 5px; border: 1px solid #ccc; border-radius: 5px; margin: .5em; color: #666; cursor: pointer; } form#insertImage .align input:hover, form#insertImage .cancel input:hover, { cursor: pointer; background-color: #eee; color: darkred; } |
Modified src/www/admin/static/scripts/wiki_editor.js from [2dad10610c] to [b1bcc40dca].
︙ | ︙ | |||
54 55 56 57 58 59 60 | var openFileInsert = function () { openIFrame(g.admin_url + 'wiki/_fichiers.php?page=' + wiki_id); }; window.te_insertFile = function (file) { | | | | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | var openFileInsert = function () { openIFrame(g.admin_url + 'wiki/_fichiers.php?page=' + wiki_id); }; window.te_insertFile = function (file) { var tag = ' <<fichier|'+file+'>>'; t.insertAtPosition(t.getSelection().start, tag); closeIFrame(); }; window.te_insertImage = function (file, position, caption) { var tag = ' <<image|' + file; if (position) tag += '|' + position; if (caption) tag += '|' + caption; |
︙ | ︙ |
Added src/www/admin/static/scripts/wiki_fichiers.js version [fdc7825154].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | (function () { g.onload(function () { uploadHelper($('#f_fichier'), { width: 1920, height: null, resize: true, bytes: 'o', size_error_msg: 'Le fichier %file fait %size, soit plus que la taille maximale autorisée de %max_size.' }); function insertImageHelper(file, from_upload) { if (!document.querySelectorAll) { window.parent.te_insertImage(file.id, 'centre'); return true; } var f = document.getElementById('insertImage'); f.style.display = 'block'; var inputs = f.querySelectorAll('input[type=button]'); for (var i = 0; i < inputs.length; i++) { inputs[i].onclick = function(e) { window.parent.te_insertImage(file.id, e.target.name, f.f_caption.value); }; } f.querySelector('dd.image').innerHTML = ''; var img = document.createElement('img'); img.src = file.thumb; img.alt = ''; f.querySelector('dd.image').appendChild(img); f.querySelector('dd.cancel input[type=reset]').onclick = function() { f.style.display = 'none'; if (from_upload) { location.href = location.href; } }; } window.insertHelper = function(data) { var file = (data.file || data); if (file.image) { insertImageHelper(file, true); } else { window.parent.te_insertFile(data.file.id); } return true; } var gallery = document.getElementsByClassName('gallery'); if (gallery.length == 1 && document.querySelector) { var items = gallery[0].getElementsByTagName('li'); for (var i = 0; i < items.length; i++) { var a = items[i].querySelector('figure > a'); a.onclick= function (e) { insertImageHelper({ id: this.getAttribute('data-id'), thumb: this.firstChild.src }); return false; }; } } var a = document.createElement('a'); a.className = 'icn'; a.title = 'Supprimer'; a.innerHTML = '✘'; a.onclick = function() { if (confirm('Supprimer ce fichier ?')) this.parentNode.submit(); }; var items = document.body.getElementsByTagName('form'); for (var i = 0; i < items.length, form = items[i]; i++) { if (form.className != 'actions') continue; var s = a.cloneNode(true); s.onclick = a.onclick; form.appendChild(s); } }); }()); |
Modified src/www/admin/wiki/_fichiers.php from [5bd0f3495e] to [96e3d7b3b6].
︙ | ︙ | |||
19 20 21 22 23 24 25 | // Vérification des hash avant upload if ($hash_check = Utils::post('uploadHelper_hashCheck')) { echo json_encode(Fichiers::checkHashList($hash_check)); exit; } | > > > > > > > > > > > > > > > > > > > > > > > > > > | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | // Vérification des hash avant upload if ($hash_check = Utils::post('uploadHelper_hashCheck')) { echo json_encode(Fichiers::checkHashList($hash_check)); exit; } if (Utils::post('delete')) { if (!Utils::CSRF_check('wiki_files_'.$page['id'])) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } else { try { $fichier = new Fichiers(Utils::post('delete')); if (!$fichier->checkAccess($user)) { throw new UserException('Vous n\'avez pas accès à ce fichier.'); } $fichier->remove(); Utils::redirect('/admin/wiki/_fichiers.php?page=' . $page['id']); } catch (UserException $e) { $error = $e->getMessage(); } } } if (Utils::post('upload') || isset($_POST['uploadHelper_status'])) { if (!Utils::CSRF_check('wiki_files_'.$page['id'])) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } elseif (Utils::post('uploadHelper_status') > 0) { $error = 'Un seul fichier peut être envoyé en même temps.'; } |
︙ | ︙ | |||
87 88 89 90 91 92 93 | $tpl->assign('images', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page['id'], true)); $tpl->assign('max_size', Utils::getMaxUploadSize()); $tpl->assign('error', $error); $tpl->assign('page', $page); $tpl->assign('sent', isset($_GET['sent']) ? true : false); | | > > > | 113 114 115 116 117 118 119 120 121 122 123 124 125 | $tpl->assign('images', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page['id'], true)); $tpl->assign('max_size', Utils::getMaxUploadSize()); $tpl->assign('error', $error); $tpl->assign('page', $page); $tpl->assign('sent', isset($_GET['sent']) ? true : false); $tpl->assign('custom_js', ['upload_helper.min.js', 'wiki_fichiers.js']); $tpl->assign('csrf_field_name', Utils::CSRF_field_name('wiki_files_' . $page['id'])); $tpl->assign('csrf_value', Utils::CSRF_create('wiki_files_' . $page['id'])); $tpl->display('admin/wiki/_fichiers.tpl'); |
Modified src/www/admin/wiki/index.php from [40c8d1ccc0] to [decb582e7c].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 | else { $tpl->assign('can_read', $wiki->canReadPage($page['droit_lecture'])); $tpl->assign('can_edit', $wiki->canWritePage($page['droit_ecriture'])); $tpl->assign('children', $wiki->getList($page['uri'] == $config->get('accueil_wiki') ? 0 : $page['id'])); $tpl->assign('breadcrumbs', $wiki->listBackBreadCrumbs($page['id'])); $tpl->assign('auteur', $membres->getNom($page['contenu']['id_auteur'])); } $tpl->assign('page', $page); $tpl->display('admin/wiki/page.tpl'); | > > > > > > > > > > > > > > > > > < < | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | else { $tpl->assign('can_read', $wiki->canReadPage($page['droit_lecture'])); $tpl->assign('can_edit', $wiki->canWritePage($page['droit_ecriture'])); $tpl->assign('children', $wiki->getList($page['uri'] == $config->get('accueil_wiki') ? 0 : $page['id'])); $tpl->assign('breadcrumbs', $wiki->listBackBreadCrumbs($page['id'])); $tpl->assign('auteur', $membres->getNom($page['contenu']['id_auteur'])); $images = Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page['id'], true); if ($images && !$page['contenu']['chiffrement']) { $images = Fichiers::filterFilesUsedInText($images, $page['contenu']['contenu']); } $fichiers = Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page['id'], false); if ($fichiers && !$page['contenu']['chiffrement']) { $fichiers = Fichiers::filterFilesUsedInText($fichiers, $page['contenu']['contenu']); } $tpl->assign('images', $images); $tpl->assign('fichiers', $fichiers); } $tpl->assign('page', $page); $tpl->display('admin/wiki/page.tpl'); |