diff -Bbur -x .svn -x .DS_Store moodle.orig/admin/user.php moodle/admin/user.php
--- moodle.orig/admin/user.php	2008-07-10 17:18:05.000000000 -0700
+++ moodle/admin/user.php	2009-03-11 10:51:37.000000000 -0700
@@ -3,6 +3,7 @@
     require_once('../config.php');
     require_once($CFG->libdir.'/adminlib.php');
     require_once($CFG->dirroot.'/user/filters/lib.php');
+    require_once($CFG->dirroot.'/blocks/marginalia/lib.php');
 
     $delete       = optional_param('delete', 0, PARAM_INT);
     $confirm      = optional_param('confirm', '', PARAM_ALPHANUM);   //md5 confirmation hash
@@ -76,6 +77,9 @@
             die;
         } else if (data_submitted() and !$user->deleted) {
             if (delete_user($user)) {
+            	// Delete annotations here to avoid adding an include to moodlelib.php
+            	// (which would then pull the annotation library into everything) 
+            	annotations_delete_user($user->id);
                 notify(get_string('deletedactivity', '', fullname($user, true)) );
             } else {
                 notify(get_string('deletednot', '', fullname($user, true)));
Only in moodle/admin: user.php.orig
Only in moodle: blocks
diff -Bbur -x .svn -x .DS_Store moodle.orig/lib/weblib.php moodle/lib/weblib.php
--- moodle.orig/lib/weblib.php	2009-02-16 15:05:37.000000000 -0800
+++ moodle/lib/weblib.php	2009-03-05 18:39:41.000000000 -0800
@@ -33,7 +33,7 @@
  * - datalib.php - functions that access the database.
  * - moodlelib.php - general-purpose Moodle functions.
  * @author Martin Dougiamas
- * @version  $Id$
+ * @version  $Id$Â
  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  * @package moodlecore
  */
@@ -5012,6 +5012,11 @@
         }
         echo "\nvar HTML_editor = $editor;";
     }
+	
+	echo "if ( Smartquote && Smartquote.subscribeHtmlArea )\n"
+		. "{\n"
+		. "  var bus = Smartquote.subscribeHtmlArea( $editor );\n"
+		. "}\n";
     echo '//]]>'."\n";
     echo '</script>'."\n";
 }
diff -Bbur -x .svn -x .DS_Store moodle.orig/mod/forum/discuss.php moodle/mod/forum/discuss.php
--- moodle.orig/mod/forum/discuss.php	2009-01-28 15:07:20.000000000 -0800
+++ moodle/mod/forum/discuss.php	2009-03-05 19:03:29.000000000 -0800
@@ -36,6 +36,13 @@
 
     // move this down fix for MDL-6926
     require_once('lib.php');
+	require_js( array( 'yui_datasource' ) );
+	require_once( $CFG->dirroot.'/blocks/marginalia/config.php' );
+    require_once( ANNOTATION_DIR.'/marginalia-php/embed.php' );
+    require_once( ANNOTATION_DIR.'/annotation_summary_query.php' );
+    require_once( ANNOTATION_DIR.'/annotation_globals.php' );
+    require_once( ANNOTATION_DIR.'/lib.php' );
+    // require_once("../../local/annotation/marginalia-config.php");
 
     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
     require_capability('mod/forum:viewdiscussion', $modcontext, NULL, true, 'noviewdiscussionspermission', 'forum');
@@ -146,9 +153,18 @@
         $navlinks[] = array('name' => format_string($post->subject), 'type' => 'title');
     }
 
+    // Begin Annotation Code to set $meta
+    $meta = moodle_marginalia::header_html(  );
+    // I'm perverting the meta argument here, but I can't figure out how otherwise
+	// to emit a stylesheet link.  #geof#
+	
     $navigation = build_navigation($navlinks, $cm);
     print_header("$course->shortname: ".format_string($discussion->name), $course->fullname,
-                     $navigation, "", "", true, $searchform, navmenu($course, $cm));
+                     $navigation, "", $meta, true, $searchform, navmenu($course, $cm));
+	
+    // refurl is the relative URL to this resource from the server root (i.e., it should start with '/')
+    $refurl = "/mod/forum/discuss.php?d=$d";  // used to start with $rootpath
+	echo moodle_marginalia::init_html( $refurl );
 
 
 /// Check to see if groups are being used in this forum
@@ -211,6 +227,12 @@
             }
         }
     }
+	
+	// Annotation controls (help, user dropdown, link to summary page)
+	echo "</td>\n<td id='annotation-controls'>";
+	moodle_marginalia::show_help( 'forum' );
+	moodle_marginalia::show_user_dropdown( $refurl, true );
+	echo moodle_marginalia::summary_link_html( $refurl, $USER->username );
     echo "</td></tr></table>";
 
     if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
