This repository has been archived by the owner on Jun 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Bootstrap.php
389 lines (349 loc) · 15.7 KB
/
Bootstrap.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
<?php
/**
* Bootstrap - A basic MediaWiki skin based on Twitter's excellent Bootstrap CSS framework
*
* @Version 1.0.0
* @Author Aaron Parecki <[email protected]>
* @Copyright Aaron Parecki 2011 - http://aaronparecki.com/
* @License: GPLv2 (http://www.gnu.org/copyleft/gpl.html)
*/
if( !defined( 'MEDIAWIKI' ) ) {
die( -1 );
}
require_once('includes/SkinTemplate.php');
/**
* Inherit main code from SkinTemplate, set the CSS and template filter.
* @todo document
* @package MediaWiki
* @subpackage Skins
*/
class SkinBootstrap extends SkinTemplate {
/** Using Bootstrap */
function initPage( &$out ) {
SkinTemplate::initPage( $out );
$this->skinname = 'bootstrap';
$this->stylename = 'bootstrap';
$this->template = 'BootstrapTemplate';
}
}
/**
* @todo document
* @package MediaWiki
* @subpackage Skins
*/
class BootstrapTemplate extends QuickTemplate {
/**
* @var Cached skin object
*/
var $skin;
/**
* Template filter callback for Bootstrap skin.
* Takes an associative array of data set from a SkinTemplate-based
* class, and a wrapper for MediaWiki's localization database, and
* outputs a formatted page.
*
* @access private
*/
function execute() {
global $wgUser, $wgSitename, $wgCopyrightLink, $wgCopyright, $wgBootstrap, $wgArticlePath, $wgGoogleAnalyticsID, $wgSiteCSS;
$this->skin = $this->data['skin'];
// Suppress warnings to prevent notices about missing indexes in $this->data
wfSuppressWarnings();
?><!DOCTYPE html>
<html xml:lang="<?php $this->text('lang') ?>" lang="<?php $this->text('lang') ?>" dir="<?php $this->text('dir') ?>">
<head>
<meta http-equiv="Content-Type" content="<?php $this->text('mimetype') ?>; charset=<?php $this->text('charset') ?>" />
<title><?php $this->text('pagetitle') ?></title>
<link rel="stylesheet" type="text/css" href="<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/site.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/js/bootstrap-tabs.js"></script>
<script type="text/javascript" src="<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/js/bootstrap-dropdown.js"></script>
<script type="text/javascript" src="<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/site.js"></script>
<?php if(isset($wgSiteCSS)) { ?>
<link rel="stylesheet" type="text/css" href="<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/<?php echo $wgSiteCSS ?>" />
<?php } ?>
<?php $this->html('headlinks') ?>
<?php
if(isset($wgGoogleAnalyticsID)) { ?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<?php echo $wgGoogleAnalyticsID; ?>']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php
}
?>
</head>
<body class="<?php echo Sanitizer::escapeClass('page-' . $this->data['title'])?>">
<div class="topbar">
<div class="topbar-inner">
<div class="container-fluid">
<a class="brand" href="<?php echo $this->data['nav_urls']['mainpage']['href'] ?>"><?php echo $wgSitename ?></a>
<ul class="nav">
<?php
$titleBar = $this->getPageRawText('Bootstrap:TitleBar');
$nav = array();
foreach(explode("\n", $titleBar) as $line) {
if(trim($line) == '') continue;
if(preg_match('/^\*\s*\[\[(.+)\]\]/', $line, $match)) {
$nav[] = array('title'=>$match[1], 'link'=>$match[1]);
}elseif(preg_match('/\*\*\s*\[\[(.+)\]\]/', $line, $match)) {
$nav[count($nav)-1]['sublinks'][] = $match[1];
}elseif(preg_match('/^\*\s*(.+)/', $line, $match)) {
$nav[] = array('title'=>$match[1]);
}
}
foreach($nav as $topItem) {
$pageTitle = Title::newFromText($topItem['title']);
if(array_key_exists('sublinks', $topItem)) {
echo '<li class="dropdown" data-dropdown="dropdown">';
echo '<a href="#" class="dropdown-toggle">' . $topItem['title'] . '</a>';
echo '<ul class="dropdown-menu">';
foreach($topItem['sublinks'] as $subLink) {
$pageTitle = Title::newFromText($subLink);
echo '<li><a href="' . $pageTitle->getLocalURL() . '">' . $subLink . '</a>';
}
echo '</ul>';
echo '</li>';
} else {
echo '<li' . ($this->data['title'] == $topItem['title'] ? ' class="active"' : '') . '><a href="' . $pageTitle->getLocalURL() . '">' . $topItem['title'] . '</a></li>';
}
}
?>
</ul>
<?php
if($wgUser->isLoggedIn()) {
if ( count( $this->data['personal_urls'] ) > 0 ) {
?>
<ul<?php $this->html('userlangattributes') ?> class="nav secondary-nav">
<li class="dropdown" data-dropdown="dropdown">
<a class="dropdown-toggle" href="#"><?php echo $wgUser->getName(); ?></a>
<ul class="dropdown-menu">
<?php foreach($this->data['personal_urls'] as $item): ?>
<li <?php echo $item['attributes'] ?>><a href="<?php echo htmlspecialchars($item['href']) ?>"<?php echo $item['key'] ?><?php if(!empty($item['class'])): ?> class="<?php echo htmlspecialchars($item['class']) ?>"<?php endif; ?>><?php echo htmlspecialchars($item['text']) ?></a></li>
<?php endforeach; ?>
</ul>
</li>
</ul>
<?php
}
?>
<?php
if ( count( $this->data['content_actions']) > 0 ) {
?>
<ul class="nav secondary-nav">
<li class="dropdown" data-dropdown="dropdown">
<a class="dropdown-toggle" href="#">Page</a>
<ul class="dropdown-menu">
<?php $lastkey = end(array_keys($this->data['content_actions'])) ?>
<?php foreach($this->data['content_actions'] as $key => $action) { ?>
<li id="ca-<?php echo Sanitizer::escapeId($key) ?>" <?php
if($action['class']) { ?>class="<?php echo htmlspecialchars($action['class']) ?>"<?php } ?>
><a href="<?php echo htmlspecialchars($action['href']) ?>"><?php
echo htmlspecialchars($action['text']) ?></a> <?php
if($key != $lastkey) //echo "•" ?></li>
<?php } ?>
</ul>
</li>
</ul>
<?php
}
} else { // else if is logged in
?>
<ul class="secondary-nav">
<li>
<?php echo Linker::linkKnown(
SpecialPage::getTitleFor( 'Userlogin' ),
wfMsg( 'login' )
) ?>
</li>
</ul>
<?php
}
?>
<form class="pull-right" action="<?php $this->text( 'wgScript' ) ?>" id="search-form">
<input type="text" placeholder="Search" name="search" onchange="$('#search-form').submit()" />
</form>
</div>
</div>
</div><!-- topbar -->
<div class="container">
<?php if( $this->data['sitenotice'] ) { ?><div id="siteNotice" class="alert-message warning"><?php $this->html('sitenotice') ?></div><?php } ?>
<div class="page-header">
<h1><?php $this->html( 'title' ) ?> <small><?php $this->html('subtitle') ?></small></h1>
</div>
<!-- Main hero unit for a primary marketing message or call to action -->
<!--
<div class="hero-unit">
<h1>Hello, world!</h1>
<p>Vestibulum id ligula porta felis euismod semper. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.</p>
<p><a class="btn primary large">Learn more »</a></p>
</div>
-->
<?php $this->html( 'bodytext' ) ?>
</div><!-- container -->
<div class="bottom">
<div class="container">
<?php
$this->includePage('Bootstrap:Footer');
?>
<footer>
<p>© <?php echo date('Y'); ?> by <a href="<?php echo (isset($wgCopyrightLink) ? $wgCopyrightLink : 'http://aaronparecki.com'); ?>"><?php echo (isset($wgCopyright) ? $wgCopyright : 'Aaron Parecki'); ?></a>
• Powered by <a href="http://mediawiki.org">MediaWiki</a>
• <a href="http://aaronparecki.com/MediaWiki_Bootstrap_Skin">Bootstrap Skin</a> by <a href="http://aaronparecki.com">Aaron Parecki</a>
</p>
</footer>
</div><!-- container -->
</div><!-- bottom -->
</body>
</html>
<?php
}
/**
* Render one or more navigations elements by name, automatically reveresed
* when UI is in RTL mode
*/
private function renderNavigation( $elements ) {
global $wgVectorUseSimpleSearch, $wgVectorShowVariantName, $wgUser;
// If only one element was given, wrap it in an array, allowing more
// flexible arguments
if ( !is_array( $elements ) ) {
$elements = array( $elements );
// If there's a series of elements, reverse them when in RTL mode
} else if ( wfUILang()->isRTL() ) {
$elements = array_reverse( $elements );
}
// Render elements
foreach ( $elements as $name => $element ) {
echo "\n<!-- {$name} -->\n";
switch ( $element ) {
case 'NAMESPACES':
?>
<div id="p-namespaces" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
<h5><?php $this->msg('namespaces') ?></h5>
<ul<?php $this->html('userlangattributes') ?>>
<?php foreach ($this->data['namespace_urls'] as $link ): ?>
<li <?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></span></li>
<?php endforeach; ?>
</ul>
</div>
<?php
break;
case 'VARIANTS':
?>
<div id="p-variants" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
<?php if ( $wgVectorShowVariantName ): ?>
<h4>
<?php foreach ( $this->data['variant_urls'] as $link ): ?>
<?php if ( stripos( $link['attributes'], 'selected' ) !== false ): ?>
<?php echo htmlspecialchars( $link['text'] ) ?>
<?php endif; ?>
<?php endforeach; ?>
</h4>
<?php endif; ?>
<h5><span><?php $this->msg('variants') ?></span><a href="#"></a></h5>
<div class="menu">
<ul<?php $this->html('userlangattributes') ?>>
<?php foreach ( $this->data['variant_urls'] as $link ): ?>
<li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php
break;
case 'VIEWS':
?>
<div id="p-views" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
<h5><?php $this->msg('views') ?></h5>
<ul<?php $this->html('userlangattributes') ?>>
<?php foreach ( $this->data['view_urls'] as $link ): ?>
<li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo (array_key_exists('img',$link) ? '<img src="'.$link['img'].'" alt="'.$link['text'].'" />' : htmlspecialchars( $link['text'] ) ) ?></a></span></li>
<?php endforeach; ?>
</ul>
</div>
<?php
break;
case 'ACTIONS':
?>
<div id="p-cactions" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
<h5><span><?php $this->msg('actions') ?></span><a href="#"></a></h5>
<div class="menu">
<ul<?php $this->html('userlangattributes') ?>>
<?php foreach ($this->data['action_urls'] as $link ): ?>
<li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php
break;
case 'PERSONAL':
?>
<div id="p-personal" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
<h5><?php $this->msg('personaltools') ?></h5>
<ul<?php $this->html('userlangattributes') ?>>
<?php foreach($this->data['personal_urls'] as $item): ?>
<li <?php echo $item['attributes'] ?>><a href="<?php echo htmlspecialchars($item['href']) ?>"<?php echo $item['key'] ?><?php if(!empty($item['class'])): ?> class="<?php echo htmlspecialchars($item['class']) ?>"<?php endif; ?>><?php echo htmlspecialchars($item['text']) ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<?php
break;
case 'SEARCH':
?>
<div id="p-search">
<h5<?php $this->html('userlangattributes') ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h5>
<form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
<input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
<?php if ( $wgVectorUseSimpleSearch && $wgUser->getOption( 'vector-simplesearch' ) ): ?>
<div id="simpleSearch">
<?php if ( $this->data['rtl'] ): ?>
<button id="searchButton" type='submit' name='button' <?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?>><img src="<?php echo $this->skin->getSkinStylePath('images/search-rtl.png'); ?>" alt="<?php $this->msg( 'searchbutton' ) ?>" /></button>
<?php endif; ?>
<input id="searchInput" name="search" type="text" <?php echo $this->skin->tooltipAndAccesskey( 'search' ); ?> <?php if( isset( $this->data['search'] ) ): ?> value="<?php $this->text( 'search' ) ?>"<?php endif; ?> />
<?php if ( !$this->data['rtl'] ): ?>
<button id="searchButton" type='submit' name='button' <?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?>><img src="<?php echo $this->skin->getSkinStylePath('images/search-ltr.png'); ?>" alt="<?php $this->msg( 'searchbutton' ) ?>" /></button>
<?php endif; ?>
</div>
<?php else: ?>
<input id="searchInput" name="search" type="text" <?php echo $this->skin->tooltipAndAccesskey( 'search' ); ?> <?php if( isset( $this->data['search'] ) ): ?> value="<?php $this->text( 'search' ) ?>"<?php endif; ?> />
<input type='submit' name="go" class="searchButton" id="searchGoButton" value="<?php $this->msg( 'searcharticle' ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-go' ); ?> />
<input type="submit" name="fulltext" class="searchButton" id="mw-searchButton" value="<?php $this->msg( 'searchbutton' ) ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?> />
<?php endif; ?>
</form>
</div>
<?php
break;
}
echo "\n<!-- /{$name} -->\n";
}
}
function getPageRawText($title) {
$pageTitle = Title::newFromText($title);
if(!$pageTitle->exists()) {
return 'Create the page [[Bootstrap:TitleBar]]';
} else {
$article = new Article($pageTitle);
return $article->getRawText();
}
}
function includePage($title) {
global $wgParser, $wgUser;
$pageTitle = Title::newFromText($title);
if(!$pageTitle->exists()) {
echo 'The page [[' . $title . ']] was not found.';
} else {
$article = new Article($pageTitle);
$wgParserOptions = new ParserOptions($wgUser);
$parserOutput = $wgParser->parse($article->getRawText(), $pageTitle, $wgParserOptions);
echo $parserOutput->getText();
}
}
}