You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2009/10/11 06:51:38 UTC

svn commit: r824021 - in /incubator/jspwiki/trunk/src: WebContent/ WebContent/templates/default/ WebContent/templates/default/editors/ java/org/apache/wiki/action/

Author: ajaquith
Date: Sun Oct 11 04:51:38 2009
New Revision: 824021

URL: http://svn.apache.org/viewvc?rev=824021&view=rev
Log:
Comment.jsp receives the Stripes treatment (initial checkin; not fully tested yet).

Modified:
    incubator/jspwiki/trunk/src/WebContent/Comment.jsp
    incubator/jspwiki/trunk/src/WebContent/templates/default/CommentContent.jsp
    incubator/jspwiki/trunk/src/WebContent/templates/default/editors/FCK.jsp
    incubator/jspwiki/trunk/src/WebContent/templates/default/editors/plain.jsp
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditActionBean.java

Modified: incubator/jspwiki/trunk/src/WebContent/Comment.jsp
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/Comment.jsp?rev=824021&r1=824020&r2=824021&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/Comment.jsp (original)
+++ incubator/jspwiki/trunk/src/WebContent/Comment.jsp Sun Oct 11 04:51:38 2009
@@ -18,307 +18,31 @@
     specific language governing permissions and limitations
     under the License.  
 --%>
-<%@ page import="org.apache.wiki.log.Logger" %>
-<%@ page import="org.apache.wiki.log.LoggerFactory" %>
-<%@ page import="org.apache.wiki.*" %>
-<%@ page import="org.apache.wiki.content.lock.PageLock" %>
-<%@ page import="org.apache.wiki.filters.*" %>
-<%@ page import="java.util.*" %>
-<%@ page import="java.text.SimpleDateFormat" %>
-<%@ page import="org.apache.wiki.htmltowiki.HtmlStringToWikiTranslator" %>
-<%@ page import="org.apache.wiki.ui.EditorManager" %>
-<%@ page import="org.apache.wiki.util.HttpUtil" %>
-<%@ page import="org.apache.wiki.preferences.Preferences" %>
-<%@ page import="org.apache.wiki.auth.login.CookieAssertionLoginModule" %>
-<%@ page import="org.apache.wiki.workflow.DecisionRequiredException" %>
-<%@ page import="org.apache.wiki.preferences.Preferences.TimeFormat" %>
-<%@ page errorPage="/Error.jsp" %>
-<%@ page import="javax.servlet.http.Cookie" %>
-<%@ taglib uri="http://jakarta.apache.org/jspwiki.tld" prefix="wiki" %>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
-<%@ page import="javax.servlet.jsp.jstl.fmt.*" %>
+<%@ taglib uri="http://jakarta.apache.org/jspwiki.tld" prefix="wiki" %>
 <%@ taglib uri="http://stripes.sourceforge.net/stripes.tld" prefix="s" %>
