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