LibertyTemplate.php 30.7 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() {
Jack Phoenix's avatar
Jack Phoenix committed
388
		$skin = $this->getSkin();
Hoto Cocoa's avatar
Hoto Cocoa committed
389 390 391 392 393 394 395
		$wgLibertyMaxRecent = isset( $GLOBALS['wgLibertyMaxRecent'] ) ?
							  $GLOBALS['wgLibertyMaxRecent'] : 10;
		?>
		<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
396 397 398
					<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
399 400
				</li>
				<li class="nav-item">
Jack Phoenix's avatar
Jack Phoenix committed
401 402 403
					<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
404 405 406 407 408
				</li>
			</ul>
			</div>
			<div class="live-recent-content">
				<ul class="live-recent-list" id="live-recent-list">
Hoto Cocoa's avatar
Hoto Cocoa committed
409 410 411 412
					<?php echo str_repeat(
						'<li><span class="recent-item">&nbsp;</span></li>',
						$wgLibertyMaxRecent
					); ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
413 414 415 416
				</ul>
			</div>
			<div class="live-recent-footer">
				<?php echo Linker::linkKnown(
Jack Phoenix's avatar
Jack Phoenix committed
417 418 419 420
					SpecialPage::getTitleFor( 'Recentchanges' ),
					'<span class="label label-info">' .
						$skin->msg( 'liberty-view-more' )->plain() .
					'</span>'
Hoto Cocoa's avatar
Hoto Cocoa committed
421 422 423 424 425
				); ?>
			</div>
		</div>
	<?php
	}
iTsurea's avatar
iTsurea committed
426