-<%@ page import="org.apache.wiki.util.TextUtil" %>
-<%@ page import="org.apache.wiki.api.WikiPage" %>
-<s:useActionBean beanclass="org.apache.wiki.action.EditActionBean" event="comment" id="wikiActionBean" />
-<s:layout-component name="headTitle">
-  <fmt:message key="comment.title.comment">
-    <fmt:param><wiki:Variable var="ApplicationName" /></fmt:param>
-    <fmt:param><wiki:PageName/></fmt:param>
-  </fmt:message>
-</s:layout-component>
-<%!
-    Logger log = LoggerFactory.getLogger("JSPWiki");
-
-	String findParam( PageContext ctx, String key )
-	{
-	    ServletRequest req = ctx.getRequest();
-	
-	    String val = req.getParameter( key );
-	
-	    if( val == null )
-	    {
-	        val = (String)ctx.findAttribute( key );
-	    }
-	
-	    return val;
-	}
-%>
-
-<%
-    WikiEngine wiki = WikiEngine.getInstance( getServletConfig() );
-    // Create wiki context and check for authorization
-    WikiContext wikiContext = wiki.createContext( request, WikiContext.COMMENT );
-    String pagereq = wikiContext.getPage().getName();
-
-    ResourceBundle rb = wikiContext.getBundle("CoreResources");
-    WikiSession wikiSession = wikiContext.getWikiSession();
-    String storedUser = wikiSession.getUserPrincipal().getName();
-
-    if( wikiSession.isAnonymous() )
-    {
-        storedUser  = TextUtil.replaceEntities( request.getParameter( "author" ) );
-    }
-
-    String ok      = request.getParameter("ok");
-    String preview = request.getParameter("preview");
-    String cancel  = request.getParameter("cancel");
-    String author  = TextUtil.replaceEntities( request.getParameter("author") );
-    String link    = TextUtil.replaceEntities( request.getParameter("link") );
-    String remember = request.getParameter("remember");
-    String changenote = TextUtil.replaceEntities( request.getParameter( "changenote" ) );
-
-    WikiPage wikipage = wikiContext.getPage();
-    WikiPage latestversion = wiki.getPage( pagereq );
-
-    session.removeAttribute( EditorManager.REQ_EDITEDTEXT );
-
-    if( latestversion == null )
-    {
-        latestversion = wikiContext.getPage();
-    }
-
-    //
-    //  Setup everything for the editors and possible preview.  We store everything in the
-    //  session.
-    //
-
-    if( remember == null )
-    {
-        remember = (String)session.getAttribute("remember");
-    }
-
-    if( remember == null ) remember = "false";
-
-    session.setAttribute("remember",remember);
-
-    if( author == null )
-    {
-        author = storedUser;
-    }
-    if( author == null || author.length() == 0 ) author = "AnonymousCoward";
-
-    session.setAttribute("author",author);
-
-    if( link == null )
-    {
-        link = HttpUtil.retrieveCookieValue( request, "link" );
-        if( link == null ) link = "";
-    }
-
-    session.setAttribute( "link", link );
-
-    if( changenote != null )
-       session.setAttribute( "changenote", changenote );
-    
-    //
-    //  Branch
-    //
-    log.debug("preview="+preview+", ok="+ok);
-
-    if( ok != null )
-    {
-        log.info("Saving page "+pagereq+". User="+storedUser+", host="+request.getRemoteAddr() );
-
-        //  Modifications are written here before actual saving
-
-        WikiPage modifiedPage = (WikiPage)wikiContext.getPage().clone();
-
-        //  FIXME: I am not entirely sure if the JSP page is the
-        //  best place to check for concurrent changes.  It certainly
-        //  is the best place to show errors, though.
-
-        String spamhash = request.getParameter( SpamFilter.getHashFieldName(request) );
-        
-        if( !SpamFilter.checkHash(wikiContext,pageContext) )
-        {
-            return;
-        }
-        
-        //
-        //  We expire ALL locks at this moment, simply because someone has
-        //  already broken it.
-        //
-        PageLock lock = wiki.getPageManager().getCurrentLock( wikipage );
-        wiki.getPageManager().unlockPage( lock );
-        session.removeAttribute( "lock-"+pagereq );
-
-        //
-        //  Set author and changenote information
-        //
-
-        modifiedPage.setAuthor( storedUser );
-
-        if( changenote != null )
-            modifiedPage.setAttribute( WikiPage.CHANGENOTE, changenote );
-        else
-            modifiedPage.removeAttribute( WikiPage.CHANGENOTE );
-        
-        //
-        //  Build comment part
-        //
-
-        StringBuffer pageText = new StringBuffer(wiki.getPureText( wikipage ));
-
-        log.debug("Page initial contents are "+pageText.length()+" chars");
-
-        //
-        //  Add a line on top only if we need to separate it from the content.
-        //
-        if( pageText.length() > 0 )
-        {
-            pageText.append( "\n\n----\n\n" );
-        }
-        
-        String commentText = EditorManager.getEditedText(pageContext);
-        
-        //
-        //  WYSIWYG editor sends us its greetings
-        //
-        String htmlText = findParam( pageContext, "htmlPageText" );
-        if( htmlText != null && cancel == null )
-        {
-        	commentText = new HtmlStringToWikiTranslator().translate(htmlText,wikiContext);
-        }
-        
-        pageText.append( commentText );
-
-        log.debug("Author name ="+author);
-        if( author != null && author.length() > 0 )
-        {
-            String signature = author;
-
-            if( link != null && link.length() > 0 )
-            {
-                link = HttpUtil.guessValidURI( link );
-
-                signature = "["+author+"|"+link+"]";
-            }
-
-            Calendar cal = Calendar.getInstance();
-            SimpleDateFormat fmt = Preferences.getDateFormat( wikiContext ,  TimeFormat.DATETIME);
-
-            pageText.append("\n\n--"+signature+", "+fmt.format(cal.getTime()));
-
-            //SimpleDateFormat fmt = new SimpleDateFormat( "YYYY-MM-DDThh:mm" ); //ISO-8601 format
-            //pageText.append("\n\n--"+signature+", [{Date value='"+fmt.format(cal.getTime())+"' }]");
-        }
-
-        if( TextUtil.isPositive(remember) )
-        {
-            if( link != null )
-            {
-                Cookie linkcookie = new Cookie("link", link);
-                linkcookie.setMaxAge(1001*24*60*60);
-                response.addCookie( linkcookie );
-            }
-
-            CookieAssertionLoginModule.setUserCookie( response, author );
-        }
-        else
-        {
-            session.removeAttribute("link");
-            session.removeAttribute("author");
-        }
-
-        try
-        {
-            wikiContext.setPage( modifiedPage );
-            wiki.saveText( wikiContext, pageText.toString() );
-        }
-        catch( DecisionRequiredException e )
-        {
-        	String redirect = wikiContext.getURL(WikiContext.VIEW,"ApprovalRequiredForPageChanges");
-            response.sendRedirect( redirect );
-            return;
-        }
-        catch( RedirectException e )
-        {
-            session.setAttribute( VariableManager.VAR_MSG, e.getMessage() );
-            response.sendRedirect( e.getRedirect() );
-            return;
-        }
-        response.sendRedirect(wiki.getViewURL(pagereq));
-        return;
-    }
-    else if( preview != null )
-    {
-        log.debug("Previewing "+pagereq);
-        session.setAttribute(EditorManager.REQ_EDITEDTEXT, EditorManager.getEditedText(pageContext));
-        response.sendRedirect( TextUtil.replaceString( wiki.getURL(WikiContext.PREVIEW, pagereq, "action=comment", false),"&amp;","&") );
-        return;
-    }
-    else if( cancel != null )
-    {
-        log.debug("Cancelled editing "+pagereq);
-        PageLock lock = (PageLock) session.getAttribute( "lock-"+pagereq );
-
-        if( lock != null )
-        {
-            wiki.getPageManager().unlockPage( lock );
-            session.removeAttribute( "lock-"+pagereq );
-        }
-        response.sendRedirect( wiki.getViewURL(pagereq) );
-        return;
-    }
-
-    log.info("Commenting page "+pagereq+". User="+request.getRemoteUser()+", host="+request.getRemoteAddr() );
-
-    //
-    //  Determine and store the date the latest version was changed.  Since
-    //  the newest version is the one that is changed, we need to track
-    //  that instead of the edited version.
-    //
-    long lastchange = 0;
-
-    Date d = latestversion.getLastModified();
-    if( d != null ) lastchange = d.getTime();
-
-    pageContext.setAttribute( "lastchange",
-                              Long.toString( lastchange ),
-                              PageContext.REQUEST_SCOPE );
-
-    //  This is a hack to get the preview to work.
-    // pageContext.setAttribute( "comment", Boolean.TRUE, PageContext.REQUEST_SCOPE );
-
-    //
-    //  Attempt to lock the page.
-    //
-    PageLock lock = wiki.getPageManager().lockPage( wikipage,
-                                                    storedUser );
-
-    if( lock != null )
-    {
-        session.setAttribute( "lock-"+pagereq, lock );
-    }
-
-    // Set the content type and include the response content
-    response.setContentType("text/html; charset="+wiki.getContentEncoding() );
-    response.setHeader( "Cache-control", "max-age=0" );
-    response.setDateHeader( "Expires", new Date().getTime() );
-    response.setDateHeader( "Last-Modified", new Date().getTime() );
-    String contentPage = wiki.getTemplateManager().findJSP( pageContext,
-                                                            wikiContext.getTemplate(),
-                                                            "EditTemplate.jsp" );
+<s:useActionBean beanclass="org.apache.wiki.action.EditActionBean" event="comment" executeResolution="true" id="wikiActionBean" />
+<s:layout-render name="${templates['DefaultLayout.jsp']}">
 
