Completed
Pull Request — master (#50)
by
unknown
02:21
created

SkinPivot::initPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
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 setupSkinUserCss(OutputPage $out) {
0 ignored issues
show
Coding Style introduced by
setupSkinUserCss uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
15
		parent::setupSkinUserCss($out);
16
		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...
17
		$wgPivotFeaturesDefaults = array(
18
			'showActionsForAnon' => true,
19
			'fixedNavBar' => false,
20
			'usePivotTabs' => false,
21
			'showHelpUnderTools' => true,
22
			'showRecentChangesUnderTools' => true,
23
			'wikiName' => &$GLOBALS['wgSitename'],
24
			'wikiNameDesktop' => &$GLOBALS['wgSitename'],
25
			'navbarIcon' => false,
26
			'IeEdgeCode' => 1,
27
			'showFooterIcons' => false,
28
			'addThisPUBID' => '',
29
			'useAddThisShare' => '',
30
			'useAddThisFollow' => ''
31
		);
32
		foreach ($wgPivotFeaturesDefaults as $fgOption => $fgOptionValue) {
33
			if ( !isset($wgPivotFeatures[$fgOption]) ) {
34
				$wgPivotFeatures[$fgOption] = $fgOptionValue;
35
			}
36
		}
37
		$out->addModuleStyles('skins.pivot.styles');
38
		$out->addModuleScripts('skins.pivot.js');
39
		$out->addHeadItem('font', '<link rel="preload" href="/skins/pivot/assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin="anonymous" />');
40
41
	}
42
43
}
44
45
46
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...
47
	public function execute() {
48
		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...
49
		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...
50
		wfSuppressWarnings();
51
		$this->html('headelement');
52
		switch ($wgPivotFeatures['usePivotTabs']) {
53
			case true:
54
			    ob_start();
55
				$this->html('bodytext');
56
				$out = ob_get_contents();
57
				ob_end_clean();
58
				$markers = array("&lt;a", "&lt;/a", "&gt;");
59
				$tags = array("<a", "</a", ">");
60
				$body = str_replace($markers, $tags, $out);
61
				break;	
62
			default:
63
				$body = '';
64
				break;
65
		}
66
		switch ($wgPivotFeatures['showFooterIcons']) {
67
			case true:
68
				$poweredbyType = "icononly";
69
				$poweredbyMakeType = 'withImage';
70
				break;
71
			default:
72
				$poweredbyType = "nocopyright";
73
				$poweredbyMakeType = 'withoutImage';
74
				break;	
75
		}
76
77
?>
78
<!-- START PIVOTTEMPLATE -->
79
		<div class="off-canvas-wrap docs-wrap" data-offcanvas="">
80
			<div class="inner-wrap">
81
				<?php if ($wgPivotFeatures['fixedNavBar'] != false) echo "<div class='fixed'>"; ?>
82
				<nav class="tab-bar hide-for-print">
83
					<section id="left-nav-aside" class="left-small show-for-small">
84
						<a class="left-off-canvas-toggle"><span id="menu-user"><i class="fa fa-navicon fa-lg"></i></span></a>
85
					</section>
86
					
87
					<section id="middle-nav" class="middle tab-bar-section">
88
						<h1 class="title"><a href="<?php echo $this->data['nav_urls']['mainpage']['href']; ?>">
89
					<span class="show-for-medium-up"><?php echo $wgPivotFeatures['wikiNameDesktop']; ?></span>
90
						<span class="show-for-small-only">
91
						<?php if ($wgPivotFeatures['navbarIcon'] != false) { ?>
92
							<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;">
93
								<?php } ?>
94
						<?php echo $wgPivotFeatures['wikiName']; ?></span></a></h1>
95
					</section>
96
					
97
					<section id="right-nav-aside" class="right-small">
98
					<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>
99
					</section>
100
				</nav>
101
				<?php if ($wgPivotFeatures['fixedNavBar'] != false) echo "</div>"; ?>
102
				    <aside class="left-off-canvas-menu">
103
      					<ul class="off-canvas-list">
104
						
105
								<li class="has-form">
106
									<form action="<?php $this->text( 'wgScript' ); ?>" id="searchform" class="mw-search">
107
										<div class="row collapse">
108
											<div class="small-12 columns">
109
												<input type="search" name="search" placeholder="<?php echo wfMessage( 'search' )->text() ?>" title="Search [alt-shift-f]" accesskey="f" id="searchInput-offcanvas" autocomplete="off">
110
											</div>
111
										</div>
112
									</form>
113
								</li>
114
								
115
							<?php $this->renderSidebar() ?>
116
						</ul>
117
					</aside>
118
					
119
					<aside class="right-off-canvas-menu">
120
					  <ul class="off-canvas-list">
121
					<?php if ($wgUser->isLoggedIn()): ?>
122
						<li id="personal-tools"><label>Personal</label></li>
123
						<?php foreach ($this->getPersonalTools() as $key => $item) { echo $this->makeListItem($key, $item); } ?>
124
							<?php else: ?>
125
								<?php if (isset($this->data['personal_urls']['anonlogin'])): ?>
126
									<li><a href="<?php echo $this->data['personal_urls']['anonlogin']['href']; ?>"><?php echo wfMessage( 'login' )->text() ?></a></li>
127
								<?php elseif (isset($this->data['personal_urls']['login'])): ?>
128
									<li><a href="<?php echo htmlspecialchars($this->data['personal_urls']['login']['href']); ?>"><?php echo wfMessage( 'login' )->text() ?></a></li>
129
										<?php else: ?>
130
											<li><?php echo Linker::link(Title::newFromText('Special:UserLogin'), wfMessage( 'login' )->text()); ?></li>
131
								<?php endif; ?>
132
							<?php endif; ?>
133
					  </ul>
134
					</aside>
135
136
					<section id="main-section" class="main-section" <?php if ($wgPivotFeatures['fixedNavBar'] != false) echo "style='margin-top:2.8125em'"; ?>>
137
					
138
						<div id="page-content">
139
							
140
							<div id="mw-js-message" style="display:none;"></div>
141
142
							<div class="row">
143
								
144
								<div id="sidebar" class="large-2 medium-3 columns hide-for-small hide-for-print">
145
										<ul class="side-nav">
146
											<li class="name logo">
147
											<a href="<?php echo $this->data['nav_urls']['mainpage']['href']; ?>">
148
												<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>		
149
											</li>
150
											<li class="has-form">
151
												<form action="<?php $this->text( 'wgScript' ); ?>" id="searchform" class="mw-search">
152
													<div class="row collapse">
153
														<div class="small-12 columns">
154
															<input type="search" name="search" placeholder="<?php echo wfMessage( 'search' )->text() ?>" title="Search [alt-shift-f]" accesskey="f" id="searchInput" autocomplete="off">
155
														</div>
156
													</div>
157
												</form>
158
											</li>
159
								
160
											<?php $this->renderSidebar() ?>
161
										</ul>
162
								</div>
163
								
164
								<div id="p-cactions" class="large-10 medium-9 columns">
165
								
166
									<div class="row">
167
										<div class="large-12 columns">
168
												<!-- Output page indicators -->
169
												<?php echo $this->getIndicators(); ?>
170
												<!-- If user is logged in output echo location -->
171
												<?php if ($wgUser->isLoggedIn()): ?>
172
												<div id="echo-notifications">
173
												<div id="echo-notifications-alerts"></div>
174
												<div id="echo-notifications-messages"></div>
175
												<div id="echo-notifications-notice"></div>
176
												</div>
177
												<?php endif; ?>
178
												<!--[if lt IE 9]>
179
												<div id="siteNotice" class="sitenotice"><?php echo $this->text('sitename') . ' '. wfMessage( 'pivot-browsermsg' )->text(); ?></div>
180
												<![endif]-->
181
182
												<?php if ( $this->data['sitenotice'] ) { ?><div id="siteNotice" class="sitenotice"><?php $this->html( 'sitenotice' ); ?></div><?php } ?>
183
												<?php if ( $this->data['newtalk'] ) { ?><div id="usermessage" class="newtalk"><?php $this->html( 'newtalk' ); ?></div><?php } ?>
184
										</div>
185
									</div>
186
								
187
									<?php if ($wgUser->isLoggedIn() || $wgPivotFeatures['showActionsForAnon']): ?>
188
										<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>
189
										<ul id="drop1" class="tiny content f-dropdown" data-dropdown-content>
190
											<?php foreach($this->data['content_actions'] as $key => $tab) { echo preg_replace(array('/\sprimary="1"/', '/\scontext="[a-z]+"/', '/\srel="archives"/'),'',$this->makeListItem($key, $tab)); } ?>
191
											<?php wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ));  ?>
