LibertyTemplate.php 30.9 KB
Newer Older
Hoto Cocoa's avatar
Hoto Cocoa committed
1
<?php // @codingStandardsIgnoreLine
Hoto Cocoa's avatar
Hoto Cocoa committed
2 3 4 5 6
class LibertyTemplate extends BaseTemplate {
	/**
	 * execute() Method
	 */
	public function execute() {
7
		global $wgLibertyAdSetting;
Jack Phoenix's avatar
Jack Phoenix committed
8 9 10

		$skin = $this->getSkin();
		$request = $skin->getRequest();
Hoto Cocoa's avatar
Hoto Cocoa committed
11
		$action = $request->getVal( 'action', 'view' );
Jack Phoenix's avatar
Jack Phoenix committed
12
		$title = $skin->getTitle();
13

Hoto Cocoa's avatar
Hoto Cocoa committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27
		$this->html( 'headelement' );
		?>
		<header>
		<div class="nav-wrapper navbar-fixed-top">
			<?php $this->navMenu(); ?>
		</div>
		</header>
		<section>
		<div class="content-wrapper">
			<aside>
			<div class="liberty-sidebar">
				<div class="liberty-right-fixed">
					<?php $this->liveRecent(); ?>
				</div>
Hoto Cocoa's avatar
Hoto Cocoa committed
28 29 30
				<?php if ( !is_null( $wgLibertyAdSetting['right'] ) ) {
					$this->buildAd( 'right' );
				} ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
31 32 33 34 35
			</div>
			</aside>
			<div class="container-fluid liberty-content">
				<div class="liberty-content-header">
					<?php if ( $this->data['sitenotice'] &&
36
							   !$request->getCookie( 'disable-notice' ) ) { ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
37 38 39 40
						<div class="alert alert-dismissible fade in alert-info liberty-notice" role="alert">
							<button type="button" class="close" data-dismiss="alert" aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
Hoto Cocoa's avatar
Hoto Cocoa committed
41
							<?php $this->html( 'sitenotice' ); ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
42 43
						</div>
					<?php } ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
44 45 46
					<?php if ( !is_null( $wgLibertyAdSetting['header'] ) ) {
						$this->buildAd( 'header' );
					}
Hoto Cocoa's avatar
Hoto Cocoa committed
47 48 49
					$this->contentsToolbox(); ?>
					<div class="title">
						<h1>
Hoto Cocoa's avatar
Hoto Cocoa committed
50
							<?php $this->html( 'title' ); ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
51 52
						</h1>
					</div>
Hoto Cocoa's avatar
Hoto Cocoa committed
53 54
					<div class="contentSub"<?php $this->html( 'userlangattributes' ); ?>>
						<?php $this->html( 'subtitle' ); ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
55 56 57
					</div>
				</div>
				<div class="liberty-content-main">
Jack Phoenix's avatar
Jack Phoenix committed
58 59 60
					<?php
					// @codingStandardsIgnoreStart
					if ( $title->getNamespace() != NS_SPECIAL &&
Hoto Cocoa's avatar
Hoto Cocoa committed
61
							   $action != 'edit' && $action != 'history' ) { ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
62
						<div class="social-buttons">
63
							<div class="twitter" data-text="<?php echo htmlspecialchars( $title, ENT_QUOTES ); ?>" title="<?php echo $skin->msg( 'liberty-twitter' )->escaped() ?>">
Hoto Cocoa's avatar
Hoto Cocoa committed
64 65
								<div><i class="fa fa-twitter"></i></div>
							</div>
66
							<div class="facebook" data-text="<?php echo htmlspecialchars( $title, ENT_QUOTES ); ?>" title="<?php echo $skin->msg( 'liberty-facebook' )->escaped() ?>">
Hoto Cocoa's avatar
Hoto Cocoa committed
67 68
								<div><i class="fa fa-facebook"></i></div>
							</div>
Hoto Cocoa's avatar
Hoto Cocoa committed
69 70
						</div>
					<?php
Jack Phoenix's avatar
Jack Phoenix committed
71 72 73
					}
					// @codingStandardsIgnoreEnd

Hoto Cocoa's avatar
Hoto Cocoa committed
74 75 76 77
					if ( $this->data['catlinks'] ) {
						$this->html( 'catlinks' );
					}
					?>
78
					<article class="mw-body-content">
Hoto Cocoa's avatar
Hoto Cocoa committed
79
						<?php $this->html( 'bodycontent' ); ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
80
					</article>
81 82 83 84 85
					<?php
					if ( $this->data['dataAfterContent'] ) {
						$this->html( 'dataAfterContent' );
					}
					?>
Hoto Cocoa's avatar
Hoto Cocoa committed
86 87 88 89
				</div>
				<footer>
				<div class="liberty-footer">
					<div class="bottom-ads"></div>
Hoto Cocoa's avatar
Hoto Cocoa committed
90
					<?php $this->footer(); ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
91 92 93 94 95 96 97 98 99 100 101
				</div>
				</footer>
			</div>
		</div>
		</section>
		<?php $this->loginModal(); ?>
		<?php
		$this->printTrail();
		$this->html( 'debughtml' );
		echo Html::closeElement( 'body' );
		echo Html::closeElement( 'html' );
Hoto Cocoa's avatar
Hoto Cocoa committed
102
		echo "\n";
Hoto Cocoa's avatar
Hoto Cocoa committed
103
	}
iTsurea's avatar
iTsurea committed
104

Hoto Cocoa's avatar
Hoto Cocoa committed
105 106 107 108
	/**
	 * Nav menu function, build top menu.
	 */
	protected function navMenu() {
Jack Phoenix's avatar
Jack Phoenix committed
109
		$skin = $this->getSkin();
Hoto Cocoa's avatar
Hoto Cocoa committed
110 111 112 113 114 115
		?>
		<nav class="navbar navbar-dark">
			<a class="navbar-brand" href="<?php echo Title::newMainPage()->getLocalURL(); ?>"></a>
			<ul class="nav navbar-nav">
				<li class="nav-item">
					<?php echo Linker::linkKnown(
Jack Phoenix's avatar
Jack Phoenix committed
116 117 118 119 120
						SpecialPage::getTitleFor( 'Recentchanges' ),
						// @codingStandardsIgnoreStart
						'<span class="fa fa-refresh"></span><span class="hide-title">' . $skin->msg( 'recentchanges' )->plain() . '</span>',
						// @codingStandardsIgnoreEnd
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
121
							'class' => 'nav-link',
Jack Phoenix's avatar
Jack Phoenix committed
122 123
							'title' => Linker::titleAttrib( 'n-recentchanges', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'n-recentchanges' )
Hoto Cocoa's avatar
Hoto Cocoa committed
124 125 126 127 128
						]
					); ?>
				</li>
				<li class="nav-item">
					<?php echo Linker::linkKnown(
Jack Phoenix's avatar
Jack Phoenix committed
129 130 131 132 133
						SpecialPage::getTitleFor( 'Randompage' ),
						// @codingStandardsIgnoreStart
						'<span class="fa fa-random"></span><span class="hide-title">' . $skin->msg( 'randompage' )->plain() . '</span>',
						// @codingStandardsIgnoreEnd
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
134
							'class' => 'nav-link',
Jack Phoenix's avatar
Jack Phoenix committed
135 136
							'title' => Linker::titleAttrib( 'n-randompage', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'n-randompage' )
Hoto Cocoa's avatar
Hoto Cocoa committed
137 138 139 140 141 142 143 144 145
						]
					); ?>
				</li>
				<?php echo $this->renderPortal( $this->parseNavbar() ); ?>
			</ul>
			<?php $this->loginBox(); ?>
			<?php $this->getNotification(); ?>
			<?php $this->searchBox(); ?>
		</nav>