-%><wiki:Include page="<%=contentPage%>" />
+  <%-- Page title should say Comment: + pagename --%>
+  <s:layout-component name="headTitle">
+    <fmt:message key="comment.title.comment">
+      <fmt:param><wiki:Variable var="ApplicationName" /></fmt:param>
+      <fmt:param><wiki:PageName/></fmt:param>
+    </fmt:message>
+  </s:layout-component>
+
+  <!-- Add Javascript for editors -->
+  <s:layout-component name="script">
+    <script type="text/javascript" src="<wiki:Link format='url' jsp='scripts/jspwiki-edit.js' />"></script>
+    <script type="text/javascript" src="<wiki:Link format='url' jsp='scripts/dialog.js' />"></script>
+    <%--
+    <script type="text/javascript" src="<wiki:Link format='url' jsp='scripts/posteditor.js' />"></script>
+    --%>
+  </s:layout-component>
+
+  <s:layout-component name="content">
+    <jsp:include page="${templates['CommentContent.jsp']}" />
+  </s:layout-component>
+  
+</s:layout-render>

Modified: incubator/jspwiki/trunk/src/WebContent/templates/default/CommentContent.jsp
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/templates/default/CommentContent.jsp?rev=824021&r1=824020&r2=824021&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/templates/default/CommentContent.jsp (original)
+++ incubator/jspwiki/trunk/src/WebContent/templates/default/CommentContent.jsp Sun Oct 11 04:51:38 2009
@@ -36,28 +36,22 @@
   </wiki:Tab>
 
   <wiki:Tab id="commentcontent" titleKey="comment.tab.addcomment">
-
-  <wiki:Editor/>
+    <wiki:Editor/>
   </wiki:Tab>
 
