live section hacks



Hi,

I got a lot farther on the live section work - it now can suck in the
content of a section into a new yarrr live comment when you click edit.

But then ran into what Brion was talking about (now I understand) - we
can't replace the HTML with the live comment as the wiki section isn't
easily mapped to DOM.

I'm attaching the patches I have so far for reference though....if we
can come up with a solution for this (maybe the hack of looking for the
next section edit link), then the last step is to make the "close"
button take the user to the edit page and dump the live comment content
in there.



Index: build.xml
===================================================================
RCS file: /cvs/gnome/yarrr/build.xml,v
retrieving revision 1.27
diff -u -r1.27 build.xml
--- build.xml	14 Jul 2005 21:21:56 -0000	1.27
+++ build.xml	28 Jul 2005 01:08:38 -0000
@@ -82,6 +82,7 @@
 			<fileset dir="${web}" includes="discussion.js"/>
 			<fileset dir="${web}" includes="statement.js"/>
 			<fileset dir="${web}" includes="yarrr.js"/>
+			<fileset dir="${web}" includes="mediawiki.js"/>			
 		</concat>
 	</target>
 	
Index: src/org/gnome/yarrr/Discussion.java
===================================================================
RCS file: /cvs/gnome/yarrr/src/org/gnome/yarrr/Discussion.java,v
retrieving revision 1.25
diff -u -r1.25 Discussion.java
--- src/org/gnome/yarrr/Discussion.java	13 Jun 2005 15:32:43 -0000	1.25
+++ src/org/gnome/yarrr/Discussion.java	28 Jul 2005 01:08:38 -0000
@@ -6,6 +6,7 @@
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
@@ -26,7 +27,7 @@
 	private boolean isDefault;
 	private String title;
 	private Date creationDate;
-	private List /* LiveComment */ comments;
+	private Map /* String,LiveComment */ comments;
     private List /* Whiteboard*/ whiteboards;
 	private Chat chat;
     private ActiveTopic topic;
@@ -37,7 +38,7 @@
 		this.title = title;
 		this.isDefault = false;
 		this.creationDate = new Date();
-		this.comments = new Vector();
+		this.comments = new HashMap();
         this.whiteboards = new Vector();
 		this.chat = new Chat();
         ReferencableObjectRegistry.register(this);
@@ -45,16 +46,20 @@
 	}
 	
     /* Comment-related methods: */
-	public synchronized LiveComment openComment(Person author, String contents) {
-		LiveComment comment = new LiveComment(this, author, contents);
-		this.comments.add(comment);
+	public synchronized LiveComment openComment(Person author, String name, String contents) {
+        LiveComment comment;        
+        comment = (LiveComment) this.comments.get(name);
+        if (comment != null)
+            return comment;
+		comment = new LiveComment(this, author, name, contents);
+		this.comments.put(name, comment);
         topic.addMonitor(comment);
 		signalChanged();
 		return comment;
 	}
 	
 	public synchronized void removeComment(LiveComment comment, Person closer) {
-		assert(this.comments.contains(comment));
+		assert(this.comments.values().contains(comment));
 		this.comments.remove(comment);
         topic.removeMonitor(comment);
         comment.delete();
@@ -62,14 +67,14 @@
 	}
 	
 	protected synchronized void deleteComment(LiveComment comment) {
-		this.comments.remove(comment);
+		this.comments.remove(comment.getName());
         topic.removeMonitor(comment);
 		comment.delete();
 		signalChanged();
 	}
 	
 	public synchronized List /* LiveComment */ getComments() {
-		return new Vector(comments);
+		return new Vector(comments.values());
 	}
     
     /* Whiteboard-related methods: */
@@ -105,7 +110,7 @@
 		table.put("isDefault", new Boolean(this.isDefault));
 		table.put("creator", this.creator.load().toString());
 		table.put("creationDate", this.creationDate);
-		table.put("comments", comments);
+		table.put("comments", this.getComments());
         table.put("whiteboards", whiteboards);        
 	}
 
Index: src/org/gnome/yarrr/LiveComment.java
===================================================================
RCS file: /cvs/gnome/yarrr/src/org/gnome/yarrr/LiveComment.java,v
retrieving revision 1.32
diff -u -r1.32 LiveComment.java
--- src/org/gnome/yarrr/LiveComment.java	13 Jul 2005 14:14:10 -0000	1.32
+++ src/org/gnome/yarrr/LiveComment.java	28 Jul 2005 01:08:38 -0000
@@ -73,10 +73,13 @@
 	private TaggedText contents;
 	
 	LinkedList /* OldVersion */ oldVersions;
+    private String name; /* Separate mapping identifier (other than the reference); used for
+                            wiki embedding */
 	
