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