-  <wiki:Tab id="attach" title="<%= attTitle %>" accesskey="a">
-    <wiki:Include page="AttachmentTab.jsp" />
-  </wiki:Tab>
+  <wiki:Tab id="attach" title="<%= attTitle %>" accesskey="a" url="Attachments.jsp?page=${wikiActionBean.page.name}" />
   
-  <wiki:Tab id="info" titleKey="info.tab"
-           url="<%=c.getURL(WikiContext.INFO, c.getPage().getName())%>"
-           accesskey="i" >
-  </wiki:Tab>
+  <wiki:Tab id="info" titleKey="info.tab" url="PageInfo.jsp?page=${wikiActionBean.page.name}" accesskey="i" />
     
-  <wiki:Tab id="edithelp" titleKey="edit.tab.help">
+  <wiki:Tab id="edithelp" titleKey="edit.tab.help" accesskey="h">
+    <wiki:InsertPage page="EditPageHelp" />
     <wiki:NoSuchPage page="EditPageHelp">
       <div class="error">
-         <fmt:message key="comment.edithelpmissing">
-            <fmt:param><wiki:EditLink page="EditPageHelp">EditPageHelp</wiki:EditLink></fmt:param>
-         </fmt:message>
+        <fmt:message key="comment.edithelpmissing">
+          <fmt:param><wiki:EditLink page="EditPageHelp">EditPageHelp</wiki:EditLink></fmt:param>
+        </fmt:message>
       </div>
-    </wiki:NoSuchPage>
-
-    <wiki:InsertPage page="EditPageHelp" />
+    </wiki:NoSuchPage>  
   </wiki:Tab>
+
 </wiki:TabbedSection>

Modified: incubator/jspwiki/trunk/src/WebContent/templates/default/editors/FCK.jsp
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/templates/default/editors/FCK.jsp?rev=824021&r1=824020&r2=824021&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/templates/default/editors/FCK.jsp (original)
+++ incubator/jspwiki/trunk/src/WebContent/templates/default/editors/FCK.jsp Sun Oct 11 04:51:38 2009
@@ -51,7 +51,7 @@
     TemplateManager.addResourceRequest( context, "script", "scripts/fckeditor/fckeditor.js" );
  %>   
 <wiki:CheckRequestContext context="edit">
-<wiki:NoSuchPage> <%-- this is a new page, check if we're cloning --%>
+  <wiki:NoSuchPage> <%-- this is a new page, check if we're cloning --%>
 <%
   String clone = request.getParameter( "clone" ); 
   if( clone != null )
@@ -73,7 +73,7 @@
     }
   }
 %>
-</wiki:NoSuchPage>
+  </wiki:NoSuchPage>
 <%
     if( usertext == null )
     {
@@ -106,19 +106,34 @@
        protocol = "https://";
    }   
 %>
+<div style="width:100%"> <%-- Required for IE6 on Windows --%>
 
-<form accept-charset="<wiki:ContentEncoding/>" method="post" 
-      action="<wiki:CheckRequestContext context='edit'><wiki:EditLink format='url'/></wiki:CheckRequestContext><wiki:CheckRequestContext context='comment'><wiki:CommentLink format='url'/></wiki:CheckRequestContext>" 
-      name="editform" id="editform"
-      enctype="application/x-www-form-urlencoded">
-    <p>
-        <%-- Edit.jsp relies on these being found.  So be careful, if you make changes. --%>
-        <input name="page" type="hidden" value="<wiki:Variable var="pagename" />" />
-        <input name="action" type="hidden" value="save" />
-        <input name="<%=SpamFilter.getHashFieldName(request)%>" type="hidden" value="<c:out value='${lastchange}' />" />
+  <%-- Print any messages or validation errors --%>
+  <s:messages />
+  <s:errors />
+
+  <s:form beanclass="org.apache.wiki.action.EditActionBean"
+              class="wikiform"
+                 id="editform"
+             method="post"
+      acceptcharset="UTF-8"
+            enctype="application/x-www-form-urlencoded">
+
+    <%-- If any conflicts, print the conflicting text here --%>
+    <c:if test="${not empty wikiActionBean.conflictText}">
+      <p>
+        <s:label for="conflictText" />
+        <s:textarea name="conflictText" readonly="true" />
+      </p>
+    </c:if>
+    
+    <%-- EditActionBean relies on these being found.  So be careful, if you make changes. --%>
+    <p id="submitbuttons">
+      <s:hidden name="page" />
+      <s:hidden name="startTime" />
     </p>
-<div style="width:100%"> <%-- Required for IE6 on Windows --%>
-<script type="text/javascript">
+    
+    <script type="text/javascript">
 //<![CDATA[
 
    var oFCKeditor = new FCKeditor( 'htmlPageText' );
@@ -135,37 +150,43 @@
    oFCKeditor.Create();
 
 //]]>
