Extension talk:BreadCrumbs/Archive

This is my first time on mediawiki, hope I'm not doing this wrong... I was wondering if anyone knew how I could get the breadcrumbs to display above the header of the page? Right now it displays at the top of the content area which of course is below the header. Thanks... I emailed the creator too, if I get a solution I'll post it here.

Another one: http://wiki.ljackson.us/MediaWiki_BreadCrumbs --pfctdayelise 05:03, 16 April 2007 (UTC)

Problem: The breadcrumb seems to be saved, and refreshing or visiting new pages simply appends to the current trail. For example: Main Page > Categories:Videos > Funny > LOL.avi (that's fine, but if I go back to the Main Page, it does this: Main Page > Categories:Videos > Funny > LOL.avi > Main Page Also it would be nice if there was an option to omit 'categories:' from the breadcrumb text.

I am getting the following Notice until I login. Once I login, the notice goes away, even after I logout. I am new to php and am trying to troubleshoot this. If I find a solution, I will post it here. --Clarke Christiansen Notice: Undefined offset:  -1 in C:\Projects\csbswiki\wiki\extensions\BreadCrumbs\BreadCrumbsFunctions.php on line 30

The problem was 2 fold. --Clarke Christiansen Here is my updated code for BreadCrumbsFunctions.php that seems to fix the problems. I am new to php here, so be nice.  0. On the first page load this would be true.    The result is the Notice above where we are trying to loop through an array that is empty and worse yet we are starting at -1.
 * 2) If you have not done anything to trigger session_start, like logging in, BreadCrumbs will not accumulate. To fix this I am checking  for $_SESSION and starting the session if it is not there.


 * 1) The BreadCrumbs extension, an extension for providing an breadcrumbs
 * 2) navigation to users.


 * 1) @addtogroup Extensions
 * 2) @author Manuel Schneider 
 * 3) @copyright © 2007 by Manuel Schneider
 * 4) @licence GNU General Public Licence 2.0 or later

if( !defined( 'MEDIAWIKI' ) ) { echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); die; }

