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