LibertyTemplate.php 32.9 KB
Newer Older
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
<?php // @codingStandardsIgnoreLine
class LibertyTemplate extends BaseTemplate {
	/**
	 * execute() Method
	 */
	public function execute() {
		global $wgLibertyAdSetting;

		$skin = $this->getSkin();
		$request = $skin->getRequest();
		$action = $request->getVal( 'action', 'view' );
		$title = $skin->getTitle();

		$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>
				<?php if ( !is_null( $wgLibertyAdSetting['right'] ) ) {
					$this->buildAd( 'right' );
				} ?>
			</div>
			</aside>
			<div class="container-fluid liberty-content">
				<div class="liberty-content-header">
					<?php if ( $this->data['sitenotice'] &&
							   !$request->getCookie( 'disable-notice' ) ) { ?>
						<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>
							<?php $this->html( 'sitenotice' ); ?>
						</div>
					<?php } ?>
					<?php if ( !is_null( $wgLibertyAdSetting['header'] ) ) {
						$this->buildAd( 'header' );
					}
					$this->contentsToolbox(); ?>
					<div class="title">
						<h1>
							<?php $this->html( 'title' ); ?>
						</h1>
					</div>
					<div class="contentSub"<?php $this->html( 'userlangattributes' ); ?>>
						<?php $this->html( 'subtitle' ); ?>
					</div>
				</div>
				<div class="liberty-content-main">
					<?php
					// @codingStandardsIgnoreStart
					if ( $title->getNamespace() != NS_SPECIAL &&
							   $action != 'edit' && $action != 'history' ) { ?>
						<div class="social-buttons">
							<div class="twitter" data-text="<?php echo htmlspecialchars( $title, ENT_QUOTES ); ?>" title="<?php echo $skin->msg( 'liberty-twitter' )->escaped() ?>">
								<div><i class="fa fa-twitter"></i></div>
							</div>
							<div class="facebook" data-text="<?php echo htmlspecialchars( $title, ENT_QUOTES ); ?>" title="<?php echo $skin->msg( 'liberty-facebook' )->escaped() ?>">
								<div><i class="fa fa-facebook"></i></div>
							</div>
						</div>
					<?php
					}
					// @codingStandardsIgnoreEnd

					if ( $this->data['catlinks'] ) {
						$this->html( 'catlinks' );
					}
					?>
					<article class="mw-body-content">
						<?php $this->html( 'bodycontent' ); ?>
					</article>
81 82 83
				</div>
				<footer>
				<div class="liberty-footer">
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
					<?php
					if ( $this->data['dataAfterContent'] ) {
						$this->html( 'dataAfterContent' );
					}
					?>
					<div class="bottom-ads"></div>
					<?php $this->footer(); ?>
				</div>
				</footer>
			</div>
		</div>
		</section>
		<?php $this->loginModal(); ?>
		<?php
		$this->printTrail();
		$this->html( 'debughtml' );
		echo Html::closeElement( 'body' );
		echo Html::closeElement( 'html' );
		echo "\n";
	}

	/**
	 * Nav menu function, build top menu.
	 */
	protected function navMenu() {
		$skin = $this->getSkin();
		?>
		<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(
						SpecialPage::getTitleFor( 'Recentchanges' ),
						// @codingStandardsIgnoreStart
						'<span class="fa fa-refresh"></span><span class="hide-title">' . $skin->msg( 'recentchanges' )->plain() . '</span>',
						// @codingStandardsIgnoreEnd
						[
							'class' => 'nav-link',
							'title' => Linker::titleAttrib( 'n-recentchanges', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'n-recentchanges' )
						]
					); ?>
				</li>
				<li class="nav-item">
					<?php echo Linker::linkKnown(
						SpecialPage::getTitleFor( 'Randompage' ),
						// @codingStandardsIgnoreStart
						'<span class="fa fa-random"></span><span class="hide-title">' . $skin->msg( 'randompage' )->plain() . '</span>',
						// @codingStandardsIgnoreEnd
						[
							'class' => 'nav-link',
							'title' => Linker::titleAttrib( 'n-randompage', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'n-randompage' )
						]
					); ?>
				</li>
				<?php echo $this->renderPortal( $this->parseNavbar() ); ?>
			</ul>
			<?php $this->loginBox(); ?>
			<?php $this->getNotification(); ?>
			<?php $this->searchBox(); ?>
		</nav>
	<?php
	}

