Passed
Branch master (15cce1)
by Tom
01:06
created

SkinPivot::initPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 9.4285
1
<?php
2
3
/**
4
 * Skin file for Pivot 
5
 *
6
 * @file
7
 * @ingroup Skins
8
 */
9
 
10
11
class SkinPivot extends SkinTemplate {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
12
	public $skinname = 'pivot', $stylename = 'pivot', $template = 'pivotTemplate', $useHeadElement = true;
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
13
14
	public function initPage(OutputPage $out) {
0 ignored issues
show
Bug introduced by
The type OutputPage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
        parent::initPage($out);
16
		global $wgLocalStylePath;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
17
18
		$viewport_meta = 'width=device-width, user-scalable=yes, initial-scale=1.0';
19
		$out->addMeta('viewport', $viewport_meta);
20
		$out->addModuleScripts('skins.pivot.js');
21
	}
22
	
23
	public function setupSkinUserCss(OutputPage $out) {
24
		parent::setupSkinUserCss($out);
25
    	global $wgLocalStylePath;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
26
		global $wgPivotFeatures;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
27
		$wgPivotFeaturesDefaults = array(
28
			'showActionsForAnon' => true,
29
			'fixedNavBar' => false,
30
			'usePivotTabs' => false,
31
			'showHelpUnderTools' => true,
32
			'showRecentChangesUnderTools' => true,
33
			'wikiName' => &$GLOBALS['wgSitename'],
34
			'wikiNameDesktop' => &$GLOBALS['wgSitename'],
35
			'navbarIcon' => false,
36
			'preloadFontAwesome' => false,
37
			'showFooterIcons' => false,
38
			'addThisPUBID' => '',
39
			'useAddThisShare' => '',
40
			'useAddThisFollow' => ''
41
		);
42
		foreach ($wgPivotFeaturesDefaults as $fgOption => $fgOptionValue) {
43
			if ( !isset($wgPivotFeatures[$fgOption]) ) {
44
				$wgPivotFeatures[$fgOption] = $fgOptionValue;
45
			}
46
		}
47
		$out->addModuleStyles('skins.pivot.styles');
48
		if ( $wgPivotFeatures['preloadFontAwesome'] ) {
49
			$out->addHeadItem('font', '<link rel="preload" href="'.$wgLocalStylePath.'/pivot/assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin="anonymous" />');
50
		}
51
	}
52
53
}
54
55
56
class pivotTemplate extends BaseTemplate {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
57
	public function execute() {
58
		global $wgUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
59
		global $wgPivotFeatures;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
60
		wfSuppressWarnings();
61
		$this->html('headelement');
62
		switch ($wgPivotFeatures['usePivotTabs']) {
63
			case true:
64
			    ob_start();
65
				$this->html('bodytext');
66
				$out = ob_get_contents();
67
				ob_end_clean();
68
				$markers = array("&lt;a", "&lt;/a", "&gt;");
69
				$tags = array("<a", "</a", ">");
70
				$body = str_replace($markers, $tags, $out);
71
				break;	
72
			default:
73
				$body = '';
74
				break;
75
		}
76
		switch ($wgPivotFeatures['showFooterIcons']) {
77
			case true:
78
				$poweredbyType = "icononly";
79
				$poweredbyMakeType = 'withImage';
80
				break;
81
			default:
82
				$poweredbyType = "nocopyright";
83
				$poweredbyMakeType = 'withoutImage';
84
				break;	
85
		}
86
87
?>
88
<!-- START PIVOTTEMPLATE -->
89
		<div class="off-canvas-wrap docs-wrap" data-offcanvas="">
90
			<div class="inner-wrap">
91
				<?php if ($wgPivotFeatures['fixedNavBar'] != false) echo "<div class='fixed'>"; ?>
92
				<nav class="tab-bar hide-for-print">
93
					<section id="left-nav-aside" class="left-small show-for-small">
94
						<a class="left-off-canvas-toggle"><span id="menu-user"><i class="fa fa-navicon fa-lg"></i></span></a>
95
					</section>
96
					
97
					<section id="middle-nav" class="middle tab-bar-section">
98
						<h1 class="title"><a href="<?php echo $this->data['nav_urls']['mainpage']['href']; ?>">
99
					<span class="show-for-medium-up"><?php echo $wgPivotFeatures['wikiNameDesktop']; ?></span>
100
						<span class="show-for-small-only">
101
						<?php if ($wgPivotFeatures['navbarIcon'] != false) { ?>
102
							<img alt="<?php echo $this->text('sitename'); ?>" src="<?php echo $this->text('logopath'); ?>" style="max-width: 64px;height:auto; max-height:36px; display: inline-block; vertical-align:middle;">
103
								<?php } ?>
104
						<?php echo $wgPivotFeatures['wikiName']; ?></span></a></h1>
105
					</section>
106
					
107
					<section id="right-nav-aside" class="right-small">
108
					<a class="right-off-canvas-toggle"><span id="menu-user"><i class="fa <?php if ($wgUser->isLoggedIn()): ?>fa-user<?php else: ?>fa-navicon<?php endif; ?> fa-lg"></i></span></a>
109
					</section>
110
				</nav>
111
				<?php if ($wgPivotFeatures['fixedNavBar'] != false) echo "</div>"; ?>
112
				    <aside class="left-off-canvas-menu">
113
      					<ul class="off-canvas-list">
114
						
115
								<li class="has-form">
116
									<form action="<?php $this->text( 'wgScript' ); ?>" id="searchform" class="mw-search">
117
										<div class="row collapse">
118
											<div class="small-12 columns">
119
												<input type="search" name="search" placeholder="<?php echo wfMessage( 'search' )->text() ?>" title="Search [alt-shift-f]" accesskey="f" id="searchInput-offcanvas" autocomplete="off">
120
											</div>
121
										</div>
122
									</form>
123
								</li>
124
								
125
							<?php $this->renderSidebar() ?>
126
						</ul>
127
					</aside>
128
					
129
					<aside class="right-off-canvas-menu">
130
					  <ul class="off-canvas-list">
131
					<?php if ($wgUser->isLoggedIn()): ?>
132
						<li id="personal-tools"><label>Personal</label></li>
133
						<?php foreach ($this->getPersonalTools() as $key => $item) { echo $this->makeListItem($key, $item); } ?>
134
							<?php else: ?>
135
								<?php if (isset($this->data['personal_urls']['anonlogin'])): ?>
136
									<li><a href="<?php echo $this->data['personal_urls']['anonlogin']['href']; ?>"><?php echo wfMessage( 'login' )->text() ?></a></li>
137
								<?php elseif (isset($this->data['personal_urls']['login'])): ?>
138
									<li><a href="<?php echo htmlspecialchars($this->data['personal_urls']['login']['href']); ?>"><?php echo wfMessage( 'login' )->text() ?></a></li>
139
										<?php else: ?>
140
											<li><?php echo Linker::link(Title::newFromText('Special:UserLogin'), wfMessage( 'login' )->text()); ?></li>
141
								<?php endif; ?>
142
							<?php endif; ?>
143
					  </ul>
144
					</aside>
145
146
					<section id="main-section" class="main-section" <?php if ($wgPivotFeatures['fixedNavBar'] != false) echo "style='margin-top:2.8125em'"; ?>>
147
					
148
						<div id="page-content">
149
							
150
							<div id="mw-js-message" style="display:none;"></div>
151
152
							<div class="row">
153
								
154
								<div id="sidebar" class="large-2 medium-3 columns hide-for-small hide-for-print">
155
										<ul class="side-nav">
156
											<li class="name logo">
157
											<a href="<?php echo $this->data['nav_urls']['mainpage']['href']; ?>">
158
												<img alt="<?php echo $this->text('sitename'); ?>" src="<?php echo $this->text('logopath') ?>" style="max-width: 100%;height: auto;display: inline-block; vertical-align: middle;"></a>		
159
											</li>
160
											<li class="has-form">
161
												<form action="<?php $this->text( 'wgScript' ); ?>" id="searchform" class="mw-search">
162
													<div class="row collapse">
163
														<div class="small-12 columns">
164
															<input type="search" name="search" placeholder="<?php echo wfMessage( 'search' )->text() ?>" title="Search [alt-shift-f]" accesskey="f" id="searchInput" autocomplete="off">
165
														</div>
166
													</div>
167
												</form>
168
											</li>
169
								
170
											<?php $this->renderSidebar() ?>
171
										</ul>
172
								</div>
173
								
174
								<div id="p-cactions" class="large-10 medium-9 columns">
175
								
176
									<div class="row">
177
										<div class="large-12 columns">
178
												<!-- Output page indicators -->
179
												<?php echo $this->getIndicators(); ?>
180
												<!-- If user is logged in output echo location -->
181
												<?php if ($wgUser->isLoggedIn()): ?>
182
												<div id="echo-notifications">
183
												<div id="echo-notifications-alerts"></div>
184
												<div id="echo-notifications-messages"></div>
185
												<div id="echo-notifications-notice"></div>
186
												</div>
187
												<?php endif; ?>
188
												<!--[if lt IE 9]>
189
												<div id="siteNotice" class="sitenotice"><?php echo $this->text('sitename') . ' '. wfMessage( 'pivot-browsermsg' )->text(); ?></div>
190
												<![endif]-->
191
192
												<?php if ( $this->data['sitenotice'] ) { ?><div id="siteNotice" class="sitenotice"><?php $this->html( 'sitenotice' ); ?></div><?php } ?>
193
												<?php if ( $this->data['newtalk'] ) { ?><div id="usermessage" class="newtalk"><?php $this->html( 'newtalk' ); ?></div><?php } ?>
194
										</div>
195
									</div>
196
								
197
									<?php if ($wgUser->isLoggedIn() || $wgPivotFeatures['showActionsForAnon']): ?>
198
										<a href="#" data-options="align:left" data-dropdown="drop1" class="button secondary small radius pull-right hide-for-print" id="drop"><i class="fa fa-navicon fa-lg"><span id="page-actions" class="show-for-medium-up">&nbsp;<?php echo wfMessage( 'actions' )->text() ?></span></i></a>
199
										<ul id="drop1" class="tiny content f-dropdown" data-dropdown-content>
200
											<?php foreach($this->data['content_actions'] as $key => $tab) { echo preg_replace(array('/\sprimary="1"/', '/\scontext="[a-z]+"/', '/\srel="archives"/'),'',$this->makeListItem($key, $tab)); } ?>
201
											<?php wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ));  ?>
