diff --git a/lang/en/docs/release.html b/lang/en/docs/release.html index 6d8cd6479bf..2b52413230a 100644 --- a/lang/en/docs/release.html +++ b/lang/en/docs/release.html @@ -101,6 +101,8 @@
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 db5249e7126..a5b0b44bc7d 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 0902879d822..0fe4880e313 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 bbf7af78327..d8680a793f0 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 00000000000..f4b7e85b192 --- /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'.$tag.'>\\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 = "\n";
+ $buffer = $buffer . $this->line_replace( eregi_replace( "^>","",$line) ). "\n";
+ $this->block_state = STATE_BLOCKQUOTE;
+ }
+ else
+ if (eregi( "^ ",$line) ) {
+ // preformatted text
+ $buffer = $buffer . "\n";
+ $buffer = $buffer . $this->line_replace($line) . "\n";
+ $this->block_state = STATE_PREFORM;
+ }
+ else
+ if (eregi("^\% ",$line) ) {
+ // preformatted text - no processing
+ $buffer = $buffer . "\n";
+ $buffer = $buffer . eregi_replace( "^\%","",$line) . "\n";
+ $this->block_state = STATE_NOTIKI;
+ }
+ else {
+ // ordinary paragraph
+ $buffer = $buffer . "\n";
+ $buffer = $buffer . $this->line_replace($line) . "\n";
+ $this->block_state = STATE_PARAGRAPH;
+ }
+ continue;
+ }
+
+ if (($this->block_state == STATE_PARAGRAPH) |
+ ($this->block_state == STATE_BLOCKQUOTE) |
+ ($this->block_state == STATE_PREFORM) ) {
+ $buffer = $buffer . $this->line_replace($line) . "\n";
+ continue;
+ }
+ elseif ($this->block_state == STATE_NOTIKI) {
+ $buffer = $buffer . $line . "\n";
+ }
+ }
+
+ // close off any block level tags
+ $buffer = $buffer . $this->close_block( $this->block_state );
+
+ return $buffer;
+ }
+
+}
+
+?>
diff --git a/mod/resource/details.php b/mod/resource/details.php
index 94e97c06d16..664e73c47cf 100644
--- a/mod/resource/details.php
+++ b/mod/resource/details.php
@@ -149,6 +149,24 @@
break;
+ case WIKITEXT:
+ $strfulltext = get_string("fulltext", "resource");
+ ?>
+
+
+ =$strfulltext?>:
+
+ helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?>
+ helpbutton("wiki", get_string("helpwiki"), "moodle", true, true) ?>
+
+
+
+
+
+
+
+ break;
+
case HTML:
$strhtmlfragment = get_string("htmlfragment", "resource");
?>
diff --git a/mod/resource/lib.php b/mod/resource/lib.php
index bf5687a4d34..8e54de4d0af 100644
--- a/mod/resource/lib.php
+++ b/mod/resource/lib.php
@@ -7,6 +7,7 @@ define("PLAINTEXT", "4");
define("WEBLINK", "5");
define("HTML", "6");
define("PROGRAM", "7");
+define("WIKITEXT", "8");
$RESOURCE_TYPE = array (REFERENCE => get_string("resourcetype1", "resource"),
WEBPAGE => get_string("resourcetype2", "resource"),
@@ -14,7 +15,8 @@ $RESOURCE_TYPE = array (REFERENCE => get_string("resourcetype1", "resource"),
PLAINTEXT => get_string("resourcetype4", "resource"),
WEBLINK => get_string("resourcetype5", "resource"),
HTML => get_string("resourcetype6", "resource"),
- PROGRAM => get_string("resourcetype7", "resource") );
+ PROGRAM => get_string("resourcetype7", "resource"),
+ WIKITEXT => get_string("resourcetype8", "resource") );
$RESOURCE_FRAME_SIZE = 130;
diff --git a/mod/resource/view.php b/mod/resource/view.php
index 6c751a6eafb..2c5e12771ce 100644
--- a/mod/resource/view.php
+++ b/mod/resource/view.php
@@ -179,6 +179,19 @@
redirect($temp);
break;
+ case WIKITEXT:
+ add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
+ print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
+ "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
+
+ print_simple_box(wiki_to_html($resource->alltext), "CENTER", "", "$THEME->cellcontent", "20" );
+
+ echo "$strlastmodified: ".userdate($resource->timemodified)."
";
+
+ print_footer($course);
+ break;
+
+
default:
print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
"", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));