From 72b2f8bb79c0fd2d6e073084697fbe0aa126f956 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Fri, 23 Mar 2007 21:53:35 +0000 Subject: [PATCH] Add a help form for the wiki syntax git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1601 839d8a87-29fc-0310-9880-83ba4fa771e5 --- classes/miniwiki.php | 79 ++++++++++++++++++++++++++----------- htdocs/javascript/xorg.js | 3 ++ modules/core.php | 9 ++++- modules/xnetgrp.php | 2 +- templates/axletter/edit.tpl | 3 ++ templates/core/wiki.help.tpl | 27 +++++++++++++ templates/emails/send.tpl | 2 +- templates/events/form.tpl | 12 +++++- templates/newsletter/submit.tpl | 8 ++++ templates/xnetgrp/announce-edit.tpl | 7 ++++ templates/xnetgrp/mail.tpl | 2 +- 11 files changed, 127 insertions(+), 27 deletions(-) create mode 100644 templates/core/wiki.help.tpl diff --git a/classes/miniwiki.php b/classes/miniwiki.php index 7de524a..f41dfa3 100644 --- a/classes/miniwiki.php +++ b/classes/miniwiki.php @@ -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('
\n',strlen('$1'))", "str_repeat('\n',strlen('$1'))"); + MiniWiki::Markup(1, "/\\\\(?>(\\\\*))\n/e", "str_repeat('
\n',strlen('$1'))", "str_repeat('\n',strlen('$1'))", "ligne1\\\\\nligne2"); // bold, italic and others // ''' bold ''' - MiniWiki::Markup(2, "/'''(.*?)'''/",'$1','*$1*'); + MiniWiki::Markup(2, "/'''(.*?)'''/",'$1','*$1*', "'''gras'''"); // '' italic '' - MiniWiki::Markup(3, "/''(.*?)''/",'$1','/$1/'); + MiniWiki::Markup(3, "/''(.*?)''/",'$1','/$1/', "''italique''"); // '+ big +' - MiniWiki::Markup(4, "/'\\+(.*?)\\+'/",'$1','*$1*'); + MiniWiki::Markup(4, "/'\\+(.*?)\\+'/",'$1','*$1*', "'+grand+'"); // '- small -' - MiniWiki::Markup(5, "/'\\-(.*?)\\-'/",'$1','$1'); + MiniWiki::Markup(5, "/'\\-(.*?)\\-'/",'$1','$1', "'-petit-'"); // '^superscript^' - MiniWiki::Markup(6, "/'\\^(.*?)\\^'/",'$1','$1'); + MiniWiki::Markup(6, "/'\\^(.*?)\\^'/",'$1','$1', "^exposant^"); // '_subscript_' - MiniWiki::Markup(7, "/'_(.*?)_'/",'$1','$1'); + MiniWiki::Markup(7, "/'_(.*?)_'/",'$1','$1', "_indice_"); // {+ underline +} - MiniWiki::Markup(8, "/\\{\\+(.*?)\\+\\}/",'$1','_$1_'); + MiniWiki::Markup(8, "/\\{\\+(.*?)\\+\\}/",'$1','_$1_', "{+insertion+}"); // {- strikeout -} - MiniWiki::Markup(9, "/\\{-(.*?)-\\}/",'$1','-$1-'); + MiniWiki::Markup(9, "/\\{-(.*?)-\\}/",'$1','-$1-', "{-suppression-}"); // [+ big +] [++ bigger ++] [+++ even bigger +++] ... - MiniWiki::Markup(10, "/\\[(([-+])+)(.*?)\\1\\]/e","'$3'", "'$3'"); + MiniWiki::Markup(10, "/\\[(([-+])+)(.*?)\\1\\]/e","'$3'", "'$3'", "[+ grand +]\n\n[++ plus gros ++]\n\n[+++ encore plus gros +++]"); // -----
- MiniWiki::Markup(11, "/(\n|^)--(--+| \n)/s", '$1
', '$1-- '."\n"); + MiniWiki::Markup(11, "/(\n|^)--(--+| \n)/s", '$1
', '$1-- '."\n", "----\n"); // titles - MiniWiki::Markup(12, '/(\n|^)(!+)([^\n]*)/se', "'$1$3'", "'$1$3'"); + MiniWiki::Markup(12, '/(\n|^)(!+)([^\n]*)/se', "'$1$3'", "'$1$3'", + "!titre1\n\n!!titre2\n\n!!!titre3"); // * unordered list - MiniWiki::Markup(13, "/(^|\n)\*(([^\n]*(\n|$))(\*[^\n]*(\n|$))*)/se", "''", "$0"); + MiniWiki::Markup(13, "/(^|\n)\*(([^\n]*(\n|$))(\*[^\n]*(\n|$))*)/se", "''", "$0", "* element1\n* element2\n* element3"); // # unordered list - MiniWiki::Markup(14, "/(^|\n)#(([^\n]*(\n|$))(#[^\n]*(\n|$))*)/se", "'
  1. '.str_replace(\"\\n#\",'
  2. ','$2').'
'", "$0"); + MiniWiki::Markup(14, "/(^|\n)#(([^\n]*(\n|$))(#[^\n]*(\n|$))*)/se", "'
  1. '.str_replace(\"\\n#\",'
  2. ','$2').'
'", "$0", "# element1\n# element2\n# element3"); // links MiniWiki::Markup(15, '/((?:https?|ftp):\/\/(?:\.*,*[\w@~%$£µ&i#\-+=_\/\?;])*)/ui', '\\0', '[\\0]'); MiniWiki::Markup(16, '/(\s|^|\\[\\[)www\.((?:\.*,*[\w@~%$£µ&i#\-+=_\/\?;])*)/iu', '\\1www.\\2', '[http://www.\\2]'); MiniWiki::Markup(17, '/(?:mailto:)?([a-z0-9.\-+_]+@([\-.+_]?[a-z0-9])+)/i', '\\0', '[mailto:\\0]'); - MiniWiki::Markup(18, '/\\[\\[\\s*.*<\/a>\\s*\|([^\\]]+)\\]\\]/i', '\\2', '\\2 [\\1]'); + MiniWiki::Markup(18, '/\\[\\[\\s*.*<\/a>\\s*\|([^\\]]+)\\]\\]/i', '\\2', '\\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/", '

', "\n\n"); + MiniWiki::Markup(19, "/\n\n/", '

', "\n\n", "paragraphe1\n\nparagraphe2"); MiniWiki::Markup(20, "/\n/", ' ', "\n"); MiniWiki::Markup(21, "/^.*<\/p>

.*$/s", "

$0

", "$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 = '' . "\n"; + $res .= "\n"; + foreach (MiniWiki::$info as $value) { + $i++; + $res .= ''; + $res .= ''; + $res .= ''; + $res .= "\n"; + } + $res .= '
SyntaxeApparence
' . nl2br(htmlentities($value)) . '' . MiniWiki::wikiToHtml($value, true) . '
'; + + if (!$with_title) { + MiniWiki::$info[12] = $info12; + } + return $res; + } +} MiniWiki::init(); diff --git a/htdocs/javascript/xorg.js b/htdocs/javascript/xorg.js index 721ec59..7fcd6f0 100644 --- a/htdocs/javascript/xorg.js +++ b/htdocs/javascript/xorg.js @@ -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; }; diff --git a/modules/core.php b/modules/core.php index 2165d27..9043210 100644 --- a/modules/core.php +++ b/modules/core.php @@ -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: diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 9098db8..2eacac8 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -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); } diff --git a/templates/axletter/edit.tpl b/templates/axletter/edit.tpl index 87724d6..d32365a 100644 --- a/templates/axletter/edit.tpl +++ b/templates/axletter/edit.tpl @@ -42,6 +42,9 @@
Sujet du mail :

+ + {icon name=information title="Syntaxe wiki"} Voir les marqueurs de mise en forme autorisés +
Titre :

Signature : diff --git a/templates/core/wiki.help.tpl b/templates/core/wiki.help.tpl new file mode 100644 index 0000000..bfb591e --- /dev/null +++ b/templates/core/wiki.help.tpl @@ -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 *} +{* *} +{**************************************************************************} + +

Syntaxe wiki

+ +{$wiki_help|smarty:nodefaults} + +{* vim:set et sws=2 sts=2 sw=2 enc=utf-8: *} diff --git a/templates/emails/send.tpl b/templates/emails/send.tpl index 5229288..bb8e90e 100644 --- a/templates/emails/send.tpl +++ b/templates/emails/send.tpl @@ -199,7 +199,7 @@
Sujet : 
- Tu peux utiliser des marqueurs wiki pour formatter ton texte.
+ Tu peux utiliser des {icon name=information title="Syntaxe wiki"} marqueurs wiki pour formatter ton texte.
coche cette case pour envoyer le mail en texte brut, sans formattage
diff --git a/templates/events/form.tpl b/templates/events/form.tpl index 418b1de..fc2a958 100644 --- a/templates/events/form.tpl +++ b/templates/events/form.tpl @@ -67,7 +67,17 @@ Texte - + + + + + + + + + {icon name=information title="Syntaxe wiki"} Voir la syntaxe wiki autorisée pour le texte de l'annonce + + diff --git a/templates/newsletter/submit.tpl b/templates/newsletter/submit.tpl index 25c39f1..6d7da3d 100644 --- a/templates/newsletter/submit.tpl +++ b/templates/newsletter/submit.tpl @@ -113,6 +113,14 @@ Tu peux lire les conseils de rédaction avant d + + + + + {icon name=information title="Syntaxe wiki"} Voir les marqueurs de mise en forme autorisés + + + diff --git a/templates/xnetgrp/announce-edit.tpl b/templates/xnetgrp/announce-edit.tpl index 1c66937..a351e76 100644 --- a/templates/xnetgrp/announce-edit.tpl +++ b/templates/xnetgrp/announce-edit.tpl @@ -97,6 +97,13 @@ function visibilityChange(box) + + + + {icon name=information title="Syntaxe wiki"} Voir la liste des marqueurs de mise en forme autorisés + + +
diff --git a/templates/xnetgrp/mail.tpl b/templates/xnetgrp/mail.tpl index 80be54f..6f36260 100644 --- a/templates/xnetgrp/mail.tpl +++ b/templates/xnetgrp/mail.tpl @@ -91,7 +91,7 @@ masculin ou féminin, par son prénom, ou son nom. - activer la syntaxe wiki pour le formattage du message + activer la syntaxe wiki pour le formattage du message -- 2.1.4