From 3e9ca9fbc55ce67a11482456776a3380a19fa2be Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 1 May 2003 03:43:16 +0000 Subject: [PATCH] Added new Wiki code to allow Resource web pages to be created/edited using Wiki format This code contributed by Howard Miller. Thanks! --- lang/en/docs/release.html | 2 + lang/en/help/resource/resourcetype.html | 5 + lang/en/moodle.php | 1 + lang/en/resource.php | 1 + lib/weblib.php | 10 + lib/wiki.php | 279 ++++++++++++++++++++++++ mod/resource/details.php | 18 ++ mod/resource/lib.php | 4 +- mod/resource/view.php | 13 ++ 9 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 lib/wiki.php diff --git a/lang/en/docs/release.html b/lang/en/docs/release.html index 6d8cd6479b..2b52413230 100644 --- a/lang/en/docs/release.html +++ b/lang/en/docs/release.html @@ -101,6 +101,8 @@
Resources
  • Better performance when editing large text or HTML resources +
  • Plain images are now display centered within a proper web page (not raw). +
  • Resource pages can now be edited using Wiki format
  • Custom Themes
    diff --git a/lang/en/help/resource/resourcetype.html b/lang/en/help/resource/resourcetype.html index 1c97e2b5c5..392a150022 100644 --- a/lang/en/help/resource/resourcetype.html +++ b/lang/en/help/resource/resourcetype.html @@ -25,3 +25,8 @@ within a frame, as if it is integrated within the course.

    Program - an external program that requires information passed to it about the current Moodle user and course. This allows external web applications to cooperate with Moodle. + +

    Wiki text - allows more formatting options that Plain Text without having to learn HTML. +You type plain text but a large range of formatting characters can be included +(e.g. *this will be bold* /this will be emphasised/) to easily create complex formatting.

    + diff --git a/lang/en/moodle.php b/lang/en/moodle.php index db5249e712..a5b0b44bc7 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -230,6 +230,7 @@ $string['helphtml'] = "How to write html"; $string['helppicture'] = "How to upload a picture"; $string['helpreading'] = "Read carefully"; $string['helptext'] = "How to write text"; +$string['helpwiki'] = "How to write Wiki text"; $string['helprichtext'] = "About Richtext editor"; $string['helpsummaries'] = "About these summaries"; $string['helpquestions'] = "Ask good questions"; diff --git a/lang/en/resource.php b/lang/en/resource.php index 0902879d82..0fe4880e31 100644 --- a/lang/en/resource.php +++ b/lang/en/resource.php @@ -26,5 +26,6 @@ $string['resourcetype4'] = "Plain text"; $string['resourcetype5'] = "Web Link"; $string['resourcetype6'] = "HTML text"; $string['resourcetype7'] = "Program"; +$string['resourcetype8'] = "Wiki text"; ?> diff --git a/lib/weblib.php b/lib/weblib.php index bbf7af7832..d8680a793f 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -561,6 +561,16 @@ function text_to_html($text, $smiley=true, $para=true) { } } +function wiki_to_html($text) { +/// given Wiki formatted text, make it into XHTML + + require('wiki.php'); + + // get Tiki object and do the deed + $wiki = new Wiki; + return $wiki->format($text); +} + function highlight($needle, $haystack) { /// This function will highlight instances of $needle in $haystack diff --git a/lib/wiki.php b/lib/wiki.php new file mode 100644 index 0000000000..f4b7e85b19 --- /dev/null +++ b/lib/wiki.php @@ -0,0 +1,279 @@ +list_state) { + case LIST_NONE: + break; + case LIST_UNORDERED: + $ltag = "\n"; + break; + case LIST_ORDERED: + $ltag = "\n"; + break; + case LIST_DEFINITION: + $ltag = "\n"; + break; + } + $this->list_state = LIST_NONE; + + switch ($state) { + case STATE_PARAGRAPH: + return "$ltag

    \n"; + break; + case STATE_BLOCKQUOTE: + return "$ltag\n"; + break; + case STATE_PREFORM: + return "$ltag\n"; + break; + case STATE_NOTIKI: + return "$ltag\n"; + break; + } + } + + + function do_replace( $line, $mark, $tag ) { + // do the regex thingy for things like bold, italic etc + // $mark is the magic character, and $tag the HTML tag to insert + + $regex = '(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'($| |[.,;:)])'; + $replace = '\\1<'.$tag.'>\\2\\3'; + return eregi_replace( $regex, $replace, $line ); + } + + function do_list( $line ) { + // handle line with list character on it + + // get magic character and then delete it from the line + $listchar = $line{0}; + $line = eregi_replace( "^[*#;:] ", "", $line ); + + // if not in "list mode" then we need to drop the appropriate start tag + $tag = ""; + if ($this->list_state == LIST_NONE) { + switch ($listchar) { + case '*': + $tag = "