-</script>
-
-<noscript>
-  <div class="error"><fmt:message key="editor.fck.noscript" /></div>
-</noscript>
-
-   <p>
-     <label for="changenote"><fmt:message key='editor.plain.changenote' /></label>
-     <input type="text" id="changenote" name="changenote" size="80" maxlength="80" value="<c:out value='${changenote}' />" />
-   </p>
-   <wiki:CheckRequestContext context="comment">
-    <fieldset>
-	<legend><fmt:message key="editor.commentsignature" /></legend>
+    </script>
+    
+    <noscript>
+      <div class="error"><fmt:message key="editor.fck.noscript" /></div>
+    </noscript>
+    
     <p>
-    <label for="authorname" accesskey="n"><fmt:message key="editor.plain.name" /></label>
-    <input type="text" name="author" id="authorname" value="<c:out value='${sessionScope.author}' />" />
-    <input type="checkbox" name="remember" id="rememberme" <%=TextUtil.isPositive((String)session.getAttribute("remember")) ? "checked='checked'" : ""%> />
-    <label for="rememberme"><fmt:message key="editor.plain.remember" /></label>
+      <s:label for="changeNote" />
+      <s:text name="changeNote" size="50" maxlength="80" />
     </p>
-	<%--FIXME: seems not to read the email of the user, but some odd previously cached value --%>
+    
+    <wiki:CheckRequestContext context="comment">
+      <fieldset>
+        <legend><fmt:message key="editor.commentsignature" /></legend>
+        <p><s:label for="author" accesskey="n" />&nbsp;<s:text name="author" /></p>
+        <p><s:label for="email" accesskey="m" />&nbsp;<s:text name="email" size="24" /></p>
+      </fieldset>
+    </wiki:CheckRequestContext>
+    
     <p>
-    <label for="link" accesskey="m"><fmt:message key="editor.plain.email" /></label>
-    <input type="text" name="link" id="link" size="24" value="<c:out value='${sessionScope.link}' />" />
+      <c:set var="saveTitle" scope="page"><fmt:message key="editor.plain.save.title" /></c:set>
+      <wiki:CheckRequestContext context='edit'>
+        <s:submit name="save" accesskey="s" title="${saveTitle}" />
+      </wiki:CheckRequestContext>
+      <wiki:CheckRequestContext context='comment'>
+        <s:submit name="comment" accesskey="s" title="${saveTitle}" />
+      </wiki:CheckRequestContext>
+      
+      <c:set var="previewTitle" scope="page"><fmt:message key="editor.plain.preview.title" /></c:set>
+      <s:submit name="preview" accesskey="v" title="${previewTitle}" />
+      
+      <c:set var="cancelTitle" scope="page"><fmt:message key="editor.plain.cancel.title" /></c:set>
+      <s:submit name="cancel" accesskey="q" title="${cancelTitle}" />
     </p>
-    </fieldset>
-  </wiki:CheckRequestContext>
 
-  <p>
-    <input name='ok' type='submit' value='<fmt:message key="editor.plain.save.submit" />' />
-    <input name='preview' type='submit' value='<fmt:message key="editor.plain.preview.submit" />' />
-    <input name='cancel' type='submit' value='<fmt:message key="editor.plain.cancel.submit" />' />
-  </p>
+    <%-- Spam detection fields --%>
+    <wiki:SpamProtect />
+  </s:form>
+
 </div>
-</form>

Modified: incubator/jspwiki/trunk/src/WebContent/templates/default/editors/plain.jsp
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/templates/default/editors/plain.jsp?rev=824021&r1=824020&r2=824021&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/templates/default/editors/plain.jsp (original)
+++ incubator/jspwiki/trunk/src/WebContent/templates/default/editors/plain.jsp Sun Oct 11 04:51:38 2009
@@ -28,7 +28,8 @@
 --%>
 <div style="width:100%"> <%-- Required for IE6 on Windows --%>
 
-  <%-- Print any validation errors --%>
+  <%-- Print any messages or validation errors --%>
+  <s:messages />
   <s:errors />
 
   <s:form beanclass="org.apache.wiki.action.EditActionBean"
@@ -77,17 +78,16 @@
       </tr>
 
       <wiki:CheckRequestContext context="comment">
-      <tr>
-        <td><s:label for="author" accesskey="n" /></td>
-        <td><s:text name="author" />
-            <s:checkbox name="remember" />
-            <s:label for="remember" />
-        </td>
-      </tr>
-      <tr>
-        <td><s:label for="email" accesskey="m" /></td>
-        <td><s:text name="email" size="24" /></td>
-      </tr>
+        <tr>
+          <td><s:label for="author" accesskey="n" /></td>
+          <td><s:text name="author" /></td>
+        </tr>
+        <wiki:UserCheck status="authenticated">
+          <tr>
+            <td><s:label for="email" accesskey="m" /></td>
+            <td><s:text name="email" size="24" /></td>
+          </tr>
+        </wiki:UserCheck>
       </wiki:CheckRequestContext>
 
     </table>
