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