Hoto Cocoa's avatar
Hoto Cocoa committed
427 428 429 430
	/**
	 * 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
431 432 433 434 435
		$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
436

Hoto Cocoa's avatar
Hoto Cocoa committed
437 438 439 440 441 442 443
		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
444 445
						$skin->msg( 'liberty-purge' )->plain(),
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
446
							'class' => 'btn btn-secondary tools-btn',
Jack Phoenix's avatar
Jack Phoenix committed
447
							'title' => $skin->msg( 'liberty-tooltip-purge' )->plain() . ' [alt+shift+p]',
Hoto Cocoa's avatar
Hoto Cocoa committed
448
							'accesskey' => 'p'
Hoto Cocoa's avatar
Hoto Cocoa committed
449 450
						],
						[ 'action' => 'purge' ]
Jack Phoenix's avatar
Jack Phoenix committed
451 452
					);
					echo Linker::linkKnown(
Hoto Cocoa's avatar
Hoto Cocoa committed
453
						$title,
Jack Phoenix's avatar
Jack Phoenix committed
454 455
						$skin->msg( 'edit' )->plain(),
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
456
							'class' => 'btn btn-secondary tools-btn',
Jack Phoenix's avatar
Jack Phoenix committed
457 458
							'title' => Linker::titleAttrib( 'ca-edit', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'ca-edit' )
Hoto Cocoa's avatar
Hoto Cocoa committed
459 460
						],
						$revid ? [ 'action' => 'edit', 'oldid' => $revid ] : [ 'action' => 'edit' ]
Jack Phoenix's avatar
Jack Phoenix committed
461 462
					);
					echo Linker::linkKnown(
Hoto Cocoa's avatar
Hoto Cocoa committed
463
						$title,
Jack Phoenix's avatar
Jack Phoenix committed
464 465
						$skin->msg( 'addsection' )->plain(),
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
466
							'class' => 'btn btn-secondary tools-btn',
Jack Phoenix's avatar
Jack Phoenix committed
467 468
							'title' => Linker::titleAttrib( 'ca-addsection', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'ca-addsection' )
Hoto Cocoa's avatar
Hoto Cocoa committed
469 470
						],
						[ 'action' => 'edit', 'section' => 'new' ]
Jack Phoenix's avatar
Jack Phoenix committed
471
					);
Hoto Cocoa's avatar
Hoto Cocoa committed
472
					if ( $companionTitle ) {
Jack Phoenix's avatar
Jack Phoenix committed
473 474 475 476 477 478 479 480 481 482 483 484 485 486
						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
487
						echo Linker::linkKnown(
Hoto Cocoa's avatar
Hoto Cocoa committed
488
							$companionTitle,
Jack Phoenix's avatar
Jack Phoenix committed
489 490
							$titlename,
							[
Hoto Cocoa's avatar
Hoto Cocoa committed
491
								'class' => 'btn btn-secondary tools-btn',
Jack Phoenix's avatar
Jack Phoenix committed
492
							] + $additionalArrayStuff
Hoto Cocoa's avatar
Hoto Cocoa committed
493 494
						);
					}
Jack Phoenix's avatar
Jack Phoenix committed
495
					echo Linker::linkKnown(
Hoto Cocoa's avatar
Hoto Cocoa committed
496
						$title,
Jack Phoenix's avatar
Jack Phoenix committed
497 498
						$skin->msg( 'history' )->plain(),
						[
Hoto Cocoa's avatar
Hoto Cocoa committed
499
							'class' => 'btn btn-secondary tools-btn',
Jack Phoenix's avatar
Jack Phoenix committed
500 501
							'title' => Linker::titleAttrib( 'ca-history', 'withaccess' ),
							'accesskey' => Linker::accesskey( 'ca-history' )
Hoto Cocoa's avatar
Hoto Cocoa committed
502 503 504 505 506 507 508 509 510
						],
						[ '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
511 512
						if ( $title->inNamespaces( NS_USER, NS_USER_TALK ) ) {
							// "User contributions" link on user and user talk pages
Hoto Cocoa's avatar
Hoto Cocoa committed
513 514
							echo Linker::linkKnown(
								SpecialPage::getTitleFor( 'Contributions', $title->getText() ),
Jack Phoenix's avatar
Jack Phoenix committed
515 516
								$skin->msg( 'contributions' )->escaped(),
								[
Hoto Cocoa's avatar
Hoto Cocoa committed
517
									'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
518 519
									'title' => Linker::titleAttrib( 't-contributions', 'withaccess' ),
									'accesskey' => Linker::accesskey( 't-contributions' )
Hoto Cocoa's avatar
Hoto Cocoa committed
520
								]
Hoto Cocoa's avatar
Hoto Cocoa committed
521 522 523 524
							);
						}
						echo Linker::linkKnown(
							$title,
Jack Phoenix's avatar
Jack Phoenix committed
525 526 527 528 529 530 531 532 533
							$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
534
							SpecialPage::getTitleFor( 'WhatLinksHere', $title ),
Jack Phoenix's avatar
Jack Phoenix committed
535 536
							$skin->msg( 'whatlinkshere' )->plain(),
							[
Hoto Cocoa's avatar
Hoto Cocoa committed
537
								'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
538 539
								'title' => Linker::titleAttrib( 't-whatlinkshere', 'withaccess' ),
								'accesskey' => Linker::accesskey( 't-whatlinkshere' )
Hoto Cocoa's avatar
Hoto Cocoa committed
540
							]
Jack Phoenix's avatar
Jack Phoenix committed
541 542 543 544 545 546 547 548 549 550 551 552 553
						);
						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
554
							<div class="dropdown-divider"></div>
Jack Phoenix's avatar
Jack Phoenix committed
555 556 557 558
							<?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
559
								$title,
Jack Phoenix's avatar
Jack Phoenix committed
560 561
								$skin->msg( $protectionMsg )->plain(),
								[
Hoto Cocoa's avatar
Hoto Cocoa committed
562
									'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
563 564
									'title' => Linker::titleAttrib( 'ca-' . $protectionMsg, 'withaccess' ),
									'accesskey' => Linker::accesskey( 'ca-' . $protectionMsg )
Hoto Cocoa's avatar
Hoto Cocoa committed
565 566 567 568
								],
								[ 'action' => 'protect' ]
							); ?>
						<?php } ?>
Jack Phoenix's avatar
Jack Phoenix committed
569
						<?php if ( $title->quickUserCan( 'delete', $user ) && $title->exists() ) { ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
570 571 572
							<div class="dropdown-divider"></div>
							<?php echo Linker::linkKnown(
								$title,
Jack Phoenix's avatar
Jack Phoenix committed
573 574
								$skin->msg( 'delete' )->plain(),
								[
Hoto Cocoa's avatar
Hoto Cocoa committed
575
									'class' => 'dropdown-item',
Jack Phoenix's avatar
Jack Phoenix committed
576 577
									'title' => Linker::titleAttrib( 'ca-delete', 'withaccess' ),
									'accesskey' => Linker::accesskey( 'ca-delete' )
Hoto Cocoa's avatar
Hoto Cocoa committed
578 579 580 581 582 583 584 585 586 587
								],
								[ 'action' => 'delete' ]
							); ?>
						<?php } ?>
					</div>
				</div>
			</div>
		<?php
		}
	}
iTsurea's avatar
iTsurea committed
588

Hoto Cocoa's avatar
Hoto Cocoa committed
589 590 591 592 593
	/**
	 * Footer function, build footer.
	 */
	protected function footer() {
		foreach ( $this->getFooterLinks() as $category => $links ) { ?>
Hoto Cocoa's avatar
Hoto Cocoa committed
594
			<ul class="footer-<?php echo $category; ?>">
Hoto Cocoa's avatar
Hoto Cocoa committed
595 596 597 598 599 600 601 602
				<?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
603
		$footericons = $this->getFooterIcons( 'icononly' );
Hoto Cocoa's avatar
Hoto Cocoa committed
604
		if ( count( $footericons ) ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
605 606 607 608 609
		?>
			<ul class="footer-icons">
				<?php
				foreach ( $footericons as $blockName => $footerIcons ) {
					?>
Hoto Cocoa's avatar
Hoto Cocoa committed
610
					<li class="footer-<?php echo htmlspecialchars( $blockName ); ?>ico">
Hoto Cocoa's avatar
Hoto Cocoa committed
611 612 613 614 615 616 617 618 619 620 621 622 623
						<?php
						foreach ( $footerIcons as $icon ) {
							echo $this->getSkin()->makeFooterIcon( $icon );
						}
						?>
					</li>
					<?php
				}
				?>
			</ul>
		<?php
		}
	}
iTsurea's avatar
iTsurea committed
624

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

Hoto Cocoa's avatar
Hoto Cocoa committed
641 642
	/**
	 * Render Portal function, build top menu contents.
Jack Phoenix's avatar
Jack Phoenix committed
643
	 * @param array $contents Menu data that will made by parseNavbar function.
Hoto Cocoa's avatar
Hoto Cocoa committed
644 645 646
	 */
	protected function renderPortal( $contents ) {
		foreach ( $contents as $content ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
647
			if ( !$content ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
648 649
				break;
			}
Hoto Cocoa's avatar
Hoto Cocoa committed
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

			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
685
						foreach ( $content['children'] as $child ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
686 687 688 689 690 691 692 693 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
							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
734
						}
Hoto Cocoa's avatar
Hoto Cocoa committed
735 736 737
					echo Html::closeElement( 'div' );
				}
			echo Html::closeElement( 'li' );
Hoto Cocoa's avatar
Hoto Cocoa committed
738 739
		}
	}
