Overview
Comment:Utilisation de SkrivML plutôt que SPIP/HTML comme langage de markup dans le wiki
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: dd75c55e87e23db0a3af677261d7c6688a2d8562
User & Date: bohwaz on 2015-01-31 02:14:21
Other Links: manifest | tags
Context
2015-01-31
02:56
correction appel namespace check-in: 9aab6f827b user: bohwaz tags: trunk
02:14
Utilisation de SkrivML plutôt que SPIP/HTML comme langage de markup dans le wiki check-in: dd75c55e87 user: bohwaz tags: trunk
2015-01-30
13:50
Ne pas permettre d'importer le numéro de catégorie, sinon on risque de changer les admins de catégorie, et de s'empêcher de se connecter. check-in: 94fb9a9df1 user: bohwaz tags: trunk
Changes

Modified src/include/lib/Garradin/Squelette_Filtres.php from [70711a0611] to [77ad36ce45].

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    static public function echapper_xml($texte)
    {
        return str_replace(''', ''', htmlspecialchars($texte, ENT_QUOTES, 'UTF-8'));
    }

    static public function formatter_texte($texte)
    {
        $texte = Utils::htmlLinksOnUrls($texte);
        $texte = Utils::htmlSpip($texte);
        $texte = Utils::htmlGarbage2xhtml($texte);

        $texte = self::typo_fr($texte);

        return $texte;
    }

    static public function typo_fr($str, $html = true)
    {







<
|
<
<







125
126
127
128
129
130
131

132


133
134
135
136
137
138
139
    static public function echapper_xml($texte)
    {
        return str_replace('&#039;', '&apos;', htmlspecialchars($texte, ENT_QUOTES, 'UTF-8'));
    }

    static public function formatter_texte($texte)
    {

        $texte = Utils::SkrivToHTML($texte);


        $texte = self::typo_fr($texte);

        return $texte;
    }

    static public function typo_fr($str, $html = true)
    {

Modified src/include/lib/Garradin/Template.php from [5f9337c020] to [3482f439eb].

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
    }

    return implode(' ', $out);
}

function tpl_format_wiki($str)
{
    $str = Utils::htmlLinksOnUrls($str);
    $str = Utils::htmlSpip($str);
    $str = Utils::htmlGarbage2xhtml($str);
    return $str;
}

function tpl_liens_wiki($str, $prefix)
{
    return preg_replace_callback('!<a href="([^/.:@]+)">!i', function ($matches) use ($prefix) {
        return '<a href="' . $prefix . Wiki::transformTitleToURI($matches[1]) . '">';
    }, $str);







<
<
<
|







189
190
191
192
193
194
195



196
197
198
199
200
201
202
203
    }

    return implode(' ', $out);
}

function tpl_format_wiki($str)
{



    return Squelette_Filtres::formatter_texte($str);
}

