Search in sources :

Example 31 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class InternalSkinManager method getCurrentSkinId.

public String getCurrentSkinId(boolean testRights) {
    String skin;
    XWikiContext xcontext = this.xcontextProvider.get();
    if (xcontext != null) {
        // Try to get it from context
        skin = (String) xcontext.get(CKEY_SKIN);
        if (StringUtils.isNotEmpty(skin)) {
            return skin;
        } else {
            skin = null;
        }
        // Try to get it from URL
        if (xcontext.getRequest() != null) {
            skin = xcontext.getRequest().getParameter("skin");
            if (StringUtils.isNotEmpty(skin)) {
                return skin;
            } else {
                skin = null;
            }
        }
        // Try to get it from preferences (user -> space -> wiki -> xwiki.properties)
        skin = this.allConfiguration.getProperty("skin");
        if (skin != null) {
            return skin;
        }
    }
    // Try to get it from xwiki.cfg
    skin = getDefaultSkinId();
    if (xcontext != null) {
        // TODO: shouldn't we make sure anyone see the skin whatever right he have ?
        if (testRights) {
            XWikiDocument document = this.wikiSkinUtils.getSkinDocument(skin);
            if (document != null) {
                if (!this.authorization.hasAccess(Right.VIEW, document.getDocumentReference())) {
                    this.logger.debug("Cannot access configured wiki skin [{}] due to access rights, using the default skin.", skin);
                    skin = getDefaultSkinId();
                }
            }
        }
        // Set found skin in the context
        xcontext.put(CKEY_SKIN, skin);
    }
    return skin;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext)

Example 32 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class CommentSaveAction method action.

@Override
public boolean action(XWikiContext context) throws XWikiException {
    // Get the XWiki utilities
    XWiki xwiki = context.getWiki();
    XWikiResponse response = context.getResponse();
    XWikiRequest request = context.getRequest();
    XWikiDocument doc = context.getDoc();
    if (!csrfTokenCheck(context) || doc.isNew()) {
        return false;
    }
    // Comment class reference
    DocumentReference commentClass = new DocumentReference(context.getWikiId(), XWiki.SYSTEM_SPACE, XWikiDocument.COMMENTSCLASS_REFERENCE.getName());
    // Edit comment
    int commentId = getCommentIdFromRequest(request);
    BaseObject commentObj = doc.getXObject(commentClass, commentId);
    if (commentObj == null) {
        return false;
    }
    // Check if the author is the current user or if the current user has the ADMIN right
    String commentAuthor = commentObj.getStringValue("author");
    DocumentReference authorReference = documentReferenceResolver.resolve(commentAuthor);
    if (!authorReference.equals(context.getUserReference()) && !authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), context.getDoc().getDocumentReference())) {
        return false;
    }
    // Edit the comment
    commentObj.set(COMMENT_FIELD_NAME, request.getParameter(String.format("XWiki.XWikiComments_%d_comment", commentId)), context);
    // Save it
    xwiki.saveDocument(doc, localizationManager.getTranslationPlain("core.comment.editComment"), true, context);
    // If xpage is specified then allow the specified template to be parsed.
    if (context.getRequest().get("xpage") != null) {
        return true;
    }
    // forward to edit
    String redirect = Utils.getRedirect("edit", context);
    sendRedirect(response, redirect);
    return false;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWiki(com.xpn.xwiki.XWiki) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 33 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class CreateAction method doCreate.

/**
 * Actually executes the create, after all preconditions have been verified.
 *
 * @param context the context of this action
 * @param newDocument the document to be created
 * @param isSpace whether the document is a space webhome or a page
 * @param templateProvider the template provider to create from
 * @throws XWikiException in case anything goes wrong accessing xwiki documents
 */
