Revision [16728]

This is an old revision of HtmlAreaEditing made by BjzIuk on 2007-05-31 10:42:20.

 

HTMLAREA for Wakka

[Note: HTMLArea is now apparently a commercial product. The codebase that was the start of HTMLarea (and may have been opensourced) is now under the name Areaedit (see http://www.formvista.com/otherprojects/areaedit.html) - 19 Aug 05]


This is a patch for WakkaWiki coded by VictorManuelVarela.

WakkaWiki a lightweight WikiEngine powered by PHP and MySQL, and developed by Hendrik Mans and Carlo Zotman. Good job!


Download Wakka with HTMLAREA

File: wakka-with-htmlarea.tgz

Note: You must set "default_handler" to "html" to run HTMLAREA in new pages.


Steps to use HTMLAREA in existing Wakka Wikis
1. Patching wakka.php
diff file for wakka.php:
*** ../wakka-subversion/wakka.php   Wed Jan 21 17:26:49 2004
--- wakka.php   Thu Jan 22 11:01:31 2004
***************
*** 120,126 ****
    function LoadPageTitles() { return $this->LoadAll("select distinct tag from ".$this->config["table_prefix"]."pages order by tag"); }
    function LoadAllPages() { return $this->LoadAll("select * from ".$this->config["table_prefix"]."pages where latest = 'Y' order by tag"); }
    function FullTextSearch($phrase) { return $this->LoadAll("select * from ".$this->config["table_prefix"]."pages where latest = 'Y' and match(tag, body) against('".mysql_escape_string($phrase)."')"); }
!   function SavePage($tag, $body, $comment_on = "")
    {
        // get current user
        $user = $this->GetUserName();
--- 120,126 ----
    function LoadPageTitles() { return $this->LoadAll("select distinct tag from ".$this->config["table_prefix"]."pages order by tag"); }
    function LoadAllPages() { return $this->LoadAll("select * from ".$this->config["table_prefix"]."pages where latest = 'Y' order by tag"); }
    function FullTextSearch($phrase) { return $this->LoadAll("select * from ".$this->config["table_prefix"]."pages where latest = 'Y' and match(tag, body) against('".mysql_escape_string($phrase)."')"); }
!   function SavePage($tag, $body, $comment_on = "", $handler="page")
    {
        // get current user
        $user = $this->GetUserName();
***************
*** 163,168 ****
--- 163,169 ----
                "owner = '".mysql_escape_string($owner)."', ".
                "user = '".mysql_escape_string($user)."', ".
                "latest = 'Y', ".
                "handler = '".mysql_escape_string($handler)."', ".
                "body = '".mysql_escape_string(trim($body))."'");
        }
    }
***************
*** 352,358 ****
        {
            $method = substr($method, strrpos('/', $method));
        }
!       if (!$handler = $this->page["handler"]) $handler = "page";
        $methodLocation = $handler."/".$method.".php";
        return $this->IncludeBuffered($methodLocation, "<i>Unknown method \"$methodLocation\"</i>", "", $this->config["handler_path"]);
    }
--- 353,359 ----
        {
            $method = substr($method, strrpos('/', $method));
        }
!       if (!$handler = $this->page["handler"]) $handler = $this->config["default_handler"];
        $methodLocation = $handler."/".$method.".php";
        return $this->IncludeBuffered($methodLocation, "<i>Unknown method \"$methodLocation\"</i>", "", $this->config["handler_path"]);
    }
***************
*** 590,595 ****
--- 591,597 ----
 
    "action_path"           => "actions",
    "handler_path"          => "handlers",
    "default_handler"   => "page",
 
    "header_action"         => "header",
    "footer_action"         => "footer",


Explanation:

