e412c9ce59c33b43f7598d0c2d5b7efb5db04705
[lhc/web/wiklou.git] / skins / Vector.php
1 <?php
2 /**
3 * Vector - Modern version of MonoBook with fresh look and many usability
4 * improvements.
5 *
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.
10 *
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.
15 *
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
20 *
21 * @todo document
22 * @file
23 * @ingroup Skins
24 */
25
26 if ( !defined( 'MEDIAWIKI' ) ) {
27 die( -1 );
28 }
29
30 /**
31 * SkinTemplate class for Vector skin
32 * @ingroup Skins
33 */
34 class SkinVector extends SkinTemplate {
35 public $useHeadElement = true;
36 public $skinname = 'vector';
37 public $stylename = 'vector';
38 public $template = 'VectorTemplate';
39
40 protected static $bodyClasses = array( 'vector-animateLayout' );
41
42 /**
43 * Initializes output page and sets up skin-specific parameters
44 * @param OutputPage $out Object to initialize
45 */
46 public function initPage( OutputPage $out ) {
47 global $wgLocalStylePath;
48
49 parent::initPage( $out );
50
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]-->"
59 );
60
61 $out->addModules( array( 'skins.vector.js', 'skins.vector.collapsibleNav' ) );
62 }
63
64 /**
65 * Loads skin and user CSS files.
66 * @param OutputPage $out
67 */
68 function setupSkinUserCss( OutputPage $out ) {
69 parent::setupSkinUserCss( $out );
70
71 $styles = array( 'skins.common.interface', 'skins.vector.styles' );
72 wfRunHooks( 'SkinVectorStyleModules', array( $this, &$styles ) );
73 $out->addModuleStyles( $styles );
74 }
75
76 /**
77 * Adds classes to the body element.
78 *
79 * @param OutputPage $out
80 * @param array &$bodyAttrs Array of attributes that will be set on the body element
81 */
82 function addToBodyAttributes( $out, &$bodyAttrs ) {
83 if ( isset( $bodyAttrs['class'] ) && strlen( $bodyAttrs['class'] ) > 0 ) {
84 $bodyAttrs['class'] .= ' ' . implode( ' ', static::$bodyClasses );
85 } else {
86 $bodyAttrs['class'] = implode( ' ', static::$bodyClasses );
87 }
88 }
89 }
90
91 /**
92 * QuickTemplate class for Vector skin
93 * @ingroup Skins
94 */
95 class VectorTemplate extends BaseTemplate {
96 /* Functions */
97
98 /**
99 * Outputs the entire contents of the (X)HTML page
100 */
101 public function execute() {
102 global $wgVectorUseIconWatch;
103
104 // Build additional attributes for navigation urls
105 $nav = $this->data['content_navigation'];
106
107 if ( $wgVectorUseIconWatch ) {
108 $mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() )
109 ? 'unwatch'
110 : 'watch';
111
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] );
117 }
118 }
119
120 $xmlID = '';
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'], ' ' );
125 }
126
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'] );
134 }
135 if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
136 $nav[$section][$key]['key'] =
137 Linker::tooltip( $xmlID );
138 } else {
139 $nav[$section][$key]['key'] =
140 Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( $xmlID ) );
141 }
142 }
143 }
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'];
148
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'] );
157 }
158 // Output HTML Page
159 $this->html( 'headelement' );
160 ?>
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">
164 <a id="top"></a>
165 <div id="mw-js-message" style="display:none;"<?php $this->html( 'userlangattributes' ) ?>></div>
166 <?php
167 if ( $this->data['sitenotice'] ) {
168 ?>
169 <div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div>
170 <?php
171 }
172 ?>
173 <h1 id="firstHeading" class="firstHeading" lang="<?php
174 $this->data['pageLanguage'] =
175 $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
176 $this->text( 'pageLanguage' );
177 ?>"><span dir="auto"><?php $this->html( 'title' ) ?></span></h1>
178 <?php $this->html( 'prebodyhtml' ) ?>
179 <div id="bodyContent">
180 <?php
181 if ( $this->data['isarticle'] ) {
182 ?>
183 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
184 <?php
185 }
186 ?>
187 <div id="contentSub"<?php
188 $this->html( 'userlangattributes' )
189 ?>><?php $this->html( 'subtitle' ) ?></div>
190 <?php
191 if ( $this->data['undelete'] ) {
192 ?>
193 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
194 <?php
195 }
196 ?>
197 <?php
198 if ( $this->data['newtalk'] ) {
199 ?>
200 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
201 <?php
202 }
203 ?>
204 <div id="jump-to-nav" class="mw-jump">
205 <?php $this->msg( 'jumpto' ) ?>
206 <a href="#mw-navigation"><?php
207 $this->msg( 'jumptonavigation' )
208 ?></a><?php
209 $this->msg( 'comma-separator' )
210 ?>
211 <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
212 </div>
213 <?php $this->html( 'bodycontent' ) ?>
214 <?php
215 if ( $this->data['printfooter'] ) {
216 ?>
217 <div class="printfooter">
218 <?php $this->html( 'printfooter' ); ?>
219 </div>
220 <?php
221 }
222 ?>
223 <?php
224 if ( $this->data['catlinks'] ) {
225 ?>
226 <?php
227 $this->html( 'catlinks' );
228 ?>
229 <?php
230 }
231 ?>
232 <?php
233 if ( $this->data['dataAfterContent'] ) {
234 ?>
235 <?php
236 $this->html( 'dataAfterContent' );
237 ?>
238 <?php
239 }
240 ?>
241 <div class="visualClear"></div>
242 <?php $this->html( 'debughtml' ); ?>
243 </div>
244 </div>
245 <div id="mw-navigation">
246 <h2><?php $this->msg( 'navigation-heading' ) ?></h2>
247 <div id="mw-head">
248 <?php $this->renderNavigation( 'PERSONAL' ); ?>
249 <div id="left-navigation">
250 <?php $this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?>
251 </div>
252 <div id="right-navigation">
253 <?php $this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?>
254 </div>
255 </div>
256 <div id="mw-panel">
257 <div id="p-logo" role="banner"><a style="background-image: url(<?php
258 $this->text( 'logopath' )
259 ?>);" href="<?php
260 echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] )
261 ?>" <?php
262 echo Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( 'p-logo' ) )
263 ?>></a></div>
264 <?php $this->renderPortals( $this->data['sidebar'] ); ?>
265 </div>
266 </div>
267 <div id="footer" role="contentinfo"<?php $this->html( 'userlangattributes' ) ?>>
268 <?php
269 foreach ( $this->getFooterLinks() as $category => $links ) {
270 ?>
271 <ul id="footer-<?php
272 echo $category
273 ?>">
274 <?php
275 foreach ( $links as $link ) {
276 ?>
277 <li id="footer-<?php
278 echo $category
279 ?>-<?php
280 echo $link
281 ?>"><?php
282 $this->html( $link )
283 ?></li>
284 <?php
285 }
286 ?>
287 </ul>
288 <?php
289 }
290 ?>
291 <?php $footericons = $this->getFooterIcons( "icononly" );
292 if ( count( $footericons ) > 0 ) { ?>
293 <ul id="footer-icons" class="noprint">
294 <?php
295 foreach ( $footericons as $blockName => $footerIcons ) {
296 ?>
297 <li id="footer-<?php
298 echo htmlspecialchars( $blockName ); ?>ico">
299 <?php
300 foreach ( $footerIcons as $icon ) {
301 ?>
302 <?php
303 echo $this->getSkin()->makeFooterIcon( $icon );
304 ?>
305
306 <?php
307 }
308 ?>
309 </li>
310 <?php
311 }
312 ?>
313 </ul>
314 <?php
315 }
316 ?>
317 <div style="clear:both"></div>
318 </div>
319 <?php $this->printTrail(); ?>
320
321 </body>
322 </html>
323 <?php
324 }
325
326 /**
327 * Render a series of portals
328 *
329 * @param array $portals
330 */
331 protected function renderPortals( $portals ) {
332 // Force the rendering of the following portals
333 if ( !isset( $portals['SEARCH'] ) ) {
334 $portals['SEARCH'] = true;
335 }
336 if ( !isset( $portals['TOOLBOX'] ) ) {
337 $portals['TOOLBOX'] = true;
338 }
339 if ( !isset( $portals['LANGUAGES'] ) ) {
340 $portals['LANGUAGES'] = true;
341 }
342 // Render portals
343 foreach ( $portals as $name => $content ) {
344 if ( $content === false ) {
345 continue;
346 }
347
348 switch ( $name ) {
349 case 'SEARCH':
350 break;
351 case 'TOOLBOX':
352 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
353 break;
354 case 'LANGUAGES':
355 if ( $this->data['language_urls'] !== false ) {
356 $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
357 }
358 break;
359 default:
360 $this->renderPortal( $name, $content );
361 break;
362 }
363 }
364 }
365
366 /**
367 * @param string $name
368 * @param array $content
369 * @param null|string $msg
370 * @param null|string|array $hook
371 */
372 protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
373 if ( $msg === null ) {
374 $msg = $name;
375 }
376 $msgObj = wfMessage( $msg );
377 ?>
378 <div class="portal" role="navigation" id='<?php
379 echo Sanitizer::escapeId( "p-$name" )
380 ?>'<?php
381 echo Linker::tooltip( 'p-' . $name )
382 ?> aria-labelledby='<?php echo Sanitizer::escapeId( "p-$name-label" ) ?>'>
383 <h3<?php
384 $this->html( 'userlangattributes' )
385 ?> id='<?php
386 echo Sanitizer::escapeId( "p-$name-label" )
387 ?>'><?php
388 echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg );
389 ?></h3>
390 <div class="body">
391 <?php
392 if ( is_array( $content ) ) { ?>
393 <ul>
394 <?php
395 foreach ( $content as $key => $val ) { ?>
396 <?php echo $this->makeListItem( $key, $val ); ?>
397
398 <?php
399 }
400 if ( $hook !== null ) {
401 wfRunHooks( $hook, array( &$this, true ) );
402 }
403 ?>
404 </ul>
405 <?php
406 } else { ?>
407 <?php
408 echo $content; /* Allow raw HTML block to be defined by extensions */
409 }
410
411 $this->renderAfterPortlet( $name );
412 ?>
413 </div>
414 </div>
415 <?php
416 }
417
418 /**
419 * Render one or more navigations elements by name, automatically reveresed
420 * when UI is in RTL mode
421 *
422 * @param array $elements
423 */
424 protected function renderNavigation( $elements ) {
425 global $wgVectorUseSimpleSearch;
426
427 // If only one element was given, wrap it in an array, allowing more
428 // flexible arguments
429 if ( !is_array( $elements ) ) {
430 $elements = array( $elements );
431 // If there's a series of elements, reverse them when in RTL mode
432 } elseif ( $this->data['rtl'] ) {
433 $elements = array_reverse( $elements );
434 }
435 // Render elements
436 foreach ( $elements as $name => $element ) {
437 switch ( $element ) {
438 case 'NAMESPACES':
439 ?>
440 <div id="p-namespaces" role="navigation" class="vectorTabs<?php
441 if ( count( $this->data['namespace_urls'] ) == 0 ) {
442 echo ' emptyPortlet';
443 }
444 ?>" aria-labelledby="p-namespaces-label">
445 <h3 id="p-namespaces-label"><?php $this->msg( 'namespaces' ) ?></h3>
446 <ul<?php $this->html( 'userlangattributes' ) ?>>
447 <?php
448 foreach ( $this->data['namespace_urls'] as $link ) {
449 ?>
450 <li <?php
451 echo $link['attributes']
452 ?>><span><a href="<?php
453 echo htmlspecialchars( $link['href'] )
454 ?>" <?php
455 echo $link['key']
456 ?>><?php
457 echo htmlspecialchars( $link['text'] )
458 ?></a></span></li>
459 <?php
460 }
461 ?>
462 </ul>
463 </div>
464 <?php
465 break;
466 case 'VARIANTS':
467 ?>
468 <div id="p-variants" role="navigation" class="vectorMenu<?php
469 if ( count( $this->data['variant_urls'] ) == 0 ) {
470 echo ' emptyPortlet';
471 }
472 ?>" aria-labelledby="p-variants-label">
473 <h3 id="mw-vector-current-variant">
474 <?php
475 foreach ( $this->data['variant_urls'] as $link ) { ?>
476 <?php
477 if ( stripos( $link['attributes'], 'selected' ) !== false ) {
478 ?>
479 <?php
480 echo htmlspecialchars( $link['text'] )
481 ?>
482 <?php
483 }
484 ?>
485 <?php
486 }
487 ?>
488 </h3>
489 <h3 id="p-variants-label"><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h3>
490 <div class="menu">
491 <ul>
492 <?php
493 foreach ( $this->data['variant_urls'] as $link ) {
494 ?>
495 <li<?php
496 echo $link['attributes']
497 ?>><a href="<?php
498 echo htmlspecialchars( $link['href'] )
499 ?>" lang="<?php
500 echo htmlspecialchars( $link['lang'] )
501 ?>" hreflang="<?php
502 echo htmlspecialchars( $link['hreflang'] )
503 ?>" <?php
504 echo $link['key']
505 ?>><?php
506 echo htmlspecialchars( $link['text'] )
507 ?></a></li>
508 <?php
509 }
510 ?>
511 </ul>
512 </div>
513 </div>
514 <?php
515 break;
516 case 'VIEWS':
517 ?>
518 <div id="p-views" role="navigation" class="vectorTabs<?php
519 if ( count( $this->data['view_urls'] ) == 0 ) {
520 echo ' emptyPortlet';
521 }
522 ?>" aria-labelledby="p-views-label">
523 <h3 id="p-views-label"><?php $this->msg( 'views' ) ?></h3>
524 <ul<?php
525 $this->html( 'userlangattributes' )
526 ?>>
527 <?php
528 foreach ( $this->data['view_urls'] as $link ) {
529 ?>
530 <li<?php
531 echo $link['attributes']
532 ?>><span><a href="<?php
533 echo htmlspecialchars( $link['href'] )
534 ?>" <?php
535 echo $link['key']
536 ?>><?php
537 // $link['text'] can be undefined - bug 27764
538 if ( array_key_exists( 'text', $link ) ) {
539 echo array_key_exists( 'img', $link )
540 ? '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />'
541 : htmlspecialchars( $link['text'] );
542 }
543 ?></a></span></li>
544 <?php
545 }
546 ?>
547 </ul>
548 </div>
549 <?php
550 break;
551 case 'ACTIONS':
552 ?>
553 <div id="p-cactions" role="navigation" class="vectorMenu<?php
554 if ( count( $this->data['action_urls'] ) == 0 ) {
555 echo ' emptyPortlet';
556 }
557 ?>" aria-labelledby="p-cactions-label">
558 <h3 id="p-cactions-label"><span><?php $this->msg( 'actions' ) ?></span><a href="#"></a></h3>
559 <div class="menu">
560 <ul<?php $this->html( 'userlangattributes' ) ?>>
561 <?php
562 foreach ( $this->data['action_urls'] as $link ) { ?>
563 <li<?php
564 echo $link['attributes']
565 ?>>
566 <a href="<?php
567 echo htmlspecialchars( $link['href'] )
568 ?>" <?php
569 echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] )
570 ?></a>
571 </li>
572 <?php
573 }
574 ?>
575 </ul>
576 </div>
577 </div>
578 <?php
579 break;
580 case 'PERSONAL':
581 ?>
582 <div id="p-personal" role="navigation" class="<?php
583 if ( count( $this->data['personal_urls'] ) == 0 ) {
584 echo ' emptyPortlet';
585 }
586 ?>" aria-labelledby="p-personal-label">
587 <h3 id="p-personal-label"><?php $this->msg( 'personaltools' ) ?></h3>
588 <ul<?php $this->html( 'userlangattributes' ) ?>>
589 <?php
590 $personalTools = $this->getPersonalTools();
591 foreach ( $personalTools as $key => $item ) {
592 echo $this->makeListItem( $key, $item );
593 }
594 ?>
595 </ul>
596 </div>
597 <?php
598 break;
599 case 'SEARCH':
600 ?>
601 <div id="p-search" role="search">
602 <h3<?php $this->html( 'userlangattributes' ) ?>>
603 <label for="searchInput"><?php $this->msg( 'search' ) ?></label>
604 </h3>
605 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
606 <?php
607 if ( $wgVectorUseSimpleSearch ) {
608 ?>
609 <div id="simpleSearch">
610 <?php
611 } else {
612 ?>
613 <div>
614 <?php
615 }
616 ?>
617 <?php
618 echo $this->makeSearchInput( array( 'id' => 'searchInput' ) );
619 echo Html::hidden( 'title', $this->get( 'searchtitle' ) );
620 // We construct two buttons (for 'go' and 'fulltext' search modes), but only one will be
621 // visible and actionable at a time (they are overlaid on top of each other in CSS).
622 // * Browsers will use the 'fulltext' one by default (as it's the first in tree-order), which
623 // is desirable when they are unable to show search suggestions (either due to being broken
624 // or having JavaScript turned off).
625 // * The mediawiki.searchSuggest module, after doing tests for the broken browsers, removes
626 // the 'fulltext' button and handles 'fulltext' search itself; this will reveal the 'go'
627 // button and cause it to be used.
628 echo $this->makeSearchButton(
629 'fulltext',
630 array( 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' )
631 );
632 echo $this->makeSearchButton( 'go', array( 'id' => 'searchButton', 'class' => 'searchButton' ) );
633 ?>
634 </div>
635 </form>
636 </div>
637 <?php
638
639 break;
640 }
641 }
642 }
643 }