private void doCreate(XWikiContext context, XWikiDocument newDocument, boolean isSpace, BaseObject templateProvider) throws XWikiException {
    XWikiRequest request = context.getRequest();
    XWikiDocument doc = context.getDoc();
    // resolver to use to resolve references received in request parameters
    DocumentReferenceResolver<String> resolver = Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, CURRENT_MIXED_RESOLVER_HINT);
    String parent = getParent(request, doc, isSpace, context);
    // get the title of the page to create, as specified in the parameters
    String title = getTitle(request, newDocument, isSpace);
    // get the template from the template parameter, to allow creation directly from template, without
    // forcing to create a template provider for each template creation
    String template = getTemplate(templateProvider, request);
    // from the template provider, find out if the document should be saved before edited
    boolean toSave = getSaveBeforeEdit(templateProvider);
    String redirectParams = null;
    String editMode = null;
    if (toSave) {
        XWiki xwiki = context.getWiki();
        DocumentReference templateReference = resolver.resolve(template);
        newDocument.readFromTemplate(templateReference, context);
        if (!StringUtils.isEmpty(parent)) {
            DocumentReference parentReference = resolver.resolve(parent);
            newDocument.setParentReference(parentReference);
        }
        if (title != null) {
            newDocument.setTitle(title);
        }
        DocumentReference currentUserReference = context.getUserReference();
        newDocument.setAuthorReference(currentUserReference);
        newDocument.setCreatorReference(currentUserReference);
        xwiki.saveDocument(newDocument, context);
        editMode = newDocument.getDefaultEditMode(context);
    } else {
        // put all the data in the redirect params, to be passed to the edit mode
        redirectParams = getRedirectParameters(parent, title, template);
        // Get the edit mode of the document to create from the specified template
        editMode = getEditMode(template, resolver, context);
    }
    // Perform a redirection to the edit mode of the new document
    String redirectURL = newDocument.getURL(editMode, redirectParams, context);
    redirectURL = context.getResponse().encodeRedirectURL(redirectURL);
    if (context.getRequest().getParameterMap().containsKey("ajax")) {
        // If this template is displayed from a modal popup, send a header in the response notifying that a
        // redirect must be performed in the calling page.
        context.getResponse().setHeader("redirect", redirectURL);
    } else {
        // Perform the redirect
        sendRedirect(context.getResponse(), redirectURL);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWiki(com.xpn.xwiki.XWiki) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 34 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class DeleteAction method deleteFromRecycleBin.

private void deleteFromRecycleBin(long index, XWikiContext context) throws XWikiException {
    XWiki xwiki = context.getWiki();
    XWikiResponse response = context.getResponse();
    XWikiDocument doc = context.getDoc();
    XWikiDeletedDocument dd = xwiki.getRecycleBinStore().getDeletedDocument(index, context, true);
    // don't try to delete it and instead redirect to the view page.
    if (dd != null) {
        DeletedDocument ddapi = new DeletedDocument(dd, context);
        if (!ddapi.canDelete()) {
            throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED, "You are not allowed to delete a document from the trash " + "immediately after it has been deleted from the wiki");
        }
        if (!dd.getFullName().equals(doc.getFullName())) {
            throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_URL_EXCEPTION, "The specified trash entry does not match the current document");
        }
        xwiki.getRecycleBinStore().deleteFromRecycleBin(index, context, true);
    }
    sendRedirect(response, Utils.getRedirect("view", context));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) DeletedDocument(com.xpn.xwiki.api.DeletedDocument) XWiki(com.xpn.xwiki.XWiki) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) XWikiException(com.xpn.xwiki.XWikiException)

Example 35 with XWikiDocument

use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.

the class DeleteAction method deleteToRecycleBin.

private boolean deleteToRecycleBin(XWikiContext context) throws XWikiException {
    XWikiRequest request = context.getRequest();
    XWikiDocument doc = context.getDoc();
    EntityReference documentReference = doesAffectChildren(request, doc.getDocumentReference()) ? doc.getDocumentReference().getLastSpaceReference() : doc.getTranslatedDocument(context).getDocumentReferenceWithLocale();
    return deleteToRecycleBin(documentReference, context);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference)

Aggregations

XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)869 DocumentReference (org.xwiki.model.reference.DocumentReference)469 BaseObject (com.xpn.xwiki.objects.BaseObject)318 Test (org.junit.Test)284 XWikiContext (com.xpn.xwiki.XWikiContext)232 XWikiException (com.xpn.xwiki.XWikiException)178 ArrayList (java.util.ArrayList)99 XWiki (com.xpn.xwiki.XWiki)97 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)86 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)71 Document (com.xpn.xwiki.api.Document)48 EntityReference (org.xwiki.model.reference.EntityReference)48 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)41 Date (java.util.Date)41 IOException (java.io.IOException)40 HashMap (java.util.HashMap)33 QueryException (org.xwiki.query.QueryException)27 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)25 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)23 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)23