@@ -102,23 +102,23 @@
     </div>
 
     <fieldset class="unit">
-    <legend><fmt:message key='editor.plain.action'/></legend>
-    <a href="#" class="tool tUNDO" title="<fmt:message key='editor.plain.undo.title'/>">undo</a>
-    <a href="#" class="tool tREDO" title="<fmt:message key='editor.plain.redo.title'/>">redo</a>
-    <a href="#" class="tool tSEARCH" title="<fmt:message key='editor.plain.find.title'/>">find</a>
-    <a href="#" class="tool tCONFIG" title="<fmt:message key='editor.plain.config.title'/>">config</a>
+      <legend><fmt:message key='editor.plain.action'/></legend>
+      <a href="#" class="tool tUNDO" title="<fmt:message key='editor.plain.undo.title'/>">undo</a>
+      <a href="#" class="tool tREDO" title="<fmt:message key='editor.plain.redo.title'/>">redo</a>
+      <a href="#" class="tool tSEARCH" title="<fmt:message key='editor.plain.find.title'/>">find</a>
+      <a href="#" class="tool tCONFIG" title="<fmt:message key='editor.plain.config.title'/>">config</a>
     </fieldset>
 
     <fieldset class="unit">
-    <legend><fmt:message key='editor.plain.insert'/></legend>
-    <a href="#" class="tool tLink" title="<fmt:message key='editor.plain.tbLink.title'/>">link</a>
-    <a href="#" class="tool tH1" title="<fmt:message key='editor.plain.tbH1.title'/>">h1</a>
-    <a href="#" class="tool tH2" title="<fmt:message key='editor.plain.tbH2.title'/>">h2</a>
-    <a href="#" class="tool tH3" title="<fmt:message key='editor.plain.tbH3.title'/>">h3</a>
-    <a href="#" class="tool tPRE" title="<fmt:message key='editor.plain.tbPRE.title'/>">pre</a>
-    <a href="#" class="tool tHR" title="<fmt:message key='editor.plain.tbHR.title'/>">hr</a>
-    <a href="#" class="tool tBR" title="<fmt:message key='editor.plain.tbBR.title'/>">br</a>
-    <a href="#" class="tool tCHAR" title="<fmt:message key='editor.plain.tbCHAR.title'/>">special</a>
+      <legend><fmt:message key='editor.plain.insert'/></legend>
+      <a href="#" class="tool tLink" title="<fmt:message key='editor.plain.tbLink.title'/>">link</a>
+      <a href="#" class="tool tH1" title="<fmt:message key='editor.plain.tbH1.title'/>">h1</a>
+      <a href="#" class="tool tH2" title="<fmt:message key='editor.plain.tbH2.title'/>">h2</a>
+      <a href="#" class="tool tH3" title="<fmt:message key='editor.plain.tbH3.title'/>">h3</a>
+      <a href="#" class="tool tPRE" title="<fmt:message key='editor.plain.tbPRE.title'/>">pre</a>
+      <a href="#" class="tool tHR" title="<fmt:message key='editor.plain.tbHR.title'/>">hr</a>
+      <a href="#" class="tool tBR" title="<fmt:message key='editor.plain.tbBR.title'/>">br</a>
+      <a href="#" class="tool tCHAR" title="<fmt:message key='editor.plain.tbCHAR.title'/>">special</a>
     </fieldset>
 
     <fieldset class="unit">
@@ -157,7 +157,7 @@
 
       <a href="#" class="tool tHORZ" title="<fmt:message key='editor.plain.tbHORZ.title'/>">tile-horz</a>
       <a href="#" class="tool tVERT" title="<fmt:message key='editor.plain.tbVERT.title'/>">tile-vert</a>
-      <label for="options.livePreview" title="<fmt:message key='editor.plain.livepreview.title'/>">
+      <s:label for="options.livePreview" title="<fmt:message key='editor.plain.livepreview.title'/>" />
       <s:checkbox name="options.livePreview" />On
     </fieldset>
 
@@ -167,7 +167,7 @@
       <s:checkbox name="options.findRegex" /><fmt:message key="editor.plain.regexp"/>
       <input type="text" name="tbREPLACE" id="tbREPLACE" size="16" />
       <s:button class="btn" id="doreplace" name="findAndReplace" />
-      s:checkbox name="options.findGlobal" /><fmt:message key="editor.plain.global"/>
+      <s:checkbox name="options.findGlobal" /><fmt:message key="editor.plain.global"/>
     </div>
 
     </div><%-- end of the toolbar --%>
@@ -187,7 +187,7 @@
       <div class="unit size1of2 lastUnit">
         <div id="previewspin" class="spin" style="display:none;"><fmt:message key="common.ajax.loading"/></div>
         <div id="livepreview" class="xflow"></div>
