Fix 'Tags' padding to keep it farther from the edge and document the source of the...
[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 /* ... */ ) {
39 return call_user_func_array( [ $this->getSkin(), 'msg' ], func_get_args() );
40 }
41
42 function msg( $str ) {
43 echo $this->getMsg( $str )->escaped();
44 }
45
46 function msgHtml( $str ) {
47 echo $this->getMsg( $str )->text();
48 }
49
50 function msgWiki( $str ) {
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',
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 ( [ 'href', 'class', 'text', 'dir', 'data', 'exists' ] as $k ) {
143 if ( isset( $plink[$k] ) ) {
144 $ptool['links'][0][$k] = $plink[$k];
145 }
146 }
147 $personal_tools[$key] = $ptool;
148 }
149 return $personal_tools;
150 }
151
152 function getSidebar( $options = [] ) {
153 // Force the rendering of the following portals
154 $sidebar = $this->data['sidebar'];
155 if ( !isset( $sidebar['SEARCH'] ) ) {
156 $sidebar['SEARCH'] = true;
157 }
158 if ( !isset( $sidebar['TOOLBOX'] ) ) {
159 $sidebar['TOOLBOX'] = true;
160 }
161 if ( !isset( $sidebar['LANGUAGES'] ) ) {
162 $sidebar['LANGUAGES'] = true;
163 }
164
165 if ( !isset( $options['search'] ) || $options['search'] !== true ) {
166 unset( $sidebar['SEARCH'] );
167 }
168 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
169 unset( $sidebar['TOOLBOX'] );
170 }
171 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
172 unset( $sidebar['LANGUAGES'] );
173 }
174
175 $boxes = [];
176 foreach ( $sidebar as $boxName => $content ) {
177 if ( $content === false ) {
178 continue;
179 }
180 switch ( $boxName ) {
181 case 'SEARCH':
182 // Search is a special case, skins should custom implement this
183 $boxes[$boxName] = [
184 'id' => 'p-search',
185 'header' => $this->getMsg( 'search' )->text(),
186 'generated' => false,
187 'content' => true,
188 ];
189 break;
190 case 'TOOLBOX':
191 $msgObj = $this->getMsg( 'toolbox' );
192 $boxes[$boxName] = [
193 'id' => 'p-tb',
194 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox',
195 'generated' => false,
196 'content' => $this->getToolbox(),
197 ];
198 break;
199 case 'LANGUAGES':
200 if ( $this->data['language_urls'] !== false ) {
201 $msgObj = $this->getMsg( 'otherlanguages' );
202 $boxes[$boxName] = [
203 'id' => 'p-lang',
204 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
205 'generated' => false,
206 'content' => $this->data['language_urls'] ?: [],
207 ];
208 }
209 break;
210 default:
211 $msgObj = $this->getMsg( $boxName );
212 $boxes[$boxName] = [
213 'id' => "p-$boxName",
214 'header' => $msgObj->exists() ? $msgObj->text() : $boxName,
215 'generated' => true,
216 'content' => $content,
217 ];
218 break;
219 }
220 }
221
222 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
223 $hookContents = null;
224 if ( isset( $boxes['TOOLBOX'] ) ) {
225 ob_start();
226 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
227 // can abort and avoid outputting double toolbox links
228 // Avoid PHP 7.1 warning from passing $this by reference
229 $template = $this;
230 Hooks::run( 'SkinTemplateToolboxEnd', [ &$template, true ] );
231 $hookContents = ob_get_contents();
232 ob_end_clean();
233 if ( !trim( $hookContents ) ) {
234 $hookContents = null;
235 }
236 }
237 // END hack
238
239 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
240 foreach ( $boxes as $boxName => $box ) {
241 if ( is_array( $box['content'] ) ) {
242 $content = '<ul>';
243 foreach ( $box['content'] as $key => $val ) {
244 $content .= "\n " . $this->makeListItem( $key, $val );
245 }
246 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
247 if ( $hookContents ) {
248 $content .= "\n $hookContents";
249 }
250 // END hack
251 $content .= "\n</ul>\n";
252 $boxes[$boxName]['content'] = $content;
253 }
254 }
255 } else {
256 if ( $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
279 return $boxes;
280 }
281
282 /**
283 * @param string $name
284 */
285 protected function renderAfterPortlet( $name ) {
286 echo $this->getAfterPortlet( $name );
287 }
288
289 /**
290 * Allows extensions to hook into known portlets and add stuff to them
291 *
292 * @param string $name
293 *
294 * @return string html
295 * @since 1.29
296 */
297 protected function getAfterPortlet( $name ) {
298 $html = '';
299 $content = '';
300 Hooks::run( 'BaseTemplateAfterPortlet', [ $this, $name, &$content ] );
301
302 if ( $content !== '' ) {
303 $html = Html::rawElement(
304 'div',
305 [ 'class' => [ 'after-portlet', 'after-portlet-' . $name ] ],
306 $content
307 );
308 }
309
310 return $html;
311 }
312
313 /**
314 * Makes a link, usually used by makeListItem to generate a link for an item
315 * in a list used in navigation lists, portlets, portals, sidebars, etc...
316 *
317 * @param string $key Usually a key from the list you are generating this
318 * link from.
319 * @param array $item Contains some of a specific set of keys.
320 *
321 * The text of the link will be generated either from the contents of the
322 * "text" key in the $item array, if a "msg" key is present a message by
323 * that name will be used, and if neither of those are set the $key will be
324 * used as a message name.
325 *
326 * If a "href" key is not present makeLink will just output htmlescaped text.
327 * The "href", "id", "class", "rel", and "type" keys are used as attributes
328 * for the link if present.
329 *
330 * If an "id" or "single-id" (if you don't want the actual id to be output
331 * on the link) is present it will be used to generate a tooltip and
332 * accesskey for the link.
333 *
334 * The keys "context" and "primary" are ignored; these keys are used
335 * internally by skins and are not supposed to be included in the HTML
336 * output.
337 *
338 * If you don't want an accesskey, set $item['tooltiponly'] = true;
339 *
340 * If a "data" key is present, it must be an array, where the keys represent
341 * the data-xxx properties with their provided values. For example,
342 * $item['data'] = [
343 * 'foo' => 1,
344 * 'bar' => 'baz',
345 * ];
346 * will render as element properties:
347 * data-foo='1' data-bar='baz'
348 *
349 * @param array $options Can be used to affect the output of a link.
350 * Possible options are:
351 * - 'text-wrapper' key to specify a list of elements to wrap the text of
352 * a link in. This should be an array of arrays containing a 'tag' and
353 * optionally an 'attributes' key. If you only have one element you don't
354 * need to wrap it in another array. eg: To use <a><span>...</span></a>
355 * in all links use [ 'text-wrapper' => [ 'tag' => 'span' ] ]
356 * for your options.
357 * - 'link-class' key can be used to specify additional classes to apply
358 * to all links.
359 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
360 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
361 * any non-link will output a "<span>" instead of just text.
362 *
363 * @return string
364 */
365 function makeLink( $key, $item, $options = [] ) {
366 if ( isset( $item['text'] ) ) {
367 $text = $item['text'];
368 } else {
369 $text = wfMessage( isset( $item['msg'] ) ? $item['msg'] : $key )->text();
370 }
371
372 $html = htmlspecialchars( $text );
373
374 if ( isset( $options['text-wrapper'] ) ) {
375 $wrapper = $options['text-wrapper'];
376 if ( isset( $wrapper['tag'] ) ) {
377 $wrapper = [ $wrapper ];
378 }
379 while ( count( $wrapper ) > 0 ) {
380 $element = array_pop( $wrapper );
381 $html = Html::rawElement( $element['tag'], isset( $element['attributes'] )
382 ? $element['attributes']
383 : 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 *
455 * @param array $options
456 *
457 * If you want something other than a "<li>" you can pass a tag name such as
458 * "tag" => "span" in the $options array to change the tag used.
459 * link/content data for the list item may come in one of two forms
460 * A "links" key may be used, in which case it should contain an array with
461 * a list of links to include inside the list item, see makeLink for the
462 * format of individual links array items.
463 *
464 * Otherwise the relevant keys from the list item $item array will be passed
465 * to makeLink instead. Note however that "id" and "class" are used by the
466 * list item directly so they will not be passed to makeLink
467 * (however the link will still support a tooltip and accesskey from it)
468 * If you need an id or class on a single link you should include a "links"
469 * array with just one link item inside of it. You can also set "link-class" in
470 * $item to set a class on the link itself. If you want to add a title
471 * to the list item itself, you can set "itemtitle" to the value.
472 * $options is also passed on to makeLink calls
473 *
474 * @return string
475 */
476 function makeListItem( $key, $item, $options = [] ) {
477 if ( isset( $item['links'] ) ) {
478 $links = [];
479 foreach ( $item['links'] as $linkKey => $link ) {
480 $links[] = $this->makeLink( $linkKey, $link, $options );
481 }
482 $html = implode( ' ', $links );
483 } else {
484 $link = $item;
485 // These keys are used by makeListItem and shouldn't be passed on to the link
486 foreach ( [ 'id', 'class', 'active', 'tag', 'itemtitle' ] as $k ) {
487 unset( $link[$k] );
488 }
489 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
490 // The id goes on the <li> not on the <a> for single links
491 // but makeSidebarLink still needs to know what id to use when
492 // generating tooltips and accesskeys.
493 $link['single-id'] = $item['id'];
494 }
495 if ( isset( $link['link-class'] ) ) {
496 // link-class should be set on the <a> itself,
497 // so pass it in as 'class'
498 $link['class'] = $link['link-class'];
499 unset( $link['link-class'] );
500 }
501 $html = $this->makeLink( $key, $link, $options );
502 }
503
504 $attrs = [];
505 foreach ( [ 'id', 'class' ] as $attr ) {
506 if ( isset( $item[$attr] ) ) {
507 $attrs[$attr] = $item[$attr];
508 }
509 }
510 if ( isset( $item['active'] ) && $item['active'] ) {
511 if ( !isset( $attrs['class'] ) ) {
512 $attrs['class'] = '';
513 }
514 $attrs['class'] .= ' active';
515 $attrs['class'] = trim( $attrs['class'] );
516 }
517 if ( isset( $item['itemtitle'] ) ) {
518 $attrs['title'] = $item['itemtitle'];
519 }
520 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
521 }
522
523 function makeSearchInput( $attrs = [] ) {
524 $realAttrs = [
525 'type' => 'search',
526 'name' => 'search',
527 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
528 ];
529 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
530 return Html::element( 'input', $realAttrs );
531 }
532
533 function makeSearchButton( $mode, $attrs = [] ) {
534 switch ( $mode ) {
535 case 'go':
536 case 'fulltext':
537 $realAttrs = [
538 'type' => 'submit',
539 'name' => $mode,
540 'value' => wfMessage( $mode == 'go' ? 'searcharticle' : 'searchbutton' )->text(),
541 ];
542 $realAttrs = array_merge(
543 $realAttrs,
544 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
545 $attrs
546 );
547 return Html::element( 'input', $realAttrs );
548 case 'image':
549 $buttonAttrs = [
550 'type' => 'submit',
551 'name' => 'button',
552 ];
553 $buttonAttrs = array_merge(
554 $buttonAttrs,
555 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
556 $attrs
557 );
558 unset( $buttonAttrs['src'] );
559 unset( $buttonAttrs['alt'] );
560 unset( $buttonAttrs['width'] );
561 unset( $buttonAttrs['height'] );
562 $imgAttrs = [
563 'src' => $attrs['src'],
564 'alt' => isset( $attrs['alt'] )
565 ? $attrs['alt']
566 : wfMessage( 'searchbutton' )->text(),
567 'width' => isset( $attrs['width'] ) ? $attrs['width'] : null,
568 'height' => isset( $attrs['height'] ) ? $attrs['height'] : null,
569 ];
570 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
571 default:
572 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
573 }
574 }
575
576 /**
577 * Returns an array of footerlinks trimmed down to only those footer links that
578 * are valid.
579 * If you pass "flat" as an option then the returned array will be a flat array
580 * of footer icons instead of a key/value array of footerlinks arrays broken
581 * up into categories.
582 * @param string $option
583 * @return array|mixed
584 */
585 function getFooterLinks( $option = null ) {
586 $footerlinks = $this->get( 'footerlinks' );
587
588 // Reduce footer links down to only those which are being used
589 $validFooterLinks = [];
590 foreach ( $footerlinks as $category => $links ) {
591 $validFooterLinks[$category] = [];
592 foreach ( $links as $link ) {
593 if ( isset( $this->data[$link] ) && $this->data[$link] ) {
594 $validFooterLinks[$category][] = $link;
595 }
596 }
597 if ( count( $validFooterLinks[$category] ) <= 0 ) {
598 unset( $validFooterLinks[$category] );
599 }
600 }
601
602 if ( $option == 'flat' ) {
603 // fold footerlinks into a single array using a bit of trickery
604 $validFooterLinks = call_user_func_array(
605 'array_merge',
606 array_values( $validFooterLinks )
607 );
608 }
609
610 return $validFooterLinks;
611 }
612
613 /**
614 * Returns an array of footer icons filtered down by options relevant to how
615 * the skin wishes to display them.
616 * If you pass "icononly" as the option all footer icons which do not have an
617 * image icon set will be filtered out.
618 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
619 * in the list of footer icons. This is mostly useful for skins which only
620 * display the text from footericons instead of the images and don't want a
621 * duplicate copyright statement because footerlinks already rendered one.
622 * @param string $option
623 * @return array
624 */
625 function getFooterIcons( $option = null ) {
626 // Generate additional footer icons
627 $footericons = $this->get( 'footericons' );
628
629 if ( $option == 'icononly' ) {
630 // Unset any icons which don't have an image
631 foreach ( $footericons as &$footerIconsBlock ) {
632 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
633 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
634 unset( $footerIconsBlock[$footerIconKey] );
635 }
636 }
637 }
638 // Redo removal of any empty blocks
639 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
640 if ( count( $footerIconsBlock ) <= 0 ) {
641 unset( $footericons[$footerIconsKey] );
642 }
643 }
644 } elseif ( $option == 'nocopyright' ) {
645 unset( $footericons['copyright']['copyright'] );
646 if ( count( $footericons['copyright'] ) <= 0 ) {
647 unset( $footericons['copyright'] );
648 }
649 }
650
651 return $footericons;
652 }
653
654 /**
655 * Renderer for getFooterIcons and getFooterLinks
656 *
657 * @param string $iconStyle $option for getFooterIcons: "icononly", "nocopyright"
658 * @param string $linkStyle $option for getFooterLinks: "flat"
659 *
660 * @return string html
661 * @since 1.29
662 */
663 protected function getFooter( $iconStyle = 'icononly', $linkStyle = 'flat' ) {
664 $validFooterIcons = $this->getFooterIcons( $iconStyle );
665 $validFooterLinks = $this->getFooterLinks( $linkStyle );
666
667 $html = '';
668
669 if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) {
670 $html .= Html::openElement( 'div', [
671 'id' => 'footer-bottom',
672 'role' => 'contentinfo',
673 'lang' => $this->get( 'userlang' ),
674 'dir' => $this->get( 'dir' )
675 ] );
676 $footerEnd = Html::closeElement( 'div' );
677 } else {
678 $footerEnd = '';
679 }
680 foreach ( $validFooterIcons as $blockName => $footerIcons ) {
681 $html .= Html::openElement( 'div', [
682 'id' => Sanitizer::escapeIdForAttribute( "f-{$blockName}ico" ),
683 'class' => 'footer-icons'
684 ] );
685 foreach ( $footerIcons as $icon ) {
686 $html .= $this->getSkin()->makeFooterIcon( $icon );
687 }
688 $html .= Html::closeElement( 'div' );
689 }
690 if ( count( $validFooterLinks ) > 0 ) {
691 $html .= Html::openElement( 'ul', [ 'id' => 'f-list', 'class' => 'footer-places' ] );
692 foreach ( $validFooterLinks as $aLink ) {
693 $html .= Html::rawElement(
694 'li',
695 [ 'id' => Sanitizer::escapeIdForAttribute( $aLink ) ],
696 $this->get( $aLink )
697 );
698 }
699 $html .= Html::closeElement( 'ul' );
700 }
701
702 $html .= $this->getClear() . $footerEnd;
703
704 return $html;
705 }
706
707 /**
708 * Get a div with the core visualClear class, for clearing floats
709 *
710 * @return string html
711 * @since 1.29
712 */
713 protected function getClear() {
714 return Html::element( 'div', [ 'class' => 'visualClear' ] );
715 }
716
717 /**
718 * Get the suggested HTML for page status indicators: icons (or short text snippets) usually
719 * displayed in the top-right corner of the page, outside of the main content.
720 *
721 * Your skin may implement this differently, for example by handling some indicator names
722 * specially with a different UI. However, it is recommended to use a `<div class="mw-indicator"
723 * id="mw-indicator-<id>" />` as a wrapper element for each indicator, for better compatibility
724 * with extensions and user scripts.
725 *
726 * The raw data is available in `$this->data['indicators']` as an associative array (keys:
727 * identifiers, values: contents) internally ordered by keys.
728 *
729 * @return string HTML
730 * @since 1.25
731 */
732 public function getIndicators() {
733 $out = "<div class=\"mw-indicators mw-body-content\">\n";
734 foreach ( $this->data['indicators'] as $id => $content ) {
735 $out .= Html::rawElement(
736 'div',
737 [
738 'id' => Sanitizer::escapeIdForAttribute( "mw-indicator-$id" ),
739 'class' => 'mw-indicator',
740 ],
741 $content
742 ) . "\n";
743 }
744 $out .= "</div>\n";
745 return $out;
746 }
747
748 /**
749 * Output getTrail
750 */
751 function printTrail() {
752 echo $this->getTrail();
753 }
754
755 /**
756 * Get the basic end-page trail including bottomscripts, reporttime, and
757 * debug stuff. This should be called right before outputting the closing
758 * body and html tags.
759 *
760 * @return string|WrappedStringList HTML
761 * @since 1.29
762 */
763 public function getTrail() {
764 return WrappedString::join( "\n", [
765 MWDebug::getDebugHTML( $this->getSkin()->getContext() ),
766 $this->get( 'bottomscripts' ),
767 $this->get( 'reporttime' )
768 ] );
769 }
770 }