192
										</ul>
193
194
									<?php endif;
195
									$namespace = str_replace('_', ' ', $this->getSkin()->getTitle()->getNsText());
196
									$displaytitle = $this->data['title'];
197
									if (!empty($namespace)) {
198
										$pagetitle = $this->getSkin()->getTitle();
199
										$newtitle = str_replace($namespace.':', '', $pagetitle);
200
										$displaytitle = str_replace($pagetitle, $newtitle, $displaytitle);
201
									?><h4 class="namespace label"><?php print $namespace; ?></h4><?php } ?>
202
									<div id="content">
203
									<h2 class="title"><?php print $displaytitle; ?></h2>
204
											<?php if ($wgPivotFeatures['useAddThisShare'] !== '') { ?>
205
											<!-- Go to www.addthis.com/dashboard to customize your tools -->
206
											<div class="<?php echo $wgPivotFeatures['useAddThisShare']; ?> hide-for-print"></div>
207
											<!-- Go to www.addthis.com/dashboard to customize your tools -->
208
											<?php } ?>
209
									<?php if ( $this->data['isarticle'] ) { ?><h3 id="tagline"><?php $this->msg( 'tagline' ) ?></h3><?php } ?>
210
									<h5 id="sitesub" class="subtitle"><?php $this->html('subtitle') ?></h5>
