0

2

I'm working for the first time with the Wiki section of the Plugin API and it looks like the documentation is still a little weak in this area and the examples provided are a little too basic to be helpful.

I've got a rudimentary Wiki block working, but can't figure out how I can figure out information about the Wiki Page that contains the instance of my WikiBlock control. For example, I'd like to know the ixWikiPage value for the parent Wiki Page.

Any help would be appreciated.

UPDATE:
This is a bit complicated to describe, so I am going to give a simplified example that demonstrates the general type of thing I need to be able to do.

How do I create a WikiBlock that can be inserted into a Wiki article that simply displays the ixWikiPage value of the page it is contained in?

flag

1 Answer

1

In general, I think the intent is that you get the CWikiPage when the WikiPageCommit* and WikiPageDisplay* methods are invoked on your subclass of WikiBlockPlugin.

Take the example in (FogBugz install)/Plugins/examples/WikiBlock/TableOfContents; it displays contents based on the headers in the document. TocBlock keeps these headers in an instance variable called rgHeaders, which is set by TocManager in its override of RenderWikiBlock. It gets the contents of the page from WikiPageDisplayView and stores what it needs in an instance variable. You will see that the other argument to WikiPageDisplayView is a CWikiPage; that's what you want.

    public override string WikiPageDisplayView(CWikiPage oPage, string sContents)
    {
        // if this page contains a TocBlock, then annotate the headers with anchors and inject our toc css
        if (ContainsWikiBlockTag(sContents, TocPlugin.BLOCK_IDENTIFIER, WikiBlockTagType.Persisted))
        {
            sContents = GetTocCss() + AnnotateHeaders(sContents);
        }
        return base.WikiPageDisplayView(oPage, sContents);
    }

    protected override string RenderWikiBlock(WikiBlock block, RenderingMode mode)
    {
        if (block is TocBlock)
        {
            (block as TocBlock).rgHeaders = headers;
        }
        return base.RenderWikiBlock(block, mode);
    }

So what you would do is to grab the CWikiPage.ixWikiPage during your override of WikiBlockManager.WikiPageDisplayView, store it in an instance variable, then use that to set an instance variable on your subclass of of WikiBlock in your override of RenderWikiBlock.

Does that make sense? I know there's a fair amount of indirection here, but it makes these WikiBlocks surprisingly flexible.

link|flag
I'm sorry, but I am still confused about how the WikiBlockPlugin, WikiBlock, and WikiBlockManager objects interact. I've modified my original question with a simple example, maybe you could update your answer to explain in terms of that example? – JohnFx Nov 18 2009 at 15:47
Thanks. That example you mentioned in the samples directory got me where I needed with regard to communicating between blockmanager and the block. I must admit though, persisting that value across those two events using a variable in the scope of the whole blockmanager feels a little uncomfortable. Is the architecture such that there is a 1-1 relationship between a block manager and an instance of a wiki page being rendered? – JohnFx Nov 19 2009 at 20:27
Yes, I understand your misgivings. Instances of BlockManager (and, it is worth noting, all objects in FogBugz Plugins) survive for one page request at most. So if we ever start showing more than one wiki page per page serve, we'll have to make that more explicit. – Brett Kiefer Nov 20 2009 at 16:55

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.