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
{
36 protected static $bodyClasses = array( 'vector-animateLayout' );
38 var $skinname = 'vector', $stylename = 'vector',
39 $template = 'VectorTemplate', $useHeadElement = true;
42 * Initializes output page and sets up skin-specific parameters
43 * @param $out OutputPage 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', 'skins.vector.collapsibleNav' ) );
64 * Loads skin and user CSS files.
65 * @param $out OutputPage object
67 function setupSkinUserCss( OutputPage
$out ) {
68 parent
::setupSkinUserCss( $out );
70 $styles = array( 'skins.common.interface', 'skins.vector.styles' );
71 wfRunHooks( 'SkinVectorStyleModules', array( $this, &$styles ) );
72 $out->addModuleStyles( $styles );
76 * Adds classes to the body element.
78 * @param $out OutputPage object
79 * @param &$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
{
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() ) ?
'unwatch' : 'watch';
109 if ( isset( $nav['actions'][$mode] ) ) {
110 $nav['views'][$mode] = $nav['actions'][$mode];
111 $nav['views'][$mode]['class'] = rtrim( 'icon ' . $nav['views'][$mode]['class'], ' ' );
112 $nav['views'][$mode]['primary'] = true;
113 unset( $nav['actions'][$mode] );
118 foreach ( $nav as $section => $links ) {
119 foreach ( $links as $key => $link ) {
120 if ( $section == 'views' && !( isset( $link['primary'] ) && $link['primary'] ) ) {
121 $link['class'] = rtrim( 'collapsible ' . $link['class'], ' ' );
124 $xmlID = isset( $link['id'] ) ?
$link['id'] : 'ca-' . $xmlID;
125 $nav[$section][$key]['attributes'] =
126 ' id="' . Sanitizer
::escapeId( $xmlID ) . '"';
127 if ( $link['class'] ) {
128 $nav[$section][$key]['attributes'] .=
129 ' class="' . htmlspecialchars( $link['class'] ) . '"';
130 unset( $nav[$section][$key]['class'] );
132 if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
133 $nav[$section][$key]['key'] =
134 Linker
::tooltip( $xmlID );
136 $nav[$section][$key]['key'] =
137 Xml
::expandAttributes( Linker
::tooltipAndAccesskeyAttribs( $xmlID ) );
141 $this->data
['namespace_urls'] = $nav['namespaces'];
142 $this->data
['view_urls'] = $nav['views'];
143 $this->data
['action_urls'] = $nav['actions'];
144 $this->data
['variant_urls'] = $nav['variants'];
146 // Reverse horizontally rendered navigation elements
147 if ( $this->data
['rtl'] ) {
148 $this->data
['view_urls'] =
149 array_reverse( $this->data
['view_urls'] );
150 $this->data
['namespace_urls'] =
151 array_reverse( $this->data
['namespace_urls'] );
152 $this->data
['personal_urls'] =
153 array_reverse( $this->data
['personal_urls'] );
156 $this->html( 'headelement' );
158 <div id
="mw-page-base" class="noprint"></div
>
159 <div id
="mw-head-base" class="noprint"></div
>
160 <div id
="content" class="mw-body" role
="main">
162 <div id
="mw-js-message" style
="display:none;"<?php
$this->html( 'userlangattributes' ) ?
>></div
>
163 <?php
if ( $this->data
['sitenotice'] ) { ?
>
164 <div id
="siteNotice"><?php
$this->html( 'sitenotice' ) ?
></div
>
166 <h1 id
="firstHeading" class="firstHeading" lang
="<?php
167 $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
168 $this->text( 'pageLanguage' );
169 ?>"><span dir
="auto"><?php
$this->html( 'title' ) ?
></span
></h1
>
170 <?php
$this->html( 'prebodyhtml' ) ?
>
171 <div id
="bodyContent">
172 <?php
if ( $this->data
['isarticle'] ) { ?
>
173 <div id
="siteSub"><?php
$this->msg( 'tagline' ) ?
></div
>
175 <div id
="contentSub"<?php
$this->html( 'userlangattributes' ) ?
>><?php
$this->html( 'subtitle' ) ?
></div
>
176 <?php
if ( $this->data
['undelete'] ) { ?
>
177 <div id
="contentSub2"><?php
$this->html( 'undelete' ) ?
></div
>
179 <?php
if ( $this->data
['newtalk'] ) { ?
>
180 <div
class="usermessage"><?php
$this->html( 'newtalk' ) ?
></div
>
182 <div id
="jump-to-nav" class="mw-jump">
183 <?php
$this->msg( 'jumpto' ) ?
>
184 <a href
="#mw-navigation"><?php
$this->msg( 'jumptonavigation' ) ?
></a
><?php
$this->msg( 'comma-separator' ) ?
>
185 <a href
="#p-search"><?php
$this->msg( 'jumptosearch' ) ?
></a
>
187 <?php
$this->html( 'bodycontent' ) ?
>
188 <?php
if ( $this->data
['printfooter'] ) { ?
>
189 <div
class="printfooter">
190 <?php
$this->html( 'printfooter' ); ?
>
193 <?php
if ( $this->data
['catlinks'] ) { ?
>
194 <?php
$this->html( 'catlinks' ); ?
>
196 <?php
if ( $this->data
['dataAfterContent'] ) { ?
>
197 <?php
$this->html( 'dataAfterContent' ); ?
>
199 <div
class="visualClear"></div
>
200 <?php
$this->html( 'debughtml' ); ?
>
203 <div id
="mw-navigation">
204 <h2
><?php
$this->msg( 'navigation-heading' ) ?
></h2
>
206 <?php
$this->renderNavigation( 'PERSONAL' ); ?
>
207 <div id
="left-navigation">
208 <?php
$this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?
>
210 <div id
="right-navigation">
211 <?php
$this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?
>
215 <div id
="p-logo" role
="banner"><a style
="background-image: url(<?php $this->text( 'logopath' ) ?>);" href
="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>" <?php
echo Xml
::expandAttributes( Linker
::tooltipAndAccesskeyAttribs( 'p-logo' ) ) ?
>></a
></div
>
216 <?php
$this->renderPortals( $this->data
['sidebar'] ); ?
>
219 <div id
="footer" role
="contentinfo"<?php
$this->html( 'userlangattributes' ) ?
>>
220 <?php
foreach ( $this->getFooterLinks() as $category => $links ) { ?
>
221 <ul id
="footer-<?php echo $category ?>">
222 <?php
foreach ( $links as $link ) { ?
>
223 <li id
="footer-<?php echo $category ?>-<?php echo $link ?>"><?php
$this->html( $link ) ?
></li
>
227 <?php
$footericons = $this->getFooterIcons( "icononly" );
228 if ( count( $footericons ) > 0 ) { ?
>
229 <ul id
="footer-icons" class="noprint">
230 <?php
foreach ( $footericons as $blockName => $footerIcons ) { ?
>
231 <li id
="footer-<?php echo htmlspecialchars( $blockName ); ?>ico">
232 <?php
foreach ( $footerIcons as $icon ) { ?
>
233 <?php
echo $this->getSkin()->makeFooterIcon( $icon ); ?
>
240 <div style
="clear:both"></div
>
242 <?php
$this->printTrail(); ?
>
250 * Render a series of portals
252 * @param $portals array
254 protected function renderPortals( $portals ) {
255 // Force the rendering of the following portals
256 if ( !isset( $portals['SEARCH'] ) ) {
257 $portals['SEARCH'] = true;
259 if ( !isset( $portals['TOOLBOX'] ) ) {
260 $portals['TOOLBOX'] = true;
262 if ( !isset( $portals['LANGUAGES'] ) ) {
263 $portals['LANGUAGES'] = true;
266 foreach ( $portals as $name => $content ) {
267 if ( $content === false ) {
275 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
278 if ( $this->data
['language_urls'] !== false ) {
279 $this->renderPortal( 'lang', $this->data
['language_urls'], 'otherlanguages' );
283 $this->renderPortal( $name, $content );
290 * @param $name string
291 * @param $content array
292 * @param $msg null|string
293 * @param $hook null|string|array
295 protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
296 if ( $msg === null ) {
299 $msgObj = wfMessage( $msg );
301 <div
class="portal" role
="navigation" id
='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php
echo Linker
::tooltip( 'p-' . $name ) ?
> aria
-labelledby
='<?php echo Sanitizer::escapeId( "p-$name-label" ) ?>'>
302 <h3
<?php
$this->html( 'userlangattributes' ) ?
> id
='<?php echo Sanitizer::escapeId( "p-$name-label" ) ?>'><?php
echo htmlspecialchars( $msgObj->exists() ?
$msgObj->text() : $msg ); ?
></h3
>
305 if ( is_array( $content ) ) { ?
>
308 foreach ( $content as $key => $val ) { ?
>
309 <?php
echo $this->makeListItem( $key, $val ); ?
>
313 if ( $hook !== null ) {
314 wfRunHooks( $hook, array( &$this, true ) );
321 echo $content; /* Allow raw HTML block to be defined by extensions */
324 $this->renderAfterPortlet( $name );
332 * Render one or more navigations elements by name, automatically reveresed
333 * when UI is in RTL mode
335 * @param $elements array
337 protected function renderNavigation( $elements ) {
338 global $wgVectorUseSimpleSearch;
340 // If only one element was given, wrap it in an array, allowing more
341 // flexible arguments
342 if ( !is_array( $elements ) ) {
343 $elements = array( $elements );
344 // If there's a series of elements, reverse them when in RTL mode
345 } elseif ( $this->data
['rtl'] ) {
346 $elements = array_reverse( $elements );
349 foreach ( $elements as $name => $element ) {
350 switch ( $element ) {
353 <div id
="p-namespaces" role
="navigation" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria
-labelledby
="p-namespaces-label">
354 <h3 id
="p-namespaces-label"><?php
$this->msg( 'namespaces' ) ?
></h3
>
355 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
356 <?php
foreach ( $this->data
['namespace_urls'] as $link ) { ?
>
357 <li
<?php
echo $link['attributes'] ?
>><span
><a href
="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php
echo $link['key'] ?
>><?php
echo htmlspecialchars( $link['text'] ) ?
></a
></span
></li
>
365 <div id
="p-variants" role
="navigation" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria
-labelledby
="p-variants-label">
366 <h3 id
="mw-vector-current-variant">
367 <?php
foreach ( $this->data
['variant_urls'] as $link ) { ?
>
368 <?php
if ( stripos( $link['attributes'], 'selected' ) !== false ) { ?
>
369 <?php
echo htmlspecialchars( $link['text'] ) ?
>
373 <h3 id
="p-variants-label"><span
><?php
$this->msg( 'variants' ) ?
></span
><a href
="#"></a
></h3
>
376 <?php
foreach ( $this->data
['variant_urls'] as $link ) { ?
>
377 <li
<?php
echo $link['attributes'] ?
>><a href
="<?php echo htmlspecialchars( $link['href'] ) ?>" lang
="<?php echo htmlspecialchars( $link['lang'] ) ?>" hreflang
="<?php echo htmlspecialchars( $link['hreflang'] ) ?>" <?php
echo $link['key'] ?
>><?php
echo htmlspecialchars( $link['text'] ) ?
></a
></li
>
386 <div id
="p-views" role
="navigation" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria
-labelledby
="p-views-label">
387 <h3 id
="p-views-label"><?php
$this->msg( 'views' ) ?
></h3
>
388 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
389 <?php
foreach ( $this->data
['view_urls'] as $link ) { ?
>
390 <li
<?php
echo $link['attributes'] ?
>><span
><a href
="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php
echo $link['key'] ?
>><?php
391 // $link['text'] can be undefined - bug 27764
392 if ( array_key_exists( 'text', $link ) ) {
393 echo array_key_exists( 'img', $link ) ?
'<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />' : htmlspecialchars( $link['text'] );
403 <div id
="p-cactions" role
="navigation" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria
-labelledby
="p-cactions-label">
404 <h3 id
="p-cactions-label"><span
><?php
$this->msg( 'actions' ) ?
></span
><a href
="#"></a
></h3
>
406 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
407 <?php
foreach ( $this->data
['action_urls'] as $link ) { ?
>
408 <li
<?php
echo $link['attributes'] ?
>><a href
="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php
echo $link['key'] ?
>><?php
echo htmlspecialchars( $link['text'] ) ?
></a
></li
>
417 <div id
="p-personal" role
="navigation" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria
-labelledby
="p-personal-label">
418 <h3 id
="p-personal-label"><?php
$this->msg( 'personaltools' ) ?
></h3
>
419 <ul
<?php
$this->html( 'userlangattributes' ) ?
>>
421 $personalTools = $this->getPersonalTools();
422 foreach ( $personalTools as $key => $item ) {
423 echo $this->makeListItem( $key, $item );
432 <div id
="p-search" role
="search">
433 <h3
<?php
$this->html( 'userlangattributes' ) ?
>><label
for="searchInput"><?php
$this->msg( 'search' ) ?
></label
></h3
>
434 <form action
="<?php $this->text( 'wgScript' ) ?>" id
="searchform">
435 <?php
if ( $wgVectorUseSimpleSearch ) { ?
>
436 <div id
="simpleSearch">
441 echo $this->makeSearchInput( array( 'id' => 'searchInput' ) );
442 echo Html
::hidden( 'title', $this->get( 'searchtitle' ) );
443 // We construct two buttons (for 'go' and 'fulltext' search modes), but only one will be
444 // visible and actionable at a time (they are overlaid on top of each other in CSS).
445 // * Browsers will use the 'fulltext' one by default (as it's the first in tree-order), which
446 // is desirable when they are unable to show search suggestions (either due to being broken
447 // or having JavaScript turned off).
448 // * The mediawiki.searchSuggest module, after doing tests for the broken browsers, removes
449 // the 'fulltext' button and handles 'fulltext' search itself; this will reveal the 'go'
450 // button and cause it to be used.
451 echo $this->makeSearchButton( 'fulltext', array( 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' ) );
452 echo $this->makeSearchButton( 'go', array( 'id' => 'searchButton', 'class' => 'searchButton' ) );