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