Rationale
The DeleteRevisionsAddOn allows users to delete revisions for a topic.
This is what happens:
- Given correct rights set in WebPreferences and TWikiPreferences (See Installation instructions), the user can click on the "Delete Topic Revisions..." link in "More Topic Actions"
- The DeleteRevisionsAddOn.pm will only search in the current web's WebPreferences topic for allowed users and topics, and only in Main.TWikiPreferences for allowed webs.
-
The topic gets moved to the TrashWeb. A new topic only containing the last revision of the original topic is created in its place.
- The topic's .txt,v file (the file that keeps track of the revisions) then gets manually moved using "rename" to the TrashWeb.
- If TrashWeb._DELREFS_CurrentWebCurrentTopic already exists, a number is appended to the trashed topic becomes TrashWeb._DELREFS_CurrentWebCurrentTopic_1
- After this, the topic is saved in the AddOn using the TWiki functions, in order to generate a new .txt,v file for the Topic.
TODO
- It is not a nice thing to directly edit the template files. A better solution should be created.
Installation instructions
- Unpack the zipfile in
/your/twiki
File |
Description |
lib/TWiki/Plugins/DeleteRevisionsPlugin.pm |
A simple plugin that checks if a) the user is in 'oopsmore.tmpl' ("More topic actions") and b) has rights to delete revisions. If so, a flag is set so that the revision delete link in oopsmore.tmpl is visible. This plugins also check's where you're coming from. Which the link in oopsmore.tmpl uses to tell 'delrefs' where it should redirect the user after it's done. |
lib/TWiki/Contrib/DeleteRevisionsAddOn.pm |
Where it all happens. Includes a method for checking whether a user is allowed to delete revisions, used by DeleteRevisionPlugin.pm |
lib/TWiki/Contrib/DeleteRevisionsAddOn/Config.spec |
Config file used for registering the bin script |
bin/delrefs/ |
The bin script, nothing fancy happening here |
- Edit templates/oopsmore.tmpl and add the following definition:
%TMPL:DEF{"deleterefs"}%
<div style="display: %IF{"'%CAN_DELETE_REVISIONS%'='YES!'" then="block" else="none"}%">
---++ %MAKETEXT{"Delete topic revisions"}%
<script>
$(function() {
$('#deleterefs').click(function(e) {
e.preventDefault();
if (confirm("Are you sure you want to delete -ALL- previous revisions for this topic? Please note:\n\t1) This action -CAN NOT- be undone without talking to a TWiki administrator.\n\t2) The topic will be moved to the Trash Web where it may be subject to -PERMANENT DELETION- after some time.\n\nUse with care.")) {
window.location = $(this).attr('href');
}
});
});
</script>
* <strong><a href="%SCRIPTURL%/delrefs/%WEB%/%TOPIC%%IF{"defined 'DELREF_REDIRECT_TO'" then="?redirectTo=%DELREF_REDIRECT_TO%"}%" rel='nofollow' id="deleterefs">%MAKETEXT{"Delete topic revisions..."}%</a></strong>
%MAKETEXT{"The topic will be cloned to !TrashWeb.[_1] before revisions are deleted in this web ([_2])." args="<nop>%TOPIC%,%WEB%"}%
</div>
%TMPL:END%
- Add the definition at the bottom of templates/oopsmore.tmpl with:
%TMPL:P{"deleterefs"}%
- In the WebPreferences of the webs you want people to be able to delete revisions in, add the following section:
---++ Topic Revision Deletion
In this web (%WEB%), which users should be allowed to delete topic revision history?
* Set DELREF_VALID_USERS = Main.User1, User2, Main.User3
On which topics should this be allowed?
* Set DELREF_VALID_TOPICS = Topic1, Topic2, Topic3
Please note that a user has to have CHANGE rights to the topic he/she is trying to delete revisions from.
- In the Main.TWikiPreferences, set the following:
---++ Topic Revision Deletion
On which webs should this be allowed?
* Set DELREF_VALID_WEBS = Web1, Web2
- Even though the DeleteRevisionsAddOn only will search for DELREF_VALID_USERS/TOPICS/WEB in CurrentWeb.WebPreferences and MainWeb.TWikiPreferences, its still recommended to FINALize these preferences.
- Re-save the TWiki configuration (/bin/configure) in order for the DeleteRevisionsAddOn Config.spec contents to be added to (/lib/LocalSite.cfg).
- That's it Whenever a user visits "More Topic Actions" he will see the "Delete Topic Revisions..." link, allowing him/her to delete the revisions, given that he/she has sufficient rights of course.