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