Merge "CologneBlue rewrite: rework otherLanguages(), CSS: serif font"
[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 fille 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->addModuleScripts( 'skins.vector' );
61 }
62
63 /**
64 * Load skin and user CSS files in the correct order
65 * fixes bug 22916
66 * @param $out OutputPage object
67 */
68 function setupSkinUserCss( OutputPage $out ){
69 parent::setupSkinUserCss( $out );
70 $out->addModuleStyles( 'skins.vector' );
71 }
72
73 /**
74 * Adds classes to the body element.
75 *
76 * @param $out OutputPage object
77 * @param &$bodyAttrs Array of attributes that will be set on the body element
78 */
79 function addToBodyAttributes( $out, &$bodyAttrs ) {
80 if ( isset( $bodyAttrs['class'] ) && strlen( $bodyAttrs['class'] ) > 0 ) {
81 $bodyAttrs['class'] .= ' ' . implode( ' ', static::$bodyClasses );
82 } else {
83 $bodyAttrs['class'] = implode( ' ', static::$bodyClasses );
84 }
85 }
86 }
87
88 /**
89 * QuickTemplate class for Vector skin
90 * @ingroup Skins
91 */
92 class VectorTemplate extends BaseTemplate {
93
94 /* Functions */
95
96 /**
97 * Outputs the entire contents of the (X)HTML page
98 */
99 public function execute() {
100 global $wgVectorUseIconWatch;
101
102 // Build additional attributes for navigation urls
103 $nav = $this->data['content_navigation'];
104
105 if ( $wgVectorUseIconWatch ) {
106 $mode = $this->getSkin()->getUser()->isWatched( $this->getSkin()->getRelevantTitle() ) ? 'unwatch' : 'watch';
107 if ( isset( $nav['actions'][$mode] ) ) {
108 $nav['views'][$mode] = $nav['actions'][$mode];
109 $nav['views'][$mode]['class'] = rtrim( 'icon ' . $nav['views'][$mode]['class'], ' ' );
110 $nav['views'][$mode]['primary'] = true;
111 unset( $nav['actions'][$mode] );
112 }
113 }
114
115 $xmlID = '';
116 foreach ( $nav as $section => $links ) {
117 foreach ( $links as $key => $link ) {
118 if ( $section == 'views' && !( isset( $link['primary'] ) && $link['primary'] ) ) {
119 $link['class'] = rtrim( 'collapsible ' . $link['class'], ' ' );
120 }
121
122 $xmlID = isset( $link['id'] ) ? $link['id'] : 'ca-' . $xmlID;
123 $nav[$section][$key]['attributes'] =
124 ' id="' . Sanitizer::escapeId( $xmlID ) . '"';
125 if ( $link['class'] ) {
126 $nav[$section][$key]['attributes'] .=
127 ' class="' . htmlspecialchars( $link['class'] ) . '"';
128 unset( $nav[$section][$key]['class'] );
129 }
130 if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
131 $nav[$section][$key]['key'] =
132 Linker::tooltip( $xmlID );
133 } else {
134 $nav[$section][$key]['key'] =
135 Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( $xmlID ) );
136 }
137 }
138 }
139 $this->data['namespace_urls'] = $nav['namespaces'];
140 $this->data['view_urls'] = $nav['views'];
141 $this->data['action_urls'] = $nav['actions'];
142 $this->data['variant_urls'] = $nav['variants'];
143
144 // Reverse horizontally rendered navigation elements
145 if ( $this->data['rtl'] ) {
146 $this->data['view_urls'] =
147 array_reverse( $this->data['view_urls'] );
148 $this->data['namespace_urls'] =
149 array_reverse( $this->data['namespace_urls'] );
150 $this->data['personal_urls'] =
151 array_reverse( $this->data['personal_urls'] );
152 }
153 // Output HTML Page
154 $this->html( 'headelement' );
155 ?>
156 <div id="mw-page-base" class="noprint"></div>
157 <div id="mw-head-base" class="noprint"></div>
158 <!-- content -->
159 <div id="content" class="mw-body">
160 <a id="top"></a>
161 <div id="mw-js-message" style="display:none;"<?php $this->html( 'userlangattributes' ) ?>></div>
162 <?php if ( $this->data['sitenotice'] ): ?>
163 <!-- sitenotice -->
164 <div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div>
165 <!-- /sitenotice -->
166 <?php endif; ?>
167 <!-- firstHeading -->
168 <h1 id="firstHeading" class="firstHeading"><span dir="auto"><?php $this->html( 'title' ) ?></span></h1>
169 <!-- /firstHeading -->
170 <!-- bodyContent -->
171 <div id="bodyContent">
172 <?php if ( $this->data['isarticle'] ): ?>
173 <!-- tagline -->
174 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
175 <!-- /tagline -->
176 <?php endif; ?>
177 <!-- subtitle -->
178 <div id="contentSub"<?php $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' ) ?></div>
179 <!-- /subtitle -->
180 <?php if ( $this->data['undelete'] ): ?>
181 <!-- undelete -->
182 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
183 <!-- /undelete -->
184 <?php endif; ?>
185 <?php if( $this->data['newtalk'] ): ?>
186 <!-- newtalk -->
187 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
188 <!-- /newtalk -->
189 <?php endif; ?>
190 <?php if ( $this->data['showjumplinks'] ): ?>
191 <!-- jumpto -->
192 <div id="jump-to-nav" class="mw-jump">
193 <?php $this->msg( 'jumpto' ) ?>
194 <a href="#mw-head"><?php $this->msg( 'jumptonavigation' ) ?></a><?php $this->msg( 'comma-separator' ) ?>
195 <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
196 </div>
197 <!-- /jumpto -->
198 <?php endif; ?>
199 <!-- bodycontent -->
200 <?php $this->html( 'bodycontent' ) ?>
201 <!-- /bodycontent -->
202 <?php if ( $this->data['printfooter'] ): ?>
203 <!-- printfooter -->
204 <div class="printfooter">
205 <?php $this->html( 'printfooter' ); ?>
206 </div>
207 <!-- /printfooter -->
208 <?php endif; ?>
209 <?php if ( $this->data['catlinks'] ): ?>
210 <!-- catlinks -->
211 <?php $this->html( 'catlinks' ); ?>
212 <!-- /catlinks -->
213 <?php endif; ?>
214 <?php if ( $this->data['dataAfterContent'] ): ?>
215 <!-- dataAfterContent -->
216 <?php $this->html( 'dataAfterContent' ); ?>
217 <!-- /dataAfterContent -->
218 <?php endif; ?>
219 <div class="visualClear"></div>
220 <!-- debughtml -->
221 <?php $this->html( 'debughtml' ); ?>
222 <!-- /debughtml -->
223 </div>
224 <!-- /bodyContent -->
225 </div>
226 <!-- /content -->
227 <!-- header -->
228 <div id="mw-head" class="noprint">
229 <?php $this->renderNavigation( 'PERSONAL' ); ?>
230 <div id="left-navigation">
231 <?php $this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?>
232 </div>
233 <div id="right-navigation">
234 <?php $this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?>
235 </div>
236 </div>
237 <!-- /header -->
238 <!-- panel -->
239 <div id="mw-panel" class="noprint">
240 <!-- logo -->
241 <div id="p-logo"><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>
242 <!-- /logo -->
243 <?php $this->renderPortals( $this->data['sidebar'] ); ?>
244 </div>
245 <!-- /panel -->
246 <!-- footer -->
247 <div id="footer"<?php $this->html( 'userlangattributes' ) ?>>
248 <?php foreach( $this->getFooterLinks() as $category => $links ): ?>
249 <ul id="footer-<?php echo $category ?>">
250 <?php foreach( $links as $link ): ?>
251 <li id="footer-<?php echo $category ?>-<?php echo $link ?>"><?php $this->html( $link ) ?></li>
252 <?php endforeach; ?>
253 </ul>
254 <?php endforeach; ?>
255 <?php $footericons = $this->getFooterIcons("icononly");
256 if ( count( $footericons ) > 0 ): ?>
257 <ul id="footer-icons" class="noprint">
258 <?php foreach ( $footericons as $blockName => $footerIcons ): ?>
259 <li id="footer-<?php echo htmlspecialchars( $blockName ); ?>ico">
260 <?php foreach ( $footerIcons as $icon ): ?>
261 <?php echo $this->getSkin()->makeFooterIcon( $icon ); ?>
262
263 <?php endforeach; ?>
264 </li>
265 <?php endforeach; ?>
266 </ul>
267 <?php endif; ?>
268 <div style="clear:both"></div>
269 </div>
270 <!-- /footer -->
271 <?php $this->printTrail(); ?>
272
273 </body>
274 </html>
275 <?php
276 }
277
278 /**
279 * Render a series of portals
280 *
281 * @param $portals array
282 */
283 protected function renderPortals( $portals ) {
284 // Force the rendering of the following portals
285 if ( !isset( $portals['SEARCH'] ) ) {
286 $portals['SEARCH'] = true;
287 }
288 if ( !isset( $portals['TOOLBOX'] ) ) {
289 $portals['TOOLBOX'] = true;
290 }
291 if ( !isset( $portals['LANGUAGES'] ) ) {
292 $portals['LANGUAGES'] = true;
293 }
294 // Render portals
295 foreach ( $portals as $name => $content ) {
296 if ( $content === false )
297 continue;
298
299 echo "\n<!-- {$name} -->\n";
300 switch( $name ) {
301 case 'SEARCH':
302 break;
303 case 'TOOLBOX':
304 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
305 break;
306 case 'LANGUAGES':
307 if ( $this->data['language_urls'] ) {
308 $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
309 }
310 break;
311 default:
312 $this->renderPortal( $name, $content );
313 break;
314 }
315 echo "\n<!-- /{$name} -->\n";
316 }
317 }
318
319 /**
320 * @param $name string
321 * @param $content array
322 * @param $msg null|string
323 * @param $hook null|string|array
324 */
325 protected function renderPortal( $name, $content, $msg = null, $hook = null ) {
326 if ( $msg === null ) {
327 $msg = $name;
328 }
329 ?>
330 <div class="portal" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo Linker::tooltip( 'p-' . $name ) ?>>
331 <h5<?php $this->html( 'userlangattributes' ) ?>><?php $msgObj = wfMessage( $msg ); echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg ); ?></h5>
332 <div class="body">
333 <?php
334 if ( is_array( $content ) ): ?>
335 <ul>
336 <?php
337 foreach( $content as $key => $val ): ?>
338 <?php echo $this->makeListItem( $key, $val ); ?>
339
340 <?php
341 endforeach;
342 if ( $hook !== null ) {
343 wfRunHooks( $hook, array( &$this, true ) );
344 }
345 ?>
346 </ul>
347 <?php
348 else: ?>
349 <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
350 <?php
351 endif; ?>
352 </div>
353 </div>
354 <?php
355 }
356
357 /**
358 * Render one or more navigations elements by name, automatically reveresed
359 * when UI is in RTL mode
360 *
361 * @param $elements array
362 */
363 protected function renderNavigation( $elements ) {
364 global $wgVectorUseSimpleSearch;
365
366 // If only one element was given, wrap it in an array, allowing more
367 // flexible arguments
368 if ( !is_array( $elements ) ) {
369 $elements = array( $elements );
370 // If there's a series of elements, reverse them when in RTL mode
371 } elseif ( $this->data['rtl'] ) {
372 $elements = array_reverse( $elements );
373 }
374 // Render elements
375 foreach ( $elements as $name => $element ) {
376 echo "\n<!-- {$name} -->\n";
377 switch ( $element ) {
378 case 'NAMESPACES':
379 ?>
380 <div id="p-namespaces" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
381 <h5><?php $this->msg( 'namespaces' ) ?></h5>
382 <ul<?php $this->html( 'userlangattributes' ) ?>>
383 <?php foreach ( $this->data['namespace_urls'] as $link ): ?>
384 <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>
385 <?php endforeach; ?>
386 </ul>
387 </div>
388 <?php
389 break;
390 case 'VARIANTS':
391 ?>
392 <div id="p-variants" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
393 <h4>
394 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
395 <?php if ( stripos( $link['attributes'], 'selected' ) !== false ): ?>
396 <?php echo htmlspecialchars( $link['text'] ) ?>
397 <?php endif; ?>
398 <?php endforeach; ?>
399 </h4>
400 <h5><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h5>
401 <div class="menu">
402 <ul>
403 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
404 <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>
405 <?php endforeach; ?>
406 </ul>
407 </div>
408 </div>
409 <?php
410 break;
411 case 'VIEWS':
412 ?>
413 <div id="p-views" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
414 <h5><?php $this->msg('views') ?></h5>
415 <ul<?php $this->html('userlangattributes') ?>>
416 <?php foreach ( $this->data['view_urls'] as $link ): ?>
417 <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php
418 // $link['text'] can be undefined - bug 27764
419 if ( array_key_exists( 'text', $link ) ) {
420 echo array_key_exists( 'img', $link ) ? '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />' : htmlspecialchars( $link['text'] );
421 }
422 ?></a></span></li>
423 <?php endforeach; ?>
424 </ul>
425 </div>
426 <?php
427 break;
428 case 'ACTIONS':
429 ?>
430 <div id="p-cactions" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
431 <h5><span><?php $this->msg( 'actions' ) ?></span><a href="#"></a></h5>
432 <div class="menu">
433 <ul<?php $this->html( 'userlangattributes' ) ?>>
434 <?php foreach ( $this->data['action_urls'] as $link ): ?>
435 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
436 <?php endforeach; ?>
437 </ul>
438 </div>
439 </div>
440 <?php
441 break;
442 case 'PERSONAL':
443 ?>
444 <div id="p-personal" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
445 <h5><?php $this->msg( 'personaltools' ) ?></h5>
446 <ul<?php $this->html( 'userlangattributes' ) ?>>
447 <?php foreach( $this->getPersonalTools() as $key => $item ) { ?>
448 <?php echo $this->makeListItem( $key, $item ); ?>
449
450 <?php } ?>
451 </ul>
452 </div>
453 <?php
454 break;
455 case 'SEARCH':
456 ?>
457 <div id="p-search">
458 <h5<?php $this->html( 'userlangattributes' ) ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h5>
459 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
460 <?php if ( $wgVectorUseSimpleSearch && $this->getSkin()->getUser()->getOption( 'vector-simplesearch' ) ): ?>
461 <div id="simpleSearch">
462 <?php if ( $this->data['rtl'] ): ?>
463 <?php echo $this->makeSearchButton( 'image', array( 'id' => 'searchButton', 'src' => $this->getSkin()->getSkinStylePath( 'images/search-rtl.png' ), 'width' => '12', 'height' => '13' ) ); ?>
464 <?php endif; ?>
465 <?php echo $this->makeSearchInput( array( 'id' => 'searchInput', 'type' => 'text' ) ); ?>
466 <?php if ( !$this->data['rtl'] ): ?>
467 <?php echo $this->makeSearchButton( 'image', array( 'id' => 'searchButton', 'src' => $this->getSkin()->getSkinStylePath( 'images/search-ltr.png' ), 'width' => '12', 'height' => '13' ) ); ?>
468 <?php endif; ?>
469 <?php else: ?>
470 <div>
471 <?php echo $this->makeSearchInput( array( 'id' => 'searchInput' ) ); ?>
472 <?php echo $this->makeSearchButton( 'go', array( 'id' => 'searchGoButton', 'class' => 'searchButton' ) ); ?>
473 <?php echo $this->makeSearchButton( 'fulltext', array( 'id' => 'mw-searchButton', 'class' => 'searchButton' ) ); ?>
474 <?php endif; ?>
475 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
476 </div>
477 </form>
478 </div>
479 <?php
480
481 break;
482 }
483 echo "\n<!-- /{$name} -->\n";
484 }
485 }
486 }