	/**
	 * Search box function, build top menu's search box.
	 */
	protected function searchBox() {
		$skin = $this->getSkin();
	?>
		<form action="<?php $this->text( 'wgScript' ); ?>" id="searchform" class="form-inline">
			<input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ); ?>"/>
			<div class="input-group">
				<?php echo $this->makeSearchInput( [ 'class' => 'form-control', 'id' => 'searchInput' ] ); ?>
				<span class="input-group-btn">
					<button type="submit" name="go"
						value="<?php echo $skin->msg( 'go' )->plain() ?>" id="searchGoButton"
							class="btn btn-secondary" type="button"><span class="fa fa-eye"></span></button>
					<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>
				</span>
			</div>
		</form>
	<?php
	}

	/**
	 * Login box function, build top menu's login button.
	 */
	protected function loginBox() {
		global $wgLibertyUseGravatar;

		$skin = $this->getSkin();
		$user = $skin->getUser();
		?>
		<div class="navbar-login">
			<?php
			// 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
					] );
				} else {
					$avatar = '';
				}

				// SocialProfile support
				if ( class_exists( 'wAvatar' ) ) {
					$avatar = new wAvatar( $user->getId(), 'm' );
					$avatar = $avatar->getAvatarURL( [
						'class' => 'profile-img'
					] );
				}
			?>
				<div class="dropdown login-menu">
					<a class="dropdown-toggle" type="button" id="login-menu"
					   data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
						<?php echo $avatar; ?>
					</a>
					<div class="dropdown-menu dropdown-menu-right login-dropdown-menu"
						 aria-labelledby="login-menu">
						<?php echo Linker::linkKnown(
							Title::makeTitle( NS_USER, $user->getName() ),
							$user->getName(),
							[
								'id' => 'pt-userpage',
								'class' => 'dropdown-item',
								'title' => Linker::titleAttrib( 'pt-userpage', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-userpage' )
							]
						); ?>
						<div class="dropdown-divider"></div>
						<?php
						if ( class_exists( 'EchoEvent' ) ) {
							$personalTools = $this->getPersonalTools();
							$notiCount = 0;
							if (
								isset( $personalTools['notifications-alert'] ) &&
								$personalTools['notifications-alert'] &&
								isset( $personalTools['notifications-message'] ) &&
								$personalTools['notifications-message']
							) {
								$notiCount = $personalTools['notifications-alert']['links'][0]['text'] +
											$personalTools['notifications-message']['links'][0]['text'];
							}
							echo Linker::linkKnown(
								SpecialPage::getTitleFor( 'Notifications' ),
zlzleking's avatar
zlzleking committed
246
								$skin->msg( 'notifications' )->plain() . ( $notiCount ? " ($notiCount)" : "" ),
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
								[
									'class' => 'dropdown-item',
									'title' => $skin->msg( 'tooltip-pt-notifications-notice' )->text()
								]
							);
						}
						?>
						<?php echo Linker::linkKnown(
							SpecialPage::getTitleFor( 'Contributions', $user->getName() ),
							$skin->msg( 'mycontris' )->plain(),
							[
								'class' => 'dropdown-item',
								'title' => Linker::titleAttrib( 'pt-mycontris', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-mycontris' )
							]
						); ?>
						<?php echo Linker::linkKnown(
							Title::makeTitle( NS_USER_TALK, $user->getName() ),
							$skin->msg( 'mytalk' )->plain(),
							[
								'class' => 'dropdown-item',
								'title' => Linker::titleAttrib( 'pt-mytalk', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-mytalk' )
							]
						); ?>
						<?php echo Linker::linkKnown(
							SpecialPage::getTitleFor( 'Watchlist' ),
							$skin->msg( 'watchlist' )->plain(),
							[
								'class' => 'dropdown-item',
								'title' => Linker::titleAttrib( 'pt-watchlist', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-watchlist' )
							]
						); ?>
						<div class="dropdown-divider"></div>
						<?php echo Linker::linkKnown(
							SpecialPage::getTitleFor( 'Preferences' ),
							$skin->msg( 'preferences' )->plain(),
							[
								'class' => 'dropdown-item',
								'title' => Linker::titleAttrib( 'pt-preferences', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-preferences' )
							]
						); ?>
						<div class="dropdown-divider view-logout"></div>
						<?php echo Linker::linkKnown(
							SpecialPage::getTitleFor( 'UserLogout' ),
							$skin->msg( 'logout' )->plain(),
							[
								'class' => 'dropdown-item view-logout',
								'title' => Linker::titleAttrib( 'pt-logout', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'pt-logout' )
							]
						); ?>
					</div>
				</div>
				<?php echo Linker::linkKnown(
						SpecialPage::getTitleFor( 'UserLogout' ),
						'<span class="fa fa-sign-out"></span>',
						[
							'class' => 'hide-logout logout-btn',
							'title' => Linker::titleAttrib( 'pt-logout', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'pt-logout' )
						]
					);
				?>
			<?php } else { ?>
				<a href="#" class="none-outline" data-toggle="modal" data-target="#login-modal">
					<span class="fa fa-sign-in"></span>
				</a>
			<?php } ?>
		</div>
	<?php
	}

	/**
	 * Login model function, build login menu model.
	 */
	protected function loginModal() {
		$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
		?>
		<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>
						<h4 class="modal-title"><?php echo $skin->msg( 'liberty-login' )->plain() ?></h4>
					</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"
							  method="post">
							<input class="loginText form-control" id="wpName1" tabindex="1"
								   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>
							<input class="loginPassword form-control" id="wpPassword1" tabindex="2"
								   placeholder="<?php echo $skin->msg( 'userlogin-yourpassword-ph' )->plain() ?>" type="password" name="lgpassword">
							<div class="modal-checkbox">
								<input name="lgremember" type="checkbox" value="1" id="lgremember" tabindex="3">
								<label for="lgremember"><?php echo $skin->msg( 'liberty-remember' )->plain() ?></label>
							</div>
							<input class="btn btn-success btn-block" type="submit" value="<?php echo $skin->msg( 'liberty-login-btn' )->plain() ?>" tabindex="4">
							<?php echo Linker::linkKnown(
								SpecialPage::getTitleFor( 'UserLogin' ),
								$skin->msg( 'userlogin-joinproject' ), [
									'class' => 'btn btn-primary btn-block',
									'tabindex' => 5,
									'type' => 'submit'
								], [
									'type' => 'signup',
									'returnto' => $title
								]
							); ?>
							<?php echo Linker::linkKnown(
								SpecialPage::getTitleFor( 'PasswordReset' ),
								$skin->msg( 'liberty-forgot-pw' )->plain()
							); ?>
379
                            <br>
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
							<?php echo Linker::linkKnown(
								SpecialPage::getTitleFor( 'login' ),
								$skin->msg( 'liberty-login-alter' )->plain()
							); ?>
							<input type="hidden" name="action" value="login" />
							<input type="hidden" name="format" value="json" />
						</form>
					</div>
					<div class="modal-footer">
						<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>
					</div>
				</div>
			</div>
		</div>
	<?php
		// Turn Continuous Integration stuff back on
		// @codingStandardsIgnoreEnd
	}

	/**
	 * Live recent function, build right side's Recent menus.
	 */
	protected function liveRecent() {
		global $wgLibertyEnableLiveRC;

		$skin = $this->getSkin();
		$wgLibertyMaxRecent = isset( $GLOBALS['wgLibertyMaxRecent'] ) ?
							  $GLOBALS['wgLibertyMaxRecent'] : 10;

		// Don't bother outputting this if the live RC feature is disabled in
		// site configuration
		if ( !$wgLibertyEnableLiveRC ) {
			return;
		}
		?>
		<div class="live-recent">
			<div class="live-recent-header">
			<ul class="nav nav-tabs">
				<li class="nav-item">
					<a href="javascript:" class="nav-link active" id="liberty-recent-tab1">
						<?php echo $skin->msg( 'recentchanges' )->plain() ?>
					</a>
				</li>
				<li class="nav-item">
					<a href="javascript:" class="nav-link" id="liberty-recent-tab2">
						<?php echo $skin->msg( 'liberty-recent-discussions' )->plain() ?>
					</a>
				</li>
			</ul>
			</div>
			<div class="live-recent-content">
				<ul class="live-recent-list" id="live-recent-list">
					<?php echo str_repeat(
						'<li><span class="recent-item">&nbsp;</span></li>',
						$wgLibertyMaxRecent
					); ?>
				</ul>
			</div>
			<div class="live-recent-footer">
				<?php echo Linker::linkKnown(
					SpecialPage::getTitleFor( 'Recentchanges' ),
					'<span class="label label-info">' .
						$skin->msg( 'liberty-view-more' )->plain() .
					'</span>'
				); ?>
			</div>
		</div>
	<?php
	}

	/**
	 * Contents tool box function, build article tool menu that will show at article title right.
	 */
	protected function contentsToolbox() {
		$skin = $this->getSkin();
		$user = $skin->getUser();
		$title = $skin->getTitle();
		$revid = $skin->getRequest()->getText( 'oldid' );
		$watched = $user->isWatched( $skin->getRelevantTitle() ) ? 'unwatch' : 'watch';
Nessun's avatar
Nessun committed
460
		$editable = isset( $this->data['content_navigation']['views']['edit'] );
461 462 463 464 465
		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">
Nessun's avatar
Nessun committed
466
					<?php
Nessun's avatar
Nessun committed
467
					$editIcon = $editable ? '<i class="fa fa-edit"></i> ' : '<i class="fa fa-lock"></i> ';
468 469
					echo Linker::linkKnown(
						$title,
Nessun's avatar
Nessun committed
470
						$editIcon . $skin->msg( 'edit' )->plain(),
471 472 473 474 475 476 477 478 479
						[
							'class' => 'btn btn-secondary tools-btn',
							'title' => Linker::titleAttrib( 'ca-edit', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'ca-edit' )
						],
						$revid ? [ 'action' => 'edit', 'oldid' => $revid ] : [ 'action' => 'edit' ]
					);
					if ( $companionTitle ) {
						if ( $title->isTalkPage() ) {
Nessun's avatar
Nessun committed
480
							$titlename = $skin->msg( 'nstab-main' )->plain();
481
							$additionalArrayStuff = [
Nessun's avatar
Nessun committed
482 483
								'title' => Linker::titleAttrib( 'ca-nstab-main', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'ca-nstab-main' )
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
							];
						} else {
							$titlename = $skin->msg( 'talk' )->plain();
							$additionalArrayStuff = [
								'title' => Linker::titleAttrib( 'ca-talk', 'withaccess' ),
								'accesskey' => Linker::accesskey( 'ca-talk' )
							];
						}
						echo Linker::linkKnown(
							$companionTitle,
							$titlename,
							[
								'class' => 'btn btn-secondary tools-btn',
							] + $additionalArrayStuff
						);
					}
					echo Linker::linkKnown(
						$title,
						$skin->msg( 'history' )->plain(),
						[
							'class' => 'btn btn-secondary tools-btn',
							'title' => Linker::titleAttrib( 'ca-history', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'ca-history' )
						],
						[ '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
						if ( $title->inNamespaces( NS_USER, NS_USER_TALK ) ) {
							// "User contributions" link on user and user talk pages
							echo Linker::linkKnown(
								SpecialPage::getTitleFor( 'Contributions', $title->getText() ),
								$skin->msg( 'contributions' )->escaped(),
								[
									'class' => 'dropdown-item',
									'title' => Linker::titleAttrib( 't-contributions', 'withaccess' ),
									'accesskey' => Linker::accesskey( 't-contributions' )
								]
							);
						}
Nessun's avatar
Nessun committed
528 529 530 531 532 533 534 535 536 537
						echo Linker::linkKnown(
							$title,
							$skin->msg( 'liberty-purge' )->plain(),
							[
								'class' => 'dropdown-item',
								'title' => $skin->msg( 'liberty-tooltip-purge' )->plain() . ' [alt+shift+p]',
								'accesskey' => 'p'
							],
							[ 'action' => 'purge' ]
						);
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
						echo Linker::linkKnown(
							$title,
							$skin->msg( $watched )->plain(),
							[
								'class' => 'dropdown-item',
								'title' => Linker::titleAttrib( 'ca-' . $watched, 'withaccess' ),
								'accesskey' => Linker::accesskey( 'ca-' . $watched )
							],
							[ 'action' => $watched ]
						);
						echo Linker::linkKnown(
							SpecialPage::getTitleFor( 'WhatLinksHere', $title ),
							$skin->msg( 'whatlinkshere' )->plain(),
							[
								'class' => 'dropdown-item',
								'title' => Linker::titleAttrib( 't-whatlinkshere', 'withaccess' ),
								'accesskey' => Linker::accesskey( 't-whatlinkshere' )
							]
						);
557 558 559 560
						echo Linker::linkKnown(
							$title,
							$skin->msg( 'liberty-info' )->plain(),
							[
zlzleking's avatar
zlzleking committed
561
								'class' => 'dropdown-item',
562 563 564 565
								'title' => $skin->msg( 'liberty-tooltip-info' )->plain() ,
							],
							[ 'action' => 'info' ]
						);
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
						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 ) ) { ?>
							<div class="dropdown-divider"></div>
							<?php
							// different labels depending on whether the page is or isn't protected
							$protectionMsg = $title->isProtected() ? 'unprotect' : 'protect';
							echo Linker::linkKnown(
								$title,
								$skin->msg( $protectionMsg )->plain(),
								[
									'class' => 'dropdown-item',
									'title' => Linker::titleAttrib( 'ca-' . $protectionMsg, 'withaccess' ),
									'accesskey' => Linker::accesskey( 'ca-' . $protectionMsg )
								],
								[ 'action' => 'protect' ]
							); ?>
						<?php } ?>
						<?php if ( $title->quickUserCan( 'delete', $user ) && $title->exists() ) { ?>
							<div class="dropdown-divider"></div>
							<?php echo Linker::linkKnown(
								$title,
								$skin->msg( 'delete' )->plain(),
								[
									'class' => 'dropdown-item',
									'title' => Linker::titleAttrib( 'ca-delete', 'withaccess' ),
									'accesskey' => Linker::accesskey( 'ca-delete' )
								],
								[ 'action' => 'delete' ]
							); ?>
						<?php } ?>
					</div>
				</div>
			</div>
		<?php
		}
	}

	/**
	 * Footer function, build footer.
	 */
	protected function footer() {
		foreach ( $this->getFooterLinks() as $category => $links ) { ?>
			<ul class="footer-<?php echo $category; ?>">
				<?php foreach ( $links as $link ) { ?>
					<li class="footer-<?php echo $category; ?>-<?php echo $link; ?>">
						<?php $this->html( $link ); ?>
					</li>
				<?php } ?>
			</ul>
		<?php
		}
		$footericons = $this->getFooterIcons( 'icononly' );
		if ( count( $footericons ) ) {
		?>
			<ul class="footer-icons">
				<?php
				foreach ( $footericons as $blockName => $footerIcons ) {
					?>
					<li class="footer-<?php echo htmlspecialchars( $blockName ); ?>ico">
						<?php
						foreach ( $footerIcons as $icon ) {
							echo $this->getSkin()->makeFooterIcon( $icon );
						}
						?>
					</li>
					<?php
				}
				?>
644 645
				<li class="designedbylibre">
					<a href="//librewiki.net">
Hoto Cocoa's avatar
Hoto Cocoa committed
646
						<?php // @codingStandardsIgnoreLine ?>
Nessun's avatar
Nessun committed
647
						<img src="<?php echo $this->getSkin()->getSkinStylePath( 'img/designedbylibre.png' ); //phpcs:ignore ?>" style="height:31px" alt="Designed by Librewiki">
648 649
					</a>
				</li>
650 651 652 653 654 655 656 657 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 693 694 695 696 697 698 699 700 701 702 703 704 705 706
			</ul>
		<?php
		}
	}

	/**
	 * Get Notification function, build notification menu.
	 */
	protected function getNotification() {
		$personalTools = $this->getPersonalTools();
		$notiCount = 0;
		if (
			isset( $personalTools['notifications-alert'] ) &&
			$personalTools['notifications-alert'] &&
			isset( $personalTools['notifications-message'] ) &&
			$personalTools['notifications-message']
		) {
			$notiCount = $personalTools['notifications-alert']['links'][0]['text'] +
						 $personalTools['notifications-message']['links'][0]['text'];
		}
		if ( $notiCount ) {
		?>
			<div id="pt-notifications" class="navbar-notification">
				<a href="#"><span class="label label-danger"><?php echo $notiCount; ?></span></a>
			</div>
		<?php
		}
	}

	/**
	 * Render Portal function, build top menu contents.
	 * @param array $contents Menu data that will made by parseNavbar function.
	 */
	protected function renderPortal( $contents ) {
		foreach ( $contents as $content ) {
			if ( !$content ) {
				break;
			}

			echo Html::openElement( 'li', [
				'class' => [ 'dropdown', 'nav-item' ]
			] );
				array_push( $content['classes'], 'nav-link' );
				if ( is_array( $content['children'] ) && count( $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', [
707
							'class' => "fa fa-".$content['icon']  // phpcs:ignore
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
						] );
					}

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

				if ( is_array( $content['children'] ) && count( $content['children'] ) ) {
					// We should fix this
					array_shift( $content['children'] );
					echo Html::openElement( 'div', [
						'class' => 'dropdown-menu',
						'role' => 'menu'
					] );
						foreach ( $content['children'] as $child ) {
							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', [
739
										'class' => 'fa fa-'.$child['icon'] // phpcs:ignore
740 741 742 743 744 745 746 747
									] );
								}

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

Hoto Cocoa's avatar
Hoto Cocoa committed
748
							// @codingStandardsIgnoreLine
Hoto Cocoa's avatar
Hoto Cocoa committed
749
							if ( is_array( $content['children'] ) && count( $content['children'] ) > 2 && !empty( $child['children'] ) ) {
750 751 752 753 754 755 756 757 758 759 760 761 762 763
								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', [
764
												'class' => 'fa fa-'.$sub['icon'] // phpcs:ignore
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
											] );
										}

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

	/**
	 * 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
	 */
	protected function parseNavbar() {
		global $wgArticlePath;

		$headings = [];
		$currentHeading = null;
		$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;
		}

		$lines = explode( "\n", $data );

		foreach ( $lines as $line ) {
			$line = rtrim( $line, "\r" );
			if ( $line[0] !== '*' ) {
				// Line does not start with '*'
				continue;
			}
			if ( $line[1] !== '*' ) {
				// 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' );

				// 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
Nessun's avatar
Nessun committed
854 855 856 857 858 859 860 861
				if ( isset( $split[3] ) ) {
					// @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 );
					}
862
				} else {
Nessun's avatar
Nessun committed
863
					$href = null;
864 865
				}

Nessun's avatar
Nessun committed
866 867 868 869 870 871
				if ( isset( $split[4] ) ) {
					// Access
					$access = preg_match( '/^([0-9a-z]{1})$/i', $split[4] ) ? $split[4] : '';
				} else {
					$access = null;
				}
872

Nessun's avatar
Nessun committed
873 874 875 876 877 878 879
				if ( isset( $split[5] ) ) {
					// Classes
					$classes = explode( ',', htmlentities( $split[5], ENT_QUOTES, 'UTF-8' ) );
					foreach ( $classes as $key => $value ) {
						$classes[$key] = trim( $value );
					}
				} else {
Nessun's avatar
Nessun committed
880
					$classes = [];
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
				}

				$item = [
					'access' => $access,
					'classes' => $classes,
					'href' => $href,
					'icon' => $icon,
					'text' => $text,
					'title' => $title
				];
				$level2Children = &$item['children'];
				$headings[] = $item;
			}
			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;
				}

