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
Push — master ( 207288...add4fc )
by
unknown
15:26
created

NavMenu::showTools()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 1
cp 0
rs 10
cc 2
eloc 2
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * File holding the NavMenu class
4
 *
5
 * This file is part of the MediaWiki skin Chameleon.
6
 *
7
 * @copyright 2013 - 2016, 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
		$sidebar = $this->getSkinTemplate()->getSidebar( array(
51 7
				'search' => false, 'toolbox' => $this->showTools(), 'languages' => $this->showLanguages()
52 7
			)
53 7
		);
54
55 7
		$msg = \Message::newFromKey( 'skin-chameleon-navmenu-flatten' );
56
57 7
		if ( $msg->exists() ) {
58
			$flatten = array_map( 'trim', explode( ';', $msg->plain() ) );
59 7
		} elseif ( $this->getDomElement() !== null ) {
60 6
			$flatten = array_map( 'trim', explode( ';', $this->getDomElement()->getAttribute( 'flatten' ) ) );
61 6
		} else {
62 1
			$flatten = array();
63
		}
64
65
		// create a dropdown for each sidebar box
66 7
		foreach ( $sidebar as $menuName => $menuDescription ) {
67
			$ret .= $this->getDropdownForNavMenu( $menuName, $menuDescription, array_search( $menuName, $flatten ) !== false );
68 7
		}
69
70 7
		return $ret;
71
	}
72
73
	/**
74
	 * @return bool
75
	 */
76
	private function showLanguages() {
77
		return $this->getDomElement() !== null && filter_var( $this->getDomElement()->getAttribute( 'showLanguages' ), FILTER_VALIDATE_BOOLEAN );
78
	}
79
80
	/**
81
	 * @return bool
82
	 */
83
	private function showTools() {
84
		return $this->getDomElement() !== null && filter_var( $this->getDomElement()->getAttribute( 'showTools' ), FILTER_VALIDATE_BOOLEAN );
85
	}
86
87
	/**
88
	 * Create a single dropdown
89
	 *
90
	 * @param string  $menuName
91
	 * @param mixed[] $menuDescription
92
	 * @param bool    $flatten
93
	 *
94
	 * @return string
95
	 */
96
	protected function getDropdownForNavMenu( $menuName, $menuDescription, $flatten = false ) {
97
98
		// open list item containing the dropdown
99
		$ret = $this->indent() . '<!-- ' . $menuName . ' -->';
100
101
		if ( $flatten ) {
102
103
			$ret .= $this->buildMenuItemsForDropdownMenu( $menuDescription );
104
105
		} elseif ( !$this->hasSubmenuItems( $menuDescription ) ) {
106
107
			$ret .= $this->buildDropdownMenuStub( $menuDescription );
108
109
		} else {
110
111
			$ret .= $this->buildDropdownOpeningTags( $menuDescription )
112
				. $this->buildMenuItemsForDropdownMenu( $menuDescription, 2 )
113
				. $this->buildDropdownClosingTags();
114
115
116
		}
117
118
		return $ret;
119
	}
120
121
	/**
122
	 * @param mixed[] $menuDescription
123
	 * @param int     $indent
124
	 *
125
	 * @return string
126
	 */
127
	protected function buildMenuItemsForDropdownMenu( $menuDescription, $indent = 0 ) {
128
129
		// build the list of submenu items
130
		if ( $this->hasSubmenuItems( $menuDescription ) ) {
131
132
			$menuitems = '';
133
			$this->indent( $indent );
134
135
			foreach ( $menuDescription[ 'content' ] as $key => $item ) {
136
				$menuitems .= $this->indent() . $this->getSkinTemplate()->makeListItem( $key, $item );
137
			}
138
139
			$this->indent( -$indent );
140
			return $menuitems;
141
142
		} else {
143
			return $this->indent() . '<!-- empty -->';
144
		}
145
	}
146
147
	/**
148
	 * @param mixed[] $menuDescription
149
	 *
150
	 * @return bool
151
	 */
152
	protected function hasSubmenuItems( $menuDescription ) {
153
		return is_array( $menuDescription[ 'content' ] ) && count( $menuDescription[ 'content' ] ) > 0;
154
	}
155
156
	/**
157
	 * @param mixed[] $menuDescription
158
	 *
159
	 * @return string
160
	 */
161
	protected function buildDropdownMenuStub( $menuDescription ) {
162
		return
163
			$this->indent() . \Html::rawElement( 'li',
164
				array(
165
					'class' => '',
166
					'title' => Linker::titleAttrib( $menuDescription[ 'id' ] )
167
				),
168
				'<a href="#">' . htmlspecialchars( $menuDescription[ 'header' ] ) . '</a>'
169
			);
170
	}
171
172
	/**
173
	 * @param mixed[] $menuDescription
174
	 *
175
	 * @return string
176
	 */
177
	protected function buildDropdownOpeningTags( $menuDescription ) {
178
		// open list item containing the dropdown
179
		$ret = $this->indent() . \Html::openElement( 'li',
180
				array(
181
					'class' => 'dropdown',
182
					'title' => Linker::titleAttrib( $menuDescription[ 'id' ] )
183
				)
184
			);
185
186
		// add the dropdown toggle
187
		$ret .= $this->indent( 1 ) . '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' .
188
			htmlspecialchars( $menuDescription[ 'header' ] ) . ' <b class="caret"></b></a>';
189
190
		// open list of dropdown menu items
191
		$ret .= $this->indent() .
192
			$this->indent() . \Html::openElement( 'ul',
193
				array(
194
					'class' => 'dropdown-menu ' . $menuDescription[ 'id' ],
195
					'id'    => IdRegistry::getRegistry()->getId( $menuDescription[ 'id' ] ),
196
				)
197
			);
198
		return $ret;
199
	}
200
201
	/**
202
	 * @return string
203
	 */
204
	protected function buildDropdownClosingTags() {
205
		return
206
			$this->indent() . '</ul>' .
207
			$this->indent( -1 ) . '</li>';
208
	}
209
210
}
211