Index: trunk/extensions/JSBreadCrumbs/JSBreadCrumbs.i18n.php |
— | — | @@ -15,6 +15,11 @@ |
16 | 16 | 'jsbreadcrumbs-desc' => 'Adds a trail of breadcrumbs below the tab bar', |
17 | 17 | 'jsbreadcrumbs-separator' => '»', |
18 | 18 | 'jsbreadcrumbs-leading-description' => 'Navigation trail', |
| 19 | + 'prefs-jsbreadcrumbs' => 'Bread Crumbs', |
| 20 | + 'prefs-jsbreadcrumbs-showsite' => 'Include site name in bread crumbs (useful when used across wikis)', |
| 21 | + 'prefs-jsbreadcrumbs-showcrumbs' => 'Display bread crumbs', |
| 22 | + 'prefs-jsbreadcrumbs-numberofcrumbs' => 'Number of bread crumbs', |
| 23 | + 'prefs-jsbreadcrumbs-numberofcrumbs-max' => 'Maximum 20 bread crumbs', |
19 | 24 | ); |
20 | 25 | |
21 | 26 | /** Afrikaans (Afrikaans) |
Index: trunk/extensions/JSBreadCrumbs/JSBreadCrumbs.php |
— | — | @@ -16,17 +16,19 @@ |
17 | 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | 18 | # http://www.gnu.org/copyleft/gpl.html |
19 | 19 | |
20 | | -$wgJSBreadCrumbsMaxCrumbs = 5; |
21 | 20 | //BreadCrumbsSeparator default set via localization |
22 | 21 | $wgJSBreadCrumbsSeparator = ''; |
23 | 22 | $wgJSBreadCrumbsCookiePath = '/'; |
| 23 | +$wgDefaultUserOptions['jsbreadcrumbs-showcrumbs'] = false; |
| 24 | +$wgDefaultUserOptions['jsbreadcrumbs-showsite'] = false; |
| 25 | +$wgDefaultUserOptions['jsbreadcrumbs-numberofcrumbs'] = 5; |
24 | 26 | |
25 | 27 | // Sets Credits |
26 | 28 | $wgExtensionCredits['other'][] = array( |
27 | 29 | 'path' => __FILE__, |
28 | 30 | 'name' => 'JSBreadCrumbs', |
29 | 31 | 'author' => 'Ryan Lane', |
30 | | - 'version' => '0.3', |
| 32 | + 'version' => '0.4', |
31 | 33 | 'url' => 'http://www.mediawiki.org/wiki/Extension:JSBreadCrumbs', |
32 | 34 | 'descriptionmsg' => 'jsbreadcrumbs-desc', |
33 | 35 | ); |
— | — | @@ -42,3 +44,4 @@ |
43 | 45 | // Registers Hooks |
44 | 46 | $wgHooks['BeforePageDisplay'][] = 'JSBreadCrumbsHooks::addResources'; |
45 | 47 | $wgHooks['MakeGlobalVariablesScript'][] = 'JSBreadCrumbsHooks::addJSVars'; |
| 48 | +$wgHooks['GetPreferences'][] = 'JSBreadCrumbsHooks::addPreferences'; |
\ No newline at end of file |
Index: trunk/extensions/JSBreadCrumbs/js/BreadCrumbs.js |
— | — | @@ -13,20 +13,38 @@ |
14 | 14 | if ( typeof wgJSBreadCrumbsLeadingDescription == "undefined" ) { |
15 | 15 | wgJSBreadCrumbsLeadingDescription = "Navigation trail"; |
16 | 16 | } |
| 17 | + if ( typeof wgJSBreadCrumbsShowSiteName == "undefined" ) { |
| 18 | + wgJSBreadCrumbsShowSiteName = false; |
| 19 | + } |
17 | 20 | |
| 21 | + if ( wgCanonicalSpecialPageName == "Userlogout" ) { |
| 22 | + $j.cookie( 'mwext-bc-title', '', { path: wgJSBreadCrumbsCookiePath } ); |
| 23 | + $j.cookie( 'mwext-bc-url', '', { path: wgJSBreadCrumbsCookiePath } ); |
| 24 | + $j.cookie( 'mwext-bc-site', '', { path: wgJSBreadCrumbsCookiePath } ); |
| 25 | + } |
18 | 26 | // Get the breadcrumbs from the cookies |
19 | 27 | var titleState = ( $j.cookie( 'mwext-bc-title' ) || "" ).split( '|' ); |
20 | 28 | var urlState = ( $j.cookie( 'mwext-bc-url' ) || "" ).split( '|' ); |
| 29 | + var siteState = ( $j.cookie( 'mwext-bc-site' ) || "" ).split( '|' ); |
21 | 30 | |
22 | 31 | // Strip the first title/url if it is empty |
23 | 32 | if ( titleState[0].length == 0 ) { |
24 | 33 | titleState.splice( 0, 1 ); |
25 | 34 | urlState.splice( 0, 1 ); |
| 35 | + siteState.splice( 0, 1 ); |
26 | 36 | } |
27 | 37 | |
| 38 | + // Get the full title |
28 | 39 | var title = wgTitle; |
29 | | - if ( wgCanonicalNamespace.length ) { |
30 | | - title = wgCanonicalNamespace + ":" + wgTitle; |
| 40 | + if ( wgNamespaceNumber != 0 ) { |
| 41 | + // If this is the project namespace, or we aren't showing the site name |
| 42 | + // then add the namespace to the title. This avoids showing the sitename |
| 43 | + // twice when adding pages in the project namespace. |
| 44 | + // TODO: This is an awkward way to do this, and bug prone when the user |
| 45 | + // logs in with a project page in the history. Find a better way. |
| 46 | + if ( wgNamespaceNumber != 4 || !wgJSBreadCrumbsShowSiteName ) { |
| 47 | + title = wgFormattedNamespaces[wgNamespaceNumber] + ":" + wgTitle; |
| 48 | + } |
31 | 49 | } |
32 | 50 | |
33 | 51 | // Remove duplicates |
— | — | @@ -35,16 +53,19 @@ |
36 | 54 | if ( matchTitleIndex != -1 && ( matchUrlIndex == matchTitleIndex ) ) { |
37 | 55 | titleState.splice( matchTitleIndex, 1 ); |
38 | 56 | urlState.splice( matchTitleIndex, 1 ); |
| 57 | + siteState.splice( matchTitleIndex, 1 ); |
39 | 58 | } |
40 | 59 | |
41 | 60 | // Add the current page |
42 | 61 | titleState.push( title ); |
43 | 62 | urlState.push( location.pathname + location.search ); |
| 63 | + siteState.push( wgSiteName ); |
44 | 64 | |
45 | 65 | // Ensure we only display the maximum breadcrumbs set |
46 | 66 | if ( titleState.length > wgJSBreadCrumbsMaxCrumbs ) { |
47 | 67 | titleState = titleState.slice( titleState.length - wgJSBreadCrumbsMaxCrumbs ); |
48 | 68 | urlState = urlState.slice( urlState.length - wgJSBreadCrumbsMaxCrumbs ); |
| 69 | + siteState = siteState.slice( siteState.length - wgJSBreadCrumbsMaxCrumbs ); |
49 | 70 | } |
50 | 71 | |
51 | 72 | // Insert the span we are going to populate |
— | — | @@ -57,15 +78,20 @@ |
58 | 79 | |
59 | 80 | // Add the bread crumbs |
60 | 81 | for ( var i = 0; i < titleState.length; i++ ) { |
61 | | - urltoappend = '<a href="' + urlState[i] + '">' + titleState[i] + '</a> '; |
| 82 | + if ( wgJSBreadCrumbsShowSiteName == true ) { |
| 83 | + urltoappend = '<a href="' + urlState[i] + '">' + siteState[i] + ':' + titleState[i] + '</a> '; |
| 84 | + } else { |
| 85 | + urltoappend = '<a href="' + urlState[i] + '">' + titleState[i] + '</a> '; |
| 86 | + } |
62 | 87 | if ( i < titleState.length - 1 ) { |
63 | | - // Only add the separator if this isn't the last title |
64 | | - urltoappend = urltoappend + wgJSBreadCrumbsSeparator + ' '; |
65 | | - } |
| 88 | + // Only add the separator if this isn't the last title |
| 89 | + urltoappend = urltoappend + wgJSBreadCrumbsSeparator + ' '; |
| 90 | + } |
66 | 91 | mwextbc.append( urltoappend ); |
67 | 92 | } |
68 | 93 | |
69 | 94 | // Save the bread crumb states to the cookies |
70 | 95 | $j.cookie( 'mwext-bc-title', titleState.join( '|' ), { path: wgJSBreadCrumbsCookiePath } ); |
71 | 96 | $j.cookie( 'mwext-bc-url', urlState.join( '|' ), { path: wgJSBreadCrumbsCookiePath } ); |
72 | | -} ); |
| 97 | + $j.cookie( 'mwext-bc-site', siteState.join( '|' ), { path: wgJSBreadCrumbsCookiePath } ); |
| 98 | +}); |
\ No newline at end of file |
Index: trunk/extensions/JSBreadCrumbs/JSBreadCrumbs.hooks.php |
— | — | @@ -1,14 +1,18 @@ |
2 | 2 | <?php |
3 | 3 | class JSBreadCrumbsHooks { |
4 | 4 | |
| 5 | + private static $variables = array(); |
| 6 | + |
5 | 7 | /** |
6 | 8 | * BeforePageDisplay hook |
7 | 9 | */ |
8 | 10 | public static function addResources( $out ) { |
9 | 11 | global $wgExtensionAssetsPath; |
10 | 12 | |
11 | | - $out->addScriptFile( "$wgExtensionAssetsPath/JSBreadCrumbs/js/BreadCrumbs.js", 5 ); |
12 | | - $out->addExtensionStyle( "$wgExtensionAssetsPath/JSBreadCrumbs/css/BreadCrumbs.css?1" ); |
| 13 | + if ( self::enableBreadCrumbs() ) { |
| 14 | + $out->addScriptFile( "$wgExtensionAssetsPath/JSBreadCrumbs/js/BreadCrumbs.js", 6 ); |
| 15 | + $out->addExtensionStyle( "$wgExtensionAssetsPath/JSBreadCrumbs/css/BreadCrumbs.css?1" ); |
| 16 | + } |
13 | 17 | |
14 | 18 | return true; |
15 | 19 | } |
— | — | @@ -17,8 +21,13 @@ |
18 | 22 | * MakeGlobalVariablesScript hook |
19 | 23 | */ |
20 | 24 | public static function addJSVars( $vars ) { |
21 | | - global $wgJSBreadCrumbsMaxCrumbs, $wgJSBreadCrumbsSeparator, $wgJSBreadCrumbsCookiePath; |
| 25 | + global $wgJSBreadCrumbsSeparator, $wgJSBreadCrumbsCookiePath; |
| 26 | + global $wgUser; |
22 | 27 | |
| 28 | + if ( !self::enableBreadCrumbs() ) { |
| 29 | + return true; |
| 30 | + } |
| 31 | + |
23 | 32 | wfLoadExtensionMessages( 'JSBreadCrumbs' ); |
24 | 33 | |
25 | 34 | // Allow localized separator to be overriden |
— | — | @@ -30,12 +39,54 @@ |
31 | 40 | |
32 | 41 | $variables = array(); |
33 | 42 | |
34 | | - $variables['wgJSBreadCrumbsMaxCrumbs'] = $wgJSBreadCrumbsMaxCrumbs; |
| 43 | + $variables['wgJSBreadCrumbsMaxCrumbs'] = $wgUser->getOption( "jsbreadcrumbs-numberofcrumbs" ); |
35 | 44 | $variables['wgJSBreadCrumbsSeparator'] = $separator; |
36 | 45 | $variables['wgJSBreadCrumbsCookiePath'] = $wgJSBreadCrumbsCookiePath; |
37 | 46 | $variables['wgJSBreadCrumbsLeadingDescription'] = wfMsg( "jsbreadcrumbs-leading-description" ); |
| 47 | + $variables['wgJSBreadCrumbsShowSiteName'] = $wgUser->getOption( "jsbreadcrumbs-showsite" ); |
38 | 48 | |
39 | 49 | $vars = array_merge( $vars, $variables ); |
| 50 | + |
40 | 51 | return true; |
41 | 52 | } |
| 53 | + |
| 54 | + /** |
| 55 | + * GetPreferences hook |
| 56 | + * |
| 57 | + * Add module-releated items to the preferences |
| 58 | + */ |
| 59 | + public static function addPreferences( $user, $defaultPreferences ) { |
| 60 | + $defaultPreferences['jsbreadcrumbs-showcrumbs'] = array( |
| 61 | + 'type' => 'toggle', |
| 62 | + 'label-message' => 'prefs-jsbreadcrumbs-showcrumbs', |
| 63 | + 'section' => 'rendering/jsbreadcrumbs', |
| 64 | + ); |
| 65 | + |
| 66 | + $defaultPreferences['jsbreadcrumbs-showsite'] = array( |
| 67 | + 'type' => 'toggle', |
| 68 | + 'label-message' => 'prefs-jsbreadcrumbs-showsite', |
| 69 | + 'section' => 'rendering/jsbreadcrumbs', |
| 70 | + ); |
| 71 | + |
| 72 | + $defaultPreferences['jsbreadcrumbs-numberofcrumbs'] = array( |
| 73 | + 'type' => 'int', |
| 74 | + 'min' => 1, |
| 75 | + 'max' => 20, |
| 76 | + 'section' => 'rendering/jsbreadcrumbs', |
| 77 | + 'help' => wfMsgHtml( 'prefs-jsbreadcrumbs-numberofcrumbs-max' ), |
| 78 | + 'label-message' => 'prefs-jsbreadcrumbs-numberofcrumbs', |
| 79 | + ); |
| 80 | + |
| 81 | + return true; |
| 82 | + } |
| 83 | + |
| 84 | + static function enableBreadCrumbs() { |
| 85 | + global $wgUser; |
| 86 | + |
| 87 | + // Ensure we only enable bread crumbs if we are using vector and |
| 88 | + // the user has them enabled |
| 89 | + if ( $wgUser->getSkin() instanceof SkinVector && $wgUser->getOption( "jsbreadcrumbs-showcrumbs" ) ) { |
| 90 | + return true; |
| 91 | + } |
| 92 | + } |
42 | 93 | } |