function fnBreadCrumbsShowHook( &$m_pageObj ) { global $wgTitle; global $wgOut; global $wgUser; global $wgBreadCrumbsDelimiter; global $wgBreadCrumbsCount; # deserialize data from session into array: $m_BreadCrumbs = array; if( isset( $_SESSION['BreadCrumbs'] ) ) { $m_BreadCrumbs = $_SESSION['BreadCrumbs']; } else { if( !isset( $_SESSION ) ) { session_start; }   $_SESSION['BreadCrumbs'] = array; } # cache index of last element: $m_count = count( $m_BreadCrumbs ) - 1; # check for doubles: if( count( $m_BreadCrumbs ) > 0 && $m_BreadCrumbs[ $m_count ] != $wgTitle->getPrefixedText ) { # reduce the array set, remove older elements: $m_BreadCrumbs = array_slice( $m_BreadCrumbs, ( 1 - $wgBreadCrumbsCount ) ); # add new page: array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText ); } else { array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText ); }

# serialize data from array to session: $_SESSION['BreadCrumbs'] = $m_BreadCrumbs; # update cache: $m_count = count( $m_BreadCrumbs ) - 1; # acquire a skin object: $m_skin =& $wgUser->getSkin; # build the breadcrumbs trail: $m_trail = ' '; for( $i = 0; $i <= $m_count; $i++ ) { $m_trail .= $m_skin->makeLink( $m_BreadCrumbs[$i] ); if( $i < $m_count ) $m_trail .= $wgBreadCrumbsDelimiter; } $m_trail .= ' '; $wgOut->addHTML( $m_trail ); # invalidate internal MediaWiki cache: $wgTitle->invalidateCache; $wgUser->invalidateCache; # Return true to let the rest work: return true; }

function fnBreadCrumbsOutputHook( &$m_pageObj, &$m_parserOutput ) { global $wgScriptPath;
 * 1) Entry point for the hook for printing the CSS:

# Register CSS file for our select box: $m_pageObj->addLink(   array( 'rel'  => 'stylesheet', 'type' => 'text/css', 'href' => $wgScriptPath. '/extensions/BreadCrumbs/BreadCrumbs.css' ) );

# Be nice: return true; } ?>

--217.6.174.66 Your start_session did the trick. Thanks for the inspiration. I edited my copy of the Breadcrumbs with your "forced session" and now it works like charm. I tested your code and for my wiki it expands breadcrumbs to infinity and doesn't kill the doublets. But now with your help the breadcrumbs are usable even for anonymous users. Big THX.

Looks worth linking to... Thanks for your work. ljackson.us --75.144.5.60 16:49, 9 May 2007 (UTC)

Well, somehow my breadcrumbs don't appear! When checking Apache's error log nothing can be found there out of the ordinary.

Same problem here with the above script: no breadcrumbs (fedora 8, php 5.2, apache 2.2, mysql 5.0, mediawiki 1.11.0) --Hvdeynde

With this script as BreadCrumpsFunctions.php, my Wiki doesnt give any output. it's just an empty page and no error-messages in the logs. without this script, the wiki works, but there is just one breadcrump and they are not added. any ideas? --87.165.92.192 08:57, 1 April 2009 (UTC)

Javascript
Because this functionality is so secondary, I think it'd be just fine if it were all cookie and javascript based. Inject the content into a div after page load.

How do I change the location of the BreadCrumbs??
I would like to change the location of the BreadCrumbs. I would like to place the BreadCrumbs before the page title or on the same line as the tabs and under the my talk, my preferences, my watchlist area. Can someone tell me if this is possible?

Thanks. --Mlbowden 14:37, 27 June 2007 (UTC)

Answer
Yes and No.

It is possible to change the position of the breadcrumbs be editing the BreadCrumbs.php by changing the hook reference ( $wgHooks['ArticleViewHeader'][] ). For example if you wanted the the breadcrumbs to be displayed as the bottom of the article then you could replace $wgHooks['ArticleViewHeader'][] with $wgHooks['PersonalUrls'][]

The catch is, that as best I can tell there is no hook that takes effect before the article title or out side the article div.

A List of the hooks can be found at www.mediawiki.org/wiki/Manual:MediaWiki_hooks]

