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