search the SavePage function, add a new $handler param (with "page" default value) and add a line in SQL insert command: handler = '$handler'
search the Method function, modify ($handler = "page") to ($handler = $this->config["default_handler"]
search the $wakkaConfig default value, add ("default_handler" => "page",)


2. Adding html formatter

formatters/html.php:
<?php

// This may look a bit strange, but all possible formatting tags have to be in a single regular expression for this to work correctly. Yup!

if (!function_exists("wakka2callback"))
{
    function wakka2callback($things)
    {
        $thing = $things[1];

        global $wakka;

        // forced links
        if (preg_match("/^\[\[(\S*)(\s (. ))?\]\]$/", $thing, $matches))
        {
            list (, $url, , $text) = $matches;
            if ($url)
            {
                if (!$text) $text = $url;
                return $wakka->Link($url, "", $text);
            }
            else
            {
                return "";
            }
        }
        // events
        else if (preg_match("/^\{\{(.*?)\}\}$/s", $thing, $matches))
        {
            if ($matches[1])
                return $wakka->Action($matches[1]);
            else
                return "{{}}";
        }
        // interwiki links!
        else if (preg_match("/^[A-Z,ÄÖÜ][A-Z,a-z,ÄÖÜ,ßäöü] [:]([A-Z,a-z,0-9,ÄÖÜ,ßäöü]*)$/s", $thing))
        {
            return $wakka->Link($thing);
        }
        // wakka links!
        else if (preg_match("/^[A-Z,ÄÖÜ][a-z,ßäöü] [A-Z,0-9,ÄÖÜ][A-Z,a-z,0-9,ÄÖÜ,ßäöü]*$/s", $thing))
        {
            return $wakka->Link($thing);
        }
        // if we reach this point, it must have been an accident.
        return $thing;
    }
}

$text = str_replace("\r", "", $text);
$text = trim($text)."\n";
$text = preg_replace_callback(
    "/(\[\[.*?\]\]|\b[a-z] :\/\/\S |\n\t (-|[0-9,a-z,A-Z] \))?|\{\{.*?\}\}|".
    "\b[A-Z,ÄÖÜ][A-Z,a-z,ÄÖÜ,ßäöü] [:]([A-Z,a-z,0-9,ÄÖÜ,ßäöü]*)\b|".
    "\b([A-Z,ÄÖÜ][a-z,ßäöü] [A-Z,0-9,ÄÖÜ][A-Z,a-z,0-9,ÄÖÜ,ßäöü]*)\b|".
    "\n)/ms", "wakka2callback", $text);

// we're cutting the last <br>
$text = preg_replace("/<br \/>$/", "", trim($text));
print($text);
?>


Explanation:

delete all HTML related stuff to show html as is.
delete all Wiki related stuff (except WakkaLinks and WakkaActions)



3. Adding html handler

Copy handlers/page/* into handlers/html/*.
The files you must change is edit.php and show.php.

diff file for handlers/html/edit.php:
*** ../page/edit.php    Wed Jan 21 17:26:57 2004
--- edit.php    Thu Jan 22 10:31:31 2004
***************
*** 29,41 ****
                // only save if new body differs from old body
                if (trim($body) != $this->page['body']) {
                    // add page (revisions)
!                   $this->SavePage($this->tag, $body);
 
                    // now we render it internally so we can write the updated link table.
                    $this->ClearLinkTable();
                    $this->StartLinkTracking();
                    $dummy = $this->Header();
!                   $dummy .= $this->Format($body);
                    $dummy .= $this->Footer();
                    $this->StopLinkTracking();
                    $this->WriteLinkTable();
--- 29,41 ----
                // only save if new body differs from old body
                if (trim($body) != $this->page['body']) {
                    // add page (revisions)
!                   $this->SavePage($this->tag, $body,'','html');
 
                    // now we render it internally so we can write the updated link table.
                    $this->ClearLinkTable();
                    $this->StartLinkTracking();
                    $dummy = $this->Header();
!                   $dummy .= $this->Format($body,'html');
                    $dummy .= $this->Footer();
                    $this->StopLinkTracking();
                    $this->WriteLinkTable();
***************
*** 67,73 ****
            "<input type=\"hidden\" name=\"previous\" value=\"".$previous."\" />\n".
            "<input type=\"hidden\" name=\"body\" value=\"".htmlspecialchars($body)."\" />\n";
       
!       $output .= $this->Format($body);
 
        $output .=
            "<br />\n".
--- 67,73 ----
            "<input type=\"hidden\" name=\"previous\" value=\"".$previous."\" />\n".
            "<input type=\"hidden\" name=\"body\" value=\"".htmlspecialchars($body)."\" />\n";
       
!       $output .= $this->Format($body,'html');
 
        $output .=
            "<br />\n".
***************
*** 88,101 ****
            $body = trim($body)."\n\n----\n\n--".$this->UserName()." (".strftime("%c").")";
        }
 
        $output .=
            $this->FormOpen("edit").
            "<input type=\"hidden\" name=\"previous\" value=\"".$previous."\" />\n".
!           "<textarea onKeyDown=\"fKeyDown()\" name=\"body\" style=\"width: 100%; height: 400px\">".htmlspecialchars($body)."</textarea><br />\n".
            "<input name=\"submit\" type=\"submit\" value=\"Store\" accesskey=\"s\" /> <input name=\"submit\" type=\"submit\" value=\"Preview\" accesskey=\"p\" /> <input type=\"button\" value=\"Cancel\" onClick=\"document.location='".$this->href("")."';\" />\n".
            $this->FormClose();
    }
 
 
    print($output);
  }
--- 88,117 ----
            $body = trim($body)."\n\n----\n\n--".$this->UserName()." (".strftime("%c").")";
        }
 
     $output .=
          '<script language="JavaScript" src="'.$this->config['base_url'].'/htmlarea/htmlarea.js"></script>'."\n".
          '<script language="JavaScript" src="'.$this->config['base_url'].'/htmlarea/dialog.js"></script>'."\n".
          '<script language="JavaScript" src="'.$this->config['base_url'].'/htmlarea/popups/en/htmlarea-lang.js"></script>'."\n";
 
        $output .=
            $this->FormOpen("edit").
            "<input type=\"hidden\" name=\"previous\" value=\"".$previous."\" />\n".
!           "<textarea onKeyDown=\"fKeyDown()\" id=\"body\" name=\"body\" style=\"width: 100%; height: 400px\">".htmlspecialchars($body)."</textarea><br />\n".
            "<input name=\"submit\" type=\"submit\" value=\"Store\" accesskey=\"s\" /> <input name=\"submit\" type=\"submit\" value=\"Preview\" accesskey=\"p\" /> <input type=\"button\" value=\"Cancel\" onClick=\"document.location='".$this->href("")."';\" />\n".
            $this->FormClose();
    }
 
    $output .= "<script language=\"JavaScript\">\n".
              "<!--\n".
              "var editor=new HTMLArea(\"body\");\n".
              "editor.config.editorURL = \"{$this->config['base_url']}/htmlarea/\";\n".
              "editor.config.imgURL = \"images/\";\n".
              "editor.config.popupURL = \"popups/en/\";\n".
              "editor.config.bodyDirection = \"ltr\";\n".
              'editor.config.toolbar = [[ "formatblock", "space", "bold", "italic", "underline", "separator", "copy", "cut", "paste", "space", "undo", "redo", "separator", "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator", "insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator", "forecolor", "separator", "inserthorizontalrule", "createlink", "insertimage", "inserttable" ]];'."\n".
              "editor.generate();\n".
              "//-->\n".
              "</script>\n";
 
    print($output);
  }


%%(php)
diff file for handlers/html/show.php:
* show.php Thu Jan 22 13:18:40 2004

showht.php Thu Jan 22 13:15:26 2004
*
* 21,27


display page
! print($this->Format($this->page["body"], "wakka"));

if this is an old revision, display some buttons
if ($this->HasAccess("write")
There are 6 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki