Closes #677: Wiki syntax for announces even after validation, and wiki
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 16 Sep 2007 17:12:44 +0000 (19:12 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 16 Sep 2007 17:12:44 +0000 (19:12 +0200)
syntax for group description on xnet

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
17 files changed:
htdocs/css/xnet.css
include/globals.inc.php.in
include/validations/evts.inc.php
modules/events.php
modules/profile.php
modules/xnetgrp.php
plugins/modifier.miniwiki.php [new file with mode: 0644]
templates/events/form.tpl
templates/events/index.tpl
templates/events/preview.tpl
templates/include/form.valid.evts.tpl
templates/profile/profile.tpl
templates/xnetgrp/announce-rss.tpl
templates/xnetgrp/asso.tpl
templates/xnetgrp/edit.tpl
templates/xnetgrp/form.announce.tpl
upgrade/0.9.15/04_announces.sql [new file with mode: 0644]

index 2513ab9..e181a5a 100644 (file)
@@ -68,6 +68,19 @@ h2    { font-size: 115%; }
     font-style: italic;
 }
 
+input.error, textarea.error {
+    background-color: #faa;
+}
+
+input.valid, textarea.valid {
+    background-color: #afa;
+}
+
+input.warning, textarea.warning {
+    background-color: #fda;
+}
+
+
 /***************************************************************************
  * DEBUG
  ***************************************************************************/
index e7f9f55..9bb1b54 100644 (file)
@@ -107,7 +107,7 @@ class PlatalGlobals
             }
 
             if ($gp) {
-                $res = XDB::query('SELECT  a.*, d.nom AS domnom
+                $res = XDB::query('SELECT  a.*, d.nom AS domnom, FIND_IN_SET(\'wiki_desc\', a.flags) AS wiki_desc
                                      FROM  groupex.asso AS a
                                 LEFT JOIN  groupex.dom  AS d ON d.id = a.dom
                                     WHERE  diminutif = {?}', $gp);
index 4a3a0ce..ed22c95 100644 (file)
@@ -136,7 +136,7 @@ class EvtReq extends Validate
     {
         if (XDB::execute("INSERT INTO  evenements
                          SET  user_id = {?}, creation_date=NOW(), titre={?}, texte={?},
-                              peremption={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide')",
+                              peremption={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide,wiki')",
                 $this->uid, $this->titre, $this->texte,
                 $this->peremption, $this->pmin, $this->pmax)) {
             $eid = XDB::insertId();
@@ -151,14 +151,9 @@ class EvtReq extends Validate
                 $forlife = get_user_forlife($this->uid);
                 require_once 'banana/forum.inc.php';
                 $banana = new ForumsBanana($forlife);
-                $text = strip_tags($this->texte, '<p><br><li><ul><ol><a>');
-                $text = preg_replace(',<a href="([^"]+)">(.*?)</a>,', '$1', $text);
-                $text = preg_replace('/<li>/', '* ', $text);
-                $text = preg_replace(',</?.+?>,i', "\n", $text);
-                $text = preg_replace("/\n{2,}/", "\n\n", $text);
                 $post = $banana->post($globals->banana->event_forum,
                                       $globals->banana->event_reply,
-                                      $this->titre, pl_entity_decode($text));
+                                      $this->titre, MiniWiki::wikiToText($this->texte, false, 0, 80));
                 if ($post != -1) {
                     XDB::execute("UPDATE  evenements
                                      SET  creation_date = creation_date, post_id = {?}
index 67e6abd..a2f77ba 100644 (file)
@@ -100,7 +100,7 @@ class EventsModule extends PLModule
             return false;
         }
         $sql = "SELECT  e.id,e.titre,e.texte,e.post_id,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife,
-                        p.x, p.y, p.attach IS NOT NULL AS img
+                        p.x, p.y, p.attach IS NOT NULL AS img, FIND_IN_SET('wiki', e.flags) AS wiki
                   FROM  evenements       AS e
              LEFT JOIN  evenements_photo AS p ON (e.id = p.eid)
             INNER JOIN  auth_user_md5    AS a ON e.user_id=a.user_id
@@ -270,14 +270,11 @@ class EventsModule extends PLModule
         if (!is_utf8($texte)) {
             $texte = utf8_encode($texte);
         }
-        if (strpos($_SERVER['HTTP_REFERER'], 'admin') === false) {
-            $texte = MiniWiki::WikiToHTML($texte);
-        }
         $titre = Get::v('titre');
         if (!is_utf8($titre)) {
             $titre = utf8_encode($titre);
         }
-        $page->assign('texte_html', $texte);
+        $page->assign('texte', $texte);
         $page->assign('titre', $titre);
         header('Content-Type: text/html; charset=utf-8');
     }
@@ -308,11 +305,8 @@ class EventsModule extends PLModule
             $action = null;
         }
 
-               $texte_catch_url = MiniWiki::WikiToHTML($texte);
-               
         $page->assign('titre', $titre);
         $page->assign('texte', $texte);
-        $page->assign('texte_html', $texte_catch_url);
         $page->assign('promo_min', $promo_min);
         $page->assign('promo_max', $promo_max);
         $page->assign('peremption', $peremption);
@@ -326,7 +320,6 @@ class EventsModule extends PLModule
         } elseif ($action && (!trim($texte) || !trim($titre))) {
             $page->trig("L'article doit avoir un titre et un contenu");
         } elseif ($action) {
-               $texte = $texte_catch_url;
             require_once 'validations.inc.php';
             $evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max,
                                  $peremption, $valid_mesg, S::v('uid'), $upload);
@@ -397,11 +390,13 @@ class EventsModule extends PLModule
             } else {
                 $res = XDB::query('SELECT flags FROM evenements WHERE id = {?}', $eid);
                 $flags = new FlagSet($res->fetchOneCell());
+                $flags->addFlag('wiki');
                 if (Post::v('important')) {
                     $flags->addFlag('important');
                 } else {
                     $flags->rmFlag('important');
                 }
+
                 XDB::execute('UPDATE evenements
                                  SET creation_date = creation_date,
                                      titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?},
@@ -428,7 +423,6 @@ class EventsModule extends PLModule
             list($titre, $texte, $peremption, $promo_min, $promo_max, $important, $img) = $res->fetchOneRow();
             $page->assign('titre',$titre);
             $page->assign('texte',$texte);
-            $page->assign('texte_html', pl_entity_decode($texte));
             $page->assign('promo_min',$promo_min);
             $page->assign('promo_max',$promo_max);
             $page->assign('peremption',$peremption);
@@ -490,7 +484,8 @@ class EventsModule extends PLModule
                             e.promo_min, e.promo_max,
                             FIND_IN_SET('valide', e.flags) AS fvalide,
                             FIND_IN_SET('archive', e.flags) AS farch,
-                            u.promo, u.nom, u.prenom, a.alias AS forlife
+                            u.promo, u.nom, u.prenom, a.alias AS forlife,
+                            FIND_IN_SET('wiki', flags) AS wiki
                       FROM  evenements    AS e
                 INNER JOIN  auth_user_md5 AS u ON(e.user_id = u.user_id)
                 INNER JOIN  aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
index b8237db..2a6f148 100644 (file)
@@ -205,8 +205,6 @@ class ProfileModule extends PLModule
 
         $new   = Env::v('modif') == 'new';
         $user  = get_user_details($login, S::v('uid'), $view);
-        $user['freetext'] = MiniWiki::WikiToHTML($user['freetext']);
-        $user['cv']       = MiniWiki::WikiToHTML($user['cv'], true);
         $title = $user['prenom'] . ' ' . ( empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage'] );
         $page->assign('xorg_title', $title);
 
index acaf70e..6d34a54 100644 (file)
@@ -171,10 +171,7 @@ class XnetGrpModule extends PLModule
                               'rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml');
         }
 
-        $page->register_modifier('wiki_to_html', array('MiniWiki','WikiToHTML'));
         $page->assign('articles', $arts);
-
-        $page->assign('asso', $globals->asso());
     }
 
     function handler_logo(&$page)
@@ -233,7 +230,8 @@ class XnetGrpModule extends PLModule
                         SET  nom={?}, diminutif={?}, cat={?}, dom={?},
                              descr={?}, site={?}, mail={?}, resp={?},
                              forum={?}, mail_domain={?}, ax={?}, pub={?},
-                             sub_url={?}, inscriptible={?}, unsub_url={?}
+                             sub_url={?}, inscriptible={?}, unsub_url={?},
+                             flags='wiki_desc'
                       WHERE  id={?}",
                       Post::v('nom'), Post::v('diminutif'),
                       Post::v('cat'), Post::i('dom'),
@@ -252,7 +250,7 @@ class XnetGrpModule extends PLModule
                     "UPDATE  groupex.asso
                         SET  descr={?}, site={?}, mail={?}, resp={?},
                              forum={?}, ax={?}, pub= {?}, sub_url={?},
-                             unsub_url={?}
+                             unsub_url={?},flags='wiki_desc'
                       WHERE  id={?}",
                       Post::v('descr'), Post::v('site'),
                       Post::v('mail'), Post::v('resp'),
@@ -266,9 +264,9 @@ class XnetGrpModule extends PLModule
                 $logo = file_get_contents($_FILES['logo']['tmp_name']);
                 $mime = $_FILES['logo']['type'];
                 XDB::execute('UPDATE groupex.asso
-                                           SET logo={?}, logo_mime={?}
-                                         WHERE id={?}', $logo, $mime,
-                                        $globals->asso('id'));
+                                 SET logo={?}, logo_mime={?}
+                               WHERE id={?}', $logo, $mime,
+                             $globals->asso('id'));
             }
 
             pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit');
