Personal tools
shadowfax.org.uk logo
Views

YAMBE

From Shadowfax

Jump to: navigation, search

Contents

Yet Another MediaWiki Breadcrumb Extension

Given there are several breadcrumb extensions, why did I bother creating Yet Another MediaWiki Breadcrumb Extension (YAMBE)?

  1. I haven't seen any extensions which work exactly how I want them to.
  2. It served as an exercise to help me learn about extending MediaWiki

You can see YAMBE in action on this site and get hold of YAMBE here

The YAMBE Approach

YAMBE is designed to allow a hierarchical breadcrumb where each page has a defined parent. This is not the wiki style and thus is probably not useful for a true wiki. However, where MediaWiki is being used more as a CMS than a wiki YAMBE comes into its own. Also, because of the way that YAMBE works it should be straightforward to implement YAMBE in parts of a wiki which need it and another breadcrumb approach in parts which do not.

How YAMBE Works

YAMBE does what it does in two parts.

On creating a new page

Whenever a new page is created beneath a page which already uses YAMBE a piece of markup is inserted at the start of the page to set up YAMBE and identify the page's parent.

If you want a breadcrumb, and you create the new page from its parent you don't need to do anything extra. The preloaded markup is already complete. If you create it from another leaf, or want later to change the parent you can edit the markup.

If you don't want a breadcrumb just delete the markup.

By way of example, here is the markup which is at the head of this page

<yambe:breadcrumb>MediaWiki|MediaWiki</yambe:breadcrumb>

The root page of the hierachy can be set up with a blank tag as it has no parent.

<yambe:breadcrumb />

On displaying a page

The second part of what YAMBE does is a parser hook. When the page is displayed this reads the markup to locate the parent, and then loops through each parent until it gets to the top of the tree. There is a variable set up to stop the script in case the hierarchy is too deep and it automatically stops if it detects an error or reaches a page which has no parent.

The Tag

<yambe:breadcrumb self="Self Text">Parent Page|Parent Text</yambe:breadcrumb>
  • Self Text is the text to display at the end of the breadcrumb for the current page. Defaults to page name if blank
  • Parent Page is the name of the parent page
  • Parent Text is the text to display in the breadcrumb for the parent

How existing breadcrumb extensions work

There are a number of approaches to building a MediaWiki Breadcrumb.

Track User Path

The first approach tracks the users path through the wiki showing recently visited pages. This is a very nice solution for a wiki, but it differs from how a breadcrumb works on a more conventional website. For example if I have a page called Leaf with a breadcrumb which looks like:

Trunk > Branch > Twig > Leaf

and I follow a link from it to a page called Fruit which is also parented off the Twig page a conventional breadcrumb would now read:

Trunk > Branch > Twig > Fruit

In contrast the wiki type breadcrumb would read:

Trunk > Branch > Twig > Leaf > Fruit.

Extensions Using this Approach

URL level-based breadcrumb

The second type of breadcrumb parses the URI to turn the directory structure of the URL into the breadcrumb. Fine if that is what you want - but I aim to not build the site hierarchy into the URL as this can result in very long URLs and also means that you have to change the URL if you change the site structure which is a bad idea (see my comments on static URLS for why!).

Extensions Using this Approach

Category Based Breadcrumb

Category-based breadcrumbs build the breadcrumb from the page name and the containing category.

Extensions Using this Approach

Markup-based Breadcrumb

There is another kind which takes some kind of markup and parses it into a breadcrumb. The thing is the markup you need to use has to be typed in manually and is nearly as long-winded as writing the breadcrumb manually anyway. So there is not much saving.



Leave your comment

Comments

Ian @Bernaut. It hasn't been tested against 1.18 - but does work with 1.17. It should be fine - but if you try it and run into any issues let me know
bernaut Does it work with MediaWiki 1.18?
matteo thanks a lot, great job!
sami cette extension de commentaire est fantastique
Ian @Saimon. I'm afraid the only way currently is to visit each page and manually add the tags. I've not thought of an easy way of letting Yambe work out the structure. Although if you have the hierarchy in a text file with the unique page names and their parents, it should be possible to make a SQL script to bulk add them into the database
saimon69 Listen,would like to ad YAMBE to an existing wiki with an already existing hierarchy, how can i make the breadcrumbs work for that?
Gingillo This is a nice integration example.
skew I like it, though I'm still looking for something the includes a thumbs-up / thumbs-down collator like yahoo answers.
Kevin Ian,