211
									<div id="contentSub" class="clear_both"></div>
212
									<div id="bodyContent" class="mw-bodytext">
213
									<?php 
214
									switch ($wgPivotFeatures['usePivotTabs']) {
215
										case true:
216
											echo $body;
217
											break;
218
										default:
219
										$this->html('bodytext');
220
											break;
221
											}
222
									?>
223
									<div class="clear_both"></div>
224
									</div>
225
									</div>
226
									<div id="categories" class="row">
227
										<div class="small-12 columns">
228
											<div class="group"><?php $this->html('catlinks'); ?></div>
229
											<?php $this->html('dataAfterContent'); ?>
230
										</div>
231
									</div>	
232
													
233
									<footer class="row">
234
235
										<div id="footer">
236
											<div id="footer-left" class="small-12 medium-8 large-9 columns">
237
											<ul id="footer-left">
238
												<?php foreach ($this->getFooterLinks("flat") as $key) { ?>
239
													<li id="footer-<?php echo $key ?>"><?php $this->html($key) ?></li>
240
												<?php } ?>									
241
											</ul>
242
											</div>	
243
											<div id="footer-right-icons" class="small-12 medium-4 large-3 columns hide-for-print">
244
											<ul id="footer-right">
245
												<li class="social-follow hide-for-print">
246
													<?php if ($wgPivotFeatures['useAddThisFollow'] !== '') { ?>
247
														<div class="social-links">
248
															<!-- Go to www.addthis.com/dashboard to customize your tools -->
249
															<div class="<?php echo $wgPivotFeatures['useAddThisFollow']; ?> hide-for-print"></div>
250
														</div>
251
													<?php } ?>
252
												</li>
253
												<?php foreach ($this->getFooterIcons($poweredbyType) as $blockName => $footerIcons) { ?>
254
													<li class="<?php echo $blockName ?>"><?php foreach ($footerIcons as $icon) { ?>
255
														<?php echo $this->getSkin()->makeFooterIcon($icon, $poweredbyMakeType); ?>
256
														<?php } ?>
257
													</li>
258
												<?php } ?>
259
											</ul>
260
											</div>		
261
										</div>			
262
									</footer>
263
								
264
								</div>
265
						</div>
266
					</div>
267
						
268
				</section>
269
				
270
			</div>
271
			</div>
272
			<a class="exit-off-canvas"></a>	
273
		</div>
274
275
		
276
		<?php $this->printTrail(); ?>
277
278
			<?php if ($this->data['isarticle'] && $wgPivotFeatures['addThisPUBID'] !== '') { ?>
279
				<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=<?php echo $wgPivotFeatures['addThisPUBID']; ?>" async="async">></script>
280
			<?php } ?>	
281
		</body>
282
		</html>
283
284
<?php
285
		wfRestoreWarnings();
286
		
287
	}
288
	
289
	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...
290
		$sidebar = $this->getSidebar();
291
		$toolbox = $this->getToolbox();
292
		foreach ($sidebar as $boxName => $box) { if ( ($box['header'] != wfMessage( 'toolbox' )->text()) ) { 
293
			echo '<li id='.Sanitizer::escapeId( $box['id'] ); Linker::tooltip( $box['id'] ).'>';
294
			echo '<li><label>'.htmlspecialchars( $box['header'] ).'</label></li>';
295
					if ( is_array( $box['content'] ) ) {
296
							foreach ($box['content'] as $key => $item) { echo $this->makeListItem($key, $item); }
297
								} }
298
									}
299
			echo '<li><label>Toolbox</label></li>';
300
					foreach ($toolbox as $key => $tbitem) { echo $this->makeListItem($key, $tbitem); }
301
		}	
302
}
303
?>
304