Add some more Wiki Syntax documentation, fix bugs in wiki tables and postioning on save, a=chris

Chris Pollett [2014-06-13 16:Jun:th]
Add some more Wiki Syntax documentation, fix bugs in wiki tables and postioning on save, a=chris
Filename
configs/createdb.php
controllers/components/social_component.php
data/default.db
lib/wiki_parser.php
views/elements/wiki_element.php
diff --git a/configs/createdb.php b/configs/createdb.php
index 6700eb9c0..e82f1dfb0 100755
--- a/configs/createdb.php
+++ b/configs/createdb.php
@@ -282,13 +282,40 @@ The HTML entity
 can be used to create a non-breaking space. The tag
 <nowiki><br></nowiki>
 can be used to produce a line break.
-==Preformatted Text==
+
+==Preformatted Text and Unformatted Text==
 You can force text to be formatted as you typed it rather
 than using the layout mechanism of the browser using the
 <nowiki><pre>preformatted text tag.</pre></nowiki>
 Alternatively, a sequence of lines all beginning with a
 space character will also be treated as preformatted.

+Wiki markup within pre tags is still parsed by Yioop.
+If you would like to add text that is not parsed, enclosed
+it in `<`nowiki> `<`/nowiki> tags.
+
+==Styling Text Paragraphs==
+Yioop wiki syntax offers a number of templates for
+control the styles, and alignment of text for
+a paragraph or group of paragraphs:<br />
+`{{`left| some text`}}`,<br /> `{{`right| some text`}}`,<br />
+and<br />
+`{{`center| some text`}}`<br /> can be used to left-justify,
+right-justify, and center a block of text. For example,
+the last command, would produce:
+{{center|
+some text
+}}
+If you know cascading style sheets (CSS), you can set
+a class or id selector for a block of text using:<br />
+`{{`class="my-class-selector" some text`}}`<br />and<br />
+`{{`id="my-id-selector" some text`}}`.<br />
+You can also apply inline styles to a block of text
+using the syntax:<br />
+`{{`style="inline styles" some text`}}`.<br />
+For example, `{{`style="color:red" some text`}}` looks
+like {{style="color:red" some text}}.
+
 ==Lists==
 The Yioop Wiki Syntax supported of ways of listing items:
 bulleted/unordered list, numbered/ordered lists, and
@@ -353,7 +380,7 @@ would be drawn as:

 ==Tables==
 A table begins with {`|`  and ends with `|`}. Cells are separated with | and