function tpl_liens_wiki($str, $prefix)
{
    return preg_replace_callback('!<a href="([^/.:@]+)">!i', function ($matches) use ($prefix) {
        return '<a href="' . $prefix . Wiki::transformTitleToURI($matches[1]) . '">';
    }, $str);

Modified src/include/lib/Garradin/Utils.php from [87835fc037] to [bf051c0ec8].

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

namespace Garradin;

class Utils
{
    static protected $country_list = null;

    static protected $g2x = null;

    static private $french_date_names = [
        'January'=>'Janvier', 'February'=>'Février', 'March'=>'Mars', 'April'=>'Avril', 'May'=>'Mai',
        'June'=>'Juin', 'July'=>'Juillet', 'August'=>'Août', 'September'=>'Septembre', 'October'=>'Octobre',
        'November'=>'Novembre', 'December'=>'Décembre', 'Monday'=>'Lundi', 'Tuesday'=>'Mardi', 'Wednesday'=>'Mercredi',
        'Thursday'=>'Jeudi','Friday'=>'Vendredi','Saturday'=>'Samedi','Sunday'=>'Dimanche',
        'Feb'=>'Fév','Apr'=>'Avr','May'=>'Mai','Jun'=>'Juin', 'Jul'=>'Juil','Aug'=>'Aout','Dec'=>'Déc',








|







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

namespace Garradin;

class Utils
{
    static protected $country_list = null;

    static protected $skriv = null;

    static private $french_date_names = [
        'January'=>'Janvier', 'February'=>'Février', 'March'=>'Mars', 'April'=>'Avril', 'May'=>'Mai',
        'June'=>'Juin', 'July'=>'Juillet', 'August'=>'Août', 'September'=>'Septembre', 'October'=>'Octobre',
        'November'=>'Novembre', 'December'=>'Décembre', 'Monday'=>'Lundi', 'Tuesday'=>'Mardi', 'Wednesday'=>'Mercredi',
        'Thursday'=>'Jeudi','Friday'=>'Vendredi','Saturday'=>'Samedi','Sunday'=>'Dimanche',
        'Feb'=>'Fév','Apr'=>'Avr','May'=>'Mai','Jun'=>'Juin', 'Jul'=>'Juil','Aug'=>'Aout','Dec'=>'Déc',
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
            function ($match) {
                $proto = $match[2] ?: $match[3];
                $text = ($proto == 'http' || $proto == 'mailto') ? $match[4] : $match[1];
                return '<a class="'.$proto.'" href="'.htmlspecialchars($match[1], ENT_QUOTES, 'UTF-8').'">'.htmlspecialchars($text, ENT_QUOTES, 'UTF-8').'</a>';
            }, $str);
    }






    static public function htmlGarbage2xhtml($str)
    {
        if (!self::$g2x)
        {
            self::$g2x = new \KD2\Garbage2xhtml;
            self::$g2x->core_attributes = ['class', 'id', 'title'];
        }



        return self::$g2x->process($str);
    }






    static public function htmlSpip($str, $prefix = '')
    {
        // Intertitres
        $str = preg_replace('/(?<!\\\\)\{{3}(\V*)\}{3}/', '<h3>$1</h3>', $str);

        // Gras
        $str = preg_replace('/(?<!\\\\)\{{2}(\V*)\}{2}/', '<strong>$1</strong>', $str);

        // Italique
        $str = preg_replace('/(?<!\\\\)\{(\V*)\}/', '<em>$1</em>', $str);


        // Espaces typograhiques


        $str = preg_replace('/\h*([?!;:»])(\s+|$)/u', '&nbsp;$1$2', $str);
        $str = preg_replace('/(^|\s+)([«])\h*/u', '$1$2&nbsp;', $str);



        // Liens
        $str = preg_replace('/(?<!\\\\)\[(.+?)->(.+?)\]/', '<a href="$2">$1</a>', $str);
        $str = preg_replace('/(?<!\\\\)\[(.+?)\]/', '<a href="$1">$1</a>', $str);

        // Adresses email
        $str = preg_replace('/<a href="((?!http).*@.*)">/iU', '<a href="mailto:$1">', $str);


        return $str;
    }

    static public function mail($to, $subject, $content, $additional_headers = [])
    {
        // Création du contenu du message
        $content = wordwrap($content);







>
>
>
>
>
|

|

|
<


>
>
|


>
>
>
>
>
|

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







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
            function ($match) {
                $proto = $match[2] ?: $match[3];
                $text = ($proto == 'http' || $proto == 'mailto') ? $match[4] : $match[1];
                return '<a class="'.$proto.'" href="'.htmlspecialchars($match[1], ENT_QUOTES, 'UTF-8').'">'.htmlspecialchars($text, ENT_QUOTES, 'UTF-8').'</a>';
            }, $str);
    }

    /**
     * Transforme un texte SkrivML en HTML
     * @param  string $str Texte SkrivML
     * @return string      Texte HTML
     */
    static public function SkrivToHTML($str)
    {
        if (!self::$skriv)
        {
            self::$skriv = new \KD2\SkrivLite;

        }

        $str = self::$skriv->render($str);

        return $str;
    }

    /**
     * Transforme les tags de base SPIP en tags SkrivML
     * @param  string $str Texte d'entrée
     * @return string      Texte transformé
     */
    static public function SpipToSkriv($str)
    {

        $str = preg_replace('/(?<!\\\\)\{{3}(\V*)\}{3}/', '=== $1 ===', $str);
        $str = preg_replace('/(?<!\\\\)\{{2}(\V*)\}{2}/', '**$1**', $str);

        $str = preg_replace('/(?<!\\\\)\{(\V*)\}/', '\'\'$1\'\'', $str);
        $str = preg_replace('/(?<!\\\\)\[(.+?)->(.+?)\]/', '[[$1 | $2]]', $str);

        $str = preg_replace('/(?<!\\\\)\[(.+?)\]/', '[[$1]]', $str);
        return $str;
    }

    /**
     * Transforme les tags HTML basiques en tags SkrivML
     * @param  string $str Texte d'entrée
     * @return string      Texte transfor
     */
    static public function HTMLToSkriv($str)
    {

        $str = preg_replace('/<h3>(\V*?)<\/h3>/', '=== $1 ===', $str);
        $str = preg_replace('/<b>(\V*)<\/b>/', '**$1**', $str);
        $str = preg_replace('/<strong>(\V*?)<\/strong>/', '**$1**', $str);

        $str = preg_replace('/<i>(\V*?)<\/i>/', '\'\'$1\'\'', $str);
        $str = preg_replace('/<em>(\V*?)<\/em>/', '\'\'$1\'\'', $str);
        $str = preg_replace('/<a href="([^"]*?)">(\V*?)<\/a>/', '[[$2 | $1]]', $str);
        return $str;
    }

    static public function mail($to, $subject, $content, $additional_headers = [])
    {
        // Création du contenu du message
        $content = wordwrap($content);

Modified src/www/admin/static/wiki-encryption.js from [2c641c3a88] to [94984cc51a].

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

	function formatContent(content)
	{
		// htmlspecialchars ENT_QUOTES
		content = content.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
			.replace(/'/g, '&#039;').replace(/"/g, '&quot');

		// HTML simple
		content = content.replace(/&lt;(\/?(del|pre|ins|b|i|strong|em|h\d|code|samp|tt))&gt;/g, '<$1>');
		console.log(content);

		// Intertitres
		content = content.replace(/\{{3}([^\n]*)\}{3}/g, '<h3>$1</h3>');



		// Gras
		content = content.replace(/\{{2}([^\n]*)\}{2}/g, '<strong>$1</strong>');

		// Italique
		content = content.replace(/\{([^\n]*)\}/g, '<em>$1</em>');

		// Espaces typograhiques
		content = content.replace(/\h*([?!;:»])(\s+|$)/g, '&nbsp;$1$2');
		content = content.replace(/(^|\s+)([«])\h*/g, '$1$2&nbsp;');

		// Liens
		content = content.replace(/\[([^-]+)-&gt;([^\]]+)\]/g, '<a href="$2">$1</a>');
		content = content.replace(/\[([^\]]+)\]/g, '<a href="$1">$1</a>');

		// nl2br
		content = content.replace(/\r/g, '').replace(/\n/g, '<br />');

		return content;
	}








<
<
<
<

|
>
>


|


|






|
|







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

	function formatContent(content)
	{
		// htmlspecialchars ENT_QUOTES
		content = content.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
			.replace(/'/g, '&#039;').replace(/"/g, '&quot');





		// Intertitres
		content = content.replace(/==([^\n]*)==/g, '<h2>$1</h2>');
		content = content.replace(/===([^\n]*)===/g, '<h3>$1</h3>');
		content = content.replace(/====([^\n]*)====/g, '<h4>$1</h4>');

		// Gras
		content = content.replace(/\*{2}([^\n]*)\*{2}/g, '<strong>$1</strong>');

		// Italique
		content = content.replace(/''([^\n]*)''/g, '<em>$1</em>');

		// Espaces typograhiques
		content = content.replace(/\h*([?!;:»])(\s+|$)/g, '&nbsp;$1$2');
		content = content.replace(/(^|\s+)([«])\h*/g, '$1$2&nbsp;');

		// Liens
		content = content.replace(/\[\[([^|]+)|([^\]]+)\]\]/g, '<a href="$2">$1</a>');
		content = content.replace(/\[\[([^\]]+)\]\]/g, '<a href="$1">$1</a>');

		// nl2br
		content = content.replace(/\r/g, '').replace(/\n/g, '<br />');

		return content;
	}

Modified src/www/admin/upgrade.php from [dbfe19e493] to [bd1441a7c4].

202
203
204
205
206
207
208
























209
210
211
212
213
214
215

if (version_compare($v, '0.7.0', '<'))
{
    $db->exec('PRAGMA foreign_keys = OFF; BEGIN;');

    // Mise à jour base de données
    $db->exec(file_get_contents(ROOT . '/include/data/0.7.0.sql'));

























    $db->exec('END;');
}

Utils::clearCaches();

$config->setVersion(garradin_version());







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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

if (version_compare($v, '0.7.0', '<'))
{
    $db->exec('PRAGMA foreign_keys = OFF; BEGIN;');

    // Mise à jour base de données
    $db->exec(file_get_contents(ROOT . '/include/data/0.7.0.sql'));

    // Changement de syntaxe du Wiki vers SkrivML
    $wiki = new Wiki;
    $st = $db->prepare('SELECT id_page, contenu, revision, chiffrement FROM wiki_revisions GROUP BY id_page ORDER BY revision DESC;');

    while ($row = $st->fetchArray(\SQLITE3_ASSOC))
    {
        // Ne pas convertir le contenu chiffré, de toute évidence
        if ($row['chiffrement'])
            continue;

        $content = $row['contenu'];
        $content = Utils::HTMLToSkriv($content);
        $content = Utils::SpipToSkriv($content);

        if ($content != $row['contenu'])
        {
            $wiki->editRevision($row['id_page'], $row['revision'], [
                'id_auteur'     =>  null,
                'contenu'       =>  $content,
                'modification'  =>  'Mise à jour 0.7.0 (transformation SPIP vers SkrivML)',
            ]);
        }
    }

    $db->exec('END;');
}

Utils::clearCaches();

$config->setVersion(garradin_version());