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