-rows are separatec with |- as can be seen in the following
+rows are separated with |- as can be seen in the following
 example:
 <nowiki>
 {|
diff --git a/controllers/components/social_component.php b/controllers/components/social_component.php
index cf5389b48..6cb10dce2 100644
--- a/controllers/components/social_component.php
+++ b/controllers/components/social_component.php
@@ -977,6 +977,19 @@ class SocialComponent extends Component implements CrawlConstants
             {
                 case "edit":
                     if(!$data["CAN_EDIT"]) { continue; }
+                    if(isset($_REQUEST['caret']) &&
+                       isset($_REQUEST['scroll_top'])) {
+                        $caret = $parent->clean($_REQUEST['caret'],
+                            'int');
+                        $scroll_top= $parent->clean($_REQUEST['scroll_top'],
+                            'int');
+                        $data['SCRIPT'] .= "wiki = elt('wiki-page');".
+                            "if (wiki.setSelectionRange) { " .
+                            "   wiki.focus();" .
+                            "   wiki.setSelectionRange($caret, $caret);".
+                            "} ".
+                            "wiki.scrollTop = $scroll_top;";
+                    }
                     $data["MODE"] = "edit";
                     if($missing_fields) {
                         $data['SCRIPT'] .=
@@ -994,19 +1007,6 @@ class SocialComponent extends Component implements CrawlConstants
                             "doMessage('<h1 class=\"red\" >".
                             tl("group_controller_page_saved").
                             "</h1>');";
-                        if(isset($_REQUEST['caret']) &&
-                           isset($_REQUEST['scroll_top'])) {
-                            $caret = $parent->clean($_REQUEST['caret'],
-                                'int');
-                            $scroll_top= $parent->clean($_REQUEST['scroll_top'],
-                                'int');
-                            $data['SCRIPT'] .= "wiki = elt('wiki-page');".
-                                "if (wiki.setSelectionRange) { " .
-                                "   wiki.focus();" .
-                                "   wiki.setSelectionRange($caret, $caret);".
-                                "} ".
-                                "wiki.scrollTop = $scroll_top;";
-                        }
                     }
                 break;
                 case "history":
diff --git a/data/default.db b/data/default.db
index aae20a67f..a9587d0a2 100644
Binary files a/data/default.db and b/data/default.db differ
diff --git a/lib/wiki_parser.php b/lib/wiki_parser.php
index 86333b17c..c5a892f2c 100644
--- a/lib/wiki_parser.php
+++ b/lib/wiki_parser.php
@@ -102,39 +102,39 @@ class WikiParser implements CrawlConstants
                 "&#039;&#039;&#039;&#039;&#039;/s", "<b><i>$1</i></b>"),
             array("/&#039;&#039;&#039;(.+?)&#039;&#039;&#039;/s", "<b>$1</b>"),
             array("/&#039;&#039;(.+?)&#039;&#039;/s", "<i>$1</i>"),
-            array('/\n*?{{center\|(.+?)}}/s',
-                "$esc<div class='center'>\n\n$1\n\n$esc</div>"),
             array('/\n*?{{\s*class\s*\=\s*'.
                 '&quot;([a-zA-Z\_\-\s]+)&quot;\s+(.+)}}/',
                 "$esc<span class=\"$1\">$2$esc</span>"),
             array('/\n*?{{\s*class\s*\=\s*'.
                 '&quot;([a-zA-Z\_\-\s]+)&quot;\s+(.+)}}/s',
-                "$esc<div class=\"$1\">\n\n$2\n\n$esc</div>"),
+                "\n\n$esc<div class=\"$1\">\n\n$2\n\n$esc</div>"),
             array('/\n*?{{\s*class\s*\=\s*'.
                 '&#039;([a-zA-Z\_\-\s]+)&#039;\s+(.+)}}/s',
-                "$esc<div class='$1'>\n\n$2\n\n$esc</div>"),
+                "\n\n$esc<div class='$1'>\n\n$2\n\n$esc</div>"),
             array('/\n*?{{\s*id\s*\=\s*&quot;([a-zA-Z\_\-]+)&quot;\s+(.+)}}/',
                 "$esc<span id=\"$1\">$2$esc</span>"),
             array('/\n*?{{\s*id\s*\=\s*&quot;([a-zA-Z\_\-]+)&quot;\s+(.+)}}/s',
-                "$esc<div id=\"$1\">\n\n$2\n\n$esc</div>"),
+                "\n\n$esc<div id=\"$1\">\n\n$2\n\n$esc</div>"),
             array('/\n*?{{\s*id\s*\=\s*&#039;([a-zA-Z\_\-]+)&#039;\s+(.+)}}/s',
-                "$esc<div id='$1'>\n\n$2\n\n$esc</div>"),
+                "\n\n$esc<div id='$1'>\n\n$2\n\n$esc</div>"),
             array('/\n*?{{\s*style\s*\=\s*'.
                 '&quot;([0-9a-zA-Z\/\#\_\-\.\;\:\s\n]+)&quot;\s+(.+)}}/',
                 "$esc<span style=\"$1\">$2$esc</span>"),
             array('/\n*?{{\s*style\s*\=\s*'.
                 '&quot;([0-9a-zA-Z\/\#\_\-\.\;\:\s\n]+)&quot;\s+(.+)}}/s',
-                "$esc<div style=\"$1\">\n\n$2\n\n$esc</div>"),
+                "\n\n$esc<div style=\"$1\">\n\n$2\n\n$esc</div>"),
             array('/\n*?{{\s*style\s*\=\s*'.
                 '&#039;([0-9a-zA-Z\_\-\.\;\:\s\n]+)&#039;\s+(.+)}}/',
                 "$esc<span style='$1'>$2$esc</span>"),
             array('/\n*?{{\s*style\s*\=\s*'.
                 '&#039;([0-9a-zA-Z\_\-\.\;\:\s\n]+)&#039;\s+(.+)}}/s',
-                "$esc<div style='$1'>\n\n$2\n\n$esc</div>"),
-            array('/\n*?{{left\s*\|(.+?)}}/s',
-                "$esc<div class='align-left'>\n\n$1\n\n$esc</div>"),
-            array('/\n*?{{right\s*\|(.+?)}}/s',
-                "$esc<div class='align-right'>\n\n$1\n\n$esc</div>"),
+                "\n\n$esc<div style='$1'>\n\n$2\n\n$esc</div>"),
+            array('/\n*{{center\s*\|\s*(.+?)}}/s',
+                "\n\n$esc<div class='center'>\n\n$1\n\n$esc</div>"),
+            array('/\n*?{{left\s*\|\s*(.+?)}}/s',
+                "\n\n$esc<div class='align-left'>\n\n$1\n\n$esc</div>"),
+            array('/\n*?{{right\s*\|\s*(.+?)}}/s',
+                "\n\n$esc<div class='align-right'>\n\n$1\n\n$esc</div>"),
             array('/{{smallcaps\|(.+?)}}/s', "<small>$1</small>"),
             array('/{{Hatnote\|(.+?)}}/si', "($1)"),
             array("/{{fraction\|(.+?)\|(.+?)}}/si", "<small>$1/$2</small>"),
