From 19ade0cc7efbb1b4a82380ed1787dc1aba3ce299 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Tue, 27 Sep 2011 05:31:57 +0000 Subject: [PATCH] Add getSidebar method to BaseTemplate to simplify the sidebar boilerplate. --- includes/SkinTemplate.php | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index b4f299aba0..c972c31868 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -1501,6 +1501,92 @@ abstract class BaseTemplate extends QuickTemplate { return $personal_tools; } + function getSidebar( $options = array() ) { + // Force the rendering of the following portals + $sidebar = $this->data['sidebar']; + if ( !isset( $sidebar['SEARCH'] ) ) { + $sidebar['SEARCH'] = true; + } + if ( !isset( $sidebar['TOOLBOX'] ) ) { + $sidebar['TOOLBOX'] = true; + } + if ( !isset( $sidebar['LANGUAGES'] ) ) { + $sidebar['LANGUAGES'] = true; + } + + if ( !isset( $options['search'] ) || $options['search'] !== true ) { + unset( $sidebar['SEARCH'] ); + } + if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) { + unset( $sidebar['TOOLBOX'] ); + } + if ( isset( $options['languages'] ) && $options['languages'] === false ) { + unset( $sidebar['LANGUAGES'] ); + } + + $boxes = array(); + foreach ( $sidebar as $boxName => $content ) { + if ( $content === false ) { + continue; + } + switch ( $boxName ) { + case 'SEARCH': + // Search is a special case, skins should custom implement this + $boxes[$boxName] = array( + 'id' => "p-search", + 'header' => wfMessage( 'search' )->text(), + 'generated' => false, + 'content' => true, + ); + break; + case 'TOOLBOX': + $msgObj = wfMessage( 'toolbox' ); + $boxes[$boxName] = array( + 'id' => "p-tb", + 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox', + 'generated' => false, + 'content' => $this->getToolbox(), + ); + break; + case 'LANGUAGES': + if ( $this->data['language_urls'] ) { + $msgObj = wfMessage( 'otherlanguages' ); + $boxes[$boxName] = array( + 'id' => "p-lang", + 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages', + 'generated' => false, + 'content' => $this->data['language_urls'], + ); + } + break; + default: + $msgObj = wfMessage( $boxName ); + $boxes[$boxName] = array( + 'id' => "p-$boxName", + 'header' => htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $boxName ), + 'generated' => true, + 'content' => $content, + ); + break; + } + } + + if ( !isset($options['withLists']) || $options['withLists'] !== true ) { + foreach ( $boxes as $boxName => $box ) { + if ( is_array( $box['content'] ) ) { + $content = "\n"; + $boxes[$boxName]['content'] = $content; + } + } + } + + return $boxes; + } + /** * Makes a link, usually used by makeListItem to generate a link for an item * in a list used in navigation lists, portlets, portals, sidebars, etc... -- 2.20.1