202
										</ul>
203
204
									<?php endif;
205
									$namespace = str_replace('_', ' ', $this->getSkin()->getTitle()->getNsText());
206
									$displaytitle = $this->data['title'];
207
									if (!empty($namespace)) {
208
										$pagetitle = $this->getSkin()->getTitle();
209
										$newtitle = str_replace($namespace.':', '', $pagetitle);
210
										$displaytitle = str_replace($pagetitle, $newtitle, $displaytitle);
211
									?><h4 class="namespace label"><?php print $namespace; ?></h4><?php } ?>
212
									<div id="content">
213
									<h2 class="title"><?php print $displaytitle; ?></h2>
214
											<?php if ($wgPivotFeatures['useAddThisShare'] !== '') { ?>
215
											<!-- Go to www.addthis.com/dashboard to customize your tools -->
216
											<div class="<?php echo $wgPivotFeatures['useAddThisShare']; ?> hide-for-print"></div>
217
											<!-- Go to www.addthis.com/dashboard to customize your tools -->
218
											<?php } ?>
219
									<?php if ( $this->data['isarticle'] ) { ?><h3 id="tagline"><?php $this->msg( 'tagline' ) ?></h3><?php } ?>
220
									<?php if ( $this->html('subtitle') ) { ?><h5 id="sitesub" class="subtitle"><?php $this->html('subtitle') ?></h5><?php } ?>