-	  </div>
+	    </div>
 
     </div>
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditActionBean.java?rev=824021&r1=824020&r2=824021&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditActionBean.java Sun Oct 11 04:51:38 2009
@@ -24,11 +24,15 @@
 import java.io.IOException;
 import java.net.URI;
 import java.security.Principal;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
 import net.sourceforge.stripes.action.*;
@@ -41,7 +45,11 @@
 import org.apache.wiki.WikiSession;
 import org.apache.wiki.api.WikiException;
 import org.apache.wiki.api.WikiPage;
+import org.apache.wiki.auth.UserManager;
+import org.apache.wiki.auth.WikiPrincipal;
+import org.apache.wiki.auth.login.CookieAssertionLoginModule;
 import org.apache.wiki.auth.permissions.PagePermission;
+import org.apache.wiki.auth.user.UserProfile;
 import org.apache.wiki.content.ContentManager;
 import org.apache.wiki.content.PageNotFoundException;
 import org.apache.wiki.content.lock.PageLock;
@@ -49,11 +57,14 @@
 import org.apache.wiki.htmltowiki.HtmlStringToWikiTranslator;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
+import org.apache.wiki.preferences.Preferences;
+import org.apache.wiki.preferences.Preferences.TimeFormat;
 import org.apache.wiki.providers.ProviderException;
 import org.apache.wiki.ui.stripes.HandlerPermission;
 import org.apache.wiki.ui.stripes.SpamProtect;
 import org.apache.wiki.ui.stripes.WikiActionBeanContext;
 import org.apache.wiki.ui.stripes.WikiRequestContext;
+import org.apache.wiki.util.HttpUtil;
 import org.apache.wiki.util.TextUtil;
 import org.apache.wiki.workflow.DecisionRequiredException;
 import org.jdom.JDOMException;
@@ -117,12 +128,57 @@
     @HandlesEvent( "comment" )
     @HandlerPermission( permissionClass = PagePermission.class, target = "${page.path}", actions = PagePermission.COMMENT_ACTION )
     @WikiRequestContext( "comment" )