@@ -518,8 +518,9 @@ function makeTableCallback($matches)
             $old_line = true;
             continue;
         }
+        $end = substr($out, -4);
         if($item == "" || $item[0] == "-") {
-            if($out[strlen($out) - 2] != "r") {
+            if($end != "<tr>") {
                 $out .= "</$old_type>";
             }
             $out .= "</tr>\n<tr>";
@@ -528,13 +529,15 @@ function makeTableCallback($matches)

         if($item[0] == "+") {
             $type= "caption";
-            $old_type = $type;
             $item = substr($item, 1);
-        }
-        if($item[0] == "#") {
+            if($end == "<tr>") {
+                $out = substr($out, 0, -4);
+            }
+        } else if($item[0] == "#") {
             $type= "th";
-            $old_type = $type;
             $item = substr($item, 1);
+        } else {
+            $type = "td";
         }
         $trim_item = trim($item);
         $attribute_trim = str_replace("\n", " ", $trim_item);
@@ -546,13 +549,15 @@ function makeTableCallback($matches)
             continue;
         }
         $skip = false;
-        if($out[strlen($out) - 2] != "r") {
+        if($end != "<tr>") {
             $out .= "</$old_type>";
+            if($old_type == "caption") {
+                $out .= "<tr>";
+            }
         }
         $out .= "<$type $state>\n$trim_item";
         $state = "";
         $old_type = $type;
-        $type = "td";
     }
     $out .= "</$old_type></tr></table>";
     return $out;
diff --git a/views/elements/wiki_element.php b/views/elements/wiki_element.php
index bad3dd92c..0994e6eb0 100644
--- a/views/elements/wiki_element.php
+++ b/views/elements/wiki_element.php
@@ -68,8 +68,17 @@ class WikiElement extends Element implements CrawlConstants
             $data["GROUP"]["GROUP_ID"]."&amp;arg=".$data['MODE']."&amp;".
             "page_name=".$data['PAGE_NAME'];
         if($is_admin || $logged_in) { ?>
-            <div class="float-same admin-collapse">[<a
-            href="<?php e($other_base_query) ?>" ><?php
+            <div class="float-same admin-collapse">[<a id='arrows-link'
+            href="<?php e($other_base_query) ?>" onclick="
+            arrows=elt('arrows-link');
+            arrows_url = arrows.href;
+            caret = (elt('wiki-page').selectionStart) ?
+                elt('wiki-page').selectionStart : 0;
+            edit_scroll = elt('scroll-top').value= (elt('wiki-page').scrollTop)?
+                elt('wiki-page').scrollTop : 0;
+            arrows_url += '&amp;caret=' + caret + '&amp;scroll_top=' +
+                edit_scroll;
+            arrows.href = arrows_url;" ><?php
             e($arrows); ?></a>]</div>
         <?php
         }
@@ -172,9 +181,11 @@ class WikiElement extends Element implements CrawlConstants
                 e(tl('wiki_element_submit')); ?></button>
             </form>
             <?php
-            e("<p><a href='?c=group&amp;group_id=".PUBLIC_GROUP_ID.
-                "&amp;arg=read&amp;a=wiki&amp;page_name=Syntax'>".
-                tl("wiki_view_syntax_summary")."</a>.</p>");
+            e("<p><a href='?c={$data['CONTROLLER']}&amp;".CSRF_TOKEN.
+                "={$data[CSRF_TOKEN]}&amp;group_id=".
+                PUBLIC_GROUP_ID. "&amp;arg=read&amp;a=wiki&amp;".
+                "page_name=Syntax'>". tl("wiki_view_syntax_summary").
+                "</a>.</p>");
         } else if(!$logged_in) {
             e("<h2>".tl("wiki_view_page_no_exist", $data["PAGE_NAME"]).
                 "</h2>");
@@ -208,7 +219,8 @@ class WikiElement extends Element implements CrawlConstants
             onsubmit="elt('caret-pos').value =
             (elt('wiki-page').selectionStart) ?
             elt('wiki-page').selectionStart : 0;
-            elt('scroll-top').value=elt('wiki-page').scrollTop;" >
+            elt('scroll-top').value= (elt('wiki-page').scrollTop) ?
+            elt('wiki-page').scrollTop : 0;" >
             <input type="hidden" name="c" value="<?php e($data['CONTROLLER']);
             ?>" />
             <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
ViewGit