Use splat operator in signature, not func_get_args
[lhc/web/wiklou.git] / includes / skins / BaseTemplate.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 use Wikimedia\WrappedString;
22 use Wikimedia\WrappedStringList;
23
24 /**
25 * New base template for a skin's template extended from QuickTemplate
26 * this class features helper methods that provide common ways of interacting
27 * with the data stored in the QuickTemplate
28 */
29 abstract class BaseTemplate extends QuickTemplate {
30
31 /**
32 * Get a Message object with its context set
33 *
34 * @param string $name Message name
35 * @param mixed $params,... Message params
36 * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847
37 * @return Message
38 */
39 public function getMsg( $name /* ... */ ) {
40 return $this->getSkin()->msg( ...func_get_args() );
41 }
42
43 function msg( $str ) {
44 echo $this->getMsg( $str )->escaped();
45 }
46
47 /**
48 * @deprecated since 1.33 Use ->msg() or ->getMsg() instead.
49 */
50 function msgWiki( $str ) {
51 wfDeprecated( __METHOD__, '1.33' ); // Hard-deprecated in 1.34
52 echo $this->getMsg( $str )->parseAsBlock();
53 }
54
55 /**
56 * Create an array of common toolbox items from the data in the quicktemplate
57 * stored by SkinTemplate.
58 * The resulting array is built according to a format intended to be passed
59 * through makeListItem to generate the html.
60 * @return array
61 */
62 function getToolbox() {
63 $toolbox = [];
64 if ( isset( $this->data['nav_urls']['whatlinkshere'] )
65 && $this->data['nav_urls']['whatlinkshere']
66 ) {
67 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
68 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
69 }
70 if ( isset( $this->data['nav_urls']['recentchangeslinked'] )
71 && $this->data['nav_urls']['recentchangeslinked']
72 ) {
73 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
74 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
75 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
76 $toolbox['recentchangeslinked']['rel'] = 'nofollow';
77 }
78 if ( isset( $this->data['feeds'] ) && $this->data['feeds'] ) {
79 $toolbox['feeds']['id'] = 'feedlinks';
80 $toolbox['feeds']['links'] = [];
81 foreach ( $this->data['feeds'] as $key => $feed ) {
82 $toolbox['feeds']['links'][$key] = $feed;
83 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
84 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
85 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
86 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
87 }
88 }
89 foreach ( [ 'contributions', 'log', 'blockip', 'emailuser', 'mute',
90 'userrights', 'upload', 'specialpages' ] as $special
91 ) {
92 if ( isset( $this->data['nav_urls'][$special] ) && $this->data['nav_urls'][$special] ) {
93 $toolbox[$special] = $this->data['nav_urls'][$special];
94 $toolbox[$special]['id'] = "t-$special";
95 }
96 }
97 if ( isset( $this->data['nav_urls']['print'] ) && $this->data['nav_urls']['print'] ) {
98 $toolbox['print'] = $this->data['nav_urls']['print'];
99 $toolbox['print']['id'] = 't-print';
100 $toolbox['print']['rel'] = 'alternate';
101 $toolbox['print']['msg'] = 'printableversion';
102 }
103 if ( isset( $this->data['nav_urls']['permalink'] ) && $this->data['nav_urls']['permalink'] ) {
104 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
105 $toolbox['permalink']['id'] = 't-permalink';
106 }
107 if ( isset( $this->data['nav_urls']['info'] ) && $this->data['nav_urls']['info'] ) {
108 $toolbox['info'] = $this->data['nav_urls']['info'];
109 $toolbox['info']['id'] = 't-info';
110 }
111
112 // Avoid PHP 7.1 warning from passing $this by reference
113 $template = $this;
114 Hooks::run( 'BaseTemplateToolbox', [ &$template, &$toolbox ] );
115 return $toolbox;
116 }
117
118 /**
119 * Create an array of personal tools items from the data in the quicktemplate
120 * stored by SkinTemplate.
121 * The resulting array is built according to a format intended to be passed
122 * through makeListItem to generate the html.
123 * This is in reality the same list as already stored in personal_urls
124 * however it is reformatted so that you can just pass the individual items
125 * to makeListItem instead of hardcoding the element creation boilerplate.
126 * @return array
127 */
128 function getPersonalTools() {
129 $personal_tools = [];
130 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
131 # The class on a personal_urls item is meant to go on the <a> instead
132 # of the <li> so we have to use a single item "links" array instead
133 # of using most of the personal_url's keys directly.
134 $ptool = [
135 'links' => [
136 [ 'single-id' => "pt-$key" ],
137 ],
138 'id' => "pt-$key",
139 ];
140 if ( isset( $plink['active'] ) ) {
141 $ptool['active'] = $plink['active'];
142 }
143 foreach ( [ 'href', 'class', 'text', 'dir', 'data', 'exists' ] as $k ) {
144 if ( isset( $plink[$k] ) ) {
145 $ptool['links'][0][$k] = $plink[$k];
146 }
147 }
148 $personal_tools[$key] = $ptool;
149 }
150 return $personal_tools;
151 }
152
153 function getSidebar( $options = [] ) {
154 // Force the rendering of the following portals
155 $sidebar = $this->data['sidebar'];
156 if ( !isset( $sidebar['SEARCH'] ) ) {
157 $sidebar['SEARCH'] = true;
158 }
159 if ( !isset( $sidebar['TOOLBOX'] ) ) {
160 $sidebar['TOOLBOX'] = true;
161 }
162 if ( !isset( $sidebar['LANGUAGES'] ) ) {
163 $sidebar['LANGUAGES'] = true;
164 }
165
166 if ( !isset( $options['search'] ) || $options['search'] !== true ) {
167 unset( $sidebar['SEARCH'] );
168 }
169 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
170 unset( $sidebar['TOOLBOX'] );
171 }
172 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
173 unset( $sidebar['LANGUAGES'] );
174 }
175
176 $boxes = [];
177 foreach ( $sidebar as $boxName => $content ) {
178 if ( $content === false ) {
179 continue;
180 }
181 switch ( $boxName ) {
182 case 'SEARCH':
183 // Search is a special case, skins should custom implement this
184 $boxes[$boxName] = [
185 'id' => 'p-search',
186 'header' => $this->getMsg( 'search' )->text(),
187 'generated' => false,
188 'content' => true,
189 ];
190 break;
191 case 'TOOLBOX':
192 $msgObj = $this->getMsg( 'toolbox' );
193 $boxes[$boxName] = [
194 'id' => 'p-tb',
195 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox',
196 'generated' => false,
197 'content' => $this->getToolbox(),
198 ];
199 break;
200 case 'LANGUAGES':
201 if ( $this->data['language_urls'] !== false ) {
202 $msgObj = $this->getMsg( 'otherlanguages' );
203 $boxes[$boxName] = [
204 'id' => 'p-lang',
205 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
206 'generated' => false,
207 'content' => $this->data['language_urls'] ?: [],
208 ];
209 }
210 break;
211 default:
212 $msgObj = $this->getMsg( $boxName );
213 $boxes[$boxName] = [
214 'id' => "p-$boxName",
215 'header' => $msgObj->exists() ? $msgObj->text() : $boxName,
216 'generated' => true,
217 'content' => $content,
218 ];
219 break;
220 }
221 }
222
223 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
224 $hookContents = null;
225 if ( isset( $boxes['TOOLBOX'] ) ) {
226 ob_start();
227 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
228 // can abort and avoid outputting double toolbox links
229 // Avoid PHP 7.1 warning from passing $this by reference
230 $template = $this;
231 Hooks::run( 'SkinTemplateToolboxEnd', [ &$template, true ] );
232 $hookContents = ob_get_contents();
233 ob_end_clean();
234 if ( !trim( $hookContents ) ) {
235 $hookContents = null;
236 }
237 }
238 // END hack
239
240 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
241 foreach ( $boxes as $boxName => $box ) {
242 if ( is_array( $box['content'] ) ) {
243 $content = '<ul>';
244 foreach ( $box['content'] as $key => $val ) {
245 $content .= "\n " . $this->makeListItem( $key, $val );
246 }
247 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
248 if ( $hookContents ) {
249 $content .= "\n $hookContents";
250 }
251 // END hack
252 $content .= "\n</ul>\n";
253 $boxes[$boxName]['content'] = $content;
254 }
255 }
256 } elseif ( $hookContents ) {
257 $boxes['TOOLBOXEND'] = [
258 'id' => 'p-toolboxend',
259 'header' => $boxes['TOOLBOX']['header'],
260 'generated' => false,
261 'content' => "<ul>{$hookContents}</ul>",
262 ];
263 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
264 $boxes2 = [];
265 foreach ( $boxes as $key => $box ) {
266 if ( $key === 'TOOLBOXEND' ) {
267 continue;
268 }
269 $boxes2[$key] = $box;
270 if ( $key === 'TOOLBOX' ) {
271 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
272 }
273 }
274 $boxes = $boxes2;
275 // END hack
276 }
277
278 return $boxes;
279 }
280
281 /**
282 * @param string $name
283 */
284 protected function renderAfterPortlet( $name ) {
285 echo $this->getAfterPortlet( $name );
286 }
287
288 /**
289 * Allows extensions to hook into known portlets and add stuff to them
290 *
291 * @param string $name
292 *
293 * @return string html
294 * @since 1.29
295 */
296 protected function getAfterPortlet( $name ) {
297 $html = '';
298 $content = '';
299 Hooks::run( 'BaseTemplateAfterPortlet', [ $this, $name, &$content ] );
300
301 if ( $content !== '' ) {
302 $html = Html::rawElement(
303 'div',
304 [ 'class' => [ 'after-portlet', 'after-portlet-' . $name ] ],
305 $content
306 );
307 }
308
309 return $html;
310 }
311
312 /**
313 * Makes a link, usually used by makeListItem to generate a link for an item
314 * in a list used in navigation lists, portlets, portals, sidebars, etc...
315 *
316 * @param string $key Usually a key from the list you are generating this
317 * link from.
318 * @param array $item Contains some of a specific set of keys.
319 *
320 * The text of the link will be generated either from the contents of the
321 * "text" key in the $item array, if a "msg" key is present a message by
322 * that name will be used, and if neither of those are set the $key will be
323 * used as a message name.
324 *
325 * If a "href" key is not present makeLink will just output htmlescaped text.
326 * The "href", "id", "class", "rel", and "type" keys are used as attributes
327 * for the link if present.
328 *
329 * If an "id" or "single-id" (if you don't want the actual id to be output
330 * on the link) is present it will be used to generate a tooltip and
331 * accesskey for the link.
332 *
333 * The keys "context" and "primary" are ignored; these keys are used
334 * internally by skins and are not supposed to be included in the HTML
335 * output.
336 *
337 * If you don't want an accesskey, set $item['tooltiponly'] = true;
338 *
339 * If a "data" key is present, it must be an array, where the keys represent
340 * the data-xxx properties with their provided values. For example,
341 * $item['data'] = [
342 * 'foo' => 1,
343 * 'bar' => 'baz',
344 * ];
345 * will render as element properties:
346 * data-foo='1' data-bar='baz'
347 *
348 * @param array $options Can be used to affect the output of a link.
349 * Possible options are:
350 * - 'text-wrapper' key to specify a list of elements to wrap the text of
351 * a link in. This should be an array of arrays containing a 'tag' and
352 * optionally an 'attributes' key. If you only have one element you don't
353 * need to wrap it in another array. eg: To use <a><span>...</span></a>
354 * in all links use [ 'text-wrapper' => [ 'tag' => 'span' ] ]
355 * for your options.
356 * - 'link-class' key can be used to specify additional classes to apply
357 * to all links.
358 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
359 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
360 * any non-link will output a "<span>" instead of just text.
361 *
362 * @return string
363 */
364 function makeLink( $key, $item, $options = [] ) {
365 $text = $item['text'] ?? wfMessage( $item['msg'] ?? $key )->text();
366
367 $html = htmlspecialchars( $text );
368
369 if ( isset( $options['text-wrapper'] ) ) {
370 $wrapper = $options['text-wrapper'];
371 if ( isset( $wrapper['tag'] ) ) {
372 $wrapper = [ $wrapper ];
373 }
374 while ( count( $wrapper ) > 0 ) {
375 $element = array_pop( $wrapper );
376 $html = Html::rawElement( $element['tag'], $element['attributes'] ?? null, $html );
377 }
378 }
379
380 if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
381 $attrs = $item;
382 foreach ( [ 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary',
383 'tooltip-params', 'exists' ] as $k ) {
384 unset( $attrs[$k] );
385 }
386
387 if ( isset( $attrs['data'] ) ) {
388 foreach ( $attrs['data'] as $key => $value ) {
389 $attrs[ 'data-' . $key ] = $value;
390 }
391 unset( $attrs[ 'data' ] );
392 }
393
394 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
395 $item['single-id'] = $item['id'];
396 }
397
398 $tooltipParams = [];
399 if ( isset( $item['tooltip-params'] ) ) {
400 $tooltipParams = $item['tooltip-params'];
401 }
402
403 if ( isset( $item['single-id'] ) ) {
404 $tooltipOption = isset( $item['exists'] ) && $item['exists'] === false ? 'nonexisting' : null;
405
406 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
407 $title = Linker::titleAttrib( $item['single-id'], $tooltipOption, $tooltipParams );
408 if ( $title !== false ) {
409 $attrs['title'] = $title;
410 }
411 } else {
412 $tip = Linker::tooltipAndAccesskeyAttribs(
413 $item['single-id'],
414 $tooltipParams,
415 $tooltipOption
416 );
417 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
418 $attrs['title'] = $tip['title'];
419 }
420 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
421 $attrs['accesskey'] = $tip['accesskey'];
422 }
423 }
424 }
425 if ( isset( $options['link-class'] ) ) {
426 if ( isset( $attrs['class'] ) ) {
427 $attrs['class'] .= " {$options['link-class']}";
428 } else {
429 $attrs['class'] = $options['link-class'];
430 }
431 }
432 $html = Html::rawElement( isset( $attrs['href'] )
433 ? 'a'
434 : $options['link-fallback'], $attrs, $html );
435 }
436
437 return $html;
438 }
439
440 /**
441 * Generates a list item for a navigation, portlet, portal, sidebar... list
442 *
443 * @param string $key Usually a key from the list you are generating this link from.
444 * @param array $item Array of list item data containing some of a specific set of keys.
445 * The "id", "class" and "itemtitle" keys will be used as attributes for the list item,
446 * if "active" contains a value of true a "active" class will also be appended to class.
447 * @phan-param array{id?:string,class?:string,itemtitle?:string,active?:bool} $item
448 *
449 * @param array $options
450 * @phan-param array{tag?:string} $options
451 *
452 * If you want something other than a "<li>" you can pass a tag name such as
453 * "tag" => "span" in the $options array to change the tag used.
454 * link/content data for the list item may come in one of two forms
455 * A "links" key may be used, in which case it should contain an array with
456 * a list of links to include inside the list item, see makeLink for the
457 * format of individual links array items.
458 *
459 * Otherwise the relevant keys from the list item $item array will be passed
460 * to makeLink instead. Note however that "id" and "class" are used by the
461 * list item directly so they will not be passed to makeLink
462 * (however the link will still support a tooltip and accesskey from it)
463 * If you need an id or class on a single link you should include a "links"
464 * array with just one link item inside of it. You can also set "link-class" in
465 * $item to set a class on the link itself. If you want to add a title
466 * to the list item itself, you can set "itemtitle" to the value.
467 * $options is also passed on to makeLink calls
468 *
469 * @return string
470 */
471 function makeListItem( $key, $item, $options = [] ) {
472 // In case this is still set from SkinTemplate, we don't want it to appear in
473 // the HTML output (normally removed in SkinTemplate::buildContentActionUrls())
474 unset( $item['redundant'] );
475
476 if ( isset( $item['links'] ) ) {
477 $links = [];
478 foreach ( $item['links'] as $linkKey => $link ) {
479 $links[] = $this->makeLink( $linkKey, $link, $options );
480 }
481 $html = implode( ' ', $links );
482 } else {
483 $link = $item;
484 // These keys are used by makeListItem and shouldn't be passed on to the link
485 foreach ( [ 'id', 'class', 'active', 'tag', 'itemtitle' ] as $k ) {
486 unset( $link[$k] );
487 }
488 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
489 // The id goes on the <li> not on the <a> for single links
490 // but makeSidebarLink still needs to know what id to use when
491 // generating tooltips and accesskeys.
492 $link['single-id'] = $item['id'];
493 }
494 if ( isset( $link['link-class'] ) ) {
495 // link-class should be set on the <a> itself,
496 // so pass it in as 'class'
497 $link['class'] = $link['link-class'];
498 unset( $link['link-class'] );
499 }
500 $html = $this->makeLink( $key, $link, $options );
501 }
502
503 $attrs = [];
504 foreach ( [ 'id', 'class' ] as $attr ) {
505 if ( isset( $item[$attr] ) ) {
506 $attrs[$attr] = $item[$attr];
507 }
508 }
509 if ( isset( $item['active'] ) && $item['active'] ) {
510 if ( !isset( $attrs['class'] ) ) {
511 $attrs['class'] = '';
512 }
513 $attrs['class'] .= ' active';
514 $attrs['class'] = trim( $attrs['class'] );
515 }
516 if ( isset( $item['itemtitle'] ) ) {
517 $attrs['title'] = $item['itemtitle'];
518 }
519 return Html::rawElement( $options['tag'] ?? 'li', $attrs, $html );
520 }
521
522 function makeSearchInput( $attrs = [] ) {
523 $realAttrs = [
524 'type' => 'search',
525 'name' => 'search',
526 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
527 ];
528 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
529 return Html::element( 'input', $realAttrs );
530 }
531
532 function makeSearchButton( $mode, $attrs = [] ) {
533 switch ( $mode ) {
534 case 'go':
535 case 'fulltext':
536 $realAttrs = [
537 'type' => 'submit',
538 'name' => $mode,
539 'value' => wfMessage( $mode == 'go' ? 'searcharticle' : 'searchbutton' )->text(),
540 ];
541 $realAttrs = array_merge(
542 $realAttrs,
543 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
544 $attrs
545 );
546 return Html::element( 'input', $realAttrs );
547 case 'image':
548 $buttonAttrs = [
549 'type' => 'submit',
550 'name' => 'button',
551 ];
552 $buttonAttrs = array_merge(
553 $buttonAttrs,
554 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
555 $attrs
556 );
557 unset( $buttonAttrs['src'] );
558 unset( $buttonAttrs['alt'] );
559 unset( $buttonAttrs['width'] );
560 unset( $buttonAttrs['height'] );
561 $imgAttrs = [
562 'src' => $attrs['src'],
563 'alt' => $attrs['alt'] ?? wfMessage( 'searchbutton' )->text(),
564 'width' => $attrs['width'] ?? null,
565 'height' => $attrs['height'] ?? null,
566 ];
567 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
568 default:
569 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
570 }
571 }
572
573 /**
574 * Returns an array of footerlinks trimmed down to only those footer links that
575 * are valid.
576 * If you pass "flat" as an option then the returned array will be a flat array
577 * of footer icons instead of a key/value array of footerlinks arrays broken
578 * up into categories.
579 * @param string|null $option
580 * @return array|mixed
581 */
582 function getFooterLinks( $option = null ) {
583 $footerlinks = $this->get( 'footerlinks' );
584
585 // Reduce footer links down to only those which are being used
586 $validFooterLinks = [];
587 foreach ( $footerlinks as $category => $links ) {
588 $validFooterLinks[$category] = [];
589 foreach ( $links as $link ) {
590 if ( isset( $this->data[$link] ) && $this->data[$link] ) {
591 $validFooterLinks[$category][] = $link;
592 }
593 }
594 if ( count( $validFooterLinks[$category] ) <= 0 ) {
595 unset( $validFooterLinks[$category] );
596 }
597 }
598
599 if ( $option == 'flat' ) {
600 // fold footerlinks into a single array using a bit of trickery
601 $validFooterLinks = array_merge( ...array_values( $validFooterLinks ) );
602 }
603
604 return $validFooterLinks;
605 }
606
607 /**
608 * Returns an array of footer icons filtered down by options relevant to how
609 * the skin wishes to display them.
610 * If you pass "icononly" as the option all footer icons which do not have an
611 * image icon set will be filtered out.
612 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
613 * in the list of footer icons. This is mostly useful for skins which only
614 * display the text from footericons instead of the images and don't want a
615 * duplicate copyright statement because footerlinks already rendered one.
616 * @param string|null $option
617 * @return array
618 */
619 function getFooterIcons( $option = null ) {
620 // Generate additional footer icons
621 $footericons = $this->get( 'footericons' );
622
623 if ( $option == 'icononly' ) {
624 // Unset any icons which don't have an image
625 foreach ( $footericons as &$footerIconsBlock ) {
626 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
627 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
628 unset( $footerIconsBlock[$footerIconKey] );
629 }
630 }
631 }
632 // Redo removal of any empty blocks
633 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
634 if ( count( $footerIconsBlock ) <= 0 ) {
635 unset( $footericons[$footerIconsKey] );
636 }
637 }
638 } elseif ( $option == 'nocopyright' ) {
639 unset( $footericons['copyright']['copyright'] );
640 if ( count( $footericons['copyright'] ) <= 0 ) {
641 unset( $footericons['copyright'] );
642 }
643 }
644
645 return $footericons;
646 }
647
648 /**
649 * Renderer for getFooterIcons and getFooterLinks
650 *
651 * @param string $iconStyle $option for getFooterIcons: "icononly", "nocopyright"
652 * @param string $linkStyle $option for getFooterLinks: "flat"
653 *
654 * @return string html
655 * @since 1.29
656 */
657 protected function getFooter( $iconStyle = 'icononly', $linkStyle = 'flat' ) {
658 $validFooterIcons = $this->getFooterIcons( $iconStyle );
659 $validFooterLinks = $this->getFooterLinks( $linkStyle );
660
661 $html = '';
662
663 if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) {
664 $html .= Html::openElement( 'div', [
665 'id' => 'footer-bottom',
666 'role' => 'contentinfo',
667 'lang' => $this->get( 'userlang' ),
668 'dir' => $this->get( 'dir' )
669 ] );
670 $footerEnd = Html::closeElement( 'div' );
671 } else {
672 $footerEnd = '';
673 }
674 foreach ( $validFooterIcons as $blockName => $footerIcons ) {
675 $html .= Html::openElement( 'div', [
676 'id' => Sanitizer::escapeIdForAttribute( "f-{$blockName}ico" ),
677 'class' => 'footer-icons'
678 ] );
679 foreach ( $footerIcons as $icon ) {
680 $html .= $this->getSkin()->makeFooterIcon( $icon );
681 }
682 $html .= Html::closeElement( 'div' );
683 }
684 if ( count( $validFooterLinks ) > 0 ) {
685 $html .= Html::openElement( 'ul', [ 'id' => 'f-list', 'class' => 'footer-places' ] );
686 foreach ( $validFooterLinks as $aLink ) {
687 $html .= Html::rawElement(
688 'li',
689 [ 'id' => Sanitizer::escapeIdForAttribute( $aLink ) ],
690 $this->get( $aLink )
691 );
692 }
693 $html .= Html::closeElement( 'ul' );
694 }
695
696 $html .= $this->getClear() . $footerEnd;
697
698 return $html;
699 }
700
701 /**
702 * Get a div with the core visualClear class, for clearing floats
703 *
704 * @return string html
705 * @since 1.29
706 */
707 protected function getClear() {
708 return Html::element( 'div', [ 'class' => 'visualClear' ] );
709 }
710
711 /**
712 * Get the suggested HTML for page status indicators: icons (or short text snippets) usually
713 * displayed in the top-right corner of the page, outside of the main content.
714 *
715 * Your skin may implement this differently, for example by handling some indicator names
716 * specially with a different UI. However, it is recommended to use a `<div class="mw-indicator"
717 * id="mw-indicator-<id>" />` as a wrapper element for each indicator, for better compatibility
718 * with extensions and user scripts.
719 *
720 * The raw data is available in `$this->data['indicators']` as an associative array (keys:
721 * identifiers, values: contents) internally ordered by keys.
722 *
723 * @return string HTML
724 * @since 1.25
725 */
726 public function getIndicators() {
727 $out = "<div class=\"mw-indicators mw-body-content\">\n";
728 foreach ( $this->data['indicators'] as $id => $content ) {
729 $out .= Html::rawElement(
730 'div',
731 [
732 'id' => Sanitizer::escapeIdForAttribute( "mw-indicator-$id" ),
733 'class' => 'mw-indicator',
734 ],
735 $content
736 ) . "\n";
737 }
738 $out .= "</div>\n";
739 return $out;
740 }
741
742 /**
743 * Output getTrail
744 */
745 function printTrail() {
746 echo $this->getTrail();
747 }
748
749 /**
750 * Get the basic end-page trail including bottomscripts, reporttime, and
751 * debug stuff. This should be called right before outputting the closing
752 * body and html tags.
753 *
754 * @return string|WrappedStringList HTML
755 * @since 1.29
756 */
757 public function getTrail() {
758 return WrappedString::join( "\n", [
759 // @phan-suppress-next-line PhanTypeMismatchArgument
760 MWDebug::getDebugHTML( $this->getSkin()->getContext() ),
761 $this->get( 'bottomscripts' ),
762 $this->get( 'reporttime' )
763 ] );
764 }
765 }