Merge "Actually assign suppression-related rights to 'suppress' group"
[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 * @deprecated since 1.33 Use ->msg() or ->getMsg() instead.
48 */
49 function msgWiki( $str ) {
50 // TODO: Add wfDeprecated( __METHOD__, '1.33' ) after 1.33 got released
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 ( [ '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 } elseif ( $hookContents ) {
256 $boxes['TOOLBOXEND'] = [
257 'id' => 'p-toolboxend',
258 'header' => $boxes['TOOLBOX']['header'],
259 'generated' => false,
260 'content' => "<ul>{$hookContents}</ul>",
261 ];
262 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
263 $boxes2 = [];
264 foreach ( $boxes as $key => $box ) {
265 if ( $key === 'TOOLBOXEND' ) {
266 continue;
267 }
268 $boxes2[$key] = $box;
269 if ( $key === 'TOOLBOX' ) {
270 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
271 }
272 }
273 $boxes = $boxes2;
274 // END hack
275 }
276
277 return $boxes;
278 }
279
280 /**
281 * @param string $name
282 */
283 protected function renderAfterPortlet( $name ) {
284 echo $this->getAfterPortlet( $name );
285 }
286
287 /**
288 * Allows extensions to hook into known portlets and add stuff to them
289 *
290 * @param string $name
291 *
292 * @return string html
293 * @since 1.29
294 */
295 protected function getAfterPortlet( $name ) {
296 $html = '';
297 $content = '';
298 Hooks::run( 'BaseTemplateAfterPortlet', [ $this, $name, &$content ] );
299
300 if ( $content !== '' ) {
301 $html = Html::rawElement(
302 'div',
303 [ 'class' => [ 'after-portlet', 'after-portlet-' . $name ] ],
304 $content
305 );
306 }
307
308 return $html;
309 }
310
311 /**
312 * Makes a link, usually used by makeListItem to generate a link for an item
313 * in a list used in navigation lists, portlets, portals, sidebars, etc...
314 *
315 * @param string $key Usually a key from the list you are generating this
316 * link from.
317 * @param array $item Contains some of a specific set of keys.
318 *
319 * The text of the link will be generated either from the contents of the
320 * "text" key in the $item array, if a "msg" key is present a message by
321 * that name will be used, and if neither of those are set the $key will be
322 * used as a message name.
323 *
324 * If a "href" key is not present makeLink will just output htmlescaped text.
325 * The "href", "id", "class", "rel", and "type" keys are used as attributes
326 * for the link if present.
327 *
328 * If an "id" or "single-id" (if you don't want the actual id to be output
329 * on the link) is present it will be used to generate a tooltip and
330 * accesskey for the link.
331 *
332 * The keys "context" and "primary" are ignored; these keys are used
333 * internally by skins and are not supposed to be included in the HTML
334 * output.
335 *
336 * If you don't want an accesskey, set $item['tooltiponly'] = true;
337 *
338 * If a "data" key is present, it must be an array, where the keys represent
339 * the data-xxx properties with their provided values. For example,
340 * $item['data'] = [
341 * 'foo' => 1,
342 * 'bar' => 'baz',
343 * ];
344 * will render as element properties:
345 * data-foo='1' data-bar='baz'
346 *
347 * @param array $options Can be used to affect the output of a link.
348 * Possible options are:
349 * - 'text-wrapper' key to specify a list of elements to wrap the text of
350 * a link in. This should be an array of arrays containing a 'tag' and
351 * optionally an 'attributes' key. If you only have one element you don't
352 * need to wrap it in another array. eg: To use <a><span>...</span></a>
353 * in all links use [ 'text-wrapper' => [ 'tag' => 'span' ] ]
354 * for your options.
355 * - 'link-class' key can be used to specify additional classes to apply
356 * to all links.
357 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
358 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
359 * any non-link will output a "<span>" instead of just text.
360 *
361 * @return string
362 */
363 function makeLink( $key, $item, $options = [] ) {
364 $text = $item['text'] ?? wfMessage( $item['msg'] ?? $key )->text();
365
366 $html = htmlspecialchars( $text );
367
368 if ( isset( $options['text-wrapper'] ) ) {
369 $wrapper = $options['text-wrapper'];
370 if ( isset( $wrapper['tag'] ) ) {
371 $wrapper = [ $wrapper ];
372 }
373 while ( count( $wrapper ) > 0 ) {
374 $element = array_pop( $wrapper );
375 $html = Html::rawElement( $element['tag'], $element['attributes'] ?? null, $html );
376 }
377 }
378
379 if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
380 $attrs = $item;
381 foreach ( [ 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary',
382 'tooltip-params', 'exists' ] as $k ) {
383 unset( $attrs[$k] );
384 }
385
386 if ( isset( $attrs['data'] ) ) {
387 foreach ( $attrs['data'] as $key => $value ) {
388 $attrs[ 'data-' . $key ] = $value;
389 }
390 unset( $attrs[ 'data' ] );
391 }
392
393 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
394 $item['single-id'] = $item['id'];
395 }
396
397 $tooltipParams = [];
398 if ( isset( $item['tooltip-params'] ) ) {
399 $tooltipParams = $item['tooltip-params'];
400 }
401
402 if ( isset( $item['single-id'] ) ) {
403 $tooltipOption = isset( $item['exists'] ) && $item['exists'] === false ? 'nonexisting' : null;
404
405 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
406 $title = Linker::titleAttrib( $item['single-id'], $tooltipOption, $tooltipParams );
407 if ( $title !== false ) {
408 $attrs['title'] = $title;
409 }
410 } else {
411 $tip = Linker::tooltipAndAccesskeyAttribs(
412 $item['single-id'],
413 $tooltipParams,
414 $tooltipOption
415 );
416 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
417 $attrs['title'] = $tip['title'];
418 }
419 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
420 $attrs['accesskey'] = $tip['accesskey'];
421 }
422 }
423 }
424 if ( isset( $options['link-class'] ) ) {
425 if ( isset( $attrs['class'] ) ) {
426 $attrs['class'] .= " {$options['link-class']}";
427 } else {
428 $attrs['class'] = $options['link-class'];
429 }
430 }
431 $html = Html::rawElement( isset( $attrs['href'] )
432 ? 'a'
433 : $options['link-fallback'], $attrs, $html );
434 }
435
436 return $html;
437 }
438
439 /**
440 * Generates a list item for a navigation, portlet, portal, sidebar... list
441 *
442 * @param string $key Usually a key from the list you are generating this link from.
443 * @param array $item Array of list item data containing some of a specific set of keys.
444 * The "id", "class" and "itemtitle" keys will be used as attributes for the list item,
445 * if "active" contains a value of true a "active" class will also be appended to class.
446 *
447 * @param array $options
448 *
449 * If you want something other than a "<li>" you can pass a tag name such as
450 * "tag" => "span" in the $options array to change the tag used.
451 * link/content data for the list item may come in one of two forms
452 * A "links" key may be used, in which case it should contain an array with
453 * a list of links to include inside the list item, see makeLink for the
454 * format of individual links array items.
455 *
456 * Otherwise the relevant keys from the list item $item array will be passed
457 * to makeLink instead. Note however that "id" and "class" are used by the
458 * list item directly so they will not be passed to makeLink
459 * (however the link will still support a tooltip and accesskey from it)
460 * If you need an id or class on a single link you should include a "links"
461 * array with just one link item inside of it. You can also set "link-class" in
462 * $item to set a class on the link itself. If you want to add a title
463 * to the list item itself, you can set "itemtitle" to the value.
464 * $options is also passed on to makeLink calls
465 *
466 * @return string
467 */
468 function makeListItem( $key, $item, $options = [] ) {
469 // In case this is still set from SkinTemplate, we don't want it to appear in
470 // the HTML output (normally removed in SkinTemplate::buildContentActionUrls())
471 unset( $item['redundant'] );
472
473 if ( isset( $item['links'] ) ) {
474 $links = [];
475 foreach ( $item['links'] as $linkKey => $link ) {
476 $links[] = $this->makeLink( $linkKey, $link, $options );
477 }
478 $html = implode( ' ', $links );
479 } else {
480 $link = $item;
481 // These keys are used by makeListItem and shouldn't be passed on to the link
482 foreach ( [ 'id', 'class', 'active', 'tag', 'itemtitle' ] as $k ) {
483 unset( $link[$k] );
484 }
485 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
486 // The id goes on the <li> not on the <a> for single links
487 // but makeSidebarLink still needs to know what id to use when
488 // generating tooltips and accesskeys.
489 $link['single-id'] = $item['id'];
490 }
491 if ( isset( $link['link-class'] ) ) {
492 // link-class should be set on the <a> itself,
493 // so pass it in as 'class'
494 $link['class'] = $link['link-class'];
495 unset( $link['link-class'] );
496 }
497 $html = $this->makeLink( $key, $link, $options );
498 }
499
500 $attrs = [];
501 foreach ( [ 'id', 'class' ] as $attr ) {
502 if ( isset( $item[$attr] ) ) {
503 $attrs[$attr] = $item[$attr];
504 }
505 }
506 if ( isset( $item['active'] ) && $item['active'] ) {
507 if ( !isset( $attrs['class'] ) ) {
508 $attrs['class'] = '';
509 }
510 $attrs['class'] .= ' active';
511 $attrs['class'] = trim( $attrs['class'] );
512 }
513 if ( isset( $item['itemtitle'] ) ) {
514 $attrs['title'] = $item['itemtitle'];
515 }
516 return Html::rawElement( $options['tag'] ?? 'li', $attrs, $html );
517 }
518
519 function makeSearchInput( $attrs = [] ) {
520 $realAttrs = [
521 'type' => 'search',
522 'name' => 'search',
523 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
524 ];
525 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
526 return Html::element( 'input', $realAttrs );
527 }
528
529 function makeSearchButton( $mode, $attrs = [] ) {
530 switch ( $mode ) {
531 case 'go':
532 case 'fulltext':
533 $realAttrs = [
534 'type' => 'submit',
535 'name' => $mode,
536 'value' => wfMessage( $mode == 'go' ? 'searcharticle' : 'searchbutton' )->text(),
537 ];
538 $realAttrs = array_merge(
539 $realAttrs,
540 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
541 $attrs
542 );
543 return Html::element( 'input', $realAttrs );
544 case 'image':
545 $buttonAttrs = [
546 'type' => 'submit',
547 'name' => 'button',
548 ];
549 $buttonAttrs = array_merge(
550 $buttonAttrs,
551 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
552 $attrs
553 );
554 unset( $buttonAttrs['src'] );
555 unset( $buttonAttrs['alt'] );
556 unset( $buttonAttrs['width'] );
557 unset( $buttonAttrs['height'] );
558 $imgAttrs = [
559 'src' => $attrs['src'],
560 'alt' => $attrs['alt'] ?? wfMessage( 'searchbutton' )->text(),
561 'width' => $attrs['width'] ?? null,
562 'height' => $attrs['height'] ?? null,
563 ];
564 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
565 default:
566 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
567 }
568 }
569
570 /**
571 * Returns an array of footerlinks trimmed down to only those footer links that
572 * are valid.
573 * If you pass "flat" as an option then the returned array will be a flat array
574 * of footer icons instead of a key/value array of footerlinks arrays broken
575 * up into categories.
576 * @param string|null $option
577 * @return array|mixed
578 */
579 function getFooterLinks( $option = null ) {
580 $footerlinks = $this->get( 'footerlinks' );
581
582 // Reduce footer links down to only those which are being used
583 $validFooterLinks = [];
584 foreach ( $footerlinks as $category => $links ) {
585 $validFooterLinks[$category] = [];
586 foreach ( $links as $link ) {
587 if ( isset( $this->data[$link] ) && $this->data[$link] ) {
588 $validFooterLinks[$category][] = $link;
589 }
590 }
591 if ( count( $validFooterLinks[$category] ) <= 0 ) {
592 unset( $validFooterLinks[$category] );
593 }
594 }
595
596 if ( $option == 'flat' ) {
597 // fold footerlinks into a single array using a bit of trickery
598 $validFooterLinks = array_merge( ...array_values( $validFooterLinks ) );
599 }
600
601 return $validFooterLinks;
602 }
603
604 /**
605 * Returns an array of footer icons filtered down by options relevant to how
606 * the skin wishes to display them.
607 * If you pass "icononly" as the option all footer icons which do not have an
608 * image icon set will be filtered out.
609 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
610 * in the list of footer icons. This is mostly useful for skins which only
611 * display the text from footericons instead of the images and don't want a
612 * duplicate copyright statement because footerlinks already rendered one.
613 * @param string|null $option
614 * @return array
615 */
616 function getFooterIcons( $option = null ) {
617 // Generate additional footer icons
618 $footericons = $this->get( 'footericons' );
619
620 if ( $option == 'icononly' ) {
621 // Unset any icons which don't have an image
622 foreach ( $footericons as &$footerIconsBlock ) {
623 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
624 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
625 unset( $footerIconsBlock[$footerIconKey] );
626 }
627 }
628 }
629 // Redo removal of any empty blocks
630 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
631 if ( count( $footerIconsBlock ) <= 0 ) {
632 unset( $footericons[$footerIconsKey] );
633 }
634 }
635 } elseif ( $option == 'nocopyright' ) {
636 unset( $footericons['copyright']['copyright'] );
637 if ( count( $footericons['copyright'] ) <= 0 ) {
638 unset( $footericons['copyright'] );
639 }
640 }
641
642 return $footericons;
643 }
644
645 /**
646 * Renderer for getFooterIcons and getFooterLinks
647 *
648 * @param string $iconStyle $option for getFooterIcons: "icononly", "nocopyright"
649 * @param string $linkStyle $option for getFooterLinks: "flat"
650 *
651 * @return string html
652 * @since 1.29
653 */
654 protected function getFooter( $iconStyle = 'icononly', $linkStyle = 'flat' ) {
655 $validFooterIcons = $this->getFooterIcons( $iconStyle );
656 $validFooterLinks = $this->getFooterLinks( $linkStyle );
657
658 $html = '';
659
660 if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) {
661 $html .= Html::openElement( 'div', [
662 'id' => 'footer-bottom',
663 'role' => 'contentinfo',
664 'lang' => $this->get( 'userlang' ),
665 'dir' => $this->get( 'dir' )
666 ] );
667 $footerEnd = Html::closeElement( 'div' );
668 } else {
669 $footerEnd = '';
670 }
671 foreach ( $validFooterIcons as $blockName => $footerIcons ) {
672 $html .= Html::openElement( 'div', [
673 'id' => Sanitizer::escapeIdForAttribute( "f-{$blockName}ico" ),
674 'class' => 'footer-icons'
675 ] );
676 foreach ( $footerIcons as $icon ) {
677 $html .= $this->getSkin()->makeFooterIcon( $icon );
678 }
679 $html .= Html::closeElement( 'div' );
680 }
681 if ( count( $validFooterLinks ) > 0 ) {
682 $html .= Html::openElement( 'ul', [ 'id' => 'f-list', 'class' => 'footer-places' ] );
683 foreach ( $validFooterLinks as $aLink ) {
684 $html .= Html::rawElement(
685 'li',
686 [ 'id' => Sanitizer::escapeIdForAttribute( $aLink ) ],
687 $this->get( $aLink )
688 );
689 }
690 $html .= Html::closeElement( 'ul' );
691 }
692
693 $html .= $this->getClear() . $footerEnd;
694
695 return $html;
696 }
697
698 /**
699 * Get a div with the core visualClear class, for clearing floats
700 *
701 * @return string html
702 * @since 1.29
703 */
704 protected function getClear() {
705 return Html::element( 'div', [ 'class' => 'visualClear' ] );
706 }
707
708 /**
709 * Get the suggested HTML for page status indicators: icons (or short text snippets) usually
710 * displayed in the top-right corner of the page, outside of the main content.
711 *
712 * Your skin may implement this differently, for example by handling some indicator names
713 * specially with a different UI. However, it is recommended to use a `<div class="mw-indicator"
714 * id="mw-indicator-<id>" />` as a wrapper element for each indicator, for better compatibility
715 * with extensions and user scripts.
716 *
717 * The raw data is available in `$this->data['indicators']` as an associative array (keys:
718 * identifiers, values: contents) internally ordered by keys.
719 *
720 * @return string HTML
721 * @since 1.25
722 */
723 public function getIndicators() {
724 $out = "<div class=\"mw-indicators mw-body-content\">\n";
725 foreach ( $this->data['indicators'] as $id => $content ) {
726 $out .= Html::rawElement(
727 'div',
728 [
729 'id' => Sanitizer::escapeIdForAttribute( "mw-indicator-$id" ),
730 'class' => 'mw-indicator',
731 ],
732 $content
733 ) . "\n";
734 }
735 $out .= "</div>\n";
736 return $out;
737 }
738
739 /**
740 * Output getTrail
741 */
742 function printTrail() {
743 echo $this->getTrail();
744 }
745
746 /**
747 * Get the basic end-page trail including bottomscripts, reporttime, and
748 * debug stuff. This should be called right before outputting the closing
749 * body and html tags.
750 *
751 * @return string|WrappedStringList HTML
752 * @since 1.29
753 */
754 public function getTrail() {
755 return WrappedString::join( "\n", [
756 MWDebug::getDebugHTML( $this->getSkin()->getContext() ),
757 $this->get( 'bottomscripts' ),
758 $this->get( 'reporttime' )
759 ] );
760 }
761 }