CSS Solution
I was able to move the position of the breadcrumb closer to the page title by editing the BreadCrumbs.css file and replacing font-size:0.8em; }
 * 1) BreadCrumbsTrail {

with the following to move the breadcrumb up 15px

font-size:0.8em; position:relative; top:-15px; } --Spinteractive 02:27, 5 December 2009 (UTC)
 * 1) BreadCrumbsTrail {

Breadcrumbs on by default
I installed the Bread crumbs extension and I really like it. Is there any possibility to switch the functionality for every user on by default? (at the moment every user has to enable bread crumbs manually) --212.23.103.101 14:44, 7 February 2008 (UTC)

This would be a truly great feature. Users aren't inclined to tamper with their preferences like that, so most people on my wiki won't ever benefit from BreadCrumbs. Which is a shame, because it's a very nice and easy way to navigate between pages when you don't want an elaborate menu structure.

Any chance you could look into this again?

-- Martin Christensen, Denmark

Solution
This is simple. Comment out the following lines in BreadCrumbs.php: if($wgUser->getOption('breadcrumb')==0) { return; } -- Martin Christensen, Denmark

BreadCrumbs to infinity and beyond
I installed the BreadCrumbs extension on Mediawiki 1.11.1 with the fix noted above and it seemed to be working fine until some users with too much time on their hands noticed the following: When you are on the Main Page and you continually click on the "Main Page" link in the navigation menu, the breadcrumbs will continually add to the breadcrumb list past the breadcrumb limit (default of 5). Additionally you can click on the link for the page you are currently on in the breadcrumb list and it will continue on past the default of 5 breadcrumbs. Now click on a link to another page or just hit "Random Page" to bring up another page and the new page comes up and the breadcrumbs is now the proper 5 breadcrumbs. I can repeat this using Firefox or IE. My guess is whatever is doing the counting is not adding to the count when you go to the same page but is displaying the page in the breadcrumbs.

What would be better is for the breadcrumbs to not advance when the same page is accessed, such as when you continually click on the "Main Page" link in the navigation menu.

How to fix this
To fix this problem, change the code in BreadCrumbsFunctions.php from line 39

Instead of this:

# check for doubles: if( count( $m_BreadCrumbs ) > 0 && $m_BreadCrumbs[ $m_count ] != $wgTitle->getPrefixedText ) { # reduce the array set, remove older elements: $m_BreadCrumbs = array_slice( $m_BreadCrumbs, ( 1 - $wgBreadCrumbsCount ) ); # add new page: array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText ); } else { array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText ); }

You should have this:

# check for doubles: if( count( $m_BreadCrumbs ) > 0 ) { if ($m_BreadCrumbs[ $m_count ] != $wgTitle->getPrefixedText ) { # reduce the array set, remove older elements: $m_BreadCrumbs = array_slice( $m_BreadCrumbs, ( 1 - $wgBreadCrumbsCount ) ); # add new page: array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText ); } }  else { array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText ); }

Thanks! That works nicely! 128.231.88.4 13:06, 10 April 2008 (UTC)

May be just my opinion, but this "checking for doubles" code works much better than the original: # check for doubles: $m_key = array_search($wgTitle->getPrefixedText, $m_BreadCrumbs ); if (($m_key != false) || ($m_BreadCrumbs[0] == $wgTitle->getPrefixedText)) $m_BreadCrumbs = array_slice( $m_BreadCrumbs, 0, $m_key + 1 ); else array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText ); This eliminates all duplicates and nicely rolls back to wherever you were before, if, for example, you click on one of the breadcrumb links. No recursing crumbs. --Gullion 22:22, 11 November 2009 (UTC)


 * NOTE: This does not fix the doubles issue in MW 1.1.6 --JSingleton 14:09, 30 September 2010 (UTC)

Breadcrumbs for anonymous?
Is it possible to enable breadcrumbs for users that aren't logged in? --N0ctrnl 17:51, 25 March 2008 (UTC)

Saved breadcrumbs misbehavior
It was noticed before, that the extension saves the breadcrubs like this: Item1 > Item2 > Item 3 (OK), but when going back to Item 2 it displays: Item1 > Item2 > Item3 > Item1.

In order to solve this behavior, insert the following lines in the BreadcrumbFunctions.php: $loc = array_search($wgTitle->getPrefixedText, $m_BreadCrumbs); if(($loc >= 0)) { $m_BreadCrumbs = array_slice($m_BreadCrumbs, 0, ($loc + 1)); } so that it looks like this: if( count( $m_BreadCrumbs ) > 0 ) { if ($m_BreadCrumbs[ $m_count ] != $wgTitle->getPrefixedText ) { # reduce the array set, remove older elements: $m_BreadCrumbs = array_slice( $m_BreadCrumbs, ( 1 - $wgBreadCrumbsCount ) ); # add new page: array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText ); }       $loc = array_search($wgTitle->getPrefixedText, $m_BreadCrumbs); if(($loc >= 0)) { #shrink array $m_BreadCrumbs = array_slice($m_BreadCrumbs, 0, ($loc + 1)); } }  else { array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText ); }
 * 1) check for doubles:

--217.6.174.66 06:51, 27 October 2009 (UTC) You don't have to invent the wheel a second time. You can use the function "in_array" for this... can look something like this (attention ... crappy code following :) )   if( $m_count < 1 || $m_BreadCrumbs[ $m_count ] != $wgTitle->getPrefixedText ) {		if( $m_count >= 1 && (!in_array($wgTitle->getPrefixedText, $m_BreadCrumbs))) {			# reduce the array set, remove older elements:			$m_BreadCrumbs = array_slice( $m_BreadCrumbs, ( 1 - $wgBreadCrumbsCount ) );		}		if (!in_array($wgTitle->getPrefixedText, $m_BreadCrumbs)){ 			# add new page:			array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText );		}  }

NOTE: This does not fix the doubles issue in MW 1.1.6 --JSingleton 14:09, 30 September 2010 (UTC)

Single Crumb
I have just started a Wiki for some project documentation. I have loaded the Breadcrumb extension but only get a link to the current page and not those that I have just come from. I am using Windows 2003/IIS/MySQL with the latest version of MediaWiki (1.14) Any pointers you an give would be appreciated.

Des Mannall

Solution
As mentioned 2 or 3 questions above you have to login to see the full path through your wiki. If you edit your wiki anonymous you won't be able to see the full path. --217.6.174.66 06:50, 27 October 2009 (UTC)

What does Wikipedia use?
How does Wikipedia implement breadcrumbs? E.g., at w:User:Sj/note, there is a breadcrumb back to w:User:Sj. Tisane 07:42, 21 March 2010 (UTC)
 * Responded on user talk page. For other curious people:
 * &rarr; see 'Subpages'.
 * -pinkgothic 14:20, 8 June 2010 (UTC)

PHP 5.3 issue
Hi. It looks like Breadcrumbs does not work with PHP 5.3. I get the following error: Detected bug in an extension! Hook BreadCrumbs::output failed to return a value; should return true to continue hook processing or false to abort.

Backtrace:


 * 1) 0 /var/www/webapps/parentvoice_dev/includes/OutputPage.php(565): wfRunHooks('OutputPageParse...', Array)
 * 2) 1 /var/www/webapps/parentvoice_dev/includes/OutputPage.php(573): OutputPage->addParserOutputNoText(Object(ParserOutput))
 * 3) 2 /var/www/webapps/parentvoice_dev/includes/Article.php(3615): OutputPage->addParserOutput(Object(ParserOutput))
 * 4) 3 /var/www/webapps/parentvoice_dev/includes/Article.php(989): Article->outputWikiText('view
 * 6) 5 /var/www/webapps/parentvoice_dev/includes/Wiki.php(63): MediaWiki->performAction(Object(OutputPage), Object(Article), Object(Title), Object(User), Object(WebRequest))
 * 7) 6 /var/www/webapps/parentvoice_dev/index.php(116): MediaWiki->initialize(Object(Title), Object(Article), Object(OutputPage), Object(User), Object(WebRequest))
 * 8) 7 {main}

