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