I appreciate the quick response. I will try that out. Thanks again!
Ian Kevin, should be very easy to make it non-clickable. The key is in the lines

// Breadcrumb is built in reverse and ends with this rather gratuitous self-link
$breadcrumb = linkFromText($wgTitle->getText(),$yambeSelf,$wgTitle->getNamespace());

If you replace the line with the following that should do the trick.

$breadcrumb = $yambeSelf;

If you want to get rid of the current page entirely you can change the line to

$breadcrumb = "";

but you will probably also need to replace the line which says

$breadcrumb = $url . $bcDelim . $breadcrumb;

with

if ($breadcrumb == "") $breadcrumb = $url;
else $breadcrumb = $url . $bcDelim . $breadcrumb;
Kevin Hi Ian,
Is there any way to make it so the current page is not displayed in the breadcrumb? For example, if I'm on a page called 'Installation', my breadcrumb might be 'Main > Windows > Installation'. Is there any way to remove 'Installation' from the breadcrumb or at least make it unclickable? Any help is appreciated.
Ian Steve, I've tested the 0.2.0 code with MediaWiki 1.16.0 and 1.17.0 and it worked well. I'm not aware of installations using it on these versions on larger wikis - but I see no reason why it should not work and am happy to assist if errors occur.
Steve This looks nice, is it compatible with the newest mw?
Janelle Hey I just wanted to say thank you so much. I'm pretty new to all of this but for work I had to get familiar fast. This is by far one of the most useful articles and has the most useful content. Thank you so much.
Claude A simple trial of the WordPress extension
Ian Hi Patrick. I've tried to email you a couple of times to get some clarification. Possible my emails have ended up in your spam folders? From my testing, provided the you save changes to the parent page before clicking on a new page link YAMBE will always work. I'm not entirely understanding the subtlety of your issue. Any more detail you can provide would be appreciated.
Patrick Hi Neil, I use YAMBE on a quicly-increasing intranet site and it's working brilliantly as a categorization method! One thing I have noticed is that if a page is created by adding it after clicking the 'edit' link at the top of a wiki page, the YAMBE markup is added - but, if the page is added by clicking the 'edit' link of an individual section within a wiki page, the YAMBE markup is not automatically added. Is this something I am doing incorrectly, or is there a way to make this behave as I'd anticipated (add the markup irrespective of where the new page link was inserted). Thanks!
Mike Ended up just removing the contents of if (substr_count($in,":")) and everything works great.
Mike Pages using a colon in the url such as Main:Subpage do not seem to be working using Main:Subpage|Subpage. All that shows is Subpage1 when Main>Subpage>Subpage1 is what should be showing. Any ideas?
Ian Hi Neil, thanks for pointing this out. Both references to "self" on line 268 should be inside single quotes. I've now fixed this (released as version 0.1.5), which should solve the issue you were encountering
Neil Hello,

I get the following message when I turn on mediawiki errors. Any ideas on how to fix?

Notice: Use of undefined constant self - assumed 'self' in /extensions/yambe.php on line 268

Thanks.
Ian Hi Kris. Glad you are finding it useful. Apologies about delay in reply (my comment auto-email seems to have been turned off!). I've not used the breadcrumb on such a large wiki, although I use it on an intranet. My expectation, however, is that performance should not decrease significantly as wiki size increases, because each link knows its parent page and can look it up directly. It could however have a perfomance implication if the $maxBackCount variable is increased, or if the pages themselves are very large.
Kris Willems Thanks for this extension. I am using it on an internal wiki and it works great. I think structuring a based on page creation order is a logical decision. I prefer this breadcrumbs system above all others, because it requires little or no administration (don't need to create categories). Do you've any idea of the performance impact? How would this behave on a wiki with 2000 pages?
Menu