Is this easy to fix? I'll be lost without this great extension!

Many Thanks

mitchelln 09:55, 27th May 2010.

Any word on this?

PHP 5.3 works with a newer version of Breadcrumbs http://upload.wikimedia.org/ext-dist/BreadCrumbs-trunk-r71600.tar.gz
 * It works, but we are back to the Double breadcrumbs issue as stated in #4 above. None of the proposed code changes work. --JSingleton 14:08, 30 September 2010 (UTC)


 * It can be got to work. Replace the doubles function with:

# check for doubles: $m_key = array_search($wgTitle->getPrefixedText, $m_BreadCrumbs ); if (($m_key != false) || ($m_BreadCrumbs[0] == $wgTitle->getPrefixedText)) $m_BreadCrumbs = array_slice( $m_BreadCrumbs, 0, $m_key + 1 ); else array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText );
 * and add $wgTitle to the globals at the top of the function

global $wgOut, $wgUser, $wgTitle;
 * Then it all works. Tested on MW 1.16.5 and PHP 5.3 :)
 * --Mitchelln 09:25, 5 October 2011 (UTC)

Possible to add a label?
Is it possible to add a label as a prefix to the BreadCrumb line?

ParserCache issue in MW 1.17.0
I got this:

Commenting out the two lines fixed that: // $parserOutput = $this->mPCache->mMemc->get( $key );                                                                                                   // $this->mPCache->mMemc->set( $key, $parserOutput, $expire );

But ideally it should be rewritten. Maybe I'll get to that at some point... Guaka 07:49, 15 November 2011 (UTC)