Hoto Cocoa's avatar
Hoto Cocoa committed
146 147
	<?php
	}
iTsurea's avatar
iTsurea committed
148

Hoto Cocoa's avatar
Hoto Cocoa committed
149 150 151 152
	/**
	 * Search box function, build top menu's search box.
	 */
	protected function searchBox() {
Jack Phoenix's avatar
Jack Phoenix committed
153
		$skin = $this->getSkin();
Hoto Cocoa's avatar
Hoto Cocoa committed
154
	?>
Hoto Cocoa's avatar
Hoto Cocoa committed
155
		<form action="<?php $this->text( 'wgScript' ); ?>" id="searchform" class="form-inline">
Jack Phoenix's avatar
Jack Phoenix committed
156
			<input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ); ?>"/>
Hoto Cocoa's avatar
Hoto Cocoa committed
157 158 159
			<div class="input-group">
				<?php echo $this->makeSearchInput( [ 'class' => 'form-control', 'id' => 'searchInput' ] ); ?>
				<span class="input-group-btn">
Jack Phoenix's avatar
Jack Phoenix committed
160 161
					<button type="submit" name="go"
						value="<?php echo $skin->msg( 'go' )->plain() ?>" id="searchGoButton"
Hoto Cocoa's avatar
Hoto Cocoa committed
162
							class="btn btn-secondary" type="button"><span class="fa fa-eye"></span></button>
Jack Phoenix's avatar
Jack Phoenix committed
163 164 165 166
					<button type="submit" name="fulltext"
						value="<?php echo $skin->msg( 'searchbutton' )->plain() ?>"
						id="mw-searchButton" class="btn btn-secondary" type="button">
						<span class="fa fa-search"></span></button>
Hoto Cocoa's avatar
Hoto Cocoa committed
167 168 169 170 171
				</span>
			</div>
		</form>
	<?php
	}
iTsurea's avatar
iTsurea committed
172

