/
LinusTemplate.php
276 lines (244 loc) · 10.6 KB
/
LinusTemplate.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
<?php
/**
* Linus skin template
*
* @file
* @ingroup Skins
* @author Jonas Neugebauer (jonasneug@gmail.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0
*/
if ( ! defined( 'MEDIAWIKI' ) ) {
die( "This is an extension to the MediaWiki package and cannot be run standalone." );
}
class LinusTemplate extends BaseTemplate {
/**
* Outputs the entire contents of the page
*/
public function execute() {
global $wgParser, $wgLinusHeadingCount;
global $wgLinusUseSidebar, $wgLinusTOCInSidebar, $wgLinusHideHeader;
// Decide if to show sidebar
$showSidebar = $wgLinusUseSidebar;
if( $wgLinusTOCInSidebar && $wgLinusHeadingCount > 3 ) {
$showSidebar = true;
}
$this->html( 'headelement' );
?>
<!-- link to content for accessibility -->
<a href="#wiki-body" class="sr-only">Skip to main content</a>
<?php $this->renderNavbar(); ?>
<main id="wiki-outer-body" class="container">
<div id="wiki-body" class="row">
<?php if ( $showSidebar ): ?>
<aside class="col-md-3 hidden-print" id="sidebar">
<?php $this->renderSidebar() ?>
</aside>
<section class="col-md-9 wiki-body-section" id="main-content">
<?php else: ?>
<section class="col-md-12 wiki-body-section" id="main-content">
<?php endif; ?>
<?php if( $this->data['sitenotice'] ): ?>
<!-- siteNotice -->
<div id="siteNotice" class="alert alert-warning"><?php $this->html('sitenotice') ?></div>
<!-- /siteNotice -->
<?php endif; ?>
<?php if ( $this->data['undelete'] ): ?>
<!-- undelete -->
<div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
<!-- /undelete -->
<?php endif; ?>
<?php if($this->data['newtalk'] ): ?>
<!-- newtalk -->
<div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
<!-- /newtalk -->
<?php endif; ?>
<?php if ( !empty( $this->data['title'] ) && !in_array($this->data['title'],$wgLinusHideHeader) ): ?>
<div class="pagetitle page-header">
<?php if( $this->getIndicators() ): ?>
<div id="page-indicators" class="pull-right">
<?php echo $this->getIndicators(); ?>
</div>
<?php endif; ?>
<h1><?php $this->html( 'title' ) ?></h1>
<?php if( $this->data['subtitle'] ): ?>
<div class="pagesubtitle text-muted"><?php $this->html('subtitle') ?></div>
<?php endif; ?>
</div>
<?php endif; ?>
<article class="body">
<?php $this->renderBody() ?>
</article>
<?php if ( $this->data['catlinks'] ): ?>
<!-- catlinks -->
<?php $this->html( 'catlinks' ); ?>
<!-- /catlinks -->
<?php endif; ?>
<?php if ( $this->data['dataAfterContent'] ): ?>
<!-- dataAfterContent -->
<div class="data-after-content"><?php $this->html( 'dataAfterContent' ); ?></div>
<!-- /dataAfterContent -->
<?php endif; ?>
</section> <!-- /.wiki-body-section -->
</div> <!-- /.row -->
</main>
<?php
$this->renderFooter();
$this->printTrail();
?>
</body>
</html><?php
} // execute()
protected function renderNavbar() {
global $wgLogo, $wgSitename, $wgSitenameshort, $wgUser, $wgEnableUploads;
global $wgLinusNavbarInverted, $wgLinusNavbarFixed,
$wgLinusTitlebarPage, $wgLinusHideActionsForAnon;
$navbarClasses = 'navbar';
if( $wgLinusNavbarInverted ) {
$navbarClasses .= ' navbar-inverse';
} else {
$navbarClasses .= ' navbar-default';
}
if( $wgLinusNavbarFixed ) {
$navbarClasses .= ' navbar-fixed-top';
}
?>
<nav class="<?php echo $navbarClasses ?>" id="main-nav">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#linus-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="<?php echo $this->data['nav_urls']['mainpage']['href'] ?>" title="<?php echo $wgSitename ?>"><?php echo isset( $wgLogo ) && $wgLogo ? '<img src="'.$wgLogo.'" alt="Logo"/> ' : (isset($wgSitenameshort) ? $wgSitenameshort : $wgSitename); ?></a>
</div>
<div class="collapse navbar-collapse" id="linus-navbar-collapse">
<?php if( LinusParser::pageExists($wgLinusTitlebarPage) ): ?>
<ul class="nav navbar-nav">
<?php echo LinusParser::nav( LinusParser::getNavigationFromPage($wgLinusTitlebarPage), true ) ?>
</ul>
<?php endif; ?>
<ul class="nav navbar-nav navbar-right">
<?php
if ( $wgUser->isLoggedIn() ) {
echo LinusParser::nav( LinusParser::getNavigationFromData('personal_urls', $wgUser->getName(), $this->data['personal_urls']) );
} else {
?>
<li>
<?php echo Linker::linkKnown( SpecialPage::getTitleFor( 'Userlogin' ), LinusParser::getIconFor('login').wfMessage( 'login' )->text() ); ?>
</li>
<?php
} // end else
if ( $wgUser->isLoggedIn() || !$wgLinusHideActionsForAnon ) {
if ( !empty($this->data['content_actions']) ) {
echo LinusParser::nav( LinusParser::getNavigationFromData('content_actions', wfMessage('article' /*'nstab-main' */), $this->data['content_actions']) );
}
}
?>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><?php echo LinusParser::getIconFor('toolbox') ?><span class="sr-only"><?php echo wfMessage('toolbox') ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu">
<?php
$toolbox = $this->getToolbox();
echo LinusParser::nav( LinusParser::getNavigationFromData('toolbox', '', $toolbox) );
?>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right" action="<?php $this->text( 'wgScript' ) ?>" id="searchform" role="search">
<div class="form-group">
<input class="form-control" type="search" name="search" placeholder="Search" title="Search <?php echo $wgSitename; ?> [ctrl-option-f]" accesskey="f" id="searchInput" autocomplete="off">
</div>
<input class="btn" type="hidden" name="title" value="Special:Search">
</form>
</div><!-- /.collapse.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<?php
}
protected function renderSidebar() {
global $wgLinusUseSidebar, $wgLinusTOCInSidebar, $wgLinusSidebarPage;
if( $wgLinusTOCInSidebar ) {
echo '<div id="toc-container"></div>'."\n";
}
if( $wgLinusUseSidebar ) {
if( LinusParser::pageExists($wgLinusSidebarPage) ) {
echo '<div class="hidden-sm hidden-xs"id="linus-sidebar-box">'."\n";
echo '<ul class="nav nav-pills nav-stacked">';
echo LinusParser::nav( LinusParser::getNavigationFromPage($wgLinusSidebarPage) );
echo '</ul>'."\n";
echo '</div>'."\n";
}
$sidebar = $this->getSidebar();
foreach( $sidebar as $boxName => $box) {
echo '<div class="hidden-sm hidden-xs"id="'.Sanitizer::escapeId($box['id']).'">'."\n";
echo '<h2>'.htmlspecialchars($box['header']).'</h2>'."\n";
echo '<ul class="nav nav-pills nav-stacked">';
// echo '<li class="disabled"><a href="#">'.$content['header'].'</a></li>';
// echo '<li class="navbar-text"><a href="#">'.$content['header'].'</a></li>';
echo LinusParser::nav(LinusParser::getNavigationFromData($boxName,'',$box['content']));
echo '</ul>'."\n";
echo '</div>'."\n";
}
}
}
protected function renderBody() {
// echo "<pre>";
// var_dump($this->getSidebar());
// echo "\n\n";
// var_dump($this->data['personal_urls']);
// echo "\n\n";
// var_dump($this->data['content_actions']);
// foreach( $this->getToolbox() as $k=>$v ) {
// echo "'".$k."' => '',\n";
// }
// echo '</pre>';
$this->html( 'bodytext' );
}
protected function renderFooter() {
global $wgLinusNavbarInverted, $wgLinusShowFooterLinks,
$wgLinusUseFooterIcons, $wgLinusFooterPage, $wgLinusCopyrightPage;
$footerClasses = 'footer footer-default';
if( $wgLinusNavbarInverted ) {
$footerClasses = 'footer footer-inverse';
}
?>
<footer class="<?php echo $footerClasses ?> container-fluid" id="main-footer">
<div class="row">
<?php echo LinusParser::getPageContent( $wgLinusFooterPage ); ?>
</div>
<div class="row">
<div class="col-md-8">
<?php if( LinusParser::pageExists( $wgLinusCopyrightPage ) ): ?>
<p class="copyright"><?php echo LinusParser::getPageContent( $wgLinusCopyrightPage ) ?></p>
<?php endif; ?>
</div>
<div class="col-md-4" id="footer-links">
<?php if( $wgLinusShowFooterLinks ): ?>
<ul>
<?php foreach ( $this->getFooterLinks('flat') as $key ): ?>
<li><?php $this->html( $key ) ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php
$footericons = $this->getFooterIcons( "icononly" );
if ( count( $footericons ) > 0 ) {
foreach ( $footericons as $blockName => $footerIcons ) {
foreach ( $footerIcons as $icon ) {
if($wgLinusUseFooterIcons) {
echo '<span class="footericon">'.$this->getSkin()->makeFooterIcon( $icon ).'</span>';
} else {
echo '<span class="footerlink">' . $this->getSkin()->makeFooterIcon( $icon, 'withoutImage' ) . '</span>';
}
}
}
}
?>
</div>
</div><!-- container -->
</footer><!-- footer -->
<?php
}
}