Hoto Cocoa's avatar
Hoto Cocoa committed
740

Hoto Cocoa's avatar
Hoto Cocoa committed
741
	/**
742 743 744 745 746 747 748
	 * 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
749 750 751
	 */
	protected function parseNavbar() {
		global $wgArticlePath;
752

Hoto Cocoa's avatar
Hoto Cocoa committed
753 754
		$headings = [];
		$currentHeading = null;
755 756 757 758 759 760 761 762 763 764
		$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
765
		$lines = explode( "\n", $data );
766

Hoto Cocoa's avatar
Hoto Cocoa committed
767
		foreach ( $lines as $line ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
768
			$line = rtrim( $line, "\r" );
Hoto Cocoa's avatar
Hoto Cocoa committed
769
			if ( $line[0] !== '*' ) {
770
				// Line does not start with '*'
Hoto Cocoa's avatar
Hoto Cocoa committed
771 772 773
				continue;
			}
			if ( $line[1] !== '*' ) {
Hoto Cocoa's avatar
Hoto Cocoa committed
774 775 776 777 778 779 780 781 782 783
				// 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' );

784 785 786 787
				// 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
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
				$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();
					}
808
				} else {
Hoto Cocoa's avatar
Hoto Cocoa committed
809
					$title = $text;
810
				}
Hoto Cocoa's avatar
Hoto Cocoa committed
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829

				// 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
830
				$item = [
Hoto Cocoa's avatar
Hoto Cocoa committed
831 832 833 834
					'access' => $access,
					'classes' => $classes,
					'href' => $href,
					'icon' => $icon,
835
					'text' => $text,
Hoto Cocoa's avatar
Hoto Cocoa committed
836
					'title' => $title
Hoto Cocoa's avatar
Hoto Cocoa committed
837
				];
Hoto Cocoa's avatar
Hoto Cocoa committed
838
				$level2Children = &$item['children'];
Hoto Cocoa's avatar
Hoto Cocoa committed
839
				$headings[] = $item;
Hoto Cocoa's avatar
Hoto Cocoa committed
840 841 842 843 844 845 846 847 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
			}
			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
