edgimar avatar edgimar committed 475af23

- added some user-configurable options

Comments (0)

Files changed (2)

 This is a simple plugin to require users to provide comments when adding
-changes to a wiki page.  User customizable options may be added in the future,
-but for now it works just fine as-is.
+changes to a wiki page.  
 
 To install, simply run "python setup.py bdist_egg".  The resulting egg file
 will be located in the 'dist' folder after it is built.  Copy this egg file
 to the plugins subdirectory of a trac environment, and restart your webserver
 to ensure that the new plugin is loaded.
 
+To customize, add the following section to your trac.ini file, and any of
+the following settings (defaults are used otherwise):
+
+[forcecomment]
+min_comment_length = 10
+cosmetic_change_comment = "cosmetic"
+error_text = "Sorry, but a comment is required."
+
+The 'cosmetic_change_comment' is a string or phrase which can be less than
+the minimum length, but will be accepted, since it indicates that nothing
+comment-worthy was changed.
+

forcecomment/forcecomment.py

 
 """  ForceComment - forces the user to provide a comment for wiki changes
 
+To customize, add the following section to your trac.ini file, and any of
+the following settings (defaults are used otherwise):
+
+[forcecomment]
+min_comment_length = 10
+cosmetic_change_comment = "cosmetic"
+error_text = "Sorry, but a comment is required."
+
+The 'cosmetic_change_comment' is a string or phrase which can be less than
+the minimum length, but will be accepted, since it indicates that nothing
+comment-worthy was changed.
+
 """
 from trac.core import *
 from trac.wiki.api import IWikiPageManipulator
             # Only a preview or diff, no need to filter the submission yet
             return []
 
+        # get the config options set in the trac config file
+        c = lambda key, default: self.env.config.get('forcecomment', key, default)
+        minLen = int(c('min_comment_length', '10'))
+        cosmeticString = c('cosmetic_change_comment', 'cosmetic')
+        errTextDefault = "A full comment must be supplied for this change," + \
+          " or use '" + cosmeticString + "' if no actual informational content has changed."
+        errorText = c('error_text', errTextDefault)
+
         #cur_page = WikiPage(self.env, name=page.name, version=page.version)
         #author = req.args.get('author', req.authname)
         comment = req.args['comment']
 
-        # Test the actual page changes as well as the comment
-        #changes = [(cur_page.text, page.text), (None, author)]
-        errorList = [(None, \
-          "A full comment must be supplied for this change," + \
-          " or use 'cosmetic' if no actual informational content has changed.")]
-
-        if (comment.lower() == 'cosmetic') or len(comment) >= 10:
+        if (comment.lower() == cosmeticString) or len(comment) >= minLen:
             return []
         else:
-            return errorList
+            return [(None, errorText)]
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.