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