Nessun's avatar
Nessun committed
933 934 935 936 937 938 939 940 941
				if ( isset( $split[3] ) ) {
					// 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 );
					}
942 943
				}

Nessun's avatar
Nessun committed
944 945 946 947
				if ( isset( $split[4] ) ) {
					// Access
					$access = preg_match( '/^([0-9a-z]{1})$/i', $split[4] ) ? $split[4] : '';
				}
948

Nessun's avatar
Nessun committed
949 950 951 952 953 954
				if ( isset( $split[5] ) ) {
					// Classes
					$classes = explode( ',', htmlentities( $split[5], ENT_QUOTES, 'UTF-8' ) );
					foreach ( $classes as $key => $value ) {
						$classes[$key] = trim( $value );
					}
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
				}

				$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' );

				// 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
				// @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 );
				}

				$item = [
					'access' => $access,
					'classes' => $classes,
					'href' => $href,
					'icon' => $icon,
					'text' => $text,
					'title' => $title
				];
				$level3Children[] = $item;
			}
		}

		return $headings;
	}

	/**
	 * Build Adsense Function.
	 * @param string $position Ad position
	 */
	protected function buildAd( $position ) {
		global $wgLibertyAdSetting;
Nessun's avatar
Nessun committed
1045 1046 1047 1048
		$adFormat = "auto";
		if ( $position === "header" ) {
			$adFormat = "horizontal";
		}
1049 1050 1051 1052 1053
		?>
			<div class="<?php echo $position; ?>-ads">
				<ins class="adsbygoogle"
					data-ad-client="<?php echo $wgLibertyAdSetting['client']; ?>"
					data-ad-slot="<?php echo $wgLibertyAdSetting[$position]; ?>"
Nessun's avatar
Nessun committed
1054
					data-ad-format="<?php echo $adFormat; ?>">
1055 1056 1057 1058 1059
				</ins>
			</div>
		<?php
	}
}