follow up to r106094
[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()->getTitle()->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 $tooltip = Linker::titleAttrib( $xmlID );
101 $tooltip = $tooltip === false ? '' : Xml::expandAttributes( array( 'title' => $tooltip ) );
102 $nav[$section][$key]['key'] = $tooltip;
103
104 } else {
105 $nav[$section][$key]['key'] =
106 Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( $xmlID ) );
107 }
108 }
109 }
110 $this->data['namespace_urls'] = $nav['namespaces'];
111 $this->data['view_urls'] = $nav['views'];
112 $this->data['action_urls'] = $nav['actions'];
113 $this->data['variant_urls'] = $nav['variants'];
114
115 // Reverse horizontally rendered navigation elements
116 if ( $this->data['rtl'] ) {
117 $this->data['view_urls'] =
118 array_reverse( $this->data['view_urls'] );
119 $this->data['namespace_urls'] =
120 array_reverse( $this->data['namespace_urls'] );
121 $this->data['personal_urls'] =
122 array_reverse( $this->data['personal_urls'] );
123 }
124 // Output HTML Page
125 $this->html( 'headelement' );
126 ?>
127 <div id="mw-page-base" class="noprint"></div>
128 <div id="mw-head-base" class="noprint"></div>
129 <!-- content -->
130 <div id="content" class="mw-body">
131 <a id="top"></a>
132 <div id="mw-js-message" style="display:none;"<?php $this->html( 'userlangattributes' ) ?>></div>
133 <?php if ( $this->data['sitenotice'] ): ?>
134 <!-- sitenotice -->
135 <div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div>
136 <!-- /sitenotice -->
137 <?php endif; ?>
138 <!-- firstHeading -->
139 <h1 id="firstHeading" class="firstHeading">
140 <span dir="auto"><?php $this->html( 'title' ) ?></span>
141 </h1>
142 <!-- /firstHeading -->
143 <!-- bodyContent -->
144 <div id="bodyContent">
145 <?php if ( $this->data['isarticle'] ): ?>
146 <!-- tagline -->
147 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
148 <!-- /tagline -->
149 <?php endif; ?>
150 <!-- subtitle -->
151 <div id="contentSub"<?php $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' ) ?></div>
152 <!-- /subtitle -->
153 <?php if ( $this->data['undelete'] ): ?>
154 <!-- undelete -->
155 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
156 <!-- /undelete -->
157 <?php endif; ?>
158 <?php if( $this->data['newtalk'] ): ?>
159 <!-- newtalk -->
160 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
161 <!-- /newtalk -->
162 <?php endif; ?>
163 <?php if ( $this->data['showjumplinks'] ): ?>
164 <!-- jumpto -->
165 <div id="jump-to-nav" class="mw-jump">
166 <?php $this->msg( 'jumpto' ) ?> <a href="#mw-head"><?php $this->msg( 'jumptonavigation' ) ?></a>,
167 <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
168 </div>
169 <!-- /jumpto -->
170 <?php endif; ?>
171 <!-- bodycontent -->
172 <?php $this->html( 'bodycontent' ) ?>
173 <!-- /bodycontent -->
174 <?php if ( $this->data['printfooter'] ): ?>
175 <!-- printfooter -->
176 <div class="printfooter">
177 <?php $this->html( 'printfooter' ); ?>
178 </div>
179 <!-- /printfooter -->
180 <?php endif; ?>
181 <?php if ( $this->data['catlinks'] ): ?>
182 <!-- catlinks -->
183 <?php $this->html( 'catlinks' ); ?>
184 <!-- /catlinks -->
185 <?php endif; ?>
186 <?php if ( $this->data['dataAfterContent'] ): ?>
187 <!-- dataAfterContent -->
188 <?php $this->html( 'dataAfterContent' ); ?>
189 <!-- /dataAfterContent -->
190 <?php endif; ?>
191 <div class="visualClear"></div>
192 <!-- debughtml -->
193 <?php $this->html( 'debughtml' ); ?>
194 <!-- /debughtml -->
195 </div>
196 <!-- /bodyContent -->
197 </div>
198 <!-- /content -->
199 <!-- header -->
200 <div id="mw-head" class="noprint">
201 <?php $this->renderNavigation( 'PERSONAL' ); ?>
202 <div id="left-navigation">
203 <?php $this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?>
204 </div>
205 <div id="right-navigation">
206 <?php $this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?>
207 </div>
208 </div>
209 <!-- /header -->
210 <!-- panel -->
211 <div id="mw-panel" class="noprint">
212 <!-- logo -->
213 <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>
214 <!-- /logo -->
215 <?php $this->renderPortals( $this->data['sidebar'] ); ?>
216 </div>
217 <!-- /panel -->
218 <!-- footer -->
219 <div id="footer"<?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 endforeach; ?>
225 </ul>
226 <?php endforeach; ?>
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 endforeach; ?>
236 </li>
237 <?php endforeach; ?>
238 </ul>
239 <?php endif; ?>
240 <div style="clear:both"></div>
241 </div>
242 <!-- /footer -->
243 <!-- fixalpha -->
244 <script type="<?php $this->text( 'jsmimetype' ) ?>"> if ( window.isMSIE55 ) fixalpha(); </script>
245 <!-- /fixalpha -->
246 <?php $this->printTrail(); ?>
247
248 </body>
249 </html>
250 <?php
251 }
252
253 /**
254 * Render a series of portals
255 *
256 * @param $portals array
257 */
258 private function renderPortals( $portals ) {
259 // Force the rendering of the following portals
260 if ( !isset( $portals['SEARCH'] ) ) {
261 $portals['SEARCH'] = true;
262 }
263 if ( !isset( $portals['TOOLBOX'] ) ) {
264 $portals['TOOLBOX'] = true;
265 }
266 if ( !isset( $portals['LANGUAGES'] ) ) {
267 $portals['LANGUAGES'] = true;
268 }
269 // Render portals
270 foreach ( $portals as $name => $content ) {
271 if ( $content === false )
272 continue;
273
274 echo "\n<!-- {$name} -->\n";
275 switch( $name ) {
276 case 'SEARCH':
277 break;
278 case 'TOOLBOX':
279 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
280 break;
281 case 'LANGUAGES':
282 if ( $this->data['language_urls'] ) {
283 $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
284 }
285 break;
286 default:
287 $this->renderPortal( $name, $content );
288 break;
289 }
290 echo "\n<!-- /{$name} -->\n";
291 }
292 }
293
294 private function renderPortal( $name, $content, $msg = null, $hook = null ) {
295 if ( $msg === null ) {
296 $msg = $name;
297 }
298 ?>
299 <div class="portal" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo Linker::tooltip( 'p-' . $name ) ?>>
300 <h5<?php $this->html( 'userlangattributes' ) ?>><?php $msgObj = wfMessage( $msg ); echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg ); ?></h5>
301 <div class="body">
302 <?php
303 if ( is_array( $content ) ): ?>
304 <ul>
305 <?php
306 foreach( $content as $key => $val ): ?>
307 <?php echo $this->makeListItem( $key, $val ); ?>
308
309 <?php
310 endforeach;
311 if ( $hook !== null ) {
312 wfRunHooks( $hook, array( &$this, true ) );
313 }
314 ?>
315 </ul>
316 <?php
317 else: ?>
318 <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
319 <?php
320 endif; ?>
321 </div>
322 </div>
323 <?php
324 }
325
326 /**
327 * Render one or more navigations elements by name, automatically reveresed
328 * when UI is in RTL mode
329 *
330 * @param $elements array
331 */
332 private function renderNavigation( $elements ) {
333 global $wgVectorUseSimpleSearch;
334
335 // If only one element was given, wrap it in an array, allowing more
336 // flexible arguments
337 if ( !is_array( $elements ) ) {
338 $elements = array( $elements );
339 // If there's a series of elements, reverse them when in RTL mode
340 } elseif ( $this->data['rtl'] ) {
341 $elements = array_reverse( $elements );
342 }
343 // Render elements
344 foreach ( $elements as $name => $element ) {
345 echo "\n<!-- {$name} -->\n";
346 switch ( $element ) {
347 case 'NAMESPACES':
348 ?>
349 <div id="p-namespaces" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
350 <h5><?php $this->msg( 'namespaces' ) ?></h5>
351 <ul<?php $this->html( 'userlangattributes' ) ?>>
352 <?php foreach ( $this->data['namespace_urls'] as $link ): ?>
353 <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>
354 <?php endforeach; ?>
355 </ul>
356 </div>
357 <?php
358 break;
359 case 'VARIANTS':
360 ?>
361 <div id="p-variants" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
362 <h4>
363 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
364 <?php if ( stripos( $link['attributes'], 'selected' ) !== false ): ?>
365 <?php echo htmlspecialchars( $link['text'] ) ?>
366 <?php endif; ?>
367 <?php endforeach; ?>
368 </h4>
369 <h5><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h5>
370 <div class="menu">
371 <ul<?php $this->html( 'userlangattributes' ) ?>>
372 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
373 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
374 <?php endforeach; ?>
375 </ul>
376 </div>
377 </div>
378 <?php
379 break;
380 case 'VIEWS':
381 ?>
382 <div id="p-views" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
383 <h5><?php $this->msg('views') ?></h5>
384 <ul<?php $this->html('userlangattributes') ?>>
385 <?php foreach ( $this->data['view_urls'] as $link ): ?>
386 <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php
387 // $link['text'] can be undefined - bug 27764
388 if ( array_key_exists( 'text', $link ) ) {
389 echo array_key_exists( 'img', $link ) ? '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />' : htmlspecialchars( $link['text'] );
390 }
391 ?></a></span></li>
392 <?php endforeach; ?>
393 </ul>
394 </div>
395 <?php
396 break;
397 case 'ACTIONS':
398 ?>
399 <div id="p-cactions" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
400 <h5><span><?php $this->msg( 'actions' ) ?></span><a href="#"></a></h5>
401 <div class="menu">
402 <ul<?php $this->html( 'userlangattributes' ) ?>>
403 <?php foreach ( $this->data['action_urls'] as $link ): ?>
404 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?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 'PERSONAL':
412 ?>
413 <div id="p-personal" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
414 <h5><?php $this->msg( 'personaltools' ) ?></h5>
415 <ul<?php $this->html( 'userlangattributes' ) ?>>
416 <?php foreach( $this->getPersonalTools() as $key => $item ) { ?>
417 <?php echo $this->makeListItem( $key, $item ); ?>
418
419 <?php } ?>
420 </ul>
421 </div>
422 <?php
423 break;
424 case 'SEARCH':
425 ?>
426 <div id="p-search">
427 <h5<?php $this->html( 'userlangattributes' ) ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h5>
428 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
429 <?php if ( $wgVectorUseSimpleSearch && $this->getSkin()->getUser()->getOption( 'vector-simplesearch' ) ): ?>
430 <div id="simpleSearch">
431 <?php if ( $this->data['rtl'] ): ?>
432 <?php echo $this->makeSearchButton( 'image', array( 'id' => 'searchButton', 'src' => $this->getSkin()->getSkinStylePath( 'images/search-rtl.png' ) ) ); ?>
433 <?php endif; ?>
434 <?php echo $this->makeSearchInput( array( 'id' => 'searchInput', 'type' => 'text' ) ); ?>
435 <?php if ( !$this->data['rtl'] ): ?>
436 <?php echo $this->makeSearchButton( 'image', array( 'id' => 'searchButton', 'src' => $this->getSkin()->getSkinStylePath( 'images/search-ltr.png' ) ) ); ?>
437 <?php endif; ?>
438 <?php else: ?>
439 <div>
440 <?php echo $this->makeSearchInput( array( 'id' => 'searchInput' ) ); ?>
441 <?php echo $this->makeSearchButton( 'go', array( 'id' => 'searchGoButton', 'class' => 'searchButton' ) ); ?>
442 <?php echo $this->makeSearchButton( 'fulltext', array( 'id' => 'mw-searchButton', 'class' => 'searchButton' ) ); ?>
443 <?php endif; ?>
444 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
445 </div>
446 </form>
447 </div>
448 <?php
449
450 break;
451 }
452 echo "\n<!-- /{$name} -->\n";
453 }
454 }
455 }