Hoto Cocoa's avatar
Hoto Cocoa committed
173 174 175 176
	/**
	 * Login box function, build top menu's login button.
	 */
	protected function loginBox() {
177
		global $wgLibertyUseGravatar;
Jack Phoenix's avatar
Jack Phoenix committed
178 179

		$skin = $this->getSkin();
180
		$user = $skin->getUser();
Hoto Cocoa's avatar
Hoto Cocoa committed
181 182 183
		?>
		<div class="navbar-login">
			<?php
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
			// If the user is logged in...
			if ( $user->isLoggedIn() ) {
				// ...and Gravatar is enabled in site config...
				if ( $wgLibertyUseGravatar ) {
					// ...and the user has a confirmed email...
					if ( $user->getEmailAuthenticationTimestamp() ) {
						// ...then, and only then, build the correct Gravatar URL
						$email = trim( $user->getEmail() );
						$email = strtolower( $email );
						$email = md5( $email ) . '?d=identicon';
					} else {
						$email = '00000000000000000000000000000000?d=identicon&f=y';
					}
					$avatar = Html::element( 'img', [
						'class' => 'profile-img',
						'src' => '//secure.gravatar.com/avatar/' . $email
					] );
Hoto Cocoa's avatar
Hoto Cocoa committed
201
				} else {
202 203 204 205 206 207 208 209 210
					$avatar = '';
				}

				// SocialProfile support
				if ( class_exists( 'wAvatar' ) ) {
					$avatar = new wAvatar( $user->getId(), 'm' );
					$avatar = $avatar->getAvatarURL( [
						'class' => 'profile-img'
					] );
Hoto Cocoa's avatar
Hoto Cocoa committed
211 212 213 214 215
				}
			?>
				<div class="dropdown login-menu">
					<a class="dropdown-toggle" type="button" id="login-menu"
					   data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
216
						<?php echo $avatar; ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
217 218 219 220
					</a>
					<div class="dropdown-menu dropdown-menu-right login-dropdown-menu"
						 aria-labelledby="login-menu">
						<?php echo Linker::linkKnown(
221 222
							Title::makeTitle( NS_USER, $user->getName() ),
							$user->getName(),
Jack Phoenix's avatar
Jack Phoenix committed
223
							[
Hoto Cocoa's avatar
Hoto Cocoa committed
224 225
								'id' => 'pt-userpage',
								'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
226 227
								'title' => Linker::titleAttrib( 'pt-userpage', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-userpage' )
Hoto Cocoa's avatar
Hoto Cocoa committed
228 229 230
							]
						); ?>
						<div class="dropdown-divider"></div>
231 232 233 234 235 236 237 238 239 240 241 242
						<?php
						if ( class_exists( 'EchoEvent' ) ) {
							echo Linker::linkKnown(
								SpecialPage::getTitleFor( 'Notifications' ),
								$skin->msg( 'notifications' )->plain(),
								[
									'class' => 'dropdown-item',
									'title' => $skin->msg( 'tooltip-pt-notifications-notice' )->text()
								]
							);
						}
						?>
Hoto Cocoa's avatar
Hoto Cocoa committed
243
						<?php echo Linker::linkKnown(
244
							SpecialPage::getTitleFor( 'Contributions', $user->getName() ),
Jack Phoenix's avatar
Jack Phoenix committed
245 246
							$skin->msg( 'mycontris' )->plain(),
							[
Hoto Cocoa's avatar
Hoto Cocoa committed
247
								'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
248 249
								'title' => Linker::titleAttrib( 'pt-mycontris', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-mycontris' )
Hoto Cocoa's avatar
Hoto Cocoa committed
250 251 252
							]
						); ?>
						<?php echo Linker::linkKnown(
253
							Title::makeTitle( NS_USER_TALK, $user->getName() ),
Jack Phoenix's avatar
Jack Phoenix committed
254 255
							$skin->msg( 'mytalk' )->plain(),
							[
Hoto Cocoa's avatar
Hoto Cocoa committed
256
								'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
257 258
								'title' => Linker::titleAttrib( 'pt-mytalk', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-mytalk' )
Hoto Cocoa's avatar
Hoto Cocoa committed
259 260 261
							]
						); ?>
						<?php echo Linker::linkKnown(
Jack Phoenix's avatar
Jack Phoenix committed
262 263 264
							SpecialPage::getTitleFor( 'Watchlist' ),
							$skin->msg( 'watchlist' )->plain(),
							[
Hoto Cocoa's avatar
Hoto Cocoa committed
265
								'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
266 267
								'title' => Linker::titleAttrib( 'pt-watchlist', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-watchlist' )
Hoto Cocoa's avatar
Hoto Cocoa committed
268 269 270 271
							]
						); ?>
						<div class="dropdown-divider"></div>
						<?php echo Linker::linkKnown(
Jack Phoenix's avatar
Jack Phoenix committed
272 273 274
							SpecialPage::getTitleFor( 'Preferences' ),
							$skin->msg( 'preferences' )->plain(),
							[
Hoto Cocoa's avatar
Hoto Cocoa committed
275
								'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
276 277
								'title' => Linker::titleAttrib( 'pt-preferences', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-preferences' )
Hoto Cocoa's avatar
Hoto Cocoa committed
278 279 280 281
							]
						); ?>
						<div class="dropdown-divider view-logout"></div>
						<?php echo Linker::linkKnown(
Jack Phoenix's avatar
Jack Phoenix committed
282 283 284
							SpecialPage::getTitleFor( 'UserLogout' ),
							$skin->msg( 'logout' )->plain(),
							[
Hoto Cocoa's avatar
Hoto Cocoa committed
285
								'class' => 'dropdown-item view-logout',
Jack Phoenix's avatar
Jack Phoenix committed
286 287
								'title' => Linker::titleAttrib( 'pt-logout', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-logout' )
Hoto Cocoa's avatar
Hoto Cocoa committed
288 289 290 291 292
							]
						); ?>
					</div>
				</div>
				<?php echo Linker::linkKnown(
Jack Phoenix's avatar
Jack Phoenix committed
293 294 295
						SpecialPage::getTitleFor( 'UserLogout' ),
						'<span class="fa fa-sign-out"></span>',
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
296
							'class' => 'hide-logout logout-btn',
Jack Phoenix's avatar
Jack Phoenix committed
297 298
							'title' => Linker::titleAttrib( 'pt-logout', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'pt-logout' )
Hoto Cocoa's avatar
Hoto Cocoa committed
299 300 301
						]
					);
				?>
Hoto Cocoa's avatar
Hoto Cocoa committed
302
			<?php } else { ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
303 304 305 306 307 308 309
				<a href="#" class="none-outline" data-toggle="modal" data-target="#login-modal">
					<span class="fa fa-sign-in"></span>
				</a>
			<?php } ?>
		</div>
	<?php
	}
iTsurea's avatar
iTsurea committed
310

Hoto Cocoa's avatar
Hoto Cocoa committed
311 312 313 314
	/**
	 * Login model function, build login menu model.
	 */
	protected function loginModal() {
315 316 317 318 319 320 321 322 323 324 325 326
		$skin = $this->getSkin();
		$title = $skin->getTitle();

		// Probably no point in rendering a login window for the users who are
		// already logged in?
		if ( $skin->getUser()->isLoggedIn() ) {
			return;
		}

		// Turn off Continuous Integration warnings about "too long" lines which are
		// perfectly acceptable in this particular context
		// @codingStandardsIgnoreStart
Hoto Cocoa's avatar
Hoto Cocoa committed
327 328 329 330 331 332 333 334 335
		?>
		<div class="modal fade login-modal" id="login-modal" tabindex="-1"
			 role="dialog" aria-labelledby="login-modalLabel" aria-hidden="true">
			<div class="modal-dialog modal-sm" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
336
						<h4 class="modal-title"><?php echo $skin->msg( 'liberty-login' )->plain() ?></h4>
Hoto Cocoa's avatar
Hoto Cocoa committed
337 338 339 340 341
					</div>
					<div class="modal-body">
						<div id="modal-login-alert" class="alert alert-hidden alert-danger" role="alert">
						</div>
						<form id="modal-loginform" name="userlogin" class="modal-loginform"
342
							  method="post">
Hoto Cocoa's avatar
Hoto Cocoa committed
343
							<input class="loginText form-control" id="wpName1" tabindex="1"
344 345
								   placeholder="<?php echo $skin->msg( 'userlogin-yourname-ph' )->plain() ?>" value="" name="lgname">
							<label for="inputPassword" class="sr-only"><?php echo $skin->msg( 'userlogin-yourpassword' )->plain() ?></label>
Hoto Cocoa's avatar
Hoto Cocoa committed
346
							<input class="loginPassword form-control" id="wpPassword1" tabindex="2"
347
								   placeholder="<?php echo $skin->msg( 'userlogin-yourpassword-ph' )->plain() ?>" type="password" name="lgpassword">
Hoto Cocoa's avatar
Hoto Cocoa committed
348 349
							<div class="modal-checkbox">
								<input name="lgremember" type="checkbox" value="1" id="lgremember" tabindex="3">
350
								<label for="lgremember"><?php echo $skin->msg( 'liberty-remember' )->plain() ?></label>
Hoto Cocoa's avatar
Hoto Cocoa committed
351
							</div>
352
							<input class="btn btn-success btn-block" type="submit" value="<?php echo $skin->msg( 'liberty-login-btn' )->plain() ?>" tabindex="4">
Hoto Cocoa's avatar
Hoto Cocoa committed
353
							<?php echo Linker::linkKnown(
354 355
								SpecialPage::getTitleFor( 'UserLogin' ),
								$skin->msg( 'userlogin-joinproject' ), [
Hoto Cocoa's avatar
Hoto Cocoa committed
356 357 358 359 360 361 362 363
									'class' => 'btn btn-primary btn-block',
									'tabindex' => 5,
									'type' => 'submit'
								], [
									'type' => 'signup',
									'returnto' => $title
								]
							); ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
364
							<?php echo Linker::linkKnown(
365 366
								SpecialPage::getTitleFor( 'PasswordReset' ),
								$skin->msg( 'liberty-forgot-pw' )->plain()
Hoto Cocoa's avatar
Hoto Cocoa committed
367
							); ?>
368 369
							<input type="hidden" name="action" value="login" />
							<input type="hidden" name="format" value="json" />
Hoto Cocoa's avatar
Hoto Cocoa committed
370 371 372
						</form>
					</div>
					<div class="modal-footer">
Hoto Cocoa's avatar
Hoto Cocoa committed
373 374
						<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo $skin->msg( 'liberty-btn-close' )->plain(); ?></button>
						<button type="button" class="btn btn-primary"><?php echo $skin->msg( 'liberty-btn-save-changes' )->plain(); ?></button>
Hoto Cocoa's avatar
Hoto Cocoa committed
375 376 377 378 379
					</div>
				</div>
			</div>
		</div>
	<?php
380 381
		// Turn Continuous Integration stuff back on
		// @codingStandardsIgnoreEnd
Hoto Cocoa's avatar
Hoto Cocoa committed
382
	}
iTsurea's avatar
iTsurea committed
383

Hoto Cocoa's avatar
Hoto Cocoa committed
384 385 386 387
	/**
	 * Live recent function, build right side's Recent menus.
	 */
	protected function liveRecent() {
388 389
		global $wgLibertyEnableLiveRC;

Jack Phoenix's avatar
Jack Phoenix committed
390
		$skin = $this->getSkin();
Hoto Cocoa's avatar
Hoto Cocoa committed
391 392
		$wgLibertyMaxRecent = isset( $GLOBALS['wgLibertyMaxRecent'] ) ?
							  $GLOBALS['wgLibertyMaxRecent'] : 10;
393 394 395 396 397 398

		// Don't bother outputting this if the live RC feature is disabled in
		// site configuration
		if ( !$wgLibertyEnableLiveRC ) {
			return;
		}
Hoto Cocoa's avatar
Hoto Cocoa committed
399 400 401 402 403
		?>
		<div class="live-recent">
			<div class="live-recent-header">
			<ul class="nav nav-tabs">
				<li class="nav-item">
Jack Phoenix's avatar
Jack Phoenix committed
404 405 406
					<a href="javascript:" class="nav-link active" id="liberty-recent-tab1">
						<?php echo $skin->msg( 'recentchanges' )->plain() ?>
					</a>
Hoto Cocoa's avatar
Hoto Cocoa committed
407 408
				</li>
				<li class="nav-item">
Jack Phoenix's avatar
Jack Phoenix committed
409 410 411
					<a href="javascript:" class="nav-link" id="liberty-recent-tab2">
						<?php echo $skin->msg( 'liberty-recent-discussions' )->plain() ?>
					</a>
Hoto Cocoa's avatar
Hoto Cocoa committed
412 413 414 415 416
				</li>
			</ul>
			</div>
			<div class="live-recent-content">
				<ul class="live-recent-list" id="live-recent-list">
Hoto Cocoa's avatar
Hoto Cocoa committed
417 418 419 420
					<?php echo str_repeat(
						'<li><span class="recent-item">&nbsp;</span></li>',
						$wgLibertyMaxRecent
					); ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
421 422 423 424
				</ul>
			</div>
			<div class="live-recent-footer">
				<?php echo Linker::linkKnown(
Jack Phoenix's avatar
Jack Phoenix committed
425 426 427 428
					SpecialPage::getTitleFor( 'Recentchanges' ),
					'<span class="label label-info">' .
						$skin->msg( 'liberty-view-more' )->plain() .
					'</span>'
Hoto Cocoa's avatar
Hoto Cocoa committed
429 430 431 432 433
				); ?>
			</div>
		</div>
	<?php
	}
iTsurea's avatar
iTsurea committed
434

Hoto Cocoa's avatar
Hoto Cocoa committed
435 436 437 438
	/**
	 * Contents tool box function, build article tool menu that will show at article title right.
	 */
	protected function contentsToolbox() {
Jack Phoenix's avatar
Jack Phoenix committed
439 440 441 442 443
		$skin = $this->getSkin();
		$user = $skin->getUser();
		$title = $skin->getTitle();
		$revid = $skin->getRequest()->getText( 'oldid' );
		$watched = $user->isWatched( $skin->getRelevantTitle() ) ? 'unwatch' : 'watch';
iTsurea's avatar
iTsurea committed
444

Hoto Cocoa's avatar
Hoto Cocoa committed
445 446 447 448 449 450 451
		if ( $title->getNamespace() != NS_SPECIAL ) {
			$companionTitle = $title->isTalkPage() ? $title->getSubjectPage() : $title->getTalkPage();
			?>
			<div class="content-tools">
				<div class="btn-group" role="group" aria-label="content-tools">
					<?php echo Linker::linkKnown(
						$title,
Jack Phoenix's avatar
Jack Phoenix committed
452 453
						$skin->msg( 'liberty-purge' )->plain(),
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
454
							'class' => 'btn btn-secondary tools-btn',
Jack Phoenix's avatar
Jack Phoenix committed
455
							'title' => $skin->msg( 'liberty-tooltip-purge' )->plain() . ' [alt+shift+p]',
Hoto Cocoa's avatar
Hoto Cocoa committed
456
							'accesskey' => 'p'
Hoto Cocoa's avatar
Hoto Cocoa committed
457 458
						],
						[ 'action' => 'purge' ]
Jack Phoenix's avatar
Jack Phoenix committed
459 460
					);
					echo Linker::linkKnown(
Hoto Cocoa's avatar
Hoto Cocoa committed
461
						$title,
Jack Phoenix's avatar
Jack Phoenix committed
462 463
						$skin->msg( 'edit' )->plain(),
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
464
							'class' => 'btn btn-secondary tools-btn',
Jack Phoenix's avatar
Jack Phoenix committed
465 466
							'title' => Linker::titleAttrib( 'ca-edit', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'ca-edit' )
Hoto Cocoa's avatar
Hoto Cocoa committed
467 468
						],
						$revid ? [ 'action' => 'edit', 'oldid' => $revid ] : [ 'action' => 'edit' ]
Jack Phoenix's avatar
Jack Phoenix committed
469 470
					);
					echo Linker::linkKnown(
Hoto Cocoa's avatar
Hoto Cocoa committed
471
						$title,
Jack Phoenix's avatar
Jack Phoenix committed
472 473
						$skin->msg( 'addsection' )->plain(),
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
474
							'class' => 'btn btn-secondary tools-btn',
Jack Phoenix's avatar
Jack Phoenix committed
475 476
							'title' => Linker::titleAttrib( 'ca-addsection', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'ca-addsection' )
Hoto Cocoa's avatar
Hoto Cocoa committed
477 478
						],
						[ 'action' => 'edit', 'section' => 'new' ]
Jack Phoenix's avatar
Jack Phoenix committed
479
					);
Hoto Cocoa's avatar
Hoto Cocoa committed
480
					if ( $companionTitle ) {
Jack Phoenix's avatar
Jack Phoenix committed
481 482 483 484 485 486 487 488 489 490 491 492 493 494
						if ( $title->isTalkPage() ) {
							$titlename = $skin->msg( 'articlepage' )->plain();
							$additionalArrayStuff = [
								// @todo FIXME!
								'title' => $titlename . '을 불러옵니다. [alt+shift+t]',
								'accesskey' => 't'
							];
						} else {
							$titlename = $skin->msg( 'talk' )->plain();
							$additionalArrayStuff = [
								'title' => Linker::titleAttrib( 'ca-talk', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'ca-talk' )
							];
						}
Hoto Cocoa's avatar
Hoto Cocoa committed
495
						echo Linker::linkKnown(
Hoto Cocoa's avatar
Hoto Cocoa committed
496
							$companionTitle,
Jack Phoenix's avatar
Jack Phoenix committed
497 498
							$titlename,
							[
Hoto Cocoa's avatar
Hoto Cocoa committed
499
								'class' => 'btn btn-secondary tools-btn',
Jack Phoenix's avatar
Jack Phoenix committed
500
							] + $additionalArrayStuff
Hoto Cocoa's avatar
Hoto Cocoa committed
501 502
						);
					}
Jack Phoenix's avatar
Jack Phoenix committed
503
					echo Linker::linkKnown(
Hoto Cocoa's avatar
Hoto Cocoa committed
504
						$title,
Jack Phoenix's avatar
Jack Phoenix committed
505 506
						$skin->msg( 'history' )->plain(),
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
507
							'class' => 'btn btn-secondary tools-btn',
Jack Phoenix's avatar
Jack Phoenix committed
508 509
							'title' => Linker::titleAttrib( 'ca-history', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'ca-history' )
Hoto Cocoa's avatar
Hoto Cocoa committed
510 511 512 513 514 515 516 517 518
						],
						[ 'action' => 'history' ]
					); ?>
					<button type="button" class="btn btn-secondary tools-btn dropdown-toggle"
							data-toggle="dropdown" aria-expanded="false">
						<span class="caret"></span>
					</button>
					<div class="dropdown-menu dropdown-menu-right" role="menu">
						<?php
Jack Phoenix's avatar
Jack Phoenix committed
519 520
						if ( $title->inNamespaces( NS_USER, NS_USER_TALK ) ) {
							// "User contributions" link on user and user talk pages
Hoto Cocoa's avatar
Hoto Cocoa committed
521 522
							echo Linker::linkKnown(
								SpecialPage::getTitleFor( 'Contributions', $title->getText() ),
Jack Phoenix's avatar
Jack Phoenix committed
523 524
								$skin->msg( 'contributions' )->escaped(),
								[
Hoto Cocoa's avatar
Hoto Cocoa committed
525
									'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
526 527
									'title' => Linker::titleAttrib( 't-contributions', 'withaccess' ),
									'accesskey' => Linker::accesskey( 't-contributions' )
Hoto Cocoa's avatar
Hoto Cocoa committed
528
								]
Hoto Cocoa's avatar
Hoto Cocoa committed
529 530 531 532
							);
						}
						echo Linker::linkKnown(
							$title,
Jack Phoenix's avatar
Jack Phoenix committed
533 534 535 536 537 538 539 540 541
							$skin->msg( $watched )->plain(),
							[
								'class' => 'dropdown-item',
								'title' => Linker::titleAttrib( 'ca-' . $watched, 'withaccess' ),
								'accesskey' => Linker::accesskey( 'ca-' . $watched )
							],
							[ 'action' => $watched ]
						);
						echo Linker::linkKnown(
Hoto Cocoa's avatar
Hoto Cocoa committed
542
							SpecialPage::getTitleFor( 'WhatLinksHere', $title ),
Jack Phoenix's avatar
Jack Phoenix committed
543 544
							$skin->msg( 'whatlinkshere' )->plain(),
							[
Hoto Cocoa's avatar
Hoto Cocoa committed
545
								'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
546 547
								'title' => Linker::titleAttrib( 't-whatlinkshere', 'withaccess' ),
								'accesskey' => Linker::accesskey( 't-whatlinkshere' )
Hoto Cocoa's avatar
Hoto Cocoa committed
548
							]
Jack Phoenix's avatar
Jack Phoenix committed
549 550 551 552 553 554 555 556 557 558 559 560 561
						);
						if ( $title->quickUserCan( 'move', $user ) && $title->exists() ) {
							echo Linker::linkKnown(
								SpecialPage::getTitleFor( 'Movepage', $title ),
								$skin->msg( 'move' )->plain(),
								[
									'class' => 'dropdown-item',
									'title' => Linker::titleAttrib( 'ca-move', 'withaccess' ),
									'accesskey' => Linker::accesskey( 'ca-move' )
								]
							);
						}
						if ( $title->quickUserCan( 'protect', $user ) ) { ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
562
							<div class="dropdown-divider"></div>
Jack Phoenix's avatar
Jack Phoenix committed
563 564 565 566
							<?php
							// different labels depending on whether the page is or isn't protected
							$protectionMsg = $title->isProtected() ? 'unprotect' : 'protect';
							echo Linker::linkKnown(
Hoto Cocoa's avatar
Hoto Cocoa committed
567
								$title,
Jack Phoenix's avatar
Jack Phoenix committed
568 569
								$skin->msg( $protectionMsg )->plain(),
								[
Hoto Cocoa's avatar
Hoto Cocoa committed
570
									'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
571 572
									'title' => Linker::titleAttrib( 'ca-' . $protectionMsg, 'withaccess' ),
									'accesskey' => Linker::accesskey( 'ca-' . $protectionMsg )
Hoto Cocoa's avatar
Hoto Cocoa committed
573 574 575 576
								],
								[ 'action' => 'protect' ]
							); ?>
						<?php } ?>
Jack Phoenix's avatar
Jack Phoenix committed
577
						<?php if ( $title->quickUserCan( 'delete', $user ) && $title->exists() ) { ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
578 579 580
							<div class="dropdown-divider"></div>
							<?php echo Linker::linkKnown(
								$title,
Jack Phoenix's avatar
Jack Phoenix committed
581 582
								$skin->msg( 'delete' )->plain(),
								[
Hoto Cocoa's avatar
Hoto Cocoa committed
583
									'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
584 585
									'title' => Linker::titleAttrib( 'ca-delete', 'withaccess' ),
									'accesskey' => Linker::accesskey( 'ca-delete' )
Hoto Cocoa's avatar
Hoto Cocoa committed
586 587 588 589 590 591 592 593 594 595
								],
								[ 'action' => 'delete' ]
							); ?>
						<?php } ?>
					</div>
				</div>
			</div>
		<?php
		}
	}
iTsurea's avatar
iTsurea committed
596

Hoto Cocoa's avatar
Hoto Cocoa committed
597 598 599 600 601
	/**
	 * Footer function, build footer.
	 */
	protected function footer() {
		foreach ( $this->getFooterLinks() as $category => $links ) { ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
602
			<ul class="footer-<?php echo $category; ?>">
Hoto Cocoa's avatar
Hoto Cocoa committed
603 604 605 606 607 608 609 610
				<?php foreach ( $links as $link ) { ?>
					<li class="footer-<?php echo $category; ?>-<?php echo $link; ?>">
						<?php $this->html( $link ); ?>
					</li>
				<?php } ?>
			</ul>
		<?php
		}
Hoto Cocoa's avatar
Hoto Cocoa committed
611
		$footericons = $this->getFooterIcons( 'icononly' );
Hoto Cocoa's avatar
Hoto Cocoa committed
612
		if ( count( $footericons ) ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
613 614 615 616 617
		?>
			<ul class="footer-icons">
				<?php
				foreach ( $footericons as $blockName => $footerIcons ) {
					?>
Hoto Cocoa's avatar
Hoto Cocoa committed
618
					<li class="footer-<?php echo htmlspecialchars( $blockName ); ?>ico">
Hoto Cocoa's avatar
Hoto Cocoa committed
619 620 621 622 623 624 625 626 627 628 629 630 631
						<?php
						foreach ( $footerIcons as $icon ) {
							echo $this->getSkin()->makeFooterIcon( $icon );
						}
						?>
					</li>
					<?php
				}
				?>
			</ul>
		<?php
		}
	}
iTsurea's avatar
iTsurea committed
632

Hoto Cocoa's avatar
Hoto Cocoa committed
633 634 635 636 637
	/**
	 * Get Notification function, build notification menu.
	 */
	protected function getNotification() {
		$personalTools = $this->getPersonalTools();
Hoto Cocoa's avatar
Hoto Cocoa committed
638 639
		$notiCount = $personalTools['notifications-alert']['links'][0]['text'] +
					 $personalTools['notifications-message']['links'][0]['text'];
Hoto Cocoa's avatar
Hoto Cocoa committed
640
		if ( $notiCount ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
641 642
		?>
			<div id="pt-notifications" class="navbar-notification">
Hoto Cocoa's avatar
Hoto Cocoa committed
643
				<a href="#"><span class="label label-danger"><?php echo $notiCount; ?></span></a>
Hoto Cocoa's avatar
Hoto Cocoa committed
644 645 646 647
			</div>
		<?php
		}
	}
iTsurea's avatar
iTsurea committed
648

Hoto Cocoa's avatar
Hoto Cocoa committed
649 650
	/**
	 * Render Portal function, build top menu contents.
Jack Phoenix's avatar
Jack Phoenix committed
651
	 * @param array $contents Menu data that will made by parseNavbar function.
Hoto Cocoa's avatar
Hoto Cocoa committed
652 653 654
	 */
	protected function renderPortal( $contents ) {
		foreach ( $contents as $content ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
655
			if ( !$content ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
656 657
				break;
			}
Hoto Cocoa's avatar
Hoto Cocoa committed
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692

			echo Html::openElement( 'li', [
				'class' => [ 'dropdown', 'nav-item' ]
			] );
				array_push( $content['classes'], 'nav-link' );
				if ( is_array( $content['children'] ) ) {
					array_push( $content['classes'], 'dropdown-toggle', 'dropdown-toggle-fix' );
				}

				echo Html::openElement( 'a', [
					'class' => $content['classes'],
					'data-toggle' => 'dropdown',
					'role' => 'button',
					'aria-haspopup' => 'true',
					'aria-expanded' => 'true',
					'title' => $content['title']
				] );
					if ( isset( $content['icon'] ) ) {
						echo Html::rawElement( 'span', [
							'class' => 'fa fa-'.$content['icon']
						] );
					}

					if ( isset( $content['text'] ) ) {
						echo Html::rawElement( 'span', [
							'class' => 'hide-title'
						], $content['text'] );
					}
				echo Html::closeElement( 'a' );

				if ( is_array( $content['children'] ) ) {
					echo Html::openElement( 'div', [
						'class' => 'dropdown-menu',
						'role' => 'menu'
					] );
Hoto Cocoa's avatar
Hoto Cocoa committed
693
						foreach ( $content['children'] as $child ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
							array_push( $child['classes'], 'dropdown-item' );
							if ( is_array( $child['children'] ) ) {
								array_push( $child['classes'], 'dropdown-toggle', 'dropdown-toggle-sub' );
							}

							echo Html::openElement( 'a', [
								'accesskey' => $child['access'],
								'class' => $child['classes'],
								'href' => $child['href'],
								'title' => $child['title']
							] );
								if ( isset( $child['icon'] ) ) {
									echo Html::rawElement( 'span', [
										'class' => 'fa fa-'.$child['icon']
									] );
								}

								if ( isset( $child['text'] ) ) {
									echo $child['text'];
								}
							echo Html::closeElement( 'a' );

							if ( is_array( $child['children'] ) ) {
								echo Html::openElement( 'div', [
									'class' => 'dropdown-menu dropdown-submenu',
									'role' => 'menu'
								] );
								foreach ( $child['children'] as $sub ) {
									array_push( $sub['classes'], 'dropdown-item' );
									echo Html::openElement( 'a', [
										'accesskey' => $sub['access'],
										'class' => $sub['classes'],
										'href' => $sub['href'],
										'title' => $sub['title']
									] );
										if ( isset( $sub['icon'] ) ) {
											echo Html::rawElement( 'span', [
												'class' => 'fa fa-'.$sub['icon']
											] );
										}

										if ( isset( $sub['text'] ) ) {
											echo $sub['text'];
										}
									echo Html::closeElement( 'a' );
								}
								echo Html::closeElement( 'div' );
							}
Hoto Cocoa's avatar
Hoto Cocoa committed
742
						}
Hoto Cocoa's avatar
Hoto Cocoa committed
743 744 745
					echo Html::closeElement( 'div' );
				}
			echo Html::closeElement( 'li' );
Hoto Cocoa's avatar
Hoto Cocoa committed
746 747
		}
	}
Hoto Cocoa's avatar
Hoto Cocoa committed
748

Hoto Cocoa's avatar
Hoto Cocoa committed
749
	/**
750 751 752 753 754 755 756
	 * Parse [[MediaWiki:Liberty-Navbar]].
	 *
	 * Its format is:
	 * * <icon name>|Name of the menu displayed to the user
	 * ** link target|Link title (can be the name of an interface message)
	 *
	 * @return array Menu data
Hoto Cocoa's avatar
Hoto Cocoa committed
757 758 759
	 */
	protected function parseNavbar() {
		global $wgArticlePath;
760

Hoto Cocoa's avatar
Hoto Cocoa committed
761 762
		$headings = [];
		$currentHeading = null;
763 764 765 766 767 768 769 770 771 772
		$data = ContentHandler::getContentText( WikiPage::factory(
			Title::newFromText( 'Liberty-Navbar', NS_MEDIAWIKI )
		)->getContent( Revision::RAW ) );
		// Well, [[MediaWiki:Liberty-Navbar]] *should* have some content, but
		// if it doesn't, bail out here so that we don't trigger E_NOTICEs
		// about undefined indexes later on
		if ( empty( $data ) ) {
			return $headings;
		}

Hoto Cocoa's avatar
Hoto Cocoa committed
773
		$lines = explode( "\n", $data );
774

Hoto Cocoa's avatar
Hoto Cocoa committed
775
		foreach ( $lines as $line ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
776
			$line = rtrim( $line, "\r" );
Hoto Cocoa's avatar
Hoto Cocoa committed
777
			if ( $line[0] !== '*' ) {
778
				// Line does not start with '*'
Hoto Cocoa's avatar
Hoto Cocoa committed
779 780 781
				continue;
			}
			if ( $line[1] !== '*' ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
782 783 784 785 786 787 788 789 790 791
				// First level menu
				$split = explode( '|', $line );
				$split[0] = substr( $split[0], 1 );
				foreach ( $split as $key => $value ) {
					$split[$key] = trim( $value );
				}

				// Icon
				$icon = htmlentities( $split[0], ENT_QUOTES, 'UTF-8' );

792 793 794 795
				// support the usual [[MediaWiki:Sidebar]] syntax of
				// ** link target|<some MW: message name> and if the
				// thing on the right side of the pipe isn't the name of a MW:
				// message, then and _only_ then render it as-is
Hoto Cocoa's avatar
Hoto Cocoa committed
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
				$textObj = wfMessage( $split[1] );
				if ( $textObj->isDisabled() ) {
					$text = htmlentities( $split[1], ENT_QUOTES, 'UTF-8' );
				} else {
					$text = $textObj->text();
				}

				// If icon and text both empty
				if ( empty( $icon ) && empty( $text ) ) {
					continue;
				}

				// Title
				if ( isset( $split[2] ) ) {
					$titleObj = wfMessage( $split[2] );
					if ( $titleObj->isDisabled() ) {
						$title = htmlentities( $split[2], ENT_QUOTES, 'UTF-8' );
					} else {
						$title = $titleObj->text();
					}
816
				} else {
Hoto Cocoa's avatar
Hoto Cocoa committed
817
					$title = $text;
818
				}
Hoto Cocoa's avatar
Hoto Cocoa committed
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837

				// Link href
				// @todo CHECKME: Should this use wfUrlProtocols() or somesuch instead?
				if ( preg_match( '/^((?:(?:http(?:s)?)?:)?\/\/(?:.{4,}))$/i', $split[3] ) ) {
					$href = htmlentities( $split[3], ENT_QUOTES, 'UTF-8' );
				} else {
					$href = str_replace( '%3A', ':', urlencode( $split[3] ) );
					$href = str_replace( '$1', $href, $wgArticlePath );
				}

				// Access
				$access = preg_match( '/^([0-9a-z]{1})$/i', $split[4] ) ? $split[4] : '';

				// Classes
				$classes = explode( ',', htmlentities( $split[5], ENT_QUOTES, 'UTF-8' ) );
				foreach ( $classes as $key => $value ) {
					$classes[$key] = trim( $value );
				}

Hoto Cocoa's avatar
Hoto Cocoa committed
838
				$item = [
Hoto Cocoa's avatar
Hoto Cocoa committed
839 840 841 842
					'access' => $access,
					'classes' => $classes,
					'href' => $href,
					'icon' => $icon,
843
					'text' => $text,
Hoto Cocoa's avatar
Hoto Cocoa committed
844
					'title' => $title
Hoto Cocoa's avatar
Hoto Cocoa committed
845
				];
Hoto Cocoa's avatar
Hoto Cocoa committed
846
				$level2Children = &$item['children'];
Hoto Cocoa's avatar
Hoto Cocoa committed
847
				$headings[] = $item;
Hoto Cocoa's avatar
Hoto Cocoa committed
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
			}
			if ( $line[2] !== '*' ) {
				// Second level menu
				$split = explode( '|', $line );
				$split[0] = substr( $split[0], 2 );
				foreach ( $split as $key => $value ) {
					$split[$key] = trim( $value );
				}

				// Icon
				$icon = htmlentities( $split[0], ENT_QUOTES, 'UTF-8' );

				// support the usual [[MediaWiki:Sidebar]] syntax of
				// ** link target|<some MW: message name> and if the
				// thing on the right side of the pipe isn't the name of a MW:
				// message, then and _only_ then render it as-is
				$textObj = wfMessage( $split[1] );
				if ( $textObj->isDisabled() ) {
					$text = htmlentities( $split[1], ENT_QUOTES, 'UTF-8' );
				} else {
					$text = $textObj->text();
				}

				// If icon and text both empty
				if ( empty( $icon ) && empty( $text ) ) {
					continue;
				}

				// Title
				if ( isset( $split[2] ) ) {
					$titleObj = wfMessage( $split[2] );
					if ( $titleObj->isDisabled() ) {
						$title = htmlentities( $split[2], ENT_QUOTES, 'UTF-8' );
					} else {
						$title = $titleObj->text();
					}
				} else {
					$title = $text;
				}

				// Link href
889
				// @todo CHECKME: Should this use wfUrlProtocols() or somesuch instead?
Hoto Cocoa's avatar
Hoto Cocoa committed
890 891
				if ( preg_match( '/^((?:(?:http(?:s)?)?:)?\/\/(?:.{4,}))$/i', $split[3] ) ) {
					$href = htmlentities( $split[3], ENT_QUOTES, 'UTF-8' );
Hoto Cocoa's avatar
Hoto Cocoa committed
892
				} else {
Hoto Cocoa's avatar
Hoto Cocoa committed
893 894
					$href = str_replace( '%3A', ':', urlencode( $split[3] ) );
					$href = str_replace( '$1', $href, $wgArticlePath );
Hoto Cocoa's avatar
Hoto Cocoa committed
895
				}
Hoto Cocoa's avatar
Hoto Cocoa committed
896 897 898 899 900 901 902 903

				// Access
				$access = preg_match( '/^([0-9a-z]{1})$/i', $split[4] ) ? $split[4] : '';

				// Classes
				$classes = explode( ',', htmlentities( $split[5], ENT_QUOTES, 'UTF-8' ) );
				foreach ( $classes as $key => $value ) {
					$classes[$key] = trim( $value );
904
				}
Hoto Cocoa's avatar
Hoto Cocoa committed
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926

				$item = [
					'access' => $access,
					'classes' => $classes,
					'href' => $href,
					'icon' => $icon,
					'text' => $text,
					'title' => $title
				];
				$level3Children = &$item['children'];
				$level2Children[] = $item;
			} else {
				// Third level menu
				$split = explode( '|', $line );
				$split[0] = substr( $split[0], 3 );
				foreach ( $split as $key => $value ) {
					$split[$key] = trim( $value );
				}

				// Icon
				$icon = htmlentities( $split[0], ENT_QUOTES, 'UTF-8' );

927 928 929 930
				// support the usual [[MediaWiki:Sidebar]] syntax of
				// ** link target|<some MW: message name> and if the
				// thing on the right side of the pipe isn't the name of a MW:
				// message, then and _only_ then render it as-is
Hoto Cocoa's avatar
Hoto Cocoa committed
931 932 933
				$textObj = wfMessage( $split[1] );
				if ( $textObj->isDisabled() ) {
					$text = htmlentities( $split[1], ENT_QUOTES, 'UTF-8' );
934
				} else {
Hoto Cocoa's avatar
Hoto Cocoa committed
935
					$text = $textObj->text();
Hoto Cocoa's avatar
Hoto Cocoa committed
936
				}
Hoto Cocoa's avatar
Hoto Cocoa committed
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972

				// If icon and text both empty
				if ( empty( $icon ) && empty( $text ) ) {
					continue;
				}

				// Title
				if ( isset( $split[2] ) ) {
					$titleObj = wfMessage( $split[2] );
					if ( $titleObj->isDisabled() ) {
						$title = htmlentities( $split[2], ENT_QUOTES, 'UTF-8' );
					} else {
						$title = $titleObj->text();
					}
				} else {
					$title = $text;
				}

				// Link href
				// @todo CHECKME: Should this use wfUrlProtocols() or somesuch instead?
				if ( preg_match( '/^((?:(?:http(?:s)?)?:)?\/\/(?:.{4,}))$/i', $split[3] ) ) {
					$href = htmlentities( $split[3], ENT_QUOTES, 'UTF-8' );
				} else {
					$href = str_replace( '%3A', ':', urlencode( $split[3] ) );
					$href = str_replace( '$1', $href, $wgArticlePath );
				}

				// Access
				$access = preg_match( '/^([0-9a-z]{1})$/i', $split[4] ) ? $split[4] : '';

				// Classes
				$classes = explode( ',', htmlentities( $split[5], ENT_QUOTES, 'UTF-8' ) );
				foreach ( $classes as $key => $value ) {
					$classes[$key] = trim( $value );
				}

Hoto Cocoa's avatar
Hoto Cocoa committed
973
				$item = [
Hoto Cocoa's avatar
Hoto Cocoa committed
974 975 976 977
					'access' => $access,
					'classes' => $classes,
					'href' => $href,
					'icon' => $icon,
Hoto Cocoa's avatar
Hoto Cocoa committed
978
					'text' => $text,
Hoto Cocoa's avatar
Hoto Cocoa committed
979
					'title' => $title
Hoto Cocoa's avatar
Hoto Cocoa committed
980
				];
Hoto Cocoa's avatar
Hoto Cocoa committed
981
				$level3Children[] = $item;
Hoto Cocoa's avatar
Hoto Cocoa committed
982 983
			}
		}
984

Hoto Cocoa's avatar
Hoto Cocoa committed
985 986
		return $headings;
	}
Hoto Cocoa's avatar
Hoto Cocoa committed
987 988 989

	/**
	 * Build Adsense Function.
Jack Phoenix's avatar
Jack Phoenix committed
990
	 * @param string $position Ad position
Hoto Cocoa's avatar
Hoto Cocoa committed
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
	 */
	protected function buildAd( $position ) {
		global $wgLibertyAdSetting;
		?>
			<div class="<?php echo $position; ?>-ads">
				<ins class="adsbygoogle"
					data-ad-client="<?php echo $wgLibertyAdSetting['client']; ?>"
					data-ad-slot="<?php echo $wgLibertyAdSetting[$position]; ?>"
					data-ad-format="auto">
				</ins>
			</div>
		<?php
	}
Hoto Cocoa's avatar
Hoto Cocoa committed
1004
}