/** * HACK: Save the given document without changing the content author because the document may * loose or win programming and script rights as a consequence and this is not the intent of this * operation. Even though the document content field was modified, the change is purely syntactic; * the semantic is not affected so it's not clear whether the content author deserves to be * updated or not (even without the side effects). * * @param document the document to be saved * @param comment the revision comment * @param minorEdit whether it's a minor edit or not * @throws XWikiException if saving the document fails */ private void saveDocumentPreservingContentAuthor( XWikiDocument document, String comment, boolean minorEdit) throws XWikiException { XWikiContext xcontext = this.xcontextProvider.get(); // Preserve the content author. document.setContentDirty(false); // Make sure the version is incremented. document.setMetaDataDirty(true); document.setAuthorReference(xcontext.getUserReference()); xcontext.getWiki().saveDocument(document, comment, minorEdit, xcontext); }
@Override public boolean action(XWikiContext context) throws XWikiException { XWiki xwiki = context.getWiki(); XWikiResponse response = context.getResponse(); XWikiDocument doc = context.getDoc(); XWikiRequest request = context.getRequest(); String className = request.getParameter("classname"); String objectNumber = request.getParameter("object"); if (className != null && objectNumber != null) { try { BaseObject object = doc.getObject(className, Integer.valueOf(objectNumber)); synchronizeObject(object, context); } catch (Exception ex) { // Wrong parameters, non-existing object return true; } } else { for (List<BaseObject> classObjects : doc.getXObjects().values()) { for (BaseObject object : classObjects) { synchronizeObject(object, context); } } } // Set the new author doc.setAuthorReference(context.getUserReference()); xwiki.saveDocument( doc, localizePlainOrKey("core.model.xobject.synchronizeObjects.versionSummary"), true, context); if (Utils.isAjaxRequest(context)) { response.setStatus(HttpServletResponse.SC_NO_CONTENT); response.setContentLength(0); } else { // forward to edit String redirect = Utils.getRedirect("edit", "editor=object", context); sendRedirect(response, redirect); } return false; }
@Override public String render(XWikiContext context) throws XWikiException { XWikiDocument editedDocument = prepareEditedDocument(context); // The current user editing the document should be displayed as author and creator (if the // edited document is // new) when the edited document is previewed. editedDocument.setAuthorReference(context.getUserReference()); if (editedDocument.isNew()) { editedDocument.setCreatorReference(context.getUserReference()); } // Make sure the current user doesn't use the programming rights of the previous content author // (by editing a // document saved with programming rights, changing it and then previewing it). Also make sure // the code // requiring programming rights is executed in preview mode if the current user has programming // rights. editedDocument.setContentAuthorReference(context.getUserReference()); // Reconfirm edit (captcha) when jcaptcha is not correct. Boolean reCheckCaptcha = (Boolean) context.get("recheckcaptcha"); return reCheckCaptcha != null && reCheckCaptcha ? "captcha" : "preview"; }