Merge "TableSorter: Fix column order when collecting headers"
[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
36 protected static $bodyClasses = array( 'vector-animateLayout' );
37
38 var $skinname = 'vector', $stylename = 'vector',
39 $template = 'VectorTemplate', $useHeadElement = true;
40
41 /**
42 * Initializes output page and sets up skin-specific parameters
43 * @param $out OutputPage 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', 'skins.vector.collapsibleNav' ) );
61 }
62
63 /**
64 * Loads skin and user CSS files.
65 * @param $out OutputPage object
66 */
67 function setupSkinUserCss( OutputPage $out ) {
68 parent::setupSkinUserCss( $out );
69
70 $styles = array( 'skins.common.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 $out OutputPage object
79 * @param &$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
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() ) ? '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] );
114 }
115 }
116
117 $xmlID = '';
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'], ' ' );
122 }
123
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'] );
131 }
132 if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
133 $nav[$section][$key]['key'] =
134 Linker::tooltip( $xmlID );
135 } else {
136 $nav[$section][$key]['key'] =
137 Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( $xmlID ) );
138 }
139 }
140 }
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'];
145
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'] );
154 }
155 // Output HTML Page
156 $this->html( 'headelement' );
157 ?>
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">
161 <a id="top"></a>
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>
165 <?php } ?>
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 <div id="bodyContent">
171 <?php if ( $this->data['isarticle'] ) { ?>
172 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
173 <?php } ?>
174 <div id="contentSub"<?php $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' ) ?></div>
175 <?php if ( $this->data['undelete'] ) { ?>
176 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
177 <?php } ?>
178 <?php if ( $this->data['newtalk'] ) { ?>
179 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
180 <?php } ?>
181 <div id="jump-to-nav" class="mw-jump">
182 <?php $this->msg( 'jumpto' ) ?>
183 <a href="#mw-navigation"><?php $this->msg( 'jumptonavigation' ) ?></a><?php $this->msg( 'comma-separator' ) ?>
184 <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
185 </div>
186 <?php $this->html( 'bodycontent' ) ?>
187 <?php if ( $this->data['printfooter'] ) { ?>
188 <div class="printfooter">
189 <?php $this->html( 'printfooter' ); ?>
190 </div>
191 <?php } ?>
192 <?php if ( $this->data['catlinks'] ) { ?>
193 <?php $this->html( 'catlinks' ); ?>
194 <?php } ?>
195 <?php if ( $this->data['dataAfterContent'] ) { ?>
196 <?php $this->html( 'dataAfterContent' ); ?>
197 <?php } ?>
198 <div class="visualClear"></div>
199 <?php $this->html( 'debughtml' ); ?>
200 </div>
201 </div>
202 <div id="mw-navigation">
203 <h2><?php $this->msg( 'navigation-heading' ) ?></h2>
204 <div id="mw-head">
205 <?php $this->renderNavigation( 'PERSONAL' ); ?>
206 <div id="left-navigation">
207 <?php $this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?>
208 </div>
209 <div id="right-navigation">
210 <?php $this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?>
211 </div>
212 </div>
213 <div id="mw-panel">
214 <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>
215 <?php $this->renderPortals( $this->data['sidebar'] ); ?>
216 </div>
217 </div>
218 <div id="footer" role="contentinfo"<?php $this->html( 'userlangattributes' ) ?>>
219 <?php foreach ( $this->getFooterLinks() as $category => $links ) { ?>
220 <ul id="footer-<?php echo $category ?>">
221 <?php foreach ( $links as $link ) { ?>
222 <li id="footer-<?php echo $category ?>-<?php echo $link ?>"><?php $this->html( $link ) ?></li>
223 <?php } ?>
224 </ul>
225 <?php } ?>
226 <?php $footericons = $this->getFooterIcons( "icononly" );
227 if ( count( $footericons ) > 0 ) { ?>
228 <ul id="footer-icons" class="noprint">
229 <?php foreach ( $footericons as $blockName => $footerIcons ) { ?>
230 <li id="footer-<?php echo htmlspecialchars( $blockName ); ?>ico">
231 <?php foreach ( $footerIcons as $icon ) { ?>
232 <?php echo $this->getSkin()->makeFooterIcon( $icon ); ?>
233
234 <?php } ?>
235 </li>
236 <?php } ?>
237 </ul>
238 <?php } ?>
239 <div style="clear:both"></div>
240 </div>
241 <?php $this->printTrail(); ?>
242
243 </body>
244 </html>
245 <?php
246 }
247
248 /**
249 * Render a series of portals
250 *
251 * @param $portals array
252 */
253 protected function renderPortals( $portals ) {
254 // Force the rendering of the following portals
255 if ( !isset( $portals['SEARCH'] ) ) {
256 $portals['SEARCH'] = true;
257 }
258 if ( !isset( $portals['TOOLBOX'] ) ) {
259 $portals['TOOLBOX'] = true;
260 }
261 if ( !isset( $portals['LANGUAGES'] ) ) {
262 $portals['LANGUAGES'] = true;
263 }
264 // Render portals
265 foreach ( $portals as $name => $content ) {
266 if ( $content === false ) {
267 continue;
268 }
269
270 switch ( $name ) {
271 case 'SEARCH':
272 break;
273 case 'TOOLBOX':
274 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
275 break;
276 case 'LANGUAGES':
277 if ( $this->data['language_urls'] ) {
278 $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
279 }
280 break;
281 default:
282 $this->renderPortal( $name, $content );
283 break;
284 }
285 }
286 }
287
288 /**
289 * @param $name string
290 * @param $content array
291 * @param $msg null|string
292 * @param $hook null|string|array
293 */
294 protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
295 if ( $msg === null ) {
296 $msg = $name;
297 }
298 $msgObj = wfMessage( $msg );
299 ?>
300 <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" ) ?>'>
301 <h3<?php $this->html( 'userlangattributes' ) ?> id='<?php echo Sanitizer::escapeId( "p-$name-label" ) ?>'><?php echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg ); ?></h3>
302 <div class="body">
303 <?php
304 if ( is_array( $content ) ) { ?>
305 <ul>
306 <?php
307 foreach ( $content as $key => $val ) { ?>
308 <?php echo $this->makeListItem( $key, $val ); ?>
309
310 <?php
311 }
312 if ( $hook !== null ) {
313 wfRunHooks( $hook, array( &$this, true ) );
314 }
315 ?>
316 </ul>
317 <?php
318 } else { ?>
319 <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
320 <?php
321 } ?>
322 </div>
323 </div>
324 <?php
325 }
326
327 /**
328 * Render one or more navigations elements by name, automatically reveresed
329 * when UI is in RTL mode
330 *
331 * @param $elements array
332 */
333 protected function renderNavigation( $elements ) {
334 global $wgVectorUseSimpleSearch;
335
336 // If only one element was given, wrap it in an array, allowing more
337 // flexible arguments
338 if ( !is_array( $elements ) ) {
339 $elements = array( $elements );
340 // If there's a series of elements, reverse them when in RTL mode
341 } elseif ( $this->data['rtl'] ) {
342 $elements = array_reverse( $elements );
343 }
344 // Render elements
345 foreach ( $elements as $name => $element ) {
346 switch ( $element ) {
347 case 'NAMESPACES':
348 ?>
349 <div id="p-namespaces" role="navigation" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria-labelledby="p-namespaces-label">
350 <h3 id="p-namespaces-label"><?php $this->msg( 'namespaces' ) ?></h3>
351 <ul<?php $this->html( 'userlangattributes' ) ?>>
352 <?php foreach ( $this->data['namespace_urls'] as $link ) { ?>
353 <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>
354 <?php } ?>
355 </ul>
356 </div>
357 <?php
358 break;
359 case 'VARIANTS':
360 ?>
361 <div id="p-variants" role="navigation" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria-labelledby="p-variants-label">
362 <h3 id="mw-vector-current-variant">
363 <?php foreach ( $this->data['variant_urls'] as $link ) { ?>
364 <?php if ( stripos( $link['attributes'], 'selected' ) !== false ) { ?>
365 <?php echo htmlspecialchars( $link['text'] ) ?>
366 <?php } ?>
367 <?php } ?>
368 </h3>
369 <h3 id="p-variants-label"><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h3>
370 <div class="menu">
371 <ul>
372 <?php foreach ( $this->data['variant_urls'] as $link ) { ?>
373 <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>
374 <?php } ?>
375 </ul>
376 </div>
377 </div>
378 <?php
379 break;
380 case 'VIEWS':
381 ?>
382 <div id="p-views" role="navigation" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria-labelledby="p-views-label">
383 <h3 id="p-views-label"><?php $this->msg( 'views' ) ?></h3>
384 <ul<?php $this->html( 'userlangattributes' ) ?>>
385 <?php foreach ( $this->data['view_urls'] as $link ) { ?>
386 <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php
387 // $link['text'] can be undefined - bug 27764
388 if ( array_key_exists( 'text', $link ) ) {
389 echo array_key_exists( 'img', $link ) ? '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />' : htmlspecialchars( $link['text'] );
390 }
391 ?></a></span></li>
392 <?php } ?>
393 </ul>
394 </div>
395 <?php
396 break;
397 case 'ACTIONS':
398 ?>
399 <div id="p-cactions" role="navigation" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria-labelledby="p-cactions-label">
400 <h3 id="p-cactions-label"><span><?php $this->msg( 'actions' ) ?></span><a href="#"></a></h3>
401 <div class="menu">
402 <ul<?php $this->html( 'userlangattributes' ) ?>>
403 <?php foreach ( $this->data['action_urls'] as $link ) { ?>
404 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
405 <?php } ?>
406 </ul>
407 </div>
408 </div>
409 <?php
410 break;
411 case 'PERSONAL':
412 ?>
413 <div id="p-personal" role="navigation" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>" aria-labelledby="p-personal-label">
414 <h3 id="p-personal-label"><?php $this->msg( 'personaltools' ) ?></h3>
415 <ul<?php $this->html( 'userlangattributes' ) ?>>
416 <?php
417 $personalTools = $this->getPersonalTools();
418 foreach ( $personalTools as $key => $item ) {
419 echo $this->makeListItem( $key, $item );
420 }
421 ?>
422 </ul>
423 </div>
424 <?php
425 break;
426 case 'SEARCH':
427 ?>
428 <div id="p-search" role="search">
429 <h3<?php $this->html( 'userlangattributes' ) ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
430 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
431 <?php if ( $wgVectorUseSimpleSearch ) { ?>
432 <div id="simpleSearch">
433 <?php } else { ?>
434 <div>
435 <?php } ?>
436 <?php
437 echo $this->makeSearchInput( array( 'id' => 'searchInput' ) );
438 echo Html::hidden( 'title', $this->get( 'searchtitle' ) );
439 // We construct two buttons (for 'go' and 'fulltext' search modes), but only one will be
440 // visible and actionable at a time (they are overlaid on top of each other in CSS).
441 // * Browsers will use the 'fulltext' one by default (as it's the first in tree-order), which
442 // is desirable when they are unable to show search suggestions (either due to being broken
443 // or having JavaScript turned off).
444 // * The mediawiki.searchSuggest module, after doing tests for the broken browsers, removes
445 // the 'fulltext' button and handles 'fulltext' search itself; this will reveal the 'go'
446 // button and cause it to be used.
447 echo $this->makeSearchButton( 'fulltext', array( 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' ) );
448 echo $this->makeSearchButton( 'go', array( 'id' => 'searchButton', 'class' => 'searchButton' ) );
449 ?>
450 </div>
451 </form>
452 </div>
453 <?php
454
455 break;
456 }
457 }
458 }
459 }