Index: trunk/extensions/BreadCrumbs/BreadCrumbsFunctions.php |
— | — | @@ -14,64 +14,67 @@ |
15 | 15 | } |
16 | 16 | |
17 | 17 | function fnBreadCrumbsShowHook( &$m_pageObj ) { |
18 | | - global $wgTitle; |
19 | | - global $wgOut; |
20 | | - global $wgUser; |
21 | | - global $wgBreadCrumbsDelimiter; |
22 | | - global $wgBreadCrumbsCount; |
23 | | - |
24 | | - # deserialize data from session into array: |
25 | | - $m_BreadCrumbs = array(); |
26 | | - if( isset( $_SESSION['BreadCrumbs'] ) ) $m_BreadCrumbs = $_SESSION['BreadCrumbs']; |
27 | | - # cache index of last element: |
28 | | - $m_count = count( $m_BreadCrumbs ) - 1; |
| 18 | + global $wgTitle, $wgOut, $wgUser; |
| 19 | + global $wgBreadCrumbsDelimiter, $wgBreadCrumbsCount, $wgBreadCrumbsShowAnons; |
29 | 20 | |
30 | | - # check for doubles: |
31 | | - if( $m_count < 1 || $m_BreadCrumbs[ $m_count ] != $wgTitle->getPrefixedText() ) { |
32 | | - if( $m_count >= 1) { |
33 | | - # reduce the array set, remove older elements: |
34 | | - $m_BreadCrumbs = array_slice( $m_BreadCrumbs, ( 1 - $wgBreadCrumbsCount ) ); |
35 | | - } |
36 | | - # add new page: |
37 | | - array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText() ); |
38 | | - } |
39 | | - # serialize data from array to session: |
40 | | - $_SESSION['BreadCrumbs'] = $m_BreadCrumbs; |
41 | | - # update cache: |
42 | | - $m_count = count( $m_BreadCrumbs ) - 1; |
| 21 | + if ( !$wgBreadCrumbsShowAnons && $wgUser->isAnon() ) |
| 22 | + return true; |
43 | 23 | |
44 | | - # acquire a skin object: |
45 | | - $m_skin =& $wgUser->getSkin(); |
46 | | - # build the breadcrumbs trail: |
47 | | - $m_trail = '<div id="BreadCrumbsTrail">'; |
48 | | - for( $i = 0; $i <= $m_count; $i++ ) { |
49 | | - $m_trail .= $m_skin->makeLink( $m_BreadCrumbs[$i] ); |
50 | | - if( $i < $m_count ) $m_trail .= $wgBreadCrumbsDelimiter; |
51 | | - } |
52 | | - $m_trail .= '</div>'; |
53 | | - $wgOut->addHTML( $m_trail ); |
| 24 | + # deserialize data from session into array: |
| 25 | + $m_BreadCrumbs = array(); |
| 26 | + if( isset( $_SESSION['BreadCrumbs'] ) ) $m_BreadCrumbs = $_SESSION['BreadCrumbs']; |
| 27 | + # cache index of last element: |
| 28 | + $m_count = count( $m_BreadCrumbs ) - 1; |
54 | 29 | |
55 | | - # invalidate internal MediaWiki cache: |
56 | | - $wgTitle->invalidateCache(); |
57 | | - $wgUser->invalidateCache(); |
| 30 | + # check for doubles: |
| 31 | + if( $m_count < 1 || $m_BreadCrumbs[ $m_count ] != $wgTitle->getPrefixedText() ) { |
| 32 | + if( $m_count >= 1) { |
| 33 | + # reduce the array set, remove older elements: |
| 34 | + $m_BreadCrumbs = array_slice( $m_BreadCrumbs, ( 1 - $wgBreadCrumbsCount ) ); |
| 35 | + } |
| 36 | + # add new page: |
| 37 | + array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText() ); |
| 38 | + } |
| 39 | + # serialize data from array to session: |
| 40 | + $_SESSION['BreadCrumbs'] = $m_BreadCrumbs; |
| 41 | + # update cache: |
| 42 | + $m_count = count( $m_BreadCrumbs ) - 1; |
58 | 43 | |
59 | | - # Return true to let the rest work: |
60 | | - return true; |
| 44 | + # acquire a skin object: |
| 45 | + $m_skin =& $wgUser->getSkin(); |
| 46 | + # build the breadcrumbs trail: |
| 47 | + $m_trail = '<div id="BreadCrumbsTrail">'; |
| 48 | + for( $i = 0; $i <= $m_count; $i++ ) { |
| 49 | + $m_trail .= $m_skin->makeLink( $m_BreadCrumbs[$i] ); |
| 50 | + if( $i < $m_count ) $m_trail .= $wgBreadCrumbsDelimiter; |
| 51 | + } |
| 52 | + $m_trail .= '</div>'; |
| 53 | + $wgOut->addHTML( $m_trail ); |
| 54 | + |
| 55 | + # invalidate internal MediaWiki cache: |
| 56 | + $wgTitle->invalidateCache(); |
| 57 | + $wgUser->invalidateCache(); |
| 58 | + |
| 59 | + # Return true to let the rest work: |
| 60 | + return true; |
61 | 61 | } |
62 | 62 | |
63 | 63 | ## Entry point for the hook for printing the CSS: |
64 | 64 | function fnBreadCrumbsOutputHook( &$m_pageObj, $m_parserOutput ) { |
65 | | - global $wgScriptPath; |
| 65 | + global $wgScriptPath, $wgBreadCrumbsShowAnons, $wgUser; |
66 | 66 | |
67 | | - # Register CSS file for our select box: |
68 | | - $m_pageObj->addLink( |
69 | | - array( |
70 | | - 'rel' => 'stylesheet', |
71 | | - 'type' => 'text/css', |
72 | | - 'href' => $wgScriptPath . '/extensions/BreadCrumbs/BreadCrumbs.css' |
73 | | - ) |
74 | | - ); |
| 67 | + if ( !$wgBreadCrumbsShowAnons && $wgUser->isAnon() ) |
| 68 | + return true; |
75 | 69 | |
76 | | - # Be nice: |
77 | | - return true; |
| 70 | + # Register CSS file for our select box: |
| 71 | + $m_pageObj->addLink( |
| 72 | + array( |
| 73 | + 'rel' => 'stylesheet', |
| 74 | + 'type' => 'text/css', |
| 75 | + 'href' => $wgScriptPath . '/extensions/BreadCrumbs/BreadCrumbs.css' |
| 76 | + ) |
| 77 | + ); |
| 78 | + |
| 79 | + # Be nice: |
| 80 | + return true; |
78 | 81 | } |
Index: trunk/extensions/BreadCrumbs/BreadCrumbs.php |
— | — | @@ -19,11 +19,12 @@ |
20 | 20 | $wgBreadCrumbsDelimiter = ' > '; |
21 | 21 | # $wgBreadCrumbsCount - number of breadcrumbs to use |
22 | 22 | $wgBreadCrumbsCount = 5; |
| 23 | +# Whether to provide the links also for anonymous users |
| 24 | +$wgBreadCrumbsShowAnons = true; |
23 | 25 | |
24 | 26 | $wgExtensionMessagesFiles['Breadcrumbs'] = dirname(__FILE__) . '/BreadCrumbs.i18n.php'; |
25 | 27 | |
26 | | -## Register extension setup hook and credits: |
27 | | -$wgExtensionFunctions[] = 'fnBreadCrumbs'; |
| 28 | +## Register extension credits: |
28 | 29 | $wgExtensionCredits['parserhook'][] = array( |
29 | 30 | 'path' => __FILE__, |
30 | 31 | 'name' => 'BreadCrumbs', |
— | — | @@ -34,17 +35,14 @@ |
35 | 36 | ); |
36 | 37 | |
37 | 38 | ## Set Hook: |
38 | | -function fnBreadCrumbs() { |
39 | | - global $wgHooks; |
40 | 39 | |
41 | | - ## Showing and updating the breadcrumbs trail |
42 | | - # Hook when viewing article header: |
43 | | - $wgHooks['ArticleViewHeader'][] = 'fnBreadCrumbsShowHook'; |
| 40 | +## Showing and updating the breadcrumbs trail |
| 41 | +# Hook when viewing article header: |
| 42 | +$wgHooks['ArticleViewHeader'][] = 'fnBreadCrumbsShowHook'; |
44 | 43 | |
45 | | - ## Infrastructure |
46 | | - # Hook our own CSS: |
47 | | - $wgHooks['OutputPageParserOutput'][] = 'fnBreadCrumbsOutputHook'; |
48 | | -} |
| 44 | +## Infrastructure |
| 45 | +# Hook our own CSS: |
| 46 | +$wgHooks['OutputPageParserOutput'][] = 'fnBreadCrumbsOutputHook'; |
49 | 47 | |
50 | 48 | ## Load the file containing the hook functions: |
51 | 49 | require_once( 'BreadCrumbsFunctions.php' ); |