This repository has been archived by the owner on May 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
BootstrapTemplate.php
executable file
·492 lines (445 loc) · 12.6 KB
/
BootstrapTemplate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
<?php
/**
* BaseTemplate class for the Bootstap skin
*
* @ingroup Skins
*/
class BootstrapTemplate extends BaseTemplate {
public function renderWikiNavbarLinks() {
echo '<ul class="navbar-nav">';
$content_navigation_views = $this->data['content_navigation']['views'];
if ( is_array($content_navigation_views) ) {
$nav_ = null;
foreach ( $content_navigation_views as $key => $item ) {
$item['class'] = 'nav-item';
$nav_ .= $this->makeListItem( $key, $item , array('tag' => 'li', 'link-class' => 'nav-link'));
}
echo $nav_;
}
echo $this->getPageLinks();
echo '<li class="nav-item">';
echo $this->getUserLinks();
echo '</li>';
echo '</ul>';
}
/**
* Outputs the entire contents of the page
*/
public function execute() {
$this->html( 'headelement' );
$body = $this->data['bodycontent'];
// Use DeToc class to extract the TOC from the body
$new_body = DeToc::ExtractToc($body, $extracted_toc);
include('_navbar_developer.php');
?>
<nav class="navbar navbar-expand flex-column flex-md-row bd-navbar">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item"><a class="nav-link" href="/">Developer Documentation</a></li>
</ul>
<div>
<?php
$this->renderWikiNavbarLinks();
?>
</div>
</div>
</nav>
<div id="mw-wrapper" class="container-fluid">
<div class="row flex-xl-nowrap">
<div class="col-12 col-md-3 col-xl-2 bd-sidebar">
<?php echo $this->getSearch(); ?>
<?php
foreach ( $this->getSidebar() as $boxName => $box ) {
// We ignore some navigation sections. They need to exist in the first place
// because they are accessed from $sidebar and they populate the navigation.
$ignored_navigation_sections = array('TOOLBOX', 'navigation');
if (in_array($boxName, $ignored_navigation_sections)) {
continue;
}
?>
<div id="<?php echo Sanitizer::escapeId( $box['id'] ) ?>"<?php echo Linker::tooltip( $box['id'] ) ?>>
<h5><?php echo htmlspecialchars( $box['header'] ); ?></h5>
<!-- If you do not want the words "Navigation" or "Tools" to appear, you can safely remove the line above. -->
<?php
if ( is_array( $box['content'] ) ) { ?>
<ul>
<?php
foreach ( $box['content'] as $key => $item ) {
echo $this->makeListItem( $key, $item );
}
?>
</ul>
<?php
} else {
echo $box['content'];
}
?>
</div>
<?php } ?>
</div>
<?php
// Only if $extracted_toc is available, create the column
if ( $extracted_toc ) { ?>
<div class="d-none d-xl-block col-xl-2 bd-toc">
<?php echo $extracted_toc; ?>
</div>
<?php } ?>
<?php
// Define the width of bd_content (the main container) depending if the TOC is
// available or not. In particular set the col-xl size, since it's the only case
// where we display the TOC.
if ( $extracted_toc ) {
$bd_content_col_xl_width = 'col-xl-8';
$padding = 'pl-md-5';
} else {
$bd_content_col_xl_width = 'col-xl-10';
$padding = 'px-md-5';
}
?>
<div class="col-12 col-md-9 <?php echo $bd_content_col_xl_width; ?> py-md-3 <?php echo $padding; ?> bd-content" role="main">
<?php
if ( $this->data['sitenotice'] ) {
echo Html::rawElement(
'div',
array( 'id' => 'siteNotice' ),
$this->get( 'sitenotice' )
);
}
if ( $this->data['newtalk'] ) {
echo Html::rawElement(
'div',
array( 'class' => 'usermessage' ),
$this->get( 'newtalk' )
);
}
echo $this->getIndicators();
// Automatic page title from URL
echo Html::rawElement(
'h1',
array(
'class' => 'firstHeading',
'lang' => $this->get( 'pageLanguage' )
),
$this->get( 'title' )
);
// Do not display tagline
// echo Html::rawElement(
// 'div',
// array( 'id' => 'siteSub' ),
// $this->getMsg( 'tagline' )->parse()
// );
?>
<div class="mw-body-content">
<?php
echo Html::openElement(
'div',
array( 'id' => 'contentSub' )
);
if ( $this->data['subtitle'] ) {
echo Html::rawelement (
'p',
[],
$this->get( 'subtitle' )
);
}
echo Html::rawelement (
'p',
[],
$this->get( 'undelete' )
);
echo Html::closeElement( 'div' );
// $this->html( 'bodycontent' );
echo $new_body;
$this->clear();
echo Html::rawElement(
'div',
array( 'class' => 'printfooter' ),
$this->get( 'printfooter' )
);
// $this->html( 'catlinks' );
$this->html( 'dataAfterContent' );
?>
</div>
</div>
</div>
</div>
<!-- Footer -->
<footer class="footer pt-4">
<!-- Footer Links -->
<div class="container-fluid text-md-left">
<!-- Grid row -->
<div class="row">
<?php
foreach ( $this->getFooterLinks() as $category => $links ) {
if ( $category == 'info' ) {
$divClasses = 'col-md-3 mt-md-0 mt-3';
$linkElement = 'p';
} else {
$divClasses = 'col-md-3 mt-md-0 mt-3';
$linkElement = 'li';
}
echo Html::openElement(
'div',
array(
'class' => $divClasses
)
);
echo Html::element(
'h5',
array(
'class' => 'text-uppercase'
),
$category
);
if ( $category != 'info' ) {
echo Html::openElement(
'ul',
array(
'id' => 'footer-' . Sanitizer::escapeId( $category ),
'role' => 'contentinfo'
)
);
}
foreach ( $links as $key ) {
echo Html::rawElement(
$linkElement,
array(
'id' => 'footer-' . Sanitizer::escapeId( $category . '-' . $key )
),
$this->get( $key )
);
}
if ( $category != 'info' ) {
echo Html::closeElement( 'ul' );
}
echo Html::closeElement( 'div' );
}
// Third footer column
echo Html::openElement('div', array('class' => 'col-md-3 mt-md-0 mt-3',));
echo Html::element('h5', array('class' => 'text-uppercase'), 'Utilities');
$sidebar = $this->getSidebar();
echo $this->getFooterMenu($sidebar['TOOLBOX']);
echo Html::closeElement( 'div' );
// Fourth footer column
echo Html::openElement('div', array('class' => 'col-md-3 mt-md-0 mt-3',));
echo Html::element('h5', array('class' => 'text-uppercase'), 'Navigation');
echo $this->getFooterMenu($sidebar['navigation']);
echo Html::closeElement( 'div' );
?>
</div>
<!-- Grid row -->
<!-- Grid row -->
<div class="row pt-4 pb-4">
<div class="col">
<!-- Copyright -->
<div class="text-center">Creative freedom starts with Blender – The Free and Open Source 3D Creation Suite
</div>
<!-- Copyright -->
</div>
</div>
<!-- Grid row -->
</div>
<!-- Footer Links -->
</footer>
<!-- Footer -->
<?php $this->printTrail() ?>
</body>
</html>
<?php
}
/**
* Generates the content of a dropdown menu
* @return string html
*/
private function getNavDropDownContent( $links, $appendDivider = false) {
if ( !is_array( $links ) || empty( $links ) ) {
return;
}
$html = '';
foreach ( $links as $key => $item ) {
$html .= $this->makeListItem( $key, $item , array('tag' => 'span', 'link-class' => 'dropdown-item'));
// $html .= $this->makeLink( $key, $item['links'][0], array('link-class' => 'dropdown-item') );
}
if ( $appendDivider ) {
$html .= Html::element('div', array('class' => 'dropdown-divider'));
}
return $html;
}
/**
* Generates a dropdown menu
* @return string html
*/
private function getNavDropDown( $box ) {
if ( !$box['content'] ) {
return;
}
$html = Html::openElement(
'li',
array(
'class' => 'nav-item dropdown',
'id' => Sanitizer::escapeId( $box['id'] )
) + Linker::tooltipAndAccesskeyAttribs( $box['id'] )
);
$html .= Html::element(
'a',
array(
'class' => 'nav-link dropdown-toggle',
'role' => 'button',
'data-toggle' => 'dropdown' ),
isset( $box['headerMessage'] ) ? $this->getMsg( $box['headerMessage'] )->text() : $box['header'] );
if ( is_array( $box['content'] ) ) {
$html .= Html::openElement( 'div', array('class' => 'dropdown-menu dropdown-menu-right') );
foreach ( $box['content'] as $key => $item ) {
$html .= $this->makeListItem( $key, $item , array('tag' => 'span', 'link-class' => 'dropdown-item'));
// $html .= $this->makeLink( $key, $item['links'][0], array('link-class' => 'dropdown-item') );
}
$html .= Html::closeElement( 'div' );
} else {
$html .= $box['content'];
}
$html .= Html::closeElement( 'li' );
return $html;
}
private function getFooterMenu( $box ) {
if ( !$box['content'] ) {
return;
}
$html = Html::openElement(
'ul',
array(
'id' => Sanitizer::escapeId( $box['id'] )
) + Linker::tooltipAndAccesskeyAttribs( $box['id'] )
);
if ( is_array( $box['content'] ) ) {
foreach ( $box['content'] as $key => $item ) {
$html .= $this->makeListItem( $key, $item , array('tag' => 'li'));
// $html .= $this->makeLink( $key, $item['links'][0], array('link-class' => 'dropdown-item') );
}
} else {
$html .= $box['content'];
}
$html .= Html::closeElement( 'ul' );
return $html;
}
/**
* Generates the logo and (optionally) site title
* @return string html
*/
private function getLogo( $id = 'p-logo', $imageOnly = false ) {
$html = Html::openElement(
'a',
array(
'href' => $this->data['nav_urls']['mainpage']['href'],
'class' => 'navbar-brand',
) + Linker::tooltipAndAccesskeyAttribs( 'p-logo' )
);
if ( $imageOnly ) {
$html .= $this->getMsg( 'sitetitle' )->escaped();
} else {
$html .= Html::element(
'img',
array(
'src' => $this->data['logopath'],
'height' => '30',
'alt' => 'Portal logo'
)
);
}
$html .= Html::closeElement( 'a' );
return $html;
}
/**
* Generates the search form
* @return string html
*/
private function getSearch() {
$html = Html::openElement(
'form',
array(
'action' => htmlspecialchars( $this->get( 'wgScript' ) ),
'role' => 'search',
'class' => 'bd-search d-flex align-items-center',
'id' => 'p-search'
)
);
$html .= Html::hidden( 'title', htmlspecialchars( $this->get( 'searchtitle' ) ) );
$html .= $this->makeSearchInput( array(
'id' => 'searchInput',
'class' => 'form-control ds-input',
'placeholder' => 'Search...',
'autocomplete' => 'off',
) );
// $html .= $this->makeSearchButton( 'go', array(
// 'id' => 'searchGoButton',
// 'class' => 'btn btn-outline-success my-2 my-sm-0'
// ) );
$html .= Html::closeElement( 'form' );
return $html;
}
/**
* Generates page-related tools/links
* @return string html
*/
private function getPageLinks() {
$content_navigation_actions = $this->data['content_navigation']['actions'];
if (empty($content_navigation_actions)) {
return;
}
$html = Html::openElement(
'li',
array(
'role' => 'navigation',
'class' => 'nav-item dropdown',
'id' => 'page-links'
) );
$html .= Html::element(
'a',
array(
'class' => 'nav-link dropdown-toggle',
'id' => 'page-links-dd',
'role' => 'button',
'data-toggle' => 'dropdown' ),
'Actions');
$html .= Html::openElement( 'div', array('class' => 'dropdown-menu dropdown-menu-right') );
$html .= $this->getNavDropDownContent( $content_navigation_actions );
$html .= Html::closeElement( 'div' );
$html .= Html::closeElement( 'li' );
return $html;
}
/**
* Generates user tools menu
* @return string html
*/
private function getUserLinks() {
return $this->getNavDropDown( array(
'id' => 'p-personal',
'headerMessage' => 'personaltools',
'content' => $this->getPersonalTools(),
) );
}
/**
* Generates site navigation menu
* @return string html
*/
private function getSiteLinks() {
$sidebar = $this->getSidebar();
return $this->getNavDropDown( $sidebar['navigation'] );
}
/**
* Generates site toolbox menu
* @return string html
*/
private function getSiteToolbox() {
$sidebar = $this->getSidebar();
return $this->getNavDropDown( $sidebar['TOOLBOX'] );
}
/**
* Outputs a css clear using the core visualClear class
*/
private function clear() {
echo '<div class="clearfix"></div>';
}
}