Overview
Comment:Modernisation admin wiki et fichiers
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 9f46f9067fd439f21e398333af8264ba8fba9105
User & Date: bohwaz on 2017-05-18 07:29:04
Other Links: branch diff | manifest | tags
Context
2017-05-19
05:46
Modernisation/remise en fonctionnement des fichiers dans le wiki check-in: 2db443930d user: bohwaz tags: dev
2017-05-18
07:29
Modernisation admin wiki et fichiers check-in: 9f46f9067f user: bohwaz tags: dev
2017-05-17
07:08
Modernisation objet fichiers check-in: 18ca9332f5 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Fichiers.php from [249ae8890d] to [a32f5a5338].

377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
	 * @param  array  $list Liste de hash à vérifier
	 * @return array        Liste des hash trouvés
	 */
	static public function checkHashList($list)
	{
		$db = DB::getInstance();

		array_walk($list, function ($a) use ($db) {
			return $db->quote($a);
		});

		$query = sprintf('SELECT hash, 1 FROM fichiers_contenu WHERE hash IN (%s);', 
			$list);
		return $db->getAssoc($query);
	}

	/**
	 * Récupération du message d'erreur
	 * @param  integer $error Code erreur du $_FILE
	 * @return string Message d'erreur







|
|



|







377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
	 * @param  array  $list Liste de hash à vérifier
	 * @return array        Liste des hash trouvés
	 */
	static public function checkHashList($list)
	{
		$db = DB::getInstance();

		array_walk($list, function (&$a) use ($db) {
			$a = $db->quote($a);
		});

		$query = sprintf('SELECT hash, 1 FROM fichiers_contenu WHERE hash IN (%s);', 
			implode(', ', $list));
		return $db->getAssoc($query);
	}

	/**
	 * Récupération du message d'erreur
	 * @param  integer $error Code erreur du $_FILE
	 * @return string Message d'erreur

Modified src/include/lib/Garradin/Wiki.php from [004bc8f304] to [a4ede7290f].

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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
            $data['parent'] = (int) $data['parent'];

            if ($data['parent'] < 0)
            {
                $data['parent'] = 0;
            }

            if (!$db->simpleQuerySingle('SELECT 1 FROM wiki_pages WHERE id = ?;', false, $data['parent']))
            {
                $data['parent'] = 0;
            }
        }

        return true;
    }

    public function create($data = [])
    {
        $this->_checkFields($data);
        $db = DB::getInstance();

        if (!empty($data['uri']))
        {
            $data['uri'] = self::transformTitleToURI($data['uri']);

            if ($db->simpleQuerySingle('SELECT 1 FROM wiki_pages WHERE uri = ? LIMIT 1;', false, $data['uri']))
            {
                throw new UserException('Cette adresse de page est déjà utilisée pour une autre page, il faut en choisir une autre.');
            }
        }
        else
        {
            $data['uri'] = self::transformTitleToURI($data['titre']);

            if (!trim($data['uri']) || $db->simpleQuerySingle('SELECT 1 FROM wiki_pages WHERE uri = ? LIMIT 1;', false, $data['uri']))
            {
                $data['uri'] .= '_' . date('d-m-Y_H-i-s');
            }
        }

        $db->simpleInsert('wiki_pages', $data);
        $id = $db->lastInsertRowId();

        // On ne peut utiliser un trigger pour insérer dans la recherche
        // car les tables virtuelles font des opérations qui modifient
        // last_insert_rowid() et donc résultat incohérent
        $db->simpleInsert('wiki_recherche', ['id' => $id, 'titre' => $data['titre']]);

        return $id;
    }

    public function edit($id, $data = [])
    {
        $db = DB::getInstance();







|

















|








|





|





|







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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
            $data['parent'] = (int) $data['parent'];

            if ($data['parent'] < 0)
            {
                $data['parent'] = 0;
            }

            if (!$db->firstColumn('SELECT 1 FROM wiki_pages WHERE id = ?;', $data['parent']))
            {
                $data['parent'] = 0;
            }
        }

        return true;
    }

    public function create($data = [])
    {
        $this->_checkFields($data);
        $db = DB::getInstance();

        if (!empty($data['uri']))
        {
            $data['uri'] = self::transformTitleToURI($data['uri']);

            if ($db->firstColumn('SELECT 1 FROM wiki_pages WHERE uri = ? LIMIT 1;', $data['uri']))
            {
                throw new UserException('Cette adresse de page est déjà utilisée pour une autre page, il faut en choisir une autre.');
            }
        }
        else
        {
            $data['uri'] = self::transformTitleToURI($data['titre']);

            if (!trim($data['uri']) || $db->firstColumn('SELECT 1 FROM wiki_pages WHERE uri = ? LIMIT 1;', $data['uri']))
            {
                $data['uri'] .= '_' . date('d-m-Y_H-i-s');
            }
        }

        $db->insert('wiki_pages', $data);
        $id = $db->lastInsertRowId();

        // On ne peut utiliser un trigger pour insérer dans la recherche
        // car les tables virtuelles font des opérations qui modifient
        // last_insert_rowid() et donc résultat incohérent
        $db->insert('wiki_recherche', ['id' => $id, 'titre' => $data['titre']]);

        return $id;
    }

    public function edit($id, $data = [])
    {
        $db = DB::getInstance();
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
	        $data['date_creation'] = gmdate('Y-m-d H:i:s', strtotime($data['date_creation']));
	    }
        
        if (isset($data['uri']))
        {
            $data['uri'] = self::transformTitleToURI($data['uri']);

            if ($db->simpleQuerySingle('SELECT 1 FROM wiki_pages WHERE uri = ? AND id != ? LIMIT 1;', false, $data['uri'], (int)$id))
            {
                throw new UserException('Cette adresse de page est déjà utilisée pour une autre page, il faut en choisir une autre.');
            }
        }

        if (isset($data['droit_lecture']) && $data['droit_lecture'] >= self::LECTURE_CATEGORIE)
        {
            $data['droit_ecriture'] = $data['droit_lecture'];
        }

        if (isset($data['parent']) && (int)$data['parent'] == (int)$id)
        {
            $data['parent'] = 0;
        }

        $data['date_modification'] = gmdate('Y-m-d H:i:s');

        $db->simpleUpdate('wiki_pages', $data, 'id = '.(int)$id);
        return true;
    }

    public function delete($id)
    {
        $db = DB::getInstance();


        if ($db->simpleQuerySingle('SELECT COUNT(*) FROM wiki_pages WHERE parent = ?;', false, (int)$id))
        {
            return false;
        }

        // Suppression des fichiers liés
        $files = Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $id, null);

        foreach ($files as $file)
        {
            $file = new Fichiers($file['id'], $file);
            $file->remove();
        }

        $db->simpleExec('DELETE FROM wiki_revisions WHERE id_page = ?;', (int)$id);
        //$db->simpleExec('DELETE FROM wiki_suivi WHERE id_page = ?;', (int)$id); FIXME
        $db->simpleExec('DELETE FROM wiki_recherche WHERE id = ?;', (int)$id);
        $db->simpleExec('DELETE FROM wiki_pages WHERE id = ?;', (int)$id);

        return true;
    }

    public function get($id)
    {
        $db = DB::getInstance();
        return $db->simpleQuerySingle('SELECT *,
            strftime(\'%s\', date_creation) AS date_creation,
            strftime(\'%s\', date_modification) AS date_modification
            FROM wiki_pages WHERE id = ? LIMIT 1;', true, (int)$id);
    }

    public function getTitle($id)
    {
        $db = DB::getInstance();
        return $db->simpleQuerySingle('SELECT titre FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$id);
    }

    public function getRevision($id, $rev)
    {
        $db = DB::getInstance();
        $champ_id = Config::getInstance()->get('champ_identite');

        // FIXME pagination au lieu de bloquer à 1000
        return $db->simpleQuerySingle('SELECT r.revision, r.modification, r.id_auteur, r.contenu,
            strftime(\'%s\', r.date) AS date, LENGTH(r.contenu) AS taille, m.'.$champ_id.' AS nom_auteur,
            r.chiffrement
            FROM wiki_revisions AS r LEFT JOIN membres AS m ON m.id = r.id_auteur
            WHERE r.id_page = ? AND revision = ? LIMIT 1;', true, (int) $id, (int) $rev);
    }

    public function listRevisions($id)
    {
        $db = DB::getInstance();
        $champ_id = Config::getInstance()->get('champ_identite');

        // FIXME pagination au lieu de bloquer à 1000
        return $db->simpleStatementFetch('SELECT r.revision, r.modification, r.id_auteur,
            strftime(\'%s\', r.date) AS date, LENGTH(r.contenu) AS taille, m.'.$champ_id.' AS nom_auteur,
            LENGTH(r.contenu) - (SELECT LENGTH(contenu) FROM wiki_revisions WHERE id_page = r.id_page AND revision < r.revision ORDER BY revision DESC LIMIT 1)
            AS diff_taille, r.chiffrement
            FROM wiki_revisions AS r LEFT JOIN membres AS m ON m.id = r.id_auteur
            WHERE r.id_page = ? ORDER BY r.revision DESC LIMIT 1000;', SQLITE3_ASSOC, (int) $id);
    }

    public function editRevision($id, $revision_edition = 0, $data)
    {
        $db = DB::getInstance();

        $revision = $db->simpleQuerySingle('SELECT revision FROM wiki_pages WHERE id = ?;', false, (int)$id);

        // ?! L'ID fournit ne correspond à rien ?
        if ($revision === false)
        {
            throw new \RuntimeException('La page demandée n\'existe pas.');
        }

        // Pas de révision
        if ($revision == 0 && !trim($data['contenu']))
        {
            return true;
        }

        // Il faut obligatoirement fournir un ID d'auteur
        if (empty($data['id_auteur']) && $data['id_auteur'] !== null)
        {
            throw new \BadMethodCallException('Aucun ID auteur de fourni.');
        }

        $contenu = $db->simpleQuerySingle('SELECT contenu FROM wiki_revisions WHERE revision = ? AND id_page = ?;', false, (int)$revision, (int)$id);

        // Pas de changement au contenu, pas la peine d'enregistrer une nouvelle révision
        if (trim($contenu) == trim($data['contenu']))
        {
            return true;
        }








|

















|







>
|









|



|
<
|
|







|


|





|







<
|



|








|




|






|



















|







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

208
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
	        $data['date_creation'] = gmdate('Y-m-d H:i:s', strtotime($data['date_creation']));
	    }
        
        if (isset($data['uri']))
        {
            $data['uri'] = self::transformTitleToURI($data['uri']);

            if ($db->firstColumn('SELECT 1 FROM wiki_pages WHERE uri = ? AND id != ? LIMIT 1;', $data['uri'], (int)$id))
            {
                throw new UserException('Cette adresse de page est déjà utilisée pour une autre page, il faut en choisir une autre.');
            }
        }

        if (isset($data['droit_lecture']) && $data['droit_lecture'] >= self::LECTURE_CATEGORIE)
        {
            $data['droit_ecriture'] = $data['droit_lecture'];
        }

        if (isset($data['parent']) && (int)$data['parent'] == (int)$id)
        {
            $data['parent'] = 0;
        }

        $data['date_modification'] = gmdate('Y-m-d H:i:s');

        $db->update('wiki_pages', $data, 'id = :id', ['id' => (int)$id]);
        return true;
    }

    public function delete($id)
    {
        $db = DB::getInstance();

        // Ne pas permettre de supprimer une page qui a des sous-pages
        if ($db->firstColumn('SELECT 1 FROM wiki_pages WHERE parent = ? LIMIT 1;', (int)$id))
        {
            return false;
        }

        // Suppression des fichiers liés
        $files = Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $id, null);

        foreach ($files as $file)
        {
            $file = new Fichiers($file->id, $file);
            $file->remove();
        }

        $db->delete('wiki_revisions', 'id_page = ?', (int)$id);

        $db->delete('wiki_recherche', 'id = ?', (int)$id);
        $db->delete('wiki_pages', 'id = ?', (int)$id);

        return true;
    }

    public function get($id)
    {
        $db = DB::getInstance();
        return $db->first('SELECT *,
            strftime(\'%s\', date_creation) AS date_creation,
            strftime(\'%s\', date_modification) AS date_modification
            FROM wiki_pages WHERE id = ? LIMIT 1;', (int)$id);
    }

    public function getTitle($id)
    {
        $db = DB::getInstance();
        return $db->firstColumn('SELECT titre FROM wiki_pages WHERE id = ? LIMIT 1;', (int)$id);
    }

    public function getRevision($id, $rev)
    {
        $db = DB::getInstance();
        $champ_id = Config::getInstance()->get('champ_identite');


        return $db->first('SELECT r.revision, r.modification, r.id_auteur, r.contenu,
            strftime(\'%s\', r.date) AS date, LENGTH(r.contenu) AS taille, m.'.$champ_id.' AS nom_auteur,
            r.chiffrement
            FROM wiki_revisions AS r LEFT JOIN membres AS m ON m.id = r.id_auteur
            WHERE r.id_page = ? AND revision = ? LIMIT 1;', (int) $id, (int) $rev);
    }

    public function listRevisions($id)
    {
        $db = DB::getInstance();
        $champ_id = Config::getInstance()->get('champ_identite');

        // FIXME pagination au lieu de bloquer à 1000
        return $db->get('SELECT r.revision, r.modification, r.id_auteur,
            strftime(\'%s\', r.date) AS date, LENGTH(r.contenu) AS taille, m.'.$champ_id.' AS nom_auteur,
            LENGTH(r.contenu) - (SELECT LENGTH(contenu) FROM wiki_revisions WHERE id_page = r.id_page AND revision < r.revision ORDER BY revision DESC LIMIT 1)
            AS diff_taille, r.chiffrement
            FROM wiki_revisions AS r LEFT JOIN membres AS m ON m.id = r.id_auteur
            WHERE r.id_page = ? ORDER BY r.revision DESC LIMIT 1000;', (int) $id);
    }

    public function editRevision($id, $revision_edition = 0, $data)
    {
        $db = DB::getInstance();

        $revision = $db->firstColumn('SELECT revision FROM wiki_pages WHERE id = ?;', (int)$id);

        // ?! L'ID fournit ne correspond à rien ?
        if ($revision === false)
        {
            throw new \RuntimeException('La page demandée n\'existe pas.');
        }

        // Pas de révision
        if ($revision == 0 && !trim($data['contenu']))
        {
            return true;
        }

        // Il faut obligatoirement fournir un ID d'auteur
        if (empty($data['id_auteur']) && $data['id_auteur'] !== null)
        {
            throw new \BadMethodCallException('Aucun ID auteur de fourni.');
        }

        $contenu = $db->firstColumn('SELECT contenu FROM wiki_revisions WHERE revision = ? AND id_page = ?;', (int)$revision, (int)$id);

        // Pas de changement au contenu, pas la peine d'enregistrer une nouvelle révision
        if (trim($contenu) == trim($data['contenu']))
        {
            return true;
        }

275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299


300
301
302
303
304
305
306

        // Incrémentons le numéro de révision
        $revision++;

        $data['id_page'] = $id;
        $data['revision'] = $revision;

        $db->simpleInsert('wiki_revisions', $data);
        $db->simpleUpdate('wiki_pages', [
            'revision'          =>  $revision,
            'date_modification' =>  gmdate('Y-m-d H:i:s'),
        ], 'id = '.(int)$id);

        return true;
    }

    public function search($query)
    {
        $db = DB::getInstance();
        return $db->simpleStatementFetch('SELECT
            p.uri, r.*, snippet(wiki_recherche, \'<b>\', \'</b>\', \'...\', -1, -50) AS snippet,
            rank(matchinfo(wiki_recherche), 0, 1.0, 1.0) AS points
            FROM wiki_recherche AS r INNER JOIN wiki_pages AS p ON p.id = r.id
            WHERE '.$this->_getLectureClause('p.').' AND wiki_recherche MATCH \''.$db->escapeString($query).'\'
            ORDER BY points DESC LIMIT 0,50;');


    }

    public function setRestrictionCategorie($id, $droit_wiki)
    {
        $this->restriction_categorie = $id;
        $this->restriction_droit = $droit_wiki;
        return true;







|
|


|




|

<
|



|
|
>
>







274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

        // Incrémentons le numéro de révision
        $revision++;

        $data['id_page'] = $id;
        $data['revision'] = $revision;

        $db->insert('wiki_revisions', $data);
        $db->update('wiki_pages', [
            'revision'          =>  $revision,
            'date_modification' =>  gmdate('Y-m-d H:i:s'),
        ], 'id = :id', ['id' => (int)$id]);

        return true;
    }

    public function search($search)
    {

        $query = sprintf('SELECT
            p.uri, r.*, snippet(wiki_recherche, \'<b>\', \'</b>\', \'...\', -1, -50) AS snippet,
            rank(matchinfo(wiki_recherche), 0, 1.0, 1.0) AS points
            FROM wiki_recherche AS r INNER JOIN wiki_pages AS p ON p.id = r.id
            WHERE %s AND wiki_recherche MATCH ?
            ORDER BY points DESC LIMIT 0,50;', $this->_getLectureClause('p.'));

        return DB::getInstance()->get($query, $search);
    }

    public function setRestrictionCategorie($id, $droit_wiki)
    {
        $this->restriction_categorie = $id;
        $this->restriction_droit = $droit_wiki;
        return true;
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494

495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
            return true;

        return false;
    }

    public function getList($parent = 0, $order_by_date = false)
    {
        $db = DB::getInstance();
        $order = ($order_by_date ? 'date_creation DESC' : 'transliterate_to_ascii(titre) COLLATE NOCASE');

        return $db->simpleStatementFetch(
            'SELECT id, revision, uri, titre,
                strftime(\'%s\', date_creation) AS date_creation,
                strftime(\'%s\', date_modification) AS date_modification
                FROM wiki_pages
                WHERE parent = ? AND '.$this->_getLectureClause().'
                ORDER BY '.$order.' LIMIT 500;',
            SQLITE3_ASSOC,
            (int) $parent
        );
    }

    public function getById($id)
    {
        $db = DB::getInstance();
        $page = $db->simpleQuerySingle('SELECT *,
                strftime(\'%s\', date_creation) AS date_creation,
                strftime(\'%s\', date_modification) AS date_modification
                FROM wiki_pages
                WHERE id = ?;', true, (int)$id);

        if (!$page)
        {
            return false;
        }

        if ($page['revision'] > 0)
        {
            $page['contenu'] = $db->simpleQuerySingle('SELECT * FROM wiki_revisions
                WHERE id_page = ? AND revision = ?;', true, (int)$page['id'], (int)$page['revision']);
        }
        else
        {
            $page['contenu'] = false;

        }

        return $page;
    }

    public function getByURI($uri)
    {
        $db = DB::getInstance();
        $page = $db->simpleQuerySingle('SELECT *,
                strftime(\'%s\', date_creation) AS date_creation,
                strftime(\'%s\', date_modification) AS date_modification
                FROM wiki_pages
                WHERE uri = ?;', true, trim($uri));

        if (!$page)
        {
            return false;
        }

        if ($page['revision'] > 0)
        {
            $page['contenu'] = $db->simpleQuerySingle('SELECT * FROM wiki_revisions
                WHERE id_page = ? AND revision = ?;', true, (int)$page['id'], (int)$page['revision']);
        }
        else
        {
            $page['contenu'] = false;
        }

        return $page;
    }

    public function listRecentModifications($page = 1)
    {
        $begin = ($page - 1) * self::ITEMS_PER_PAGE;

        $db = DB::getInstance();

        return $db->simpleStatementFetch('SELECT *,
                strftime(\'%s\', date_creation) AS date_creation,
                strftime(\'%s\', date_modification) AS date_modification
                FROM wiki_pages
                WHERE '.$this->_getLectureClause().'
                ORDER BY date_modification DESC;', SQLITE3_ASSOC);
    }

    public function countRecentModifications()
    {
        $db = DB::getInstance();
        return $db->simpleQuerySingle('SELECT COUNT(*) FROM wiki_pages WHERE '.$this->_getLectureClause().';');
    }

    public function listBackBreadCrumbs($id)
    {
        if ($id == 0)
            return [];

        $db = DB::getInstance();
        $flat = [];
        $max = 0;

        while ($id > 0 && $max++ < 10)
        {
            $res = $db->simpleQuerySingle('SELECT parent, titre, uri
                FROM wiki_pages WHERE id = ? LIMIT 1;', true, (int)$id);

            $flat[] = [
                'id'        =>  $id,
                'titre'     =>  $res['titre'],
                'uri'       =>  $res['uri'],
            ];

            if ($id == $res['parent'])
            {
                throw new Exception('Parent! ' . $id . '/' . $res['parent']);
            }

            $id = (int)$res['parent'];
        }

        return array_reverse($flat);
    }

    public function listBackParentTree($id)
    {
        $db = DB::getInstance();
        $flat = [
            [

                'id' => 0,
                'parent' => null,
                'titre' => 'Racine',
                'children' => $db->simpleStatementFetchAssocKey('SELECT id, parent, titre FROM wiki_pages
                    WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;',
                    SQLITE3_ASSOC, 0)
            ]
        ];

        $max = 0;

        do
        {
            $parent = $db->simpleQuerySingle('SELECT parent FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$id);

            $flat[$id] = [
                'id'        =>  $id,
                'parent'    =>  $id ? (int)$parent : null,
                'titre'     =>  $id ? (string)$db->simpleQuerySingle('SELECT titre FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$id) : 'Racine',
                'children'  =>  $db->simpleStatementFetchAssocKey('SELECT id, parent, titre FROM wiki_pages
                    WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;',
                    SQLITE3_ASSOC, (int)$id)
            ];

            $id = (int)$parent;
        }
        while ($id != 0 && $max++ < 20);

        $tree = [];
        foreach ($flat as $id=>&$node)
        {
            if (is_null($node['parent']))
            {
                $tree[$id] = &$node;
            }
            else
            {
                if (!isset($flat[$node['parent']]['children']))
                {
                    $flat[$node['parent']]['children'] = [];
                }

                $flat[$node['parent']]['children'][$id] = &$node;
            }
        }

        return $tree;
    }
}







<


<
|
|
|

|
|
<
|
<





|
|
|
|
|






|
|
|
<
<
<

|
>







|
<
<
<
<
<

|




<
<
<
<
<
<
<
<
<
<
|








|




|





|













|
|



|
|


|

|


|









<
>



|

|









|


|
|

|









|





|

|


|






363
364
365
366
367
368
369

370
371

372
373
374
375
376
377

378

379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397



398
399
400
401
402
403
404
405
406
407
408





409
410
411
412
413
414










415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472

473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
            return true;

        return false;
    }

    public function getList($parent = 0, $order_by_date = false)
    {

        $order = ($order_by_date ? 'date_creation DESC' : 'transliterate_to_ascii(titre) COLLATE NOCASE');


        $query = sprintf('SELECT id, revision, uri, titre,
                strftime(\'%%s\', date_creation) AS date_creation,
                strftime(\'%%s\', date_modification) AS date_modification
                FROM wiki_pages
                WHERE parent = ? AND %s ORDER BY %s LIMIT 500;', $this->_getLectureClause(), $order);


        return DB::getInstance()->get($query, (int) $parent);

    }

    public function getById($id)
    {
        $db = DB::getInstance();
        $page = $db->first('SELECT *,
            strftime(\'%s\', date_creation) AS date_creation,
            strftime(\'%s\', date_modification) AS date_modification
            FROM wiki_pages
            WHERE id = ?;', (int)$id);

        if (!$page)
        {
            return false;
        }

        $page->contenu = false;

        if ($page->revision > 0)



        {
            $page->contenu = $db->first('SELECT * FROM wiki_revisions
                WHERE id_page = ? AND revision = ?;', (int)$page->id, (int)$page->revision);
        }

        return $page;
    }

    public function getByURI($uri)
    {
        $id = DB::getInstance()->firstColumn('SELECT id FROM wiki_pages WHERE uri = ?;', $uri);






        if (!$id)
        {
            return false;
        }











        return $this->getByID($id);
    }

    public function listRecentModifications($page = 1)
    {
        $begin = ($page - 1) * self::ITEMS_PER_PAGE;

        $db = DB::getInstance();

        return $db->get('SELECT *,
                strftime(\'%s\', date_creation) AS date_creation,
                strftime(\'%s\', date_modification) AS date_modification
                FROM wiki_pages
                WHERE '.$this->_getLectureClause().'
                ORDER BY date_modification DESC;');
    }

    public function countRecentModifications()
    {
        $db = DB::getInstance();
        return $db->firstColumn('SELECT COUNT(*) FROM wiki_pages WHERE '.$this->_getLectureClause().';');
    }

    public function listBackBreadCrumbs($id)
    {
        if ($id == 0)
            return [];

        $db = DB::getInstance();
        $flat = [];
        $max = 0;

        while ($id > 0 && $max++ < 10)
        {
            $res = $db->first('SELECT parent, titre, uri
                FROM wiki_pages WHERE id = ? LIMIT 1;', (int)$id);

            $flat[] = [
                'id'        =>  $id,
                'titre'     =>  $res->titre,
                'uri'       =>  $res->uri,
            ];

            if ($id == $res->parent)
            {
                throw new Exception('Parent! ' . $id . '/' . $res->parent);
            }

            $id = (int)$res->parent;
        }

        return array_reverse($flat);
    }

    public function listBackParentTree($id)
    {
        $db = DB::getInstance();
        $flat = [

            (object) [
                'id' => 0,
                'parent' => null,
                'titre' => 'Racine',
                'children' => $db->getAssocKey('SELECT id, parent, titre FROM wiki_pages
                    WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;',
                    0)
            ]
        ];

        $max = 0;

        do
        {
            $parent = $db->simpleQuerySingle('SELECT parent FROM wiki_pages WHERE id = ? LIMIT 1;', false, (int)$id);

            $flat[$id] = (object) [
                'id'        =>  $id,
                'parent'    =>  $id ? (int)$parent : null,
                'titre'     =>  $id ? $this->getTitle($id) : 'Racine',
                'children'  =>  $db->getAssocKey('SELECT id, parent, titre FROM wiki_pages
                    WHERE parent = ? ORDER BY transliterate_to_ascii(titre) COLLATE NOCASE;',
                    (int)$id)
            ];

            $id = (int)$parent;
        }
        while ($id != 0 && $max++ < 20);

        $tree = [];
        foreach ($flat as $id=>&$node)
        {
            if (is_null($node->parent))
            {
                $tree[$id] = &$node;
            }
            else
            {
                if (!isset($flat[$node->parent]->children))
                {
                    $flat[$node->parent]->children = [];
                }

                $flat[$node->parent]->children[$id] = &$node;
            }
        }

        return $tree;
    }
}

Modified src/templates/admin/wiki/_fichiers.tpl from [0b713bbc92] to [dd6a332789].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{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}
    </p>
{/if}

<form method="post" enctype="multipart/form-data" action="{$self_url}" id="f_upload">
    <fieldset>
        <legend>Téléverser un fichier</legend>
        <input type="hidden" name="MAX_FILE_SIZE" value="{$max_size}" id="f_maxsize" />
        <dl>
            <dd class="help">Taille maximale : {$max_size|format_bytes}</dd>


<
<
|
<
<







1
2


3


4
5
6
7
8
9
10
{include file="admin/_head.tpl" title="Inclure un fichier" current="wiki" body_id="transparent" is_popup=true js=1}



{form_errors}



<form method="post" enctype="multipart/form-data" action="{$self_url}" id="f_upload">
    <fieldset>
        <legend>Téléverser un fichier</legend>
        <input type="hidden" name="MAX_FILE_SIZE" value="{$max_size}" id="f_maxsize" />
        <dl>
            <dd class="help">Taille maximale : {$max_size|format_bytes}</dd>

Modified src/templates/admin/wiki/creer.tpl from [85b6a3631c] to [f972f094f4].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{include file="admin/_head.tpl" title="Créer une page" current="wiki"}

{if $error}
    <p class="error">
        {$error}
    </p>
{/if}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Informations</legend>
        <dl>
            <dt><label for="f_titre">Titre</label> <b title="(Champ obligatoire)">obligatoire</b></dt>


<
<
|
<
<







1
2


3


4
5
6
7
8
9
10
{include file="admin/_head.tpl" title="Créer une page" current="wiki"}



{form_errors}



<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Informations</legend>
        <dl>
            <dt><label for="f_titre">Titre</label> <b title="(Champ obligatoire)">obligatoire</b></dt>

Modified src/templates/admin/wiki/editer.tpl from [63babc113b] to [8014427a9f].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{include file="admin/_head.tpl" title="Éditer une page" current="wiki" js=1}

{if $error}
    <p class="error">
        {$error}
    </p>
{/if}

<form method="post" action="{$self_url}" id="f_form">

    <fieldset class="wikiMain">
        <legend>Informations générales</legend>
        <dl>
            <dt><label for="f_titre">Titre</label> <b title="(Champ obligatoire)">obligatoire</b></dt>


<
<
|
<
<







1
2


3


4
5
6
7
8
9
10
{include file="admin/_head.tpl" title="Éditer une page" current="wiki" js=1}



{form_errors}



<form method="post" action="{$self_url}" id="f_form">

    <fieldset class="wikiMain">
        <legend>Informations générales</legend>
        <dl>
            <dt><label for="f_titre">Titre</label> <b title="(Champ obligatoire)">obligatoire</b></dt>

Modified src/templates/admin/wiki/supprimer.tpl from [9dc193042d] to [24adc9aa6f].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{include file="admin/_head.tpl" title="Supprimer : %s"|args:$page.titre current="wiki"}

<ul class="actions">
    <li><a href="{$www_url}admin/wiki/"><strong>Wiki</strong></a></li>
    <li><a href="{$www_url}admin/wiki/chercher.php">Rechercher</a></li>
    <li><a href="{$www_url}admin/wiki/?{$page.uri}">Voir la page</a></li>
    <li><a href="{$www_url}admin/wiki/editer.php?id={$page.id}">Éditer</a></li>
</ul>

{if $error}
    <p class="error">
        {$error}
    </p>
{/if}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Supprimer cette page du wiki ?</legend>
        <h3 class="warning">
            Êtes-vous sûr de vouloir supprimer la page «&nbsp;{$page.titre}&nbsp;» ?









<
<
|
<
<







1
2
3
4
5
6
7
8
9


10


11
12
13
14
15
16
17
{include file="admin/_head.tpl" title="Supprimer : %s"|args:$page.titre current="wiki"}

<ul class="actions">
    <li><a href="{$www_url}admin/wiki/"><strong>Wiki</strong></a></li>
    <li><a href="{$www_url}admin/wiki/chercher.php">Rechercher</a></li>
    <li><a href="{$www_url}admin/wiki/?{$page.uri}">Voir la page</a></li>
    <li><a href="{$www_url}admin/wiki/editer.php?id={$page.id}">Éditer</a></li>
</ul>



{form_errors}



<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Supprimer cette page du wiki ?</legend>
        <h3 class="warning">
            Êtes-vous sûr de vouloir supprimer la page «&nbsp;{$page.titre}&nbsp;» ?

Modified src/www/admin/_inc.php from [eb2f2a42ed] to [ee330da3e9].

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
<?php

namespace Garradin;

use Garradin\Membres\Session;


require_once __DIR__ . '/../../include/init.php';

// Redirection automatique en HTTPS si nécessaire
if (PREFER_HTTPS !== true && PREFER_HTTPS >= 2 && empty($_SERVER['HTTPS']) && empty($_POST))
{
    utils::redirect(str_replace('http://', 'https://', utils::getSelfURL()));
    exit;
}

// Alias utiles pour la gestion de formulaires


function f($key)
{
    return \KD2\Form::get($key);
}


function fc($action, Array $rules, Array &$errors = [])
{
    return \KD2\Form::check($action, $rules, $errors);





















}

$tpl = Template::getInstance();
$tpl->assign('admin_url', WWW_URL . 'admin/');

$session = Session::get();






>











>
>


|


>
|

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
<?php

namespace Garradin;

use Garradin\Membres\Session;
use KD2\Form;

require_once __DIR__ . '/../../include/init.php';

// Redirection automatique en HTTPS si nécessaire
if (PREFER_HTTPS !== true && PREFER_HTTPS >= 2 && empty($_SERVER['HTTPS']) && empty($_POST))
{
    utils::redirect(str_replace('http://', 'https://', utils::getSelfURL()));
    exit;
}

// Alias utiles pour la gestion de formulaires

// Form element: retourne un élément de formulaire
function f($key)
{
    return Form::get($key);
}

// Form-Check: valider un formulaire
function fc($action, Array $rules = [], Array &$errors = [])
{
    return Form::check($action, $rules, $errors);
}

// Query-Validate: valider les éléments passés en GET
function qv(Array $rules)
{
    if (Form::validate($rules, $errors, $_GET))
    {
        return true;
    }

    foreach ($errors as &$error)
    {
        $error = sprintf('%s: %s', $error['name'], $error['rule']);
    }

    throw new UserException(sprintf('Paramètres invalides (%s).', implode(', ',  $errors)));
}

function qg($key)
{
    return isset($_GET[$key]) ? $_GET[$key] : null;
}

$tpl = Template::getInstance();
$tpl->assign('admin_url', WWW_URL . 'admin/');

$session = Session::get();

Modified src/www/admin/wiki/_chercher_parent.php from [0f4a26d1bc] to [9651102d9e].

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
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

if ((trim(Utils::get('parent')) == '') || !is_numeric(Utils::get('parent')))
{
    throw new UserException('Numéro de page parent invalide.');
}

$parent = (int) Utils::get('parent');

$tpl->assign('parent', $parent);
$tpl->assign('list', $wiki->listBackParentTree($parent));

function tpl_display_tree($params)
{
    if (isset($params['tree']))
        $tree = $params['tree'];
    else
        $tree = $params;

    $out = '<ul>';

    foreach ($tree as $node)
    {
        $out .= '<li'.(Utils::get('parent') == $node['id'] ? ' class="current"' : '').'><h3><a href="?parent='.(int)$node['id'].'">'.htmlspecialchars($node['titre'], ENT_QUOTES, 'UTF-8', false).'</a></h3>';

        if (!empty($node['children']))
        {
            $out .= tpl_display_tree($node['children']);
        }

        $out .= '</li>';
    }

    $out .= '</ul>';

    return $out;
}

$tpl->register_function('display_tree', 'Garradin\tpl_display_tree');

$tpl->display('admin/wiki/_chercher_parent.tpl');

?>





|
|
<
<
<
|






|
|







|

|

|













<
<
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


<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

qv(['parent' => 'required|numeric']);




$parent = (int) qg('parent');

$tpl->assign('parent', $parent);
$tpl->assign('list', $wiki->listBackParentTree($parent));

function tpl_display_tree($params)
{
    if (isset($params->tree))
        $tree = $params->tree;
    else
        $tree = $params;

    $out = '<ul>';

    foreach ($tree as $node)
    {
        $out .= '<li'.(qg('parent') == $node->id ? ' class="current"' : '').'><h3><a href="?parent='.(int)$node->id.'">'.htmlspecialchars($node->titre, ENT_QUOTES, 'UTF-8', false).'</a></h3>';

        if (!empty($node->children))
        {
            $out .= tpl_display_tree($node->children);
        }

        $out .= '</li>';
    }

    $out .= '</ul>';

    return $out;
}

$tpl->register_function('display_tree', 'Garradin\tpl_display_tree');

$tpl->display('admin/wiki/_chercher_parent.tpl');


Modified src/www/admin/wiki/_fichiers.php from [96e3d7b3b6] to [abc1a885cc].

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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

if ((trim(Utils::get('page')) == '') || !is_numeric(Utils::get('page')))
{
    throw new UserException('Numéro de page invalide.');
}

$page = $wiki->getById(Utils::get('page'));
$error = false;

if (!$page)
{
    throw new UserException('Page introuvable.');
}

// 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.';

    }
    elseif (!empty($_POST['fichier']) || isset($_FILES['fichier']))
    {
        try {
            if (isset($_POST['uploadHelper_status']) && !empty($_POST['fichier']))
            {
                $fichier = Fichiers::uploadExistingHash(Utils::post('fichier'), Utils::post('uploadHelper_fileHash'));
            }
            else
            {
                $fichier = Fichiers::upload($_FILES['fichier']);
            }

            // Lier le fichier à la page wiki
            $fichier->linkTo(Fichiers::LIEN_WIKI, $page['id']);
            $uri = '/admin/wiki/_fichiers.php?page=' . $page['id'] . '&sent';

            if (isset($_POST['uploadHelper_status']))
            {
                echo json_encode([
                    'redirect'  =>  WWW_URL . $uri,
                    'callback'  =>  'insertHelper',
                    'file'      =>  [
                        'image' =>  (int)$fichier->image,
                        'id'    =>  (int)$fichier->id,
                        'nom'   =>  $fichier->nom,
                        'thumb' =>  $fichier->image ? $fichier->getURL(200) : false
                    ],
                ]);
                exit;
            }

            Utils::redirect($uri);
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
    else
    {
        $error = 'Aucun fichier envoyé.';
    }

    if (isset($_POST['uploadHelper_status']))
    {
        echo json_encode(['error' => $error]);
        exit;
    }
}

$tpl->assign('fichiers', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page['id'], false));
$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');





|
|
<
<
<
|
|







|





|

|

<
<
<
<

|







|



|




|

|
|
<
<
|

|
>
|
|


|

|



|



|
|

|


















|




|


|

|




|
|


|

|



|
|


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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

qv(['page' => 'required|numeric']);




$page = $wiki->getById(qg('page'));
$form_errors = [];

if (!$page)
{
    throw new UserException('Page introuvable.');
}

// Vérification des hash avant upload
if ($hash_check = f('uploadHelper_hashCheck'))
{
    echo json_encode(Fichiers::checkHashList($hash_check));
    exit;
}

if (f('delete'))
{
    if (fc('wiki_files_'.$page->id, [], $form_errors))
    {




        try {
            $fichier = new Fichiers(f('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)
        {
            $form_errors[] = $e->getMessage();
        }
    }
}

if (f('upload') || f('uploadHelper_status') !== null)
{
    fc('wiki_files_'.$page->id, [], $form_errors);



    if (f('uploadHelper_status') > 0)
    {
        $form_errors[] = 'Un seul fichier peut être envoyé en même temps.';
    }
    
    if (f('fichier') && count($form_errors) === 0)
    {
        try {
            if (null !== f('uploadHelper_status') && f('fichier'))
            {
                $fichier = Fichiers::uploadExistingHash(f('fichier'), f('uploadHelper_fileHash'));
            }
            else
            {
                $fichier = Fichiers::upload(f('fichier'));
            }

            // Lier le fichier à la page wiki
            $fichier->linkTo(Fichiers::LIEN_WIKI, $page->id);
            $uri = '/admin/wiki/_fichiers.php?page=' . $page->id . '&sent';

            if (f('uploadHelper_status') !== null)
            {
                echo json_encode([
                    'redirect'  =>  WWW_URL . $uri,
                    'callback'  =>  'insertHelper',
                    'file'      =>  [
                        'image' =>  (int)$fichier->image,
                        'id'    =>  (int)$fichier->id,
                        'nom'   =>  $fichier->nom,
                        'thumb' =>  $fichier->image ? $fichier->getURL(200) : false
                    ],
                ]);
                exit;
            }

            Utils::redirect($uri);
        }
        catch (UserException $e)
        {
            $form_errors[] = $e->getMessage();
        }
    }
    else
    {
        $form_errors[] = 'Aucun fichier envoyé.';
    }

    if (f('uploadHelper_status') !== null)
    {
        echo json_encode(['error' => implode(PHP_EOL, $form_errors)]);
        exit;
    }
}

$tpl->assign('fichiers', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page->id, false));
$tpl->assign('images', Fichiers::listLinkedFiles(Fichiers::LIEN_WIKI, $page->id, true));

$tpl->assign('max_size', Utils::getMaxUploadSize());
$tpl->assign('form_errors', $form_errors);
$tpl->assign('page', $page);
$tpl->assign('sent', (bool)qg('sent'));

$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/_inc.php from [cc2813c16f] to [87acafcdb8].

1
2
3

4
5
6
7
8
9
10
11
12
13
14
<?php

namespace Garradin;

require_once __DIR__ . '/../_inc.php';

if ($user['droits']['wiki'] < Membres::DROIT_ACCES)
{
    throw new UserException("Vous n'avez pas le droit d'accéder à cette page.");
}

$wiki = new Wiki;
$wiki->setRestrictionCategorie($user['id_categorie'], $user['droits']['wiki']);

?>



>


|
|
<
<
<

|
<
<
1
2
3
4
5
6
7
8



9
10


<?php

namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$session->requireAccess('wiki', Membres::DROIT_ACCES);




$wiki = new Wiki;
$wiki->setRestrictionCategorie($user->id_categorie, $user->droits->wiki);


Modified src/www/admin/wiki/chercher.php from [c5890b7ab3] to [6cce625794].

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
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$q = trim(Utils::get('q'));

$tpl->assign('recherche', $q);

if (Utils::get('q'))
{
    $r = $wiki->search($q);
    $tpl->assign('resultats', $r);
    $tpl->assign('nb_resultats', count($r));
}

function tpl_clean_snippet($str)
{
    return preg_replace('!&lt;(/?b)&gt;!', '<$1>', $str);
}

$tpl->register_modifier('clean_snippet', 'Garradin\tpl_clean_snippet');

$tpl->display('admin/wiki/chercher.tpl');

?>





|



|














<
<
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24


<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$q = trim(qg('q'));

$tpl->assign('recherche', $q);

if ($q)
{
    $r = $wiki->search($q);
    $tpl->assign('resultats', $r);
    $tpl->assign('nb_resultats', count($r));
}

function tpl_clean_snippet($str)
{
    return preg_replace('!&lt;(/?b)&gt;!', '<$1>', $str);
}

$tpl->register_modifier('clean_snippet', 'Garradin\tpl_clean_snippet');

$tpl->display('admin/wiki/chercher.tpl');


Modified src/www/admin/wiki/creer.php from [8acb6b5d39] to [842d664ef0].

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
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$error = false;
$parent = (int) Utils::get('parent') ?: 0;

if (!empty($_POST['create']))
{
    if (!Utils::CSRF_check('wiki_create'))
    {

        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    {
        try {
            $id = $wiki->create([
                'titre'         =>  Utils::post('titre'),
                'parent'        =>  $parent,
            ]);

            Utils::redirect('/admin/wiki/editer.php?id='.$id);
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}

$tpl->assign('error', $error);

$tpl->display('admin/wiki/creer.tpl');

?>





|


|

|
<
>
|
<
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
<
|


<
<
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


<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$form_errors = [];
$parent = (int) Utils::get('parent') ?: 0;

if (f('create'))
{
    fc('wiki_create', [

        'titre' => 'required',
        'parent'=> 'required|integer'

    ], $form_errors);

    try {
        $id = $wiki->create([
            'titre'  => f('titre'),
            'parent' => $parent,
        ]);

        Utils::redirect('/admin/wiki/editer.php?id='.$id);
    }
    catch (UserException $e)
    {
        $form_errors[] = $e->getMessage();
    }
}


$tpl->assign('form_errors', $form_errors);

$tpl->display('admin/wiki/creer.tpl');


Modified src/www/admin/wiki/editer.php from [7a3da3be01] to [698ce7fbac].

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
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

if ($user['droits']['wiki'] < Membres::DROIT_ECRITURE)
{
    throw new UserException("Vous n'avez pas le droit d'accéder à cette page.");
}

if (!Utils::get('id') || !is_numeric(Utils::get('id')))
{
    throw new UserException('Numéro de page invalide.');
}

$page = $wiki->getById(Utils::get('id'));

$error = false;

if (!$page)
{
    throw new UserException('Page introuvable.');
}

if (!empty($page['contenu']))
{
    $page['chiffrement'] = $page['contenu']['chiffrement'];
    $page['contenu'] = $page['contenu']['contenu'];
}

if (Utils::post('date'))
{
    $date = Utils::post('date') . ' ' . sprintf('%02d:%02d', Utils::post('date_h'), Utils::post('date_min'));
}
else
{
    $date = false;
}

if (!empty($_POST['save']))
{
    if (!Utils::CSRF_check('wiki_edit_'.$page['id']))
    {





        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    elseif ($page['date_modification'] > (int) Utils::post('debut_edition'))
    {
        $error = 'La page a été modifiée par quelqu\'un d\'autre depuis que vous avez commencé l\'édition.';
    }
    else

    {
        try {
            $wiki->edit($page['id'], [
                'titre'         =>  Utils::post('titre'),
                'uri'           =>  Utils::post('uri'),
                'parent'        =>  Utils::post('parent'),
                'droit_lecture' =>  Utils::post('droit_lecture'),
                'droit_ecriture'=>  Utils::post('droit_ecriture'),
                'date_creation' =>  $date,
            ]);

            $wiki->editRevision($page['id'], (int) Utils::post('revision_edition'), [
                'contenu'       =>  Utils::post('contenu'),
                'modification'  =>  Utils::post('modification'),
                'id_auteur'     =>  $user['id'],
                'chiffrement'   =>  Utils::post('chiffrement'),
            ]);

            $page = $wiki->getById($page['id']);

            Utils::redirect('/admin/wiki/?'.$page['uri']);
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}

$parent = (int) Utils::post('parent') ?: (int) $page['parent'];
$tpl->assign('parent', $parent ? $wiki->getTitle($parent) : 0);

$tpl->assign('error', $error);
$tpl->assign('page', $page);

$tpl->assign('wiki', $wiki);

$tpl->assign('time', time());
$tpl->assign('date', $date ? strtotime($date) : $page['date_creation']);

$tpl->assign('custom_js', ['wiki_editor.js', 'wiki-encryption.js']);

$tpl->display('admin/wiki/editer.tpl');





|
|
<
<
|
<
|
<
<
<
|
>
|






|

|
|


|

|

<
|
<
<
|
<

|
<
>
>
>
>
>
|
|
|

|

|
>


|
|
|
|
|
|



|
|
|
|
|


|

|



|




|


|





|




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
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

$session->requireAccess('wiki', Membres::DROIT_ECRITURE);



qv(['id' => 'required|numeric']);





$page = $wiki->getById(qg('id'));
$form_errors = [];
$date = false;

if (!$page)
{
    throw new UserException('Page introuvable.');
}

if (!empty($page->contenu))
{
    $page->chiffrement = $page->contenu->chiffrement;
    $page->contenu = $page->contenu->contenu;
}

if (f('date'))
{
    $date = f('date') . ' ' . sprintf('%02d:%02d', f('date_h'), f('date_min'));
}




if (f('save'))

{
    fc('wiki_edit_'.$page->id, [

        'titre'          => 'required',
        'uri'            => 'required',
        'parent'         => 'numeric',
        'droit_lecture'  => 'numeric',
        'droit_ecriture' => 'numeric',
    ], $form_errors);
    
    if ($page->date_modification > (int) f('debut_edition'))
    {
        $form_errors[] = 'La page a été modifiée par quelqu\'un d\'autre depuis que vous avez commencé l\'édition.';
    }

    if (count($form_errors) === 0)
    {
        try {
            $wiki->edit($page->id, [
                'titre'         =>  f('titre'),
                'uri'           =>  f('uri'),
                'parent'        =>  f('parent'),
                'droit_lecture' =>  f('droit_lecture'),
                'droit_ecriture'=>  f('droit_ecriture'),
                'date_creation' =>  $date,
            ]);

            $wiki->editRevision($page->id, (int) f('revision_edition'), [
                'contenu'      =>  f('contenu'),
                'modification' =>  f('modification'),
                'id_auteur'    =>  $user->id,
                'chiffrement'  =>  f('chiffrement'),
            ]);

            $page = $wiki->getById($page->id);

            Utils::redirect('/admin/wiki/?'.$page->uri);
        }
        catch (UserException $e)
        {
            $form_errors[] = $e->getMessage();
        }
    }
}

$parent = (int) f('parent') ?: (int) $page->parent;
$tpl->assign('parent', $parent ? $wiki->getTitle($parent) : 0);

$tpl->assign('form_errors', $form_errors);
$tpl->assign('page', $page);

$tpl->assign('wiki', $wiki);

$tpl->assign('time', time());
$tpl->assign('date', $date ? strtotime($date) : $page->date_creation);

$tpl->assign('custom_js', ['wiki_editor.js', 'wiki-encryption.js']);

$tpl->display('admin/wiki/editer.tpl');

Modified src/www/admin/wiki/historique.php from [af9f7b27c0] to [0c8cd47a0e].

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
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

if (!trim(Utils::get('id')))
{
    throw new UserException("Page inconnue.");
}

$page = $wiki->getByID(Utils::get('id'));

if (!$page)
{
    throw new UserException("Cette page n'existe pas.");
}

if (!$wiki->canReadPage($page['droit_lecture']))
{
    throw new UserException("Vous n'avez pas le droit de voir cette page.");
}

if (Utils::get('diff'))
{
    $revs = explode('.', Utils::get('diff'));

    if (count($revs) != 2)
    {
        throw new UserException("Erreur de paramètre.");
    }

    $rev1 = $wiki->getRevision($page['id'], (int)$revs[0]);
    $rev2 = $wiki->getRevision($page['id'], (int)$revs[1]);

    if ($rev1['chiffrement'])
    {
        $rev1['contenu'] = 'Contenu chiffré';
    }

    if ($rev2['chiffrement'])
    {
        $rev2['contenu'] = 'Contenu chiffré';
    }

    $tpl->assign('rev1', $rev1);
    $tpl->assign('rev2', $rev2);
    $tpl->assign('diff', true);
}
else
{
    $tpl->assign('revisions', $wiki->listRevisions($page['id']));
}

$tpl->assign('can_edit', $wiki->canWritePage($page['droit_ecriture']));
$tpl->assign('page', $page);

$tpl->display('admin/wiki/historique.tpl');

?>





|
|
<
<
<
|






|




|

|






|
|

|

|


|

|








|


|



<
<
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


<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

qv(['id' => 'required|numeric']);




$page = $wiki->getByID(qg('id'));

if (!$page)
{
    throw new UserException("Cette page n'existe pas.");
}

if (!$wiki->canReadPage($page->droit_lecture))
{
    throw new UserException("Vous n'avez pas le droit de voir cette page.");
}

if (qg('diff'))
{
    $revs = explode('.', qg('diff'));

    if (count($revs) != 2)
    {
        throw new UserException("Erreur de paramètre.");
    }

    $rev1 = $wiki->getRevision($page->id, (int)$revs[0]);
    $rev2 = $wiki->getRevision($page->id, (int)$revs[1]);

    if ($rev1->chiffrement)
    {
        $rev1->contenu = 'Contenu chiffré';
    }

    if ($rev2->chiffrement)
    {
        $rev2->contenu = 'Contenu chiffré';
    }

    $tpl->assign('rev1', $rev1);
    $tpl->assign('rev2', $rev2);
    $tpl->assign('diff', true);
}
else
{
    $tpl->assign('revisions', $wiki->listRevisions($page->id));
}

$tpl->assign('can_edit', $wiki->canWritePage($page->droit_ecriture));
$tpl->assign('page', $page);

$tpl->display('admin/wiki/historique.tpl');


Modified src/www/admin/wiki/index.php from [eb50176436] to [1316e9394d].

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
{
    $tpl->assign('uri', $page_uri);
    $tpl->assign('can_edit', $wiki->canWritePage(Wiki::ECRITURE_NORMAL));
    $tpl->assign('can_read', true);
}
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 == '' ? 0 : $page['id'], true));
    $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->assign('custom_js', ['wiki_gallery.js']);

$tpl->display('admin/wiki/page.tpl');







>
|
|
|
|
|

|

|

|


|

|

|











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
{
    $tpl->assign('uri', $page_uri);
    $tpl->assign('can_edit', $wiki->canWritePage(Wiki::ECRITURE_NORMAL));
    $tpl->assign('can_read', true);
}
else
{
    $membres = new Membres;
    $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 == '' ? 0 : $page->id, true));
    $tpl->assign('breadcrumbs', $wiki->listBackBreadCrumbs($page->id));
    $tpl->assign('auteur', $page->contenu ? $membres->getNom($page->contenu->id_auteur) : null);

    $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->assign('custom_js', ['wiki_gallery.js']);

$tpl->display('admin/wiki/page.tpl');

Modified src/www/admin/wiki/recent.php from [4437267093] to [f963840a1e].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

namespace Garradin;

require_once __DIR__ . '/_inc.php';

$page = (int) Utils::get('p') ?: 1;

$tpl->assign('page', $page);
$tpl->assign('bypage', Wiki::ITEMS_PER_PAGE);
$tpl->assign('total', $wiki->countRecentModifications());
$tpl->assign('list', $wiki->listRecentModifications($page));

$tpl->display('admin/wiki/recent.tpl');

?>






|







<
<
1
2
3
4
5
6
7
8
9
10
11
12
13
14


<?php

namespace Garradin;

require_once __DIR__ . '/_inc.php';

$page = (int) qg('p') ?: 1;

$tpl->assign('page', $page);
$tpl->assign('bypage', Wiki::ITEMS_PER_PAGE);
$tpl->assign('total', $wiki->countRecentModifications());
$tpl->assign('list', $wiki->listRecentModifications($page));

$tpl->display('admin/wiki/recent.tpl');


Modified src/www/admin/wiki/supprimer.php from [e3a0d118d5] to [2f4ab439a2].

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
<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

if ($user['droits']['wiki'] < Membres::DROIT_ADMIN)
{
    throw new UserException("Vous n'avez pas le droit d'accéder à cette page.");
}

if (!trim(Utils::get('id')))
{
    throw new UserException("Page inconnue.");
}

$page = $wiki->getByID(Utils::get('id'));

if (!$page)
{
    throw new UserException("Cette page n'existe pas.");
}


$error = false;

if (!empty($_POST['delete']))
{
    if (!Utils::CSRF_check('delete_wiki_'.$page['id']))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    {
        if ($wiki->delete($page['id']))
        {
            Utils::redirect('/admin/wiki/');
        }
        else
        {
            $error = "D'autres pages utilisent cette page comme rubrique parente.";
        }
    }
}

$tpl->assign('error', $error);
$tpl->assign('page', $page);

$tpl->display('admin/wiki/supprimer.tpl');

?>





|
|
<
<
|
<
|
<
<
<
|






|
<

|

|

<
<
<
<
|





|




|



<
<
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


<?php
namespace Garradin;

require_once __DIR__ . '/_inc.php';

qv(['id' => 'required|numeric']);



$session->requireAccess('wiki', Membres::DROIT_ADMIN);





$page = $wiki->getByID(qg('id'));

if (!$page)
{
    throw new UserException("Cette page n'existe pas.");
}

$form_errors = [];


if (f('delete'))
{
    if (fc('delete_wiki_'.$page->id, [], $form_errors))
    {




        if ($wiki->delete($page->id))
        {
            Utils::redirect('/admin/wiki/');
        }
        else
        {
            $form_errors[] = "D'autres pages utilisent cette page comme rubrique parente.";
        }
    }
}

$tpl->assign('form_errors', $form_errors);
$tpl->assign('page', $page);

$tpl->display('admin/wiki/supprimer.tpl');