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