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 $skinname = 'vector';
36 public $stylename = 'vector';
37 public $template = 'VectorTemplate';
39 protected static $bodyClasses = array( 'vector-animateLayout' );
42 * Initializes output page and sets up skin-specific parameters
43 * @param OutputPage $out Object to initialize
45 public function initPage( OutputPage
$out ) {
46 global $wgLocalStylePath;
48 parent
::initPage( $out );
50 // Append CSS which includes IE only behavior fixes for hover support -
51 // this is better than including this in a CSS file since it doesn't
52 // wait for the CSS file to load before fetching the HTC file.
53 $min = $this->getRequest()->getFuzzyBool( 'debug' ) ?
'' : '.min';
54 $out->addHeadItem( 'csshover',
55 '<!--[if lt IE 7]><style type="text/css">body{behavior:url("' .
56 htmlspecialchars( $wgLocalStylePath ) .
57 "/{$this->stylename}/csshover{$min}.htc\")}</style><![endif]-->"
60 $out->addModules( array( 'skins.vector.js' ) );
64 * Loads skin and user CSS files.
65 * @param OutputPage $out
67 function setupSkinUserCss( OutputPage
$out ) {
68 parent
::setupSkinUserCss( $out );
70 $styles = array( 'mediawiki.skinning.interface', 'skins.vector.styles' );
71 wfRunHooks( 'SkinVectorStyleModules', array( $this, &$styles ) );
72 $out->addModuleStyles( $styles );
76 * Adds classes to the body element.
78 * @param OutputPage $out
79 * @param array &$bodyAttrs Array of attributes that will be set on the body element
81 function addToBodyAttributes( $out, &$bodyAttrs ) {
82 if ( isset( $bodyAttrs['class'] ) && strlen( $bodyAttrs['class'] ) > 0 ) {
83 $bodyAttrs['class'] .= ' ' . implode( ' ', static::$bodyClasses );
85 $bodyAttrs['class'] = implode( ' ', static::$bodyClasses );
91 * QuickTemplate class for Vector skin
94 class VectorTemplate
extends BaseTemplate
{
98 * Outputs the entire contents of the (X)HTML page
100 public function execute() {
101 global $wgVectorUseIconWatch;
103 // Build additional attributes for navigation urls
104 $nav = $this->data
['content_navigation'];
106 if ( $wgVectorUseIconWatch ) {
107 $mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() )
111 if ( isset( $nav['actions'][$mode] ) ) {
112 $nav['views'][$mode] = $nav['actions'][$mode];
113 $nav['views'][$mode]['class'] = rtrim( 'icon ' . $nav['views'][$mode]['class'], ' ' );
114 $nav['views'][$mode]['primary'] = true;
115 unset( $nav['actions'][$mode] );
120 foreach ( $nav as $section => $links ) {
121 foreach ( $links as $key => $link ) {
122 if ( $section == 'views' && !( isset( $link['primary'] ) && $link['primary'] ) ) {
123 $link['class'] = rtrim( 'collapsible ' . $link['class'], ' ' );
126 $xmlID = isset( $link['id'] ) ?
$link['id'] : 'ca-' . $xmlID;
127 $nav[$section][$key]['attributes'] =
128 ' id="' . Sanitizer
::escapeId( $xmlID ) . '"';
129 if ( $link['class'] ) {
130 $nav[$section][$key]['attributes'] .=
131 ' class="' . htmlspecialchars( $link['class'] ) . '"';
132 unset( $nav[$section][$key]['class'] );
134 if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
135 $nav[$section][$key]['key'] =
136 Linker
::tooltip( $xmlID );
138 $nav[$section][$key]['key'] =
139 Xml
::expandAttributes( Linker
::tooltipAndAccesskeyAttribs( $xmlID ) );
143 $this->data
['namespace_urls'] = $nav['namespaces'];
144 $this->data
['view_urls'] = $nav['views'];
145 $this->data
['action_urls'] = $nav['actions'];
146 $this->data
['variant_urls'] = $nav['variants'];
148 // Reverse horizontally rendered navigation elements
149 if ( $this->data
['rtl'] ) {
150 $this->data
['view_urls'] =
151 array_reverse( $this->data
['view_urls'] );
152 $this->data
['namespace_urls'] =
153 array_reverse( $this->data
['namespace_urls'] );
154 $this->data
['personal_urls'] =
155 array_reverse( $this->data
['personal_urls'] );
158 $this->html( 'headelement' );
160 <div id
="mw-page-base" class="noprint"></div
>
161 <div id
="mw-head-base" class="noprint"></div
>
162 <div id
="content" class="mw-body" role
="main">
166 if ( $this->data
['sitenotice'] ) {
168 <div id
="siteNotice"><?php
$this->html( 'sitenotice' ) ?
></div
>
172 <h1 id
="firstHeading" class="firstHeading" lang
="<?php
173 $this->data['pageLanguage'] =
174 $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
175 $this->text( 'pageLanguage' );
176 ?>"><span dir
="auto"><?php
$this->html( 'title' ) ?
></span
></h1
>
177 <?php
$this->html( 'prebodyhtml' ) ?
>
178 <div id
="bodyContent" class="mw-body-content">
180 if ( $this->data
['isarticle'] ) {
182 <div id
="siteSub"><?php
$this->msg( 'tagline' ) ?
></div
>
186 <div id
="contentSub"<?php
187 $this->html( 'userlangattributes' )
188 ?
>><?php
$this->html( 'subtitle' ) ?
></div
>
190 if ( $this->data
['undelete'] ) {
192 <div id
="contentSub2"><?php
$this->html( 'undelete' ) ?
></div
>
197 if ( $this->data
['newtalk'] ) {
199 <div
class="usermessage"><?php
$this->html( 'newtalk' ) ?
></div
>
203 <div id
="jump-to-nav" class="mw-jump">
204 <?php
$this->msg( 'jumpto' ) ?
>
205 <a href
="#mw-navigation"><?php
206 $this->msg( 'jumptonavigation' )
208 $this->msg( 'comma-separator' )
210 <a href
="#p-search"><?php
$this->msg( 'jumptosearch' ) ?
></a
>
212 <?php
$this->html( 'bodycontent' ) ?
>
214 if ( $this->data
['printfooter'] ) {
216 <div
class="printfooter">
217 <?php
$this->html( 'printfooter' ); ?
>
223 if ( $this->data
['catlinks'] ) {
226 $this->html( 'catlinks' );
232 if ( $this->data
['dataAfterContent'] ) {
235 $this->html( 'dataAfterContent' );
240 <div
class="visualClear"></div
>
241 <?php
$this->html( 'debughtml' ); ?
>
244 <div id
="mw-navigation">
245 <h2
><?php
$this->msg( 'navigation-heading' ) ?
></h2
>
248 <?php
$this->renderNavigation( 'PERSONAL' ); ?
>
249 <div id
="left-navigation">
250 <?php
$this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?
>
252 <div id
="right-navigation">
253 <?php
$this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?
>
257 <div id
="p-logo" role
="banner"><a style
="background-image: url(<?php
258 $this->text( 'logopath' )
260 echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] )
262 echo Xml
::expandAttributes( Linker
::tooltipAndAccesskeyAttribs( 'p-logo' ) )
264 <?php
$this->renderPortals( $this->data
['sidebar'] ); ?
>
267 <div id
="footer" role
="contentinfo"<?php
$this->html( 'userlangattributes' ) ?
>>
269 foreach ( $this->getFooterLinks() as $category => $links ) {
275 foreach ( $links as $link ) {
291 <?php
$footericons = $this->getFooterIcons( "icononly" );
292 if ( count( $footericons ) > 0 ) {
294 <ul id
="footer-icons" class="noprint">
296 foreach ( $footericons as $blockName => $footerIcons ) {
299 echo htmlspecialchars( $blockName ); ?>ico">
301 foreach ( $footerIcons as $icon ) {
304 echo $this->getSkin()->makeFooterIcon( $icon );
318 <div style
="clear:both"></div
>
320 <?php
$this->printTrail(); ?
>
328 * Render a series of portals
330 * @param array $portals
332 protected function renderPortals( $portals ) {
333 // Force the rendering of the following portals
334 if ( !isset( $portals['SEARCH'] ) ) {
335 $portals['SEARCH'] = true;
337 if ( !isset( $portals['TOOLBOX'] ) ) {
338 $portals['TOOLBOX'] = true;
340 if ( !isset( $portals['LANGUAGES'] ) ) {
341 $portals['LANGUAGES'] = true;
344 foreach ( $portals as $name => $content ) {
345 if ( $content === false ) {
353 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
356 if ( $this->data
['language_urls'] !== false ) {
357 $this->renderPortal( 'lang', $this->data
['language_urls'], 'otherlanguages' );
361 $this->renderPortal( $name, $content );
368 * @param string $name
369 * @param array $content
370 * @param null|string $msg
371 * @param null|string|array $hook
373 protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
374 if ( $msg === null ) {
377 $msgObj = wfMessage( $msg );
379 <div
class="portal" role
="navigation" id
='<?php
380 echo Sanitizer::escapeId( "p-$name" )
382 echo Linker
::tooltip( 'p-' . $name )
383 ?
> aria
-labelledby
='<?php echo Sanitizer::escapeId( "p-$name-label" ) ?>'>
385 $this->html( 'userlangattributes' )
387 echo Sanitizer::escapeId( "p-$name-label" )
389 echo htmlspecialchars( $msgObj->exists() ?
$msgObj->text() : $msg );
394 if ( is_array( $content ) ) {
398 foreach ( $content as $key => $val ) {
400 <?php
echo $this->makeListItem( $key, $val ); ?
>
404 if ( $hook !== null ) {
405 wfRunHooks( $hook, array( &$this, true ) );
413 echo $content; /* Allow raw HTML block to be defined by extensions */
416 $this->renderAfterPortlet( $name );
424 * Render one or more navigations elements by name, automatically reveresed
425 * when UI is in RTL mode
427 * @param array $elements
429 protected function renderNavigation( $elements ) {
430 global $wgVectorUseSimpleSearch;
432 // If only one element was given, wrap it in an array, allowing more
433 // flexible arguments
434 if ( !is_array( $elements ) ) {
435 $elements = array( $elements );
436 // If there's a series of elements, reverse them when in RTL mode
437 } elseif ( $this->data
['rtl'] ) {
438 $elements = array_reverse( $elements );
441 foreach ( $elements as $name => $element ) {
442 switch ( $element ) {
445 <div id
="p-namespaces" role
="navigation" class="vectorTabs<?php
446 if ( count( $this->data['namespace_urls'] ) == 0 ) {
447 echo ' emptyPortlet';
449 ?>" aria
-labelledby
="p-namespaces-label">
450 <h3 id
="p-namespaces-label"><?php
$this->msg( 'namespaces' ) ?
></h3
>
451 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
453 foreach ( $this->data
['namespace_urls'] as $link ) {
456 echo $link['attributes']
457 ?
>><span
><a href
="<?php
458 echo htmlspecialchars( $link['href'] )
462 echo htmlspecialchars( $link['text'] )
473 <div id
="p-variants" role
="navigation" class="vectorMenu<?php
474 if ( count( $this->data['variant_urls'] ) == 0 ) {
475 echo ' emptyPortlet';
477 ?>" aria
-labelledby
="p-variants-label">
478 <h3 id
="mw-vector-current-variant">
480 foreach ( $this->data
['variant_urls'] as $link ) {
483 if ( stripos( $link['attributes'], 'selected' ) !== false ) {
486 echo htmlspecialchars( $link['text'] )
496 <h3 id
="p-variants-label"><span
><?php
$this->msg( 'variants' ) ?
></span
><a href
="#"></a
></h3
>
501 foreach ( $this->data
['variant_urls'] as $link ) {
504 echo $link['attributes']
506 echo htmlspecialchars( $link['href'] )
508 echo htmlspecialchars( $link['lang'] )
510 echo htmlspecialchars( $link['hreflang'] )
514 echo htmlspecialchars( $link['text'] )
526 <div id
="p-views" role
="navigation" class="vectorTabs<?php
527 if ( count( $this->data['view_urls'] ) == 0 ) {
528 echo ' emptyPortlet';
530 ?>" aria
-labelledby
="p-views-label">
531 <h3 id
="p-views-label"><?php
$this->msg( 'views' ) ?
></h3
>
533 $this->html( 'userlangattributes' )
536 foreach ( $this->data
['view_urls'] as $link ) {
539 echo $link['attributes']
540 ?
>><span
><a href
="<?php
541 echo htmlspecialchars( $link['href'] )
545 // $link['text'] can be undefined - bug 27764
546 if ( array_key_exists( 'text', $link ) ) {
547 echo array_key_exists( 'img', $link )
548 ?
'<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />'
549 : htmlspecialchars( $link['text'] );
561 <div id
="p-cactions" role
="navigation" class="vectorMenu<?php
562 if ( count( $this->data['action_urls'] ) == 0 ) {
563 echo ' emptyPortlet';
565 ?>" aria
-labelledby
="p-cactions-label">
566 <h3 id
="p-cactions-label"><span
><?php
$this->msg( 'vector-more-actions' ) ?
></span
><a href
="#"></a
></h3
>
569 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
571 foreach ( $this->data
['action_urls'] as $link ) {
574 echo $link['attributes']
577 echo htmlspecialchars( $link['href'] )
579 echo $link['key'] ?
>><?php
echo htmlspecialchars( $link['text'] )
592 <div id
="p-personal" role
="navigation" class="<?php
593 if ( count( $this->data['personal_urls'] ) == 0 ) {
594 echo ' emptyPortlet';
596 ?>" aria
-labelledby
="p-personal-label">
597 <h3 id
="p-personal-label"><?php
$this->msg( 'personaltools' ) ?
></h3
>
598 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
600 $personalTools = $this->getPersonalTools();
601 foreach ( $personalTools as $key => $item ) {
602 echo $this->makeListItem( $key, $item );
611 <div id
="p-search" role
="search">
612 <h3
<?php
$this->html( 'userlangattributes' ) ?
>>
613 <label
for="searchInput"><?php
$this->msg( 'search' ) ?
></label
>
616 <form action
="<?php $this->text( 'wgScript' ) ?>" id
="searchform">
618 if ($wgVectorUseSimpleSearch) {
620 <div id
="simpleSearch">
629 echo $this->makeSearchInput( array( 'id' => 'searchInput' ) );
630 echo Html
::hidden( 'title', $this->get( 'searchtitle' ) );
631 // We construct two buttons (for 'go' and 'fulltext' search modes),
632 // but only one will be visible and actionable at a time (they are
633 // overlaid on top of each other in CSS).
634 // * Browsers will use the 'fulltext' one by default (as it's the
635 // first in tree-order), which is desirable when they are unable
636 // to show search suggestions (either due to being broken or
637 // having JavaScript turned off).
638 // * The mediawiki.searchSuggest module, after doing tests for the
639 // broken browsers, removes the 'fulltext' button and handles
640 // 'fulltext' search itself; this will reveal the 'go' button and
641 // cause it to be used.
642 echo $this->makeSearchButton(
644 array( 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' )
646 echo $this->makeSearchButton(
648 array( 'id' => 'searchButton', 'class' => 'searchButton' )