From: MatmaRex Date: Sat, 27 Oct 2012 14:48:06 +0000 (+0200) Subject: CologneBlue rewrite: rework quickbar() once again X-Git-Tag: 1.31.0-rc.0~21788^2~1 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=5e9afaea04e9276964f5669ad7f541278c7227bc;p=lhc%2Fweb%2Fwiklou.git CologneBlue rewrite: rework quickbar() once again * three separate phases: * semantic modifications (adding new portlets, removing langlinks, moving search to top) * filling out special items with content (searchbox, toolbox) * generating the HTML * split new portlets data to a separate function, sidebarAdditions() * fix missing headings for items added as HTML strings instead of a links array (bug 41456) * fix double escaping of some headings Change-Id: Id1889591d1ac78f2b78a55ab225df37278c87b2b --- diff --git a/skins/CologneBlue.php b/skins/CologneBlue.php index 4a03aa09bc..4aa307b062 100644 --- a/skins/CologneBlue.php +++ b/skins/CologneBlue.php @@ -540,13 +540,48 @@ class CologneBlueTemplate extends BaseTemplate { } /** - * @param $heading string - * @return string + * Adds CologneBlue-specific items to the sidebar: qbedit, qbpageoptions and qbmyoptions menus. + * + * @param $bar sidebar data + * @return array modified sidebar data * * @fixed */ - function menuHead( $heading ) { - return "\n
" . htmlspecialchars( $heading ) . "
"; + function sidebarAdditions( $bar ) { + // "This page" and "Edit" menus + // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'], + // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose. + // We also don't use $...['variants'], these are displayed in the top menu. + $content_navigation = $this->data['content_navigation']; + $qbpageoptions = array_merge( + $content_navigation['namespaces'], + array( + 'history' => $content_navigation['views']['history'], + 'watch' => $content_navigation['actions']['watch'], + 'unwatch' => $content_navigation['actions']['unwatch'], + ) + ); + $content_navigation['actions']['watch'] = null; + $content_navigation['actions']['unwatch'] = null; + $qbedit = array_merge( + array( + 'edit' => $content_navigation['views']['edit'], + 'addsection' => $content_navigation['views']['addsection'], + ), + $content_navigation['actions'] + ); + + // Personal tools ("My pages") + $qbmyoptions = $this->getPersonalTools(); + foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) { + $qbmyoptions[$key] = null; + } + + $bar['qbedit'] = $qbedit; + $bar['qbpageoptions'] = $qbpageoptions; + $bar['qbmyoptions'] = $qbmyoptions; + + return $bar; } /** @@ -557,113 +592,76 @@ class CologneBlueTemplate extends BaseTemplate { * * @fixed */ - function quickBar(){ - $s = "\n
"; - - $sep = "
\n"; - - $plain_bar = $this->data['sidebar']; + function quickBar() { + // Massage the sidebar. We want to: + // * place SEARCH at the beginning + // * add new portlets before TOOLBOX (or at the end, if it's missing) + // * remove LANGUAGES (langlinks are displayed elsewhere) + $orig_bar = $this->data['sidebar']; $bar = array(); - - // Massage the sidebar - // We want to place SEARCH at the beginning and a lot of stuff before TOOLBOX (or at the end, if it's missing) - $additions_done = false; - while ( !$additions_done ) { - $bar = array(); // Empty it out - - // Always display search on top - $bar['SEARCH'] = true; - - foreach ( $plain_bar as $heading => $links ) { - if ( $heading == 'TOOLBOX' ) { - if( $links !== NULL ) { - // If this is not a toolbox prosthetic we inserted outselves, fill it out - $plain_bar['TOOLBOX'] = $this->getToolbox(); - } - - // And insert the stuff - - // "This page" and "Edit" menus - // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'], - // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose. - // We also don't use $...['variants'], these are displayed in the top menu. - $content_navigation = $this->data['content_navigation']; - $qbpageoptions = array_merge( - $content_navigation['namespaces'], - array( - 'history' => $content_navigation['views']['history'], - 'watch' => $content_navigation['actions']['watch'], - 'unwatch' => $content_navigation['actions']['unwatch'], - ) - ); - $content_navigation['actions']['watch'] = null; - $content_navigation['actions']['unwatch'] = null; - $qbedit = array_merge( - array( - 'edit' => $content_navigation['views']['edit'], - 'addsection' => $content_navigation['views']['addsection'], - ), - $content_navigation['actions'] - ); - $bar['qbedit'] = $qbedit; - $bar['qbpageoptions'] = $qbpageoptions; - - // Personal tools ("My pages") - $bar['qbmyoptions'] = $this->getPersonalTools(); - foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) { - $bar['qbmyoptions'][$key] = null; - } - - $additions_done = true; - } - - // Re-insert current heading, unless it's SEARCH - if ( $heading != 'SEARCH' ) { - $bar[$heading] = $plain_bar[$heading]; - } + $hasToolbox = false; + + // Always display search first + $bar['SEARCH'] = true; + // Copy everything except for langlinks, inserting new items before toolbox + foreach ( $orig_bar as $heading => $data ) { + if ( $heading == 'TOOLBOX' ) { + // Insert the stuff + $bar = $this->sidebarAdditions( $bar ); + $hasToolbox = true; } - // If TOOLBOX is missing, $additions_done is still false - if ( !$additions_done ) { - $plain_bar['TOOLBOX'] = false; + if ( $heading != 'LANGUAGES' ) { + $bar[$heading] = $data; } } + // If toolbox is missing, add our items at the end + if ( !$hasToolbox ) { + $bar = $this->sidebarAdditions( $bar ); + } - foreach ( $bar as $heading => $links ) { - if ( $heading == 'SEARCH' ) { - $s .= $this->menuHead( wfMessage( 'qbfind' )->text() ); - $s .= $this->searchForm( 'sidebar' ); - } elseif ( $heading == 'LANGUAGES' ) { - // discard these; we display languages below page content - } elseif ( $links ) { - if ( is_array( $links ) ) { - // Use the navigation heading from standard sidebar as the "browse" section - if ( $heading == 'navigation' ) { - $heading = 'qbbrowse'; - } - if ( $heading == 'TOOLBOX' ) { - $heading = 'toolbox'; - } - $headingMsg = wfMessage( $heading ); - $any_link = false; - $t = $this->menuHead( $headingMsg->exists() ? $headingMsg->escaped() : htmlspecialchars( $heading ) ); + // Fill out special sidebar items with content + $orig_bar = $bar; + $bar = array(); + foreach ( $orig_bar as $heading => $data ) { + if ( $heading == 'SEARCH' ) { + $bar['qbfind'] = $this->searchForm( 'sidebar' ); + } elseif ( $heading == 'TOOLBOX' ) { + $bar['toolbox'] = $this->getToolbox(); + } elseif ( $heading == 'navigation' ) { + // Use the navigation heading from standard sidebar as the "browse" section + $bar['qbbrowse'] = $data; + } else { + $bar[$heading] = $data; + } + } - foreach ( $links as $key => $link ) { - // Can be empty due to rampant sidebar massaging we're doing above - if ( $link ) { - $any_link = true; - $t .= $this->makeListItem( $key, $link, array( 'tag' => 'span' ) ) . $sep; - } - } - if ( $any_link ) { - $s .= $t; + // Output the sidebar + $s = "\n
"; + $sep = "
\n"; + foreach ( $bar as $heading => $data ) { + $headingMsg = wfMessage( $heading ); + $headingHTML = "\n
" . ( $headingMsg->exists() ? $headingMsg->escaped() : htmlspecialchars( $heading ) ) . "
"; + + if ( is_array( $data ) ) { + // $data is an array of links + $any_link = false; + $listHTML = ""; + foreach ( $data as $key => $link ) { + // Can be empty due to how the sidebar additions are done + if ( $link ) { + $any_link = true; + $listHTML .= $this->makeListItem( $key, $link, array( 'tag' => 'span' ) ) . $sep; } - } else { - // $links can be a HTML string - $s .= $links; } + if ( $any_link ) { + $s .= $headingHTML . $listHTML; + } + } else { + // $data is a HTML string + $s .= $headingHTML . $data; } }