Commits

edgimar committed 77d9fc5

- initial commit of force-comment plugin
* * *
- add README, and license to main file
* * *
- change readme

  • Participants

Comments (0)

Files changed (4)

+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.
+
+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.
+

File forcecomment/__init__.py

+from forcecomment import *
+

File forcecomment/forcecomment.py

+# Copyright 2009 Mark Edgington
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+"""  ForceComment - forces the user to provide a comment for wiki changes
+
+"""
+from trac.core import *
+from trac.wiki.api import IWikiPageManipulator
+
+__author__ = 'Mark Edgington'
+__author_email__ = 'edgimar@gmail.com'
+
+class ForceCommentPlugin(Component):
+    implements(IWikiPageManipulator)
+
+    def prepare_wiki_page(req, page, fields):
+        """Not currently called, but should be provided for future
+        compatibility."""
+        pass
+
+    def validate_wiki_page(self, req, page):
+        """Validate a wiki page after it's been populated from user input.
+       
+        Must return a list of `(field, message)` tuples, one for each problem
+        detected. `field` can be `None` to indicate an overall problem with the
+        page. Therefore, a return value of `[]` means everything is OK.
+        
+        """
+        #if req.perm.has_permission('WIKI_ADMIN'):
+        #    # An administrator is allowed to have an empty comment
+        #    return []
+
+        if ('preview' in req.args) or ('diff' in req.args):
+            # Only a preview or diff, no need to filter the submission yet
+            return []
+
+        #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:
+            return []
+        else:
+            return errorList
+
+from setuptools import find_packages, setup
+
+setup(
+        name='ForceComment', version='0.1',
+        packages=find_packages(exclude=['*.tests*']),
+        entry_points="""
+                    [trac.plugins]
+                    forcecomment = forcecomment
+                    """,
+    )
+