r62974 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62973‎ | r62974 | r62975 >
Date:20:44, 25 February 2010
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
DynamicSidebar: Fix usage of array_search n r62959
Modified paths:
  • /trunk/extensions/DynamicSidebar/DynamicSidebar.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DynamicSidebar/DynamicSidebar.body.php
@@ -30,18 +30,18 @@
3131 // Replace the GROUP-SIDEBAR entry with the group's sidebar
3232 $groupSB = array();
3333 $skin->addToSidebarPlain( $groupSB, self::doGroupSidebar() );
34 - array_splice( $sidebar, array_search( 'GROUP-SIDEBAR', $sidebar ), 1, $groupSB );
 34+ array_splice( $sidebar, array_search( 'GROUP-SIDEBAR', array_keys( $sidebar ), true ), 1, $groupSB );
3535 }
3636 if ( $wgDynamicSidebarUseUserpages && isset( $sidebar['USER-SIDEBAR'] ) ) {
3737 // Replace the USER-SIDEBAR entry with the user's sidebar
3838 $userSB = array();
3939 $skin->addToSidebarPlain( $userSB, self::doUserSidebar() );
40 - array_splice( $sidebar, array_search( 'USER-SIDEBAR', $sidebar ), 1, $userSB );
 40+ array_splice( $sidebar, array_search( 'USER-SIDEBAR', array_keys( $sidebar ), true ), 1, $userSB );
4141 }
4242 if ( $wgDynamicSidebarUseCategories && isset( $sidebar['CATEGORY-SIDEBAR'] ) ) {
4343 $catSB = array();
4444 $skin->addToSidebarPlain( $catSB, self::doCategorySidebar() );
45 - array_splice( $sidebar, array_search( 'CATEGORY-SIDEBAR', $sidebar ), 1, $catSB );
 45+ array_splice( $sidebar, array_search( 'CATEGORY-SIDEBAR', array_keys( $sidebar ), true ), 1, $catSB );
4646 }
4747 return true;
4848 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r62959DynamicSidebar: Convert to using the existing SkinBuildSidebar hook, so addin...catrope16:00, 25 February 2010

Comments

#Comment by Ryan lane (talk | contribs)   22:21, 25 February 2010

Ugh. array_splice doesn't preserve keys, so,

  • test
    • Test|Test

comes back as:

    [0] => Array
        (
            [0] => Array
                (
                    [text] => Test
                    [href] => /sandbox/index.php/Test
                    [id] => n-test
                    [active] => 
                )

        )

Instead of:

    [test] => Array
        (
            [0] => Array
                (
                    [text] => Test
                    [href] => /sandbox/index.php/Test
                    [id] => n-test
                    [active] => 
                )

        )

Which causes that portion of the sidebar to be replaced with whatever is previously defined as [0].

Status & tagging log