Extension talk:BreadCrumbs/LQT Archive 1

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; } ?>

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

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]

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)

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 ); }

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