-    public Resolution comment()
+    public Resolution comment() throws ProviderException
     {
+        WikiActionBeanContext wikiContext = getContext();
+        HttpServletRequest request = wikiContext.getRequest();
+        HttpSession session = request.getSession();
+        Principal user = wikiContext.getCurrentUser();
+        WikiPage page = getPage();
+        String pageName = page.getName();
+
+        log.info("Commenting page "+pageName+". User="+request.getRemoteUser()+", host="+request.getRemoteAddr() );
+        
         // Set the editing start time (will be written to the JSPs as encrypted parameter)
         setStartTime( System.currentTimeMillis() );
 
-        return null;
+        // If page is locked, make sure we tell the user
+        List<Message> messages = wikiContext.getMessages();
+        WikiEngine engine = wikiContext.getEngine();
+        ContentManager mgr = engine.getContentManager();
+        PageLock lock = mgr.getCurrentLock( page );
+        if( lock != null )
+        {
+            messages.add( new LocalizableMessage( "edit.locked", lock.getLocker(), lock.getTimeLeft() ) );
+        }
+
+        // If user is not editing the latest one, tell user also
+        ValidationErrors errors = getContext().getValidationErrors();
+        WikiPage latest;
+        try
+        {
+            latest = engine.getPage( page.getName() );
+        }
+        catch( PageNotFoundException e )
+        {
+            latest = page;
+        }
+        if( latest.getVersion() != page.getVersion() )
+        {
+            errors.addGlobalError( new LocalizableError( "edit.restoring", page.getVersion() ) );
+        }
+
+        // Attempt to lock the page.
+        lock = mgr.lockPage( page, user.getName() );
+        if( lock != null )
+        {
+            session.setAttribute( LOCK_PREFIX + pageName, lock );
+        }
+
+        // The comment field is initialized with nothing
+        m_text = "";
+
+        return new ForwardResolution( "/Comment.jsp" );
     }
 
     /**
@@ -298,24 +354,49 @@
     }
 
     /**
-     * Initializes default values that must be set in order for events to work
+     * <p>Initializes default values that must be set in order for events to work
      * properly. This method before after binding and validation of the
      * ActionBean's other properties, to make sure that the values we want are
-     * bound. The values set includes the <code>author</code> property, which
-     * is set to the value passed in the request parameter <code>author</code>
-     * if the user is anonymous. In all other cases, the author is always set to
-     * the name of the Principal returned by
-     * {@link WikiSession#getUserPrincipal()}.
+     * bound. The values set includes:</p>
+     * <ul>
+     * <li>the {@code author} property, which
+     * is set to the value passed in the request parameter {@code author}
+     * or {@code Anonymous Coward} if the user is anonymous. In all other cases,
+     * the author is always set to the name of the Principal returned by
+     * {@link WikiSession#getUserPrincipal()}.</li>
+     * <li>the {@code email} property, which for authenticated users is set
+     * to their user profile's e-mail address</li>
+     * </ul>
      */
     @After( stages = LifecycleStage.BindingAndValidation )
     public void initDefaultValues()
     {
         // Set author: prefer authenticated/asserted principals first
         WikiSession wikiSession = getContext().getWikiSession();
-        if( getAuthor() == null || !wikiSession.isAnonymous() )
+        if( m_author == null && wikiSession.isAnonymous() )
+        {
+            Principal author = wikiSession.getUserPrincipal();
+            if ( author instanceof WikiPrincipal &&
+                WikiPrincipal.IP_ADDRESS.equals( ((WikiPrincipal)author).getType() ) )
+            {
+                setAuthor( "Anonymous Coward" );
+            }
+        }
+        else
         {
             setAuthor( wikiSession.getUserPrincipal().getName() );
         }
+        
+        // Set email if user is authenticated
+        if ( wikiSession.isAuthenticated() )
+        {
+            UserManager mgr = getContext().getEngine().getUserManager();
+            UserProfile profile = mgr.getUserProfile( wikiSession );
+            if ( profile.getEmail() != null )
+            {
+                m_email = profile.getEmail();
+            }
+        }
     }
 
     /**
@@ -406,16 +487,36 @@
                 session.removeAttribute( "captcha" );
             }
 
+            // If this is an append, add a separation line and the author's details
             if( m_append )
             {
                 StringBuffer pageText = new StringBuffer( engine.getText( pagereq ) );
+                if( pageText.length() > 0 )
+                {
+                    pageText.append( "\n\n----\n\n" );
+                }
                 pageText.append( m_text );
+                if( m_author != null && m_author.length() > 0 )
+                {
+                    String signature = m_author;
+                    if( m_email != null && m_email.length() > 0 )
+                    {
+                        String link = HttpUtil.guessValidURI( m_email );
+                        signature = "["+m_author+"|"+link+"]";
+                    }
+                    Calendar cal = Calendar.getInstance();
+                    SimpleDateFormat fmt = Preferences.getDateFormat( wikiContext ,  TimeFormat.DATETIME);
+                    pageText.append("\n\n--"+signature+", "+fmt.format(cal.getTime()));
+                }
                 engine.saveText( wikiContext, pageText.toString() );
             }
             else
             {
                 engine.saveText( wikiContext, m_text );
             }
+            
+            //  We expire ALL locks at this moment, simply because someone has
+            //  already broken it.
             PageLock lock = (PageLock) session.getAttribute( LOCK_PREFIX + pagereq );
             engine.getContentManager().unlockPage( lock );
             session.removeAttribute( LOCK_PREFIX +page.getName() );
@@ -452,14 +553,22 @@
     }
 
     /**
-     * Sets the author.
+     * If the WikiSession is anonymous or asserted, sets the author and
+     * causes the "assertion cookie" to be set in the HTTP response. If the
+     * user is authenticated, this method does nothing.
      * 
      * @param author the author
      */
     @Validate( required = false )
     public void setAuthor( String author )
     {
-        m_author = author;
+        WikiSession session = getContext().getWikiSession();
+        if ( !session.isAuthenticated() )
+        {
+            m_author = TextUtil.replaceEntities( author );
+            HttpServletResponse response = getContext().getResponse();
+            CookieAssertionLoginModule.setUserCookie( response, m_author );
+        }
     }
 
     /**
@@ -516,14 +625,35 @@
     }
 
     /**
-     * Sets the email.
+     * Sets the e-mail address for the user, and causes a Cookie called
+     * {@code link} to be written to the HTTP response. If the user
+     * is authenticated, this method will check to see if {@code email} is
+     * different from the one in the user's UserProfile. If it is,
+     * it will add a message to the user indicating that it is different
+     * and can be changed in their user profile if desired.
      * 
-     * @param email the email
+     * @param email the email address
      */
-    @Validate( required = false )
+    @Validate( required = false, converter = EmailTypeConverter.class )
     public void setEmail( String email )
     {
         m_email = email;
+        Cookie linkcookie = new Cookie("link", email );
+        linkcookie.setMaxAge(1001*24*60*60);
+        getContext().getResponse().addCookie( linkcookie );
+        
+        // If authenticated, is the e-mail different than the one on file?
+        WikiSession session = getContext().getWikiSession();
+        if ( session.isAuthenticated() )
+        {
+            WikiEngine engine = getContext().getEngine();
+            UserProfile profile = engine.getUserManager().getUserProfile( session );
+            if ( email.equals( profile.getEmail() ) )
+            {
+                Message message = new LocalizableMessage( "changed.email" );
+                getContext().getMessages().add( message );
+            }
+        }
     }
 
     /**