Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[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',
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 if ( isset( $item['links'] ) ) {
470 $links = [];
471 foreach ( $item['links'] as $linkKey => $link ) {
472 $links[] = $this->makeLink( $linkKey, $link, $options );
473 }
474 $html = implode( ' ', $links );
475 } else {
476 $link = $item;
477 // These keys are used by makeListItem and shouldn't be passed on to the link
478 foreach ( [ 'id', 'class', 'active', 'tag', 'itemtitle' ] as $k ) {
479 unset( $link[$k] );
480 }
481 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
482 // The id goes on the <li> not on the <a> for single links
483 // but makeSidebarLink still needs to know what id to use when
484 // generating tooltips and accesskeys.
485 $link['single-id'] = $item['id'];
486 }
487 if ( isset( $link['link-class'] ) ) {
488 // link-class should be set on the <a> itself,
489 // so pass it in as 'class'
490 $link['class'] = $link['link-class'];
491 unset( $link['link-class'] );
492 }
493 $html = $this->makeLink( $key, $link, $options );
494 }
495
496 $attrs = [];
497 foreach ( [ 'id', 'class' ] as $attr ) {
498 if ( isset( $item[$attr] ) ) {
499 $attrs[$attr] = $item[$attr];
500 }
501 }
502 if ( isset( $item['active'] ) && $item['active'] ) {
503 if ( !isset( $attrs['class'] ) ) {
504 $attrs['class'] = '';
505 }
506 $attrs['class'] .= ' active';
507 $attrs['class'] = trim( $attrs['class'] );
508 }
509 if ( isset( $item['itemtitle'] ) ) {
510 $attrs['title'] = $item['itemtitle'];
511 }
512 return Html::rawElement( $options['tag'] ?? 'li', $attrs, $html );
513 }
514
515 function makeSearchInput( $attrs = [] ) {
516 $realAttrs = [
517 'type' => 'search',
518 'name' => 'search',
519 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
520 ];
521 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
522 return Html::element( 'input', $realAttrs );
523 }
524
525 function makeSearchButton( $mode, $attrs = [] ) {
526 switch ( $mode ) {
527 case 'go':
528 case 'fulltext':
529 $realAttrs = [
530 'type' => 'submit',
531 'name' => $mode,
532 'value' => wfMessage( $mode == 'go' ? 'searcharticle' : 'searchbutton' )->text(),
533 ];
534 $realAttrs = array_merge(
535 $realAttrs,
536 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
537 $attrs
538 );
539 return Html::element( 'input', $realAttrs );
540 case 'image':
541 $buttonAttrs = [
542 'type' => 'submit',
543 'name' => 'button',
544 ];
545 $buttonAttrs = array_merge(
546 $buttonAttrs,
547 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
548 $attrs
549 );
550 unset( $buttonAttrs['src'] );
551 unset( $buttonAttrs['alt'] );
552 unset( $buttonAttrs['width'] );
553 unset( $buttonAttrs['height'] );
554 $imgAttrs = [
555 'src' => $attrs['src'],
556 'alt' => $attrs['alt'] ?? wfMessage( 'searchbutton' )->text(),
557 'width' => $attrs['width'] ?? null,
558 'height' => $attrs['height'] ?? null,
559 ];
560 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
561 default:
562 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
563 }
564 }
565
566 /**
567 * Returns an array of footerlinks trimmed down to only those footer links that
568 * are valid.
569 * If you pass "flat" as an option then the returned array will be a flat array
570 * of footer icons instead of a key/value array of footerlinks arrays broken
571 * up into categories.
572 * @param string|null $option
573 * @return array|mixed
574 */
575 function getFooterLinks( $option = null ) {
576 $footerlinks = $this->get( 'footerlinks' );
577
578 // Reduce footer links down to only those which are being used
579 $validFooterLinks = [];
580 foreach ( $footerlinks as $category => $links ) {
581 $validFooterLinks[$category] = [];
582 foreach ( $links as $link ) {
583 if ( isset( $this->data[$link] ) && $this->data[$link] ) {
584 $validFooterLinks[$category][] = $link;
585 }
586 }
587 if ( count( $validFooterLinks[$category] ) <= 0 ) {
588 unset( $validFooterLinks[$category] );
589 }
590 }
591
592 if ( $option == 'flat' ) {
593 // fold footerlinks into a single array using a bit of trickery
594 $validFooterLinks = array_merge( ...array_values( $validFooterLinks ) );
595 }
596
597 return $validFooterLinks;
598 }
599
600 /**
601 * Returns an array of footer icons filtered down by options relevant to how
602 * the skin wishes to display them.
603 * If you pass "icononly" as the option all footer icons which do not have an
604 * image icon set will be filtered out.
605 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
606 * in the list of footer icons. This is mostly useful for skins which only
607 * display the text from footericons instead of the images and don't want a
608 * duplicate copyright statement because footerlinks already rendered one.
609 * @param string|null $option
610 * @return array
611 */
612 function getFooterIcons( $option = null ) {
613 // Generate additional footer icons
614 $footericons = $this->get( 'footericons' );
615
616 if ( $option == 'icononly' ) {
617 // Unset any icons which don't have an image
618 foreach ( $footericons as &$footerIconsBlock ) {
619 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
620 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
621 unset( $footerIconsBlock[$footerIconKey] );
622 }
623 }
624 }
625 // Redo removal of any empty blocks
626 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
627 if ( count( $footerIconsBlock ) <= 0 ) {
628 unset( $footericons[$footerIconsKey] );
629 }
630 }
631 } elseif ( $option == 'nocopyright' ) {
632 unset( $footericons['copyright']['copyright'] );
633 if ( count( $footericons['copyright'] ) <= 0 ) {
634 unset( $footericons['copyright'] );
635 }
636 }
637
638 return $footericons;
639 }
640
641 /**
642 * Renderer for getFooterIcons and getFooterLinks
643 *
644 * @param string $iconStyle $option for getFooterIcons: "icononly", "nocopyright"
645 * @param string $linkStyle $option for getFooterLinks: "flat"
646 *
647 * @return string html
648 * @since 1.29
649 */
650 protected function getFooter( $iconStyle = 'icononly', $linkStyle = 'flat' ) {
651 $validFooterIcons = $this->getFooterIcons( $iconStyle );
652 $validFooterLinks = $this->getFooterLinks( $linkStyle );
653
654 $html = '';
655
656 if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) {
657 $html .= Html::openElement( 'div', [
658 'id' => 'footer-bottom',
659 'role' => 'contentinfo',
660 'lang' => $this->get( 'userlang' ),
661 'dir' => $this->get( 'dir' )
662 ] );
663 $footerEnd = Html::closeElement( 'div' );
664 } else {
665 $footerEnd = '';
666 }
667 foreach ( $validFooterIcons as $blockName => $footerIcons ) {
668 $html .= Html::openElement( 'div', [
669 'id' => Sanitizer::escapeIdForAttribute( "f-{$blockName}ico" ),
670 'class' => 'footer-icons'
671 ] );
672 foreach ( $footerIcons as $icon ) {
673 $html .= $this->getSkin()->makeFooterIcon( $icon );
674 }
675 $html .= Html::closeElement( 'div' );
676 }
677 if ( count( $validFooterLinks ) > 0 ) {
678 $html .= Html::openElement( 'ul', [ 'id' => 'f-list', 'class' => 'footer-places' ] );
679 foreach ( $validFooterLinks as $aLink ) {
680 $html .= Html::rawElement(
681 'li',
682 [ 'id' => Sanitizer::escapeIdForAttribute( $aLink ) ],
683 $this->get( $aLink )
684 );
685 }
686 $html .= Html::closeElement( 'ul' );
687 }
688
689 $html .= $this->getClear() . $footerEnd;
690
691 return $html;
692 }
693
694 /**
695 * Get a div with the core visualClear class, for clearing floats
696 *
697 * @return string html
698 * @since 1.29
699 */
700 protected function getClear() {
701 return Html::element( 'div', [ 'class' => 'visualClear' ] );
702 }
703
704 /**
705 * Get the suggested HTML for page status indicators: icons (or short text snippets) usually
706 * displayed in the top-right corner of the page, outside of the main content.
707 *
708 * Your skin may implement this differently, for example by handling some indicator names
709 * specially with a different UI. However, it is recommended to use a `<div class="mw-indicator"
710 * id="mw-indicator-<id>" />` as a wrapper element for each indicator, for better compatibility
711 * with extensions and user scripts.
712 *
713 * The raw data is available in `$this->data['indicators']` as an associative array (keys:
714 * identifiers, values: contents) internally ordered by keys.
715 *
716 * @return string HTML
717 * @since 1.25
718 */
719 public function getIndicators() {
720 $out = "<div class=\"mw-indicators mw-body-content\">\n";
721 foreach ( $this->data['indicators'] as $id => $content ) {
722 $out .= Html::rawElement(
723 'div',
724 [
725 'id' => Sanitizer::escapeIdForAttribute( "mw-indicator-$id" ),
726 'class' => 'mw-indicator',
727 ],
728 $content
729 ) . "\n";
730 }
731 $out .= "</div>\n";
732 return $out;
733 }
734
735 /**
736 * Output getTrail
737 */
738 function printTrail() {
739 echo $this->getTrail();
740 }
741
742 /**
743 * Get the basic end-page trail including bottomscripts, reporttime, and
744 * debug stuff. This should be called right before outputting the closing
745 * body and html tags.
746 *
747 * @return string|WrappedStringList HTML
748 * @since 1.29
749 */
750 public function getTrail() {
751 return WrappedString::join( "\n", [
752 MWDebug::getDebugHTML( $this->getSkin()->getContext() ),
753 $this->get( 'bottomscripts' ),
754 $this->get( 'reporttime' )
755 ] );
756 }
757 }