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