Wiki Discussions - Preparing the storage
Before discussion can take place in a wiki page, we need to allow the designer to decide what kind of discussion to take place in the wiki page, and where to store them. I decided to allow the designer to do this when he activates the feature in the wiki library. Hence I created a customaction to add a link in the wiki library's setting page.

This link can easily be added by create a custom action definition. I won't be discussion how to create the full custom action definition xml, nor the feature.xml, since you can find ready resources using Uncle G, or Mr Live, so here is the custom action definition I used.
<CustomAction
Id="WikiDiscussionSettings"
GroupId="Communications"
Location="Microsoft.SharePoint.ListEdit"
Sequence="10"
Title="Discussion Settings"
RegistrationType="List"
RegistrationId="119">
<UrlAction Url="_layouts/WIki/DiscussionSettings.aspx?List={ListId}"/>
</CustomAction>
Clicking on discussion settings would allow the designer to enable discussions, and select which discussion board template to use.

After the designer selected the discussion list, a discussion list with the name "[Wiki Library] Discussion" will be created, and a routine which is handled by Microlau, will be executed to add the web parts to all the existing pages. I'll let him to illustrate this. But is it this simple?
Notice that the dropdown list for Wiki Discussion List is showing links? Links is not a discussion list template, so why is it listed in the dropdown list for the designer to select?
The ListTemplates collection in the SPWeb object lists out all the list templates available in the web. Each SPListTemplate has a property called BaseType, which is of SPBaseType enum. By right, I should be able to use this property to check if this list template is a discussion list template, as the enum has SPBaseType.DiscussionBoard. But when you access the property, it returns SPBaseType.GenericList. Therefore, I don't have a way to list out only Discussion List templates, but at least I can remove list templates that are document libraries.
To work around this, I have to create a "temporary" instance of the list, and check the content types in the list. When I can find a content type that inherits from Threads or Message, the list is a discussion list. If I don't, I delete this "temporary" list and ask the designer to select a list that is a discussion. The code below does the checking.
SPContentTypeId cidForumContentTypeId = new SPContentTypeId("0x0107");
foreach (SPContentType oContentType in splDiscussionList.ContentTypes)
{
if (cidForumContentTypeId.IsParentOf(oContentType.Id))
{
IsDiscussionList = true;
break;
}
}
Building the web part