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