Index: trunk/extensions/DynamicSidebar/DynamicSidebar.body.php |
— | — | @@ -26,23 +26,44 @@ |
27 | 27 | global $wgDynamicSidebarUseGroups, $wgDynamicSidebarUseUserpages; |
28 | 28 | global $wgDynamicSidebarUseCategories; |
29 | 29 | |
| 30 | + $groupSB = array(); |
| 31 | + $userSB = array(); |
| 32 | + $catSB = array(); |
30 | 33 | if ( $wgDynamicSidebarUseGroups && isset( $sidebar['GROUP-SIDEBAR'] ) ) { |
31 | | - // Replace the GROUP-SIDEBAR entry with the group's sidebar |
32 | | - $groupSB = array(); |
33 | 34 | $skin->addToSidebarPlain( $groupSB, self::doGroupSidebar() ); |
34 | | - array_splice( $sidebar, array_search( 'GROUP-SIDEBAR', array_keys( $sidebar ), true ), 1, $groupSB ); |
35 | 35 | } |
36 | 36 | if ( $wgDynamicSidebarUseUserpages && isset( $sidebar['USER-SIDEBAR'] ) ) { |
37 | | - // Replace the USER-SIDEBAR entry with the user's sidebar |
38 | | - $userSB = array(); |
39 | 37 | $skin->addToSidebarPlain( $userSB, self::doUserSidebar() ); |
40 | | - array_splice( $sidebar, array_search( 'USER-SIDEBAR', array_keys( $sidebar ), true ), 1, $userSB ); |
41 | 38 | } |
42 | 39 | if ( $wgDynamicSidebarUseCategories && isset( $sidebar['CATEGORY-SIDEBAR'] ) ) { |
43 | | - $catSB = array(); |
44 | 40 | $skin->addToSidebarPlain( $catSB, self::doCategorySidebar() ); |
45 | | - array_splice( $sidebar, array_search( 'CATEGORY-SIDEBAR', array_keys( $sidebar ), true ), 1, $catSB ); |
46 | 41 | } |
| 42 | + |
| 43 | + $sidebar_copy = array(); |
| 44 | + |
| 45 | + foreach ( $sidebar as $sidebar_key => $sidebar_item ) { |
| 46 | + if ( $sidebar_key == 'GROUP-SIDEBAR' ) { |
| 47 | + // Replace the GROUP-SIDEBAR entry with the group's sidebar |
| 48 | + foreach ( $groupSB as $groupSBkey => $groupSBvalue ) { |
| 49 | + $sidebar_copy[$groupSBkey] = $groupSBvalue; |
| 50 | + } |
| 51 | + } else if ( $sidebar_key == 'USER-SIDEBAR' ) { |
| 52 | + // Replace the USER-SIDEBAR entry with the user's sidebar |
| 53 | + foreach ( $userSB as $userSBkey => $userSBvalue ) { |
| 54 | + $sidebar_copy[$userSBkey] = $userSBvalue; |
| 55 | + } |
| 56 | + } else if ( $sidebar_key == 'CATEGORY-SIDEBAR' ) { |
| 57 | + // Replace the CATEGORY-SIDEBAR entry with the category's sidebar |
| 58 | + foreach ( $catSB as $catSBkey => $catSBvalue ) { |
| 59 | + $sidebar_copy[$catSBkey] = $catSBvalue; |
| 60 | + } |
| 61 | + } else { |
| 62 | + // Add the original array item back |
| 63 | + $sidebar_copy[$sidebar_key] = $sidebar_item; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + $sidebar = $sidebar_copy; |
47 | 68 | return true; |
48 | 69 | } |
49 | 70 | |
— | — | @@ -74,7 +95,7 @@ |
75 | 96 | * @access private |
76 | 97 | * @return string |
77 | 98 | */ |
78 | | - private static function doGroupSidebar( $matches ) { |
| 99 | + private static function doGroupSidebar() { |
79 | 100 | global $wgUser; |
80 | 101 | |
81 | 102 | // Get group membership array. |
— | — | @@ -89,7 +110,7 @@ |
90 | 111 | foreach ( $groups as $group ) { |
91 | 112 | // Form the path to the article: |
92 | 113 | // MediaWiki:Sidebar/<group> |
93 | | - $title = Title::makeTitle( NS_MEDIAWIKI, 'Sidebar/' . $group ); |
| 114 | + $title = Title::makeTitle( NS_MEDIAWIKI, 'Sidebar/Group:' . $group ); |
94 | 115 | if ( !$title->exists() ) { |
95 | 116 | continue; |
96 | 117 | } |
— | — | @@ -106,7 +127,7 @@ |
107 | 128 | * @access private |
108 | 129 | * @return string |
109 | 130 | */ |
110 | | - private static function doCategorySidebar( $matches ) { |
| 131 | + private static function doCategorySidebar() { |
111 | 132 | global $wgUser; |
112 | 133 | |
113 | 134 | self::printDebug( "User name: {$wgUser->getName()}" ); |
— | — | @@ -131,12 +152,14 @@ |
132 | 153 | |
133 | 154 | // Form the path to the article: |
134 | 155 | // MediaWiki:Sidebar/<category> |
135 | | - $title = Title::makeTitle( NS_MEDIAWIKI, 'Sidebar/' . $category ); |
| 156 | + $title = Title::makeTitle( NS_MEDIAWIKI, 'Sidebar/Category:' . $category ); |
136 | 157 | if ( !$title->exists() ) { |
| 158 | + self::printDebug( "$category category page doesn't exist." ); |
137 | 159 | continue; |
138 | 160 | } |
139 | 161 | $a = new Article( $title ); |
140 | 162 | $text .= $a->getContent() . "\n"; |
| 163 | + self::printDebug( "$category text output is: $text" ); |
141 | 164 | } |
142 | 165 | return $text; |
143 | 166 | } |
Index: trunk/extensions/DynamicSidebar/DynamicSidebar.php |
— | — | @@ -25,8 +25,14 @@ |
26 | 26 | } |
27 | 27 | |
28 | 28 | // Set defaults |
| 29 | + |
| 30 | +// Allow users to create their own custom sidebars under User:<username>/Sidebar |
29 | 31 | $wgDynamicSidebarUseUserpages = true; |
| 32 | + |
| 33 | +// Allow group sidebars under MediaWiki:Sidebar/Group:<group> |
30 | 34 | $wgDynamicSidebarUseGroups = true; |
| 35 | + |
| 36 | +// Allow category based sidebars under MediaWiki:Sidebar/Group:<category> |
31 | 37 | $wgDynamicSidebarUseCategories = true; |
32 | 38 | |
33 | 39 | $wgExtensionCredits['other'][] = array( |