881
				// @todo CHECKME: Should this use wfUrlProtocols() or somesuch instead?
Hoto Cocoa's avatar
Hoto Cocoa committed
882 883
				if ( preg_match( '/^((?:(?:http(?:s)?)?:)?\/\/(?:.{4,}))$/i', $split[3] ) ) {
					$href = htmlentities( $split[3], ENT_QUOTES, 'UTF-8' );
Hoto Cocoa's avatar
Hoto Cocoa committed
884
				} else {
Hoto Cocoa's avatar
Hoto Cocoa committed
885 886
					$href = str_replace( '%3A', ':', urlencode( $split[3] ) );
					$href = str_replace( '$1', $href, $wgArticlePath );
Hoto Cocoa's avatar
Hoto Cocoa committed
887
				}
Hoto Cocoa's avatar
Hoto Cocoa committed
888 889 890 891 892 893 894 895

				// 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 );
896
				}
Hoto Cocoa's avatar
Hoto Cocoa committed
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918

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

919 920 921 922
				// 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
923 924 925
				$textObj = wfMessage( $split[1] );
				if ( $textObj->isDisabled() ) {
					$text = htmlentities( $split[1], ENT_QUOTES, 'UTF-8' );
926
				} else {
Hoto Cocoa's avatar
Hoto Cocoa committed
927
					$text = $textObj->text();
Hoto Cocoa's avatar
Hoto Cocoa committed
928
				}
Hoto Cocoa's avatar
Hoto Cocoa committed
929 930 931 932 933 934 935 936 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

				// 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
965
				$item = [
Hoto Cocoa's avatar
Hoto Cocoa committed
966 967 968 969
					'access' => $access,
					'classes' => $classes,
					'href' => $href,
					'icon' => $icon,
Hoto Cocoa's avatar
Hoto Cocoa committed
970
					'text' => $text,
Hoto Cocoa's avatar
Hoto Cocoa committed
971
					'title' => $title
Hoto Cocoa's avatar
Hoto Cocoa committed
972
				];
Hoto Cocoa's avatar
Hoto Cocoa committed
973
				$level3Children[] = $item;
Hoto Cocoa's avatar
Hoto Cocoa committed
974 975
			}
		}
976

Hoto Cocoa's avatar
Hoto Cocoa committed
977 978
		return $headings;
	}
Hoto Cocoa's avatar
Hoto Cocoa committed
979 980 981

	/**
	 * Build Adsense Function.
Jack Phoenix's avatar
Jack Phoenix committed
982
	 * @param string $position Ad position
Hoto Cocoa's avatar
Hoto Cocoa committed
983 984 985 986 987 988 989 990 991 992 993 994 995
	 */
	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
996
}