Only in moodle/mod/forum: lib-20090305.php
diff -Bbur -x .svn -x .DS_Store moodle.orig/mod/forum/lib.php moodle/mod/forum/lib.php
--- moodle.orig/mod/forum/lib.php	2009-03-03 15:06:34.000000000 -0800
+++ moodle/mod/forum/lib.php	2009-03-16 19:28:05.000000000 -0700
@@ -1,6 +1,9 @@
 <?php  // $Id$
 
 require_once($CFG->libdir.'/filelib.php');
+require_once( $CFG->dirroot.'/blocks/marginalia/config.php' );
+require_once( ANNOTATION_DIR.'/marginalia-php/marginalia-constants.php' );
+require_once( ANNOTATION_DIR.'/annotation_globals.php' );
 
 /// CONSTANTS ///////////////////////////////////////////////////////////
 
@@ -1501,7 +1504,7 @@
 function forum_get_post_full($postid) {
     global $CFG;
 
-    return get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname, u.email, u.picture, u.imagealt
+    return get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname, u.username, u.email, u.picture, u.imagealt
                              FROM {$CFG->prefix}forum_posts p
                                   JOIN {$CFG->prefix}forum_discussions d ON p.discussion = d.id
                                   LEFT JOIN {$CFG->prefix}user u ON p.userid = u.id
@@ -1517,7 +1520,7 @@
 function forum_get_discussion_posts($discussion, $sort, $forumid) {
     global $CFG;
 
-    return get_records_sql("SELECT p.*, $forumid AS forum, u.firstname, u.lastname, u.email, u.picture, u.imagealt
+    return get_records_sql("SELECT p.*, $forumid AS forum, u.firstname, u.lastname, u.username, u.email, u.picture, u.imagealt
                               FROM {$CFG->prefix}forum_posts p
                          LEFT JOIN {$CFG->prefix}user u ON p.userid = u.id
                              WHERE p.discussion = $discussion
@@ -1544,7 +1547,7 @@
         $tr_join = "LEFT JOIN {$CFG->prefix}forum_read fr ON (fr.postid = p.id AND fr.userid = $USER->id)";
     }
 
-    if (!$posts = get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture, u.imagealt $tr_sel
+    if (!$posts = get_records_sql("SELECT p.*, u.firstname, u.lastname, u.username, u.email, u.picture, u.imagealt $tr_sel
                                      FROM {$CFG->prefix}forum_posts p
                                           LEFT JOIN {$CFG->prefix}user u ON p.userid = u.id
                                           $tr_join
@@ -1582,7 +1585,7 @@
 function forum_get_child_posts($parent, $forumid) {
     global $CFG;
 
-    return get_records_sql("SELECT p.*, $forumid AS forum, u.firstname, u.lastname, u.email, u.picture, u.imagealt
+    return get_records_sql("SELECT p.*, $forumid AS forum, u.firstname, u.lastname, u.username, u.email, u.picture, u.imagealt
                               FROM {$CFG->prefix}forum_posts p
                          LEFT JOIN {$CFG->prefix}user u ON p.userid = u.id
                              WHERE p.parent = '$parent'
@@ -2852,7 +2855,7 @@
     }
 
     echo '<a id="p'.$post->id.'"></a>';
-    echo '<table cellspacing="0" class="forumpost'.$read_style.'">';
+    echo '<table cellspacing="0" class="forumpost'.$read_style.' '.PM_POST_CLASS.'" id="m'.$post->id.'">';
 
     // Picture
     $postuser = new object();
@@ -2867,23 +2870,42 @@
     echo '</td>';
 
     if ($post->parent) {
-        echo '<td class="topic">';
+        echo '<td class="topic" colspan="3">';
     } else {
-        echo '<td class="topic starter">';
+        echo '<td class="topic starter" colspan="3">';
     }
 
     if (!empty($post->subjectnoformat)) {
-        echo '<div class="subject">'.$post->subject.'</div>';
+        echo '<div class="subject '.PM_TITLE_CLASS.'">'.$post->subject.'</div>';
     } else {
-        echo '<div class="subject">'.format_string($post->subject).'</div>';
+        echo '<div class="subject '.PM_TITLE_CLASS.'">'.format_string($post->subject).'</div>';
     }
 
+    // #GEOF# Annotations must use a unique value for the user ID
+    // This should be a string, and it should be human-readable and suitable for
+    // outside consumption.  I'm therefore using username rather than ID.
+    // If Moodle displayed these values, the fields wouldn'n need to be hidden.
+    $rootpath = $CFG->wwwroot; //parse_url( $CFG->wwwroot );
+    //$rootpath = $rootpath[ 'path' ];
+    $refurl = "$rootpath/mod/forum/permalink.php?p=$post->id";
+    $discussurl = "$rootpath/mod/forum/discuss.php?d=$post->discussion"; // used for summary link
+	// This class author, used by Marginalia, must preceed the one below, used by Moodle.
+	// Unfortunately I can't use that one - it's marked author but it is not, in fact, the author
+	// - it also includes "by", the date, etc.  (grrr) #geof#
+    echo "<span style='display:none' class='" . PM_AUTHOR_CLASS . "' title='".htmlspecialchars( $post->username )."'>" . htmlspecialchars($post->firstname.' '.$post->lastname) . "</span>\n";
+    echo "<abbr style='display:none' class='" . PM_DATE_CLASS . "' title='" . date( 'Ymd', $post->modified ) . 'T' . date( 'HiO', $post->modified ) . "'></abbr>\n";
+    echo "<a style='display:none' rel='" . PM_URL_REL . "' href='$refurl'></a>\n";
+
     echo '<div class="author">';
     $fullname = fullname($postuser, $cm->cache->caps['moodle/site:viewfullnames']);
     $by = new object();
     $by->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.
                 $post->userid.'&amp;course='.$course->id.'">'.$fullname.'</a>';
     $by->date = userdate($post->modified);
+
+    // This, I presume, is to localize string display.  Unfortunately it's
+    // unstructured text, so I can't insert the necessary <abbr> element with the date.
+    // Instead that's done in a hidden tag above.
     print_string('bynameondate', 'forum', $by);
     echo '</div></td></tr>';
 
@@ -2907,7 +2929,7 @@
 
 // Actual content
 
-    echo '</td><td class="content">'."\n";
+    echo '</td><td class="content" valign="top">'."\n";
 
     if ($post->attachment) {
         echo '<div class="attachments">';
@@ -2925,12 +2947,12 @@
         // Print shortened version
         echo format_text(forum_shorten_post($post->message), $post->format, $options, $course->id);
         $numwords = count_words(strip_tags($post->message));
-        echo '<div class="posting"><a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'">';
+        echo '<div class="posting ' . PM_CONTENT_CLASS . '"><a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'">';
         echo get_string('readtherest', 'forum');
         echo '</a> ('.get_string('numwords', '', $numwords).')...</div>';
     } else {
         // Print whole message
-        echo '<div class="posting">';
+        echo '<div class="posting ' . PM_CONTENT_CLASS . '">';
         if ($highlight) {
             echo highlight($highlight, format_text($post->message, $post->format, $options, $course->id));
         } else {
@@ -3002,6 +3024,10 @@
         $commands[] = '<a href="'.$CFG->wwwroot.'/mod/forum/post.php?delete='.$post->id.'">'.$strdelete.'</a>';
     }
 
+	// The span below is to allow text-decoration:underline, which doesn't seem
+	// to work otherwise (Firefox bug?)
+	$commands[] = "<button class='smartquote'><span>Quote</span></button>";
+	
     if ($reply) {
         $commands[] = '<a href="'.$CFG->wwwroot.'/mod/forum/post.php?reply='.$post->id.'">'.$strreply.'</a>';
     }
@@ -3087,7 +3113,18 @@
     if ($footer) {
         echo '<div class="footer">'.$footer.'</div>';
     }
-    echo '</td></tr></table>'."\n\n";
+//	if ( $canannotate )
+//	{
+		echo "</td><td class='control-margin'><div><button type='button' "
+			." title='".htmlspecialchars( get_string( 'create_button', ANNOTATION_STRINGS ) )."'" 
+			." onclick='window.moodleMarginalia.createAnnotation(event,\"m$post->id\")'><span>&gt;</span></button></div></td>\n";
+		echo "<td class='".AN_NOTES_CLASS."' valign='top'><div>";
+		echo "<ol></ol>\n";
+		echo "</div></td>\n";
+//	}
+//	else
+//		echo "<td></td><td></td>";
+    echo '</tr></table>'."\n\n";
 
     if ($istracked && !$CFG->forum_usermarksread && !$post_read) {
         forum_tp_mark_post_read($USER->id, $post, $forum->id);
Only in moodle/mod/forum: permalink.php
diff -Bbur -x .svn -x .DS_Store moodle.orig/mod/forum/post.php moodle/mod/forum/post.php
--- moodle.orig/mod/forum/post.php	2009-01-14 15:07:01.000000000 -0800
+++ moodle/mod/forum/post.php	2009-03-11 13:13:32.000000000 -0700
@@ -13,7 +13,7 @@
     $name    = optional_param('name', '', PARAM_CLEAN);
     $confirm = optional_param('confirm', 0, PARAM_INT);
     $groupid = optional_param('groupid', null, PARAM_INT);
-
+	$messageinit = optional_param('message',0,PARAM_CLEANHTML);	// #geof#
 
     //these page_params will be passed as hidden variables later in the form.
     $page_params = array('reply'=>$reply, 'forum'=>$forum, 'edit'=>$edit);
@@ -110,7 +110,7 @@
         $post->parent     = 0;
         $post->subject    = '';
         $post->userid     = $USER->id;
-        $post->message    = '';
+        $post->message     = $messageinit ? $messageinit : '';	// #geof#
 
         if (isset($groupid)) {
             $post->groupid = $groupid;
@@ -178,7 +178,7 @@
         $post->parent      = $parent->id;
         $post->subject     = $parent->subject;
         $post->userid      = $USER->id;
-        $post->message     = '';
+        $post->message     = $messageinit ? $messageinit : '';	// #geof#
 
         $post->groupid = ($discussion->groupid == -1) ? 0 : $discussion->groupid;
 
@@ -446,6 +446,11 @@
     // fix for MDL-6926
     course_setup($course->id);
     require_once('post_form.php');
+    require_once('../../blocks/marginalia/config.php');
+    require_once( ANNOTATION_DIR.'/marginalia-php/embed.php' );
+    require_once( ANNOTATION_DIR.'/annotation_summary_query.php' );
+    require_once( ANNOTATION_DIR.'/annotation_globals.php' );
+    require_once( ANNOTATION_DIR.'/lib.php' );
 
     $mform_post = new mod_forum_post_form('post.php', array('course'=>$course, 'cm'=>$cm, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
 
@@ -460,6 +463,12 @@
             $errordestination = $SESSION->fromurl;
         }
 
+		// Strip out any annotation class names.
+		$expr = '/(<[^>]+\s)class=[\\\\]?[\'\"][^>\'\"]*\bannotation\b[^>\'\"]*[\\\\]?[\'\"]/';
+		$post->message = preg_replace( $expr, '$1', $post->message );
+		// It would be good to also strip out annotation highlighting, but that's tricky.
+		// #/geof#
+
         // TODO add attachment processing
         //$fromform->attachment = isset($_FILES['attachment']) ? $_FILES['attachment'] : NULL;
 
@@ -667,6 +676,21 @@
 
     $forcefocus = empty($reply) ? NULL : 'message';
 
+    // The Javascript is required for smartquotes to work.  #geof#
+	$meta = "<link rel='stylesheet' type='text/css' href='$CFG->wwwroot/blocks/marginalia/annotation-styles.php'/>\n"
+		."<script language='JavaScript' type='text/javascript' src='$CFG->wwwroot/blocks/marginalia/marginalia/log.js'></script>\n"
+    	."<script language='JavaScript' type='text/javascript' src='$CFG->wwwroot/blocks/marginalia/marginalia/3rd-party.js'></script>\n"
+		."<script language='JavaScript' type='text/javascript' src='$CFG->wwwroot/blocks/marginalia/marginalia/domutil.js'></script>\n"
+		."<script language='JavaScript' type='text/javascript' src='$CFG->wwwroot/blocks/marginalia/marginalia/ranges.js'></script>\n"
+		."<script language='JavaScript' type='text/javascript' src='$CFG->wwwroot/blocks/marginalia/marginalia/post-micro.js'></script>\n"
+		."<script language='JavaScript' type='text/javascript' src='$CFG->wwwroot/blocks/marginalia/smartquote.js'></script>\n"
+		."<script language='JavaScript' type='text/javascript'>\n"
+		."  addEvent( window, 'load', function() { Smartquote.enableSmartquote( '".$CFG->wwwroot."'); } );\n"
+		."</script>\n";
+	// It is incredibly inefficient to use the CookieBus to send this quote.  However... avoiding that means finding
+	// the editor object, which has been given a random name by the library.  *That* would mean heavier modification
+	// to other Moodle code, which would make Marginalia harder to integrate and maintain.  So.  This is it.
+
     $navlinks = array();
     if ($post->parent) {
         $navlinks[] = array('name' => format_string($toppost->subject, true), 'link' => "discuss.php?d=$discussion->id", 'type' => 'title');
@@ -678,7 +702,7 @@
 
     print_header("$course->shortname: $strdiscussionname ".
                   format_string($toppost->subject), $course->fullname,
-                  $navigation, $mform_post->focus($forcefocus), "", true, "", navmenu($course, $cm));
+                  $navigation, $mform_post->focus($forcefocus), $meta, true, "", navmenu($course, $cm));
 
 // checkup
     if (!empty($parent) && !forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
