GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#5)
by mw
13:19
created

NavMenu::isMarkedToUseLanguageLinksInNavMenu()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * File holding the NavMenu class
4
 *
5
 * This file is part of the MediaWiki skin Chameleon.
6
 *
7
 * @copyright 2013 - 2014, Stephan Gambke
8
 * @license   GNU General Public License, version 3 (or any later version)
9
 *
10
 * The Chameleon skin is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by the Free
12
 * Software Foundation, either version 3 of the License, or (at your option) any
13
 * later version.
14
 *
15
 * The Chameleon skin is distributed in the hope that it will be useful, but
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18
 * details.
19
 *
20
 * You should have received a copy of the GNU General Public License along
21
 * with this program. If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 * @file
24
 * @ingroup   Skins
25
 */
26
27
namespace Skins\Chameleon\Components;
28
29
use Linker;
30
use Skins\Chameleon\IdRegistry;
31
32
/**
33
 * The NavMenu class.
34
 *
35
 * @author  Stephan Gambke
36
 * @since   1.0
37
 * @ingroup Skins
38
 */
39
class NavMenu extends Component {
40
41
	/**
42
	 * Builds the HTML code for this component
43
	 *
44
	 * @return string the HTML code
45
	 */
46 7
	public function getHtml() {
47
48 7
		$ret = '';
49
50 7
		// LANGUAGES is always part of the sidebar array, so use "languages" as
51 7
		// indicator for what the user wants
52 7
53 7
		$sidebar = $this->getSkinTemplate()->getSidebar( array(
54
				'search' => false, 'toolbox' => false, 'languages' => $this->isMarkedToUseLanguageLinksInNavMenu()
55 7
			)
56
		);
57 7
58
		// Copy content to the position
59 7
		if ( isset( $sidebar['LANGUAGES'] ) ) {
60 6
			$sidebar['languages'] = $sidebar['LANGUAGES'];
61 6
			unset( $sidebar['LANGUAGES'] );
62 1
		} else {
63
			unset( $sidebar['languages'] );
64
		}
65
66 7
		$msg = \Message::newFromKey( 'skin-chameleon-navmenu-flatten' );
67
68 7
		if ( $msg->exists() ) {
69
			$flatten = array_map( 'trim', explode( ';', $msg->plain() ) );
70 7
		} elseif ( $this->getDomElement() !== null ) {
71
			$flatten = array_map( 'trim', explode( ';', $this->getDomElement()->getAttribute( 'flatten' ) ) );
72
		} else {
73
			$flatten = array();
74
		}
75
76
		// create a dropdown for each sidebar box
77
		foreach ( $sidebar as $menuName => $menuDescription ) {
78
			$ret .= $this->getDropdownForNavMenu( $menuName, $menuDescription, array_search( $menuName, $flatten ) !== false );
79
		}
80
81
		return $ret;
82
	}
83
84
	// Did a user deliberately choose a languages list for the NavMenu?
85
	private function isMarkedToUseLanguageLinksInNavMenu() {
86
87
		$keys = array_keys(
88
			$this->getSkinTemplate()->getSidebar()
89
		);
90
91
		return array_search( 'languages', $keys ) !== false;
92
	}
93
94
	/**
95
	 * Create a single dropdown
96
	 *
97
	 * @param string  $menuName
98
	 * @param mixed[] $menuDescription
99
	 * @param bool    $flatten
100
	 *
101
	 * @return string
102
	 */
103
	protected function getDropdownForNavMenu( $menuName, $menuDescription, $flatten = false ) {
104
105
		// open list item containing the dropdown
106
		$ret = $this->indent() . '<!-- ' . $menuName . ' -->';
107
108
		if ( $flatten ) {
109
110
			$ret .= $this->buildMenuItemsForDropdownMenu( $menuDescription );
111
112
		} elseif ( !$this->hasSubmenuItems( $menuDescription ) ) {
113
114
			$ret .= $this->buildDropdownMenuStub( $menuDescription );
115
116
		} else {
117
118
			$ret .= $this->buildDropdownOpeningTags( $menuDescription )
119
				. $this->buildMenuItemsForDropdownMenu( $menuDescription, 2 )
120
				. $this->buildDropdownClosingTags();
121
122
123
		}
124
125
		return $ret;
126
	}
127
128
	/**
129
	 * @param mixed[] $menuDescription
130
	 * @param int     $indent
131
	 *
132
	 * @return string
133
	 */
134
	protected function buildMenuItemsForDropdownMenu( $menuDescription, $indent = 0 ) {
135
136
		// build the list of submenu items
137
		if ( $this->hasSubmenuItems( $menuDescription ) ) {
138
139
			$menuitems = '';
140
			$this->indent( $indent );
141
142
			foreach ( $menuDescription[ 'content' ] as $key => $item ) {
143
				$menuitems .= $this->indent() . $this->getSkinTemplate()->makeListItem( $key, $item );
144
			}
145
146
			$this->indent( -$indent );
147
			return $menuitems;
148
149
		} else {
150
			return $this->indent() . '<!-- empty -->';
151
		}
152
	}
153
154
	/**
155
	 * @param mixed[] $menuDescription
156
	 *
157
	 * @return bool
158
	 */
159
	protected function hasSubmenuItems( $menuDescription ) {
160
		return is_array( $menuDescription[ 'content' ] ) && count( $menuDescription[ 'content' ] ) > 0;
161
	}
162
163
	/**
164
	 * @param mixed[] $menuDescription
165
	 *
166
	 * @return string
167
	 */
168
	protected function buildDropdownMenuStub( $menuDescription ) {
169
		return
170
			$this->indent() . \Html::rawElement( 'li',
171
				array(
172
					'class' => '',
173
					'title' => Linker::titleAttrib( $menuDescription[ 'id' ] )
174
				),
175
				'<a href="#">' . htmlspecialchars( $menuDescription[ 'header' ] ) . '</a>'
176
			);
177
	}
178
179
	/**
180
	 * @param mixed[] $menuDescription
181
	 *
182
	 * @return string
183
	 */
184
	protected function buildDropdownOpeningTags( $menuDescription ) {
185
		// open list item containing the dropdown
186
		$ret = $this->indent() . \Html::openElement( 'li',
187
				array(
188
					'class' => 'dropdown',
189
					'title' => Linker::titleAttrib( $menuDescription[ 'id' ] )
190
				)
191
			);
192
193
		// add the dropdown toggle
194
		$ret .= $this->indent( 1 ) . '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' .
195
			htmlspecialchars( $menuDescription[ 'header' ] ) . ' <b class="caret"></b></a>';
196
197
		// open list of dropdown menu items
198
		$ret .= $this->indent() .
199
			$this->indent() . \Html::openElement( 'ul',
200
				array(
201
					'class' => 'dropdown-menu ' . $menuDescription[ 'id' ],
202
					'id'    => IdRegistry::getRegistry()->getId( $menuDescription[ 'id' ] ),
203
				)
204
			);
205
		return $ret;
206
	}
207
208
	/**
209
	 * @return string
210
	 */
211
	protected function buildDropdownClosingTags() {
212
		return
213
			$this->indent() . '</ul>' .
214
			$this->indent( -1 ) . '</li>';
215
	}
216
217
}
218