Merge "Add force option to password policy"
[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 $this->getSkin()->msg( ...func_get_args() );
40 }
41
42 function msg( $str ) {
43 echo $this->getMsg( $str )->escaped();
44 }
45
46 /**
47 * @param string $str
48 * @warning You should never use this method. I18n messages should be escaped
49 * @deprecated 1.32 Use ->msg() or ->msgWiki() instead.
50 * @suppress SecurityCheck-XSS
51 * @return-taint exec_html
52 */
53 function msgHtml( $str ) {
54 wfDeprecated( __METHOD__, '1.32' );
55 echo $this->getMsg( $str )->text();
56 }
57
58 function msgWiki( $str ) {
59 echo $this->getMsg( $str )->parseAsBlock();
60 }
61
62 /**
63 * Create an array of common toolbox items from the data in the quicktemplate
64 * stored by SkinTemplate.
65 * The resulting array is built according to a format intended to be passed
66 * through makeListItem to generate the html.
67 * @return array
68 */
69 function getToolbox() {
70 $toolbox = [];
71 if ( isset( $this->data['nav_urls']['whatlinkshere'] )
72 && $this->data['nav_urls']['whatlinkshere']
73 ) {
74 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
75 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
76 }
77 if ( isset( $this->data['nav_urls']['recentchangeslinked'] )
78 && $this->data['nav_urls']['recentchangeslinked']
79 ) {
80 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
81 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
82 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
83 $toolbox['recentchangeslinked']['rel'] = 'nofollow';
84 }
85 if ( isset( $this->data['feeds'] ) && $this->data['feeds'] ) {
86 $toolbox['feeds']['id'] = 'feedlinks';
87 $toolbox['feeds']['links'] = [];
88 foreach ( $this->data['feeds'] as $key => $feed ) {
89 $toolbox['feeds']['links'][$key] = $feed;
90 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
91 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
92 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
93 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
94 }
95 }
96 foreach ( [ 'contributions', 'log', 'blockip', 'emailuser',
97 'userrights', 'upload', 'specialpages' ] as $special
98 ) {
99 if ( isset( $this->data['nav_urls'][$special] ) && $this->data['nav_urls'][$special] ) {
100 $toolbox[$special] = $this->data['nav_urls'][$special];
101 $toolbox[$special]['id'] = "t-$special";
102 }
103 }
104 if ( isset( $this->data['nav_urls']['print'] ) && $this->data['nav_urls']['print'] ) {
105 $toolbox['print'] = $this->data['nav_urls']['print'];
106 $toolbox['print']['id'] = 't-print';
107 $toolbox['print']['rel'] = 'alternate';
108 $toolbox['print']['msg'] = 'printableversion';
109 }
110 if ( isset( $this->data['nav_urls']['permalink'] ) && $this->data['nav_urls']['permalink'] ) {
111 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
112 $toolbox['permalink']['id'] = 't-permalink';
113 }
114 if ( isset( $this->data['nav_urls']['info'] ) && $this->data['nav_urls']['info'] ) {
115 $toolbox['info'] = $this->data['nav_urls']['info'];
116 $toolbox['info']['id'] = 't-info';
117 }
118
119 // Avoid PHP 7.1 warning from passing $this by reference
120 $template = $this;
121 Hooks::run( 'BaseTemplateToolbox', [ &$template, &$toolbox ] );
122 return $toolbox;
123 }
124
125 /**
126 * Create an array of personal tools items from the data in the quicktemplate
127 * stored by SkinTemplate.
128 * The resulting array is built according to a format intended to be passed
129 * through makeListItem to generate the html.
130 * This is in reality the same list as already stored in personal_urls
131 * however it is reformatted so that you can just pass the individual items
132 * to makeListItem instead of hardcoding the element creation boilerplate.
133 * @return array
134 */
135 function getPersonalTools() {
136 $personal_tools = [];
137 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
138 # The class on a personal_urls item is meant to go on the <a> instead
139 # of the <li> so we have to use a single item "links" array instead
140 # of using most of the personal_url's keys directly.
141 $ptool = [
142 'links' => [
143 [ 'single-id' => "pt-$key" ],
144 ],
145 'id' => "pt-$key",
146 ];
147 if ( isset( $plink['active'] ) ) {
148 $ptool['active'] = $plink['active'];
149 }
150 foreach ( [ 'href', 'class', 'text', 'dir', 'data', 'exists' ] 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 } else {
264 if ( $hookContents ) {
265 $boxes['TOOLBOXEND'] = [
266 'id' => 'p-toolboxend',
267 'header' => $boxes['TOOLBOX']['header'],
268 'generated' => false,
269 'content' => "<ul>{$hookContents}</ul>",
270 ];
271 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
272 $boxes2 = [];
273 foreach ( $boxes as $key => $box ) {
274 if ( $key === 'TOOLBOXEND' ) {
275 continue;
276 }
277 $boxes2[$key] = $box;
278 if ( $key === 'TOOLBOX' ) {
279 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
280 }
281 }
282 $boxes = $boxes2;
283 // END hack
284 }
285 }
286
287 return $boxes;
288 }
289
290 /**
291 * @param string $name
292 */
293 protected function renderAfterPortlet( $name ) {
294 echo $this->getAfterPortlet( $name );
295 }
296
297 /**
298 * Allows extensions to hook into known portlets and add stuff to them
299 *
300 * @param string $name
301 *
302 * @return string html
303 * @since 1.29
304 */
305 protected function getAfterPortlet( $name ) {
306 $html = '';
307 $content = '';
308 Hooks::run( 'BaseTemplateAfterPortlet', [ $this, $name, &$content ] );
309
310 if ( $content !== '' ) {
311 $html = Html::rawElement(
312 'div',
313 [ 'class' => [ 'after-portlet', 'after-portlet-' . $name ] ],
314 $content
315 );
316 }
317
318 return $html;
319 }
320
321 /**
322 * Makes a link, usually used by makeListItem to generate a link for an item
323 * in a list used in navigation lists, portlets, portals, sidebars, etc...
324 *
325 * @param string $key Usually a key from the list you are generating this
326 * link from.
327 * @param array $item Contains some of a specific set of keys.
328 *
329 * The text of the link will be generated either from the contents of the
330 * "text" key in the $item array, if a "msg" key is present a message by
331 * that name will be used, and if neither of those are set the $key will be
332 * used as a message name.
333 *
334 * If a "href" key is not present makeLink will just output htmlescaped text.
335 * The "href", "id", "class", "rel", and "type" keys are used as attributes
336 * for the link if present.
337 *
338 * If an "id" or "single-id" (if you don't want the actual id to be output
339 * on the link) is present it will be used to generate a tooltip and
340 * accesskey for the link.
341 *
342 * The keys "context" and "primary" are ignored; these keys are used
343 * internally by skins and are not supposed to be included in the HTML
344 * output.
345 *
346 * If you don't want an accesskey, set $item['tooltiponly'] = true;
347 *
348 * If a "data" key is present, it must be an array, where the keys represent
349 * the data-xxx properties with their provided values. For example,
350 * $item['data'] = [
351 * 'foo' => 1,
352 * 'bar' => 'baz',
353 * ];
354 * will render as element properties:
355 * data-foo='1' data-bar='baz'
356 *
357 * @param array $options Can be used to affect the output of a link.
358 * Possible options are:
359 * - 'text-wrapper' key to specify a list of elements to wrap the text of
360 * a link in. This should be an array of arrays containing a 'tag' and
361 * optionally an 'attributes' key. If you only have one element you don't
362 * need to wrap it in another array. eg: To use <a><span>...</span></a>
363 * in all links use [ 'text-wrapper' => [ 'tag' => 'span' ] ]
364 * for your options.
365 * - 'link-class' key can be used to specify additional classes to apply
366 * to all links.
367 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
368 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
369 * any non-link will output a "<span>" instead of just text.
370 *
371 * @return string
372 */
373 function makeLink( $key, $item, $options = [] ) {
374 $text = $item['text'] ?? wfMessage( $item['msg'] ?? $key )->text();
375
376 $html = htmlspecialchars( $text );
377
378 if ( isset( $options['text-wrapper'] ) ) {
379 $wrapper = $options['text-wrapper'];
380 if ( isset( $wrapper['tag'] ) ) {
381 $wrapper = [ $wrapper ];
382 }
383 while ( count( $wrapper ) > 0 ) {
384 $element = array_pop( $wrapper );
385 $html = Html::rawElement( $element['tag'], $element['attributes'] ?? null, $html );
386 }
387 }
388
389 if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
390 $attrs = $item;
391 foreach ( [ 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary',
392 'tooltip-params', 'exists' ] as $k ) {
393 unset( $attrs[$k] );
394 }
395
396 if ( isset( $attrs['data'] ) ) {
397 foreach ( $attrs['data'] as $key => $value ) {
398 $attrs[ 'data-' . $key ] = $value;
399 }
400 unset( $attrs[ 'data' ] );
401 }
402
403 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
404 $item['single-id'] = $item['id'];
405 }
406
407 $tooltipParams = [];
408 if ( isset( $item['tooltip-params'] ) ) {
409 $tooltipParams = $item['tooltip-params'];
410 }
411
412 if ( isset( $item['single-id'] ) ) {
413 $tooltipOption = isset( $item['exists'] ) && $item['exists'] === false ? 'nonexisting' : null;
414
415 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
416 $title = Linker::titleAttrib( $item['single-id'], $tooltipOption, $tooltipParams );
417 if ( $title !== false ) {
418 $attrs['title'] = $title;
419 }
420 } else {
421 $tip = Linker::tooltipAndAccesskeyAttribs(
422 $item['single-id'],
423 $tooltipParams,
424 $tooltipOption
425 );
426 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
427 $attrs['title'] = $tip['title'];
428 }
429 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
430 $attrs['accesskey'] = $tip['accesskey'];
431 }
432 }
433 }
434 if ( isset( $options['link-class'] ) ) {
435 if ( isset( $attrs['class'] ) ) {
436 $attrs['class'] .= " {$options['link-class']}";
437 } else {
438 $attrs['class'] = $options['link-class'];
439 }
440 }
441 $html = Html::rawElement( isset( $attrs['href'] )
442 ? 'a'
443 : $options['link-fallback'], $attrs, $html );
444 }
445
446 return $html;
447 }
448
449 /**
450 * Generates a list item for a navigation, portlet, portal, sidebar... list
451 *
452 * @param string $key Usually a key from the list you are generating this link from.
453 * @param array $item Array of list item data containing some of a specific set of keys.
454 * The "id", "class" and "itemtitle" keys will be used as attributes for the list item,
455 * if "active" contains a value of true a "active" class will also be appended to class.
456 *
457 * @param array $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 if ( isset( $item['links'] ) ) {
480 $links = [];
481 foreach ( $item['links'] as $linkKey => $link ) {
482 $links[] = $this->makeLink( $linkKey, $link, $options );
483 }
484 $html = implode( ' ', $links );
485 } else {
486 $link = $item;
487 // These keys are used by makeListItem and shouldn't be passed on to the link
488 foreach ( [ 'id', 'class', 'active', 'tag', 'itemtitle' ] as $k ) {
489 unset( $link[$k] );
490 }
491 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
492 // The id goes on the <li> not on the <a> for single links
493 // but makeSidebarLink still needs to know what id to use when
494 // generating tooltips and accesskeys.
495 $link['single-id'] = $item['id'];
496 }
497 if ( isset( $link['link-class'] ) ) {
498 // link-class should be set on the <a> itself,
499 // so pass it in as 'class'
500 $link['class'] = $link['link-class'];
501 unset( $link['link-class'] );
502 }
503 $html = $this->makeLink( $key, $link, $options );
504 }
505
506 $attrs = [];
507 foreach ( [ 'id', 'class' ] as $attr ) {
508 if ( isset( $item[$attr] ) ) {
509 $attrs[$attr] = $item[$attr];
510 }
511 }
512 if ( isset( $item['active'] ) && $item['active'] ) {
513 if ( !isset( $attrs['class'] ) ) {
514 $attrs['class'] = '';
515 }
516 $attrs['class'] .= ' active';
517 $attrs['class'] = trim( $attrs['class'] );
518 }
519 if ( isset( $item['itemtitle'] ) ) {
520 $attrs['title'] = $item['itemtitle'];
521 }
522 return Html::rawElement( $options['tag'] ?? 'li', $attrs, $html );
523 }
524
525 function makeSearchInput( $attrs = [] ) {
526 $realAttrs = [
527 'type' => 'search',
528 'name' => 'search',
529 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
530 ];
531 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
532 return Html::element( 'input', $realAttrs );
533 }
534
535 function makeSearchButton( $mode, $attrs = [] ) {
536 switch ( $mode ) {
537 case 'go':
538 case 'fulltext':
539 $realAttrs = [
540 'type' => 'submit',
541 'name' => $mode,
542 'value' => wfMessage( $mode == 'go' ? 'searcharticle' : 'searchbutton' )->text(),
543 ];
544 $realAttrs = array_merge(
545 $realAttrs,
546 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
547 $attrs
548 );
549 return Html::element( 'input', $realAttrs );
550 case 'image':
551 $buttonAttrs = [
552 'type' => 'submit',
553 'name' => 'button',
554 ];
555 $buttonAttrs = array_merge(
556 $buttonAttrs,
557 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
558 $attrs
559 );
560 unset( $buttonAttrs['src'] );
561 unset( $buttonAttrs['alt'] );
562 unset( $buttonAttrs['width'] );
563 unset( $buttonAttrs['height'] );
564 $imgAttrs = [
565 'src' => $attrs['src'],
566 'alt' => $attrs['alt'] ?? wfMessage( 'searchbutton' )->text(),
567 'width' => $attrs['width'] ?? null,
568 '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|null $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 = array_merge( ...array_values( $validFooterLinks ) );
605 }
606
607 return $validFooterLinks;
608 }
609
610 /**
611 * Returns an array of footer icons filtered down by options relevant to how
612 * the skin wishes to display them.
613 * If you pass "icononly" as the option all footer icons which do not have an
614 * image icon set will be filtered out.
615 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
616 * in the list of footer icons. This is mostly useful for skins which only
617 * display the text from footericons instead of the images and don't want a
618 * duplicate copyright statement because footerlinks already rendered one.
619 * @param string|null $option
620 * @return array
621 */
622 function getFooterIcons( $option = null ) {
623 // Generate additional footer icons
624 $footericons = $this->get( 'footericons' );
625
626 if ( $option == 'icononly' ) {
627 // Unset any icons which don't have an image
628 foreach ( $footericons as &$footerIconsBlock ) {
629 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
630 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
631 unset( $footerIconsBlock[$footerIconKey] );
632 }
633 }
634 }
635 // Redo removal of any empty blocks
636 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
637 if ( count( $footerIconsBlock ) <= 0 ) {
638 unset( $footericons[$footerIconsKey] );
639 }
640 }
641 } elseif ( $option == 'nocopyright' ) {
642 unset( $footericons['copyright']['copyright'] );
643 if ( count( $footericons['copyright'] ) <= 0 ) {
644 unset( $footericons['copyright'] );
645 }
646 }
647
648 return $footericons;
649 }
650
651 /**
652 * Renderer for getFooterIcons and getFooterLinks
653 *
654 * @param string $iconStyle $option for getFooterIcons: "icononly", "nocopyright"
655 * @param string $linkStyle $option for getFooterLinks: "flat"
656 *
657 * @return string html
658 * @since 1.29
659 */
660 protected function getFooter( $iconStyle = 'icononly', $linkStyle = 'flat' ) {
661 $validFooterIcons = $this->getFooterIcons( $iconStyle );
662 $validFooterLinks = $this->getFooterLinks( $linkStyle );
663
664 $html = '';
665
666 if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) {
667 $html .= Html::openElement( 'div', [
668 'id' => 'footer-bottom',
669 'role' => 'contentinfo',
670 'lang' => $this->get( 'userlang' ),
671 'dir' => $this->get( 'dir' )
672 ] );
673 $footerEnd = Html::closeElement( 'div' );
674 } else {
675 $footerEnd = '';
676 }
677 foreach ( $validFooterIcons as $blockName => $footerIcons ) {
678 $html .= Html::openElement( 'div', [
679 'id' => Sanitizer::escapeIdForAttribute( "f-{$blockName}ico" ),
680 'class' => 'footer-icons'
681 ] );
682 foreach ( $footerIcons as $icon ) {
683 $html .= $this->getSkin()->makeFooterIcon( $icon );
684 }
685 $html .= Html::closeElement( 'div' );
686 }
687 if ( count( $validFooterLinks ) > 0 ) {
688 $html .= Html::openElement( 'ul', [ 'id' => 'f-list', 'class' => 'footer-places' ] );
689 foreach ( $validFooterLinks as $aLink ) {
690 $html .= Html::rawElement(
691 'li',
692 [ 'id' => Sanitizer::escapeIdForAttribute( $aLink ) ],
693 $this->get( $aLink )
694 );
695 }
696 $html .= Html::closeElement( 'ul' );
697 }
698
699 $html .= $this->getClear() . $footerEnd;
700
701 return $html;
702 }
703
704 /**
705 * Get a div with the core visualClear class, for clearing floats
706 *
707 * @return string html
708 * @since 1.29
709 */
710 protected function getClear() {
711 return Html::element( 'div', [ 'class' => 'visualClear' ] );
712 }
713
714 /**
715 * Get the suggested HTML for page status indicators: icons (or short text snippets) usually
716 * displayed in the top-right corner of the page, outside of the main content.
717 *
718 * Your skin may implement this differently, for example by handling some indicator names
719 * specially with a different UI. However, it is recommended to use a `<div class="mw-indicator"
720 * id="mw-indicator-<id>" />` as a wrapper element for each indicator, for better compatibility
721 * with extensions and user scripts.
722 *
723 * The raw data is available in `$this->data['indicators']` as an associative array (keys:
724 * identifiers, values: contents) internally ordered by keys.
725 *
726 * @return string HTML
727 * @since 1.25
728 */
729 public function getIndicators() {
730 $out = "<div class=\"mw-indicators mw-body-content\">\n";
731 foreach ( $this->data['indicators'] as $id => $content ) {
732 $out .= Html::rawElement(
733 'div',
734 [
735 'id' => Sanitizer::escapeIdForAttribute( "mw-indicator-$id" ),
736 'class' => 'mw-indicator',
737 ],
738 $content
739 ) . "\n";
740 }
741 $out .= "</div>\n";
742 return $out;
743 }
744
745 /**
746 * Output getTrail
747 */
748 function printTrail() {
749 echo $this->getTrail();
750 }
751
752 /**
753 * Get the basic end-page trail including bottomscripts, reporttime, and
754 * debug stuff. This should be called right before outputting the closing
755 * body and html tags.
756 *
757 * @return string|WrappedStringList HTML
758 * @since 1.29
759 */
760 public function getTrail() {
761 return WrappedString::join( "\n", [
762 MWDebug::getDebugHTML( $this->getSkin()->getContext() ),
763 $this->get( 'bottomscripts' ),
764 $this->get( 'reporttime' )
765 ] );
766 }
767 }