@@ -279,6 +277,11 @@ class XnetGrpModule extends PLModule
             $page->assign('dom', $dom);
             $page->assign('super', true);
         }
+        if (!$globals->asso('wiki_desc') && $globals->asso('descr')) {
+            $page->trig("Attention, le format de la description a changé et utilise désormais la syntaxe wiki "
+                      . "intégrée au site. Il te faudra probablement adapter le formatage du texte actuelle pour "
+                      . "qu'il s'affiche correctement avec cette nouvelle syntaxe.");
+        }
     }
 
     function handler_mail(&$page)
@@ -1023,7 +1026,6 @@ class XnetGrpModule extends PLModule
         global $globals;
         require_once('rss.inc.php');
         $uid = init_rss('xnetgrp/announce-rss.tpl', $user, $hash, false);
-        $page->register_modifier('wiki_to_html', array('MiniWiki', 'WikiToHTML'));
 
         if ($uid) {
             $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date,
@@ -1050,7 +1052,6 @@ class XnetGrpModule extends PLModule
     {
         global $globals, $platal;
         $page->changeTpl('xnetgrp/announce-edit.tpl');
-        $page->register_modifier('wiki_to_html', array('MiniWiki','WikiToHTML'));
         $page->assign('new', is_null($aid));
         $art = array();
 
@@ -1117,8 +1118,7 @@ class XnetGrpModule extends PLModule
                 $aid = XDB::insertId();
                 if ($art['xorg']) {
                     require_once('validations.inc.php');
-                    $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'],
-                                    MiniWiki::WikiToHTML($fulltext),
+                    $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext,
                                     $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::v('uid'));
                     $article->submit();
                     $page->trig("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation");
diff --git a/plugins/modifier.miniwiki.php b/plugins/modifier.miniwiki.php
new file mode 100644 (file)
index 0000000..d437c3f
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+/***************************************************************************
+ *  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                *
+ ***************************************************************************/
+
+require_once 'platal.inc.php';
+
+function smarty_modifier_miniwiki($string, $format = 'no_title')
+{
+    return MiniWiki::wikiToHTML($string, $format == 'title');
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
index 5b078d0..13afdaa 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-{assign var=texte value=$smarty.request.texte|default:$texte} 
-{assign var=titre value=$smarty.request.titre|default:$titre} 
-{assign var=promo_min value=$smarty.request.promo_min|default:$promo_min} 
-{assign var=promo_max value=$smarty.request.promo_max|default:$promo_max} 
+{if $smarty.request.texte}
+{assign var=texte value=$smarty.request.texte}
+{/if}
+{assign var=titre value=$smarty.request.titre|default:$titre}
+{assign var=promo_min value=$smarty.request.promo_min|default:$promo_min}
+{assign var=promo_max value=$smarty.request.promo_max|default:$promo_max}
 {assign var=peremption value=$smarty.request.peremption|default:$peremption}
 {assign var=important value=$smarty.request.important|default:$important}
 
index f10936e..7b02de3 100644 (file)
@@ -196,7 +196,11 @@ Bienvenue {$smarty.session.prenom}{if $birthday}
           </div>
           {/if}
           <div style="text-align: justify">
+            {if !$ev.wiki}
             {$ev.texte|smarty:nodefaults|nl2br}
+            {else}
+            {$ev.texte|miniwiki|smarty:nodefaults}
+            {/if}
           </div>
         </div>
       </td>
index 18058ed..1fa82b8 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-{if trim($titre) || trim($texte_html)}
+{if trim($titre) || trim($texte)}
 <table class="bicol">
   <tr><th><em>Aperçu de : </em>{$titre|nl2br}</th></tr>
-  <tr class="pair"><td>{$texte_html|nl2br|smarty:nodefaults}</td></tr>
+  <tr class="pair"><td>{$texte|miniwiki|smarty:nodefaults}</td></tr>
 </table>
 {/if}
 
index d626a9a..680c2e0 100644 (file)
@@ -27,7 +27,7 @@
 </tr>
 <tr class="pair">
   <td class="titre">Texte</td>
-  <td>{tidy}{$valid->texte|nl2br|smarty:nodefaults}{/tidy}</td>
+  <td>{tidy}{$valid->texte|miniwiki|smarty:nodefaults}{/tidy}</td>
 </tr>
 <tr class="pair">
   <td class="titre">Péremption</td>
index 27ce51c..4b73b91 100644 (file)
@@ -52,7 +52,7 @@ function chgMainWinLoc(strPage)
       {if $x.gpxs_join}<div><em class="intitule">Groupe(s) et institution(s) X : </em><span><br/>{$x.gpxs_join|smarty:nodefaults}</span></div>{/if}
     {/if}
     {if $x.web}<div><em class="intitule">Site Web : </em><br /><a href="{$x.web}" class='popup'>{$x.web}</a></div>{/if}
-    {if $x.freetext}<div><em class="intitule">Commentaires : </em><br /><span>{$x.freetext|smarty:nodefaults}</span></div>{/if}
+    {if $x.freetext}<div><em class="intitule">Commentaires : </em><br /><span>{$x.freetext|miniwiki|smarty:nodefaults}</span></div>{/if}
   </div>
   <div id="fiche_identite" class="part">
     <div class="civilite">
@@ -179,7 +179,7 @@ function chgMainWinLoc(strPage)
   {if $logged && $x.cv}
   <div class="part">
     <h2>Curriculum Vitae :</h2>
-    {$x.cv|smarty:nodefaults}
+    {$x.cv|miniwiki:title|smarty:nodefaults}
   </div>
   {/if}
   {if !$logged}
index da0b8cb..4d1b517 100644 (file)
@@ -37,7 +37,7 @@
       <title>{$line.titre|strip_tags}</title>
       <guid isPermaLink="false">{$line.id}</guid>
       <link>{#globals.baseurl#}/{$asso.diminutif}/#art{$line.id}</link>
-      <description><![CDATA[{$line.texte|wiki_to_html}{if $line.contacts}<br/><br/><strong>Contacts :</strong><br/>{$line.contacts|wiki_to_html}{/if}]]></description>
+      <description><![CDATA[{$line.texte|miniwiki}{if $line.contacts}<br/><br/><strong>Contacts :</strong><br/>{$line.contacts|miniwiki}{/if}]]></description>
       <author>{$line.prenom} {$line.nom} (X{$line.promo})</author>
       <pubDate>{$line.create_date|rss_date}</pubDate>
     </item>
index b616d7b..d1f72af 100644 (file)
 <br />
 
 <div style="text-align: justify">
+  {if $asso.wiki_desc}
+  {$asso.descr|miniwiki:title|smarty:nodefaults}
+  {else}
   {$asso.descr|smarty:nodefaults}
+  {/if}
 </div>
 
 <br />
index 886cdaf..bf0dfe0 100644 (file)
   </table>
 
   <div class="center">
+    <input type="submit" name="submit" value="Enregistrer" />
+  </div>
+
+  <div class="center">
+    {javascript name=ajax}
+    <div id="preview_descr" style="display: none; text-align: justify"></div>
     <br />
-    <textarea name="descr" cols="70" rows="15">{$asso.descr}</textarea>
+    <a href="wiki_help" class="popup3">
+      {icon name=information title="Syntaxe wiki"} Voir la syntaxe wiki autorisée pour la description
+    </a>
+    <textarea name="descr" cols="70" rows="15" id="descr"
+              {if !$asso.wiki_desc && $asso.descr}class="error"{/if}>{$asso.descr}</textarea>
+    <input type="submit" name="preview" value="Aperçu de la description"
+           onclick="previewWiki('descr', 'preview_descr', true, 'preview_descr'); return false;" /><br />
     <input type="submit" name="submit" value="Enregistrer" />
   </div>
 </form>
index ca3b565..fecbd7d 100644 (file)
@@ -38,9 +38,7 @@
   </tr>
   <tr>
     <td style="padding-bottom: 1em">
-      {tidy}
-      {$art.texte|wiki_to_html|smarty:nodefaults}
-      {/tidy}
+      {$art.texte|miniwiki|smarty:nodefaults}
     </td>
   </tr>
   {if ($is_logged || $admin) && $art.contacts}
   </tr>
   <tr class="pair">
     <td style="padding-left: 20px">
-      {tidy}
       {if $art.contact_html}
+      {tidy}
       {$art.contact_html|nl2br|smarty:nodefaults}
+      {/tidy}
       {else}
-      {$art.contacts|wiki_to_html|nl2br|smarty:nodefaults}
+      {$art.contacts|miniwiki|smarty:nodefaults}
       {/if}
-      {/tidy}
     </td>
   </tr>
   {/if}
diff --git a/upgrade/0.9.15/04_announces.sql b/upgrade/0.9.15/04_announces.sql
new file mode 100644 (file)
index 0000000..2f9eeaf
--- /dev/null
@@ -0,0 +1,6 @@
+alter table evenements change flags flags set('valide','archive','important','wiki') not null;
+use groupex
+alter table asso add column flags set('wiki_desc') not null;
+use x4dat
+
+# vim:set syntax=mysql: