|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the ToolbarHorizontal 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 Hooks; |
|
30
|
|
|
use Linker; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* ToolbarHorizontal class |
|
34
|
|
|
* |
|
35
|
|
|
* A horizontal toolbar containing standard sidebar items (toolbox, language links). |
|
36
|
|
|
* |
|
37
|
|
|
* The toolbar is an unordered list in a nav element: <nav role="navigation" id="p-tb" > |
|
38
|
|
|
* |
|
39
|
|
|
* @author Stephan Gambke |
|
40
|
|
|
* @since 1.0 |
|
41
|
|
|
* @ingroup Skins |
|
42
|
|
|
*/ |
|
43
|
|
|
class ToolbarHorizontal extends Component { |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Builds the HTML code for this component |
|
47
|
|
|
* |
|
48
|
|
|
* @return String the HTML code |
|
49
|
|
|
*/ |
|
50
|
7 |
|
public function getHtml() { |
|
51
|
|
|
|
|
52
|
7 |
|
$skinTemplate = $this->getSkinTemplate(); |
|
53
|
|
|
|
|
54
|
7 |
|
$ret = $this->indent() . '<!-- ' . htmlspecialchars( $skinTemplate->getMsg( 'toolbox' )->text() ) . '-->' . |
|
55
|
7 |
|
$this->indent() . '<nav class="navbar navbar-default p-tb ' . $this->getClassString() . '" id="p-tb" ' . Linker::tooltip( 'p-tb' ) . ' >' . |
|
56
|
7 |
|
$this->indent( 1 ) . '<ul class="nav navbar-nav small">'; |
|
57
|
|
|
|
|
58
|
7 |
|
$this->indent( 1 ); |
|
59
|
|
|
|
|
60
|
|
|
// insert toolbox items |
|
61
|
7 |
|
if ( !$this->hideTools() ) { |
|
62
|
7 |
|
$ret .= $this->addTools( $skinTemplate ); |
|
63
|
7 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
// insert language links |
|
66
|
7 |
|
if ( !$this->hideLanguages() ) { |
|
67
|
7 |
|
$ret .= $this->addLanguageLinks( $skinTemplate ); |
|
68
|
7 |
|
} |
|
69
|
|
|
|
|
70
|
7 |
|
$ret .= $this->indent( -1 ) . '</ul>' . |
|
71
|
7 |
|
$this->indent( -1 ) . '</nav>' . "\n"; |
|
72
|
|
|
|
|
73
|
7 |
|
return $ret; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param $skinTemplate |
|
78
|
|
|
* @return string |
|
79
|
|
|
* @throws \FatalError |
|
80
|
|
|
* @throws \MWException |
|
81
|
|
|
*/ |
|
82
|
7 |
|
private function addTools( $skinTemplate ) { |
|
83
|
|
|
|
|
84
|
7 |
|
$ret = ''; |
|
85
|
|
|
|
|
86
|
|
|
// TODO: Do we need to care of dropdown menus here? E.g. RSS feeds? See SkinTemplateToolboxEnd.php:1485 |
|
87
|
7 |
|
foreach ( $skinTemplate->getToolbox() as $key => $tbitem ) { |
|
88
|
|
|
$ret .= $this->indent() . $skinTemplate->makeListItem( $key, $tbitem ); |
|
89
|
7 |
|
} |
|
90
|
|
|
|
|
91
|
7 |
|
ob_start(); |
|
92
|
|
|
// We pass an extra 'true' at the end so extensions using BaseTemplateToolbox |
|
93
|
|
|
// can abort and avoid outputting double toolbox links |
|
94
|
7 |
|
Hooks::run( 'SkinTemplateToolboxEnd', array( &$skinTemplate, true ) ); |
|
95
|
7 |
|
$ret .= $this->indent() . ob_get_contents(); |
|
96
|
7 |
|
ob_end_clean(); |
|
97
|
7 |
|
return $ret; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param $skinTemplate |
|
102
|
|
|
* @return string |
|
103
|
|
|
* @throws \MWException |
|
104
|
|
|
*/ |
|
105
|
7 |
|
private function addLanguageLinks( $skinTemplate ) { |
|
106
|
|
|
|
|
107
|
7 |
|
$ret = ''; |
|
108
|
|
|
|
|
109
|
7 |
|
if ( array_key_exists( 'language_urls', $skinTemplate->data ) && $skinTemplate->data[ 'language_urls' ] ) { |
|
110
|
|
|
|
|
111
|
|
|
$ret .= $this->indent() . '<li class="dropdown dropup p-lang" id="p-lang" ' . Linker::tooltip( 'p-lang' ) . ' >' . |
|
112
|
|
|
$this->indent( 1 ) . '<a href="#" data-target="#" class="dropdown-toggle" data-toggle="dropdown">' . |
|
113
|
|
|
htmlspecialchars( $skinTemplate->getMsg( 'otherlanguages' )->text() ) . ' <b class="caret"></b>' . '</a>' . |
|
114
|
|
|
$this->indent() . '<ul class="dropdown-menu" >'; |
|
115
|
|
|
|
|
116
|
|
|
$this->indent( 1 ); |
|
117
|
|
|
foreach ( $skinTemplate->data[ 'language_urls' ] as $key => $langlink ) { |
|
118
|
|
|
$ret .= $this->indent() . $skinTemplate->makeListItem( $key, $langlink, array( 'link-class' => 'small' ) ); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
$ret .= $this->indent( -1 ) . '</ul>' . |
|
122
|
|
|
$this->indent( -1 ) . '</li>'; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
7 |
|
return $ret; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return bool |
|
130
|
|
|
*/ |
|
131
|
7 |
|
private function hideTools() { |
|
132
|
7 |
|
return $this->getDomElement() !== null && filter_var( $this->getDomElement()->getAttribute( 'hideTools' ), FILTER_VALIDATE_BOOLEAN ); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @return bool |
|
137
|
|
|
*/ |
|
138
|
7 |
|
private function hideLanguages() { |
|
139
|
7 |
|
return $this->getDomElement() !== null && filter_var( $this->getDomElement()->getAttribute( 'hideLanguages' ), FILTER_VALIDATE_BOOLEAN ); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|