Ticket #5992 (closed enhancement: fixed)
[patch] More graceful wiki page validation with req.warning
| Reported by: | hyuga <hyugaricdeau@…> | Owned by: | cboos |
|---|---|---|---|
| Priority: | high | Milestone: | 0.11 |
| Component: | wiki system | Version: | devel |
| Severity: | normal | Keywords: | wiki, validation |
| Cc: |
Description
This does away with the InvalidWikiPage exception entirely, and instead of raising an error upon finding the first invalid field, all page_manipulators are allowed to perform validation, and add warnings to req.warning. This was all warnings are displayed, and can also be displayed during preview, diff, and when trying to submit:
-
trac/wiki/web_ui.py
43 43 from trac.wiki.model import WikiPage 44 44 45 45 46 class InvalidWikiPage(TracError):47 """Exception raised when a Wiki page fails validation."""48 49 50 46 class WikiModule(Component): 51 47 52 48 implements(IContentConverter, INavigationContributor, IPermissionRequestor, … … 130 126 if a in req.args: 131 127 action = a 132 128 break 133 if action == 'edit' and not has_collision: 129 valid = self._validate(context) 130 if action == 'edit' and not has_collision and valid: 134 131 self._do_save(context) 135 132 else: 136 133 return self._render_editor(context, action, has_collision) … … 167 164 168 165 # Internal methods 169 166 167 def _validate(self, context): 168 req = context.req 169 page = context.resource 170 171 valid = True 172 # Give the manipulators a pass at post-processing the page 173 for manipulator in self.page_manipulators: 174 for field, message in manipulator.validate_wiki_page(req, page): 175 valid = False 176 if field: 177 req.warning(_("The Wiki page field '%(field)s' is " 178 "invalid: %(message)s", 179 field=field, message=message)) 180 else: 181 req.warning(_("Invalid Wiki page: %(message)s", 182 message=message)) 183 return valid 184 170 185 def _page_data(self, context, action=''): 171 186 page_name = context.name() 172 187 title = context.summary() … … 253 268 # WIKI_ADMIN 254 269 page.readonly = int('readonly' in req.args) 255 270 256 # Give the manipulators a pass at post-processing the page257 for manipulator in self.page_manipulators:258 for field, message in manipulator.validate_wiki_page(req, page):259 if field:260 raise InvalidWikiPage(_("The Wiki page field '%(field)s' "261 "is invalid: %(message)s",262 field=field, message=message))263 else:264 raise InvalidWikiPage(_("Invalid Wiki page: %(message)s",265 message=message))266 267 271 try: 268 272 page.save(get_reporter_id(req, 'author'), req.args.get('comment'), 269 273 req.remote_addr)
Attachments
Change History
Note: See
TracTickets for help on using
tickets.


