Fixes Bug 32403. Will only work on browsers that support dir="auto". Won't break...
[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 $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" dir="auto"><?php $this->html( 'title' ) ?></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 <!-- fixalpha -->
240 <script type="<?php $this->text( 'jsmimetype' ) ?>"> if ( window.isMSIE55 ) fixalpha(); </script>
241 <!-- /fixalpha -->
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 private 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 echo "\n<!-- {$name} -->\n";
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'] ) {
279 $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
280 }
281 break;
282 default:
283 $this->renderPortal( $name, $content );
284 break;
285 }
286 echo "\n<!-- /{$name} -->\n";
287 }
288 }
289
290 private function renderPortal( $name, $content, $msg = null, $hook = null ) {
291 if ( $msg === null ) {
292 $msg = $name;
293 }
294 ?>
295 <div class="portal" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo Linker::tooltip( 'p-' . $name ) ?>>
296 <h5<?php $this->html( 'userlangattributes' ) ?>><?php $msgObj = wfMessage( $msg ); echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $msg ); ?></h5>
297 <div class="body">
298 <?php
299 if ( is_array( $content ) ): ?>
300 <ul>
301 <?php
302 foreach( $content as $key => $val ): ?>
303 <?php echo $this->makeListItem( $key, $val ); ?>
304
305 <?php
306 endforeach;
307 if ( $hook !== null ) {
308 wfRunHooks( $hook, array( &$this, true ) );
309 }
310 ?>
311 </ul>
312 <?php
313 else: ?>
314 <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
315 <?php
316 endif; ?>
317 </div>
318 </div>
319 <?php
320 }
321
322 /**
323 * Render one or more navigations elements by name, automatically reveresed
324 * when UI is in RTL mode
325 *
326 * @param $elements array
327 */
328 private function renderNavigation( $elements ) {
329 global $wgVectorUseSimpleSearch;
330
331 // If only one element was given, wrap it in an array, allowing more
332 // flexible arguments
333 if ( !is_array( $elements ) ) {
334 $elements = array( $elements );
335 // If there's a series of elements, reverse them when in RTL mode
336 } elseif ( $this->data['rtl'] ) {
337 $elements = array_reverse( $elements );
338 }
339 // Render elements
340 foreach ( $elements as $name => $element ) {
341 echo "\n<!-- {$name} -->\n";
342 switch ( $element ) {
343 case 'NAMESPACES':
344 ?>
345 <div id="p-namespaces" class="vectorTabs<?php if ( count( $this->data['namespace_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
346 <h5><?php $this->msg( 'namespaces' ) ?></h5>
347 <ul<?php $this->html( 'userlangattributes' ) ?>>
348 <?php foreach ( $this->data['namespace_urls'] as $link ): ?>
349 <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>
350 <?php endforeach; ?>
351 </ul>
352 </div>
353 <?php
354 break;
355 case 'VARIANTS':
356 ?>
357 <div id="p-variants" class="vectorMenu<?php if ( count( $this->data['variant_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
358 <h4>
359 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
360 <?php if ( stripos( $link['attributes'], 'selected' ) !== false ): ?>
361 <?php echo htmlspecialchars( $link['text'] ) ?>
362 <?php endif; ?>
363 <?php endforeach; ?>
364 </h4>
365 <h5><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h5>
366 <div class="menu">
367 <ul<?php $this->html( 'userlangattributes' ) ?>>
368 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
369 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
370 <?php endforeach; ?>
371 </ul>
372 </div>
373 </div>
374 <?php
375 break;
376 case 'VIEWS':
377 ?>
378 <div id="p-views" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
379 <h5><?php $this->msg('views') ?></h5>
380 <ul<?php $this->html('userlangattributes') ?>>
381 <?php foreach ( $this->data['view_urls'] as $link ): ?>
382 <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php
383 // $link['text'] can be undefined - bug 27764
384 if ( array_key_exists( 'text', $link ) ) {
385 echo array_key_exists( 'img', $link ) ? '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />' : htmlspecialchars( $link['text'] );
386 }
387 ?></a></span></li>
388 <?php endforeach; ?>
389 </ul>
390 </div>
391 <?php
392 break;
393 case 'ACTIONS':
394 ?>
395 <div id="p-cactions" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
396 <h5><span><?php $this->msg( 'actions' ) ?></span><a href="#"></a></h5>
397 <div class="menu">
398 <ul<?php $this->html( 'userlangattributes' ) ?>>
399 <?php foreach ( $this->data['action_urls'] as $link ): ?>
400 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
401 <?php endforeach; ?>
402 </ul>
403 </div>
404 </div>
405 <?php
406 break;
407 case 'PERSONAL':
408 ?>
409 <div id="p-personal" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
410 <h5><?php $this->msg( 'personaltools' ) ?></h5>
411 <ul<?php $this->html( 'userlangattributes' ) ?>>
412 <?php foreach( $this->getPersonalTools() as $key => $item ) { ?>
413 <?php echo $this->makeListItem( $key, $item ); ?>
414
415 <?php } ?>
416 </ul>
417 </div>
418 <?php
419 break;
420 case 'SEARCH':
421 ?>
422 <div id="p-search">
423 <h5<?php $this->html( 'userlangattributes' ) ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h5>
424 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
425 <?php if ( $wgVectorUseSimpleSearch && $this->getSkin()->getUser()->getOption( 'vector-simplesearch' ) ): ?>
426 <div id="simpleSearch">
427 <?php if ( $this->data['rtl'] ): ?>
428 <?php echo $this->makeSearchButton( 'image', array( 'id' => 'searchButton', 'src' => $this->getSkin()->getSkinStylePath( 'images/search-rtl.png' ) ) ); ?>
429 <?php endif; ?>
430 <?php echo $this->makeSearchInput( array( 'id' => 'searchInput', 'type' => 'text' ) ); ?>
431 <?php if ( !$this->data['rtl'] ): ?>
432 <?php echo $this->makeSearchButton( 'image', array( 'id' => 'searchButton', 'src' => $this->getSkin()->getSkinStylePath( 'images/search-ltr.png' ) ) ); ?>
433 <?php endif; ?>
434 <?php else: ?>
435 <div>
436 <?php echo $this->makeSearchInput( array( 'id' => 'searchInput' ) ); ?>
437 <?php echo $this->makeSearchButton( 'go', array( 'id' => 'searchGoButton', 'class' => 'searchButton' ) ); ?>
438 <?php echo $this->makeSearchButton( 'fulltext', array( 'id' => 'mw-searchButton', 'class' => 'searchButton' ) ); ?>
439 <?php endif; ?>
440 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
441 </div>
442 </form>
443 </div>
444 <?php
445
446 break;
447 }
448 echo "\n<!-- /{$name} -->\n";
449 }
450 }
451 }