3 * Vector - Modern version of MonoBook with fresh look and many usability
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
26 * QuickTemplate class for Vector skin
29 class VectorTemplate
extends BaseTemplate
{
33 * Outputs the entire contents of the (X)HTML page
35 public function execute() {
36 // Build additional attributes for navigation urls
37 $nav = $this->data
['content_navigation'];
39 if ( $this->config
->get( 'VectorUseIconWatch' ) ) {
40 $mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() )
44 if ( isset( $nav['actions'][$mode] ) ) {
45 $nav['views'][$mode] = $nav['actions'][$mode];
46 $nav['views'][$mode]['class'] = rtrim( 'icon ' . $nav['views'][$mode]['class'], ' ' );
47 $nav['views'][$mode]['primary'] = true;
48 unset( $nav['actions'][$mode] );
53 foreach ( $nav as $section => $links ) {
54 foreach ( $links as $key => $link ) {
55 if ( $section == 'views' && !( isset( $link['primary'] ) && $link['primary'] ) ) {
56 $link['class'] = rtrim( 'collapsible ' . $link['class'], ' ' );
59 $xmlID = isset( $link['id'] ) ?
$link['id'] : 'ca-' . $xmlID;
60 $nav[$section][$key]['attributes'] =
61 ' id="' . Sanitizer
::escapeId( $xmlID ) . '"';
62 if ( $link['class'] ) {
63 $nav[$section][$key]['attributes'] .=
64 ' class="' . htmlspecialchars( $link['class'] ) . '"';
65 unset( $nav[$section][$key]['class'] );
67 if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
68 $nav[$section][$key]['key'] =
69 Linker
::tooltip( $xmlID );
71 $nav[$section][$key]['key'] =
72 Xml
::expandAttributes( Linker
::tooltipAndAccesskeyAttribs( $xmlID ) );
76 $this->data
['namespace_urls'] = $nav['namespaces'];
77 $this->data
['view_urls'] = $nav['views'];
78 $this->data
['action_urls'] = $nav['actions'];
79 $this->data
['variant_urls'] = $nav['variants'];
81 // Reverse horizontally rendered navigation elements
82 if ( $this->data
['rtl'] ) {
83 $this->data
['view_urls'] =
84 array_reverse( $this->data
['view_urls'] );
85 $this->data
['namespace_urls'] =
86 array_reverse( $this->data
['namespace_urls'] );
87 $this->data
['personal_urls'] =
88 array_reverse( $this->data
['personal_urls'] );
91 $this->data
['pageLanguage'] =
92 $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
95 $this->html( 'headelement' );
97 <div id
="mw-page-base" class="noprint"></div
>
98 <div id
="mw-head-base" class="noprint"></div
>
99 <div id
="content" class="mw-body" role
="main">
103 if ( $this->data
['sitenotice'] ) {
105 <div id
="siteNotice"><?php
$this->html( 'sitenotice' ) ?
></div
>
110 if ( is_callable( [ $this, 'getIndicators' ] ) ) {
111 echo $this->getIndicators();
113 // Loose comparison with '!=' is intentional, to catch null and false too, but not '0'
114 if ( $this->data
['title'] != '' ) {
116 <h1 id
="firstHeading" class="firstHeading" lang
="<?php $this->text( 'pageLanguage' ); ?>"><?php
117 $this->html( 'title' )
121 <?php
$this->html( 'prebodyhtml' ) ?
>
122 <div id
="bodyContent" class="mw-body-content">
124 if ( $this->data
['isarticle'] ) {
126 <div id
="siteSub"><?php
$this->msg( 'tagline' ) ?
></div
>
130 <div id
="contentSub"<?php
$this->html( 'userlangattributes' ) ?
>><?php
131 $this->html( 'subtitle' )
134 if ( $this->data
['undelete'] ) {
136 <div id
="contentSub2"><?php
$this->html( 'undelete' ) ?
></div
>
141 if ( $this->data
['newtalk'] ) {
143 <div
class="usermessage"><?php
$this->html( 'newtalk' ) ?
></div
>
147 <div id
="jump-to-nav" class="mw-jump">
148 <?php
$this->msg( 'jumpto' ) ?
>
149 <a href
="#mw-head"><?php
150 $this->msg( 'jumptonavigation' )
151 ?
></a
><?php
$this->msg( 'comma-separator' ) ?
>
152 <a href
="#p-search"><?php
$this->msg( 'jumptosearch' ) ?
></a
>
155 $this->html( 'bodycontent' );
157 if ( $this->data
['printfooter'] ) {
159 <div
class="printfooter">
160 <?php
$this->html( 'printfooter' ); ?
>
165 if ( $this->data
['catlinks'] ) {
166 $this->html( 'catlinks' );
169 if ( $this->data
['dataAfterContent'] ) {
170 $this->html( 'dataAfterContent' );
173 <div
class="visualClear"></div
>
174 <?php
$this->html( 'debughtml' ); ?
>
177 <div id
="mw-navigation">
178 <h2
><?php
$this->msg( 'navigation-heading' ) ?
></h2
>
181 <?php
$this->renderNavigation( 'PERSONAL' ); ?
>
182 <div id
="left-navigation">
183 <?php
$this->renderNavigation( [ 'NAMESPACES', 'VARIANTS' ] ); ?
>
185 <div id
="right-navigation">
186 <?php
$this->renderNavigation( [ 'VIEWS', 'ACTIONS', 'SEARCH' ] ); ?
>
190 <div id
="p-logo" role
="banner"><a
class="mw-wiki-logo" href
="<?php
191 echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] )
193 echo Xml
::expandAttributes( Linker
::tooltipAndAccesskeyAttribs( 'p-logo' ) )
195 <?php
$this->renderPortals( $this->data
['sidebar'] ); ?
>
198 <div id
="footer" role
="contentinfo"<?php
$this->html( 'userlangattributes' ) ?
>>
200 foreach ( $this->getFooterLinks() as $category => $links ) {
202 <ul id
="footer-<?php echo $category ?>">
204 foreach ( $links as $link ) {
206 <li id
="footer-<?php echo $category ?>-<?php echo $link ?>"><?php
$this->html( $link ) ?
></li
>
214 <?php
$footericons = $this->getFooterIcons( 'icononly' );
215 if ( count( $footericons ) > 0 ) {
217 <ul id
="footer-icons" class="noprint">
219 foreach ( $footericons as $blockName => $footerIcons ) {
221 <li id
="footer-<?php echo htmlspecialchars( $blockName ); ?>ico">
223 foreach ( $footerIcons as $icon ) {
224 echo $this->getSkin()->makeFooterIcon( $icon );
235 <div style
="clear:both"></div
>
237 <?php
$this->printTrail(); ?
>
245 * Render a series of portals
247 * @param array $portals
249 protected function renderPortals( $portals ) {
250 // Force the rendering of the following portals
251 if ( !isset( $portals['SEARCH'] ) ) {
252 $portals['SEARCH'] = true;
254 if ( !isset( $portals['TOOLBOX'] ) ) {
255 $portals['TOOLBOX'] = true;
257 if ( !isset( $portals['LANGUAGES'] ) ) {
258 $portals['LANGUAGES'] = true;
261 foreach ( $portals as $name => $content ) {
262 if ( $content === false ) {
266 // Numeric strings gets an integer when set as key, cast back - T73639
267 $name = (string)$name;
273 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
276 if ( $this->data
['language_urls'] !== false ) {
277 $this->renderPortal( 'lang', $this->data
['language_urls'], 'otherlanguages' );
281 $this->renderPortal( $name, $content );
288 * @param string $name
289 * @param array $content
290 * @param null|string $msg
291 * @param null|string|array $hook
293 protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
294 if ( $msg === null ) {
297 $msgObj = wfMessage( $msg );
298 $labelId = Sanitizer
::escapeId( "p-$name-label" );
300 <div
class="portal" role
="navigation" id
='<?php
301 echo Sanitizer::escapeId( "p-$name" )
303 echo Linker
::tooltip( 'p-' . $name )
304 ?
> aria
-labelledby
='<?php echo $labelId ?>'>
305 <h3
<?php
$this->html( 'userlangattributes' ) ?
> id
='<?php echo $labelId ?>'><?php
306 echo htmlspecialchars( $msgObj->exists() ?
$msgObj->text() : $msg );
311 if ( is_array( $content ) ) {
315 foreach ( $content as $key => $val ) {
316 echo $this->makeListItem( $key, $val );
318 if ( $hook !== null ) {
319 Hooks
::run( $hook, [ &$this, true ] );
325 echo $content; /* Allow raw HTML block to be defined by extensions */
328 $this->renderAfterPortlet( $name );
336 * Render one or more navigations elements by name, automatically reveresed
337 * when UI is in RTL mode
339 * @param array $elements
341 protected function renderNavigation( $elements ) {
342 // If only one element was given, wrap it in an array, allowing more
343 // flexible arguments
344 if ( !is_array( $elements ) ) {
345 $elements = [ $elements ];
346 // If there's a series of elements, reverse them when in RTL mode
347 } elseif ( $this->data
['rtl'] ) {
348 $elements = array_reverse( $elements );
351 foreach ( $elements as $name => $element ) {
352 switch ( $element ) {
355 <div id
="p-namespaces" role
="navigation" class="vectorTabs<?php
356 if ( count( $this->data['namespace_urls'] ) == 0 ) {
357 echo ' emptyPortlet';
359 ?>" aria
-labelledby
="p-namespaces-label">
360 <h3 id
="p-namespaces-label"><?php
$this->msg( 'namespaces' ) ?
></h3
>
361 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
363 foreach ( $this->data
['namespace_urls'] as $link ) {
365 <li
<?php
echo $link['attributes'] ?
>><span
><a href
="<?php
366 echo htmlspecialchars( $link['href'] )
369 if ( isset ( $link['rel'] ) ) {
370 echo ' rel="' . htmlspecialchars( $link['rel'] ) . '"';
373 echo htmlspecialchars( $link['text'] )
384 <div id
="p-variants" role
="navigation" class="vectorMenu<?php
385 if ( count( $this->data['variant_urls'] ) == 0 ) {
386 echo ' emptyPortlet';
388 ?>" aria
-labelledby
="p-variants-label">
390 // Replace the label with the name of currently chosen variant, if any
391 $variantLabel = $this->getMsg( 'variants' )->text();
392 foreach ( $this->data
['variant_urls'] as $link ) {
393 if ( stripos( $link['attributes'], 'selected' ) !== false ) {
394 $variantLabel = $link['text'];
399 <h3 id
="p-variants-label">
400 <span
><?php
echo htmlspecialchars( $variantLabel ) ?
></span
><a href
="#"></a
>
406 foreach ( $this->data
['variant_urls'] as $link ) {
408 <li
<?php
echo $link['attributes'] ?
>><a href
="<?php
409 echo htmlspecialchars( $link['href'] )
411 echo htmlspecialchars( $link['lang'] )
413 echo htmlspecialchars( $link['hreflang'] )
417 echo htmlspecialchars( $link['text'] )
429 <div id
="p-views" role
="navigation" class="vectorTabs<?php
430 if ( count( $this->data['view_urls'] ) == 0 ) {
431 echo ' emptyPortlet';
433 ?>" aria
-labelledby
="p-views-label">
434 <h3 id
="p-views-label"><?php
$this->msg( 'views' ) ?
></h3
>
435 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
437 foreach ( $this->data
['view_urls'] as $link ) {
439 <li
<?php
echo $link['attributes'] ?
>><span
><a href
="<?php
440 echo htmlspecialchars( $link['href'] )
443 if ( isset ( $link['rel'] ) ) {
444 echo ' rel="' . htmlspecialchars( $link['rel'] ) . '"';
447 // $link['text'] can be undefined - bug 27764
448 if ( array_key_exists( 'text', $link ) ) {
449 echo array_key_exists( 'img', $link )
450 ?
'<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />'
451 : htmlspecialchars( $link['text'] );
463 <div id
="p-cactions" role
="navigation" class="vectorMenu<?php
464 if ( count( $this->data['action_urls'] ) == 0 ) {
465 echo ' emptyPortlet';
467 ?>" aria
-labelledby
="p-cactions-label">
468 <h3 id
="p-cactions-label"><span
><?php
469 $this->msg( 'vector-more-actions' )
470 ?
></span
><a href
="#"></a
></h3
>
473 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
475 foreach ( $this->data
['action_urls'] as $link ) {
477 <li
<?php
echo $link['attributes'] ?
>>
479 echo htmlspecialchars( $link['href'] )
481 echo $link['key'] ?
>><?php
echo htmlspecialchars( $link['text'] )
494 <div id
="p-personal" role
="navigation" class="<?php
495 if ( count( $this->data['personal_urls'] ) == 0 ) {
496 echo ' emptyPortlet';
498 ?>" aria
-labelledby
="p-personal-label">
499 <h3 id
="p-personal-label"><?php
$this->msg( 'personaltools' ) ?
></h3
>
500 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
505 if ( !$this->getSkin()->getUser()->isLoggedIn() &&
506 User
::groupHasPermission( '*', 'edit' ) ){
509 Html
::rawElement( 'li',
510 [ 'id' => 'pt-anonuserpage' ],
511 $this->getMsg( 'notloggedin' )->escaped()
516 $personalTools = $this->getPersonalTools();
519 if ( array_key_exists( 'uls', $personalTools ) ) {
520 $langSelector = $this->makeListItem( 'uls', $personalTools[ 'uls' ] );
521 unset( $personalTools[ 'uls' ] );
524 if ( !$this->data
[ 'rtl' ] ) {
529 foreach ( $personalTools as $key => $item ) {
530 echo $this->makeListItem( $key, $item );
533 if ( $this->data
[ 'rtl' ] ) {
544 <div id
="p-search" role
="search">
545 <h3
<?php
$this->html( 'userlangattributes' ) ?
>>
546 <label
for="searchInput"><?php
$this->msg( 'search' ) ?
></label
>
549 <form action
="<?php $this->text( 'wgScript' ) ?>" id
="searchform">
550 <div
<?php
echo $this->config
->get( 'VectorUseSimpleSearch' ) ?
' id="simpleSearch"' : '' ?
>>
552 echo $this->makeSearchInput( [ 'id' => 'searchInput' ] );
553 echo Html
::hidden( 'title', $this->get( 'searchtitle' ) );
554 // We construct two buttons (for 'go' and 'fulltext' search modes),
555 // but only one will be visible and actionable at a time (they are
556 // overlaid on top of each other in CSS).
557 // * Browsers will use the 'fulltext' one by default (as it's the
558 // first in tree-order), which is desirable when they are unable
559 // to show search suggestions (either due to being broken or
560 // having JavaScript turned off).
561 // * The mediawiki.searchSuggest module, after doing tests for the
562 // broken browsers, removes the 'fulltext' button and handles
563 // 'fulltext' search itself; this will reveal the 'go' button and
564 // cause it to be used.
565 echo $this->makeSearchButton(
567 [ 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' ]
569 echo $this->makeSearchButton(
571 [ 'id' => 'searchButton', 'class' => 'searchButton' ]