-	public LiveComment(Discussion discussion, Person opener, String contents) {
+	public LiveComment(Discussion discussion, Person opener, String name, String contents) {
 		this.oldVersions = new LinkedList();
 		this.startTime = new Date();
+        this.name = name;
 		this.authors = new ArrayList();
 		this.struckAuthors = new HashSet();
 		this.opener = opener.getRef();
@@ -240,6 +243,7 @@
 	public synchronized void xmlRpcSerialize(Map map) {
 		super.xmlRpcSerialize(map);
 		map.put("text", contents.getText());
+        map.put("name", name);
         map.put("tags", contents.getTagString());
 		map.put("opener", getOpener().toString());
 		map.put("authors", personCollectionToVector(getAuthors()));
@@ -270,5 +274,9 @@
 
     public Date getStartTime() {
         return this.startTime;
+    }
+
+    public String getName() {
+        return this.name;
     }
 }
Index: src/org/gnome/yarrr/YarrrXmlRpcMethods.java
===================================================================
RCS file: /cvs/gnome/yarrr/src/org/gnome/yarrr/YarrrXmlRpcMethods.java,v
retrieving revision 1.74
diff -u -r1.74 YarrrXmlRpcMethods.java
--- src/org/gnome/yarrr/YarrrXmlRpcMethods.java	12 Jul 2005 14:13:52 -0000	1.74
+++ src/org/gnome/yarrr/YarrrXmlRpcMethods.java	28 Jul 2005 01:08:38 -0000
@@ -96,8 +96,8 @@
 		return topic.addStatement(getCaller(), content);
 	}
 	
-	public LiveComment openLiveComment(Discussion discussion, String contents) {
-		return discussion.openComment(getCaller(), contents);
+	public LiveComment openLiveComment(Discussion discussion, String name, String contents) {
+		return discussion.openComment(getCaller(), name, contents);
 	}
 
 	public boolean deAuthorLiveComment(Discussion discussion, LiveComment comment) {
Index: src/org/gnome/yarrr/log4j.properties
===================================================================
RCS file: /cvs/gnome/yarrr/src/org/gnome/yarrr/log4j.properties,v
retrieving revision 1.8
diff -u -r1.8 log4j.properties
--- src/org/gnome/yarrr/log4j.properties	19 May 2005 10:08:06 -0000	1.8
+++ src/org/gnome/yarrr/log4j.properties	28 Jul 2005 01:08:38 -0000
@@ -5,6 +5,7 @@
 log4j.appender.stdout.layout.ConversionPattern=%x %d{ABSOLUTE} %5p %c{1}:%L - %m%n
 
 log4j.logger.rootLogger=debug,stdout
+log4j.logger.org.gnome.yarrr=debug,stdout
 
 #log4j.logger.org.gnome.yarrr.ReferencableObjectRegistry=info
 #log4j.logger.org.gnome.yarrr.ReferencableObject=debug
@@ -15,8 +16,7 @@
 #log4j.logger.org.gnome.yarrr.ClientPoll=debug
 
 # Make this debug to see xmlrpc calls
-#log4j.logger.org.gnome.yarrr.xmlrpc.XmlRpcHandler=info
-#log4j.logger.org.gnome.yarrr=info, stdout
+log4j.logger.org.gnome.yarrr.xmlrpc.XmlRpcHandler=debug,stdout
 
 #log4j.logger.net.sf.ehcache=warn, stdout
 #log4j.logger.org.hibernate=info, stdout
Index: src/org/gnome/yarrr/tests/YarrrUsingTest.java
===================================================================
RCS file: /cvs/gnome/yarrr/src/org/gnome/yarrr/tests/YarrrUsingTest.java,v
retrieving revision 1.13
diff -u -r1.13 YarrrUsingTest.java
--- src/org/gnome/yarrr/tests/YarrrUsingTest.java	21 Jun 2005 16:02:19 -0000	1.13
+++ src/org/gnome/yarrr/tests/YarrrUsingTest.java	28 Jul 2005 01:08:39 -0000
@@ -127,7 +127,7 @@
 
     protected LiveComment getLiveComment() {
         Discussion d = getDefaultDiscussion();
-        return d.openComment(this.getYarrr().getTheCapn(), "");
+        return d.openComment(this.getYarrr().getTheCapn(), "", "");
     }
 
     protected ClosedComment getClosedComment() throws Exception {
Index: web/comment.js
===================================================================
RCS file: /cvs/gnome/yarrr/web/comment.js,v
retrieving revision 1.44
diff -u -r1.44 comment.js
--- web/comment.js	20 Jul 2005 18:38:24 -0000	1.44
+++ web/comment.js	28 Jul 2005 01:08:39 -0000
@@ -1,5 +1,4 @@
 function Comment(id, container) {
-  this.id = id;
   this.editedTimeoutObj = null;
 
   this.callActive = false;
@@ -8,6 +7,8 @@
   
   this.sendingVersion = undefined;
   this.sendingText = "";
+  
+  this.name = "";
 
   // We know the initial version is always 0, and its empty
   this.oldVersion = 0;
@@ -64,15 +65,12 @@
   this.closebutton.onclick = function() { comment.close(); return false; };
   this.cancelbutton.onclick = function() { comment.cancel(); return false; };
 
-  var precached = stealPrecachedReferencableObject(this.id)
-  if (precached != null)
-    this.sync(precached)
-  else 
-    this.update()
+  Comment.superclass.init.call(this, id)
 }
 
 Comment.prototype = new ReferencableObject();
 Comment.prototype.constructor = Comment;
+Comment.superclass = ReferencableObject.prototype;
 
 // Signal
 Comment.prototype.oncancel = function () { }
@@ -262,6 +260,9 @@
   }
   if (mycolor != -1)
     this.editor.setIgnoreColor(mycolor);
+  
+  if ("name" in content)
+    this.name = content.name;
     
   var diff = diff_tagged_strings(this.editor.getLastText(), this.editor.getLastColors(), content.text, content.tags)
   this.gotNewVersion(content.version, diff, null);
Index: web/discussion.js
===================================================================
RCS file: /cvs/gnome/yarrr/web/discussion.js,v
retrieving revision 1.6
diff -u -r1.6 discussion.js
--- web/discussion.js	26 Jul 2005 22:32:29 -0000	1.6
+++ web/discussion.js	28 Jul 2005 01:08:39 -0000
@@ -1,5 +1,14 @@
 function Discussion(id, topic) {
-  this.id = id;
+  if (arguments.length > 0) {
+    this.init(id, topic) 
+  }
+}
+  
+Discussion.prototype = new ReferencableObject();
+Discussion.prototype.constructor = Discussion
+Discussion.superclass = ReferencableObject.prototype;
+
+Discussion.prototype.init = function (id, topic) {
   this.livecomments = {};
   this.whiteboards = {};
   this.chat = null;
@@ -13,7 +22,7 @@
   var discussions = window.document.getElementById("discussions");
   var elt = document.createElement("div")
   this.topdiv = elt
-  elt.setAttribute("id", this.id)
+  elt.setAttribute("id", id)
   elt.setAttribute("class", "discussion")
   discussions.appendChild(elt)
   
@@ -50,12 +59,13 @@
   // Add number of open comments
   span = document.createElement("span");
   span.setAttribute("class", "discussionTitleInfo");
+  span.appendChild(document.createTextNode(", "))
   discussiondiv.appendChild(span)
+  this.summary_span = document.createElement("span")
+  this.summary_span.setAttribute("class", "discussionTitleSummary")
+  discussiondiv.appendChild(this.summary_span);
 
-  // Create "Open Comment" button
-  this.closedCommentButton = document.createElement("form");
-  this.closedCommentButton.setAttribute("class", "closedcommentbutton")
-  discussiondiv.appendChild(this.closedCommentButton)
+  this.initOpenComment(discussiondiv);
   
   // Create title form
   this.title_form_div = document.createElement("div")
@@ -137,14 +147,23 @@
   this.expanded = true; // Will be inverted by expand
   this.expand();
   
-  var precached = stealPrecachedReferencableObject(this.id)
-  if (precached != null)
-    this.sync(precached)
-  else
-    this.update();
+  Discussion.superclass.init.call(this, id)
 }
 
-Discussion.prototype = new ReferencableObject();
+Discussion.prototype.initOpenComment = function (discussiondiv) {
+  // Create "Open Comment" button
+  this.closedCommentButton = document.createElement("form");
+  this.closedCommentButton.setAttribute("class", "closedcommentbutton")
+  var input = document.createElement("input");
+  input.setAttribute("type", "button");
+  input.setAttribute("value", "New Comment");
+  if (getYarrrPerson().isAnonymous()) {
+    input.setAttribute("disabled", "true")
+  }
+  input.addEventListener("click", function (e) { discussion.openComment(""); e.stopPropagation(); return false; }, false);
+  this.closedCommentButton.appendChild(input);
+  discussiondiv.appendChild(this.closedCommentButton)
+}
 
 Discussion.prototype.getTopic = function () {
   return this.topic;
@@ -163,11 +182,15 @@
   if (this.expanded) {
     this.expander.src = getYarrrURL("images/expanded.png");
     expandee.style.display = "block";
-    this.closedCommentButton.style.display = "inline";
+    if (this.closedCommentButton) {
+      this.closedCommentButton.style.display = "inline";
+    }
     this.notebook.show ();
   } else {
     this.expander.src = getYarrrURL("images/collapsed.png");
-    this.closedCommentButton.style.display = "none";
+    if (this.closedCommentButton) {
+      this.closedCommentButton.style.display = "none";
+    }
     expandee.style.display = "none";
     this.notebook.hide ();
   }
@@ -176,7 +199,7 @@
 Discussion.prototype.openComment = function (contents) {
   var discussion = this;
   setTimeout(function () {
-    yarrr.openLiveComment(discussion.id, contents, function (result, err) {
+    yarrr.openLiveComment(discussion.id, "", contents, function (result, err) {
       if (err) { errorLog.reportError('openLiveComment failed: ' + err); return; }
       discussion.openedCommentId = result;
     });
@@ -193,6 +216,11 @@
 Discussion.prototype.onCommentClose = function(commentid) {
 }
 
+Discussion.prototype.createComment = function (commentId)
+{
+  return new Comment(commentId, this.comments_div);
+}
+
 Discussion.prototype.sync = function(contents) {
   var discussion = this;
   if (this.chat == null && ('chat' in contents)) {
@@ -206,7 +234,7 @@
     var commentid = comments[i];
     commentsdict[commentid] = true;
     if (! (commentid in this.livecomments)) {
-      this.livecomments[commentid] = new Comment(commentid, this.comments_div);
+      this.livecomments[commentid] = this.createComment(commentid)
       var comment = this.livecomments[commentid]
       if (this.openedCommentId == commentid) {
         this.livecomments[commentid].focus()
@@ -265,7 +293,14 @@
       this.creator_div.style.display = "inline";
     }
   }
-
+  
+  this.summary_span.innerHTML = "";
+  var len = 0;
+  for (var comment in this.livecomments) {
+    len++;
+  }
+  this.summary_span.appendChild(document.createTextNode("" + len + " open comments"));
+  
   if (!this.initialized && !this.expanded && contents.isDefault) {
     this.expand()
   }
@@ -284,4 +319,50 @@
   errorLog.reportEvent("discussion::createWhiteboard (button pressed)");
   var discussion = this;
   yarrr.createWhiteboard(this.id, function (res, err) { discussion.openedWhiteboardId = res; });
+}
+
+function EmbeddedDiscussion(id, topic) {
+  EmbeddedDiscussion.superclass.init.call(this, id, topic)
+}
+
+EmbeddedDiscussion.prototype = new Discussion()
+EmbeddedDiscussion.prototype.constructor = EmbeddedDiscussion
+EmbeddedDiscussion.superclass = Discussion.prototype;
+
+EmbeddedDiscussion.prototype.createComment = function (commentId) {
+  var dummy_div = document.createElement("div")
+  
+  alert("creating comment" + commentId)  
+  var comment = new Comment(commentId, dummy_div);
+  var discussion = this;
+
+
+  comment.addInitHook(function () {
+    alert("initializing comment " + comment + " (" +comment.name + ")")
+    var sections = document.getElementsByName(comment.name)
+    if (sections.length != 1) {
+      errorLog.reportError("invalid number of sections with name \"" + comment.name + "\" (" + sections.length + ")");
+      return;
+    }
+    var section = sections[0]
+    var parent = section.parentNode
+    /* Take out the wiki section, replace it with live comment */
+    parent.replaceChild(dummy_div, section)
+  })
+  return comment;
+}
+
+EmbeddedDiscussion.prototype.openNamedComment = function (name, contents) {
+  var discussion = this;
+  /* TODO - why do we have this timeout?  */
+  setTimeout(function () {
+    yarrr.openLiveComment(discussion.id, name, contents, function (result, err) {
+      if (err) { errorLog.reportError('openLiveComment failed: ' + err); return; }
+      discussion.openedCommentId = result;
+    });
+  }, 10);
+}
+
+EmbeddedDiscussion.prototype.initOpenComment = function (discussiondiv) {
+ /* Override */
 }
Index: web/error-logger.js
===================================================================
RCS file: /cvs/gnome/yarrr/web/error-logger.js,v
retrieving revision 1.7
diff -u -r1.7 error-logger.js
--- web/error-logger.js	21 Mar 2005 20:03:04 -0000	1.7
+++ web/error-logger.js	28 Jul 2005 01:08:39 -0000
@@ -1,47 +1,57 @@
-
 function ErrorLogger(title, varname) {
   this.title = title;
   this.varname = varname;
   this.showErrorLog = false;
   this.debugWindow = null;
-  this.html = "<html><head><title>" + this.title + "</title>";
-  this.html += "<link rel=\"stylesheet\" href=\"stylesheets/error-logger.css\"/></head>";
-  this.html += "<body onload=\"" + varname + ".initlog();\">";
-  this.html += "<form name=\"ErrorLoggerClose\"><input type=\"button\" value=\"Close Window\" onclick=\"window.opener." + varname + ".hide();\"/></form><br/>";
-  this.html += "<form name=\"debug\"><input type=\"button\" value=\"Clear Log\" onclick=\"window.opener." + varname + ".clear();\"/><br/></form>";
-  this.html += "<div id=\"ErrorLoggerDebugLog\"></div></body></html>";
-  this.debugHTML = "";
+  this.autoshow = false
+  this.log = null
+  this.logEntries = []
+}
+
+function LogEntry(type, klass, text) {
+  this.type = type
+  this.date = new Date()
+  this.klass = klass
+  this.text = text
+}
+
+ErrorLogger.prototype.enableAutoShow = function () {
+  this.autoshow = true;
 }
 
 // Private
 ErrorLogger.prototype.isActive = function() {
-  return (this.debugWindow != null) && (!this.debugWindow.closed);
+  return (this.debugWindow) && (!this.debugWindow.closed);
 }
 
 ErrorLogger.prototype.show = function() {
   try {
     if (!this.isActive()) {
       this.debugWindow = window.open();
-      this.debugWindow.document.write(this.html);
+      var html = this.debugWindow.document.documentElement
+	  this.debugWindow.document.title = this.title
+	  var body = this.debugWindow.document.body
+	  var errorlog = this
+	  var div = this.debugWindow.document.createElement("div")
+	  this.log = div
+	  div.setAttribute("id", "ErrorLoggerDebugLog")
+	  body.appendChild(div)
+      var i;
+      for (i = 0; i < this.logEntries.length; i++) {
+        this.appendLogEntry(this.logEntries[i])
+      } 
+      this.logEntries = null	  
     }
   } catch (e) {
     alert(e);
   }
 }
 
-ErrorLogger.prototype.initlog = function() {
-  try {
-    var log = this.debugWindow.document.getElementById("ErrorLoggerDebugLog");
-    log.innerHTML = this.debugHTML;
-  } catch (e) {
-    alert (e);
-  }
-}
-
 ErrorLogger.prototype.hide = function() {
   try {
     if (this.debugWindow != null) {
       this.debugWindow.close();
+      this.debugWindow = null
     }
   } catch (e) {
     alert(e);
@@ -49,27 +59,49 @@
 }
 
 // Private
-ErrorLogger.prototype.append = function(text) {
-  this.debugHTML += text;
-  if (this.isActive()) {
-    var log = this.debugWindow.document.getElementById("ErrorLoggerDebugLog");
-    log.innerHTML += text;
+ErrorLogger.prototype.append = function(klass, header, text) {
+  var entry = new LogEntry(header, klass, text)
+  if (this.debugWindow) {
+    this.appendLogEntry(entry, null)    
+  } else {
+     this.logEntries.push(entry)
   }
 }
 
+ErrorLogger.prototype.appendLogEntry = function (entry) {
+  var logEntry = this.debugWindow.document.createElement("p")
+  var span = this.debugWindow.document.createElement("span")  
+  logEntry.appendChild(span)
+  if (entry.klass == "ErrorLoggerError") {
+    span.style.color = "red";
+    span.style.fontWeight = "bolder";
+  }
+  span.style.fontSize = "larger";  
+  span.appendChild(this.debugWindow.document.createTextNode(entry.type))
+  span = this.debugWindow.document.createElement("span")
+  span.style.marginLeft = "1em";
+  span.appendChild(this.debugWindow.document.createTextNode(entry.text))
+  logEntry.appendChild(span)  
+  logEntry.appendChild(this.debugWindow.document.createElement("br"))
+  span = this.debugWindow.document.createElement("span")
+  span.style.fontSize = "smaller";
+  span.style.color = "gray";
+  span.appendChild(this.debugWindow.document.createTextNode(new Date()))
+  logEntry.appendChild(span)
+  this.log.appendChild(logEntry)
+  this.log.appendChild(this.debugWindow.document.createElement("hr"))  
+}
+
 ErrorLogger.prototype.clear = function() {
   this.debugHTML = "";
   if (this.isActive()) {
-    var log = this.debugWindow.document.getElementById("ErrorLoggerDebugLog");
-    log.innerHTML = this.debugHTML;
+    this.log.innerHTML = "";
   }
 }   
 
 ErrorLogger.prototype.reportEvent = function(details) {
   try {
-    this.append("<p><span class=\"ErrorLoggerEvent\">Event (at " + new Date() + "):</span><pre>");
-    this.append(details);
-    this.append("</pre></p>");
+    this.append("ErrorLoggerEvent", "Event", details)
   } catch (e) {
     alert(e);
   }
@@ -77,9 +109,12 @@
 
 ErrorLogger.prototype.reportError = function(text) {
   try {
-    this.append("<p><span class=\"ErrorLoggerError\">Error (at " + new Date() + "):</span><br/><pre>");
-    this.append(text);
-    this.append("</pre></p>");
+    this.haveError = true;  
+    this.append("ErrorLoggerError", "Error", text)
+    if (this.autoshow) {
+      this.autoshow = false
+      this.show();
+    }
   } catch (e) {
     alert(e);
   }
Index: web/referencableobject.js
===================================================================
RCS file: /cvs/gnome/yarrr/web/referencableobject.js,v
retrieving revision 1.44
diff -u -r1.44 referencableobject.js
--- web/referencableobject.js	19 Jul 2005 19:39:47 -0000	1.44
+++ web/referencableobject.js	28 Jul 2005 01:08:40 -0000
@@ -1,4 +1,6 @@
 var errorLog = new ErrorLogger("Yarrr Debug Log", "errorLog");
+window.addEventListener("unload", function (e) { errorLog.hide(); return true; }, false);
+
 var xmlrpc = importModule("xmlrpc");
 var yarrr = null;
 var yarrrMethods = ["dumpObjects",
@@ -76,10 +78,45 @@
 function ReferencableObject() {
 }
 
+ReferencableObject.prototype.init = function (id) {
+  if (arguments.length == 0)
+    return;
+  this.id = id
+  this.inithooks = []
+  this.didInit = false    
+  var precached = stealPrecachedReferencableObject(this.id)
+  if (precached != null)
+    this.doSync(precached)
+  else
+    this.update();
+}
+
 ReferencableObject.prototype.getId = function () {
   return this.id;
 }
 
+ReferencableObject.prototype.addInitHook = function (func) {
+  if (this.didInit) {
+    errorLog.reportEvent("object " + this + " already initialized, invoking init callback immediately")    
+    func.call()
+  } else {
+    this.inithooks.push(func)
+  }
+}
+
+ReferencableObject.prototype.doSync = function (contents) {
+  this.sync(contents);
+  errorLog.reportEvent("synchronizing object: " + this)
+  if (!this.didInit) {
+    errorLog.reportEvent("calling init hooks for object: " + this)  
+    for (i = 0; i < this.inithooks.length; i++) {
+      this.inithooks[i].call()
+    }
+    this.inithooks = null
+    this.didInit = true    
+  }
+}
+
 ReferencableObject.prototype.dumpObjectsResult = function (result, err) {
   if (err) {
     errorLog.reportError('dumpObjects failed: ' + err);
@@ -91,7 +128,8 @@
     if (contents == "UnknownReferenceException")
       return;
     errorLog.reportEvent("dumpObjects returned" + result + ", " + err);
-    this.sync(result[0]);
+    this.doSync(result[0]);
+
   } catch (e) {
     errorLog.reportError('Synchronization of object ' + this.getId() + ' failed: ' + e);
   }
Index: web/topic.js
===================================================================
RCS file: /cvs/gnome/yarrr/web/topic.js,v
retrieving revision 1.131
diff -u -r1.131 topic.js
--- web/topic.js	26 Jul 2005 10:31:44 -0000	1.131
+++ web/topic.js	28 Jul 2005 01:08:40 -0000
@@ -9,24 +9,24 @@
     } 
 }
 
-function BaseTopic () {
+function BaseTopic (id, onUnread) {
+  if (arguments.length == 0)
+    return;
+  this.init(id, onUnread)
 }
 
 BaseTopic.prototype = new ReferencableObject();
+BaseTopic.prototype.constructor = BaseTopic;
+BaseTopic.superclass = ReferencableObject.prototype;
 
 BaseTopic.prototype.init = function (id, onUnread) {
-  this.id = id;
   this.onUnread = onUnread
   this.closedcomments = {};
   this.updateVersion = null;
   
   this.peopleElt = window.document.getElementById("peoplePlaceholder")
  
-  var precached = stealPrecachedReferencableObject(this.id)
-  if (precached != null)
-    this.sync(precached)
-  else
-    this.update();
+  BaseTopic.superclass.init.call(this, id)
 }
 
 BaseTopic.prototype.setPresentPersons = function (persons) {
@@ -78,15 +78,16 @@
   for (var i = 0; i < content.discussions.length; i++) {
     var id = content.discussions[i];
     if (!(id in this.discussions)) {
-      this.discussions[id] = new Discussion(id, this);
+      this.discussions[id] = new EmbeddedDiscussion(id, this);
       var discussion = this.discussions[id]
       registerObject(discussion)
       discussion.onCommentClose = function (commentid) {
-      	yarrr.closeLiveComment(topic.getId(), discussion.getId(), commentid, function (result, err) {});
+      	alert("comment closed");
       } 
     }
   }
   
+  /*
   for (var i = 0; i < content.closed.length; i++) {
     var id = content.closed[i];
     if (!(id in this.closedcomments)) {
@@ -97,6 +98,7 @@
       }
     }
   }
+  */
 }
 
 Topic.prototype = new BaseTopic();
Index: web/wikiembed.jsp
===================================================================
RCS file: /cvs/gnome/yarrr/web/wikiembed.jsp,v
retrieving revision 1.7
diff -u -r1.7 wikiembed.jsp
--- web/wikiembed.jsp	26 Jul 2005 10:31:44 -0000	1.7
+++ web/wikiembed.jsp	28 Jul 2005 01:08:40 -0000
@@ -1,88 +1,35 @@
-function createYarrrWikiArticleURI() {
-  return wikiArticlePath + "?title=" + ${JStopictitle};
-}
-
-function createYarrrWikiURI(page) {
-  return wikiArticlePath + "?title=" + page;
-}
-
-function createYarrrWikiLink(page, text) {
-  var a = document.createElement("a")
-  a.setAttribute("href", createYarrrWikiURI(page))
-  a.appendChild(document.createTextNode("login"))
-  return a;
-}
-
-function updateWikiContent() {
-  var urllib = importModule("urllib");
-  urllib.getURL(createYarrrWikiArticleURI() + "&live=true", null, null, null,
-  				function (request) {
-  				  var articleContent = document.getElementById("articleContent");
-  				  articleContent.innerHTML = request.responseText;
-  				   
-  				  // FIXME this is broken, because it will initialize more
-  				  // than it should. No point in fixing it now though, since
-  				  // we are going to move the chat outside the content.
-  				  yarrrInit();
-  				});
-}
+yarrrWikiHeaderText = ${headertext}
+yarrrWikiTitle = ${JStopictitle}
 
 function yarrrFullInit(rootobj) {
+  errorLog.reportEvent("starting yarrrFullInit")
+  // Hack
+  if (wikiYarrrXmlRpcURL.search(/localhost/) >= 0) {
+    errorLog.enableAutoShow();
+  }
+ 
   theTopic = new EmbeddedTopic(rootobj)
   registerObject(theTopic);
-  if (getYarrrPerson().isAnonymous()) {
-    var wikiHeader = document.getElementById("yarrrWikiHeader");
-    if (wikiHeader) {
-      var div = document.createElement("div")
-      div.setAttribute("class", "yarrrLoginNotification")
-      div.appendChild(document.createTextNode("You must "))
-      div.appendChild(createYarrrWikiLink("Special:Userlogin&returnto=" + ${JStopictitle}, "login"))
-      div.appendChild(document.createTextNode(" to use the discussion."))
-      wikiHeader.appendChild(div)
-    }
-  }
-  
-  // Override mediawiki's logout link
-  var logoutLi = document.getElementById("pt-logout");
-  if (logoutLi) {
-    logoutLi.addEventListener("click", function (e) { 
-                                         e.preventDefault();
-                                         e.stopPropagation();
-                                         try {
-                                           yarrr.logout(function (result, err) { 
-                                               if (err) { errorLog.reportError(err); alert('logout failed: ' + err); return; }; 
-                                               document.location = createYarrrWikiURI("Special:Userlogout&returnto=" + ${JStopictitle});
-                                             });
-                                         } catch (e) {
-                                           errorLog.reportError(e);
-                                           alert('failed to invoke logout: '+e);
-                                         }
-                                         return true;
-                                        }, false);
-  }  
+
+  errorLog.reportEvent("calling yarrrWikiInit")
+  yarrrWikiInit(rootobj)
+  errorLog.reportEvent("adding init hook") 
+  theTopic.addInitHook(function () { yarrrWikiFullInit(theTopic); })  
 }
 
 function yarrrInit() {
+  try {
   setWidgetImageDir(wikiYarrrRoot + "images/");
   
-  /* Add the notification area */
-  var bodyContent = document.getElementById("content")
-  if (bodyContent) {
-    var elt = document.createElement("div")
-    elt.setAttribute("id", "yarrrNotificationArea")
-    bodyContent.insertBefore(elt, bodyContent.firstChild)
-  }
-  
-  var wikiHeader = document.getElementById("yarrrWikiHeader");
-  if (wikiHeader) {
-    var h1 = document.createElement("h1")
-    h1.appendChild(document.createTextNode(${headertext}))
-    wikiHeader.appendChild(h1)
-  }
+  yarrrWikiPreInit();
 
   var rootobj = "${topicid}"
+  errorLog.reportEvent("starting yarrrInitFull")  
   yarrrInitFull("${anonymousPerson}", "${person}", rootobj, "${clientInstanceId}", 
                 ${referencableObjectPreCache}, wikiYarrrRoot, wikiYarrrXmlRpcURL, yarrrFullInit)
+  } catch (e) {
+    errorLog.reportError(e);
+  }
 }
  
 if (window.addEventListener) window.addEventListener("load",yarrrInit,false); 
Index: web/mediawiki.js
===================================================================
RCS file: web/mediawiki.js
diff -N web/mediawiki.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ web/mediawiki.js	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,129 @@
+function createYarrrWikiURI(page) {
+  return wikiArticlePath + "?title=" + page;
+}
+
+function createYarrrWikiLink(page, text) {
+  var a = document.createElement("a")
+  a.setAttribute("href", createYarrrWikiURI(page))
+  a.appendChild(document.createTextNode("login"))
+  return a;
+}
+
+function updateWikiContent() {
+  var urllib = importModule("urllib");
+  urllib.getURL(createYarrrWikiArticleURI() + "&live=true", null, null, null,
+  				function (request) {
+  				  var articleContent = document.getElementById("articleContent");
+  				  articleContent.innerHTML = request.responseText;
+  				   
+  				  // FIXME this is broken, because it will initialize more
+  				  // than it should. No point in fixing it now though, since
+  				  // we are going to move the chat outside the content.
+  				  yarrrInit();
+  				});
+}
+
+function yarrrWikiPreInit () {
+  errorLog.reportEvent("yarrrWikPreiInit")
+  /* Add the notification area */
+  var bodyContent = document.getElementById("content")
+  if (bodyContent) {
+    var elt = document.createElement("div")
+    elt.setAttribute("id", "yarrrNotificationArea")
+    bodyContent.insertBefore(elt, bodyContent.firstChild)
+  }
+  
+  var wikiHeader = document.getElementById("yarrrWikiHeader");
+  if (wikiHeader) {
+    var h1 = document.createElement("h1")
+    h1.appendChild(document.createTextNode(yarrrWikiHeaderText))
+    wikiHeader.appendChild(h1)
+  }
+  errorLog.reportEvent("yarrrWikPreiInit finished")  
+}
+
+function yarrrWikiInit (rootobj) {
+ errorLog.reportEvent("yarrrWikiInit")
+ if (getYarrrPerson().isAnonymous()) {
+    var wikiHeader = document.getElementById("yarrrWikiHeader");
+    if (wikiHeader) {
+      var div = document.createElement("div")
+      div.setAttribute("class", "yarrrLoginNotification")
+      div.appendChild(document.createTextNode("You must "))
+      div.appendChild(createYarrrWikiLink("Special:Userlogin&returnto=" + yarrrWikiTitle, "login"))
+      div.appendChild(document.createTextNode(" to use the discussion."))
+      wikiHeader.appendChild(div)
+    }
+  }
+  
+  // Override mediawiki's logout link
+  var logoutLi = document.getElementById("pt-logout");
+  if (logoutLi) {
+    logoutLi.addEventListener("click", function (e) { 
+                                         e.preventDefault();
+                                         e.stopPropagation();
+                                         try {
+                                           yarrr.logout(function (result, err) { 
+                                               if (err) { errorLog.reportError(err); alert('logout failed: ' + err); return; }; 
+                                               document.location = createYarrrWikiURI("Special:Userlogout&returnto=" + yarrrWikiTitle);
+                                             });
+                                         } catch (e) {
+                                           errorLog.reportError(e);
+                                           alert('failed to invoke logout: '+e);
+                                         }
+                                         return true;
+                                        }, false);
+  }
+ errorLog.reportEvent("yarrrWikiInit finished")  
+}
+
+function yarrrWikiFullInit (topic) {
+  errorLog.reportEvent("yarrrWikiFullInit") 
+  var discussions = getObjectKeys(topic.discussions)
+  if (discussions.length != 1) {
+    errorLog.reportError("invalid number of discussions: " + discussions.length);
+    return;
+  }
+  var discussion = topic.discussions[discussions[0]]
+  var i;
+  var editsectionnum = 1;
+  var editsectionname;
+  var divs = document.getElementsByTagName("div")
+  for (i = 0; i < divs.length; i++) {
+    var div = divs[i]  
+    if (div.getAttribute("class") == "editsection") {
+      var links = div.getElementsByTagName("a")
+      var j;
+      for (j = 0; j < links.length; j++) {
+        var link = links[j]
+        if (link.getAttribute("title") == yarrrWikiTitle) {
+          var newlink = link.getAttribute("href").replace(/&action=edit/g, "&action=view&sectsource=true")
+          link.setAttribute("href", newlink)
+        } 
+      }
+      // This is pretty evil.
+      if (typeof yarrrSubmitSection != 'undefined' && !editsectionname && yarrrSubmitSection == editsectionnum) {
+        var anchor = div.nextSibling
+        while (anchor && anchor.tagName != "A") {
+          anchor = anchor.nextSibling
+        }
+        if (!anchor || !anchor.getAttribute("name")) {
+          errorLog.reportError("couldn't find section anchor!");
+        }
+        editsectionname = anchor.getAttribute("name")
+      }      
+      editsectionnum++
+    }
+  }
+  if (editsectionname) {
+    var wikitext = ''
+    var sectsource = document.getElementById("yarrrSectionSource")
+    if (!sectsource) {
+      errorLog.reportError("Couldn't find yarrrSectionSource");
+    }
+    var wikitext = sectsource.firstChild.nodeValue
+    alert("opening comment for " + editsectionname + "with content: " + wikitext)    
+    discussion.openNamedComment(editsectionname, wikitext)
+  }
+  errorLog.reportEvent("yarrrWikiFullInit finished")   
+}
--- includes/Article.php~	2005-04-26 07:39:39.000000000 -0400
+++ includes/Article.php	2005-07-27 21:02:36.000000000 -0400
@@ -697,6 +697,7 @@
 		$diff = $wgRequest->getVal( 'diff' );
 		$rcid = $wgRequest->getVal( 'rcid' );
 		$rdfrom = $wgRequest->getVal( 'rdfrom' );
+		$sectsource = $wgRequest->getVal( 'sectsource' );
 
 		$wgOut->setArticleFlag( true );
 		$wgOut->setRobotpolicy( 'index,follow' );
@@ -728,7 +729,7 @@
 			}
 		}
 		# Should the parser cache be used?
-		if ( $wgEnableParserCache && intval($wgUser->getOption( 'stubthreshold' )) == 0 && empty( $oldid ) ) {
+		if ( $wgEnableParserCache && intval($wgUser->getOption( 'stubthreshold' )) == 0 && empty( $oldid ) && !$sectsource) {
 			$pcache = true;
 		} else {
 			$pcache = false;
@@ -810,6 +811,16 @@
 					'action=markpatrolled&rcid='.$rcid )
 			 ) );
 		}
+		if ($sectsource) {
+			$section = $wgRequest->getVal( 'section' );
+			if ($section && preg_match("/^\\d+$/", $section)) {
+				$wikitext = $this->getSection($this->mContent, $section);
+				$wgOut->addHTML("<script type=\"text/javascript\">yarrrSubmitSection = $section;</script>");
+				$wgOut->addHTML("<div id=\"yarrrSectionSource\" style=\"display: none\">");
+				$wgOut->addHTML(htmlspecialchars ($wikitext));
+				$wgOut->addHTML("</div>");
+			}
+		}
 
 		# Put link titles into the link cache
 		$wgOut->transformBuffer();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]