Source:
<code>public boolean restoreDeletedDocument(long deletedDocumentId, boolean checkContextUser) { XWikiContext context = this.xcontextProvider.get(); XWiki xwiki = context.getWiki(); DocumentReference deletedDocumentReference = null; try { XWikiDeletedDocument deletedDocument = xwiki.getDeletedDocument(deletedDocumentId, context); if (deletedDocument == null) { logger.error("Deleted document with ID does not exist.", deletedDocumentId); return false; } deletedDocumentReference = deletedDocument.getDocumentReference(); if (xwiki.exists(deletedDocumentReference, context)) { logger.error("Document with ID can not be restored. Document already exists", deletedDocument.getFullName(), deletedDocumentId); <START> } else if (checkContextUser && (!canRestoreDeletedDocument(deletedDocumentId, context.getUserReference()) <END> || !canRestoreDeletedDocument(deletedDocumentId, context.getAuthorReference())) ) { logger.error("You are not allowed to restore document with ID [{}]", deletedDocumentReference, deletedDocumentId); } else { xwiki.restoreFromRecycleBin(deletedDocument.getId(), "Restored from recycle bin", context); logger.info("Document has been restored", deletedDocumentReference); return true; } } catch (Exception e) { if (deletedDocumentReference != null) { logger.error("Failed to restore document with ID [{}]", deletedDocumentReference, deletedDocumentId, e); } else { logger.error("Failed to restore deleted document with ID [{}]", deletedDocumentId, e); } } return false; }</code><technical_language>messages depending if right is user author. end "WTF I admin !"</technical_language>

Target:
public boolean restoreDeletedDocument(long deletedDocumentId, boolean checkContextUser) { XWikiContext context = this.xcontextProvider.get(); XWiki xwiki = context.getWiki(); DocumentReference deletedDocumentReference = null; try { XWikiDeletedDocument deletedDocument = xwiki.getDeletedDocument(deletedDocumentId, context); if (deletedDocument == null) { logger.error("Deleted document with ID does not exist.", deletedDocumentId); return false; } deletedDocumentReference = deletedDocument.getDocumentReference(); if (xwiki.exists(deletedDocumentReference, context)) { logger.error("Document with ID can not be restored. Document already exists", deletedDocument.getFullName(), deletedDocumentId); } else if (checkContextUser && !canRestoreDeletedDocument(deletedDocumentId, context.getAuthorReference())) { logger.error("The author of this script is not allowed to restore document with ID [{}]", context.getAuthorReference(), deletedDocumentReference, deletedDocumentId); } else if (checkContextUser && !canRestoreDeletedDocument(deletedDocumentId, context.getUserReference())) { logger.error("You are not allowed to restore document with ID [{}]", deletedDocumentReference, deletedDocumentId); } else { xwiki.restoreFromRecycleBin(deletedDocument.getId(), "Restored from recycle bin", context); logger.info("Document has been restored", deletedDocumentReference); return true; } } catch (Exception e) { if (deletedDocumentReference != null) { logger.error("Failed to restore document with ID [{}]", deletedDocumentReference, deletedDocumentId, e); } else { logger.error("Failed to restore deleted document with ID [{}]", deletedDocumentId, e); } } return false; }