mediawiki.page.gallery.resize: Remove weird mw.hook call
[lhc/web/wiklou.git] / skins / vector / 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 <?php
166 if ( $this->data['sitenotice'] ) {
167 ?>
168 <div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div>
169 <?php
170 }
171 ?>
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">
179 <?php
180 if ( $this->data['isarticle'] ) {
181 ?>
182 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
183 <?php
184 }
185 ?>
186 <div id="contentSub"<?php
187 $this->html( 'userlangattributes' )
188 ?>><?php $this->html( 'subtitle' ) ?></div>
189 <?php
190 if ( $this->data['undelete'] ) {
191 ?>
192 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
193 <?php
194 }
195 ?>
196 <?php
197 if ( $this->data['newtalk'] ) {
198 ?>
199 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
200 <?php
201 }
202 ?>
203 <div id="jump-to-nav" class="mw-jump">
204 <?php $this->msg( 'jumpto' ) ?>
205 <a href="#mw-navigation"><?php
206 $this->msg( 'jumptonavigation' )
207 ?></a><?php
208 $this->msg( 'comma-separator' )
209 ?>
210 <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
211 </div>
212 <?php $this->html( 'bodycontent' ) ?>
213 <?php
214 if ( $this->data['printfooter'] ) {
215 ?>
216 <div class="printfooter">
217 <?php $this->html( 'printfooter' ); ?>
218 </div>
219 <?php
220 }
221 ?>
222 <?php
223 if ( $this->data['catlinks'] ) {
224 ?>
225 <?php
226 $this->html( 'catlinks' );
227 ?>
228 <?php
229 }
230 ?>
231 <?php
232 if ( $this->data['dataAfterContent'] ) {
233 ?>
234 <?php
235 $this->html( 'dataAfterContent' );
236 ?>
237 <?php
238 }
239 ?>
240 <div class="visualClear"></div>
241 <?php $this->html( 'debughtml' ); ?>
242 </div>
243 </div>
244 <div id="mw-navigation">
245 <h2><?php $this->msg( 'navigation-heading' ) ?></h2>
246
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 ?>
294 <ul id="footer-icons" class="noprint">
295 <?php
296 foreach ( $footericons as $blockName => $footerIcons ) {
297 ?>
298 <li id="footer-<?php
299 echo htmlspecialchars( $blockName ); ?>ico">
300 <?php
301 foreach ( $footerIcons as $icon ) {
302 ?>
303 <?php
304 echo $this->getSkin()->makeFooterIcon( $icon );
305 ?>
306
307 <?php
308 }
309 ?>
310 </li>
311 <?php
312 }
313 ?>
314 </ul>
315 <?php
316 }
317 ?>
318 <div style="clear:both"></div>
319 </div>
320 <?php $this->printTrail(); ?>
321
322 </body>
323 </html>
324 <?php
325 }
326
327 /**
328 * Render a series of portals
329 *
330 * @param array $portals
331 */
332 protected function renderPortals( $portals ) {
333 // Force the rendering of the following portals
334 if ( !isset( $portals['SEARCH'] ) ) {
335 $portals['SEARCH'] = true;
336 }
337 if ( !isset( $portals['TOOLBOX'] ) ) {
338 $portals['TOOLBOX'] = true;
339 }
340 if ( !isset( $portals['LANGUAGES'] ) ) {
341 $portals['LANGUAGES'] = true;
342 }
343 // Render portals
344 foreach ( $portals as $name => $content ) {
345 if ( $content === false ) {
346 continue;
347 }
348
349 switch ( $name ) {
350 case 'SEARCH':
351 break;
352 case 'TOOLBOX':
353 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
354 break;
355 case 'LANGUAGES':
356 if ( $this->data['language_urls'] !== false ) {
357 $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
358 }
359 break;
360 default:
361 $this->renderPortal( $name, $content );
362 break;
363 }
364 }
365 }
366
367 /**
368 * @param string $name
369 * @param array $content
370 * @param null|string $msg
371 * @param null|string|array $hook
372 */
373 protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
374 if ( $msg === null ) {
375 $msg = $name;
376 }
377 $msgObj = wfMessage( $msg );
378 ?>
379 <div class="portal" role="navigation" id='<?php
380 echo Sanitizer::escapeId( "p-$name" )
381 ?>'<?php
382 echo Linker::tooltip( 'p-' . $name )
383 ?> aria-labelledby='<?php echo Sanitizer::escapeId( "p-$name-label" ) ?>'>
384 <h3<?php
385 $this->html( 'userlangattributes' )
386 ?> id='<?php
387 echo Sanitizer::escapeId( "p-$name-label" )
388 ?>'><?php
389 echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg );
390 ?></h3>
391
392 <div class="body">
393 <?php
394 if ( is_array( $content ) ) {
395 ?>
396 <ul>
397 <?php
398 foreach ( $content as $key => $val ) {
399 ?>
400 <?php echo $this->makeListItem( $key, $val ); ?>
401
402 <?php
403 }
404 if ( $hook !== null ) {
405 wfRunHooks( $hook, array( &$this, true ) );
406 }
407 ?>
408 </ul>
409 <?php
410 } else {
411 ?>
412 <?php
413 echo $content; /* Allow raw HTML block to be defined by extensions */
414 }
415
416 $this->renderAfterPortlet( $name );
417 ?>
418 </div>
419 </div>
420 <?php
421 }
422
423 /**
424 * Render one or more navigations elements by name, automatically reveresed
425 * when UI is in RTL mode
426 *
427 * @param array $elements
428 */
429 protected function renderNavigation( $elements ) {
430 global $wgVectorUseSimpleSearch;
431
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 );
439 }
440 // Render elements
441 foreach ( $elements as $name => $element ) {
442 switch ( $element ) {
443 case 'NAMESPACES':
444 ?>
445 <div id="p-namespaces" role="navigation" class="vectorTabs<?php
446 if ( count( $this->data['namespace_urls'] ) == 0 ) {
447 echo ' emptyPortlet';
448 }
449 ?>" aria-labelledby="p-namespaces-label">
450 <h3 id="p-namespaces-label"><?php $this->msg( 'namespaces' ) ?></h3>
451 <ul<?php $this->html( 'userlangattributes' ) ?>>
452 <?php
453 foreach ( $this->data['namespace_urls'] as $link ) {
454 ?>
455 <li <?php
456 echo $link['attributes']
457 ?>><span><a href="<?php
458 echo htmlspecialchars( $link['href'] )
459 ?>" <?php
460 echo $link['key']
461 ?>><?php
462 echo htmlspecialchars( $link['text'] )
463 ?></a></span></li>
464 <?php
465 }
466 ?>
467 </ul>
468 </div>
469 <?php
470 break;
471 case 'VARIANTS':
472 ?>
473 <div id="p-variants" role="navigation" class="vectorMenu<?php
474 if ( count( $this->data['variant_urls'] ) == 0 ) {
475 echo ' emptyPortlet';
476 }
477 ?>" aria-labelledby="p-variants-label">
478 <h3 id="mw-vector-current-variant">
479 <?php
480 foreach ( $this->data['variant_urls'] as $link ) {
481 ?>
482 <?php
483 if ( stripos( $link['attributes'], 'selected' ) !== false ) {
484 ?>
485 <?php
486 echo htmlspecialchars( $link['text'] )
487 ?>
488 <?php
489 }
490 ?>
491 <?php
492 }
493 ?>
494 </h3>
495
496 <h3 id="p-variants-label"><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h3>
497
498 <div class="menu">
499 <ul>
500 <?php
501 foreach ( $this->data['variant_urls'] as $link ) {
502 ?>
503 <li<?php
504 echo $link['attributes']
505 ?>><a href="<?php
506 echo htmlspecialchars( $link['href'] )
507 ?>" lang="<?php
508 echo htmlspecialchars( $link['lang'] )
509 ?>" hreflang="<?php
510 echo htmlspecialchars( $link['hreflang'] )
511 ?>" <?php
512 echo $link['key']
513 ?>><?php
514 echo htmlspecialchars( $link['text'] )
515 ?></a></li>
516 <?php
517 }
518 ?>
519 </ul>
520 </div>
521 </div>
522 <?php
523 break;
524 case 'VIEWS':
525 ?>
526 <div id="p-views" role="navigation" class="vectorTabs<?php
527 if ( count( $this->data['view_urls'] ) == 0 ) {
528 echo ' emptyPortlet';
529 }
530 ?>" aria-labelledby="p-views-label">
531 <h3 id="p-views-label"><?php $this->msg( 'views' ) ?></h3>
532 <ul<?php
533 $this->html( 'userlangattributes' )
534 ?>>
535 <?php
536 foreach ( $this->data['view_urls'] as $link ) {
537 ?>
538 <li<?php
539 echo $link['attributes']
540 ?>><span><a href="<?php
541 echo htmlspecialchars( $link['href'] )
542 ?>" <?php
543 echo $link['key']
544 ?>><?php
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'] );
550 }
551 ?></a></span></li>
552 <?php
553 }
554 ?>
555 </ul>
556 </div>
557 <?php
558 break;
559 case 'ACTIONS':
560 ?>
561 <div id="p-cactions" role="navigation" class="vectorMenu<?php
562 if ( count( $this->data['action_urls'] ) == 0 ) {
563 echo ' emptyPortlet';
564 }
565 ?>" aria-labelledby="p-cactions-label">
566 <h3 id="p-cactions-label"><span><?php $this->msg( 'vector-more-actions' ) ?></span><a href="#"></a></h3>
567
568 <div class="menu">
569 <ul<?php $this->html( 'userlangattributes' ) ?>>
570 <?php
571 foreach ( $this->data['action_urls'] as $link ) {
572 ?>
573 <li<?php
574 echo $link['attributes']
575 ?>>
576 <a href="<?php
577 echo htmlspecialchars( $link['href'] )
578 ?>" <?php
579 echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] )
580 ?></a>
581 </li>
582 <?php
583 }
584 ?>
585 </ul>
586 </div>
587 </div>
588 <?php
589 break;
590 case 'PERSONAL':
591 ?>
592 <div id="p-personal" role="navigation" class="<?php
593 if ( count( $this->data['personal_urls'] ) == 0 ) {
594 echo ' emptyPortlet';
595 }
596 ?>" aria-labelledby="p-personal-label">
597 <h3 id="p-personal-label"><?php $this->msg( 'personaltools' ) ?></h3>
598 <ul<?php $this->html( 'userlangattributes' ) ?>>
599 <?php
600 $personalTools = $this->getPersonalTools();
601 foreach ( $personalTools as $key => $item ) {
602 echo $this->makeListItem( $key, $item );
603 }
604 ?>
605 </ul>
606 </div>
607 <?php
608 break;
609 case 'SEARCH':
610 ?>
611 <div id="p-search" role="search">
612 <h3<?php $this->html( 'userlangattributes' ) ?>>
613 <label for="searchInput"><?php $this->msg( 'search' ) ?></label>
614 </h3>
615
616 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
617 <?php
618 if ($wgVectorUseSimpleSearch) {
619 ?>
620 <div id="simpleSearch">
621 <?php
622 } else {
623 ?>
624 <div>
625 <?php
626 }
627 ?>
628 <?php
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(
643 'fulltext',
644 array( 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' )
645 );
646 echo $this->makeSearchButton(
647 'go',
648 array( 'id' => 'searchButton', 'class' => 'searchButton' )
649 );
650 ?>
651 </div>
652 </form>
653 </div>
654 <?php
655
656 break;
657 }
658 }
659 }
660 }