r62988 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62987‎ | r62988 | r62989 >
Date:01:19, 26 February 2010
Author:laner
Status:ok
Tags:
Comment:
* Commented default globals
* Changed behavior of modifySidebar() to step through the sidebar array, copy items to a new array, and replace the old array; fixed issues with array_splice
* Group and Category Sidebar pages are now at MediaWiki:Sidebar/Group:<group> and MediaWiki:Sidebar/Category:<category> respectively
* Removed $matches from doGroupSidebar() and doCategorySidebar(), since neither function takes arguments now
Modified paths:
  • /trunk/extensions/DynamicSidebar/DynamicSidebar.body.php (modified) (history)
  • /trunk/extensions/DynamicSidebar/DynamicSidebar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DynamicSidebar/DynamicSidebar.body.php
@@ -26,23 +26,44 @@
2727 global $wgDynamicSidebarUseGroups, $wgDynamicSidebarUseUserpages;
2828 global $wgDynamicSidebarUseCategories;
2929
 30+ $groupSB = array();
 31+ $userSB = array();
 32+ $catSB = array();
3033 if ( $wgDynamicSidebarUseGroups && isset( $sidebar['GROUP-SIDEBAR'] ) ) {
31 - // Replace the GROUP-SIDEBAR entry with the group's sidebar
32 - $groupSB = array();
3334 $skin->addToSidebarPlain( $groupSB, self::doGroupSidebar() );
34 - array_splice( $sidebar, array_search( 'GROUP-SIDEBAR', array_keys( $sidebar ), true ), 1, $groupSB );
3535 }
3636 if ( $wgDynamicSidebarUseUserpages && isset( $sidebar['USER-SIDEBAR'] ) ) {
37 - // Replace the USER-SIDEBAR entry with the user's sidebar
38 - $userSB = array();
3937 $skin->addToSidebarPlain( $userSB, self::doUserSidebar() );
40 - array_splice( $sidebar, array_search( 'USER-SIDEBAR', array_keys( $sidebar ), true ), 1, $userSB );
4138 }
4239 if ( $wgDynamicSidebarUseCategories && isset( $sidebar['CATEGORY-SIDEBAR'] ) ) {
43 - $catSB = array();
4440 $skin->addToSidebarPlain( $catSB, self::doCategorySidebar() );
45 - array_splice( $sidebar, array_search( 'CATEGORY-SIDEBAR', array_keys( $sidebar ), true ), 1, $catSB );
4641 }
 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;
4768 return true;
4869 }
4970
@@ -74,7 +95,7 @@
7596 * @access private
7697 * @return string
7798 */
78 - private static function doGroupSidebar( $matches ) {
 99+ private static function doGroupSidebar() {
79100 global $wgUser;
80101
81102 // Get group membership array.
@@ -89,7 +110,7 @@
90111 foreach ( $groups as $group ) {
91112 // Form the path to the article:
92113 // MediaWiki:Sidebar/<group>
93 - $title = Title::makeTitle( NS_MEDIAWIKI, 'Sidebar/' . $group );
 114+ $title = Title::makeTitle( NS_MEDIAWIKI, 'Sidebar/Group:' . $group );
94115 if ( !$title->exists() ) {
95116 continue;
96117 }
@@ -106,7 +127,7 @@
107128 * @access private
108129 * @return string
109130 */
110 - private static function doCategorySidebar( $matches ) {
 131+ private static function doCategorySidebar() {
111132 global $wgUser;
112133
113134 self::printDebug( "User name: {$wgUser->getName()}" );
@@ -131,12 +152,14 @@
132153
133154 // Form the path to the article:
134155 // MediaWiki:Sidebar/<category>
135 - $title = Title::makeTitle( NS_MEDIAWIKI, 'Sidebar/' . $category );
 156+ $title = Title::makeTitle( NS_MEDIAWIKI, 'Sidebar/Category:' . $category );
136157 if ( !$title->exists() ) {
 158+ self::printDebug( "$category category page doesn't exist." );
137159 continue;
138160 }
139161 $a = new Article( $title );
140162 $text .= $a->getContent() . "\n";
 163+ self::printDebug( "$category text output is: $text" );
141164 }
142165 return $text;
143166 }
Index: trunk/extensions/DynamicSidebar/DynamicSidebar.php
@@ -25,8 +25,14 @@
2626 }
2727
2828 // Set defaults
 29+
 30+// Allow users to create their own custom sidebars under User:<username>/Sidebar
2931 $wgDynamicSidebarUseUserpages = true;
 32+
 33+// Allow group sidebars under MediaWiki:Sidebar/Group:<group>
3034 $wgDynamicSidebarUseGroups = true;
 35+
 36+// Allow category based sidebars under MediaWiki:Sidebar/Group:<category>
3137 $wgDynamicSidebarUseCategories = true;
3238
3339 $wgExtensionCredits['other'][] = array(

Status & tagging log