221
									<div id="contentSub" class="clear_both"></div>
222
									<div id="bodyContent" class="mw-bodytext">
223
									<?php 
224
									switch ($wgPivotFeatures['usePivotTabs']) {
225
										case true:
226
											echo $body;
227
											break;
228
										default:
229
										$this->html('bodytext');
230
											break;
231
											}
232
									?>
233
									<div class="clear_both"></div>
234
									</div>
235
									</div>
236
									<div id="categories" class="row">
237
										<div class="small-12 columns">
238
											<div class="group"><?php $this->html('catlinks'); ?></div>
239
											<?php $this->html('dataAfterContent'); ?>
240
										</div>
241
									</div>	
242
													
243
									<footer class="row">
244
245
										<div id="footer">
246
											<div id="div-footer-left" class="small-12 medium-8 large-9 columns">
247
											<ul id="footer-left">
248
												<?php foreach ($this->getFooterLinks("flat") as $key) { ?>
249
													<li id="footer-<?php echo $key ?>"><?php $this->html($key) ?></li>
250
												<?php } ?>									
251
											</ul>
252
											</div>	
253
											<div id="footer-right-icons" class="small-12 medium-4 large-3 columns hide-for-print">
254
											<ul id="footer-right">
255
												<li class="social-follow hide-for-print">
