Edgewall Software

Extension Point : IWikiChangeListener

InterfaceIWikiChangeListenerSince0.10
Moduletrac.wiki.apiSourceapi.py

The IWikiChangeListener allows components to listen for and to react to wiki page events.

Purpose

The Trac wiki system organizes knowledge and information in wiki pages. Plugins can hook into the wiki system to trigger their own actions when wiki pages are created, deleted, changed or renamed.

The main purpose for this interface is to allow plugins to stay informed about the existing wiki pages and trigger appropriate actions elsewhere (e.g. sending notifications, starting indexing services, updating supplementary data structures etc.)

(For ticket validation and manipulation use IWikiPageManipulator instead.)

Usage

Implementing the interface follows the standard guidelines found in TracDev/ComponentArchitecture and of course TracDev/PluginDevelopment.

When a user creates a new milestone the wiki_page_added method is called. Similarly methods are called when a user deletes a wiki page (wiki_page_deleted) or a version of a wiki page (wiki_page_version_deleted ), edits the wiki page (wiki_page_changed), renames a wiki page (wiki_page_renamed) or edits a wiki page version comment (wiki_page_comment_modified).

The Wiki page data can be accessed as usual (e.g. page.text).

Examples

The CommitTicketUpdater can be enabled so referencing a ticket in a commit log message automatically updates that ticket. Similarly sometimes you might want to reference a ticket in a wiki page change comment. The following minimal example IWikiChangeListener implementation could implement such a feature:

import re
from trac.core import Component, implements
from trac.wiki.api import IWikiChangeListener
from trac.ticket.model import Ticket

class WikiTicketUpdater(Component):
    implements(IWikiChangeListener)

    def wiki_page_added(self, page):
        pass

    def wiki_page_changed(self, page, version, t, comment, author):
        ref = re.search('see #(\d+)', comment)
        if ref:
            id = int(ref.group(1))
            ticket = Ticket(self.env, id)
            ticket_comment = "In [wiki:%s@%s]: %s" % (page.name, version, comment)
            ticket.save_changes(author, ticket_comment, t)

    def wiki_page_deleted(self, page):
        pass

    def wiki_page_version_deleted(self, page):
        pass

    def wiki_page_renamed(self, page, old_name):
        pass

Available Implementations

Additional Information and References

API History

Last modified 6 years ago Last modified on Jun 11, 2018, 8:45:25 PM
Note: See TracWiki for help on using the wiki.