Debian Codegraph @

includes/GreyStuffTemplate.php

raw symbols SCIP
1 <?php
2
3 /**
4 * GreyStuff skin stuff.
5 *
6 * @file
7 * @ingroup Skins
8 * @author Calimonius the Estrange
9 * @author Jack Phoenix
10 * @authors Whoever wrote monobook
11 * @date 2014
12 *
13 */
14
15 use MediaWiki\ResourceLoader\SkinModule;
16
17 /**
18 * Main skin class
19 * @ingroup Skins
20 */
21 class GreyStuffTemplate extends BaseTemplate {
22
23 /**
24 * @inheritDoc
25 */
26 public function execute() {
27 // Apparently not set by default?
28 $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
29
30 // Move some content actions links
31 if ( isset( $this->data['content_navigation']['actions']['watch'] ) ) {
32 $this->data['content_navigation']['views2']['watch']
33 = $this->data['content_navigation']['actions']['watch'];
34 unset( $this->data['content_navigation']['actions']['watch'] );
35 }
36 if ( isset( $this->data['content_navigation']['actions']['unwatch'] ) ) {
37 $this->data['content_navigation']['views2']['unwatch']
38 = $this->data['content_navigation']['actions']['unwatch'];
39 unset( $this->data['content_navigation']['actions']['unwatch'] );
40 }
41 if ( isset( $this->data['content_navigation']['views']['history'] ) ) {
42 $this->data['sidebar']['TOOLBOX']['history'] = $this->data['content_navigation']['views']['history'];
43 $this->data['sidebar']['TOOLBOX']['history']['text'] = $this->getMsg( 'greystuff-history' )->text();
44 unset( $this->data['content_navigation']['views']['history'] );
45 }
46
47 // Open html, body elements, etc
48 $html = '';
49
50 $html .= Html::openElement( 'div', [ 'id' => 'globalWrapper' ] );
51
52 $html .= Html::rawElement(
53 'div',
54 [ 'id' => 'header-container', 'lang' => $this->get( 'userlang' ), 'dir' => $this->get( 'dir' ) ],
55 Html::rawElement( 'div', [ 'id' => 'header-top-container' ],
56 Html::rawElement( 'div', [ 'id' => 'header-top' ],
57 Html::element( 'a', [ 'href' => '#footer-navigation', 'id' => 'jump-to-end' ] ) .
58 Html::rawElement( 'div', [ 'id' => 'main-banner' ], $this->getBanner() ) .
59 Html::element( 'div', [ 'id' => 'menus-cover' ] ) .
60 Html::element( 'div', [ 'id' => 'main-menu-toggle' ] ) .
61 Html::element( 'div', [ 'id' => 'personal-menu-toggle' ] ) .
62 Html::element( 'div', [ 'id' => 'tools-menu-toggle' ] ) .
63
64 $this->getPersonalNavigation() .
65 Html::element( 'div', [ 'class' => 'mobileClear' ] ) .
66 $this->getSearch() .
67 $this->getClear()
68 )
69 )
70 );
71
72 $html .= $this->getClear();
73
74 $html .= Html::rawElement( 'div', [ 'id' => 'header-navigation-container' ],
75 Html::rawElement( 'div', [ 'id' => 'header-navigation' ],
76 $this->getMainNavigation()
77 )
78 );
79
80 $html .= Html::rawElement( 'div', [ 'id' => 'content-container' ],
81 Html::rawElement( 'div', [ 'id' => 'content', 'class' => 'mw-body-primary', 'role' => 'main' ],
82 Html::element( 'a', [ 'id' => 'top' ] ) .
83 $this->getSiteNotice() .
84 $this->getSubtitle() .
85 $this->getContentHeader() .
86 // for double underline on the header
87 Html::element( 'div', [ 'id' => 'content-header-inner' ] ) .
88
89 $this->getClear() .
90
91 Html::rawElement( 'div', [ 'id' => 'bodyContent', 'class' => 'mw-body-content' ],
92 Html::rawElement( 'div', [ 'id' => 'siteSub' ], $this->getMsg( 'tagline' ) ) .
93 $this->get( 'bodytext' ) .
94 $this->getClear()
95 ) .
96 $this->getAfterContent()
97 )
98 );
99
100 $html .= Html::rawElement( 'div', [ 'id' => 'footer' ],
101 Html::rawElement( 'div', [ 'id' => 'footer-banner' ], $this->getBanner( 'p-banner-footer' ) ) .
102 Html::rawElement( 'div', [ 'id' => 'footer-navigation' ],
103 Html::element( 'a', [ 'href' => '#header-container', 'id' => 'return-to-top' ] ) .
104 $this->getMainNavigation( 'f' )
105 ) .
106 $this->getClear() .
107 $this->getFooterBlock( [ 'id' => 'footer-bottom' ] )
108 );
109
110 echo $html;
111 }
112
113 /**
114 * Generate a block of navigation links with a header
115 *
116 * Re-copied out of splash, perhaps not the best idea. (Original comment: '<INSERT SCREAMING>')
117 *
118 * @param string $name
119 * @param array|string $content array of links for use with makeListItem, or a block of text
120 * @param null|string|array $msg
121 * @param array $setOptions random crap to rename/do/whatever
122 *
123 * @return string HTML
124 */
125 protected function getPortlet( $name, $content, $msg = null, $setOptions = [] ) {
126 // random stuff to override with any provided options
127 $options = $setOptions + [
128 // extra classes/ids
129 'id' => 'p-' . $name,
130 'class' => [ 'mw-portlet', 'emptyPortlet' => !$content ],
131 'extra-classes' => [],
132 // what to wrap the body list in, if anything
133 'body-wrapper' => 'div',
134 'body-id' => '',
135 'body-class' => 'mw-portlet-body',
136 'body-extra-classes' => [],
137 // makeListItem options
138 'list-item' => [ 'text-wrapper' => [ 'tag' => 'span' ] ],
139 // option to stick arbitrary stuff at the beginning of the ul
140 'list-prepend' => '',
141 'extra-header' => false,
142 'incontentlanguage' => false,
143 'prefix' => 'p'
144 ];
145
146 // Handle the different $msg possibilities
147 if ( $msg === null ) {
148 $msg = $name;
149 } elseif ( is_array( $msg ) ) {
150 $msgString = array_shift( $msg );
151 $msgParams = $msg;
152 $msg = $msgString;
153 }
154 if ( $options['incontentlanguage'] ) {
155 $msgObj = $this->getMsg( $msg )->inContentLanguage();
156 } else {
157 $msgObj = $this->getMsg( $msg );
158 }
159 if ( $msgObj->exists() ) {
160 if ( !empty( $msgParams ) ) {
161 $msgString = $this->getMsg( $msg, $msgParams )->parse();
162 } else {
163 $msgString = $msgObj->parse();
164 }
165 } else {
166 $msgString = htmlspecialchars( $msg );
167 }
168
169 $labelId = Sanitizer::escapeIdForAttribute( "{$options['prefix']}-$name-label" );
170
171 if ( is_array( $content ) ) {
172 if ( !count( $content ) ) {
173 return '';
174 }
175
176 $contentText = '';
177 if ( $options['extra-header'] ) {
178 $contentText .= Html::rawElement( 'h3', [], $msgString );
179 }
180
181 $contentText .= Html::openElement( 'ul',
182 [ 'lang' => $this->get( 'userlang' ), 'dir' => $this->get( 'dir' ) ]
183 );
184 $contentText .= $options['list-prepend'];
185 foreach ( $content as $key => $item ) {
186 $contentText .= $this->makeListItem( $key, $item, $options['list-item'] );
187 }
188 $contentText .= Html::closeElement( 'ul' );
189 } else {
190 $contentText = $content;
191 }
192
193 // Special handling for role=search and other weird things
194 $divOptions = [
195 'role' => 'navigation',
196 'class' => $this->mergeClasses( $options['class'], $options['extra-classes'] ),
197 'id' => Sanitizer::escapeIdForAttribute( $options['id'] ),
198 'title' => Linker::titleAttrib( $options['id'] ),
199 'aria-labelledby' => $labelId,
200 ];
201
202 $labelOptions = [
203 'id' => $labelId,
204 'lang' => $this->get( 'userlang' ),
205 'dir' => $this->get( 'dir' )
206 ];
207
208 // @phan-suppress-next-line PhanSuspiciousValueComparison
209 if ( $options['body-wrapper'] !== 'none' ) {
210 $bodyDivOptions = [ 'class' => $this->mergeClasses(
211 $options['body-class'],
212 $options['body-extra-classes']
213 ) ];
214 if ( strlen( $options['body-id'] ) ) {
215 $bodyDivOptions['id'] = $options['body-id'];
216 }
217 $body = Html::rawElement( $options['body-wrapper'], $bodyDivOptions,
218 $contentText .
219 $this->getSkin()->getAfterPortlet( $name )
220 );
221 } else {
222 $body = $contentText . $this->getSkin()->getAfterPortlet( $name );
223 }
224
225 $html = Html::rawElement( 'div', $divOptions,
226 Html::rawElement( 'h3', $labelOptions, $msgString ) .
227 $body
228 );
229
230 return $html;
231 }
232
233 /**
234 * Helper function for getPortlet
235 *
236 * Merge all provided css classes into a single array
237 * Account for possible different input methods matching what Html::element stuff takes
238 *
239 * @param string|array $class base portlet/body class
240 * @param string|array $extraClasses any extra classes to also include
241 *
242 * @return array all classes to apply
243 */
244 protected function mergeClasses( $class, $extraClasses ) {
245 if ( !is_array( $class ) ) {
246 $class = [ $class ];
247 }
248 if ( !is_array( $extraClasses ) ) {
249 $extraClasses = [ $extraClasses ];
250 }
251
252 return array_merge( $class, $extraClasses );
253 }
254
255 /**
256 * Get first heading, with page tool stuff
257 *
258 * @return string html
259 */
260 protected function getContentHeader() {
261 $html = Html::openElement( 'div', [ 'id' => 'content-header' ] );
262
263 $html .= Html::rawElement(
264 'h1',
265 [ 'id' => 'firstHeading', 'class' => 'firstHeading', 'lang' => $this->get( 'pageLanguage' ) ],
266 $this->get( 'title' )
267 );
268 $html .= Html::element( 'div', [ 'class' => 'mobileClear' ] ) .
269 $this->getIndicators() .
270 Html::rawElement( 'div', [ 'id' => 'page-namespaces' ],
271 $this->getPortlet( 'namespaces', $this->data['content_navigation']['namespaces'] )
272 );
273
274 $pageTools = Html::openElement( 'div', [ 'id' => 'page-tools' ] );
275 $pageTools .= $this->getPortlet(
276 'views',
277 $this->data['content_navigation']['views']
278 );
279 $pageTools .= $this->getPortlet(
280 'actions',
281 $this->data['content_navigation']['actions'],
282 null,
283 [ 'body-extra-classes' => [ 'dropdown' ] ]
284 );
285 if ( isset( $this->data['content_navigation']['views2'] ) ) {
286 $pageTools .= $this->getPortlet(
287 'more-actions',
288 $this->data['content_navigation']['views2'],
289 'actions'
290 );
291 }
292 $pageTools .= Html::closeElement( 'div' );
293
294 $html .= $pageTools;
295 $html .= Html::closeElement( 'div' );
296
297 return $html;
298 }
299
300 /**
301 * Get all main navigation portlets, sectioned into navigation and navigation-tools divs
302 *
303 * @param string $idPrefix
304 *
305 * @return string html
306 */
307 protected function getMainNavigation( $idPrefix = '' ) {
308 $sidebar = $this->data['sidebar'];
309 $toolbox = $sidebar['TOOLBOX'];
310 $languageUrls = $sidebar['LANGUAGES'];
311 $sidebar['SEARCH'] = false;
312 $sidebar['TOOLBOX'] = false;
313 $sidebar['LANGUAGES'] = false;
314
315 // Add some extra links to the toolbox
316 $skin = $this->getSkin();
317 $title = $skin->getTitle();
318 $toolbox['purge'] = [
319 'text' => $this->getMsg( 'greystuff-purge' )->text(),
320 'id' => 't-purge',
321 'href' => $title->getLocalURL( [ 'action' => 'purge' ] ),
322 'rel' => 'nofollow'
323 ];
324
325 $html = '';
326 if ( $idPrefix !== '' ) {
327 foreach ( $toolbox as $item => $details ) {
328 $toolbox[$item]['id'] = $idPrefix . $details['id'];
329 }
330 }
331
332 // Main navigation, from [[MediaWiki:Sidebar]]
333 $mainBlock = '';
334 foreach ( $sidebar as $name => $content ) {
335 // is_array() check to skip things like [[mw:Extension:NewsBox]]
336 // which output raw HTML and would thus trigger an "invalid argument
337 // supplied for foreach() in line ..." on the foreach() loop below
338 if ( $content === false || !is_array( $content ) ) {
339 continue;
340 }
341 // Numeric strings gets an integer when set as key, cast back - T73639
342 $name = (string)$name;
343
344 if ( $idPrefix !== '' ) {
345 foreach ( $content as $item => $details ) {
346 $content[$item]['id'] = $idPrefix . $details['id'];
347 }
348 }
349 $mainBlock .= $this->getPortlet( $name, $content, null, [
350 'body-extra-classes' => [ 'dropdown' ],
351 'id' => $idPrefix . 'p-' . $name,
352 'prefix' => $idPrefix . 'p'
353 ] );
354 }
355
356 // Site and page tools (toolbox, languages)
357 $toolsBlock = '';
358 if ( $languageUrls || $this->getSkin()->getAfterPortlet( 'lang' ) !== '' ) {
359 $toolsBlock .= $this->getPortlet( 'lang', $languageUrls, 'otherlanguages', [
360 'body-extra-classes' => [ 'dropdown' ],
361 'id' => $idPrefix . 'p-lang',
362 'prefix' => $idPrefix . 'p'
363 ] );
364 }
365 if ( isset( $this->data['variant_urls'] ) && $this->data['variant_urls'] !== false ) {
366 $toolsBlock .= $this->getPortlet( 'variants', $this->data['variant_urls'], null, [
367 'body-extra-classes' => [ 'dropdown' ],
368 'id' => $idPrefix . 'p-variants',
369 'prefix' => $idPrefix . 'p'
370 ] );
371 }
372 $toolsBlock .= $this->getPortlet( 'tbx', $toolbox, 'toolbox', [
373 'body-extra-classes' => [ 'dropdown' ],
374 'id' => $idPrefix . 'p-tbx',
375 'prefix' => $idPrefix . 'p'
376 ] );
377
378 $html .= Html::rawElement( 'div', [ 'class' => 'navigation' ], $mainBlock );
379 $html .= Html::rawElement( 'div', [ 'class' => 'navigation-tools' ], $toolsBlock );
380
381 return $html;
382 }
383
384 /**
385 * Get the banner for the site (including the logo image)
386 *
387 * We assume any meaningful subtitle will contain more than one character to allow for use
388 * cases such as '-' and the like (content that sets it to functionally nothing). May or may
389 * not be a valid assumption in practice.
390 *
391 * @param string $id
392 *
393 * @return string html
394 */
395 protected function getBanner( $id = 'p-banner' ) {
396 $config = $this->getSkin()->getContext()->getConfig();
397 $logos = SkinModule::getAvailableLogos( $config );
398 $html = '';
399
400 if ( $config->get( 'GreyStuffUseLogoImage' ) ) {
401 if ( !isset( $logos['icon'] ) ) {
402 // Oldschool wgLogo via RL
403 $html .= Html::rawElement( 'div', [ 'class' => 'p-logo', 'role' => 'banner' ],
404 Html::element( 'a', array_merge( [
405 'class' => 'mw-wiki-logo',
406 'href' => $this->data['nav_urls']['mainpage']['href'] ],
407 Linker::tooltipAndAccesskeyAttribs( 'p-logo' )
408 ) )
409 );
410
411 // The above needs to be a separate link due to how the image is applied, soo...
412 $html .= Html::openElement( 'a', [ 'href' => $this->data['nav_urls']['mainpage']['href'] ] );
413 } else {
414 $html .= Html::openElement( 'a', array_merge(
415 [ 'href' => $this->data['nav_urls']['mainpage']['href'] ],
416 Linker::tooltipAndAccesskeyAttribs( 'p-logo' )
417 ) );
418 $html .= Html::element( 'img', [ 'src' => $logos['icon'], 'class' => 'p-logo' ] );
419 }
420 } else {
421 // No image logo, but we still gotta open the link for the banner stuff...
422 $html .= Html::openElement( 'a', array_merge(
423 [ 'href' => $this->data['nav_urls']['mainpage']['href'] ],
424 Linker::tooltipAndAccesskeyAttribs( 'p-logo' )
425 ) );
426 }
427
428 $subtitleText = $this->getMsg( 'sitesubtitle' )->inContentLanguage()->text();
429 $wordmarkText = $this->getMsg( 'sitetitle' )->inContentLanguage()->text();
430
431 $bannerClass = [ 'mw-portlet', 'p-banner' ];
432 if ( isset( $logos['tagline'] ) ) {
433 $taglineData = $logos['tagline'];
434 $subtitle = Html::rawElement( 'div', [ 'class' => 'sitesubtitle' ],
435 Html::element( 'img', [
436 'src' => $taglineData['src'],
437 'height' => $taglineData['height'] ?? null,
438 'width' => $taglineData['width'] ?? null,
439 'alt' => $subtitleText
440 ] )
441 );
442 $bannerClass[] = 'full-banner';
443 } elseif ( strlen( $subtitleText ) > 1 ) {
444 $subtitle = Html::element( 'div', [ 'class' => 'sitesubtitle' ], $subtitleText );
445 $bannerClass[] = 'full-banner';
446 } else {
447 $subtitle = '';
448 $bannerClass[] = 'title-banner';
449 }
450
451 // Wordmark image! Fancy!
452 if ( isset( $logos['wordmark'] ) ) {
453 $wordmarkData = $logos['wordmark'];
454 $wordmark = Html::element( 'img', [
455 'src' => $wordmarkData['src'],
456 'height' => $wordmarkData['height'] ?? null,
457 'width' => $wordmarkData['width'] ?? null,
458 'alt' => $wordmarkText
459 ] );
460 } else {
461 $wordmark = Html::element( 'div', [ 'class' => 'wordmark-text' ], $wordmarkText );
462 }
463
464 $html .= Html::rawElement( 'div', [ 'class' => $bannerClass, 'id' => $id ],
465 Html::rawElement( 'div', [ 'class' => 'sitetitle', 'role' => 'banner' ],
466 $wordmark . $subtitle
467 )
468 );
469
470 $html .= Html::closeElement( 'a' );
471
472 return $html;
473 }
474
475 /**
476 * Get user dropdown portlet
477 *
478 * @return string html
479 */
480 protected function getPersonalNavigation() {
481 $skin = $this->getSkin();
482 $user = $skin->getUser();
483 $personalTools = $skin->getPersonalToolsForMakeListItem( $this->get( 'personal_urls' ) );
484
485 $html = '';
486 $extraTools = [];
487
488 // Remove Echo badges
489 if ( isset( $personalTools['notifications-alert'] ) ) {
490 $extraTools['notifications-alert'] = $personalTools['notifications-alert'];
491 unset( $personalTools['notifications-alert'] );
492 }
493 if ( isset( $personalTools['notifications-notice'] ) ) {
494 $extraTools['notifications-notice'] = $personalTools['notifications-notice'];
495 unset( $personalTools['notifications-notice'] );
496 }
497
498 if ( $user->isRegistered() ) {
499 $headerMsg = [ 'greystuff-loggedinas', $user->getName() ];
500 } else {
501 $headerMsg = 'greystuff-notloggedin';
502 }
503
504 $html .= Html::openElement( 'div', [ 'id' => 'p-personal-container' ] );
505
506 if ( isset( $personalTools['userpage'] ) ) {
507 $personalTools['userpage']['links'][0]['text'] = $this->getMsg( 'greystuff-userpage' )->text();
508 }
509 if ( isset( $personalTools['mytalk'] ) ) {
510 $personalTools['mytalk']['links'][0]['text'] = $this->getMsg( 'greystuff-talkpage' )->text();
511 }
512 if ( isset( $personalTools['anonuserpage'] ) ) {
513 // Pointless; already used as the dropdown header
514 unset( $personalTools['anonuserpage'] );
515 }
516
517 // Re-add Echo badges
518 if ( $extraTools ) {
519 $iconList = '';
520 foreach ( $extraTools as $key => $item ) {
521 $iconList .= $skin->makeListItem( $key, $item );
522 }
523
524 $html .= Html::rawElement(
525 'div',
526 [ 'id' => 'p-personal-extra', 'class' => 'p-body' ],
527 Html::rawElement( 'ul', [], $iconList )
528 );
529 }
530
531 $html .= $this->getPortlet( 'personal', $personalTools, $headerMsg,
532 [ 'body-extra-classes' => [ 'dropdown' ] ]
533 );
534
535 $html .= Html::closeElement( 'div' );
536
537 return $html;
538 }
539
540 /**
541 * Get the search block
542 *
543 * @return string html
544 */
545 protected function getSearch() {
546 $skin = $this->getSkin();
547 $html = '';
548
549 $html .= Html::openElement( 'div', [ 'class' => 'mw-portlet', 'id' => 'p-search', 'role' => 'search' ] );
550
551 $html .= Html::rawElement(
552 'h3',
553 [ 'lang' => $this->get( 'userlang' ), 'dir' => $this->get( 'dir' ) ],
554 Html::rawElement( 'label', [ 'for' => 'searchInput' ], $this->getMsg( 'search' ) )
555 );
556
557 $html .= Html::rawElement( 'form', [ 'action' => $this->get( 'wgScript' ), 'id' => 'searchform' ],
558 Html::rawElement( 'div', [ 'id' => 'simpleSearch' ],
559 Html::rawElement( 'div', [ 'id' => 'searchInput-container-container' ],
560 Html::rawElement( 'div', [ 'id' => 'searchInput-container' ],
561 $skin->makeSearchInput( [ 'id' => 'searchInput', 'type' => 'text' ] )
562 )
563 ) .
564 $skin->makeSearchButton( 'go', [
565 'id' => 'searchGoButton',
566 'class' => 'searchButton',
567 'value' => $this->getMsg( 'searcharticle' )->text()
568 ] ) .
569 Html::hidden( 'title', $this->get( 'searchtitle' ) )
570 )
571 );
572
573 $html .= Html::closeElement( 'div' );
574
575 return $html;
576 }
577
578 /**
579 * @return string html
580 */
581 protected function getSiteNotice() {
582 $html = '';
583
584 if ( $this->data['sitenotice'] ) {
585 $html = Html::rawElement( 'div', [ 'id' => 'siteNotice' ], $this->get( 'sitenotice' ) );
586 }
587
588 return $html;
589 }
590
591 /**
592 * Gets the page subtitle (block immediately below first heading), not to be confused with
593 * the site subtitle (which also may appear here in some skins)
594 *
595 * @return string html
596 */
597 protected function getSubtitle() {
598 $html = '';
599
600 if ( $this->data['subtitle'] || $this->data['undelete'] || $this->data['newtalk'] ) {
601 $html .= Html::openElement( 'div', [ 'id' => 'content-top-stuff' ] );
602 $html .= Html::rawElement( 'div', [
603 'id' => 'contentSub',
604 'lang' => $this->get( 'userlang' ),
605 'dir' => $this->get( 'dir' )
606 ],
607 $this->get( 'subtitle' )
608 );
609 if ( $this->data['undelete'] ) {
610 $html .= Html::rawElement( 'div', [ 'id' => 'contentSub2' ],
611 $this->get( 'undelete' )
612 );
613 }
614 if ( $this->data['newtalk'] ) {
615 $html .= Html::rawElement( 'div', [ 'class' => 'usermessage' ],
616 $this->get( 'newtalk' )
617 );
618 }
619 $html .= Html::closeElement( 'div' );
620 }
621
622 return $html;
623 }
624
625 /**
626 * Get the data after content, catlinks, and potential other stuff that may appear within
627 * the content block but after the main content
628 *
629 * @return string html
630 */
631 protected function getAfterContent() {
632 $html = '';
633
634 if ( $this->data['catlinks'] || $this->data['dataAfterContent'] ) {
635 $html .= Html::openElement( 'div', [ 'id' => 'content-bottom-stuff' ] );
636 if ( $this->data['catlinks'] ) {
637 $html .= $this->get( 'catlinks' ) . $this->getClear();
638 }
639 if ( $this->data['dataAfterContent'] ) {
640 $html .= $this->get( 'dataAfterContent' );
641 }
642 $html .= Html::closeElement( 'div' );
643 }
644
645 return $html;
646 }
647
648 /**
649 * Better renderer for the footer icons and getFooterLinks
650 *
651 * @param array $setOptions Miscellaneous other options
652 * * 'id' for footer id
653 * * 'class' for footer class
654 * * 'order' to determine whether icons or links appear first: 'iconsfirst' or links, though in
655 * practice we currently only check if it is or isn't 'iconsfirst'
656 * * 'link-prefix' to set the prefix for all link and block ids; most skins use 'f' or 'footer',
657 * as in id='f-whatever' vs id='footer-whatever'
658 * * 'link-style' to pass to getFooterLinks: "flat" to disable categorisation of links in a
659 * nested array
660 *
661 * @return string html
662 */
663 protected function getFooterBlock( $setOptions = [] ) {
664 // Set options and fill in defaults
665 $options = $setOptions + [
666 'id' => 'footer',
667 'class' => 'mw-footer',
668 'order' => 'iconsfirst',
669 'link-prefix' => 'footer',
670 'link-style' => null
671 ];
672
673 // phpcs:ignore Generic.Files.LineLength.TooLong
674 '@phan-var array{id:string,class:string,order:string,link-prefix:string,link-style:?string} $options';
675
676 $validFooterIcons = $this->get( 'footericons' );
677 $validFooterLinks = $this->getFooterLinks( $options['link-style'] );
678
679 $html = '';
680
681 $html .= Html::openElement( 'div', [
682 'id' => $options['id'],
683 'class' => $options['class'],
684 'role' => 'contentinfo',
685 'lang' => $this->get( 'userlang' ),
686 'dir' => $this->get( 'dir' )
687 ] );
688
689 $iconsHTML = '';
690 if ( count( $validFooterIcons ) > 0 ) {
691 $skin = $this->getSkin();
692 $iconsHTML .= Html::openElement( 'ul', [ 'id' => "{$options['link-prefix']}-icons" ] );
693 foreach ( $validFooterIcons as $blockName => &$footerIcons ) {
694 $iconsHTML .= Html::openElement( 'li', [
695 'id' => Sanitizer::escapeIdForAttribute(
696 "{$options['link-prefix']}-{$blockName}ico"
697 ),
698 'class' => 'footer-icons'
699 ] );
700 foreach ( $footerIcons as $footerIconKey => $icon ) {
701 if ( !isset( $footerIcon['src'] ) ) {
702 unset( $footerIcons[$footerIconKey] );
703 }
704 $iconsHTML .= $skin->makeFooterIcon( $icon );
705 }
706 $iconsHTML .= Html::closeElement( 'li' );
707 }
708 $iconsHTML .= Html::closeElement( 'ul' );
709 }
710
711 $linksHTML = '';
712 if ( count( $validFooterLinks ) > 0 ) {
713 if ( $options['link-style'] === 'flat' ) {
714 $linksHTML .= Html::openElement( 'ul', [
715 'id' => "{$options['link-prefix']}-list",
716 'class' => 'footer-places'
717 ] );
718 foreach ( $validFooterLinks as $link ) {
719 $linksHTML .= Html::rawElement(
720 'li',
721 [ 'id' => Sanitizer::escapeIdForAttribute( $link ) ],
722 $this->get( $link )
723 );
724 }
725 $linksHTML .= Html::closeElement( 'ul' );
726 } else {
727 $linksHTML .= Html::openElement( 'div', [ 'id' => "{$options['link-prefix']}-list" ] );
728 foreach ( $validFooterLinks as $category => $links ) {
729 $linksHTML .= Html::openElement( 'ul',
730 [ 'id' => Sanitizer::escapeIdForAttribute(
731 "{$options['link-prefix']}-{$category}"
732 ) ]
733 );
734 foreach ( $links as $link ) {
735 $linksHTML .= Html::rawElement(
736 'li',
737 [ 'id' => Sanitizer::escapeIdForAttribute(
738 "{$options['link-prefix']}-{$category}-{$link}"
739 ) ],
740 $this->get( $link )
741 );
742 }
743 $linksHTML .= Html::closeElement( 'ul' );
744 }
745 $linksHTML .= Html::closeElement( 'div' );
746 }
747 }
748
749 if ( $options['order'] === 'iconsfirst' ) {
750 $html .= $iconsHTML . $linksHTML;
751 } else {
752 $html .= $linksHTML . $iconsHTML;
753 }
754
755 $html .= $this->getClear() . Html::closeElement( 'div' );
756
757 return $html;
758 }
759 }