Details
- Applies to
- 1.5.3
- Wannabe
- 1.7.1
- Purpose
- Add user preference to automatically subscribe to edited pages
- Description
- The patch adds and option to the User Preferences page to allow users automatically subscribe to pages they edit. Actually, it lets them pick the default choice of subscribe to this page presented on the Editor Screen.
During the Edit session users want the ability to go ahead and subscribe to future changes to the page. This patch adds a checkbox (next to the Trivial Change and Remove trailing whitespace boxes) to subscribe to the page or not. The default value of the control is defined by each user in their User Preferences (Users who rely on RSS feeds to wiki pages would likely choose default: NO and other users loving emails would choose YES)
Patch
I had to make a couple of 1-line changes to the following files:
multiconfig.py
add the following to the user_checkbox_fields variable + ('subscribe_edits', lambda _: _('Subscribe to pages that I edit')), and this to the user_checkbox_defaults + 'subscribe_edits': 1,
The PageEditor and PageEditorGui.py files had to be changed
PageEditor.py
@@ -387,32 +383,6 @@ }) if self.cfg.mail_enabled: + # Add an option to automatically subscribe to pages + # Determine if User wants default subscription + uid = self.request.user.valid and self.request.user.id or self.request.remote_addr + this_user = user.User(self.request, id=uid) + + subscribe_checked = this_user.subscribe_edits + if this_user.subscribe_edits: + if form.get('savetext', [None])[0] != None and form.get('subscribe',['UNKOWN'])[0] == 'UNKOWN': + subscribe_checked = 0 + elif form.get('subscribe',['UNKOWN'])[0] == '1': + subscribe_checked = 1 + + subscribe_disabled = '' + if self.request.user.isSubscribedTo([self.page_name]) == 1: + subscribe_checked = 1 + subscribe_disabled = 'disabled' + + self.request.write(''' + +<input type="checkbox" name="subscribe" id="chksubscribe" value="1" %(disabled)s %(checked)s> +<label for="chksubscribe">%(label)s</label> ''' % { + 'checked': ('', 'checked')[subscribe_checked], + 'label': _("Subscribe to this page"), + 'disabled' : subscribe_disabled, + }) + self.request.write(''' <input type="checkbox" name="trivial" id="chktrivial" value="1" %(checked)s> @@ -860,7 +830,6 @@ @keyword extra: extra info field (e.g. for SAVE/REVERT with revno) @keyword comment: comment field (when preview is true) @keyword action: action for editlog (default: SAVE) + @keyword subscribe: subscribe the user to the page (default: set by User preference) @rtype: unicode @return: error msg """ @@ -944,7 +913,6 @@ comment = kw.get('comment', u'') extra = kw.get('extra', u'') trivial = kw.get('trivial', 0) + subscribe = kw.get('subscribe',0) # write the page file mtime_usecs, rev = self._write_file(newtext, action, comment, extra) @@ -953,13 +921,6 @@ # send notification mails if self.request.cfg.mail_enabled: msg = msg + self._notifySubscribers(comment, trivial) + # subscribe user to page + if subscribe and self.request.user.isSubscribedTo([self.page_name]) == 0: + uid = self.request.user.valid and self.request.user.id or self.request.remote_addr + this_user = user.User(self.request, id=uid) + this_user.subscribe(self.page_name) + this_user.save() + msg = msg + _("<BR>") + _("You are now subscribed to this page, subsequent changes to this page will be emailed to you.")
@@ -317,34 +313,8 @@ 'category': unicode(util.web.makeSelection('category', cat_pages)), }) if self.cfg.mail_enabled: + # Add an option to automatically subscribe to pages + # Determine if User wants default subscription + uid = self.request.user.valid and self.request.user.id or self.request.remote_addr + this_user = user.User(self.request, id=uid) + + subscribe_checked = this_user.subscribe_edits + if this_user.subscribe_edits: + if form.get('savetext', [None])[0] != None and form.get('subscribe',['UNKOWN'])[0] == 'UNKOWN': + subscribe_checked = 0 + elif form.get('subscribe',['UNKOWN'])[0] == '1': + subscribe_checked = 1 + + subscribe_disabled = '' + if self.request.user.isSubscribedTo([self.page_name]) == 1: + subscribe_checked = 1 + subscribe_disabled = 'disabled' + self.request.write(''' +<input type="checkbox" name="subscribe" id="chksubscribe" value="1" %(disabled)s %(checked)s> +<label for="chksubscribe">%(label)s</label> ''' % { + 'checked': ('', 'checked')[subscribe_checked], + 'label': _("Subscribe to this page"), + 'disabled' : subscribe_disabled, + }) + + self.request.write(''' + <input type="checkbox" name="trivial" id="chktrivial" value="1" %(checked)s> <label for="chktrivial">%(label)s</label> ''' % { 'checked': ('', 'checked')[form.get('trivial',['0'])[0] == '1'],
wikiaction had to be changed to grab the form value and pass it to the pg.saveText
@@ -550,7 +548,6 @@ category = request.form.get('category', [None])[0] rstrip = int(request.form.get('rstrip', ['0'])[0]) trivial = int(request.form.get('trivial', ['0'])[0]) + subscribe = int(request.form.get('subscribe',['0'])[0]) if request.form.has_key('button_switch'): if editor == 'text': @@ -638,7 +635,7 @@ # Save new text else: try: + savemsg = pg.saveText(savetext, rev, trivial=trivial, comment=comment, subscribe=subscribe) - savemsg = pg.saveText(savetext, rev, trivial=trivial, comment=comment) except pg.EditConflict, msg: # Handle conflict and send editor
Discussion
I'd like to see this integrated into the Moin codebase, but I figure somebody will more time will have to construct my chages above into a legitimate 'patch' package.
Plan
- Priority:
- Assigned to:
- Status: