Merge "Permit destructors in MediaWikiTestCaseTrait::createNoOpMock"
[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 * @phan-param array{id?:string,class?:string,itemtitle?:string,active?:bool} $item
448 *
449 * @param array $options
450 * @phan-param array{tag?:string} $options
451 *
452 * If you want something other than a "<li>" you can pass a tag name such as
453 * "tag" => "span" in the $options array to change the tag used.
454 * link/content data for the list item may come in one of two forms
455 * A "links" key may be used, in which case it should contain an array with
456 * a list of links to include inside the list item, see makeLink for the
457 * format of individual links array items.
458 *
459 * Otherwise the relevant keys from the list item $item array will be passed
460 * to makeLink instead. Note however that "id" and "class" are used by the
461 * list item directly so they will not be passed to makeLink
462 * (however the link will still support a tooltip and accesskey from it)
463 * If you need an id or class on a single link you should include a "links"
464 * array with just one link item inside of it. You can also set "link-class" in
465 * $item to set a class on the link itself. If you want to add a title
466 * to the list item itself, you can set "itemtitle" to the value.
467 * $options is also passed on to makeLink calls
468 *
469 * @return string
470 */
471 function makeListItem( $key, $item, $options = [] ) {
472 // In case this is still set from SkinTemplate, we don't want it to appear in
473 // the HTML output (normally removed in SkinTemplate::buildContentActionUrls())
474 unset( $item['redundant'] );
475
476 if ( isset( $item['links'] ) ) {
477 $links = [];
478 foreach ( $item['links'] as $linkKey => $link ) {
479 $links[] = $this->makeLink( $linkKey, $link, $options );
480 }
481 $html = implode( ' ', $links );
482 } else {
483 $link = $item;
484 // These keys are used by makeListItem and shouldn't be passed on to the link
485 foreach ( [ 'id', 'class', 'active', 'tag', 'itemtitle' ] as $k ) {
486 unset( $link[$k] );
487 }
488 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
489 // The id goes on the <li> not on the <a> for single links
490 // but makeSidebarLink still needs to know what id to use when
491 // generating tooltips and accesskeys.
492 $link['single-id'] = $item['id'];
493 }
494 if ( isset( $link['link-class'] ) ) {
495 // link-class should be set on the <a> itself,
496 // so pass it in as 'class'
497 $link['class'] = $link['link-class'];
498 unset( $link['link-class'] );
499 }
500 $html = $this->makeLink( $key, $link, $options );
501 }
502
503 $attrs = [];
504 foreach ( [ 'id', 'class' ] as $attr ) {
505 if ( isset( $item[$attr] ) ) {
506 $attrs[$attr] = $item[$attr];
507 }
508 }
509 if ( isset( $item['active'] ) && $item['active'] ) {
510 if ( !isset( $attrs['class'] ) ) {
511 $attrs['class'] = '';
512 }
513 $attrs['class'] .= ' active';
514 $attrs['class'] = trim( $attrs['class'] );
515 }
516 if ( isset( $item['itemtitle'] ) ) {
517 $attrs['title'] = $item['itemtitle'];
518 }
519 // @phan-suppress-next-line PhanTypeInvalidDimOffset
520 return Html::rawElement( $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' => $attrs['alt'] ?? wfMessage( 'searchbutton' )->text(),
565 'width' => $attrs['width'] ?? null,
566 'height' => $attrs['height'] ?? null,
567 ];
568 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
569 default:
570 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
571 }
572 }
573
574 /**
575 * Returns an array of footerlinks trimmed down to only those footer links that
576 * are valid.
577 * If you pass "flat" as an option then the returned array will be a flat array
578 * of footer icons instead of a key/value array of footerlinks arrays broken
579 * up into categories.
580 * @param string|null $option
581 * @return array|mixed
582 */
583 function getFooterLinks( $option = null ) {
584 $footerlinks = $this->get( 'footerlinks' );
585
586 // Reduce footer links down to only those which are being used
587 $validFooterLinks = [];
588 foreach ( $footerlinks as $category => $links ) {
589 $validFooterLinks[$category] = [];
590 foreach ( $links as $link ) {
591 if ( isset( $this->data[$link] ) && $this->data[$link] ) {
592 $validFooterLinks[$category][] = $link;
593 }
594 }
595 if ( count( $validFooterLinks[$category] ) <= 0 ) {
596 unset( $validFooterLinks[$category] );
597 }
598 }
599
600 if ( $option == 'flat' ) {
601 // fold footerlinks into a single array using a bit of trickery
602 $validFooterLinks = array_merge( ...array_values( $validFooterLinks ) );
603 }
604
605 return $validFooterLinks;
606 }
607
608 /**
609 * Returns an array of footer icons filtered down by options relevant to how
610 * the skin wishes to display them.
611 * If you pass "icononly" as the option all footer icons which do not have an
612 * image icon set will be filtered out.
613 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
614 * in the list of footer icons. This is mostly useful for skins which only
615 * display the text from footericons instead of the images and don't want a
616 * duplicate copyright statement because footerlinks already rendered one.
617 * @param string|null $option
618 * @return array
619 */
620 function getFooterIcons( $option = null ) {
621 // Generate additional footer icons
622 $footericons = $this->get( 'footericons' );
623
624 if ( $option == 'icononly' ) {
625 // Unset any icons which don't have an image
626 foreach ( $footericons as &$footerIconsBlock ) {
627 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
628 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
629 unset( $footerIconsBlock[$footerIconKey] );
630 }
631 }
632 }
633 // Redo removal of any empty blocks
634 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
635 if ( count( $footerIconsBlock ) <= 0 ) {
636 unset( $footericons[$footerIconsKey] );
637 }
638 }
639 } elseif ( $option == 'nocopyright' ) {
640 unset( $footericons['copyright']['copyright'] );
641 if ( count( $footericons['copyright'] ) <= 0 ) {
642 unset( $footericons['copyright'] );
643 }
644 }
645
646 return $footericons;
647 }
648
649 /**
650 * Renderer for getFooterIcons and getFooterLinks
651 *
652 * @param string $iconStyle $option for getFooterIcons: "icononly", "nocopyright"
653 * @param string $linkStyle $option for getFooterLinks: "flat"
654 *
655 * @return string html
656 * @since 1.29
657 */
658 protected function getFooter( $iconStyle = 'icononly', $linkStyle = 'flat' ) {
659 $validFooterIcons = $this->getFooterIcons( $iconStyle );
660 $validFooterLinks = $this->getFooterLinks( $linkStyle );
661
662 $html = '';
663
664 if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) {
665 $html .= Html::openElement( 'div', [
666 'id' => 'footer-bottom',
667 'role' => 'contentinfo',
668 'lang' => $this->get( 'userlang' ),
669 'dir' => $this->get( 'dir' )
670 ] );
671 $footerEnd = Html::closeElement( 'div' );
672 } else {
673 $footerEnd = '';
674 }
675 foreach ( $validFooterIcons as $blockName => $footerIcons ) {
676 $html .= Html::openElement( 'div', [
677 'id' => Sanitizer::escapeIdForAttribute( "f-{$blockName}ico" ),
678 'class' => 'footer-icons'
679 ] );
680 foreach ( $footerIcons as $icon ) {
681 $html .= $this->getSkin()->makeFooterIcon( $icon );
682 }
683 $html .= Html::closeElement( 'div' );
684 }
685 if ( count( $validFooterLinks ) > 0 ) {
686 $html .= Html::openElement( 'ul', [ 'id' => 'f-list', 'class' => 'footer-places' ] );
687 foreach ( $validFooterLinks as $aLink ) {
688 $html .= Html::rawElement(
689 'li',
690 [ 'id' => Sanitizer::escapeIdForAttribute( $aLink ) ],
691 $this->get( $aLink )
692 );
693 }
694 $html .= Html::closeElement( 'ul' );
695 }
696
697 $html .= $this->getClear() . $footerEnd;
698
699 return $html;
700 }
701
702 /**
703 * Get a div with the core visualClear class, for clearing floats
704 *
705 * @return string html
706 * @since 1.29
707 */
708 protected function getClear() {
709 return Html::element( 'div', [ 'class' => 'visualClear' ] );
710 }
711
712 /**
713 * Get the suggested HTML for page status indicators: icons (or short text snippets) usually
714 * displayed in the top-right corner of the page, outside of the main content.
715 *
716 * Your skin may implement this differently, for example by handling some indicator names
717 * specially with a different UI. However, it is recommended to use a `<div class="mw-indicator"
718 * id="mw-indicator-<id>" />` as a wrapper element for each indicator, for better compatibility
719 * with extensions and user scripts.
720 *
721 * The raw data is available in `$this->data['indicators']` as an associative array (keys:
722 * identifiers, values: contents) internally ordered by keys.
723 *
724 * @return string HTML
725 * @since 1.25
726 */
727 public function getIndicators() {
728 $out = "<div class=\"mw-indicators mw-body-content\">\n";
729 foreach ( $this->data['indicators'] as $id => $content ) {
730 $out .= Html::rawElement(
731 'div',
732 [
733 'id' => Sanitizer::escapeIdForAttribute( "mw-indicator-$id" ),
734 'class' => 'mw-indicator',
735 ],
736 $content
737 ) . "\n";
738 }
739 $out .= "</div>\n";
740 return $out;
741 }
742
743 /**
744 * Output getTrail
745 */
746 function printTrail() {
747 echo $this->getTrail();
748 }
749
750 /**
751 * Get the basic end-page trail including bottomscripts, reporttime, and
752 * debug stuff. This should be called right before outputting the closing
753 * body and html tags.
754 *
755 * @return string|WrappedStringList HTML
756 * @since 1.29
757 */
758 public function getTrail() {
759 return WrappedString::join( "\n", [
760 MWDebug::getDebugHTML( $this->getSkin()->getContext() ),
761 $this->get( 'bottomscripts' ),
762 $this->get( 'reporttime' )
763 ] );
764 }
765 }