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 if ( !defined( 'MEDIAWIKI' ) ) {
31 * SkinTemplate class for Vector skin
34 class SkinVector
extends SkinTemplate
{
35 public $useHeadElement = true;
36 public $skinname = 'vector';
37 public $stylename = 'vector';
38 public $template = 'VectorTemplate';
40 protected static $bodyClasses = array( 'vector-animateLayout' );
43 * Initializes output page and sets up skin-specific parameters
44 * @param OutputPage $out Object to initialize
46 public function initPage( OutputPage
$out ) {
47 global $wgLocalStylePath;
49 parent
::initPage( $out );
51 // Append CSS which includes IE only behavior fixes for hover support -
52 // this is better than including this in a CSS file since it doesn't
53 // wait for the CSS file to load before fetching the HTC file.
54 $min = $this->getRequest()->getFuzzyBool( 'debug' ) ?
'' : '.min';
55 $out->addHeadItem( 'csshover',
56 '<!--[if lt IE 7]><style type="text/css">body{behavior:url("' .
57 htmlspecialchars( $wgLocalStylePath ) .
58 "/{$this->stylename}/csshover{$min}.htc\")}</style><![endif]-->"
61 $out->addModules( array( 'skins.vector.js' ) );
65 * Loads skin and user CSS files.
66 * @param OutputPage $out
68 function setupSkinUserCss( OutputPage
$out ) {
69 parent
::setupSkinUserCss( $out );
71 $styles = array( 'mediawiki.skinning.interface', 'skins.vector.styles' );
72 wfRunHooks( 'SkinVectorStyleModules', array( $this, &$styles ) );
73 $out->addModuleStyles( $styles );
77 * Adds classes to the body element.
79 * @param OutputPage $out
80 * @param array &$bodyAttrs Array of attributes that will be set on the body element
82 function addToBodyAttributes( $out, &$bodyAttrs ) {
83 if ( isset( $bodyAttrs['class'] ) && strlen( $bodyAttrs['class'] ) > 0 ) {
84 $bodyAttrs['class'] .= ' ' . implode( ' ', static::$bodyClasses );
86 $bodyAttrs['class'] = implode( ' ', static::$bodyClasses );
92 * QuickTemplate class for Vector skin
95 class VectorTemplate
extends BaseTemplate
{
99 * Outputs the entire contents of the (X)HTML page
101 public function execute() {
102 global $wgVectorUseIconWatch;
104 // Build additional attributes for navigation urls
105 $nav = $this->data
['content_navigation'];
107 if ( $wgVectorUseIconWatch ) {
108 $mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() )
112 if ( isset( $nav['actions'][$mode] ) ) {
113 $nav['views'][$mode] = $nav['actions'][$mode];
114 $nav['views'][$mode]['class'] = rtrim( 'icon ' . $nav['views'][$mode]['class'], ' ' );
115 $nav['views'][$mode]['primary'] = true;
116 unset( $nav['actions'][$mode] );
121 foreach ( $nav as $section => $links ) {
122 foreach ( $links as $key => $link ) {
123 if ( $section == 'views' && !( isset( $link['primary'] ) && $link['primary'] ) ) {
124 $link['class'] = rtrim( 'collapsible ' . $link['class'], ' ' );
127 $xmlID = isset( $link['id'] ) ?
$link['id'] : 'ca-' . $xmlID;
128 $nav[$section][$key]['attributes'] =
129 ' id="' . Sanitizer
::escapeId( $xmlID ) . '"';
130 if ( $link['class'] ) {
131 $nav[$section][$key]['attributes'] .=
132 ' class="' . htmlspecialchars( $link['class'] ) . '"';
133 unset( $nav[$section][$key]['class'] );
135 if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
136 $nav[$section][$key]['key'] =
137 Linker
::tooltip( $xmlID );
139 $nav[$section][$key]['key'] =
140 Xml
::expandAttributes( Linker
::tooltipAndAccesskeyAttribs( $xmlID ) );
144 $this->data
['namespace_urls'] = $nav['namespaces'];
145 $this->data
['view_urls'] = $nav['views'];
146 $this->data
['action_urls'] = $nav['actions'];
147 $this->data
['variant_urls'] = $nav['variants'];
149 // Reverse horizontally rendered navigation elements
150 if ( $this->data
['rtl'] ) {
151 $this->data
['view_urls'] =
152 array_reverse( $this->data
['view_urls'] );
153 $this->data
['namespace_urls'] =
154 array_reverse( $this->data
['namespace_urls'] );
155 $this->data
['personal_urls'] =
156 array_reverse( $this->data
['personal_urls'] );
159 $this->html( 'headelement' );
161 <div id
="mw-page-base" class="noprint"></div
>
162 <div id
="mw-head-base" class="noprint"></div
>
163 <div id
="content" class="mw-body" role
="main">
166 <div id
="mw-js-message" style
="display:none;"<?php
$this->html( 'userlangattributes' ) ?
>></div
>
168 if ( $this->data
['sitenotice'] ) {
170 <div id
="siteNotice"><?php
$this->html( 'sitenotice' ) ?
></div
>
174 <h1 id
="firstHeading" class="firstHeading" lang
="<?php
175 $this->data['pageLanguage'] =
176 $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
177 $this->text( 'pageLanguage' );
178 ?>"><span dir
="auto"><?php
$this->html( 'title' ) ?
></span
></h1
>
179 <?php
$this->html( 'prebodyhtml' ) ?
>
180 <div id
="bodyContent" class="mw-body-content">
182 if ( $this->data
['isarticle'] ) {
184 <div id
="siteSub"><?php
$this->msg( 'tagline' ) ?
></div
>
188 <div id
="contentSub"<?php
189 $this->html( 'userlangattributes' )
190 ?
>><?php
$this->html( 'subtitle' ) ?
></div
>
192 if ( $this->data
['undelete'] ) {
194 <div id
="contentSub2"><?php
$this->html( 'undelete' ) ?
></div
>
199 if ( $this->data
['newtalk'] ) {
201 <div
class="usermessage"><?php
$this->html( 'newtalk' ) ?
></div
>
205 <div id
="jump-to-nav" class="mw-jump">
206 <?php
$this->msg( 'jumpto' ) ?
>
207 <a href
="#mw-navigation"><?php
208 $this->msg( 'jumptonavigation' )
210 $this->msg( 'comma-separator' )
212 <a href
="#p-search"><?php
$this->msg( 'jumptosearch' ) ?
></a
>
214 <?php
$this->html( 'bodycontent' ) ?
>
216 if ( $this->data
['printfooter'] ) {
218 <div
class="printfooter">
219 <?php
$this->html( 'printfooter' ); ?
>
225 if ( $this->data
['catlinks'] ) {
228 $this->html( 'catlinks' );
234 if ( $this->data
['dataAfterContent'] ) {
237 $this->html( 'dataAfterContent' );
242 <div
class="visualClear"></div
>
243 <?php
$this->html( 'debughtml' ); ?
>
246 <div id
="mw-navigation">
247 <h2
><?php
$this->msg( 'navigation-heading' ) ?
></h2
>
250 <?php
$this->renderNavigation( 'PERSONAL' ); ?
>
251 <div id
="left-navigation">
252 <?php
$this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?
>
254 <div id
="right-navigation">
255 <?php
$this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?
>
259 <div id
="p-logo" role
="banner"><a style
="background-image: url(<?php
260 $this->text( 'logopath' )
262 echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] )
264 echo Xml
::expandAttributes( Linker
::tooltipAndAccesskeyAttribs( 'p-logo' ) )
266 <?php
$this->renderPortals( $this->data
['sidebar'] ); ?
>
269 <div id
="footer" role
="contentinfo"<?php
$this->html( 'userlangattributes' ) ?
>>
271 foreach ( $this->getFooterLinks() as $category => $links ) {
277 foreach ( $links as $link ) {
293 <?php
$footericons = $this->getFooterIcons( "icononly" );
294 if ( count( $footericons ) > 0 ) {
296 <ul id
="footer-icons" class="noprint">
298 foreach ( $footericons as $blockName => $footerIcons ) {
301 echo htmlspecialchars( $blockName ); ?>ico">
303 foreach ( $footerIcons as $icon ) {
306 echo $this->getSkin()->makeFooterIcon( $icon );
320 <div style
="clear:both"></div
>
322 <?php
$this->printTrail(); ?
>
330 * Render a series of portals
332 * @param array $portals
334 protected function renderPortals( $portals ) {
335 // Force the rendering of the following portals
336 if ( !isset( $portals['SEARCH'] ) ) {
337 $portals['SEARCH'] = true;
339 if ( !isset( $portals['TOOLBOX'] ) ) {
340 $portals['TOOLBOX'] = true;
342 if ( !isset( $portals['LANGUAGES'] ) ) {
343 $portals['LANGUAGES'] = true;
346 foreach ( $portals as $name => $content ) {
347 if ( $content === false ) {
355 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
358 if ( $this->data
['language_urls'] !== false ) {
359 $this->renderPortal( 'lang', $this->data
['language_urls'], 'otherlanguages' );
363 $this->renderPortal( $name, $content );
370 * @param string $name
371 * @param array $content
372 * @param null|string $msg
373 * @param null|string|array $hook
375 protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
376 if ( $msg === null ) {
379 $msgObj = wfMessage( $msg );
381 <div
class="portal" role
="navigation" id
='<?php
382 echo Sanitizer::escapeId( "p-$name" )
384 echo Linker
::tooltip( 'p-' . $name )
385 ?
> aria
-labelledby
='<?php echo Sanitizer::escapeId( "p-$name-label" ) ?>'>
387 $this->html( 'userlangattributes' )
389 echo Sanitizer::escapeId( "p-$name-label" )
391 echo htmlspecialchars( $msgObj->exists() ?
$msgObj->text() : $msg );
396 if ( is_array( $content ) ) {
400 foreach ( $content as $key => $val ) {
402 <?php
echo $this->makeListItem( $key, $val ); ?
>
406 if ( $hook !== null ) {
407 wfRunHooks( $hook, array( &$this, true ) );
415 echo $content; /* Allow raw HTML block to be defined by extensions */
418 $this->renderAfterPortlet( $name );
426 * Render one or more navigations elements by name, automatically reveresed
427 * when UI is in RTL mode
429 * @param array $elements
431 protected function renderNavigation( $elements ) {
432 global $wgVectorUseSimpleSearch;
434 // If only one element was given, wrap it in an array, allowing more
435 // flexible arguments
436 if ( !is_array( $elements ) ) {
437 $elements = array( $elements );
438 // If there's a series of elements, reverse them when in RTL mode
439 } elseif ( $this->data
['rtl'] ) {
440 $elements = array_reverse( $elements );
443 foreach ( $elements as $name => $element ) {
444 switch ( $element ) {
447 <div id
="p-namespaces" role
="navigation" class="vectorTabs<?php
448 if ( count( $this->data['namespace_urls'] ) == 0 ) {
449 echo ' emptyPortlet';
451 ?>" aria
-labelledby
="p-namespaces-label">
452 <h3 id
="p-namespaces-label"><?php
$this->msg( 'namespaces' ) ?
></h3
>
453 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
455 foreach ( $this->data
['namespace_urls'] as $link ) {
458 echo $link['attributes']
459 ?
>><span
><a href
="<?php
460 echo htmlspecialchars( $link['href'] )
464 echo htmlspecialchars( $link['text'] )
475 <div id
="p-variants" role
="navigation" class="vectorMenu<?php
476 if ( count( $this->data['variant_urls'] ) == 0 ) {
477 echo ' emptyPortlet';
479 ?>" aria
-labelledby
="p-variants-label">
480 <h3 id
="mw-vector-current-variant">
482 foreach ( $this->data
['variant_urls'] as $link ) {
485 if ( stripos( $link['attributes'], 'selected' ) !== false ) {
488 echo htmlspecialchars( $link['text'] )
498 <h3 id
="p-variants-label"><span
><?php
$this->msg( 'variants' ) ?
></span
><a href
="#"></a
></h3
>
503 foreach ( $this->data
['variant_urls'] as $link ) {
506 echo $link['attributes']
508 echo htmlspecialchars( $link['href'] )
510 echo htmlspecialchars( $link['lang'] )
512 echo htmlspecialchars( $link['hreflang'] )
516 echo htmlspecialchars( $link['text'] )
528 <div id
="p-views" role
="navigation" class="vectorTabs<?php
529 if ( count( $this->data['view_urls'] ) == 0 ) {
530 echo ' emptyPortlet';
532 ?>" aria
-labelledby
="p-views-label">
533 <h3 id
="p-views-label"><?php
$this->msg( 'views' ) ?
></h3
>
535 $this->html( 'userlangattributes' )
538 foreach ( $this->data
['view_urls'] as $link ) {
541 echo $link['attributes']
542 ?
>><span
><a href
="<?php
543 echo htmlspecialchars( $link['href'] )
547 // $link['text'] can be undefined - bug 27764
548 if ( array_key_exists( 'text', $link ) ) {
549 echo array_key_exists( 'img', $link )
550 ?
'<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />'
551 : htmlspecialchars( $link['text'] );
563 <div id
="p-cactions" role
="navigation" class="vectorMenu<?php
564 if ( count( $this->data['action_urls'] ) == 0 ) {
565 echo ' emptyPortlet';
567 ?>" aria
-labelledby
="p-cactions-label">
568 <h3 id
="p-cactions-label"><span
><?php
$this->msg( 'actions' ) ?
></span
><a href
="#"></a
></h3
>
571 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
573 foreach ( $this->data
['action_urls'] as $link ) {
576 echo $link['attributes']
579 echo htmlspecialchars( $link['href'] )
581 echo $link['key'] ?
>><?php
echo htmlspecialchars( $link['text'] )
594 <div id
="p-personal" role
="navigation" class="<?php
595 if ( count( $this->data['personal_urls'] ) == 0 ) {
596 echo ' emptyPortlet';
598 ?>" aria
-labelledby
="p-personal-label">
599 <h3 id
="p-personal-label"><?php
$this->msg( 'personaltools' ) ?
></h3
>
600 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
602 $personalTools = $this->getPersonalTools();
603 foreach ( $personalTools as $key => $item ) {
604 echo $this->makeListItem( $key, $item );
613 <div id
="p-search" role
="search">
614 <h3
<?php
$this->html( 'userlangattributes' ) ?
>>
615 <label
for="searchInput"><?php
$this->msg( 'search' ) ?
></label
>
618 <form action
="<?php $this->text( 'wgScript' ) ?>" id
="searchform">
620 if ($wgVectorUseSimpleSearch) {
622 <div id
="simpleSearch">
631 echo $this->makeSearchInput( array( 'id' => 'searchInput' ) );
632 echo Html
::hidden( 'title', $this->get( 'searchtitle' ) );
633 // We construct two buttons (for 'go' and 'fulltext' search modes),
634 // but only one will be visible and actionable at a time (they are
635 // overlaid on top of each other in CSS).
636 // * Browsers will use the 'fulltext' one by default (as it's the
637 // first in tree-order), which is desirable when they are unable
638 // to show search suggestions (either due to being broken or
639 // having JavaScript turned off).
640 // * The mediawiki.searchSuggest module, after doing tests for the
641 // broken browsers, removes the 'fulltext' button and handles
642 // 'fulltext' search itself; this will reveal the 'go' button and
643 // cause it to be used.
644 echo $this->makeSearchButton(
646 array( 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' )
648 echo $this->makeSearchButton(
650 array( 'id' => 'searchButton', 'class' => 'searchButton' )