Add a help form for the wiki syntax
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 23 Mar 2007 21:53:35 +0000 (21:53 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 23 Mar 2007 21:53:35 +0000 (21:53 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1601 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/miniwiki.php
htdocs/javascript/xorg.js
modules/core.php
modules/xnetgrp.php
templates/axletter/edit.tpl
templates/core/wiki.help.tpl [new file with mode: 0644]
templates/emails/send.tpl
templates/events/form.tpl
templates/newsletter/submit.tpl
templates/xnetgrp/announce-edit.tpl
templates/xnetgrp/mail.tpl

index 7de524a..f41dfa3 100644 (file)
@@ -7,64 +7,73 @@ class MiniWiki
     private static $replacementHTML = array();
     private static $replacementText = array();
 
-    public static function Markup($id, $pattern, $replacement, $replacementTxt) {
+    private static $info     = array();
+
+    public static function Markup($id, $pattern, $replacement, $replacementTxt, $info = null)
+    {
         MiniWiki::$patternsWiki[$id] = $pattern;
         MiniWiki::$replacementHTML[$id] = $replacement;
         MiniWiki::$replacementText[$id] = $replacementTxt;
+        if ($info) {
+            MiniWiki::$info[$id] = $info;
+        }
     }
     
-    public static function init() {
+    public static function init()
+    {
         if (isset(MiniWiki::$patternsWiki[0])) {
             return;
         }
         MiniWiki::Markup(0, "/(\r\n|\r([^\n]))/", "\n$2", "\n$2");
                 
         // retours à la ligne avec \\
-        MiniWiki::Markup(1, "/\\\\(?".">(\\\\*))\n/e", "str_repeat('<br />\n',strlen('$1'))", "str_repeat('\n',strlen('$1'))");
+        MiniWiki::Markup(1, "/\\\\(?>(\\\\*))\n/e", "str_repeat('<br />\n',strlen('$1'))", "str_repeat('\n',strlen('$1'))", "ligne1\\\\\nligne2");
         
         // bold, italic and others
         // ''' bold '''
-        MiniWiki::Markup(2, "/'''(.*?)'''/",'<strong>$1</strong>','*$1*');
+        MiniWiki::Markup(2, "/'''(.*?)'''/",'<strong>$1</strong>','*$1*', "'''gras'''");
         // '' italic ''
-        MiniWiki::Markup(3, "/''(.*?)''/",'<em>$1</em>','/$1/');
+        MiniWiki::Markup(3, "/''(.*?)''/",'<em>$1</em>','/$1/', "''italique''");
         // '+ big +'
-        MiniWiki::Markup(4, "/'\\+(.*?)\\+'/",'<big>$1</big>','*$1*');
+        MiniWiki::Markup(4, "/'\\+(.*?)\\+'/",'<big>$1</big>','*$1*', "'+grand+'");
         // '- small -'
-        MiniWiki::Markup(5, "/'\\-(.*?)\\-'/",'<small>$1</small>','$1');
+        MiniWiki::Markup(5, "/'\\-(.*?)\\-'/",'<small>$1</small>','$1', "'-petit-'");
         // '^superscript^'
-        MiniWiki::Markup(6, "/'\\^(.*?)\\^'/",'<sup>$1</sup>','$1');
+        MiniWiki::Markup(6, "/'\\^(.*?)\\^'/",'<sup>$1</sup>','$1', "^exposant^");
         // '_subscript_'
-        MiniWiki::Markup(7, "/'_(.*?)_'/",'<sub>$1</sub>','$1');
+        MiniWiki::Markup(7, "/'_(.*?)_'/",'<sub>$1</sub>','$1', "_indice_");
         // {+ underline +}
-        MiniWiki::Markup(8, "/\\{\\+(.*?)\\+\\}/",'<ins>$1</ins>','_$1_');
+        MiniWiki::Markup(8, "/\\{\\+(.*?)\\+\\}/",'<ins>$1</ins>','_$1_', "{+insertion+}");
         // {- strikeout -}
-        MiniWiki::Markup(9, "/\\{-(.*?)-\\}/",'<del>$1</del>','-$1-');
+        MiniWiki::Markup(9, "/\\{-(.*?)-\\}/",'<del>$1</del>','-$1-', "{-suppression-}");
         // [+ big +] [++ bigger ++] [+++ even bigger +++] ...
-        MiniWiki::Markup(10, "/\\[(([-+])+)(.*?)\\1\\]/e","'<span style=\'font-size:'.(round(pow(6/5,$2strlen('$1'))*100,0)).'%\'>$3</span>'", "'$3'");
+        MiniWiki::Markup(10, "/\\[(([-+])+)(.*?)\\1\\]/e","'<span style=\'font-size:'.(round(pow(6/5,$2strlen('$1'))*100,0)).'%\'>$3</span>'", "'$3'", "[+ grand +]\n\n[++ plus gros ++]\n\n[+++ encore plus gros +++]");
         
         // ----- <hr/>
-        MiniWiki::Markup(11, "/(\n|^)--(--+| \n)/s", '$1<hr/>', '$1-- '."\n");
+        MiniWiki::Markup(11, "/(\n|^)--(--+| \n)/s", '$1<hr/>', '$1-- '."\n", "----\n");
         // titles
-        MiniWiki::Markup(12, '/(\n|^)(!+)([^\n]*)/se', "'$1<h'.strlen('$2').'>$3</h'.strlen('$2').'>'", "'$1$3'");
+        MiniWiki::Markup(12, '/(\n|^)(!+)([^\n]*)/se', "'$1<h'.strlen('$2').'>$3</h'.strlen('$2').'>'", "'$1$3'",
+                             "!titre1\n\n!!titre2\n\n!!!titre3");
         
         // * unordered list
-        MiniWiki::Markup(13, "/(^|\n)\*(([^\n]*(\n|$))(\*[^\n]*(\n|$))*)/se", "'<ul><li>'.str_replace(\"\\n*\",'</li><li>','$2').'</li></ul>'", "$0");
+        MiniWiki::Markup(13, "/(^|\n)\*(([^\n]*(\n|$))(\*[^\n]*(\n|$))*)/se", "'<ul><li>'.str_replace(\"\\n*\",'</li><li>','$2').'</li></ul>'", "$0", "* element1\n* element2\n* element3");
         // # unordered list
-        MiniWiki::Markup(14, "/(^|\n)#(([^\n]*(\n|$))(#[^\n]*(\n|$))*)/se", "'<ol><li>'.str_replace(\"\\n#\",'</li><li>','$2').'</li></ol>'", "$0");
+        MiniWiki::Markup(14, "/(^|\n)#(([^\n]*(\n|$))(#[^\n]*(\n|$))*)/se", "'<ol><li>'.str_replace(\"\\n#\",'</li><li>','$2').'</li></ol>'", "$0", "# element1\n# element2\n# element3");
         
         // links
         MiniWiki::Markup(15, '/((?:https?|ftp):\/\/(?:\.*,*[\w@~%$£µ&i#\-+=_\/\?;])*)/ui', '<a href="\\0">\\0</a>', '[\\0]');
         MiniWiki::Markup(16, '/(\s|^|\\[\\[)www\.((?:\.*,*[\w@~%$£µ&i#\-+=_\/\?;])*)/iu', '\\1<a href="http://www.\\2">www.\\2</a>', '[http://www.\\2]');
         MiniWiki::Markup(17, '/(?:mailto:)?([a-z0-9.\-+_]+@([\-.+_]?[a-z0-9])+)/i', '<a href="mailto:\\0">\\0</a>', '[mailto:\\0]');
-        MiniWiki::Markup(18, '/\\[\\[\\s*<a href="([^>]*)">.*<\/a>\\s*\|([^\\]]+)\\]\\]/i', '<a href="\\1">\\2</a>', '\\2 [\\1]');
+        MiniWiki::Markup(18, '/\\[\\[\\s*<a href="([^>]*)">.*<\/a>\\s*\|([^\\]]+)\\]\\]/i', '<a href="\\1">\\2</a>', '\\2 [\\1]', "[[http://www.example.com|Mon site web]]\n\nhttp://www.example.com\n\ntest@example.com");
         
         // paragraphs and empty lines
-        MiniWiki::Markup(19, "/\n\n/", '</p><p>', "\n\n");
+        MiniWiki::Markup(19, "/\n\n/", '</p><p>', "\n\n", "paragraphe1\n\nparagraphe2");
         MiniWiki::Markup(20, "/\n/", ' ', "\n");
         MiniWiki::Markup(21, "/^.*<\/p><p>.*$/s", "<p>$0</p>", "$0");
     }
 
-    public static function WikiToHTML($wiki, $title = false) {
+    public static function WikiToHTML($wiki, $title = false)
+    {
         if (!$title) {
             $oldrule12 = MiniWiki::$replacementHTML[12];
             MiniWiki::$replacementHTML[12] = "'$0'";
@@ -76,7 +85,7 @@ class MiniWiki
         return $html;
     }
     
-    private function justify($text,$n)
+    private static function justify($text,$n)
     {
         $arr = explode("\n",wordwrap($text,$n));
         $arr = array_map('trim',$arr);
@@ -121,7 +130,8 @@ class MiniWiki
     }
     
 
-    public static function WikiToText($wiki, $just=false, $indent=0, $width=68, $title=false) {
+    public static function WikiToText($wiki, $just=false, $indent=0, $width=68, $title=false)
+    {
         if (!$title) {
             $oldrule12 = MiniWiki::$replacementHTML[12];
             MiniWiki::$replacementHTML[12] = "'$0'";
@@ -137,7 +147,32 @@ class MiniWiki
         }
         return $text;
     }
-};
+
+    static public function help($with_title = false)
+    {
+        if (!$with_title) {
+            $info12 = MiniWiki::$info[12];
+            unset(MiniWiki::$info[12]);
+        }
+
+        $i = 0;
+        $res = '<table class="bicol">' . "\n";
+        $res .= "<tr><th>Syntaxe</th><th>Apparence</th></tr>\n";
+        foreach (MiniWiki::$info as $value) {
+            $i++;
+            $res .= '<tr class="' . ($i % 2 ? 'impair' : 'pair') . '">';
+            $res .= '<td>' . nl2br(htmlentities($value)) . '</td>';
+            $res .= '<td>' . MiniWiki::wikiToHtml($value, true) . '</td>';
+            $res .= "</tr>\n";
+        }
+        $res .= '</table>';
+
+        if (!$with_title) {
+            MiniWiki::$info[12] = $info12;
+        }
+        return $res;
+    }
+}
 
 MiniWiki::init();
 
index 721ec59..7fcd6f0 100644 (file)
@@ -153,6 +153,9 @@ function auto_links() {
        if(node.className == 'popup2') {
         node.onclick = function () { popWin(this,840,600); return false; };
        }
+    if(node.className == 'popup3') {
+        node.onclick = function () { popWin(this, 640, 800); return false; };
+    }
        if(matches = (/^popup_([0-9]*)x([0-9]*)$/).exec(node.className)) {
            var w = matches[1], h = matches[2];
            node.onclick = function () { popWin(this,w,h); return false; };
index 2165d27..9043210 100644 (file)
@@ -30,6 +30,7 @@ class CoreModule extends PLModule
             'send_bug'    => $this->make_hook('bug', AUTH_COOKIE),
             'purge_cache' => $this->make_hook('purge_cache', AUTH_COOKIE, 'admin'),
             'get_rights'  => $this->make_hook('get_rights', AUTH_MDP, 'admin'),
+            'wiki_help'   => $this->make_hook('wiki_help', AUTH_PUBLIC),
 
             'valid.html'  => $this->make_hook('valid', AUTH_PUBLIC),
             'favicon.ico' => $this->make_hook('favicon', AUTH_PUBLIC),
@@ -108,7 +109,7 @@ class CoreModule extends PLModule
 
     function handler_bug(&$page)
     {
-        $page->changeTpl('core/bug.tpl',SIMPLE);
+        $page->changeTpl('core/bug.tpl', SIMPLE);
         $page->addJsLink('close_on_esc.js');
         if (Env::has('send') && trim(Env::v('detailed_desc'))) {
             $body = wordwrap(Env::v('detailed_desc'), 78) . "\n\n"
@@ -128,6 +129,12 @@ class CoreModule extends PLModule
             $page->trig("Merci de remplir une explication du problème rencontré");
         }
     }
+
+    function handler_wiki_help(&$page, $action = 'title')
+    {
+        $page->changeTpl('core/wiki.help.tpl', SIMPLE);
+        $page->assign('wiki_help', MiniWiki::help($action == 'title'));
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index 9098db8..2eacac8 100644 (file)
@@ -1117,7 +1117,7 @@ class XnetGrpModule extends PLModule
             }
         } 
 
-        $art['contact_html'] = MiniWiki::WikiToHTML($art['contact_html']);
+        $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']);
         $page->assign('art', $art);
     }
 
index 87724d6..d32365a 100644 (file)
@@ -42,6 +42,9 @@
   <fieldset>
     <legend>Sujet du mail : <input type="text" name="subject" value="{$subject}" size="60"/></legend>
     <p class="center">
+      <a href="wiki_help" class="popup3">
+        {icon name=information title="Syntaxe wiki"} Voir les marqueurs de mise en forme autorisés
+      </a><br />
       <strong>Titre : </strong><input type="text" name="title" value="{$title}" size="60" /><br />
       <textarea name="body" rows="30" cols="78">{$body}</textarea><br />
       <strong>Signature : </strong><input type="text" name="signature" value="{$signature}" size="60" />
diff --git a/templates/core/wiki.help.tpl b/templates/core/wiki.help.tpl
new file mode 100644 (file)
index 0000000..bfb591e
--- /dev/null
@@ -0,0 +1,27 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2007 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>Syntaxe wiki</h1>
+
+{$wiki_help|smarty:nodefaults}
+
+{* vim:set et sws=2 sts=2 sw=2 enc=utf-8: *}
index 5229288..bb8e90e 100644 (file)
   <fieldset>
     <legend>Sujet&nbsp;:&nbsp;<input type='text' name='sujet' size='60' value="{$smarty.request.sujet}" /></legend>
     <div class="center">
-      Tu peux utiliser des marqueurs <em>wiki</em> pour formatter ton texte.<br />
+      Tu peux utiliser des <a href="wiki_help" class="popup3">{icon name=information title="Syntaxe wiki"} marqueurs wiki</a> pour formatter ton texte.<br />
       <small><input type="checkbox" name="nowiki" value="1" {if $smarty.request.nowiki}checked="checked"{/if} />
       coche cette case pour envoyer le mail en texte brut, sans formattage</small>
     </div>
index 418b1de..fc2a958 100644 (file)
     </tr>
     <tr>
       <td class="titre">Texte</td>
-      <td><textarea name="texte" id="texte" rows="10" cols="60" onfocus="update_texte_count(this.form)">{$texte}</textarea></td>
+      <td>
+        <textarea name="texte" id="texte" rows="10" cols="60" onfocus="update_texte_count(this.form)">{$texte}</textarea>
+      </td>
+    </tr>
+    <tr>
+      <td></td>
+      <td class="smaller">
+        <a href="wiki_help/notitle" class="popup3">
+          {icon name=information title="Syntaxe wiki"} Voir la syntaxe wiki autorisée pour le texte de l'annonce
+        </a>
+      </td>
     </tr>
     <tr>
       <td colspan="2" class="smaller">
index 25c39f1..6d7da3d 100644 (file)
@@ -113,6 +113,14 @@ Tu peux <a href='nl/submit#conseils'>lire les conseils de rédaction</a> avant d
         <textarea cols="68" rows="3" name='append'>{if $art}{$art->append()}{/if}</textarea>
       </td>
     </tr>
+    <tr class="pair smaller">
+      <td></td>
+      <td>
+        <a href="wiki_help/notitle" class="popup3">
+          {icon name=information title="Syntaxe wiki"} Voir les marqueurs de mise en forme autorisés
+        </a>
+      </td>
+    <tr>
     <tr class='pair'>
       <td colspan='2' class='center'>
         <input type='submit' name='see' value='visualiser' />
index 1c66937..a351e76 100644 (file)
@@ -97,6 +97,13 @@ function visibilityChange(box)
         <textarea cols="60" rows="6" name='contacts'>{$art.contacts}</textarea>
       </td>
     </tr>
+    <tr style="border-top: 1px solid gray">
+      <td colspan="2" class="center">
+        <a href="wiki_help/notitle" class="popup3">
+          {icon name=information title="Syntaxe wiki"} Voir la liste des marqueurs de mise en forme autorisés
+        </a>
+      </td>
+    </tr>
   </table>
   <br />
 
index 80be54f..6f36260 100644 (file)
@@ -91,7 +91,7 @@ masculin ou féminin, par son prénom, ou son nom.
     <tr>
       <td colspan="2" class="smaller">
         <input type="checkbox" name="wiki" value="1" checked="1" />
-        activer la syntaxe wiki pour le formattage du message
+        activer <a href="wiki_help" class="popup3">la syntaxe wiki</a> pour le formattage du message
       </td>
     </tr>
     <tr>