256
													<?php if ($wgPivotFeatures['useAddThisFollow'] !== '') { ?>
257
														<div class="social-links">
258
															<!-- Go to www.addthis.com/dashboard to customize your tools -->
259
															<div class="<?php echo $wgPivotFeatures['useAddThisFollow']; ?> hide-for-print"></div>
260
														</div>
261
													<?php } ?>
262
												</li>
263
												<?php foreach ($this->getFooterIcons($poweredbyType) as $blockName => $footerIcons) { ?>
264
													<li class="<?php echo $blockName ?>"><?php foreach ($footerIcons as $icon) { ?>
265
														<?php echo $this->getSkin()->makeFooterIcon($icon, $poweredbyMakeType); ?>
266
														<?php } ?>
267
													</li>
268
												<?php } ?>
269
											</ul>
270
											</div>		
271
										</div>			
272
									</footer>
273
								
274
								</div>
275
						</div>
276
					</div>
277
						
278
				</section>
279
				
280
			</div>
281
		</div>
282
		<div>
283
			<a class="exit-off-canvas"></a>	
284
		</div>
285
		
286
		
287
		<?php $this->printTrail(); ?>
288
289
			<?php if ($this->data['isarticle'] && $wgPivotFeatures['addThisPUBID'] !== '') { ?>
290
				<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=<?php echo $wgPivotFeatures['addThisPUBID']; ?>" async="async"></script>
291
			<?php } ?>	
292
		</body>
293
		</html>
294
295
<?php
296
		wfRestoreWarnings();
297
		
298
	}
299
	
300
	function renderSidebar() { 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
301
		$sidebar = $this->getSidebar();
302
		foreach ($sidebar as $boxName => $box) { 
303
			echo '<li><label class="sidebar" id="'.Sanitizer::escapeId( $box['id'] ).'"';echo Linker::tooltip( $box['id'] ).'>'.htmlspecialchars( $box['header'] ).'</label></li>';
304
					if ( is_array( $box['content'] ) ) {
305
							foreach ($box['content'] as $key => $item) { echo $this->makeListItem($key, $item); }
306
								} 
307
							}
308
		return;	}	
309
}
310
?>