Vector.php: coding style
[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, $wgRequest;
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 = $wgRequest->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 /* Members */
64
65 /**
66 * @var Skin Cached skin object
67 */
68 var $skin;
69
70 /* Functions */
71
72 /**
73 * Outputs the entire contents of the (X)HTML page
74 */
75 public function execute() {
76 global $wgLang, $wgVectorUseIconWatch;
77
78 $this->skin = $this->data['skin'];
79
80 // Build additional attributes for navigation urls
81 //$nav = $this->skin->buildNavigationUrls();
82 $nav = $this->data['content_navigation'];
83
84 if ( $wgVectorUseIconWatch ) {
85 $mode = $this->skin->getTitle()->userIsWatching() ? 'unwatch' : 'watch';
86 if ( isset( $nav['actions'][$mode] ) ) {
87 $nav['views'][$mode] = $nav['actions'][$mode];
88 $nav['views'][$mode]['class'] = rtrim( 'icon ' . $nav['views'][$mode]['class'], ' ' );
89 $nav['views'][$mode]['primary'] = true;
90 unset( $nav['actions'][$mode] );
91 }
92 }
93
94 $xmlID = '';
95 foreach ( $nav as $section => $links ) {
96 foreach ( $links as $key => $link ) {
97 if ( $section == 'views' && !( isset( $link['primary'] ) && $link['primary'] ) ) {
98 $link['class'] = rtrim( 'collapsible ' . $link['class'], ' ' );
99 }
100
101 $xmlID = isset( $link['id'] ) ? $link['id'] : 'ca-' . $xmlID;
102 $nav[$section][$key]['attributes'] =
103 ' id="' . Sanitizer::escapeId( $xmlID ) . '"';
104 if ( $link['class'] ) {
105 $nav[$section][$key]['attributes'] .=
106 ' class="' . htmlspecialchars( $link['class'] ) . '"';
107 unset( $nav[$section][$key]['class'] );
108 }
109 if ( isset( $link['tooltiponly'] ) && $link['tooltiponly'] ) {
110 $nav[$section][$key]['key'] =
111 Linker::tooltip( $xmlID );
112 } else {
113 $nav[$section][$key]['key'] =
114 Xml::expandAttributes( Linker::tooltipAndAccesskeyAttribs( $xmlID ) );
115 }
116 }
117 }
118 $this->data['namespace_urls'] = $nav['namespaces'];
119 $this->data['view_urls'] = $nav['views'];
120 $this->data['action_urls'] = $nav['actions'];
121 $this->data['variant_urls'] = $nav['variants'];
122
123 // Reverse horizontally rendered navigation elements
124 if ( $wgLang->isRTL() ) {
125 $this->data['view_urls'] =
126 array_reverse( $this->data['view_urls'] );
127 $this->data['namespace_urls'] =
128 array_reverse( $this->data['namespace_urls'] );
129 $this->data['personal_urls'] =
130 array_reverse( $this->data['personal_urls'] );
131 }
132 // Output HTML Page
133 $this->html( 'headelement' );
134 ?>
135 <div id="mw-page-base" class="noprint"></div>
136 <div id="mw-head-base" class="noprint"></div>
137 <!-- content -->
138 <div id="content"<?php $this->html( 'specialpageattributes' ) ?>>
139 <a id="top"></a>
140 <div id="mw-js-message" style="display:none;"<?php $this->html( 'userlangattributes' ) ?>></div>
141 <?php if ( $this->data['sitenotice'] ): ?>
142 <!-- sitenotice -->
143 <div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div>
144 <!-- /sitenotice -->
145 <?php endif; ?>
146 <!-- firstHeading -->
147 <h1 id="firstHeading" class="firstHeading"><?php $this->html( 'title' ) ?></h1>
148 <!-- /firstHeading -->
149 <!-- bodyContent -->
150 <div id="bodyContent">
151 <?php if ( $this->data['isarticle'] ): ?>
152 <!-- tagline -->
153 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
154 <!-- /tagline -->
155 <?php endif; ?>
156 <!-- subtitle -->
157 <div id="contentSub"<?php $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' ) ?></div>
158 <!-- /subtitle -->
159 <?php if ( $this->data['undelete'] ): ?>
160 <!-- undelete -->
161 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
162 <!-- /undelete -->
163 <?php endif; ?>
164 <?php if( $this->data['newtalk'] ): ?>
165 <!-- newtalk -->
166 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
167 <!-- /newtalk -->
168 <?php endif; ?>
169 <?php if ( $this->data['showjumplinks'] ): ?>
170 <!-- jumpto -->
171 <div id="jump-to-nav">
172 <?php $this->msg( 'jumpto' ) ?> <a href="#mw-head"><?php $this->msg( 'jumptonavigation' ) ?></a>,
173 <a href="#p-search"><?php $this->msg( 'jumptosearch' ) ?></a>
174 </div>
175 <!-- /jumpto -->
176 <?php endif; ?>
177 <!-- bodytext -->
178 <?php $this->html( 'bodytext' ) ?>
179 <!-- /bodytext -->
180 <?php if ( $this->data['printfooter'] ): ?>
181 <!-- printfooter -->
182 <div class="printfooter">
183 <?php $this->html( 'printfooter' ); ?>
184 </div>
185 <!-- /printfooter -->
186 <?php endif; ?>
187 <!-- debughtml -->
188 <?php $this->html( 'debughtml' ); ?>
189 <!-- /debughtml -->
190 <?php if ( $this->data['catlinks'] ): ?>
191 <!-- catlinks -->
192 <?php $this->html( 'catlinks' ); ?>
193 <!-- /catlinks -->
194 <?php endif; ?>
195 <?php if ( $this->data['dataAfterContent'] ): ?>
196 <!-- dataAfterContent -->
197 <?php $this->html( 'dataAfterContent' ); ?>
198 <!-- /dataAfterContent -->
199 <?php endif; ?>
200 <div class="visualClear"></div>
201 </div>
202 <!-- /bodyContent -->
203 </div>
204 <!-- /content -->
205 <!-- header -->
206 <div id="mw-head" class="noprint">
207 <?php $this->renderNavigation( 'PERSONAL' ); ?>
208 <div id="left-navigation">
209 <?php $this->renderNavigation( array( 'NAMESPACES', 'VARIANTS' ) ); ?>
210 </div>
211 <div id="right-navigation">
212 <?php $this->renderNavigation( array( 'VIEWS', 'ACTIONS', 'SEARCH' ) ); ?>
213 </div>
214 </div>
215 <!-- /header -->
216 <!-- panel -->
217 <div id="mw-panel" class="noprint">
218 <!-- logo -->
219 <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 Linker::tooltipAndAccesskeyAttribs( 'p-logo' ) ?>></a></div>
220 <!-- /logo -->
221 <?php $this->renderPortals( $this->data['sidebar'] ); ?>
222 </div>
223 <!-- /panel -->
224 <!-- footer -->
225 <div id="footer"<?php $this->html( 'userlangattributes' ) ?>>
226 <?php foreach( $this->getFooterLinks() as $category => $links ): ?>
227 <ul id="footer-<?php echo $category ?>">
228 <?php foreach( $links as $link ): ?>
229 <li id="footer-<?php echo $category ?>-<?php echo $link ?>"><?php $this->html( $link ) ?></li>
230 <?php endforeach; ?>
231 </ul>
232 <?php endforeach; ?>
233 <?php $footericons = $this->getFooterIcons("icononly");
234 if ( count( $footericons ) > 0 ): ?>
235 <ul id="footer-icons" class="noprint">
236 <?php foreach ( $footericons as $blockName => $footerIcons ): ?>
237 <li id="footer-<?php echo htmlspecialchars( $blockName ); ?>ico">
238 <?php foreach ( $footerIcons as $icon ): ?>
239 <?php echo $this->skin->makeFooterIcon( $icon ); ?>
240
241 <?php endforeach; ?>
242 </li>
243 <?php endforeach; ?>
244 </ul>
245 <?php endif; ?>
246 <div style="clear:both"></div>
247 </div>
248 <!-- /footer -->
249 <!-- fixalpha -->
250 <script type="<?php $this->text( 'jsmimetype' ) ?>"> if ( window.isMSIE55 ) fixalpha(); </script>
251 <!-- /fixalpha -->
252 <?php $this->printTrail(); ?>
253
254 </body>
255 </html>
256 <?php
257 }
258
259 /**
260 * Render a series of portals
261 */
262 private function renderPortals( $portals ) {
263 // Force the rendering of the following portals
264 if ( !isset( $portals['SEARCH'] ) ) {
265 $portals['SEARCH'] = true;
266 }
267 if ( !isset( $portals['TOOLBOX'] ) ) {
268 $portals['TOOLBOX'] = true;
269 }
270 if ( !isset( $portals['LANGUAGES'] ) ) {
271 $portals['LANGUAGES'] = true;
272 }
273 // Render portals
274 foreach ( $portals as $name => $content ) {
275 echo "\n<!-- {$name} -->\n";
276 switch( $name ) {
277 case 'SEARCH':
278 break;
279 case 'TOOLBOX':
280 $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
281 break;
282 case 'LANGUAGES':
283 if ( $this->data['language_urls'] ) {
284 $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
285 }
286 break;
287 default:
288 $this->renderPortal( $name, $content );
289 break;
290 }
291 echo "\n<!-- /{$name} -->\n";
292 }
293 }
294
295 private function renderPortal( $name, $content, $msg = null, $hook = null ) {
296 if ( !isset( $msg ) ) {
297 $msg = $name;
298 }
299 ?>
300 <div class="portal" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo Linker::tooltip( 'p-' . $name ) ?>>
301 <h5<?php $this->html( 'userlangattributes' ) ?>><?php $out = wfMsg( $msg ); if ( wfEmptyMsg( $msg ) ) echo htmlspecialchars( $msg ); else echo htmlspecialchars( $out ); ?></h5>
302 <div class="body">
303 <?php
304 if ( is_array( $content ) ): ?>
305 <ul>
306 <?php
307 foreach( $content as $key => $val ): ?>
308 <?php echo $this->makeListItem( $key, $val ); ?>
309
310 <?php
311 endforeach;
312 if ( isset( $hook ) ) {
313 wfRunHooks( $hook, array( &$this ) );
314 }
315 ?>
316 </ul>
317 <?php
318 else: ?>
319 <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
320 <?php
321 endif; ?>
322 </div>
323 </div>
324 <?php
325 }
326
327 /**
328 * Render one or more navigations elements by name, automatically reveresed
329 * when UI is in RTL mode
330 */
331 private function renderNavigation( $elements ) {
332 global $wgVectorUseSimpleSearch, $wgVectorShowVariantName, $wgUser;
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 ( wfUILang()->isRTL() ) {
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 <?php if ( $wgVectorShowVariantName ): ?>
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 <?php endif; ?>
370 <h5><span><?php $this->msg( 'variants' ) ?></span><a href="#"></a></h5>
371 <div class="menu">
372 <ul<?php $this->html( 'userlangattributes' ) ?>>
373 <?php foreach ( $this->data['variant_urls'] as $link ): ?>
374 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
375 <?php endforeach; ?>
376 </ul>
377 </div>
378 </div>
379 <?php
380 break;
381 case 'VIEWS':
382 ?>
383 <div id="p-views" class="vectorTabs<?php if ( count( $this->data['view_urls'] ) == 0 ) { echo ' emptyPortlet'; } ?>">
384 <h5><?php $this->msg('views') ?></h5>
385 <ul<?php $this->html('userlangattributes') ?>>
386 <?php foreach ( $this->data['view_urls'] as $link ): ?>
387 <li<?php echo $link['attributes'] ?>><span><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php
388 // $link['text'] can be undefined - bug 27764
389 if ( array_key_exists( 'text', $link ) ) {
390 echo array_key_exists( 'img', $link ) ? '<img src="' . $link['img'] . '" alt="' . $link['text'] . '" />' : htmlspecialchars( $link['text'] );
391 }
392 ?></a></span></li>
393 <?php endforeach; ?>
394 </ul>
395 </div>
396 <?php
397 break;
398 case 'ACTIONS':
399 ?>
400 <div id="p-cactions" class="vectorMenu<?php if ( count( $this->data['action_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
401 <h5><span><?php $this->msg( 'actions' ) ?></span><a href="#"></a></h5>
402 <div class="menu">
403 <ul<?php $this->html( 'userlangattributes' ) ?>>
404 <?php foreach ( $this->data['action_urls'] as $link ): ?>
405 <li<?php echo $link['attributes'] ?>><a href="<?php echo htmlspecialchars( $link['href'] ) ?>" <?php echo $link['key'] ?>><?php echo htmlspecialchars( $link['text'] ) ?></a></li>
406 <?php endforeach; ?>
407 </ul>
408 </div>
409 </div>
410 <?php
411 break;
412 case 'PERSONAL':
413 ?>
414 <div id="p-personal" class="<?php if ( count( $this->data['personal_urls'] ) == 0 ) echo ' emptyPortlet'; ?>">
415 <h5><?php $this->msg( 'personaltools' ) ?></h5>
416 <ul<?php $this->html( 'userlangattributes' ) ?>>
417 <?php foreach( $this->getPersonalTools() as $key => $item ) { ?>
418 <?php echo $this->makeListItem( $key, $item ); ?>
419
420 <?php } ?>
421 </ul>
422 </div>
423 <?php
424 break;
425 case 'SEARCH':
426 ?>
427 <div id="p-search">
428 <h5<?php $this->html( 'userlangattributes' ) ?>><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h5>
429 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
430 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
431 <?php if ( $wgVectorUseSimpleSearch && $wgUser->getOption( 'vector-simplesearch' ) ): ?>
432 <div id="simpleSearch">
433 <?php if ( $this->data['rtl'] ): ?>
434 <?php echo $this->makeSearchButton( 'image', array( 'id' => 'searchButton', 'src' => $this->skin->getSkinStylePath( 'images/search-rtl.png' ) ) ); ?>
435 <?php endif; ?>
436 <?php echo $this->makeSearchInput( array( 'id' => 'searchInput', 'type' => 'text' ) ); ?>
437 <?php if ( !$this->data['rtl'] ): ?>
438 <?php echo $this->makeSearchButton( 'image', array( 'id' => 'searchButton', 'src' => $this->skin->getSkinStylePath( 'images/search-ltr.png' ) ) ); ?>
439 <?php endif; ?>
440 </div>
441 <?php else: ?>
442 <?php echo $this->makeSearchInput( array( 'id' => 'searchInput' ) ); ?>
443 <?php echo $this->makeSearchButton( 'go', array( 'id' => 'searchGoButton', 'class' => 'searchButton' ) ); ?>
444 <?php echo $this->makeSearchButton( 'fulltext', array( 'id' => 'mw-searchButton', 'class' => 'searchButton' ) ); ?>
445 <?php endif; ?>
446 </form>
447 </div>
448 <?php
449
450 break;
451 }
452 echo "\n<!-- /{$name} -->\n";
453 }
454 }
455 }